clean up SkPicture include
Get SkPicture.h ready for documenting. - remove private methods - move private forward declarations - name parameters R=reed@google.com, bsalomon@google.com Bug: skia:6898 Change-Id: I28829111203d8ae2a4661cf02c99023403aa0df0 Reviewed-on: https://skia-review.googlesource.com/134120 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Cary Clark <caryclark@skia.org> Commit-Queue: Cary Clark <caryclark@google.com>
This commit is contained in:
parent
e73d7d84d7
commit
efd99cc928
@ -18,6 +18,7 @@
|
||||
#include "SkMaskFilter.h"
|
||||
#include "SkNullCanvas.h"
|
||||
#include "SkPathEffect.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
#include "SkPoint3.h"
|
||||
#include "SkRSXform.h"
|
||||
@ -1734,7 +1735,7 @@ DEF_FUZZ(RasterN32CanvasViaSerialization, fuzz) {
|
||||
sk_sp<SkData> data = pic->serialize();
|
||||
if (!data) { fuzz->signalBug(); }
|
||||
SkReadBuffer rb(data->data(), data->size());
|
||||
auto deserialized = SkPicture::MakeFromBuffer(rb);
|
||||
auto deserialized = SkPicturePriv::MakeFromBuffer(rb);
|
||||
if (!deserialized) { fuzz->signalBug(); }
|
||||
auto surface = SkSurface::MakeRasterN32Premul(kCanvasSize.width(), kCanvasSize.height());
|
||||
SkASSERT(surface && surface->getCanvas());
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "SkOSPath.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkPipe.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkStream.h"
|
||||
@ -604,7 +604,7 @@ static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
|
||||
static void fuzz_skp(sk_sp<SkData> bytes) {
|
||||
SkReadBuffer buf(bytes->data(), bytes->size());
|
||||
SkDebugf("Decoding\n");
|
||||
sk_sp<SkPicture> pic(SkPicture::MakeFromBuffer(buf));
|
||||
sk_sp<SkPicture> pic(SkPicturePriv::MakeFromBuffer(buf));
|
||||
if (!pic) {
|
||||
SkDebugf("[terminated] Couldn't decode as a picture.\n");
|
||||
return;
|
||||
|
@ -12,20 +12,13 @@
|
||||
#include "SkRect.h"
|
||||
#include "SkTypes.h"
|
||||
|
||||
class SkBigPicture;
|
||||
class SkCanvas;
|
||||
class SkData;
|
||||
struct SkDeserialProcs;
|
||||
class SkImage;
|
||||
class SkPictureData;
|
||||
class SkReadBuffer;
|
||||
class SkRefCntSet;
|
||||
struct SkSerialProcs;
|
||||
class SkStream;
|
||||
class SkTypefacePlayback;
|
||||
class SkWStream;
|
||||
class SkWriteBuffer;
|
||||
struct SkPictInfo;
|
||||
|
||||
/** \class SkPicture
|
||||
|
||||
@ -38,20 +31,12 @@ public:
|
||||
* Recreate a picture that was serialized into a stream or data.
|
||||
*/
|
||||
|
||||
static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs* = nullptr);
|
||||
static sk_sp<SkPicture> MakeFromData(const SkData* data, const SkDeserialProcs* = nullptr);
|
||||
static sk_sp<SkPicture> MakeFromStream(SkStream* stream,
|
||||
const SkDeserialProcs* procs = nullptr);
|
||||
static sk_sp<SkPicture> MakeFromData(const SkData* data,
|
||||
const SkDeserialProcs* procs = nullptr);
|
||||
static sk_sp<SkPicture> MakeFromData(const void* data, size_t size,
|
||||
const SkDeserialProcs* = nullptr);
|
||||
|
||||
/**
|
||||
* 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::MakeFromBuffer().
|
||||
* @param SkReadBuffer Serialized picture data.
|
||||
* @return A new SkPicture representing the serialized data, or NULL if the buffer is
|
||||
* invalid.
|
||||
*/
|
||||
static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer&);
|
||||
const SkDeserialProcs* procs = nullptr);
|
||||
|
||||
/**
|
||||
* Subclasses of this can be passed to playback(). During the playback
|
||||
@ -77,7 +62,7 @@ public:
|
||||
@param canvas the canvas receiving the drawing commands.
|
||||
@param callback a callback that allows interruption of playback
|
||||
*/
|
||||
virtual void playback(SkCanvas*, AbortCallback* = nullptr) const = 0;
|
||||
virtual void playback(SkCanvas* canvas, AbortCallback* callback = nullptr) const = 0;
|
||||
|
||||
/** Return a cull rect for this picture.
|
||||
Ops recorded into this picture that attempt to draw outside the cull might not be drawn.
|
||||
@ -87,8 +72,8 @@ public:
|
||||
/** Returns a non-zero value unique among all pictures. */
|
||||
uint32_t uniqueID() const;
|
||||
|
||||
sk_sp<SkData> serialize(const SkSerialProcs* = nullptr) const;
|
||||
void serialize(SkWStream*, const SkSerialProcs* = nullptr) const;
|
||||
sk_sp<SkData> serialize(const SkSerialProcs* procs = nullptr) const;
|
||||
void serialize(SkWStream* stream, const SkSerialProcs* procs = nullptr) const;
|
||||
|
||||
/**
|
||||
* Return a placeholder SkPicture.
|
||||
@ -98,11 +83,6 @@ public:
|
||||
*/
|
||||
static sk_sp<SkPicture> MakePlaceholder(SkRect cull);
|
||||
|
||||
/**
|
||||
* Serialize to a buffer.
|
||||
*/
|
||||
void flatten(SkWriteBuffer&) const;
|
||||
|
||||
/** 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
|
||||
@ -113,18 +93,17 @@ public:
|
||||
/** Returns the approximate byte size of this picture, not including large ref'd objects. */
|
||||
virtual size_t approximateBytesUsed() const = 0;
|
||||
|
||||
// Returns NULL if this is not an SkBigPicture.
|
||||
virtual const SkBigPicture* asSkBigPicture() const { return nullptr; }
|
||||
|
||||
private:
|
||||
// Subclass whitelist.
|
||||
SkPicture();
|
||||
friend class SkBigPicture;
|
||||
friend class SkEmptyPicture;
|
||||
friend class SkPicturePriv;
|
||||
template <typename> friend class SkMiniPicture;
|
||||
|
||||
void serialize(SkWStream*, const SkSerialProcs*, SkRefCntSet* typefaces) const;
|
||||
static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs*, SkTypefacePlayback*);
|
||||
void serialize(SkWStream*, const SkSerialProcs*, class SkRefCntSet* typefaces) const;
|
||||
static sk_sp<SkPicture> MakeFromStream(SkStream*, const SkDeserialProcs*,
|
||||
class SkTypefacePlayback*);
|
||||
friend class SkPictureData;
|
||||
|
||||
/** Return true if the SkStream/Buffer represents a serialized picture, and
|
||||
@ -135,9 +114,12 @@ private:
|
||||
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*);
|
||||
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; }
|
||||
|
||||
friend struct SkPathCounter;
|
||||
|
||||
@ -177,13 +159,13 @@ private:
|
||||
|
||||
static_assert(MIN_PICTURE_VERSION <= 62, "Remove kFontAxes_bad from SkFontDescriptor.cpp");
|
||||
|
||||
static bool IsValidPictInfo(const SkPictInfo& info);
|
||||
static sk_sp<SkPicture> Forwardport(const SkPictInfo&,
|
||||
const SkPictureData*,
|
||||
SkReadBuffer* buffer);
|
||||
static bool IsValidPictInfo(const struct SkPictInfo& info);
|
||||
static sk_sp<SkPicture> Forwardport(const struct SkPictInfo&,
|
||||
const class SkPictureData*,
|
||||
class SkReadBuffer* buffer);
|
||||
|
||||
SkPictInfo createHeader() const;
|
||||
SkPictureData* backport() const;
|
||||
struct SkPictInfo createHeader() const;
|
||||
class SkPictureData* backport() const;
|
||||
|
||||
mutable uint32_t fUniqueID;
|
||||
};
|
||||
|
@ -8,10 +8,10 @@
|
||||
#include "SkAtomics.h"
|
||||
#include "SkImageGenerator.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkPictureCommon.h"
|
||||
#include "SkPictureData.h"
|
||||
#include "SkPicturePlayback.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkPictureRecord.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
#include "SkSerialProcs.h"
|
||||
@ -198,9 +198,9 @@ sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, const SkDeserialPro
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) {
|
||||
sk_sp<SkPicture> SkPicturePriv::MakeFromBuffer(SkReadBuffer& buffer) {
|
||||
SkPictInfo info;
|
||||
if (!BufferIsSKP(&buffer, &info)) {
|
||||
if (!SkPicture::BufferIsSKP(&buffer, &info)) {
|
||||
return nullptr;
|
||||
}
|
||||
// size should be 0, 1, or negative
|
||||
@ -218,7 +218,7 @@ sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) {
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, info));
|
||||
return Forwardport(info, data.get(), &buffer);
|
||||
return SkPicture::Forwardport(info, data.get(), &buffer);
|
||||
}
|
||||
|
||||
SkPictureData* SkPicture::backport() const {
|
||||
@ -296,15 +296,15 @@ void SkPicture::serialize(SkWStream* stream, const SkSerialProcs* procsPtr,
|
||||
}
|
||||
}
|
||||
|
||||
void SkPicture::flatten(SkWriteBuffer& buffer) const {
|
||||
SkPictInfo info = this->createHeader();
|
||||
std::unique_ptr<SkPictureData> data(this->backport());
|
||||
void SkPicturePriv::Flatten(const sk_sp<const SkPicture> picture, SkWriteBuffer& buffer) {
|
||||
SkPictInfo info = picture->createHeader();
|
||||
std::unique_ptr<SkPictureData> data(picture->backport());
|
||||
|
||||
buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic));
|
||||
buffer.writeUInt(info.getVersion());
|
||||
buffer.writeRect(info.fCullRect);
|
||||
|
||||
if (auto custom = custom_serialize(this, buffer.fProcs)) {
|
||||
if (auto custom = custom_serialize(picture.get(), buffer.fProcs)) {
|
||||
int32_t size = SkToS32(custom->size());
|
||||
buffer.write32(-size); // negative for custom format
|
||||
buffer.writePad32(custom->data(), size);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkPictureData.h"
|
||||
#include "SkPictureRecord.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkTextBlob.h"
|
||||
#include "SkTypeface.h"
|
||||
@ -232,7 +233,7 @@ void SkPictureData::flatten(SkWriteBuffer& buffer) const {
|
||||
if (!fPictures.empty()) {
|
||||
write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictures.count());
|
||||
for (const auto& pic : fPictures) {
|
||||
pic->flatten(buffer);
|
||||
SkPicturePriv::Flatten(pic, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -440,7 +441,7 @@ void SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t
|
||||
fOpData = std::move(data);
|
||||
} break;
|
||||
case SK_PICT_PICTURE_TAG:
|
||||
new_array_from_buffer(buffer, size, fPictures, SkPicture::MakeFromBuffer);
|
||||
new_array_from_buffer(buffer, size, fPictures, SkPicturePriv::MakeFromBuffer);
|
||||
break;
|
||||
case SK_PICT_DRAWABLE_TAG:
|
||||
new_array_from_buffer(buffer, size, fDrawables, create_drawable_from_buffer);
|
||||
|
39
src/core/SkPicturePriv.h
Normal file
39
src/core/SkPicturePriv.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkPicturePriv_DEFINED
|
||||
#define SkPicturePriv_DEFINED
|
||||
|
||||
#include "SkPicture.h"
|
||||
|
||||
class SkReadBuffer;
|
||||
class SkWriteBuffer;
|
||||
|
||||
class SkPicturePriv {
|
||||
public:
|
||||
/**
|
||||
* 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::MakeFromBuffer().
|
||||
* @param buffer Serialized picture data.
|
||||
* @return A new SkPicture representing the serialized data, or NULL if the buffer is
|
||||
* invalid.
|
||||
*/
|
||||
static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer& buffer);
|
||||
|
||||
/**
|
||||
* Serialize to a buffer.
|
||||
*/
|
||||
static void Flatten(const sk_sp<const SkPicture> , SkWriteBuffer& buffer);
|
||||
|
||||
// Returns NULL if this is not an SkBigPicture.
|
||||
static const SkBigPicture* AsSkBigPicture(const sk_sp<const SkPicture> picture) {
|
||||
return picture->asSkBigPicture();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -292,7 +292,7 @@ private:
|
||||
SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory;
|
||||
|
||||
SkDeserialProcs fProcs;
|
||||
friend class SkPicture;
|
||||
friend class SkPicturePriv;
|
||||
|
||||
#ifdef DEBUG_NON_DETERMINISTIC_ASSERT
|
||||
// Debugging counter to keep track of how many bitmaps we
|
||||
|
@ -67,7 +67,7 @@ protected:
|
||||
SkDeduper* fDeduper = nullptr;
|
||||
SkSerialProcs fProcs;
|
||||
|
||||
friend class SkPicture; // fProcs
|
||||
friend class SkPicturePriv; // fProcs
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "SkColorSpaceXformer.h"
|
||||
#include "SkFlattenablePriv.h"
|
||||
#include "SkImageSource.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkSpecialImage.h"
|
||||
#include "SkSpecialSurface.h"
|
||||
@ -58,7 +59,7 @@ sk_sp<SkFlattenable> SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SkRect cropRect;
|
||||
|
||||
if (buffer.readBool()) {
|
||||
picture = SkPicture::MakeFromBuffer(buffer);
|
||||
picture = SkPicturePriv::MakeFromBuffer(buffer);
|
||||
}
|
||||
buffer.readRect(&cropRect);
|
||||
|
||||
@ -77,7 +78,7 @@ void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
bool hasPicture = (fPicture != nullptr);
|
||||
buffer.writeBool(hasPicture);
|
||||
if (hasPicture) {
|
||||
fPicture->flatten(buffer);
|
||||
SkPicturePriv::Flatten(fPicture, buffer);
|
||||
}
|
||||
buffer.writeRect(fCropRect);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "SkImage.h"
|
||||
#include "SkImageShader.h"
|
||||
#include "SkMatrixUtils.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkPictureImageGenerator.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkResourceCache.h"
|
||||
@ -157,7 +157,7 @@ sk_sp<SkFlattenable> SkPictureShader::CreateProc(SkReadBuffer& buffer) {
|
||||
|
||||
bool didSerialize = buffer.readBool();
|
||||
if (didSerialize) {
|
||||
picture = SkPicture::MakeFromBuffer(buffer);
|
||||
picture = SkPicturePriv::MakeFromBuffer(buffer);
|
||||
}
|
||||
return SkPictureShader::Make(picture, mx, my, &lm, &tile);
|
||||
}
|
||||
@ -169,7 +169,7 @@ void SkPictureShader::flatten(SkWriteBuffer& buffer) const {
|
||||
buffer.writeRect(fTile);
|
||||
|
||||
buffer.writeBool(true);
|
||||
fPicture->flatten(buffer);
|
||||
SkPicturePriv::Flatten(fPicture, buffer);
|
||||
}
|
||||
|
||||
// Returns a cached image shader, which wraps a single picture tile at the given
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "SkMiniRecorder.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "SkRandom.h"
|
||||
@ -452,7 +452,7 @@ static void test_cull_rect_reset(skiatest::Reporter* reporter) {
|
||||
canvas->drawRect(bounds, paint);
|
||||
canvas->drawRect(bounds, paint);
|
||||
sk_sp<SkPicture> p(recorder.finishRecordingAsPictureWithCull(bounds));
|
||||
const SkBigPicture* picture = p->asSkBigPicture();
|
||||
const SkBigPicture* picture = SkPicturePriv::AsSkBigPicture(p);
|
||||
REPORTER_ASSERT(reporter, picture);
|
||||
|
||||
SkRect finalCullRect = picture->cullRect();
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "SkMatrixPriv.h"
|
||||
#include "SkOSFile.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
#include "SkShaderBase.h"
|
||||
#include "SkTableColorFilter.h"
|
||||
@ -544,14 +545,14 @@ DEF_TEST(Serialization, reporter) {
|
||||
|
||||
// Serialize picture
|
||||
SkBinaryWriteBuffer writer;
|
||||
pict->flatten(writer);
|
||||
SkPicturePriv::Flatten(pict, writer);
|
||||
size_t size = writer.bytesWritten();
|
||||
SkAutoTMalloc<unsigned char> data(size);
|
||||
writer.writeToMemory(static_cast<void*>(data.get()));
|
||||
|
||||
// Deserialize picture
|
||||
SkReadBuffer reader(static_cast<void*>(data.get()), size);
|
||||
sk_sp<SkPicture> readPict(SkPicture::MakeFromBuffer(reader));
|
||||
sk_sp<SkPicture> readPict(SkPicturePriv::MakeFromBuffer(reader));
|
||||
REPORTER_ASSERT(reporter, reader.isValid());
|
||||
REPORTER_ASSERT(reporter, readPict.get());
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SkPicturePriv.h"
|
||||
#include "SkRecord.h"
|
||||
#include "SkRecordDraw.h"
|
||||
|
||||
@ -63,7 +64,7 @@ public:
|
||||
void print(const SkRecords::DrawPicture& command, double ns) {
|
||||
this->printNameAndTime(command, ns);
|
||||
|
||||
if (auto bp = command.picture->asSkBigPicture()) {
|
||||
if (auto bp = SkPicturePriv::AsSkBigPicture(command.picture)) {
|
||||
++fIndent;
|
||||
|
||||
const SkRecord& record = *bp->record();
|
||||
|
Loading…
Reference in New Issue
Block a user