aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkWriteBuffer.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2014-12-09 05:35:07 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-09 05:35:07 -0800
commitc0708cb7bcc22a6ad14fc3c2198d8e00d71c6754 (patch)
tree48e23acfa8e27ee9755058f22fbceaf080c407fe /src/core/SkWriteBuffer.cpp
parent8b7b9c2e804b54a8301363091f418cfeda719fe3 (diff)
Revert of Replace EncodeBitmap with an interface. (patchset #11 id:190001 of https://codereview.chromium.org/784643002/)
Reason for revert: Compilation is failing on some bots Original issue's description: > Replace EncodeBitmap with an interface. > > Gives more flexibility to the caller to decide whether to use the > encoded data returned by refEncodedData(). > > Provides an implementation that supports the old version of > SkPicture::serialize(). > > TODO: Update Chrome, so we can remove SK_LEGACY_ENCODE_BITMAP entirely > > BUG=skia:3190 > > Committed: https://skia.googlesource.com/skia/+/0c4aba6edb9900c597359dfa49d3ce4a41bc5dd1 TBR=reed@google.com,scroggo@google.com NOTREECHECKS=true NOTRY=true BUG=skia:3190 Review URL: https://codereview.chromium.org/787833002
Diffstat (limited to 'src/core/SkWriteBuffer.cpp')
-rw-r--r--src/core/SkWriteBuffer.cpp61
1 files changed, 27 insertions, 34 deletions
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;