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
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
class SkBigPicture;
|
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;
|
2014-07-01 15:47:04 +00:00
|
|
|
class SkPictureData;
|
2016-03-24 17:41:47 +00:00
|
|
|
class SkReadBuffer;
|
2015-08-18 15:29:59 +00:00
|
|
|
class SkRefCntSet;
|
2017-12-05 20:11:24 +00:00
|
|
|
struct SkSerialProcs;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkStream;
|
2015-08-18 15:29:59 +00:00
|
|
|
class SkTypefacePlayback;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkWStream;
|
2016-03-24 17:41:47 +00:00
|
|
|
class SkWriteBuffer;
|
2013-06-28 21:32:00 +00:00
|
|
|
struct SkPictInfo;
|
|
|
|
|
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:
|
2016-02-17 18:02:29 +00:00
|
|
|
/**
|
2017-12-16 11:12:32 +00:00
|
|
|
* Recreate a picture that was serialized into a stream or data.
|
2016-02-17 18:02:29 +00:00
|
|
|
*/
|
2017-12-15 20:42:14 +00:00
|
|
|
|
2017-12-20 19:12:07 +00:00
|
|
|
static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs* = nullptr);
|
|
|
|
static sk_sp<SkPicture> MakeFromData(const SkData* data, const SkDeserialProcs* = nullptr);
|
|
|
|
static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
|
|
|
|
const SkDeserialProcs* = nullptr);
|
2017-12-05 20:11:24 +00:00
|
|
|
|
2014-02-07 12:20:04 +00:00
|
|
|
/**
|
|
|
|
* Recreate a picture that was serialized into a buffer. If the creation requires bitmap
|
|
|
|
* decoding, the decoder must be set on the SkReadBuffer parameter by calling
|
|
|
|
* SkReadBuffer::setBitmapDecoder() before calling SkPicture::CreateFromBuffer().
|
|
|
|
* @param SkReadBuffer Serialized picture data.
|
|
|
|
* @return A new SkPicture representing the serialized data, or NULL if the buffer is
|
|
|
|
* invalid.
|
|
|
|
*/
|
2016-03-18 14:25:55 +00:00
|
|
|
static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer&);
|
2014-02-07 12:20:04 +00:00
|
|
|
|
2015-01-07 15:28:41 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
class SK_API AbortCallback {
|
|
|
|
public:
|
|
|
|
AbortCallback() {}
|
|
|
|
virtual ~AbortCallback() {}
|
|
|
|
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.
|
2013-05-20 17:02:41 +00:00
|
|
|
@param canvas the canvas receiving the drawing commands.
|
2014-09-04 15:42:50 +00:00
|
|
|
@param callback a callback that allows interruption of playback
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-08-28 14:34:05 +00:00
|
|
|
virtual void playback(SkCanvas*, AbortCallback* = nullptr) const = 0;
|
2015-05-18 20:47:17 +00:00
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
/** Return a cull rect for this picture.
|
|
|
|
Ops recorded into this picture that attempt to draw outside the cull might not be drawn.
|
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
|
|
|
*/
|
2015-05-19 18:11:26 +00:00
|
|
|
virtual SkRect cullRect() const = 0;
|
|
|
|
|
|
|
|
/** Returns a non-zero value unique among all pictures. */
|
2015-04-07 13:34:05 +00:00
|
|
|
uint32_t uniqueID() const;
|
2014-04-02 23:51:13 +00:00
|
|
|
|
2017-12-20 19:12:07 +00:00
|
|
|
sk_sp<SkData> serialize(const SkSerialProcs* = nullptr) const;
|
|
|
|
void serialize(SkWStream*, const SkSerialProcs* = nullptr) const;
|
|
|
|
|
2014-02-07 12:20:04 +00:00
|
|
|
/**
|
|
|
|
* Serialize to a buffer.
|
|
|
|
*/
|
|
|
|
void flatten(SkWriteBuffer&) const;
|
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
/** Return 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.
|
|
|
|
*/
|
|
|
|
virtual int approximateOpCount() const = 0;
|
|
|
|
|
2017-12-25 00:50:57 +00:00
|
|
|
/** Returns the approximate byte size of this picture, not including large ref'd objects. */
|
|
|
|
virtual size_t approximateBytesUsed() const = 0;
|
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
// Returns NULL if this is not an SkBigPicture.
|
2017-08-28 14:34:05 +00:00
|
|
|
virtual const SkBigPicture* asSkBigPicture() const { return nullptr; }
|
2014-11-24 16:20:57 +00:00
|
|
|
|
2015-06-16 16:28:37 +00:00
|
|
|
static bool PictureIOSecurityPrecautionsEnabled();
|
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
private:
|
|
|
|
// Subclass whitelist.
|
|
|
|
SkPicture();
|
|
|
|
friend class SkBigPicture;
|
|
|
|
friend class SkEmptyPicture;
|
|
|
|
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
|
|
|
|
2017-12-20 19:12:07 +00:00
|
|
|
void serialize(SkWStream*, const SkSerialProcs*, SkRefCntSet* typefaces) const;
|
|
|
|
static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs*, 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
|
|
|
|
CreateFromStream or CreateFromBuffer. Note, CreateFromStream and
|
|
|
|
CreateFromBuffer perform this check internally so these entry points are
|
|
|
|
intended for stand alone tools.
|
|
|
|
If false is returned, SkPictInfo is unmodified.
|
|
|
|
*/
|
|
|
|
static bool StreamIsSKP(SkStream*, SkPictInfo*);
|
|
|
|
static bool BufferIsSKP(SkReadBuffer*, SkPictInfo*);
|
|
|
|
friend bool SkPicture_StreamIsSKP(SkStream*, SkPictInfo*);
|
|
|
|
|
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
|
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.
|
2017-12-29 04:35:23 +00:00
|
|
|
static const uint32_t MIN_PICTURE_VERSION = 51; // Produced by Chrome ~M56.
|
2017-11-09 21:50:20 +00:00
|
|
|
static const uint32_t CURRENT_PICTURE_VERSION = 59;
|
2012-11-13 20:41:18 +00:00
|
|
|
|
Fixing SkPicture serialization
Fixed a few issues while attempting to use the new
serialization path for SkPicture inside a fuzzer:
- SkReadBuffer and SkValidatingReadBuffer both had a fReader
member instead of sharing the same member, which leads to
problems if a base class function is used
- In SkPicture, a header is now written as a single chunk of
data, so it also has to be read as a single chunk of data
- In the SkPicturePlayback destructor, a bad deserialization
would lead to a crash if we don't safely unref fOpData
- Also in SkPicturePlayback, if we only use a ReadBuffer for
the whole deserialization, additional tags must be added to
parseBufferTag()
- SkValidatingReadBuffer::readBitmap() was broken, but this
path wasn't usen't since the only use case for
SkValidatingReadBuffer is currently image filters and
bitmaps are unflattened as part of the deserialization of
SkBitmapSource
- SkPictureImageFilter was not deserializable. Added it to
SkGlobalInitialization*
- Added a test that exercises the SkPicture serialization /
deserialization code
BUG=skia:
R=senorblanco@google.com, senorblanco@chromium.org, reed@google.com, robertphillips@google.com
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/195223003
git-svn-id: http://skia.googlecode.com/svn/trunk@13764 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-03-12 14:46:41 +00:00
|
|
|
static bool IsValidPictInfo(const SkPictInfo& info);
|
2016-04-22 18:40:42 +00:00
|
|
|
static sk_sp<SkPicture> Forwardport(const SkPictInfo&,
|
|
|
|
const SkPictureData*,
|
2016-09-30 16:27:20 +00:00
|
|
|
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
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
SkPictInfo createHeader() const;
|
|
|
|
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
|