Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPictureRecorder.h
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkPictureRecorder_DEFINED
9 #define SkPictureRecorder_DEFINED
10 
11 #include "../private/SkMiniRecorder.h"
12 #include "SkBBHFactory.h"
13 #include "SkPicture.h"
14 #include "SkRefCnt.h"
15 
16 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
17 namespace android {
18  class Picture;
19 };
20 #endif
21 
22 class GrContext;
23 class SkCanvas;
24 class SkDrawable;
25 class SkPictureRecord;
26 class SkRecord;
27 class SkRecorder;
28 
29 class SK_API SkPictureRecorder : SkNoncopyable {
30 public:
33 
34  enum RecordFlags {
35  // If you call drawPicture() or drawDrawable() on the recording canvas, this flag forces
36  // that object to playback its contents immediately rather than reffing the object.
37  kPlaybackDrawPicture_RecordFlag = 1 << 0,
38  };
39 
40  enum FinishFlags {
41  kReturnNullForEmpty_FinishFlag = 1 << 0, // no draw-ops will return nullptr
42  };
43 
51  SkCanvas* beginRecording(const SkRect& bounds,
52  SkBBHFactory* bbhFactory = NULL,
53  uint32_t recordFlags = 0);
54 
55  SkCanvas* beginRecording(SkScalar width, SkScalar height,
56  SkBBHFactory* bbhFactory = NULL,
57  uint32_t recordFlags = 0) {
58  return this->beginRecording(SkRect::MakeWH(width, height), bbhFactory, recordFlags);
59  }
60 
64  SkCanvas* getRecordingCanvas();
65 
76  sk_sp<SkPicture> finishRecordingAsPicture(uint32_t endFlags = 0);
77 
87  sk_sp<SkPicture> finishRecordingAsPictureWithCull(const SkRect& cullRect,
88  uint32_t endFlags = 0);
89 
100  sk_sp<SkDrawable> finishRecordingAsDrawable(uint32_t endFlags = 0);
101 
102 #ifdef SK_SUPPORT_LEGACY_PICTURE_PTR
103  SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture() {
104  return this->finishRecordingAsPicture().release();
105  }
106  SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture(const SkRect& cullRect) {
107  return this->finishRecordingAsPictureWithCull(cullRect).release();
108  }
109  SkDrawable* SK_WARN_UNUSED_RESULT endRecordingAsDrawable() {
110  return this->finishRecordingAsDrawable().release();
111  }
112  SkPicture* SK_WARN_UNUSED_RESULT endRecording() { return this->endRecordingAsPicture(); }
113 #endif
114 
115  // Strawman API.
116  void optimizeFor(GrContext* ctx) { fGrContextToOptimizeFor = ctx; }
117 
118 private:
119  void reset();
120 
124 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
125  friend class android::Picture;
126 #endif
127  friend class SkPictureRecorderReplayTester; // for unit testing
128  void partialReplay(SkCanvas* canvas) const;
129 
130  bool fActivelyRecording;
131  uint32_t fFlags;
132  SkRect fCullRect;
134  SkAutoTUnref<SkRecorder> fRecorder;
135  SkAutoTUnref<SkRecord> fRecord;
136  SkMiniRecorder fMiniRecorder;
137 
138  GrContext* fGrContextToOptimizeFor = nullptr;
139 
140  typedef SkNoncopyable INHERITED;
141 };
142 
143 #endif
T *SK_WARN_UNUSED_RESULT release()
Return the bare pointer, and set the internal object pointer to nullptr.
Definition: SkRefCnt.h:363
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
Definition: SkBBHFactory.h:15
An SkPicture records drawing commands made to a canvas to be played back at a later time...
Definition: SkPicture.h:38
Definition: GrContext.h:48
Base-class for objects that draw into SkCanvas.
Definition: SkDrawable.h:25
Definition: SkRect.h:390
Definition: SkPictureRecorder.h:29