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

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

Issue 249453002: First step in pulling SkPicturePlayback & SkPictureRecord out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: cleanup Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkPicturePlayback.h ('k') | src/core/SkPictureRecord.h » ('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 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include <new> 7 #include <new>
8 #include "SkBBoxHierarchy.h" 8 #include "SkBBoxHierarchy.h"
9 #include "SkPicturePlayback.h" 9 #include "SkPicturePlayback.h"
10 #include "SkPictureRecord.h" 10 #include "SkPictureRecord.h"
11 #include "SkPictureStateTree.h" 11 #include "SkPictureStateTree.h"
12 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkTypeface.h" 13 #include "SkTypeface.h"
14 #include "SkTSort.h" 14 #include "SkTSort.h"
15 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
16 16
17 template <typename T> int SafeCount(const T* obj) { 17 template <typename T> int SafeCount(const T* obj) {
18 return obj ? obj->count() : 0; 18 return obj ? obj->count() : 0;
19 } 19 }
20 20
21 /* Define this to spew out a debug statement whenever we skip the remainder of 21 /* Define this to spew out a debug statement whenever we skip the remainder of
22 a save/restore block because a clip... command returned false (empty). 22 a save/restore block because a clip... command returned false (empty).
23 */ 23 */
24 #define SPEW_CLIP_SKIPPINGx 24 #define SPEW_CLIP_SKIPPINGx
25 25
26 SkPicturePlayback::SkPicturePlayback(const SkPictInfo& info) : fInfo(info) { 26 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture, const SkPictInfo& info)
27 : fPicture(picture)
28 , fInfo(info) {
27 this->init(); 29 this->init();
28 } 30 }
29 31
30 SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, 32 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture,
33 const SkPictureRecord& record,
31 const SkPictInfo& info, 34 const SkPictInfo& info,
32 bool deepCopy) 35 bool deepCopy)
33 : fInfo(info) { 36 : fPicture(picture)
37 , fInfo(info) {
34 #ifdef SK_DEBUG_SIZE 38 #ifdef SK_DEBUG_SIZE
35 size_t overallBytes, bitmapBytes, matricesBytes, 39 size_t overallBytes, bitmapBytes, matricesBytes,
36 paintBytes, pathBytes, pictureBytes, regionBytes; 40 paintBytes, pathBytes, pictureBytes, regionBytes;
37 int bitmaps = record.bitmaps(&bitmapBytes); 41 int bitmaps = record.bitmaps(&bitmapBytes);
38 int matrices = record.matrices(&matricesBytes); 42 int matrices = record.matrices(&matricesBytes);
39 int paints = record.paints(&paintBytes); 43 int paints = record.paints(&paintBytes);
40 int paths = record.paths(&pathBytes); 44 int paths = record.paths(&pathBytes);
41 int pictures = record.pictures(&pictureBytes); 45 int pictures = record.pictures(&pictureBytes);
42 int regions = record.regions(&regionBytes); 46 int regions = record.regions(&regionBytes);
43 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(), 47 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 fBoundingHierarchy->flushDeferredInserts(); 92 fBoundingHierarchy->flushDeferredInserts();
89 } 93 }
90 94
91 // copy over the refcnt dictionary to our reader 95 // copy over the refcnt dictionary to our reader
92 record.fFlattenableHeap.setupPlaybacks(); 96 record.fFlattenableHeap.setupPlaybacks();
93 97
94 fBitmaps = record.fBitmapHeap->extractBitmaps(); 98 fBitmaps = record.fBitmapHeap->extractBitmaps();
95 fPaints = record.fPaints.unflattenToArray(); 99 fPaints = record.fPaints.unflattenToArray();
96 100
97 fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap)); 101 fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap));
98 fPathHeap.reset(SkSafeRef(record.fPathHeap));
99 102
100 // ensure that the paths bounds are pre-computed 103 picture->initForPlayback();
101 if (fPathHeap.get()) {
102 for (int i = 0; i < fPathHeap->count(); i++) {
103 (*fPathHeap)[i].updateBoundsCache();
104 }
105 }
106 104
107 const SkTDArray<SkPicture* >& pictures = record.getPictureRefs(); 105 const SkTDArray<SkPicture* >& pictures = record.getPictureRefs();
108 fPictureCount = pictures.count(); 106 fPictureCount = pictures.count();
109 if (fPictureCount > 0) { 107 if (fPictureCount > 0) {
110 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount); 108 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount);
111 for (int i = 0; i < fPictureCount; i++) { 109 for (int i = 0; i < fPictureCount; i++) {
112 if (deepCopy) { 110 if (deepCopy) {
113 fPictureRefs[i] = pictures[i]->clone(); 111 fPictureRefs[i] = pictures[i]->clone();
114 } else { 112 } else {
115 fPictureRefs[i] = pictures[i]; 113 fPictureRefs[i] = pictures[i];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 */ 151 */
154 152
155 return paint.getShader() || 153 return paint.getShader() ||
156 #ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API 154 #ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
157 paint.getRasterizer() || 155 paint.getRasterizer() ||
158 #endif 156 #endif
159 paint.getLooper() || // needs to hide its addLayer... 157 paint.getLooper() || // needs to hide its addLayer...
160 paint.getImageFilter(); 158 paint.getImageFilter();
161 } 159 }
162 160
163 SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInf o* deepCopyInfo) 161 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture, const SkPicturePl ayback& src,
164 : fInfo(src.fInfo) { 162 SkPictCopyInfo* deepCopyInfo)
163 : fPicture(picture)
164 , fInfo(src.fInfo) {
165 this->init(); 165 this->init();
166 166
167 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); 167 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get()));
168 fPathHeap.reset(SkSafeRef(src.fPathHeap.get()));
169 168
170 fOpData = SkSafeRef(src.fOpData); 169 fOpData = SkSafeRef(src.fOpData);
171 170
172 fBoundingHierarchy = src.fBoundingHierarchy; 171 fBoundingHierarchy = src.fBoundingHierarchy;
173 fStateTree = src.fStateTree; 172 fStateTree = src.fStateTree;
174 173
175 SkSafeRef(fBoundingHierarchy); 174 SkSafeRef(fBoundingHierarchy);
176 SkSafeRef(fStateTree); 175 SkSafeRef(fStateTree);
177 176
178 if (deepCopyInfo) { 177 if (deepCopyInfo) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 278
280 for (int i = 0; i < fPictureCount; i++) { 279 for (int i = 0; i < fPictureCount; i++) {
281 fPictureRefs[i]->unref(); 280 fPictureRefs[i]->unref();
282 } 281 }
283 SkDELETE_ARRAY(fPictureRefs); 282 SkDELETE_ARRAY(fPictureRefs);
284 283
285 SkDELETE(fFactoryPlayback); 284 SkDELETE(fFactoryPlayback);
286 } 285 }
287 286
288 void SkPicturePlayback::dumpSize() const { 287 void SkPicturePlayback::dumpSize() const {
289 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d] paths=%d\n ", 288 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d]\n",
290 fOpData->size(), 289 fOpData->size(),
291 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap), 290 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap),
292 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint), 291 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint));
293 SafeCount(fPathHeap.get())); 292 fPicture->dumpSize();
294 } 293 }
295 294
296 bool SkPicturePlayback::containsBitmaps() const { 295 bool SkPicturePlayback::containsBitmaps() const {
297 if (fBitmaps && fBitmaps->count() > 0) { 296 if (fBitmaps && fBitmaps->count() > 0) {
298 return true; 297 return true;
299 } 298 }
300 for (int i = 0; i < fPictureCount; ++i) { 299 for (int i = 0; i < fPictureCount; ++i) {
301 if (fPictureRefs[i]->willPlayBackBitmaps()) { 300 if (fPictureRefs[i]->willPlayBackBitmaps()) {
302 return true; 301 return true;
303 } 302 }
304 } 303 }
305 return false; 304 return false;
306 } 305 }
307 306
308 /////////////////////////////////////////////////////////////////////////////// 307 ///////////////////////////////////////////////////////////////////////////////
309 /////////////////////////////////////////////////////////////////////////////// 308 ///////////////////////////////////////////////////////////////////////////////
310 309
311 #include "SkStream.h" 310 #include "SkStream.h"
312 311
313 static void write_tag_size(SkWriteBuffer& buffer, uint32_t tag, size_t size) {
314 buffer.writeUInt(tag);
315 buffer.writeUInt(SkToU32(size));
316 }
317
318 static void write_tag_size(SkWStream* stream, uint32_t tag, size_t size) {
319 stream->write32(tag);
320 stream->write32(SkToU32(size));
321 }
322
323 static size_t compute_chunk_size(SkFlattenable::Factory* array, int count) { 312 static size_t compute_chunk_size(SkFlattenable::Factory* array, int count) {
324 size_t size = 4; // for 'count' 313 size_t size = 4; // for 'count'
325 314
326 for (int i = 0; i < count; i++) { 315 for (int i = 0; i < count; i++) {
327 const char* name = SkFlattenable::FactoryToName(array[i]); 316 const char* name = SkFlattenable::FactoryToName(array[i]);
328 if (NULL == name || 0 == *name) { 317 if (NULL == name || 0 == *name) {
329 size += SkWStream::SizeOfPackedUInt(0); 318 size += SkWStream::SizeOfPackedUInt(0);
330 } else { 319 } else {
331 size_t len = strlen(name); 320 size_t len = strlen(name);
332 size += SkWStream::SizeOfPackedUInt(len); 321 size += SkWStream::SizeOfPackedUInt(len);
333 size += len; 322 size += len;
334 } 323 }
335 } 324 }
336 325
337 return size; 326 return size;
338 } 327 }
339 328
340 static void write_factories(SkWStream* stream, const SkFactorySet& rec) { 329 void SkPicturePlayback::WriteFactories(SkWStream* stream, const SkFactorySet& re c) {
341 int count = rec.count(); 330 int count = rec.count();
342 331
343 SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count); 332 SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count);
344 SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get(); 333 SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get();
345 rec.copyToArray(array); 334 rec.copyToArray(array);
346 335
347 size_t size = compute_chunk_size(array, count); 336 size_t size = compute_chunk_size(array, count);
348 337
349 // TODO: write_tag_size should really take a size_t 338 // TODO: write_tag_size should really take a size_t
350 write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size); 339 SkPicture::WriteTagSize(stream, SK_PICT_FACTORY_TAG, (uint32_t) size);
351 SkDEBUGCODE(size_t start = stream->bytesWritten()); 340 SkDEBUGCODE(size_t start = stream->bytesWritten());
352 stream->write32(count); 341 stream->write32(count);
353 342
354 for (int i = 0; i < count; i++) { 343 for (int i = 0; i < count; i++) {
355 const char* name = SkFlattenable::FactoryToName(array[i]); 344 const char* name = SkFlattenable::FactoryToName(array[i]);
356 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name); 345 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name);
357 if (NULL == name || 0 == *name) { 346 if (NULL == name || 0 == *name) {
358 stream->writePackedUInt(0); 347 stream->writePackedUInt(0);
359 } else { 348 } else {
360 size_t len = strlen(name); 349 size_t len = strlen(name);
361 stream->writePackedUInt(len); 350 stream->writePackedUInt(len);
362 stream->write(name, len); 351 stream->write(name, len);
363 } 352 }
364 } 353 }
365 354
366 SkASSERT(size == (stream->bytesWritten() - start)); 355 SkASSERT(size == (stream->bytesWritten() - start));
367 } 356 }
368 357
369 static void write_typefaces(SkWStream* stream, const SkRefCntSet& rec) { 358 void SkPicturePlayback::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec ) {
370 int count = rec.count(); 359 int count = rec.count();
371 360
372 write_tag_size(stream, SK_PICT_TYPEFACE_TAG, count); 361 SkPicture::WriteTagSize(stream, SK_PICT_TYPEFACE_TAG, count);
373 362
374 SkAutoSTMalloc<16, SkTypeface*> storage(count); 363 SkAutoSTMalloc<16, SkTypeface*> storage(count);
375 SkTypeface** array = (SkTypeface**)storage.get(); 364 SkTypeface** array = (SkTypeface**)storage.get();
376 rec.copyToArray((SkRefCnt**)array); 365 rec.copyToArray((SkRefCnt**)array);
377 366
378 for (int i = 0; i < count; i++) { 367 for (int i = 0; i < count; i++) {
379 array[i]->serialize(stream); 368 array[i]->serialize(stream);
380 } 369 }
381 } 370 }
382 371
383 void SkPicturePlayback::flattenToBuffer(SkWriteBuffer& buffer) const { 372 void SkPicturePlayback::flattenToBuffer(SkWriteBuffer& buffer) const {
384 int i, n; 373 int i, n;
385 374
386 if ((n = SafeCount(fBitmaps)) > 0) { 375 if ((n = SafeCount(fBitmaps)) > 0) {
387 write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); 376 SkPicture::WriteTagSize(buffer, SK_PICT_BITMAP_BUFFER_TAG, n);
388 for (i = 0; i < n; i++) { 377 for (i = 0; i < n; i++) {
389 buffer.writeBitmap((*fBitmaps)[i]); 378 buffer.writeBitmap((*fBitmaps)[i]);
390 } 379 }
391 } 380 }
392 381
393 if ((n = SafeCount(fPaints)) > 0) { 382 if ((n = SafeCount(fPaints)) > 0) {
394 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); 383 SkPicture::WriteTagSize(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
395 for (i = 0; i < n; i++) { 384 for (i = 0; i < n; i++) {
396 buffer.writePaint((*fPaints)[i]); 385 buffer.writePaint((*fPaints)[i]);
397 } 386 }
398 } 387 }
399 388
400 if ((n = SafeCount(fPathHeap.get())) > 0) { 389 fPicture->flattenToBuffer(buffer);
401 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n);
402 fPathHeap->flatten(buffer);
403 }
404 } 390 }
405 391
406 void SkPicturePlayback::serialize(SkWStream* stream, 392 void SkPicturePlayback::serialize(SkWStream* stream,
407 SkPicture::EncodeBitmap encoder) const { 393 SkPicture::EncodeBitmap encoder) const {
408 write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size()); 394 SkPicture::WriteTagSize(stream, SK_PICT_READER_TAG, fOpData->size());
409 stream->write(fOpData->bytes(), fOpData->size()); 395 stream->write(fOpData->bytes(), fOpData->size());
410 396
411 if (fPictureCount > 0) { 397 if (fPictureCount > 0) {
412 write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount); 398 SkPicture::WriteTagSize(stream, SK_PICT_PICTURE_TAG, fPictureCount);
413 for (int i = 0; i < fPictureCount; i++) { 399 for (int i = 0; i < fPictureCount; i++) {
414 fPictureRefs[i]->serialize(stream, encoder); 400 fPictureRefs[i]->serialize(stream, encoder);
415 } 401 }
416 } 402 }
417 403
418 // Write some of our data into a writebuffer, and then serialize that 404 // Write some of our data into a writebuffer, and then serialize that
419 // into our stream 405 // into our stream
420 { 406 {
421 SkRefCntSet typefaceSet; 407 SkRefCntSet typefaceSet;
422 SkFactorySet factSet; 408 SkFactorySet factSet;
423 409
424 SkWriteBuffer buffer(SkWriteBuffer::kCrossProcess_Flag); 410 SkWriteBuffer buffer(SkWriteBuffer::kCrossProcess_Flag);
425 buffer.setTypefaceRecorder(&typefaceSet); 411 buffer.setTypefaceRecorder(&typefaceSet);
426 buffer.setFactoryRecorder(&factSet); 412 buffer.setFactoryRecorder(&factSet);
427 buffer.setBitmapEncoder(encoder); 413 buffer.setBitmapEncoder(encoder);
428 414
429 this->flattenToBuffer(buffer); 415 this->flattenToBuffer(buffer);
430 416
431 // We have to write these two sets into the stream *before* we write 417 // We have to write these two sets into the stream *before* we write
432 // the buffer, since parsing that buffer will require that we already 418 // the buffer, since parsing that buffer will require that we already
433 // have these sets available to use. 419 // have these sets available to use.
434 write_factories(stream, factSet); 420 WriteFactories(stream, factSet);
435 write_typefaces(stream, typefaceSet); 421 WriteTypefaces(stream, typefaceSet);
436 422
437 write_tag_size(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWritten()); 423 SkPicture::WriteTagSize(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWri tten());
438 buffer.writeToStream(stream); 424 buffer.writeToStream(stream);
439 } 425 }
440 426
441 stream->write32(SK_PICT_EOF_TAG); 427 stream->write32(SK_PICT_EOF_TAG);
442 } 428 }
443 429
444 void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const { 430 void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const {
445 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size()); 431 SkPicture::WriteTagSize(buffer, SK_PICT_READER_TAG, fOpData->size());
446 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); 432 buffer.writeByteArray(fOpData->bytes(), fOpData->size());
447 433
448 if (fPictureCount > 0) { 434 if (fPictureCount > 0) {
449 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount); 435 SkPicture::WriteTagSize(buffer, SK_PICT_PICTURE_TAG, fPictureCount);
450 for (int i = 0; i < fPictureCount; i++) { 436 for (int i = 0; i < fPictureCount; i++) {
451 fPictureRefs[i]->flatten(buffer); 437 fPictureRefs[i]->flatten(buffer);
452 } 438 }
453 } 439 }
454 440
455 // Write this picture playback's data into a writebuffer 441 // Write this picture playback's data into a writebuffer
456 this->flattenToBuffer(buffer); 442 this->flattenToBuffer(buffer);
457 buffer.write32(SK_PICT_EOF_TAG); 443 buffer.write32(SK_PICT_EOF_TAG);
458 } 444 }
459 445
(...skipping 15 matching lines...) Expand all
475 461
476 uint32_t rbMask = 0; 462 uint32_t rbMask = 0;
477 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { 463 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) {
478 if (pictInfoFlags & gSD[i].fSrc) { 464 if (pictInfoFlags & gSD[i].fSrc) {
479 rbMask |= gSD[i].fDst; 465 rbMask |= gSD[i].fDst;
480 } 466 }
481 } 467 }
482 return rbMask; 468 return rbMask;
483 } 469 }
484 470
485 bool SkPicturePlayback::parseStreamTag(SkStream* stream, 471 bool SkPicturePlayback::parseStreamTag(SkPicture* picture,
472 SkStream* stream,
486 uint32_t tag, 473 uint32_t tag,
487 uint32_t size, 474 uint32_t size,
488 SkPicture::InstallPixelRefProc proc) { 475 SkPicture::InstallPixelRefProc proc) {
489 /* 476 /*
490 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen 477 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen
491 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required 478 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required
492 * but if they are present, they need to have been seen before the buffer. 479 * but if they are present, they need to have been seen before the buffer.
493 * 480 *
494 * We assert that if/when we see either of these, that we have not yet seen 481 * We assert that if/when we see either of these, that we have not yet seen
495 * the buffer tag, because if we have, then its too-late to deal with the 482 * the buffer tag, because if we have, then its too-late to deal with the
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags)); 564 buffer.setFlags(pictInfoFlagsToReadBufferFlags(fInfo.fFlags));
578 buffer.setPictureVersion(fInfo.fVersion); 565 buffer.setPictureVersion(fInfo.fVersion);
579 566
580 fFactoryPlayback->setupBuffer(buffer); 567 fFactoryPlayback->setupBuffer(buffer);
581 fTFPlayback.setupBuffer(buffer); 568 fTFPlayback.setupBuffer(buffer);
582 buffer.setBitmapDecoder(proc); 569 buffer.setBitmapDecoder(proc);
583 570
584 while (!buffer.eof()) { 571 while (!buffer.eof()) {
585 tag = buffer.readUInt(); 572 tag = buffer.readUInt();
586 size = buffer.readUInt(); 573 size = buffer.readUInt();
587 if (!this->parseBufferTag(buffer, tag, size)) { 574 if (!this->parseBufferTag(picture, buffer, tag, size)) {
588 return false; 575 return false;
589 } 576 }
590 } 577 }
591 SkDEBUGCODE(haveBuffer = true;) 578 SkDEBUGCODE(haveBuffer = true;)
592 } break; 579 } break;
593 } 580 }
594 return true; // success 581 return true; // success
595 } 582 }
596 583
597 bool SkPicturePlayback::parseBufferTag(SkReadBuffer& buffer, 584 bool SkPicturePlayback::parseBufferTag(SkPicture* picture,
585 SkReadBuffer& buffer,
598 uint32_t tag, uint32_t size) { 586 uint32_t tag, uint32_t size) {
599 switch (tag) { 587 switch (tag) {
600 case SK_PICT_BITMAP_BUFFER_TAG: { 588 case SK_PICT_BITMAP_BUFFER_TAG: {
601 const int count = SkToInt(size); 589 const int count = SkToInt(size);
602 fBitmaps = SkTRefArray<SkBitmap>::Create(size); 590 fBitmaps = SkTRefArray<SkBitmap>::Create(size);
603 for (int i = 0; i < count; ++i) { 591 for (int i = 0; i < count; ++i) {
604 SkBitmap* bm = &fBitmaps->writableAt(i); 592 SkBitmap* bm = &fBitmaps->writableAt(i);
605 buffer.readBitmap(bm); 593 buffer.readBitmap(bm);
606 bm->setImmutable(); 594 bm->setImmutable();
607 } 595 }
608 } break; 596 } break;
609 case SK_PICT_PAINT_BUFFER_TAG: { 597 case SK_PICT_PAINT_BUFFER_TAG: {
610 const int count = SkToInt(size); 598 const int count = SkToInt(size);
611 fPaints = SkTRefArray<SkPaint>::Create(size); 599 fPaints = SkTRefArray<SkPaint>::Create(size);
612 for (int i = 0; i < count; ++i) { 600 for (int i = 0; i < count; ++i) {
613 buffer.readPaint(&fPaints->writableAt(i)); 601 buffer.readPaint(&fPaints->writableAt(i));
614 } 602 }
615 } break; 603 } break;
616 case SK_PICT_PATH_BUFFER_TAG: 604 case SK_PICT_PATH_BUFFER_TAG:
617 if (size > 0) { 605 picture->parseBufferTag(buffer, tag, size);
618 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer)));
619 }
620 break; 606 break;
621 case SK_PICT_READER_TAG: { 607 case SK_PICT_READER_TAG: {
622 SkAutoMalloc storage(size); 608 SkAutoMalloc storage(size);
623 if (!buffer.readByteArray(storage.get(), size) || 609 if (!buffer.readByteArray(storage.get(), size) ||
624 !buffer.validate(NULL == fOpData)) { 610 !buffer.validate(NULL == fOpData)) {
625 return false; 611 return false;
626 } 612 }
627 SkASSERT(NULL == fOpData); 613 SkASSERT(NULL == fOpData);
628 fOpData = SkData::NewFromMalloc(storage.detach(), size); 614 fOpData = SkData::NewFromMalloc(storage.detach(), size);
629 } break; 615 } break;
(...skipping 23 matching lines...) Expand all
653 return false; 639 return false;
654 } 640 }
655 } break; 641 } break;
656 default: 642 default:
657 // The tag was invalid. 643 // The tag was invalid.
658 return false; 644 return false;
659 } 645 }
660 return true; // success 646 return true; // success
661 } 647 }
662 648
663 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, 649 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkPicture* picture,
650 SkStream* stream,
664 const SkPictInfo& info, 651 const SkPictInfo& info,
665 SkPicture::InstallPixelRe fProc proc) { 652 SkPicture::InstallPixelRe fProc proc) {
666 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf o))); 653 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (pic ture, info)));
667 654
668 if (!playback->parseStream(stream, proc)) { 655 if (!playback->parseStream(picture, stream, proc)) {
669 return NULL; 656 return NULL;
670 } 657 }
671 return playback.detach(); 658 return playback.detach();
672 } 659 }
673 660
674 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer, 661 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkPicture* picture,
662 SkReadBuffer& buffer,
675 const SkPictInfo& info) { 663 const SkPictInfo& info) {
676 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf o))); 664 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (pic ture, info)));
677 buffer.setPictureVersion(info.fVersion); 665 buffer.setPictureVersion(info.fVersion);
678 666
679 if (!playback->parseBuffer(buffer)) { 667 if (!playback->parseBuffer(picture, buffer)) {
680 return NULL; 668 return NULL;
681 } 669 }
682 return playback.detach(); 670 return playback.detach();
683 } 671 }
684 672
685 bool SkPicturePlayback::parseStream(SkStream* stream, 673 bool SkPicturePlayback::parseStream(SkPicture* picture,
674 SkStream* stream,
686 SkPicture::InstallPixelRefProc proc) { 675 SkPicture::InstallPixelRefProc proc) {
687 for (;;) { 676 for (;;) {
688 uint32_t tag = stream->readU32(); 677 uint32_t tag = stream->readU32();
689 if (SK_PICT_EOF_TAG == tag) { 678 if (SK_PICT_EOF_TAG == tag) {
690 break; 679 break;
691 } 680 }
692 681
693 uint32_t size = stream->readU32(); 682 uint32_t size = stream->readU32();
694 if (!this->parseStreamTag(stream, tag, size, proc)) { 683 if (!this->parseStreamTag(picture, stream, tag, size, proc)) {
695 return false; // we're invalid 684 return false; // we're invalid
696 } 685 }
697 } 686 }
698 return true; 687 return true;
699 } 688 }
700 689
701 bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) { 690 bool SkPicturePlayback::parseBuffer(SkPicture* picture, SkReadBuffer& buffer) {
702 for (;;) { 691 for (;;) {
703 uint32_t tag = buffer.readUInt(); 692 uint32_t tag = buffer.readUInt();
704 if (SK_PICT_EOF_TAG == tag) { 693 if (SK_PICT_EOF_TAG == tag) {
705 break; 694 break;
706 } 695 }
707 696
708 uint32_t size = buffer.readUInt(); 697 uint32_t size = buffer.readUInt();
709 if (!this->parseBufferTag(buffer, tag, size)) { 698 if (!this->parseBufferTag(picture, buffer, tag, size)) {
710 return false; // we're invalid 699 return false; // we're invalid
711 } 700 }
712 } 701 }
713 return true; 702 return true;
714 } 703 }
715 704
716 /////////////////////////////////////////////////////////////////////////////// 705 ///////////////////////////////////////////////////////////////////////////////
717 /////////////////////////////////////////////////////////////////////////////// 706 ///////////////////////////////////////////////////////////////////////////////
718 707
719 #ifdef SPEW_CLIP_SKIPPING 708 #ifdef SPEW_CLIP_SKIPPING
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 for (index = 0; index < fPictureCount; index++) 1771 for (index = 0; index < fPictureCount; index++)
1783 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), 1772 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1784 "picture%p, ", fPictureRefs[index]); 1773 "picture%p, ", fPictureRefs[index]);
1785 if (fPictureCount > 0) 1774 if (fPictureCount > 0)
1786 SkDebugf("%s0};\n", pBuffer); 1775 SkDebugf("%s0};\n", pBuffer);
1787 1776
1788 const_cast<SkPicturePlayback*>(this)->dumpStream(); 1777 const_cast<SkPicturePlayback*>(this)->dumpStream();
1789 } 1778 }
1790 1779
1791 #endif 1780 #endif
OLDNEW
« no previous file with comments | « src/core/SkPicturePlayback.h ('k') | src/core/SkPictureRecord.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698