diff options
author | robertphillips <robertphillips@google.com> | 2014-07-10 09:35:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-07-10 09:35:12 -0700 |
commit | 6142609b22814283210f79d698182b651a93136c (patch) | |
tree | d49bde0884bf278b41be4c85b1c985fa290f386e /src/core | |
parent | fd429991e99d18cbb956f91b7c347440b39684c1 (diff) |
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
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPicture.cpp | 12 | ||||
-rw-r--r-- | src/core/SkPictureData.cpp | 35 | ||||
-rw-r--r-- | src/core/SkPictureData.h | 23 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 4 | ||||
-rw-r--r-- | src/core/SkPictureRecord.h | 2 |
5 files changed, 38 insertions, 38 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 6c7da8a69b..9261664717 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -474,18 +474,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(); diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 2c71eebf2f..e89ef37bde 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -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); } diff --git a/src/core/SkPictureData.h b/src/core/SkPictureData.h index efae974840..e4ee86ab8f 100644 --- a/src/core/SkPictureData.h +++ b/src/core/SkPictureData.h @@ -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; diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 0c5c74a4fc..d16a6353e9 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -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; diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 0fdfaa7108..a1b52fb195 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -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 |