-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the Picture and Recorder classes. (#199)
- Loading branch information
Showing
27 changed files
with
1,613 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making tgfx available. | ||
// | ||
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/BSD-3-Clause | ||
// | ||
// unless required by applicable law or agreed to in writing, software distributed under the | ||
// license is distributed on an "as is" basis, without warranties or conditions of any kind, | ||
// either express or implied. see the license for the specific language governing permissions | ||
// and limitations under the license. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include "tgfx/core/Matrix.h" | ||
#include "tgfx/core/Path.h" | ||
|
||
namespace tgfx { | ||
class Record; | ||
class Canvas; | ||
class DrawContext; | ||
class MCState; | ||
|
||
/** | ||
* The Picture class captures the drawing commands made on a Canvas, which can be replayed later. | ||
* The Picture object is thread-safe and immutable once created. Pictures can be created by a | ||
* Recorder or loaded from serialized data. | ||
*/ | ||
class Picture { | ||
public: | ||
~Picture(); | ||
|
||
/** | ||
* Returns the bounding box of the Picture when drawn with the given Matrix. | ||
*/ | ||
Rect getBounds(const Matrix& matrix = Matrix::I()) const; | ||
|
||
/** | ||
* Replays the drawing commands on the specified canvas. In the case that the commands are | ||
* recorded, each command in the Picture is sent separately to canvas. To add a single command to | ||
* draw Picture to recording canvas, call Canvas::drawPicture() instead. | ||
*/ | ||
void playback(Canvas* canvas) const; | ||
|
||
private: | ||
std::vector<Record*> records = {}; | ||
|
||
explicit Picture(std::vector<Record*> records); | ||
|
||
void playback(DrawContext* drawContext, const MCState& state) const; | ||
|
||
friend class DrawContext; | ||
friend class RenderContext; | ||
friend class RecordingContext; | ||
friend class Canvas; | ||
}; | ||
} // namespace tgfx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making tgfx available. | ||
// | ||
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/BSD-3-Clause | ||
// | ||
// unless required by applicable law or agreed to in writing, software distributed under the | ||
// license is distributed on an "as is" basis, without warranties or conditions of any kind, | ||
// either express or implied. see the license for the specific language governing permissions | ||
// and limitations under the license. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include "tgfx/core/Canvas.h" | ||
#include "tgfx/core/Picture.h" | ||
|
||
namespace tgfx { | ||
class RecordingContext; | ||
|
||
/** | ||
* The Recorder class records drawing commands made to a Canvas and generates a Picture object that | ||
* captures all these commands, allowing them to be replayed at a later time. | ||
*/ | ||
class Recorder { | ||
public: | ||
~Recorder(); | ||
|
||
/** | ||
* Begins recording drawing commands. If recording is already active, it clears the existing | ||
* commands and starts afresh. Returns the canvas that captures the drawing commands. The returned | ||
* Canvas is managed by the Recorder and is deleted when the Recorder is deleted. | ||
*/ | ||
Canvas* beginRecording(); | ||
|
||
/** | ||
* Returns the recording canvas if one is active, or NULL if recording is not active. | ||
*/ | ||
Canvas* getRecordingCanvas() const; | ||
|
||
/** | ||
* Signals that the caller is done recording and returns a Picture object that captures all the | ||
* drawing commands made to the canvas. Returns nullptr if no recording is active or no commands | ||
* were recorded. | ||
*/ | ||
std::shared_ptr<Picture> finishRecordingAsPicture(); | ||
|
||
private: | ||
bool activelyRecording = false; | ||
RecordingContext* recordingContext = nullptr; | ||
Canvas* canvas = nullptr; | ||
}; | ||
} // namespace tgfx |
Oops, something went wrong.