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

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

Issue 22875008: Prevent picture recording from over optimizing the culling of clips. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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 | « include/core/SkCanvas.h ('k') | no next file » | 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 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 SkASSERT(!"eeek, don't try to change the device on a recording canvas"); 142 SkASSERT(!"eeek, don't try to change the device on a recording canvas");
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 = kSaveSize;
152 uint32_t initialOffset = this->addDraw(SAVE, &size); 153 uint32_t initialOffset = this->addDraw(SAVE, &size);
153 addInt(flags); 154 addInt(flags);
154 155
155 validate(initialOffset, size); 156 validate(initialOffset, size);
156 return this->INHERITED::save(flags); 157 return this->INHERITED::save(flags);
157 } 158 }
158 159
159 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, 160 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint,
160 SaveFlags flags) { 161 SaveFlags flags) {
161 // record the offset to us, making it non-positive to distinguish a save 162 // record the offset to us, making it non-positive to distinguish a save
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 473
473 // now offset points to a save 474 // now offset points to a save
474 offset = -offset; 475 offset = -offset;
475 uint32_t opSize; 476 uint32_t opSize;
476 DrawType op = peek_op_and_size(writer, offset, &opSize); 477 DrawType op = peek_op_and_size(writer, offset, &opSize);
477 if (SAVE_LAYER == op) { 478 if (SAVE_LAYER == op) {
478 // not ready to cull these out yet (mrr) 479 // not ready to cull these out yet (mrr)
479 return false; 480 return false;
480 } 481 }
481 SkASSERT(SAVE == op); 482 SkASSERT(SAVE == op);
483 SkASSERT(kSaveSize == opSize);
484
485 // get the save flag (last 4-bytes of the space allocated for the opSize)
486 SkCanvas::SaveFlags saveFlags = (SkCanvas::SaveFlags) *writer->peek32(offset +4);
487 if (SkCanvas::kMatrixClip_SaveFlag != saveFlags) {
488 // This function's optimization is only correct for kMatrixClip style sa ves.
489 // TODO: set checkMatrix & checkClip booleans here and then check for th e
490 // offending operations in the following loop.
491 return false;
492 }
482 493
483 // Walk forward until we get back to either a draw-verb (abort) or we hit 494 // Walk forward until we get back to either a draw-verb (abort) or we hit
484 // our restore (success). 495 // our restore (success).
485 int32_t saveOffset = offset; 496 int32_t saveOffset = offset;
486 497
487 offset += opSize; 498 offset += opSize;
488 while (offset < restoreOffset) { 499 while (offset < restoreOffset) {
489 op = peek_op_and_size(writer, offset, &opSize); 500 op = peek_op_and_size(writer, offset, &opSize);
490 if ((op > CONCAT && op < ROTATE) || (SAVE_LAYER == op)) { 501 if ((op > CONCAT && op < ROTATE) || (SAVE_LAYER == op)) {
491 // drawing verb, abort 502 // drawing verb, abort
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 void SkPictureRecord::validateRegions() const { 1483 void SkPictureRecord::validateRegions() const {
1473 int count = fRegions.count(); 1484 int count = fRegions.count();
1474 SkASSERT((unsigned) count < 0x1000); 1485 SkASSERT((unsigned) count < 0x1000);
1475 for (int index = 0; index < count; index++) { 1486 for (int index = 0; index < count; index++) {
1476 const SkFlatData* region = fRegions[index]; 1487 const SkFlatData* region = fRegions[index];
1477 SkASSERT(region); 1488 SkASSERT(region);
1478 // region->validate(); 1489 // region->validate();
1479 } 1490 }
1480 } 1491 }
1481 #endif 1492 #endif
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698