diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPicture.cpp | 39 | ||||
-rw-r--r-- | src/core/SkPictureData.cpp | 6 | ||||
-rw-r--r-- | src/core/SkPictureData.h | 3 | ||||
-rw-r--r-- | src/core/SkWriteBuffer.cpp | 61 |
4 files changed, 34 insertions, 75 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 3296264be8..0d7773b520 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -1,3 +1,4 @@ + /* * Copyright 2007 The Android Open Source Project * @@ -453,41 +454,7 @@ SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info, return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/)); } -#ifdef SK_LEGACY_ENCODE_BITMAP -// Helper to support the EncodeBitmap version of serialize. -// Mimics the old behavior of always accepting the encoded data, and encoding -// using EncodeBitmap if there was no encoded data. -class EncodeBitmapSerializer : public SkPixelSerializer { -public: - explicit EncodeBitmapSerializer(SkPicture::EncodeBitmap encoder) - : fEncoder(encoder) - { - SkASSERT(fEncoder); - } - - virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; } - - virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels, - size_t rowBytes) SK_OVERRIDE { - // Required by signature of EncodeBitmap. - size_t unused; - SkBitmap bm; - bm.installPixels(info, pixels, rowBytes); - return fEncoder(&unused, bm); - } - -private: - SkPicture::EncodeBitmap fEncoder; -}; - -void SkPicture::serialize(SkWStream* wStream, SkPicture::EncodeBitmap encoder) const { - EncodeBitmapSerializer serializer(encoder); - this->serialize(wStream, &serializer); -} - -#endif - -void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer) const { +void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { SkPictInfo info; this->createHeader(&info); SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePicts(), @@ -496,7 +463,7 @@ void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer) stream->write(&info, sizeof(info)); if (data) { stream->writeBool(true); - data->serialize(stream, pixelSerializer); + data->serialize(stream, encoder); } else { stream->writeBool(false); } diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 938274aceb..2b2265403f 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -218,14 +218,14 @@ void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const { } void SkPictureData::serialize(SkWStream* stream, - SkPixelSerializer* pixelSerializer) const { + SkPicture::EncodeBitmap encoder) const { write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size()); stream->write(fOpData->bytes(), fOpData->size()); if (fPictureCount > 0) { write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount); for (int i = 0; i < fPictureCount; i++) { - fPictureRefs[i]->serialize(stream, pixelSerializer); + fPictureRefs[i]->serialize(stream, encoder); } } @@ -238,7 +238,7 @@ void SkPictureData::serialize(SkWStream* stream, SkWriteBuffer buffer(SkWriteBuffer::kCrossProcess_Flag); buffer.setTypefaceRecorder(&typefaceSet); buffer.setFactoryRecorder(&factSet); - buffer.setPixelSerializer(pixelSerializer); + buffer.setBitmapEncoder(encoder); this->flattenToBuffer(buffer); diff --git a/src/core/SkPictureData.h b/src/core/SkPictureData.h index ab78f8a313..667880675b 100644 --- a/src/core/SkPictureData.h +++ b/src/core/SkPictureData.h @@ -15,7 +15,6 @@ class SkData; class SkPictureRecord; -class SkPixelSerializer; class SkReader32; class SkStream; class SkWStream; @@ -65,7 +64,7 @@ public: virtual ~SkPictureData(); - void serialize(SkWStream*, SkPixelSerializer*) const; + void serialize(SkWStream*, SkPicture::EncodeBitmap) const; void flatten(SkWriteBuffer&) const; bool containsBitmaps() const; diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp index bcae1f8bc9..c79d2758c7 100644 --- a/src/core/SkWriteBuffer.cpp +++ b/src/core/SkWriteBuffer.cpp @@ -20,7 +20,8 @@ SkWriteBuffer::SkWriteBuffer(uint32_t flags) , fFactorySet(NULL) , fNamedFactorySet(NULL) , fBitmapHeap(NULL) - , fTFSet(NULL) { + , fTFSet(NULL) + , fBitmapEncoder(NULL) { } SkWriteBuffer::SkWriteBuffer(void* storage, size_t storageSize, uint32_t flags) @@ -29,7 +30,8 @@ SkWriteBuffer::SkWriteBuffer(void* storage, size_t storageSize, uint32_t flags) , fNamedFactorySet(NULL) , fWriter(storage, storageSize) , fBitmapHeap(NULL) - , fTFSet(NULL) { + , fTFSet(NULL) + , fBitmapEncoder(NULL) { } SkWriteBuffer::~SkWriteBuffer() { @@ -170,7 +172,7 @@ void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) { // SkBitmapHeapReader to read the SkBitmap. False if the bitmap was serialized another way. this->writeBool(useBitmapHeap); if (useBitmapHeap) { - SkASSERT(NULL == fPixelSerializer); + SkASSERT(NULL == fBitmapEncoder); int32_t slot = fBitmapHeap->insert(bitmap); fWriter.write32(slot); // crbug.com/155875 @@ -183,33 +185,25 @@ void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) { return; } - SkPixelRef* pixelRef = bitmap.pixelRef(); - if (pixelRef) { - // see if the pixelref already has an encoded version - SkAutoDataUnref existingData(bitmap.pixelRef()->refEncodedData()); - if (existingData.get() != NULL) { - // Assumes that if the client did not set a serializer, they are - // happy to get the encoded data. - if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingData->data(), - existingData->size())) { - write_encoded_bitmap(this, existingData, bitmap.pixelRefOrigin()); - return; - } + // see if the pixelref already has an encoded version + if (bitmap.pixelRef()) { + SkAutoDataUnref data(bitmap.pixelRef()->refEncodedData()); + if (data.get() != NULL) { + write_encoded_bitmap(this, data, bitmap.pixelRefOrigin()); + return; } + } - // see if the caller wants to manually encode - if (fPixelSerializer) { - SkASSERT(NULL == fBitmapHeap); - SkAutoLockPixels alp(bitmap); - SkAutoDataUnref data(fPixelSerializer->encodePixels(bitmap.info(), - bitmap.getPixels(), - bitmap.rowBytes())); - if (data.get() != NULL) { - // if we have to "encode" the bitmap, then we assume there is no - // offset to share, since we are effectively creating a new pixelref - write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); - return; - } + // see if the caller wants to manually encode + if (fBitmapEncoder != NULL) { + SkASSERT(NULL == fBitmapHeap); + size_t offset = 0; // this parameter is deprecated/ignored + // if we have to "encode" the bitmap, then we assume there is no + // offset to share, since we are effectively creating a new pixelref + SkAutoDataUnref data(fBitmapEncoder(&offset, bitmap)); + if (data.get() != NULL) { + write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); + return; } } @@ -251,15 +245,14 @@ SkRefCntSet* SkWriteBuffer::setTypefaceRecorder(SkRefCntSet* rec) { void SkWriteBuffer::setBitmapHeap(SkBitmapHeap* bitmapHeap) { SkRefCnt_SafeAssign(fBitmapHeap, bitmapHeap); if (bitmapHeap != NULL) { - SkASSERT(NULL == fPixelSerializer); - fPixelSerializer.reset(NULL); + SkASSERT(NULL == fBitmapEncoder); + fBitmapEncoder = NULL; } } -void SkWriteBuffer::setPixelSerializer(SkPixelSerializer* serializer) { - fPixelSerializer.reset(serializer); - if (serializer) { - serializer->ref(); +void SkWriteBuffer::setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder) { + fBitmapEncoder = bitmapEncoder; + if (bitmapEncoder != NULL) { SkASSERT(NULL == fBitmapHeap); SkSafeUnref(fBitmapHeap); fBitmapHeap = NULL; |