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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2021-01-15 19:14:45 +00:00
|
|
|
#include "include/core/SkSamplingOptions.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/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;
|
2019-04-02 21:49:12 +00:00
|
|
|
class SkMatrix;
|
2017-12-05 20:11:24 +00:00
|
|
|
struct SkSerialProcs;
|
2019-04-02 21:49:12 +00:00
|
|
|
class SkShader;
|
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
|
2018-08-10 17:11:06 +00:00
|
|
|
SkPicture records drawing commands made to SkCanvas. The command stream may be
|
|
|
|
played in whole or in part at a later time.
|
|
|
|
|
|
|
|
SkPicture is an abstract class. SkPicture may be generated by SkPictureRecorder
|
|
|
|
or SkDrawable, or from SkPicture previously saved to SkData or SkStream.
|
|
|
|
|
|
|
|
SkPicture may contain any SkCanvas drawing command, as well as one or more
|
|
|
|
SkCanvas matrix or SkCanvas clip. SkPicture has a cull SkRect, which is used as
|
|
|
|
a bounding box hint. To limit SkPicture bounds, use SkCanvas clip when
|
|
|
|
recording or drawing SkPicture.
|
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-08-10 17:11:06 +00:00
|
|
|
/** Recreates SkPicture that was serialized into a stream. Returns constructed SkPicture
|
|
|
|
if successful; otherwise, returns nullptr. Fails if data does not permit
|
|
|
|
constructing valid SkPicture.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
procs->fPictureProc permits supplying a custom function to decode SkPicture.
|
|
|
|
If procs->fPictureProc is nullptr, default decoding is used. procs->fPictureCtx
|
|
|
|
may be used to provide user context to procs->fPictureProc; procs->fPictureProc
|
2018-08-10 17:11:06 +00:00
|
|
|
is called with a pointer to data, data byte length, and user context.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@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
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Recreates SkPicture that was serialized into data. Returns constructed SkPicture
|
|
|
|
if successful; otherwise, returns nullptr. Fails if data does not permit
|
|
|
|
constructing valid SkPicture.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
procs->fPictureProc permits supplying a custom function to decode SkPicture.
|
|
|
|
If procs->fPictureProc is nullptr, default decoding is used. procs->fPictureCtx
|
|
|
|
may be used to provide user context to procs->fPictureProc; procs->fPictureProc
|
2018-08-10 17:11:06 +00:00
|
|
|
is called with a pointer to data, data byte length, and user context.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@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
|
2018-08-10 17:11:06 +00:00
|
|
|
AbortCallback is an abstract class. An implementation of AbortCallback may
|
|
|
|
passed as a parameter to SkPicture::playback, to stop it before all drawing
|
|
|
|
commands have been processed.
|
|
|
|
|
|
|
|
If AbortCallback::abort returns true, SkPicture::playback is interrupted.
|
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
|
2018-08-10 17:11:06 +00:00
|
|
|
AbortCallback provides an override for abort() that can stop SkPicture::playback.
|
|
|
|
|
|
|
|
The part of SkPicture drawn when aborted is undefined. SkPicture instantiations are
|
|
|
|
free to stop drawing at different points during playback.
|
|
|
|
|
|
|
|
If the abort happens inside one or more calls to SkCanvas::save(), stack
|
|
|
|
of SkCanvas matrix and SkCanvas clip values is restored to its state before
|
|
|
|
SkPicture::playback was called.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@return true to stop playback
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_AbortCallback_abort
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2015-01-07 15:28:41 +00:00
|
|
|
virtual bool abort() = 0;
|
|
|
|
};
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Replays the drawing commands on the specified canvas. In the case that the
|
|
|
|
commands are recorded, each command in the SkPicture is sent separately to canvas.
|
|
|
|
|
|
|
|
To add a single command to draw SkPicture to recording canvas, call
|
|
|
|
SkCanvas::drawPicture instead.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@param canvas receiver of drawing commands
|
|
|
|
@param callback allows interruption of playback
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_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-08-10 17:11:06 +00:00
|
|
|
/** Returns cull SkRect for this picture, passed in when SkPicture was created.
|
|
|
|
Returned SkRect does not specify clipping SkRect for SkPicture; cull is hint
|
|
|
|
of SkPicture bounds.
|
|
|
|
|
|
|
|
SkPicture is free to discard recorded drawing commands that fall outside
|
|
|
|
cull.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@return bounds passed when SkPicture was created
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_cullRect
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2015-05-19 18:11:26 +00:00
|
|
|
virtual SkRect cullRect() const = 0;
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns a non-zero value unique among SkPicture in Skia process.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@return identifier for SkPicture
|
|
|
|
*/
|
2018-12-04 14:05:26 +00:00
|
|
|
uint32_t uniqueID() const { return fUniqueID; }
|
2014-04-02 23:51:13 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns storage containing SkData describing SkPicture, using optional custom
|
|
|
|
encoders.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
procs->fPictureProc permits supplying a custom function to encode SkPicture.
|
|
|
|
If procs->fPictureProc is nullptr, default encoding is used. procs->fPictureCtx
|
|
|
|
may be used to provide user context to procs->fPictureProc; procs->fPictureProc
|
2018-08-10 17:11:06 +00:00
|
|
|
is called with a pointer to SkPicture and user context.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@param procs custom serial data encoders; may be nullptr
|
|
|
|
@return storage containing serialized SkPicture
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_serialize
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
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.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
procs->fPictureProc permits supplying a custom function to encode SkPicture.
|
|
|
|
If procs->fPictureProc is nullptr, default encoding is used. procs->fPictureCtx
|
|
|
|
may be used to provide user context to procs->fPictureProc; procs->fPictureProc
|
2018-08-10 17:11:06 +00:00
|
|
|
is called with a pointer to SkPicture and user context.
|
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
@param stream writable serial data stream
|
|
|
|
@param procs custom serial data encoders; may be nullptr
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_serialize_2
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
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-08-10 17:11:06 +00:00
|
|
|
/** Returns a placeholder SkPicture. Result does not draw, and contains only
|
|
|
|
cull SkRect, a hint of its bounds. Result is immutable; it cannot be changed
|
|
|
|
later. Result identifier is unique.
|
|
|
|
|
|
|
|
Returned placeholder can be intercepted during playback to insert other
|
|
|
|
commands into SkCanvas draw stream.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@param cull placeholder dimensions
|
|
|
|
@return placeholder with unique identifier
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_MakePlaceholder
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2018-01-26 14:49:48 +00:00
|
|
|
static sk_sp<SkPicture> MakePlaceholder(SkRect cull);
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns the approximate number of operations in SkPicture. Returned value
|
|
|
|
may be greater or less than the number of SkCanvas calls
|
|
|
|
recorded: some calls may be recorded as more than one operation, other
|
2018-07-13 12:21:59 +00:00
|
|
|
calls may be optimized away.
|
|
|
|
|
2020-08-17 21:12:13 +00:00
|
|
|
@param nested if true, include the op-counts of nested pictures as well, else
|
|
|
|
just return count the ops in the top-level picture.
|
2018-07-13 12:21:59 +00:00
|
|
|
@return approximate operation count
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_approximateOpCount
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2020-08-17 21:12:13 +00:00
|
|
|
virtual int approximateOpCount(bool nested = false) const = 0;
|
2018-01-27 17:30:04 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns the approximate byte size of SkPicture. Does not include large objects
|
2018-08-10 17:11:06 +00:00
|
|
|
referenced by SkPicture.
|
2018-07-13 12:21:59 +00:00
|
|
|
|
|
|
|
@return approximate size
|
2019-03-15 19:47:01 +00:00
|
|
|
|
|
|
|
example: https://fiddle.skia.org/c/@Picture_approximateBytesUsed
|
2018-07-13 12:21:59 +00:00
|
|
|
*/
|
2017-12-25 00:50:57 +00:00
|
|
|
virtual size_t approximateBytesUsed() const = 0;
|
|
|
|
|
2019-04-02 21:49:12 +00:00
|
|
|
/** Return a new shader that will draw with this picture.
|
|
|
|
*
|
|
|
|
* @param tmx The tiling mode to use when sampling in the x-direction.
|
|
|
|
* @param tmy The tiling mode to use when sampling in the y-direction.
|
2021-01-15 19:14:45 +00:00
|
|
|
* @param mode How to filter the tiles
|
2019-04-02 21:49:12 +00:00
|
|
|
* @param localMatrix Optional matrix used when sampling
|
|
|
|
* @param tile The tile rectangle in picture coordinates: this represents the subset
|
|
|
|
* (or superset) of the picture used when building a tile. It is not
|
|
|
|
* affected by localMatrix and does not imply scaling (only translation
|
|
|
|
* and cropping). If null, the tile rect is considered equal to the picture
|
|
|
|
* bounds.
|
|
|
|
* @return Returns a new shader object. Note: this function never returns null.
|
|
|
|
*/
|
2021-01-15 19:14:45 +00:00
|
|
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode,
|
|
|
|
const SkMatrix* localMatrix, const SkRect* tileRect) const;
|
|
|
|
|
|
|
|
// DEPRECATED
|
2019-04-02 21:49:12 +00:00
|
|
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy,
|
|
|
|
const SkMatrix* localMatrix, const SkRect* tileRect) const;
|
|
|
|
sk_sp<SkShader> makeShader(SkTileMode tmx, SkTileMode tmy,
|
|
|
|
const SkMatrix* localMatrix = nullptr) const;
|
|
|
|
|
2015-05-19 18:11:26 +00:00
|
|
|
private:
|
2020-07-23 11:55:59 +00:00
|
|
|
// Allowed subclasses.
|
2015-05-19 18:11:26 +00:00
|
|
|
SkPicture();
|
|
|
|
friend class SkBigPicture;
|
|
|
|
friend class SkEmptyPicture;
|
2018-06-11 20:25:43 +00:00
|
|
|
friend class SkPicturePriv;
|
2019-05-20 12:45:50 +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
|
|
|
|
2019-06-07 18:40:00 +00:00
|
|
|
void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces,
|
|
|
|
bool textBlobsOnly=false) const;
|
2018-06-11 20:25:43 +00:00
|
|
|
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
|
|
|
|
2019-05-20 12:45:50 +00:00
|
|
|
friend struct SkPathCounter;
|
|
|
|
|
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
|
|
|
|
2018-12-04 14:05:26 +00:00
|
|
|
uint32_t fUniqueID;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|