2011-07-28 14:26:00 +00:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkPicture_DEFINED
|
|
|
|
#define SkPicture_DEFINED
|
|
|
|
|
2013-02-22 21:38:35 +00:00
|
|
|
#include "SkBitmap.h"
|
2013-06-28 21:32:00 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkRefCnt.h"
|
|
|
|
|
2014-03-19 21:24:25 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
class GrContext;
|
|
|
|
#endif
|
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
class SkBBHFactory;
|
2012-11-01 17:10:32 +00:00
|
|
|
class SkBBoxHierarchy;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkCanvas;
|
2013-05-20 17:02:41 +00:00
|
|
|
class SkDrawPictureCallback;
|
2013-05-21 20:31:23 +00:00
|
|
|
class SkData;
|
2014-04-23 22:35:42 +00:00
|
|
|
class SkPathHeap;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkPicturePlayback;
|
|
|
|
class SkPictureRecord;
|
|
|
|
class SkStream;
|
|
|
|
class SkWStream;
|
|
|
|
|
2013-06-28 21:32:00 +00:00
|
|
|
struct SkPictInfo;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \class SkPicture
|
|
|
|
|
|
|
|
The SkPicture class records the drawing commands made to a canvas, to
|
|
|
|
be played back at a later time.
|
|
|
|
*/
|
2011-04-25 20:02:38 +00:00
|
|
|
class SK_API SkPicture : public SkRefCnt {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-06-21 20:25:03 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkPicture)
|
|
|
|
|
2014-03-16 19:46:36 +00:00
|
|
|
// AccelData provides a base class for device-specific acceleration
|
2014-03-17 03:02:17 +00:00
|
|
|
// data. It is added to the picture via a call to a device's optimize
|
2014-03-16 19:46:36 +00:00
|
|
|
// method.
|
|
|
|
class AccelData : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
typedef uint8_t Domain;
|
|
|
|
typedef uint32_t Key;
|
|
|
|
|
|
|
|
AccelData(Key key) : fKey(key) { }
|
|
|
|
|
|
|
|
const Key& getKey() const { return fKey; }
|
|
|
|
|
|
|
|
// This entry point allows user's to get a unique domain prefix
|
|
|
|
// for their keys
|
|
|
|
static Domain GenerateDomain();
|
|
|
|
private:
|
|
|
|
Key fKey;
|
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPicture();
|
|
|
|
/** Make a copy of the contents of src. If src records more drawing after
|
|
|
|
this call, those elements will not appear in this picture.
|
|
|
|
*/
|
|
|
|
SkPicture(const SkPicture& src);
|
2013-02-22 21:38:35 +00:00
|
|
|
|
2014-03-16 19:46:36 +00:00
|
|
|
/** PRIVATE / EXPERIMENTAL -- do not call */
|
2014-06-04 12:40:44 +00:00
|
|
|
void EXPERIMENTAL_addAccelData(const AccelData* data) const {
|
2014-03-17 03:02:17 +00:00
|
|
|
SkRefCnt_SafeAssign(fAccelData, data);
|
2014-03-16 19:46:36 +00:00
|
|
|
}
|
|
|
|
/** PRIVATE / EXPERIMENTAL -- do not call */
|
2014-03-17 03:02:17 +00:00
|
|
|
const AccelData* EXPERIMENTAL_getAccelData(AccelData::Key key) const {
|
2014-03-16 19:46:36 +00:00
|
|
|
if (NULL != fAccelData && fAccelData->getKey() == key) {
|
2014-03-17 03:02:17 +00:00
|
|
|
return fAccelData;
|
2014-03-16 19:46:36 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-25 14:36:28 +00:00
|
|
|
/**
|
2013-02-22 21:38:35 +00:00
|
|
|
* Function signature defining a function that sets up an SkBitmap from encoded data. On
|
|
|
|
* success, the SkBitmap should have its Config, width, height, rowBytes and pixelref set.
|
|
|
|
* If the installed pixelref has decoded the data into pixels, then the src buffer need not be
|
|
|
|
* copied. If the pixelref defers the actual decode until its lockPixels() is called, then it
|
|
|
|
* must make a copy of the src buffer.
|
|
|
|
* @param src Encoded data.
|
|
|
|
* @param length Size of the encoded data, in bytes.
|
|
|
|
* @param dst SkBitmap to install the pixel ref on.
|
|
|
|
* @param bool Whether or not a pixel ref was successfully installed.
|
2012-06-25 14:36:28 +00:00
|
|
|
*/
|
2013-02-22 21:38:35 +00:00
|
|
|
typedef bool (*InstallPixelRefProc)(const void* src, size_t length, SkBitmap* dst);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recreate a picture that was serialized into a stream.
|
|
|
|
* @param SkStream Serialized picture data.
|
|
|
|
* @param proc Function pointer for installing pixelrefs on SkBitmaps representing the
|
|
|
|
* encoded bitmap data from the stream.
|
2013-06-28 21:32:00 +00:00
|
|
|
* @return A new SkPicture representing the serialized data, or NULL if the stream is
|
|
|
|
* invalid.
|
2013-02-22 21:38:35 +00:00
|
|
|
*/
|
2013-06-28 21:32:00 +00:00
|
|
|
static SkPicture* CreateFromStream(SkStream*,
|
|
|
|
InstallPixelRefProc proc = &SkImageDecoder::DecodeMemory);
|
2013-02-22 21:38:35 +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.
|
|
|
|
*/
|
|
|
|
static SkPicture* CreateFromBuffer(SkReadBuffer&);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual ~SkPicture();
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/**
|
|
|
|
* Swap the contents of the two pictures. Guaranteed to succeed.
|
|
|
|
*/
|
|
|
|
void swap(SkPicture& other);
|
2012-08-30 14:38:00 +00:00
|
|
|
|
2012-08-29 18:52:07 +00:00
|
|
|
/**
|
|
|
|
* Creates a thread-safe clone of the picture that is ready for playback.
|
|
|
|
*/
|
|
|
|
SkPicture* clone() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates multiple thread-safe clones of this picture that are ready for
|
|
|
|
* playback. The resulting clones are stored in the provided array of
|
|
|
|
* SkPictures.
|
|
|
|
*/
|
|
|
|
void clone(SkPicture* pictures, int count) const;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-06-03 17:04:47 +00:00
|
|
|
// TODO: kUsePathBoundsForClip_RecordingFlag no longer belongs in
|
|
|
|
// SkPicture. It should be moved to SkPictureRecorder (or just made
|
|
|
|
// the default behavior).
|
2009-02-13 14:56:09 +00:00
|
|
|
enum RecordingFlags {
|
|
|
|
/* This flag specifies that when clipPath() is called, the path will
|
|
|
|
be faithfully recorded, but the recording canvas' current clip will
|
|
|
|
only see the path's bounds. This speeds up the recording process
|
|
|
|
without compromising the fidelity of the playback. The only side-
|
|
|
|
effect for recording is that calling getTotalClip() or related
|
|
|
|
clip-query calls will reflect the path's bounds, not the actual
|
|
|
|
path.
|
|
|
|
*/
|
2014-04-16 16:02:10 +00:00
|
|
|
kUsePathBoundsForClip_RecordingFlag = 0x01
|
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Replays the drawing commands on the specified canvas. This internally
|
|
|
|
calls endRecording() if that has not already been called.
|
2013-05-20 17:02:41 +00:00
|
|
|
@param canvas the canvas receiving the drawing commands.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2014-06-04 12:40:44 +00:00
|
|
|
void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL) const;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return the width of the picture's recording canvas. This
|
|
|
|
value reflects what was passed to setSize(), and does not necessarily
|
|
|
|
reflect the bounds of what has been recorded into the picture.
|
|
|
|
@return the width of the picture's recording canvas
|
|
|
|
*/
|
|
|
|
int width() const { return fWidth; }
|
|
|
|
|
|
|
|
/** Return the height of the picture's recording canvas. This
|
|
|
|
value reflects what was passed to setSize(), and does not necessarily
|
|
|
|
reflect the bounds of what has been recorded into the picture.
|
|
|
|
@return the height of the picture's recording canvas
|
|
|
|
*/
|
|
|
|
int height() const { return fHeight; }
|
|
|
|
|
2014-04-03 03:04:26 +00:00
|
|
|
/** Return a non-zero, unique value representing the picture. This call is
|
|
|
|
only valid when not recording. Between a beginRecording/endRecording
|
2014-04-07 18:26:22 +00:00
|
|
|
pair it will just return 0 (the invalid ID). Each beginRecording/
|
2014-04-02 23:51:13 +00:00
|
|
|
endRecording pair will cause a different generation ID to be returned.
|
|
|
|
*/
|
2014-04-07 18:26:22 +00:00
|
|
|
uint32_t uniqueID() const;
|
2014-04-02 23:51:13 +00:00
|
|
|
|
2013-02-22 22:04:19 +00:00
|
|
|
/**
|
2013-05-21 20:31:23 +00:00
|
|
|
* Function to encode an SkBitmap to an SkData. A function with this
|
2014-01-30 18:58:24 +00:00
|
|
|
* signature can be passed to serialize() and SkWriteBuffer.
|
|
|
|
* Returning NULL will tell the SkWriteBuffer to use
|
2013-05-21 20:31:23 +00:00
|
|
|
* SkBitmap::flatten() to store the bitmap.
|
2014-01-08 15:42:01 +00:00
|
|
|
*
|
|
|
|
* @param pixelRefOffset DEPRECATED -- caller assumes it will return 0.
|
2013-05-21 20:31:23 +00:00
|
|
|
* @return SkData If non-NULL, holds encoded data representing the passed
|
|
|
|
* in bitmap. The caller is responsible for calling unref().
|
2013-02-22 22:04:19 +00:00
|
|
|
*/
|
2013-05-21 20:31:23 +00:00
|
|
|
typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm);
|
2013-02-22 22:04:19 +00:00
|
|
|
|
Add the ability to provide function pointers to SkPicture serialization
and deserialization for encoding and decoding bitmaps.
Remove kForceFlattenBitmapPixels_Flag, which is no longer used.
When an SkOrderedReadBuffer needs to read a bitmap, if it does not
have an image decoder, use a dummy bitmap.
In GM, add a tolerance option for color differences, used when
testing picture serialization, so it can assume two images are the
same even though PNG encoding/decoding may have resulted in small
differences.
Create dummy implementations for SkImageDecoder and SkImageEncoder
functions in SkImageDecoder_empty so that a project that does not
want to include the images project it can still build.
Allow ports to build without images project.
In Mac's image encoder, copy 4444 to 8888 before encoding.
Add SkWriter32::reservePad, to provide a pointer to write non 4 byte
aligned data, padded with zeroes.
In bench_ and render_ pictures, pass decode function to SkPicture
creation from a stream.
BUG=https://code.google.com/p/skia/issues/detail?id=842
Review URL: https://codereview.appspot.com/6551071
git-svn-id: http://skia.googlecode.com/svn/trunk@5818 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-10-04 21:46:08 +00:00
|
|
|
/**
|
|
|
|
* Serialize to a stream. If non NULL, encoder will be used to encode
|
|
|
|
* any bitmaps in the picture.
|
2013-05-21 20:31:23 +00:00
|
|
|
* encoder will never be called with a NULL pixelRefOffset.
|
Add the ability to provide function pointers to SkPicture serialization
and deserialization for encoding and decoding bitmaps.
Remove kForceFlattenBitmapPixels_Flag, which is no longer used.
When an SkOrderedReadBuffer needs to read a bitmap, if it does not
have an image decoder, use a dummy bitmap.
In GM, add a tolerance option for color differences, used when
testing picture serialization, so it can assume two images are the
same even though PNG encoding/decoding may have resulted in small
differences.
Create dummy implementations for SkImageDecoder and SkImageEncoder
functions in SkImageDecoder_empty so that a project that does not
want to include the images project it can still build.
Allow ports to build without images project.
In Mac's image encoder, copy 4444 to 8888 before encoding.
Add SkWriter32::reservePad, to provide a pointer to write non 4 byte
aligned data, padded with zeroes.
In bench_ and render_ pictures, pass decode function to SkPicture
creation from a stream.
BUG=https://code.google.com/p/skia/issues/detail?id=842
Review URL: https://codereview.appspot.com/6551071
git-svn-id: http://skia.googlecode.com/svn/trunk@5818 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-10-04 21:46:08 +00:00
|
|
|
*/
|
2013-02-22 22:04:19 +00:00
|
|
|
void serialize(SkWStream*, EncodeBitmap encoder = NULL) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-02-07 12:20:04 +00:00
|
|
|
/**
|
|
|
|
* Serialize to a buffer.
|
|
|
|
*/
|
|
|
|
void flatten(SkWriteBuffer&) const;
|
|
|
|
|
2013-10-24 11:12:47 +00:00
|
|
|
/**
|
|
|
|
* Returns true if any bitmaps may be produced when this SkPicture
|
|
|
|
* is replayed.
|
|
|
|
* Returns false if called while still recording.
|
|
|
|
*/
|
|
|
|
bool willPlayBackBitmaps() const;
|
|
|
|
|
2013-02-01 16:18:09 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Signals that the caller is prematurely done replaying the drawing
|
|
|
|
commands. This can be called from a canvas virtual while the picture
|
2012-08-23 18:09:54 +00:00
|
|
|
is drawing. Has no effect if the picture is not drawing.
|
2013-02-01 16:18:09 +00:00
|
|
|
@deprecated preserving for legacy purposes
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void abortPlayback();
|
2013-02-01 16:18:09 +00:00
|
|
|
#endif
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2014-03-03 19:18:39 +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
|
2014-03-04 03:02:32 +00:00
|
|
|
rewound so it will have to be manually reset before passing to
|
2014-03-03 19:18:39 +00:00
|
|
|
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 InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*);
|
|
|
|
static bool InternalOnly_BufferIsSKP(SkReadBuffer&, SkPictInfo*);
|
|
|
|
|
2014-03-04 19:08:57 +00:00
|
|
|
/** Enable/disable all the picture recording optimizations (i.e.,
|
|
|
|
those in SkPictureRecord). It is mainly intended for testing the
|
|
|
|
existing optimizations (i.e., to actually have the pattern
|
|
|
|
appear in an .skp we have to disable the optimization). Call right
|
|
|
|
after 'beginRecording'.
|
|
|
|
*/
|
|
|
|
void internalOnly_EnableOpts(bool enableOpts);
|
|
|
|
|
2014-03-19 21:24:25 +00:00
|
|
|
/** Return true if the picture is suitable for rendering on the GPU.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2014-05-30 21:52:52 +00:00
|
|
|
bool suitableForGpuRasterization(GrContext*, const char ** = NULL) const;
|
2014-03-19 21:24:25 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-07 14:45:40 +00:00
|
|
|
protected:
|
2012-11-13 20:41:18 +00:00
|
|
|
// V2 : adds SkPixelRef's generation ID.
|
|
|
|
// V3 : PictInfo tag at beginning, and EOF tag at the end
|
|
|
|
// V4 : move SkPictInfo to be the header
|
|
|
|
// V5 : don't read/write FunctionPtr on cross-process (we can detect that)
|
|
|
|
// V6 : added serialization of SkPath's bounds (and packed its flags tighter)
|
|
|
|
// V7 : changed drawBitmapRect(IRect) to drawBitmapRectToRect(Rect)
|
|
|
|
// V8 : Add an option for encoding bitmaps
|
|
|
|
// V9 : Allow the reader and writer of an SKP disagree on whether to support
|
|
|
|
// SK_SUPPORT_HINTING_SCALE_FACTOR
|
2012-12-12 20:48:18 +00:00
|
|
|
// V10: add drawRRect, drawOval, clipRRect
|
2013-04-30 02:32:41 +00:00
|
|
|
// V11: modify how readBitmap and writeBitmap store their info.
|
2013-05-31 15:17:50 +00:00
|
|
|
// V12: add conics to SkPath, use new SkPathRef flattening
|
2013-08-16 10:24:37 +00:00
|
|
|
// V13: add flag to drawBitmapRectToRect
|
2013-08-27 16:14:03 +00:00
|
|
|
// parameterize blurs by sigma rather than radius
|
2013-09-26 12:18:23 +00:00
|
|
|
// V14: Add flags word to PathRef serialization
|
2014-04-02 23:51:13 +00:00
|
|
|
// V15: Remove A1 bitmap config (and renumber remaining configs)
|
2013-12-03 16:43:54 +00:00
|
|
|
// V16: Move SkPath's isOval flag to SkPathRef
|
2013-12-13 19:58:46 +00:00
|
|
|
// V17: SkPixelRef now writes SkImageInfo
|
2014-01-08 15:42:01 +00:00
|
|
|
// V18: SkBitmap now records x,y for its pixelref origin, instead of offset.
|
2014-01-23 15:16:05 +00:00
|
|
|
// V19: encode matrices and regions into the ops stream
|
2014-02-07 12:20:04 +00:00
|
|
|
// V20: added bool to SkPictureImageFilter's serialization (to allow SkPicture serialization)
|
2014-02-27 17:40:13 +00:00
|
|
|
// V21: add pushCull, popCull
|
2014-03-05 18:25:20 +00:00
|
|
|
// V22: SK_PICT_FACTORY_TAG's size is now the chunk size in bytes
|
2014-04-16 12:58:02 +00:00
|
|
|
// V23: SkPaint::FilterLevel became a real enum
|
2014-04-21 13:10:25 +00:00
|
|
|
// V24: SkTwoPointConicalGradient now has fFlipped flag for gradient flipping
|
2014-04-22 15:21:18 +00:00
|
|
|
// V25: SkDashPathEffect now only writes phase and interval array when flattening
|
2014-04-24 16:54:46 +00:00
|
|
|
// V26: Removed boolean from SkColorShader for inheriting color from SkPaint.
|
2014-05-22 12:27:41 +00:00
|
|
|
// V27: Remove SkUnitMapper from gradients (and skia).
|
2014-05-23 13:21:55 +00:00
|
|
|
// V28: No longer call bitmap::flatten inside SkWriteBuffer::writeBitmap.
|
2014-02-18 22:08:16 +00:00
|
|
|
|
|
|
|
// Note: If the picture version needs to be increased then please follow the
|
|
|
|
// steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw
|
2014-02-25 02:16:10 +00:00
|
|
|
|
|
|
|
// Only SKPs within the min/current picture version range (inclusive) can be read.
|
|
|
|
static const uint32_t MIN_PICTURE_VERSION = 19;
|
2014-05-23 13:21:55 +00:00
|
|
|
static const uint32_t CURRENT_PICTURE_VERSION = 28;
|
2012-11-13 20:41:18 +00:00
|
|
|
|
2014-04-07 18:26:22 +00:00
|
|
|
mutable uint32_t fUniqueID;
|
2014-04-02 23:51:13 +00:00
|
|
|
|
2012-11-13 20:41:18 +00:00
|
|
|
// fPlayback, fRecord, fWidth & fHeight are protected to allow derived classes to
|
2012-11-13 21:46:06 +00:00
|
|
|
// install their own SkPicturePlayback-derived players,SkPictureRecord-derived
|
2012-11-13 20:41:18 +00:00
|
|
|
// recorders and set the picture size
|
2014-03-16 19:46:36 +00:00
|
|
|
SkPicturePlayback* fPlayback;
|
|
|
|
SkPictureRecord* fRecord;
|
|
|
|
int fWidth, fHeight;
|
2014-06-04 12:40:44 +00:00
|
|
|
mutable const AccelData* fAccelData;
|
2012-10-24 19:30:41 +00:00
|
|
|
|
2014-04-07 18:26:22 +00:00
|
|
|
void needsNewGenID() { fUniqueID = SK_InvalidGenID; }
|
2014-04-02 23:51:13 +00:00
|
|
|
|
2013-06-28 21:32:00 +00:00
|
|
|
// Create a new SkPicture from an existing SkPicturePlayback. Ref count of
|
|
|
|
// playback is unchanged.
|
|
|
|
SkPicture(SkPicturePlayback*, int width, int height);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2014-04-23 22:35:42 +00:00
|
|
|
friend class SkPictureRecord;
|
|
|
|
friend class SkPictureTester; // for unit testing
|
|
|
|
|
|
|
|
SkAutoTUnref<SkPathHeap> fPathHeap; // reference counted
|
|
|
|
|
2014-04-24 21:53:13 +00:00
|
|
|
// ContentInfo is not serialized! It is intended solely for use
|
|
|
|
// with suitableForGpuRasterization.
|
|
|
|
class ContentInfo {
|
|
|
|
public:
|
|
|
|
ContentInfo() { this->reset(); }
|
|
|
|
|
|
|
|
ContentInfo(const ContentInfo& src) { this->set(src); }
|
|
|
|
|
|
|
|
void set(const ContentInfo& src) {
|
|
|
|
fNumPaintWithPathEffectUses = src.fNumPaintWithPathEffectUses;
|
|
|
|
fNumAAConcavePaths = src.fNumAAConcavePaths;
|
|
|
|
fNumAAHairlineConcavePaths = src.fNumAAHairlineConcavePaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
fNumPaintWithPathEffectUses = 0;
|
|
|
|
fNumAAConcavePaths = 0;
|
|
|
|
fNumAAHairlineConcavePaths = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void swap(ContentInfo* other) {
|
|
|
|
SkTSwap(fNumPaintWithPathEffectUses, other->fNumPaintWithPathEffectUses);
|
|
|
|
SkTSwap(fNumAAConcavePaths, other->fNumAAConcavePaths);
|
|
|
|
SkTSwap(fNumAAHairlineConcavePaths, other->fNumAAHairlineConcavePaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This field is incremented every time a paint with a path effect is
|
|
|
|
// used (i.e., it is not a de-duplicated count)
|
|
|
|
int fNumPaintWithPathEffectUses;
|
2014-04-25 03:05:58 +00:00
|
|
|
// This field is incremented every time an anti-aliased drawPath call is
|
2014-04-24 21:53:13 +00:00
|
|
|
// issued with a concave path
|
|
|
|
int fNumAAConcavePaths;
|
|
|
|
// This field is incremented every time a drawPath call is
|
|
|
|
// issued for a hairline stroked concave path.
|
|
|
|
int fNumAAHairlineConcavePaths;
|
|
|
|
};
|
|
|
|
|
|
|
|
ContentInfo fContentInfo;
|
|
|
|
|
|
|
|
void incPaintWithPathEffectUses() {
|
|
|
|
++fContentInfo.fNumPaintWithPathEffectUses;
|
|
|
|
}
|
|
|
|
int numPaintWithPathEffectUses() const {
|
|
|
|
return fContentInfo.fNumPaintWithPathEffectUses;
|
|
|
|
}
|
|
|
|
|
|
|
|
void incAAConcavePaths() {
|
|
|
|
++fContentInfo.fNumAAConcavePaths;
|
|
|
|
}
|
|
|
|
int numAAConcavePaths() const {
|
|
|
|
return fContentInfo.fNumAAConcavePaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
void incAAHairlineConcavePaths() {
|
|
|
|
++fContentInfo.fNumAAHairlineConcavePaths;
|
|
|
|
SkASSERT(fContentInfo.fNumAAHairlineConcavePaths <= fContentInfo.fNumAAConcavePaths);
|
|
|
|
}
|
|
|
|
int numAAHairlineConcavePaths() const {
|
|
|
|
return fContentInfo.fNumAAHairlineConcavePaths;
|
|
|
|
}
|
|
|
|
|
2014-04-23 22:35:42 +00:00
|
|
|
const SkPath& getPath(int index) const;
|
|
|
|
int addPathToHeap(const SkPath& path);
|
|
|
|
|
|
|
|
void flattenToBuffer(SkWriteBuffer& buffer) const;
|
|
|
|
bool parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t size);
|
|
|
|
|
|
|
|
static void WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size);
|
|
|
|
static void WriteTagSize(SkWStream* stream, uint32_t tag, size_t size);
|
|
|
|
|
|
|
|
void initForPlayback() const;
|
|
|
|
void dumpSize() const;
|
|
|
|
|
2014-03-18 17:45:32 +00:00
|
|
|
// An OperationList encapsulates a set of operation offsets into the picture byte
|
|
|
|
// stream along with the CTMs needed for those operation.
|
2014-04-07 19:34:38 +00:00
|
|
|
class OperationList : ::SkNoncopyable {
|
2014-03-18 17:45:32 +00:00
|
|
|
public:
|
|
|
|
virtual ~OperationList() {}
|
|
|
|
|
|
|
|
// If valid returns false then there is no optimization data
|
|
|
|
// present. All the draw operations need to be issued.
|
|
|
|
virtual bool valid() const { return false; }
|
|
|
|
|
|
|
|
// The following three entry points should only be accessed if
|
|
|
|
// 'valid' returns true.
|
|
|
|
virtual int numOps() const { SkASSERT(false); return 0; };
|
|
|
|
// The offset in the picture of the operation to execute.
|
|
|
|
virtual uint32_t offset(int index) const { SkASSERT(false); return 0; };
|
|
|
|
// The CTM that must be installed for the operation to behave correctly
|
|
|
|
virtual const SkMatrix& matrix(int index) const { SkASSERT(false); return SkMatrix::I(); }
|
|
|
|
|
|
|
|
static const OperationList& InvalidList();
|
|
|
|
};
|
|
|
|
|
|
|
|
/** PRIVATE / EXPERIMENTAL -- do not call
|
|
|
|
Return the operations required to render the content inside 'queryRect'.
|
|
|
|
*/
|
2014-06-04 12:40:44 +00:00
|
|
|
const OperationList& EXPERIMENTAL_getActiveOps(const SkIRect& queryRect) const;
|
2014-03-18 17:45:32 +00:00
|
|
|
|
2014-03-24 19:40:49 +00:00
|
|
|
/** PRIVATE / EXPERIMENTAL -- do not call
|
|
|
|
Return the ID of the operation currently being executed when playing
|
|
|
|
back. 0 indicates no call is active.
|
|
|
|
*/
|
|
|
|
size_t EXPERIMENTAL_curOpID() const;
|
|
|
|
|
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
|
|
|
void createHeader(SkPictInfo* info) const;
|
|
|
|
static bool IsValidPictInfo(const SkPictInfo& info);
|
2014-05-19 12:36:15 +00:00
|
|
|
static SkPicturePlayback* FakeEndRecording(const SkPicture* resourceSrc,
|
|
|
|
const SkPictureRecord& record,
|
|
|
|
bool deepCopy);
|
2014-02-07 12:20:04 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
friend class SkFlatPicture;
|
|
|
|
friend class SkPicturePlayback;
|
2014-04-17 23:35:06 +00:00
|
|
|
friend class SkPictureRecorder;
|
2014-03-18 17:45:32 +00:00
|
|
|
friend class SkGpuDevice;
|
2014-05-07 21:31:09 +00:00
|
|
|
friend class GrGatherCanvas;
|
2014-03-24 19:40:49 +00:00
|
|
|
friend class GrGatherDevice;
|
|
|
|
friend class SkDebugCanvas;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2014-06-03 17:04:47 +00:00
|
|
|
// TODO: beginRecording, getRecordingCanvas & endRecording can now be
|
|
|
|
// be moved out of SkPicture (and, presumably, be directly implemented
|
|
|
|
// in SkPictureRecorder)
|
|
|
|
|
|
|
|
/** Returns the canvas that records the drawing commands.
|
|
|
|
@param width the base width for the picture, as if the recording
|
|
|
|
canvas' bitmap had this width.
|
|
|
|
@param height the base width for the picture, as if the recording
|
|
|
|
canvas' bitmap had this height.
|
|
|
|
@param factory if non-NULL, the factory used to the BBH for the recorded picture
|
|
|
|
@param recordFlags optional flags that control recording.
|
|
|
|
@return the picture canvas.
|
|
|
|
*/
|
|
|
|
SkCanvas* beginRecording(int width, int height, SkBBHFactory* factory, uint32_t recordFlags);
|
|
|
|
/** Returns the recording canvas if one is active, or NULL if recording is
|
|
|
|
not active. This does not alter the refcnt on the canvas (if present).
|
|
|
|
*/
|
|
|
|
SkCanvas* getRecordingCanvas() const;
|
|
|
|
/** Signal that the caller is done recording. This invalidates the canvas
|
|
|
|
returned by beginRecording/getRecordingCanvas, and prepares the picture
|
|
|
|
for drawing. Note: this happens implicitly the first time the picture
|
|
|
|
is drawn.
|
|
|
|
*/
|
|
|
|
void endRecording();
|
|
|
|
|
2012-06-21 20:25:03 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2013-05-20 17:02:41 +00:00
|
|
|
/**
|
|
|
|
* Subclasses of this can be passed to canvas.drawPicture. During the drawing
|
|
|
|
* of the picture, this callback will periodically be invoked. If its
|
|
|
|
* abortDrawing() 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 drawPicture call was made.
|
|
|
|
*/
|
2013-05-22 21:11:42 +00:00
|
|
|
class SK_API SkDrawPictureCallback {
|
2013-05-20 17:02:41 +00:00
|
|
|
public:
|
|
|
|
SkDrawPictureCallback() {}
|
|
|
|
virtual ~SkDrawPictureCallback() {}
|
2013-05-21 07:01:40 +00:00
|
|
|
|
2013-05-20 17:02:41 +00:00
|
|
|
virtual bool abortDrawing() = 0;
|
|
|
|
};
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#endif
|