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

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

Issue 1373683003: change pixel-serializer to support reencoding existing data Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: I hate this warning Created 5 years, 2 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
« no previous file with comments | « src/core/SkPixelSerializer.cpp ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // unflattened (i.e. stale) instance of a similar flattenable is in the dictionary 179 // unflattened (i.e. stale) instance of a similar flattenable is in the dictionary
180 // and the instance currently being written is re-using the same slot fr om the 180 // and the instance currently being written is re-using the same slot fr om the
181 // bitmap heap. 181 // bitmap heap.
182 fWriter.write32(bitmap.getGenerationID()); 182 fWriter.write32(bitmap.getGenerationID());
183 return; 183 return;
184 } 184 }
185 185
186 SkPixelRef* pixelRef = bitmap.pixelRef(); 186 SkPixelRef* pixelRef = bitmap.pixelRef();
187 if (pixelRef) { 187 if (pixelRef) {
188 // see if the pixelref already has an encoded version 188 // see if the pixelref already has an encoded version
189 SkAutoDataUnref existingData(pixelRef->refEncodedData()); 189 SkAutoDataUnref encodedData(pixelRef->refEncodedData());
190 if (existingData.get() != nullptr) { 190 if (encodedData) {
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) {
194 existingDa ta->size())) { 194 encodedData.reset(fPixelSerializer->reencodeData(encodedData));
195 write_encoded_bitmap(this, existingData, bitmap.pixelRefOrigin() ); 195 }
196 if (encodedData) {
197 write_encoded_bitmap(this, encodedData, bitmap.pixelRefOrigin()) ;
196 return; 198 return;
197 } 199 }
198 } 200 }
199 201
200 // see if the caller wants to manually encode 202 // see if the caller wants to manually encode
201 SkAutoPixmapUnlock result; 203 SkAutoPixmapUnlock result;
202 if (fPixelSerializer && bitmap.requestLock(&result)) { 204 if (fPixelSerializer && bitmap.requestLock(&result)) {
203 const SkPixmap& pmap = result.pixmap();
204 SkASSERT(nullptr == fBitmapHeap); 205 SkASSERT(nullptr == fBitmapHeap);
205 SkAutoDataUnref data(fPixelSerializer->encodePixels(pmap.info(), 206 SkAutoDataUnref data(fPixelSerializer->encodePixels(result.pixmap()) );
206 pmap.addr(), 207 if (data) {
207 pmap.rowBytes()) );
208 if (data.get() != nullptr) {
209 // if we have to "encode" the bitmap, then we assume there is no 208 // if we have to "encode" the bitmap, then we assume there is no
210 // offset to share, since we are effectively creating a new pixe lref 209 // offset to share, since we are effectively creating a new pixe lref
211 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0)); 210 write_encoded_bitmap(this, data, SkIPoint::Make(0, 0));
212 return; 211 return;
213 } 212 }
214 } 213 }
215 } 214 }
216 215
217 this->writeUInt(0); // signal raw pixels 216 this->writeUInt(0); // signal raw pixels
218 SkBitmap::WriteRawPixels(this, bitmap); 217 SkBitmap::WriteRawPixels(this, bitmap);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // make room for the size of the flattened object 333 // make room for the size of the flattened object
335 (void)fWriter.reserve(sizeof(uint32_t)); 334 (void)fWriter.reserve(sizeof(uint32_t));
336 // record the current size, so we can subtract after the object writes. 335 // record the current size, so we can subtract after the object writes.
337 size_t offset = fWriter.bytesWritten(); 336 size_t offset = fWriter.bytesWritten();
338 // now flatten the object 337 // now flatten the object
339 flattenable->flatten(*this); 338 flattenable->flatten(*this);
340 size_t objSize = fWriter.bytesWritten() - offset; 339 size_t objSize = fWriter.bytesWritten() - offset;
341 // record the obj's size 340 // record the obj's size
342 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize)); 341 fWriter.overwriteTAt(offset - sizeof(uint32_t), SkToU32(objSize));
343 } 342 }
OLDNEW
« no previous file with comments | « src/core/SkPixelSerializer.cpp ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698