2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2007 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/* Generated by tools/bookmaker from include/core/SkPicture.h and docs/SkPicture_Reference.bmh
|
|
|
|
on 2018-07-13 08:15:11. Additional documentation and examples can be found at:
|
|
|
|
https://skia.org/user/api/SkPicture_Reference
|
|
|
|
|
|
|
|
You may edit either file directly. Structural changes to public interfaces require
|
|
|
|
editing both files. After editing docs/SkPicture_Reference.bmh, run:
|
|
|
|
bookmaker -b docs -i include/core/SkPicture.h -p
|
|
|
|
to create an updated version of this file.
|
|
|
|
*/
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkPicture_DEFINED
|
|
|
|
#define SkPicture_DEFINED
|
|
|
|
|
|
|
|
#include "SkRefCnt.h"
|
2016-03-24 17:41:47 +00:00
|
|
|
#include "SkRect.h"
|
2015-05-19 18:11:26 +00:00
|
|
|
#include "SkTypes.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
2016-08-11 10:55:15 +00:00
|
|
|
class SkData;
|
2017-12-05 20:11:24 +00:00
|
|
|
struct SkDeserialProcs;
|
2016-08-11 10:55:15 +00:00
|
|
|
class SkImage;
|
2017-12-05 20:11:24 +00:00
|
|
|
struct SkSerialProcs;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkStream;
|
|
|
|
class SkWStream;
|
2013-06-28 21:32:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \class SkPicture
|
2015-05-19 18:11:26 +00:00
|
|
|
An SkPicture records drawing commands made to a canvas to be played back at a later time.
|
|
|
|
This base class handles serialization and a few other miscellany.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2015-05-20 17:55:49 +00:00
|
|
|
class SK_API SkPicture : public SkRefCnt {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2017-12-15 20:42:14 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Recreates a picture that was serialized into a stream.
|
|
|
|
|
|
|
|
@param stream container for serial data
|
|
|
|
@param procs custom serial data decoders; may be nullptr
|
|
|
|
@return SkPicture constructed from stream data
|
|
|
|
*/
|
2018-06-11 20:25:43 +00:00
|
|
|
static sk_sp<SkPicture> MakeFromStream(SkStream* stream,
|
|
|
|
const SkDeserialProcs* procs = nullptr);
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Recreates a picture that was serialized into data.
|
|
|
|
|
|
|
|
@param data container for serial data
|
|
|
|
@param procs custom serial data decoders; may be nullptr
|
|
|
|
@return SkPicture constructed from data
|
|
|
|
*/
|
2018-06-11 20:25:43 +00:00
|
|
|
static sk_sp<SkPicture> MakeFromData(const SkData* data,
|
|
|
|
const SkDeserialProcs* procs = nullptr);
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
@param data pointer to serial data
|
|
|
|
@param size size of data
|
|
|
|
@param procs custom serial data decoders; may be nullptr
|
|
|
|
@return SkPicture constructed from data
|
|
|
|
*/
|
2017-12-20 19:12:07 +00:00
|
|
|
static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
|
2018-06-11 20:25:43 +00:00
|
|
|
const SkDeserialProcs* procs = nullptr);
|
2014-02-07 12:20:04 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** \class SkPicture::AbortCallback
|
|
|
|
Subclasses of this can be passed to playback(). During the playback
|
|
|
|
of the picture, this callback will periodically be invoked. If its
|
|
|
|
abort() returns true, then picture playback will be interrupted.
|
|
|
|
The resulting drawing is undefined, as there is no guarantee how often the
|
|
|
|
callback will be invoked. If the abort happens inside some level of nested
|
|
|
|
calls to save(), restore will automatically be called to return the state
|
|
|
|
to the same level it was before the playback call was made.
|
2015-01-07 15:28:41 +00:00
|
|
|
*/
|
|
|
|
class SK_API AbortCallback {
|
|
|
|
public:
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Has no effect.
|
|
|
|
|
|
|
|
@return abstract class cannot be instantiated
|
|
|
|
*/
|
2015-01-07 15:28:41 +00:00
|
|
|
AbortCallback() {}
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Has no effect.
|
|
|
|
*/
|
2015-01-07 15:28:41 +00:00
|
|
|
virtual ~AbortCallback() {}
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Stops SkPicture playback when some condition is met. A subclass of
|
|
|
|
AbortCallback provides an override for abort() that can stop playback() from
|
|
|
|
drawing the entire picture.
|
|
|
|
|
|
|
|
@return true to stop playback
|
|
|
|
*/
|
2015-01-07 15:28:41 +00:00
|
|
|
virtual bool abort() = 0;
|
|
|
|
};
|
|
|
|
|
2014-09-04 15:42:50 +00:00
|
|
|
/** Replays the drawing commands on the specified canvas. Note that
|
|
|
|
this has the effect of unfurling this picture into the destination
|
|
|
|
canvas. Using the SkCanvas::drawPicture entry point gives the destination
|
|
|
|
canvas the option of just taking a ref.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@param canvas receiver of drawing commands
|
|
|
|
@param callback allows interruption of playback
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2018-06-11 20:25:43 +00:00
|
|
|
virtual void playback(SkCanvas* canvas, AbortCallback* callback = nullptr) const = 0;
|
2015-05-18 20:47:17 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns cull SkRect for this picture.
|
2015-05-19 18:11:26 +00:00
|
|
|
Ops recorded into this picture that attempt to draw outside the cull might not be drawn.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@return bounds passed when SkPicture was created
|
|
|
|
*/
|
2015-05-19 18:11:26 +00:00
|
|
|
virtual SkRect cullRect() const = 0;
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns a non-zero value unique among all pictures.
|
|
|
|
|
|
|
|
@return identifier for SkPicture
|
|
|
|
*/
|
2015-04-07 13:34:05 +00:00
|
|
|
uint32_t uniqueID() const;
|
2014-04-02 23:51:13 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns storage containing data describing SkPicture, using optional custom encoders.
|
|
|
|
|
|
|
|
@param procs custom serial data encoders; may be nullptr
|
|
|
|
@return storage containing serialized SkPicture
|
|
|
|
*/
|
2018-06-11 20:25:43 +00:00
|
|
|
sk_sp<SkData> serialize(const SkSerialProcs* procs = nullptr) const;
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
/** Writes picture to stream, using optional custom encoders.
|
|
|
|
|
|
|
|
@param stream writable serial data stream
|
|
|
|
@param procs custom serial data encoders; may be nullptr
|
|
|
|
*/
|
2018-06-11 20:25:43 +00:00
|
|
|
void serialize(SkWStream* stream, const SkSerialProcs* procs = nullptr) const;
|
2017-12-20 19:12:07 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns a placeholder SkPicture.
|
|
|
|
This placeholder does not draw anything itself. It has a distinct uniqueID()
|
|
|
|
(just like all SkPicture) and will always be visible to SkSerialProcs.
|
|
|
|
|
|
|
|
@param cull placeholder dimensions
|
|
|
|
@return placeholder with unique identifier
|
|
|
|
*/
|
2018-01-26 14:49:48 +00:00
|
|
|
static sk_sp<SkPicture> MakePlaceholder(SkRect cull);
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns the approximate number of operations in this picture. This
|
|
|
|
number may be greater or less than the number of SkCanvas calls
|
|
|
|
recorded: some calls may be recorded as more than one operation, or some
|
|
|
|
calls may be optimized away.
|
|
|
|
|
|
|
|
@return approximate operation count
|
|
|
|
*/
|
2018-01-27 17:30:04 +00:00
|
|
|
virtual int approximateOpCount() const = 0;
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns the approximate byte size of SkPicture. Does not include large objects
|
|
|
|
referenced SkPicture.
|
|
|
|
|
|
|
|
@return approximate size
|
|
|
|
*/
|
2017-12-25 00:50:57 +00:00
|
|
|
virtual size_t approximateBytesUsed() const = 0;
|
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
private:
|
|
|
|
// Subclass whitelist.
|
|
|
|
SkPicture();
|
|
|
|
friend class SkBigPicture;
|
|
|
|
friend class SkEmptyPicture;
|
2018-06-11 20:25:43 +00:00
|
|
|
friend class SkPicturePriv;
|
2015-05-19 18:11:26 +00:00
|
|
|
template <typename> friend class SkMiniPicture;
|
Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (patchset #25 id:480001 of https://codereview.chromium.org/1112523006/)
Reason for revert:
win_chromium_compile_dbg_ng
FAILED: ninja -t msvc -e environment.x86 -- E:\b\build\goma/gomacc "E:\b\depot_tools\win_toolchain\vs2013_files\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\third_party\skia\src\core\skia.SkBitmapHeap.obj.rsp /c ..\..\third_party\skia\src\core\SkBitmapHeap.cpp /Foobj\third_party\skia\src\core\skia.SkBitmapHeap.obj /Fdobj\skia\skia.cc.pdb
e:\b\build\slave\win\build\src\third_party\skia\include\core\skpicture.h(176) : error C2487: 'CURRENT_PICTURE_VERSION' : member of dll interface class may not be declared with dll interface
Original issue's description:
> Sketch splitting SkPicture into an interface and SkBigPicture.
>
> Adds small pictures for drawRect(), drawTextBlob(), and drawPath().
> These cover about 89% of draw calls from Blink SKPs,
> and about 25% of draw calls from our GMs.
>
> SkPicture handles:
> - serialization and deserialization
> - unique IDs
>
> Everything else is left to the subclasses:
> - playback(), cullRect()
> - hasBitmap(), hasText(), suitableForGPU(), etc.
> - LayerInfo / AccelData if applicable.
>
> The time to record a 1-op picture improves a good chunk
> (2 mallocs to 1), and the time to record a 0-op picture
> greatly improves (2 mallocs to none):
>
> picture_overhead_draw: 450ns -> 350ns
> picture_overhead_nodraw: 300ns -> 90ns
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/c92c129ff85b05a714bd1bf921c02d5e14651f8b
>
> Latest blink_linux_rel:
>
> http://build.chromium.org/p/tryserver.blink/builders/linux_blink_rel/builds/61248
>
> Committed: https://skia.googlesource.com/skia/+/15877b6eae33a9282458bdb904a6d00440eca0ec
TBR=reed@google.com,robertphillips@google.com,fmalita@chromium.org,mtklein@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1130283004
2015-05-18 21:53:43 +00:00
|
|
|
|
2018-06-11 20:25:43 +00:00
|
|
|
void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces) const;
|
|
|
|
static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs*,
|
|
|
|
class SkTypefacePlayback*);
|
2015-08-18 15:29:59 +00:00
|
|
|
friend class SkPictureData;
|
|
|
|
|
2017-12-20 19:09:20 +00:00
|
|
|
/** Return true if the SkStream/Buffer represents a serialized picture, and
|
|
|
|
fills out SkPictInfo. After this function returns, the data source is not
|
|
|
|
rewound so it will have to be manually reset before passing to
|
2018-01-26 14:49:48 +00:00
|
|
|
MakeFromStream or MakeFromBuffer. Note, MakeFromStream and
|
|
|
|
MakeFromBuffer perform this check internally so these entry points are
|
2017-12-20 19:09:20 +00:00
|
|
|
intended for stand alone tools.
|
|
|
|
If false is returned, SkPictInfo is unmodified.
|
|
|
|
*/
|
2018-06-11 20:25:43 +00:00
|
|
|
static bool StreamIsSKP(SkStream*, struct SkPictInfo*);
|
|
|
|
static bool BufferIsSKP(class SkReadBuffer*, struct SkPictInfo*);
|
|
|
|
friend bool SkPicture_StreamIsSKP(SkStream*, struct SkPictInfo*);
|
|
|
|
|
|
|
|
// Returns NULL if this is not an SkBigPicture.
|
|
|
|
virtual const class SkBigPicture* asSkBigPicture() const { return nullptr; }
|
2017-12-20 19:09:20 +00:00
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
friend struct SkPathCounter;
|
Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (patchset #25 id:480001 of https://codereview.chromium.org/1112523006/)
Reason for revert:
win_chromium_compile_dbg_ng
FAILED: ninja -t msvc -e environment.x86 -- E:\b\build\goma/gomacc "E:\b\depot_tools\win_toolchain\vs2013_files\VC\bin\amd64_x86\cl.exe" /nologo /showIncludes /FC @obj\third_party\skia\src\core\skia.SkBitmapHeap.obj.rsp /c ..\..\third_party\skia\src\core\SkBitmapHeap.cpp /Foobj\third_party\skia\src\core\skia.SkBitmapHeap.obj /Fdobj\skia\skia.cc.pdb
e:\b\build\slave\win\build\src\third_party\skia\include\core\skpicture.h(176) : error C2487: 'CURRENT_PICTURE_VERSION' : member of dll interface class may not be declared with dll interface
Original issue's description:
> Sketch splitting SkPicture into an interface and SkBigPicture.
>
> Adds small pictures for drawRect(), drawTextBlob(), and drawPath().
> These cover about 89% of draw calls from Blink SKPs,
> and about 25% of draw calls from our GMs.
>
> SkPicture handles:
> - serialization and deserialization
> - unique IDs
>
> Everything else is left to the subclasses:
> - playback(), cullRect()
> - hasBitmap(), hasText(), suitableForGPU(), etc.
> - LayerInfo / AccelData if applicable.
>
> The time to record a 1-op picture improves a good chunk
> (2 mallocs to 1), and the time to record a 0-op picture
> greatly improves (2 mallocs to none):
>
> picture_overhead_draw: 450ns -> 350ns
> picture_overhead_nodraw: 300ns -> 90ns
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/c92c129ff85b05a714bd1bf921c02d5e14651f8b
>
> Latest blink_linux_rel:
>
> http://build.chromium.org/p/tryserver.blink/builders/linux_blink_rel/builds/61248
>
> Committed: https://skia.googlesource.com/skia/+/15877b6eae33a9282458bdb904a6d00440eca0ec
TBR=reed@google.com,robertphillips@google.com,fmalita@chromium.org,mtklein@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1130283004
2015-05-18 21:53:43 +00:00
|
|
|
|
2014-08-29 15:03:56 +00:00
|
|
|
// V35: Store SkRect (rather then width & height) in header
|
2014-09-29 19:10:27 +00:00
|
|
|
// V36: Remove (obsolete) alphatype from SkColorTable
|
2014-12-04 15:50:14 +00:00
|
|
|
// V37: Added shadow only option to SkDropShadowImageFilter (last version to record CLEAR)
|
2014-12-09 21:07:22 +00:00
|
|
|
// V38: Added PictureResolution option to SkPictureImageFilter
|
|
|
|
// V39: Added FilterLevel option to SkPictureImageFilter
|
2015-03-18 20:14:54 +00:00
|
|
|
// V40: Remove UniqueID serialization from SkImageFilter.
|
2015-04-10 15:39:58 +00:00
|
|
|
// V41: Added serialization of SkBitmapSource's filterQuality parameter
|
2015-05-20 19:05:15 +00:00
|
|
|
// V42: Added a bool to SkPictureShader serialization to indicate did-we-serialize-a-picture?
|
2015-06-22 19:48:26 +00:00
|
|
|
// V43: Added DRAW_IMAGE and DRAW_IMAGE_RECT opt codes to serialized data
|
2016-03-05 00:36:20 +00:00
|
|
|
// V44: Move annotations from paint to drawAnnotation
|
2016-04-08 19:19:50 +00:00
|
|
|
// V45: Add invNormRotation to SkLightingShader.
|
2016-07-07 19:47:17 +00:00
|
|
|
// V46: Add drawTextRSXform
|
2016-08-10 23:25:25 +00:00
|
|
|
// V47: Add occluder rect to SkBlurMaskFilter
|
2016-08-30 18:58:33 +00:00
|
|
|
// V48: Read and write extended SkTextBlobs.
|
2016-09-28 18:27:28 +00:00
|
|
|
// V49: Gradients serialized as SkColor4f + SkColorSpace
|
2016-10-06 00:33:02 +00:00
|
|
|
// V50: SkXfermode -> SkBlendMode
|
2016-10-28 19:42:34 +00:00
|
|
|
// V51: more SkXfermode -> SkBlendMode
|
2017-03-13 13:03:24 +00:00
|
|
|
// V52: Remove SkTextBlob::fRunCount
|
2017-04-28 17:48:37 +00:00
|
|
|
// V53: SaveLayerRec clip mask
|
2017-06-09 14:51:52 +00:00
|
|
|
// V54: ComposeShader can use a Mode or a Lerp
|
2017-06-19 03:35:57 +00:00
|
|
|
// V55: Drop blendmode[] from MergeImageFilter
|
2017-07-11 03:20:33 +00:00
|
|
|
// V56: Add TileMode in SkBlurImageFilter.
|
2017-08-01 20:38:08 +00:00
|
|
|
// V57: Sweep tiling info.
|
2017-10-18 20:22:35 +00:00
|
|
|
// V58: No more 2pt conical flipping.
|
2017-11-09 21:50:20 +00:00
|
|
|
// V59: No more LocalSpace option on PictureImageFilter
|
2018-01-03 16:32:13 +00:00
|
|
|
// V60: Remove flags in picture header
|
2018-01-18 20:19:13 +00:00
|
|
|
// V61: Change SkDrawPictureRec to take two colors rather than two alphas
|
2018-03-08 21:29:12 +00:00
|
|
|
// V62: Don't negate size of custom encoded images (don't write origin x,y either)
|
2018-05-29 19:41:27 +00:00
|
|
|
// V63: Store image bounds (including origin) instead of just width/height to support subsets
|
2014-02-18 22:08:16 +00:00
|
|
|
|
2014-02-25 02:16:10 +00:00
|
|
|
// Only SKPs within the min/current picture version range (inclusive) can be read.
|
2018-01-03 18:17:18 +00:00
|
|
|
static const uint32_t MIN_PICTURE_VERSION = 56; // august 2017
|
2018-05-29 19:41:27 +00:00
|
|
|
static const uint32_t CURRENT_PICTURE_VERSION = 63;
|
2012-11-13 20:41:18 +00:00
|
|
|
|
2016-10-07 19:50:53 +00:00
|
|
|
static_assert(MIN_PICTURE_VERSION <= 62, "Remove kFontAxes_bad from SkFontDescriptor.cpp");
|
|
|
|
|
2018-06-11 20:25:43 +00:00
|
|
|
static bool IsValidPictInfo(const struct SkPictInfo& info);
|
|
|
|
static sk_sp<SkPicture> Forwardport(const struct SkPictInfo&,
|
|
|
|
const class SkPictureData*,
|
|
|
|
class SkReadBuffer* buffer);
|
Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (patchset #22 id:420001 of https://codereview.chromium.org/1112523006/)
Reason for revert:
speculative revert to fix failures in DEPS roll
Original issue's description:
> Sketch splitting SkPicture into an interface and SkBigPicture.
>
> Adds small pictures for drawRect(), drawTextBlob(), and drawPath().
> These cover about 89% of draw calls from Blink SKPs,
> and about 25% of draw calls from our GMs.
>
> SkPicture handles:
> - serialization and deserialization
> - unique IDs
>
> Everything else is left to the subclasses:
> - playback(), cullRect()
> - hasBitmap(), hasText(), suitableForGPU(), etc.
> - LayerInfo / AccelData if applicable.
>
> The time to record a 1-op picture improves a good chunk
> (2 mallocs to 1), and the time to record a 0-op picture
> greatly improves (2 mallocs to none):
>
> picture_overhead_draw: 450ns -> 350ns
> picture_overhead_nodraw: 300ns -> 90ns
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/c92c129ff85b05a714bd1bf921c02d5e14651f8b
TBR=reed@google.com,robertphillips@google.com,mtklein@google.com,mtklein@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1130333002
2015-05-08 00:30:13 +00:00
|
|
|
|
2018-06-11 20:25:43 +00:00
|
|
|
struct SkPictInfo createHeader() const;
|
|
|
|
class SkPictureData* backport() const;
|
2014-11-17 14:45:18 +00:00
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
mutable uint32_t fUniqueID;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|