OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "SkPictureRecord.h" | 8 #include "SkPictureRecord.h" |
9 #include "SkTSearch.h" | 9 #include "SkTSearch.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
11 #include "SkRRect.h" | 11 #include "SkRRect.h" |
12 #include "SkBBoxHierarchy.h" | 12 #include "SkBBoxHierarchy.h" |
13 #include "SkDevice.h" | 13 #include "SkDevice.h" |
14 #include "SkPictureStateTree.h" | 14 #include "SkPictureStateTree.h" |
15 | 15 |
16 #define MIN_WRITER_SIZE 16384 | 16 #define MIN_WRITER_SIZE 16384 |
17 #define HEAP_BLOCK_SIZE 4096 | 17 #define HEAP_BLOCK_SIZE 4096 |
18 | 18 |
19 enum { | 19 enum { |
20 // just need a value that save or getSaveCount would never return | 20 // just need a value that save or getSaveCount would never return |
21 kNoInitialSave = -1, | 21 kNoInitialSave = -1, |
22 }; | 22 }; |
23 | 23 |
24 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c. | 24 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et c. |
25 static int const kUInt32Size = 4; | 25 static int const kUInt32Size = 4; |
26 | 26 |
27 static const uint32_t kSaveSize = 2 * kUInt32Size; | |
27 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; | 28 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; |
28 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect ); | 29 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect ); |
29 | 30 |
30 SkPictureRecord::SkPictureRecord(uint32_t flags, SkDevice* device) : | 31 SkPictureRecord::SkPictureRecord(uint32_t flags, SkDevice* device) : |
31 INHERITED(device), | 32 INHERITED(device), |
32 fBoundingHierarchy(NULL), | 33 fBoundingHierarchy(NULL), |
33 fStateTree(NULL), | 34 fStateTree(NULL), |
34 fFlattenableHeap(HEAP_BLOCK_SIZE), | 35 fFlattenableHeap(HEAP_BLOCK_SIZE), |
35 fMatrices(&fFlattenableHeap), | 36 fMatrices(&fFlattenableHeap), |
36 fPaints(&fFlattenableHeap), | 37 fPaints(&fFlattenableHeap), |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 return this->INHERITED::setDevice(device); | 143 return this->INHERITED::setDevice(device); |
143 } | 144 } |
144 | 145 |
145 int SkPictureRecord::save(SaveFlags flags) { | 146 int SkPictureRecord::save(SaveFlags flags) { |
146 // record the offset to us, making it non-positive to distinguish a save | 147 // record the offset to us, making it non-positive to distinguish a save |
147 // from a clip entry. | 148 // from a clip entry. |
148 fRestoreOffsetStack.push(-(int32_t)fWriter.size()); | 149 fRestoreOffsetStack.push(-(int32_t)fWriter.size()); |
149 | 150 |
150 // op + flags | 151 // op + flags |
151 uint32_t size = 2 * kUInt32Size; | 152 uint32_t size = 2 * kUInt32Size; |
153 SkASSERT(kSaveSize == size); | |
154 | |
152 uint32_t initialOffset = this->addDraw(SAVE, &size); | 155 uint32_t initialOffset = this->addDraw(SAVE, &size); |
153 addInt(flags); | 156 addInt(flags); |
154 | 157 |
155 validate(initialOffset, size); | 158 validate(initialOffset, size); |
156 return this->INHERITED::save(flags); | 159 return this->INHERITED::save(flags); |
157 } | 160 } |
158 | 161 |
159 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, | 162 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, |
160 SaveFlags flags) { | 163 SaveFlags flags) { |
161 // record the offset to us, making it non-positive to distinguish a save | 164 // record the offset to us, making it non-positive to distinguish a save |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 SkPaintDictionary* paintDict) { | 464 SkPaintDictionary* paintDict) { |
462 #ifdef TRACK_COLLAPSE_STATS | 465 #ifdef TRACK_COLLAPSE_STATS |
463 gCollapseCalls += 1; | 466 gCollapseCalls += 1; |
464 #endif | 467 #endif |
465 | 468 |
466 int32_t restoreOffset = (int32_t)writer->size(); | 469 int32_t restoreOffset = (int32_t)writer->size(); |
467 | 470 |
468 // back up to the save block | 471 // back up to the save block |
469 while (offset > 0) { | 472 while (offset > 0) { |
470 offset = *writer->peek32(offset); | 473 offset = *writer->peek32(offset); |
471 } | 474 } |
robertphillips
2013/08/13 13:45:55
What is this?
| |
475 kSaveLayerNoBoundsSize; | |
472 | 476 |
473 // now offset points to a save | 477 // now offset points to a save |
474 offset = -offset; | 478 offset = -offset; |
475 uint32_t opSize; | 479 uint32_t opSize; |
476 DrawType op = peek_op_and_size(writer, offset, &opSize); | 480 DrawType op = peek_op_and_size(writer, offset, &opSize); |
477 if (SAVE_LAYER == op) { | 481 if (SAVE_LAYER == op) { |
478 // not ready to cull these out yet (mrr) | 482 // not ready to cull these out yet (mrr) |
479 return false; | 483 return false; |
480 } | 484 } |
481 SkASSERT(SAVE == op); | 485 SkASSERT(SAVE == op); |
486 SkASSERT(kSaveSize == opSize); | |
487 | |
488 // get the save flag (last 4-bytes of the space allocated for the opSize) | |
489 SkCanvas::SaveFlags saveFlag = (SkCanvas::SaveFlags) *writer->peek32(offset+ 4); | |
490 if (SkCanvas::kMatrixClip_SaveFlag != (SkCanvas::kMatrixClip_SaveFlag & save Flag)) { | |
491 // This function's optimization is only correct for kMatrixClip style sa ves. | |
492 // TODO: set checkMatrix & checkClip booleans here and then check for th e | |
493 // offending operations in the following loop. | |
494 return false; | |
495 } | |
482 | 496 |
483 // Walk forward until we get back to either a draw-verb (abort) or we hit | 497 // Walk forward until we get back to either a draw-verb (abort) or we hit |
484 // our restore (success). | 498 // our restore (success). |
485 int32_t saveOffset = offset; | 499 int32_t saveOffset = offset; |
486 | 500 |
487 offset += opSize; | 501 offset += opSize; |
488 while (offset < restoreOffset) { | 502 while (offset < restoreOffset) { |
489 op = peek_op_and_size(writer, offset, &opSize); | 503 op = peek_op_and_size(writer, offset, &opSize); |
490 if ((op > CONCAT && op < ROTATE) || (SAVE_LAYER == op)) { | 504 if ((op > CONCAT && op < ROTATE) || (SAVE_LAYER == op)) { |
491 // drawing verb, abort | 505 // drawing verb, abort |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 void SkPictureRecord::validateRegions() const { | 1486 void SkPictureRecord::validateRegions() const { |
1473 int count = fRegions.count(); | 1487 int count = fRegions.count(); |
1474 SkASSERT((unsigned) count < 0x1000); | 1488 SkASSERT((unsigned) count < 0x1000); |
1475 for (int index = 0; index < count; index++) { | 1489 for (int index = 0; index < count; index++) { |
1476 const SkFlatData* region = fRegions[index]; | 1490 const SkFlatData* region = fRegions[index]; |
1477 SkASSERT(region); | 1491 SkASSERT(region); |
1478 // region->validate(); | 1492 // region->validate(); |
1479 } | 1493 } |
1480 } | 1494 } |
1481 #endif | 1495 #endif |
OLD | NEW |