Skia
2D Graphics Library
SkPicture.h
Go to the documentation of this file.
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 "include/core/SkRect.h"
12 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkTypes.h"
16 
17 class SkCanvas;
18 class SkData;
19 struct SkDeserialProcs;
20 class SkImage;
21 class SkMatrix;
22 struct SkSerialProcs;
23 class SkShader;
24 class SkStream;
25 class SkWStream;
26 
39 class SK_API SkPicture : public SkRefCnt {
40 public:
41 
56  const SkDeserialProcs* procs = nullptr);
57 
71  static sk_sp<SkPicture> MakeFromData(const SkData* data,
72  const SkDeserialProcs* procs = nullptr);
73 
81  static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
82  const SkDeserialProcs* procs = nullptr);
83 
92  public:
93 
99 
102  virtual ~AbortCallback() {}
103 
118  virtual bool abort() = 0;
119  };
120 
132  virtual void playback(SkCanvas* canvas, AbortCallback* callback = nullptr) const = 0;
133 
145  virtual SkRect cullRect() const = 0;
146 
151  uint32_t uniqueID() const { return fUniqueID; }
152 
166  sk_sp<SkData> serialize(const SkSerialProcs* procs = nullptr) const;
167 
180  void serialize(SkWStream* stream, const SkSerialProcs* procs = nullptr) const;
181 
195 
207  virtual int approximateOpCount(bool nested = false) const = 0;
208 
216  virtual size_t approximateBytesUsed() const = 0;
217 
232  const SkMatrix* localMatrix, const SkRect* tileRect) const;
233 
234  // DEPRECATED
236  const SkMatrix* localMatrix, const SkRect* tileRect) const;
238  const SkMatrix* localMatrix = nullptr) const;
239 
240 private:
241  // Allowed subclasses.
242  SkPicture();
243  friend class SkBigPicture;
244  friend class SkEmptyPicture;
245  friend class SkPicturePriv;
246  template <typename> friend class SkMiniPicture;
247 
248  void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces,
249  bool textBlobsOnly=false) const;
250  static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs*,
251  class SkTypefacePlayback*);
252  friend class SkPictureData;
253 
262  static bool StreamIsSKP(SkStream*, struct SkPictInfo*);
263  static bool BufferIsSKP(class SkReadBuffer*, struct SkPictInfo*);
264  friend bool SkPicture_StreamIsSKP(SkStream*, struct SkPictInfo*);
265 
266  // Returns NULL if this is not an SkBigPicture.
267  virtual const class SkBigPicture* asSkBigPicture() const { return nullptr; }
268 
269  friend struct SkPathCounter;
270 
271  static bool IsValidPictInfo(const struct SkPictInfo& info);
272  static sk_sp<SkPicture> Forwardport(const struct SkPictInfo&,
273  const class SkPictureData*,
274  class SkReadBuffer* buffer);
275 
276  struct SkPictInfo createHeader() const;
277  class SkPictureData* backport() const;
278 
279  uint32_t fUniqueID;
280 };
281 
282 #endif
SkImage
Definition: SkImage.h:58
SkRefCnt
Definition: SkRefCnt.h:118
SkTypes.h
SkPicture::AbortCallback::AbortCallback
AbortCallback()
Has no effect.
Definition: SkPicture.h:98
SkRect.h
SkPicture::makeShader
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix *localMatrix=nullptr) const
SkShader
Definition: SkShader.h:39
SkData
SkData holds an immutable data buffer.
Definition: SkData.h:22
SkStream
SkStream – abstraction for a source of bytes.
Definition: SkStream.h:41
SkRefCnt.h
SkFilterMode
SkFilterMode
Definition: SkSamplingOptions.h:14
SkPicture::playback
virtual void playback(SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
Replays the drawing commands on the specified canvas.
SkTileMode
SkTileMode
Definition: SkTileMode.h:13
sk_sp< SkPicture >
SkPicture::MakeFromData
static sk_sp< SkPicture > MakeFromData(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
SkPicture::AbortCallback::~AbortCallback
virtual ~AbortCallback()
Has no effect.
Definition: SkPicture.h:102
SkPicture::SkPicture_StreamIsSKP
friend bool SkPicture_StreamIsSKP(SkStream *, struct SkPictInfo *)
SK_API
#define SK_API
Definition: SkTypes.h:181
SkCanvas
Definition: SkCanvas.h:90
SkPicture
Definition: SkPicture.h:39
SkPicture::serialize
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
Returns storage containing SkData describing SkPicture, using optional custom encoders.
SkPicture::approximateBytesUsed
virtual size_t approximateBytesUsed() const =0
Returns the approximate byte size of SkPicture.
SkPicture::serialize
void serialize(SkWStream *stream, const SkSerialProcs *procs=nullptr) const
Writes picture to stream, using optional custom encoders.
SkPicture::MakeFromStream
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
Recreates SkPicture that was serialized into a stream.
SkPicture::makeShader
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
Return a new shader that will draw with this picture.
SkPicture::uniqueID
uint32_t uniqueID() const
Returns a non-zero value unique among SkPicture in Skia process.
Definition: SkPicture.h:151
SkPicture::approximateOpCount
virtual int approximateOpCount(bool nested=false) const =0
Returns the approximate number of operations in SkPicture.
SkPicture::MakeFromData
static sk_sp< SkPicture > MakeFromData(const SkData *data, const SkDeserialProcs *procs=nullptr)
Recreates SkPicture that was serialized into data.
SkMatrix
Definition: SkMatrix.h:48
SkTileMode.h
SkPicture::AbortCallback
Definition: SkPicture.h:91
SkPicture::makeShader
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkMatrix *localMatrix, const SkRect *tileRect) const
SkSerialProcs
Definition: SkSerialProcs.h:50
SkWStream
Definition: SkStream.h:227
SkRect
Definition: SkRect.h:572
SkDeserialProcs
Definition: SkSerialProcs.h:61
SkPicture::AbortCallback::abort
virtual bool abort()=0
Stops SkPicture playback when some condition is met.
SkPicture::cullRect
virtual SkRect cullRect() const =0
Returns cull SkRect for this picture, passed in when SkPicture was created.
SkPicture::MakePlaceholder
static sk_sp< SkPicture > MakePlaceholder(SkRect cull)
Returns a placeholder SkPicture.
SkSamplingOptions.h