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

Side by Side Diff: src/core/SkWriteBuffer.cpp

Issue 1074983003: add SkPixmap and external locking to bitmaps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 7 months 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 unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkWriteBuffer.h" 9 #include "SkWriteBuffer.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Assumes that if the client did not set a serializer, they are 191 // Assumes that if the client did not set a serializer, they are
192 // happy to get the encoded data. 192 // happy to get the encoded data.
193 if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingDa ta->data(), 193 if (!fPixelSerializer || fPixelSerializer->useEncodedData(existingDa ta->data(),
194 existingDa ta->size())) { 194 existingDa ta->size())) {
195 write_encoded_bitmap(this, existingData, bitmap.pixelRefOrigin() ); 195 write_encoded_bitmap(this, existingData, bitmap.pixelRefOrigin() );
196 return; 196 return;
197 } 197 }
198 } 198 }
199 199
200 // see if the caller wants to manually encode 200 // see if the caller wants to manually encode
201 if (fPixelSerializer) { 201 SkAutoPixmapUnlock result;
202 if (fPixelSerializer && bitmap.requestLock(&result)) {
203 const SkPixmap& pmap = result.pixmap();
202 SkASSERT(NULL == fBitmapHeap); 204 SkASSERT(NULL == fBitmapHeap);
203 SkAutoLockPixels alp(bitmap); 205 SkAutoDataUnref data(fPixelSerializer->encodePixels(pmap.info(),
204 SkAutoDataUnref data(fPixelSerializer->encodePixels(bitmap.info(), 206 pmap.addr(),
205 bitmap.getPixels (), 207 pmap.rowBytes()) );
206 bitmap.rowBytes( )));
207 if (data.get() != NULL) { 208 if (data.get() != NULL) {
208 // if we have to "encode" the bitmap, then we assume there is no 209 // if we have to "encode" the bitmap, then we assume there is no
209 // offset to share, since we are effectively creating a new pixe lref 210 // offset to share, since we are effectively creating a new pixe lref
210 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); 211 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0));
211 return; 212 return;
212 } 213 }
213 } 214 }
214 } 215 }
215 216
216 this->writeUInt(0); // signal raw pixels 217 this->writeUInt(0); // signal raw pixels
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // make room for the size of the flattened object 321 // make room for the size of the flattened object
321 (void)fWriter.reserve(sizeof(uint32_t)); 322 (void)fWriter.reserve(sizeof(uint32_t));
322 // record the current size, so we can subtract after the object writes. 323 // record the current size, so we can subtract after the object writes.
323 size_t offset = fWriter.bytesWritten(); 324 size_t offset = fWriter.bytesWritten();
324 // now flatten the object 325 // now flatten the object
325 flattenable->flatten(*this); 326 flattenable->flatten(*this);
326 size_t objSize = fWriter.bytesWritten() - offset; 327 size_t objSize = fWriter.bytesWritten() - offset;
327 // record the obj's size 328 // record the obj's size
328 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); 329 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize));
329 } 330 }
OLDNEW
« src/core/SkPixelRef.cpp ('K') | « src/core/SkPixmap.cpp ('k') | tests/BitmapCopyTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698