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"
13 #include "include/core/SkShader.h" // IWYU pragma: keep
14 #include "include/core/SkTypes.h"
15 
16 #include <atomic>
17 #include <cstddef>
18 #include <cstdint>
19 
20 class SkCanvas;
21 class SkData;
22 class SkMatrix;
23 class SkStream;
24 class SkWStream;
25 enum class SkFilterMode;
26 struct SkDeserialProcs;
27 struct SkSerialProcs;
28 
29 // TODO(kjlubick) Remove this after cleaning up clients
30 #include "include/core/SkTileMode.h" // IWYU pragma: keep
31 
44 class SK_API SkPicture : public SkRefCnt {
45 public:
46  ~SkPicture() override;
47 
62  const SkDeserialProcs* procs = nullptr);
63 
77  static sk_sp<SkPicture> MakeFromData(const SkData* data,
78  const SkDeserialProcs* procs = nullptr);
79 
87  static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
88  const SkDeserialProcs* procs = nullptr);
89 
97  class SK_API AbortCallback {
98  public:
101  virtual ~AbortCallback() = default;
102 
117  virtual bool abort() = 0;
118 
119  protected:
120  AbortCallback() = default;
121  AbortCallback(const AbortCallback&) = delete;
123  };
124 
136  virtual void playback(SkCanvas* canvas, AbortCallback* callback = nullptr) const = 0;
137 
149  virtual SkRect cullRect() const = 0;
150 
155  uint32_t uniqueID() const { return fUniqueID; }
156 
174  sk_sp<SkData> serialize(const SkSerialProcs* procs = nullptr) const;
175 
192  void serialize(SkWStream* stream, const SkSerialProcs* procs = nullptr) const;
193 
207 
219  virtual int approximateOpCount(bool nested = false) const = 0;
220 
228  virtual size_t approximateBytesUsed() const = 0;
229 
244  const SkMatrix* localMatrix, const SkRect* tileRect) const;
245 
247  return this->makeShader(tmx, tmy, mode, nullptr, nullptr);
248  }
249 
250 private:
251  // Allowed subclasses.
252  SkPicture();
253  friend class SkBigPicture;
254  friend class SkEmptyPicture;
255  friend class SkPicturePriv;
256 
257  void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces,
258  bool textBlobsOnly=false) const;
259  static sk_sp<SkPicture> MakeFromStreamPriv(SkStream*, const SkDeserialProcs*,
260  class SkTypefacePlayback*,
261  int recursionLimit);
262  friend class SkPictureData;
263 
272  static bool StreamIsSKP(SkStream*, struct SkPictInfo*);
273  static bool BufferIsSKP(class SkReadBuffer*, struct SkPictInfo*);
274  friend bool SkPicture_StreamIsSKP(SkStream*, struct SkPictInfo*);
275 
276  // Returns NULL if this is not an SkBigPicture.
277  virtual const class SkBigPicture* asSkBigPicture() const { return nullptr; }
278 
279  static bool IsValidPictInfo(const struct SkPictInfo& info);
280  static sk_sp<SkPicture> Forwardport(const struct SkPictInfo&,
281  const class SkPictureData*,
282  class SkReadBuffer* buffer);
283 
284  struct SkPictInfo createHeader() const;
285  class SkPictureData* backport() const;
286 
287  uint32_t fUniqueID;
288  mutable std::atomic<bool> fAddedToCache{false};
289 };
290 
291 #endif
SkFilterMode
Definition: SkSamplingOptions.h:16
SkTileMode
Definition: SkTileMode.h:13
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
SkData holds an immutable data buffer.
Definition: SkData.h:25
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
AbortCallback is an abstract class.
Definition: SkPicture.h:97
virtual bool abort()=0
Stops SkPicture playback when some condition is met.
virtual ~AbortCallback()=default
Has no effect.
AbortCallback & operator=(const AbortCallback &)=delete
AbortCallback(const AbortCallback &)=delete
SkPicture records drawing commands made to SkCanvas.
Definition: SkPicture.h:44
uint32_t uniqueID() const
Returns a non-zero value unique among SkPicture in Skia process.
Definition: SkPicture.h:155
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.
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
Recreates SkPicture that was serialized into a stream.
static sk_sp< SkPicture > MakePlaceholder(SkRect cull)
Returns a placeholder SkPicture.
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode) const
Definition: SkPicture.h:246
virtual SkRect cullRect() const =0
Returns cull SkRect for this picture, passed in when SkPicture was created.
friend bool SkPicture_StreamIsSKP(SkStream *, struct SkPictInfo *)
virtual void playback(SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
Replays the drawing commands on the specified canvas.
virtual size_t approximateBytesUsed() const =0
Returns the approximate byte size of SkPicture.
~SkPicture() override
static sk_sp< SkPicture > MakeFromData(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
Returns storage containing SkData describing SkPicture, using optional custom encoders.
void serialize(SkWStream *stream, const SkSerialProcs *procs=nullptr) const
Writes picture to stream, using optional custom encoders.
virtual int approximateOpCount(bool nested=false) const =0
Returns the approximate number of operations in SkPicture.
static sk_sp< SkPicture > MakeFromData(const SkData *data, const SkDeserialProcs *procs=nullptr)
Recreates SkPicture that was serialized into data.
Definition: SkRefCnt.h:119
SkStream – abstraction for a source of bytes.
Definition: SkStream.h:29
Definition: SkStream.h:218
Definition: SkSerialProcs.h:97
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
Definition: SkSerialProcs.h:86