Skia
2DGraphicsLibrary
 All Classes Namespaces 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 
61  static sk_sp<SkPicture> MakeFromStream(SkStream*, SkImageDeserializer*);
62  static sk_sp<SkPicture> MakeFromStream(SkStream*);
63  static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
64  SkImageDeserializer* = nullptr);
65  static sk_sp<SkPicture> MakeFromData(const SkData* data, SkImageDeserializer* = nullptr);
66 
75  static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer&);
76 
87  class SK_API AbortCallback {
88  public:
89  AbortCallback() {}
90  virtual ~AbortCallback() {}
91  virtual bool abort() = 0;
92  };
93 
101  virtual void playback(SkCanvas*, AbortCallback* = NULL) const = 0;
102 
106  virtual SkRect cullRect() const = 0;
107 
109  uint32_t uniqueID() const;
110 
115  sk_sp<SkData> serialize(SkPixelSerializer* = nullptr) const;
116 
121  void serialize(SkWStream*, SkPixelSerializer* = nullptr) const;
122 
126  void flatten(SkWriteBuffer&) const;
127 
132  virtual bool willPlayBackBitmaps() const = 0;
133 
139  virtual int approximateOpCount() const = 0;
140 
142  virtual size_t approximateBytesUsed() const = 0;
143 
152  static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*);
153  static bool InternalOnly_BufferIsSKP(SkReadBuffer*, SkPictInfo*);
154 
155 #ifdef SK_SUPPORT_LEGACY_PICTURE_GPUVETO
156 
157  bool suitableForGpuRasterization(GrContext*, const char** whyNot = NULL) const;
158 #endif
159 
160  // Sent via SkMessageBus from destructor.
161  struct DeletionMessage { int32_t fUniqueID; }; // TODO: -> uint32_t?
162 
163  // Returns NULL if this is not an SkBigPicture.
164  virtual const SkBigPicture* asSkBigPicture() const { return NULL; }
165 
166  // Global setting to enable or disable security precautions for serialization.
167  static void SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set);
168  static bool PictureIOSecurityPrecautionsEnabled();
169 
170 private:
171  // Subclass whitelist.
172  SkPicture();
173  friend class SkBigPicture;
174  friend class SkEmptyPicture;
175  template <typename> friend class SkMiniPicture;
176 
177  void serialize(SkWStream*, SkPixelSerializer*, SkRefCntSet* typefaces) const;
178  static sk_sp<SkPicture> MakeFromStream(SkStream*, SkImageDeserializer*, SkTypefacePlayback*);
179  friend class SkPictureData;
180 
181  virtual int numSlowPaths() const = 0;
182  friend class SkPictureGpuAnalyzer;
183  friend struct SkPathCounter;
184 
185  // V35: Store SkRect (rather then width & height) in header
186  // V36: Remove (obsolete) alphatype from SkColorTable
187  // V37: Added shadow only option to SkDropShadowImageFilter (last version to record CLEAR)
188  // V38: Added PictureResolution option to SkPictureImageFilter
189  // V39: Added FilterLevel option to SkPictureImageFilter
190  // V40: Remove UniqueID serialization from SkImageFilter.
191  // V41: Added serialization of SkBitmapSource's filterQuality parameter
192  // V42: Added a bool to SkPictureShader serialization to indicate did-we-serialize-a-picture?
193  // V43: Added DRAW_IMAGE and DRAW_IMAGE_RECT opt codes to serialized data
194  // V44: Move annotations from paint to drawAnnotation
195  // V45: Add invNormRotation to SkLightingShader.
196  // V46: Add drawTextRSXform
197  // V47: Add occluder rect to SkBlurMaskFilter
198  // V48: Read and write extended SkTextBlobs.
199  // V49: Gradients serialized as SkColor4f + SkColorSpace
200  // V50: SkXfermode -> SkBlendMode
201  // V51: more SkXfermode -> SkBlendMode
202  // V52: Remove SkTextBlob::fRunCount
203  // V53: SaveLayerRec clip mask
204  // V54: ComposeShader can use a Mode or a Lerp
205  // V55: Drop blendmode[] from MergeImageFilter
206 
207  // Only SKPs within the min/current picture version range (inclusive) can be read.
208  static const uint32_t MIN_PICTURE_VERSION = 51; // Produced by Chrome ~M56.
209  static const uint32_t CURRENT_PICTURE_VERSION = 55;
210 
211  static bool IsValidPictInfo(const SkPictInfo& info);
212  static sk_sp<SkPicture> Forwardport(const SkPictInfo&,
213  const SkPictureData*,
214  SkReadBuffer* buffer);
215 
216  SkPictInfo createHeader() const;
217  SkPictureData* backport() const;
218 
219  mutable uint32_t fUniqueID;
220 };
221 
222 #endif
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:59
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:25
Definition: SkRefCnt.h:125
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:87
Definition: SkPicture.h:161
SkData holds an immutable data buffer.
Definition: SkData.h:22
The SkBitmap class specifies a raster bitmap.
Definition: SkBitmap.h:37
Definition: GrContext.h:47
Interface for serializing pixels, e.g.
Definition: SkPixelSerializer.h:19
SkStream – abstraction for a source of bytes.
Definition: SkStream.h:40
Definition: SkStream.h:182
Definition: SkWriteBuffer.h:27
Definition: SkRect.h:404
Definition: SkImageDeserializer.h:17
SkImage is an abstraction for drawing a rectagle of pixels, though the particular type of image could...
Definition: SkImage.h:48
Gathers GPU-related statistics for one or more SkPictures.
Definition: SkPictureAnalyzer.h:26