Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPicture.h
1 /*
2  * Copyright 2007 The Android Open Source Project
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 SkPicture_DEFINED
9 #define SkPicture_DEFINED
10 
11 #include "SkRefCnt.h"
12 #include "SkRect.h"
13 #include "SkTypes.h"
14 
15 class GrContext;
16 class SkBigPicture;
17 class SkBitmap;
18 class SkCanvas;
19 class SkData;
20 class SkImage;
22 class SkPath;
23 class SkPictureData;
24 class SkPixelSerializer;
25 class SkReadBuffer;
26 class SkRefCntSet;
27 class SkStream;
28 class SkTypefacePlayback;
29 class SkWStream;
30 class SkWriteBuffer;
31 struct SkPictInfo;
32 
38 class SK_API SkPicture : public SkRefCnt {
39 public:
40  virtual ~SkPicture();
41 
53  typedef bool (*InstallPixelRefProc)(const void* src, size_t length, SkBitmap* dst);
54 
55 #ifdef SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF
56 
64  static sk_sp<SkPicture> MakeFromStream(SkStream*, InstallPixelRefProc proc);
65  static sk_sp<SkPicture> MakeFromStream(SkStream* stream, std::nullptr_t) {
66  return MakeFromStream(stream);
67  }
68 #endif
69 
76  static sk_sp<SkPicture> MakeFromStream(SkStream*, SkImageDeserializer*);
77  static sk_sp<SkPicture> MakeFromStream(SkStream*);
78 
87  static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer&);
88 
99  class SK_API AbortCallback {
100  public:
101  AbortCallback() {}
102  virtual ~AbortCallback() {}
103  virtual bool abort() = 0;
104  };
105 
113  virtual void playback(SkCanvas*, AbortCallback* = NULL) const = 0;
114 
118  virtual SkRect cullRect() const = 0;
119 
121  uint32_t uniqueID() const;
122 
127  void serialize(SkWStream*, SkPixelSerializer* = NULL) const;
128 
132  void flatten(SkWriteBuffer&) const;
133 
138  virtual bool willPlayBackBitmaps() const = 0;
139 
145  virtual int approximateOpCount() const = 0;
146 
148  virtual size_t approximateBytesUsed() const = 0;
149 
158  static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*);
159  static bool InternalOnly_BufferIsSKP(SkReadBuffer*, SkPictInfo*);
160 
161 #ifdef SK_SUPPORT_LEGACY_PICTURE_GPUVETO
162 
163  bool suitableForGpuRasterization(GrContext*, const char** whyNot = NULL) const;
164 #endif
165 
166  // Sent via SkMessageBus from destructor.
167  struct DeletionMessage { int32_t fUniqueID; }; // TODO: -> uint32_t?
168 
169  // Returns NULL if this is not an SkBigPicture.
170  virtual const SkBigPicture* asSkBigPicture() const { return NULL; }
171 
172  // Global setting to enable or disable security precautions for serialization.
173  static void SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set);
174  static bool PictureIOSecurityPrecautionsEnabled();
175 
176 #ifdef SK_SUPPORT_LEGACY_PICTURE_PTR
177  static SkPicture* CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
178  return MakeFromStream(stream, proc).release();
179  }
180  static SkPicture* CreateFromStream(SkStream* stream) {
181  return MakeFromStream(stream).release();
182  }
183  static SkPicture* CreateFromBuffer(SkReadBuffer& rbuf) {
184  return MakeFromBuffer(rbuf).release();
185  }
186 #endif
187 
188 private:
189  // Subclass whitelist.
190  SkPicture();
191  friend class SkBigPicture;
192  friend class SkEmptyPicture;
193  template <typename> friend class SkMiniPicture;
194 
195  void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet* typefaces) const;
196  static sk_sp<SkPicture> MakeFromStream(SkStream*, SkImageDeserializer*, SkTypefacePlayback*);
197  friend class SkPictureData;
198 
199  virtual int numSlowPaths() const = 0;
200  friend class SkPictureGpuAnalyzer;
201  friend struct SkPathCounter;
202 
203  // V35: Store SkRect (rather then width & height) in header
204  // V36: Remove (obsolete) alphatype from SkColorTable
205  // V37: Added shadow only option to SkDropShadowImageFilter (last version to record CLEAR)
206  // V38: Added PictureResolution option to SkPictureImageFilter
207  // V39: Added FilterLevel option to SkPictureImageFilter
208  // V40: Remove UniqueID serialization from SkImageFilter.
209  // V41: Added serialization of SkBitmapSource's filterQuality parameter
210  // V42: Added a bool to SkPictureShader serialization to indicate did-we-serialize-a-picture?
211  // V43: Added DRAW_IMAGE and DRAW_IMAGE_RECT opt codes to serialized data
212  // V44: Move annotations from paint to drawAnnotation
213  // V45: Add invNormRotation to SkLightingShader.
214  // V46: Add drawTextRSXform
215  // V47: Add occluder rect to SkBlurMaskFilter
216 
217  // Only SKPs within the min/current picture version range (inclusive) can be read.
218  static const uint32_t MIN_PICTURE_VERSION = 35; // Produced by Chrome M39.
219  static const uint32_t CURRENT_PICTURE_VERSION = 47;
220 
221  static_assert(MIN_PICTURE_VERSION <= 41,
222  "Remove kFontFileName and related code from SkFontDescriptor.cpp.");
223 
224  static_assert(MIN_PICTURE_VERSION <= 42,
225  "Remove COMMENT API handlers from SkPicturePlayback.cpp");
226 
227  static_assert(MIN_PICTURE_VERSION <= 43,
228  "Remove SkBitmapSourceDeserializer.");
229 
230  static_assert(MIN_PICTURE_VERSION <= 45,
231  "Remove decoding of old SkTypeface::Style from SkFontDescriptor.cpp.");
232 
233  static bool IsValidPictInfo(const SkPictInfo& info);
234  static sk_sp<SkPicture> Forwardport(const SkPictInfo&,
235  const SkPictureData*,
236  const SkReadBuffer* buffer);
237 
238  SkPictInfo createHeader() const;
239  SkPictureData* backport() const;
240 
241  mutable uint32_t fUniqueID;
242 };
243 
244 #endif
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:27
Definition: SkRefCnt.h:135
An SkPicture records drawing commands made to a canvas to be played back at a later time...
Definition: SkPicture.h:38
Subclasses of this can be passed to playback().
Definition: SkPicture.h:99
Definition: SkPicture.h:167
SkData holds an immutable data buffer.
Definition: SkData.h:22
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:41
Definition: GrContext.h:48
Interface for serializing pixels, e.g.
Definition: SkPixelSerializer.h:19
SkStream – abstraction for a source of bytes.
Definition: SkStream.h:38
Definition: SkStream.h:182
Definition: SkWriteBuffer.h:26
Definition: SkRect.h:390
Definition: SkImageDeserializer.h:17
SkImage is an abstraction for drawing a rectagle of pixels, though the particular type of image could...
Definition: SkImage.h:45
Gathers GPU-related statistics for one or more SkPictures.
Definition: SkPictureAnalyzer.h:25