Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: src/core/SkWriteBuffer.cpp

Issue 784643002: Replace EncodeBitmap with an interface. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPictureData.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkWriteBuffer.cpp
diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp
index c79d2758c763e8fa2c1170e4206ac4133ec058dd..6048c9f5c2c3ea8717b0222c070f3bb1b063d002 100644
--- a/src/core/SkWriteBuffer.cpp
+++ b/src/core/SkWriteBuffer.cpp
@@ -20,8 +20,7 @@ SkWriteBuffer::SkWriteBuffer(uint32_t flags)
, fFactorySet(NULL)
, fNamedFactorySet(NULL)
, fBitmapHeap(NULL)
- , fTFSet(NULL)
- , fBitmapEncoder(NULL) {
+ , fTFSet(NULL) {
}
SkWriteBuffer::SkWriteBuffer(void* storage, size_t storageSize, uint32_t flags)
@@ -30,8 +29,7 @@ SkWriteBuffer::SkWriteBuffer(void* storage, size_t storageSize, uint32_t flags)
, fNamedFactorySet(NULL)
, fWriter(storage, storageSize)
, fBitmapHeap(NULL)
- , fTFSet(NULL)
- , fBitmapEncoder(NULL) {
+ , fTFSet(NULL) {
}
SkWriteBuffer::~SkWriteBuffer() {
@@ -172,7 +170,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 == fBitmapEncoder);
+ SkASSERT(NULL == fPixelSerializer);
int32_t slot = fBitmapHeap->insert(bitmap);
fWriter.write32(slot);
// crbug.com/155875
@@ -185,25 +183,33 @@ void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
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;
+ SkPixelRef* pixelRef = bitmap.pixelRef();
+ if (pixelRef) {
+ // see if the pixelref already has an encoded version
+ SkAutoDataUnref existingData(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 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;
+ // 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;
+ }
}
}
@@ -245,14 +251,15 @@ SkRefCntSet* SkWriteBuffer::setTypefaceRecorder(SkRefCntSet* rec) {
void SkWriteBuffer::setBitmapHeap(SkBitmapHeap* bitmapHeap) {
SkRefCnt_SafeAssign(fBitmapHeap, bitmapHeap);
if (bitmapHeap != NULL) {
- SkASSERT(NULL == fBitmapEncoder);
- fBitmapEncoder = NULL;
+ SkASSERT(NULL == fPixelSerializer);
+ fPixelSerializer.reset(NULL);
}
}
-void SkWriteBuffer::setBitmapEncoder(SkPicture::EncodeBitmap bitmapEncoder) {
- fBitmapEncoder = bitmapEncoder;
- if (bitmapEncoder != NULL) {
+void SkWriteBuffer::setPixelSerializer(SkPixelSerializer* serializer) {
+ fPixelSerializer.reset(serializer);
+ if (serializer) {
+ serializer->ref();
SkASSERT(NULL == fBitmapHeap);
SkSafeUnref(fBitmapHeap);
fBitmapHeap = NULL;
« no previous file with comments | « src/core/SkPictureData.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698