2014-04-18 18:04:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPictureRecorder_DEFINED
|
|
|
|
#define SkPictureRecorder_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBBHFactory.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
|
2014-06-17 20:42:59 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
|
|
namespace android {
|
|
|
|
class Picture;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2014-04-18 18:04:41 +00:00
|
|
|
class SkCanvas;
|
2015-02-06 16:36:15 +00:00
|
|
|
class SkDrawable;
|
2019-05-20 12:45:50 +00:00
|
|
|
class SkMiniRecorder;
|
2014-06-08 12:55:05 +00:00
|
|
|
class SkPictureRecord;
|
2014-06-17 19:08:15 +00:00
|
|
|
class SkRecord;
|
|
|
|
class SkRecorder;
|
2014-04-18 18:04:41 +00:00
|
|
|
|
2019-06-04 13:51:54 +00:00
|
|
|
class SK_API SkPictureRecorder {
|
2014-04-18 18:04:41 +00:00
|
|
|
public:
|
2014-06-23 17:29:10 +00:00
|
|
|
SkPictureRecorder();
|
2014-06-08 12:55:05 +00:00
|
|
|
~SkPictureRecorder();
|
|
|
|
|
2016-07-06 16:29:16 +00:00
|
|
|
enum FinishFlags {
|
2014-11-11 12:54:49 +00:00
|
|
|
};
|
|
|
|
|
2014-04-18 18:04:41 +00:00
|
|
|
/** Returns the canvas that records the drawing commands.
|
2014-11-19 16:04:34 +00:00
|
|
|
@param bounds the cull rect used when recording this picture. Any drawing the falls outside
|
|
|
|
of this rect is undefined, and may be drawn or it may not.
|
2020-01-21 16:48:46 +00:00
|
|
|
@param bbh optional acceleration structure
|
2014-04-18 18:04:41 +00:00
|
|
|
@param recordFlags optional flags that control recording.
|
|
|
|
@return the canvas.
|
|
|
|
*/
|
2020-08-21 17:42:01 +00:00
|
|
|
SkCanvas* beginRecording(const SkRect& bounds, sk_sp<SkBBoxHierarchy> bbh);
|
2020-01-21 16:48:46 +00:00
|
|
|
|
2020-08-21 17:42:01 +00:00
|
|
|
SkCanvas* beginRecording(const SkRect& bounds, SkBBHFactory* bbhFactory = nullptr);
|
2014-11-19 14:59:41 +00:00
|
|
|
|
2014-11-19 16:04:34 +00:00
|
|
|
SkCanvas* beginRecording(SkScalar width, SkScalar height,
|
2020-08-21 17:42:01 +00:00
|
|
|
SkBBHFactory* bbhFactory = nullptr) {
|
|
|
|
return this->beginRecording(SkRect::MakeWH(width, height), bbhFactory);
|
2014-11-19 16:04:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 18:04:41 +00:00
|
|
|
/** Returns the recording canvas if one is active, or NULL if recording is
|
|
|
|
not active. This does not alter the refcnt on the canvas (if present).
|
|
|
|
*/
|
2014-06-08 12:55:05 +00:00
|
|
|
SkCanvas* getRecordingCanvas();
|
2014-04-18 18:04:41 +00:00
|
|
|
|
2014-11-24 22:41:51 +00:00
|
|
|
/**
|
|
|
|
* Signal that the caller is done recording. This invalidates the canvas returned by
|
|
|
|
* beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who
|
|
|
|
* must call unref() when they are done using it.
|
|
|
|
*
|
|
|
|
* The returned picture is immutable. If during recording drawables were added to the canvas,
|
|
|
|
* these will have been "drawn" into a recording canvas, so that this resulting picture will
|
|
|
|
* reflect their current state, but will not contain a live reference to the drawables
|
|
|
|
* themselves.
|
|
|
|
*/
|
2020-08-21 17:42:01 +00:00
|
|
|
sk_sp<SkPicture> finishRecordingAsPicture();
|
2014-11-24 22:41:51 +00:00
|
|
|
|
2015-07-07 21:27:10 +00:00
|
|
|
/**
|
|
|
|
* Signal that the caller is done recording, and update the cull rect to use for bounding
|
|
|
|
* box hierarchy (BBH) generation. The behavior is the same as calling
|
2017-02-22 18:12:30 +00:00
|
|
|
* finishRecordingAsPicture(), except that this method updates the cull rect initially passed
|
2015-07-07 21:27:10 +00:00
|
|
|
* into beginRecording.
|
|
|
|
* @param cullRect the new culling rectangle to use as the overall bound for BBH generation
|
|
|
|
* and subsequent culling operations.
|
|
|
|
* @return the picture containing the recorded content.
|
|
|
|
*/
|
2020-08-21 17:42:01 +00:00
|
|
|
sk_sp<SkPicture> finishRecordingAsPictureWithCull(const SkRect& cullRect);
|
2015-07-07 21:27:10 +00:00
|
|
|
|
2014-11-24 22:41:51 +00:00
|
|
|
/**
|
|
|
|
* Signal that the caller is done recording. This invalidates the canvas returned by
|
|
|
|
* beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who
|
|
|
|
* must call unref() when they are done using it.
|
|
|
|
*
|
2017-02-22 18:12:30 +00:00
|
|
|
* Unlike finishRecordingAsPicture(), which returns an immutable picture, the returned drawable
|
2014-11-24 22:41:51 +00:00
|
|
|
* may contain live references to other drawables (if they were added to the recording canvas)
|
|
|
|
* and therefore this drawable will reflect the current state of those nested drawables anytime
|
|
|
|
* it is drawn or a new picture is snapped from it (by calling drawable->newPictureSnapshot()).
|
|
|
|
*/
|
2020-08-21 17:42:01 +00:00
|
|
|
sk_sp<SkDrawable> finishRecordingAsDrawable();
|
2014-11-24 22:41:51 +00:00
|
|
|
|
2014-04-18 18:04:41 +00:00
|
|
|
private:
|
2014-06-17 19:08:15 +00:00
|
|
|
void reset();
|
|
|
|
|
2014-05-27 23:41:45 +00:00
|
|
|
/** Replay the current (partially recorded) operation stream into
|
|
|
|
canvas. This call doesn't close the current recording.
|
|
|
|
*/
|
2014-06-17 20:42:59 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
|
|
friend class android::Picture;
|
|
|
|
#endif
|
2014-05-27 23:41:45 +00:00
|
|
|
friend class SkPictureRecorderReplayTester; // for unit testing
|
2014-05-29 15:57:11 +00:00
|
|
|
void partialReplay(SkCanvas* canvas) const;
|
2014-05-27 23:41:45 +00:00
|
|
|
|
2016-11-12 14:06:55 +00:00
|
|
|
bool fActivelyRecording;
|
|
|
|
SkRect fCullRect;
|
|
|
|
sk_sp<SkBBoxHierarchy> fBBH;
|
|
|
|
std::unique_ptr<SkRecorder> fRecorder;
|
|
|
|
sk_sp<SkRecord> fRecord;
|
2019-05-20 12:45:50 +00:00
|
|
|
std::unique_ptr<SkMiniRecorder> fMiniRecorder;
|
2014-04-18 18:04:41 +00:00
|
|
|
|
2019-06-04 13:51:54 +00:00
|
|
|
SkPictureRecorder(SkPictureRecorder&&) = delete;
|
|
|
|
SkPictureRecorder& operator=(SkPictureRecorder&&) = delete;
|
2014-04-18 18:04:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|