Cleanup SkPicture* classes a bit

This is an attempt to reduce the number of friends the various SkPicture* classes have.
Probably the only controversial part is making getBitmap, getPath, getPicture and getPaint
public on SkPictureData (and adding a new initIterator entry point).

R=mtklein@google.com, reed@google.com

Author: robertphillips@google.com

Review URL: https://codereview.chromium.org/384753004
This commit is contained in:
robertphillips 2014-07-10 09:35:12 -07:00 committed by Commit bot
parent fd429991e9
commit 6142609b22
7 changed files with 43 additions and 50 deletions

View File

@ -280,14 +280,11 @@ private:
void createHeader(SkPictInfo* info) const;
static bool IsValidPictInfo(const SkPictInfo& info);
friend class SkFlatPicture;
friend class SkPictureData;
friend class SkPictureRecorder; // just for SkPicture-based constructor
friend class SkGpuDevice;
friend class GrGatherCanvas;
friend class GrGatherDevice;
friend class SkDebugCanvas;
friend class SkPicturePlayback; // to get fData
friend class SkPictureData; // to access OperationList
friend class SkPictureRecorder; // just for SkPicture-based constructor
friend class SkGpuDevice; // for EXPERIMENTAL_getActiveOps/OperationList
friend class GrGatherCanvas; // needs to know if old or new picture
friend class SkPicturePlayback; // to get fData & OperationList
friend class SkPictureReplacementPlayback; // to access OperationList
typedef SkRefCnt INHERITED;

View File

@ -473,18 +473,6 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
}
}
// fRecord OK
void SkPicture::WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size) {
buffer.writeUInt(tag);
buffer.writeUInt(SkToU32(size));
}
// fRecord OK
void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) {
stream->write32(tag);
stream->write32(SkToU32(size));
}
// fRecord OK
void SkPicture::flatten(SkWriteBuffer& buffer) const {
const SkPictureData* data = fData.get();

View File

@ -9,7 +9,6 @@
#include "SkDrawPictureCallback.h"
#include "SkPictureData.h"
#include "SkPictureRecord.h"
#include "SkPictureStateTree.h"
#include "SkReadBuffer.h"
#include "SkTypeface.h"
#include "SkTSort.h"
@ -38,8 +37,8 @@ void SkPictureData::initForPlayback() const {
}
SkPictureData::SkPictureData(const SkPictureRecord& record,
const SkPictInfo& info,
bool deepCopyOps)
const SkPictInfo& info,
bool deepCopyOps)
: fInfo(info) {
#ifdef SK_DEBUG_SIZE
size_t overallBytes, bitmapBytes, matricesBytes,
@ -289,6 +288,16 @@ static size_t compute_chunk_size(SkFlattenable::Factory* array, int count) {
return size;
}
static void write_tag_size(SkWriteBuffer& buffer, uint32_t tag, size_t size) {
buffer.writeUInt(tag);
buffer.writeUInt(SkToU32(size));
}
static void write_tag_size(SkWStream* stream, uint32_t tag, size_t size) {
stream->write32(tag);
stream->write32(SkToU32(size));
}
void SkPictureData::WriteFactories(SkWStream* stream, const SkFactorySet& rec) {
int count = rec.count();
@ -299,7 +308,7 @@ void SkPictureData::WriteFactories(SkWStream* stream, const SkFactorySet& rec) {
size_t size = compute_chunk_size(array, count);
// TODO: write_tag_size should really take a size_t
SkPicture::WriteTagSize(stream, SK_PICT_FACTORY_TAG, (uint32_t) size);
write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size);
SkDEBUGCODE(size_t start = stream->bytesWritten());
stream->write32(count);
@ -321,7 +330,7 @@ void SkPictureData::WriteFactories(SkWStream* stream, const SkFactorySet& rec) {
void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) {
int count = rec.count();
SkPicture::WriteTagSize(stream, SK_PICT_TYPEFACE_TAG, count);
write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count);
SkAutoSTMalloc<16, SkTypeface*> storage(count);
SkTypeface** array = (SkTypeface**)storage.get();
@ -336,32 +345,32 @@ void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const {
int i, n;
if ((n = SafeCount(fBitmaps)) > 0) {
SkPicture::WriteTagSize(buffer, SK_PICT_BITMAP_BUFFER_TAG, n);
write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n);
for (i = 0; i < n; i++) {
buffer.writeBitmap((*fBitmaps)[i]);
}
}
if ((n = SafeCount(fPaints)) > 0) {
SkPicture::WriteTagSize(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
for (i = 0; i < n; i++) {
buffer.writePaint((*fPaints)[i]);
}
}
if ((n = SafeCount(fPathHeap.get())) > 0) {
SkPicture::WriteTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n);
write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n);
fPathHeap->flatten(buffer);
}
}
void SkPictureData::serialize(SkWStream* stream,
SkPicture::EncodeBitmap encoder) const {
SkPicture::WriteTagSize(stream, SK_PICT_READER_TAG, fOpData->size());
write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size());
stream->write(fOpData->bytes(), fOpData->size());
if (fPictureCount > 0) {
SkPicture::WriteTagSize(stream, SK_PICT_PICTURE_TAG, fPictureCount);
write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount);
for (int i = 0; i < fPictureCount; i++) {
fPictureRefs[i]->serialize(stream, encoder);
}
@ -386,7 +395,7 @@ void SkPictureData::serialize(SkWStream* stream,
WriteFactories(stream, factSet);
WriteTypefaces(stream, typefaceSet);
SkPicture::WriteTagSize(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten());
write_tag_size(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten());
buffer.writeToStream(stream);
}
@ -394,11 +403,11 @@ void SkPictureData::serialize(SkWStream* stream,
}
void SkPictureData::flatten(SkWriteBuffer& buffer) const {
SkPicture::WriteTagSize(buffer, SK_PICT_READER_TAG, fOpData->size());
write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size());
buffer.writeByteArray(fOpData->bytes(), fOpData->size());
if (fPictureCount > 0) {
SkPicture::WriteTagSize(buffer, SK_PICT_PICTURE_TAG, fPictureCount);
write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount);
for (int i = 0; i < fPictureCount; i++) {
fPictureRefs[i]->flatten(buffer);
}

View File

@ -12,6 +12,7 @@
#include "SkPathHeap.h"
#include "SkPicture.h"
#include "SkPictureFlat.h"
#include "SkPictureStateTree.h"
class SkData;
class SkPictureRecord;
@ -24,7 +25,6 @@ class SkPaint;
class SkPath;
class SkPictureStateTree;
class SkReadBuffer;
class SkRegion;
struct SkPictInfo {
enum Flags {
@ -160,8 +160,7 @@ protected:
bool parseStream(SkStream*, SkPicture::InstallPixelRefProc);
bool parseBuffer(SkReadBuffer& buffer);
private:
public:
const SkBitmap& getBitmap(SkReader32* reader) const {
const int index = reader->readInt();
if (SkBitmapHeap::INVALID_SLOT == index) {
@ -192,10 +191,15 @@ private:
return &(*fPaints)[index - 1];
}
void init();
void initIterator(SkPictureStateTree::Iterator* iter,
const SkTDArray<void*>& draws,
SkCanvas* canvas) const {
if (NULL != fStateTree) {
fStateTree->initIterator(iter, draws, canvas);
}
}
#ifdef SK_DEBUG_SIZE
public:
int size(size_t* sizePtr);
int bitmaps(size_t* size);
int paints(size_t* size);
@ -241,15 +245,14 @@ public:
GrPixelConfig config, SkScalar dpi) const;
#endif
private: // these help us with reading/writing
private:
void init();
// these help us with reading/writing
bool parseStreamTag(SkStream*, uint32_t tag, uint32_t size, SkPicture::InstallPixelRefProc);
bool parseBufferTag(SkReadBuffer&, uint32_t tag, uint32_t size);
void flattenToBuffer(SkWriteBuffer&) const;
private:
friend class SkPicture;
friend class SkPicturePlayback;
// Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_SLOT. This empty
// bitmap allows playback to draw nothing and move on.
SkBitmap fBadBitmap;

View File

@ -66,7 +66,7 @@ static SkBitmap shallow_copy(const SkBitmap& bitmap) {
const SkPicture::OperationList* SkPicturePlayback::getActiveOps(const SkCanvas* canvas) {
if (fUseBBH && NULL != fPictureData->fStateTree && NULL != fPictureData->fBoundingHierarchy) {
if (fUseBBH) {
SkRect clipBounds;
if (canvas->getClipBounds(&clipBounds)) {
SkIRect query;
@ -89,7 +89,7 @@ bool SkPicturePlayback::initIterator(SkPictureStateTree::Iterator* iter,
return false; // nothing to draw
}
fPictureData->fStateTree->initIterator(iter, activeOpsList->fOps, canvas);
fPictureData->initIterator(iter, activeOpsList->fOps, canvas);
}
return true;

View File

@ -325,7 +325,7 @@ private:
bool fOptsEnabled;
int fInitialSaveCount;
friend class SkPictureData;
friend class SkPictureData; // for SkPictureData's SkPictureRecord-based constructor
friend class SkPictureTester; // for unit testing
#ifdef SK_COLLAPSE_MATRIX_CLIP_STATE

View File

@ -1840,10 +1840,6 @@ void SkGpuDevice::EXPERIMENTAL_purge(const SkPicture* picture) {
bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* picture) {
if (NULL == picture->fData.get()) {
return false;
}
SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey();
const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key);