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

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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
mtklein 2013/08/13 13:57:53 This seems a little roundabout to me, given that t
robertphillips 2013/08/13 14:33:03 Mainly for solidarity with kSaveLayerNoBoundsSize
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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 475
473 // now offset points to a save 476 // now offset points to a save
474 offset = -offset; 477 offset = -offset;
475 uint32_t opSize; 478 uint32_t opSize;
476 DrawType op = peek_op_and_size(writer, offset, &opSize); 479 DrawType op = peek_op_and_size(writer, offset, &opSize);
477 if (SAVE_LAYER == op) { 480 if (SAVE_LAYER == op) {
478 // not ready to cull these out yet (mrr) 481 // not ready to cull these out yet (mrr)
479 return false; 482 return false;
480 } 483 }
481 SkASSERT(SAVE == op); 484 SkASSERT(SAVE == op);
485 SkASSERT(kSaveSize == opSize);
486
487 // get the save flag (last 4-bytes of the space allocated for the opSize)
488 SkCanvas::SaveFlags saveFlag = (SkCanvas::SaveFlags) *writer->peek32(offset+ 4);
mtklein 2013/08/13 13:57:53 This is a nit, but given that it's a bitwise enum,
mtklein 2013/08/13 13:57:53 Again, a nit, but this guy can be const.
489 if (SkCanvas::kMatrixClip_SaveFlag != (SkCanvas::kMatrixClip_SaveFlag & save Flag)) {
mtklein 2013/08/13 13:57:53 Maybe I'm brainfarting, but can't we write this as
robertphillips 2013/08/13 14:33:03 Unfortunately there are several other save flags t
mtklein 2013/08/13 14:40:47 Either way, aren't we filtering out anything which
490 // This function's optimization is only correct for kMatrixClip style sa ves.
491 // TODO: set checkMatrix & checkClip booleans here and then check for th e
492 // offending operations in the following loop.
493 return false;
494 }
482 495
483 // Walk forward until we get back to either a draw-verb (abort) or we hit 496 // Walk forward until we get back to either a draw-verb (abort) or we hit
484 // our restore (success). 497 // our restore (success).
485 int32_t saveOffset = offset; 498 int32_t saveOffset = offset;
486 499
487 offset += opSize; 500 offset += opSize;
488 while (offset < restoreOffset) { 501 while (offset < restoreOffset) {
489 op = peek_op_and_size(writer, offset, &opSize); 502 op = peek_op_and_size(writer, offset, &opSize);
490 if ((op > CONCAT && op < ROTATE) || (SAVE_LAYER == op)) { 503 if ((op > CONCAT && op < ROTATE) || (SAVE_LAYER == op)) {
491 // drawing verb, abort 504 // drawing verb, abort
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 void SkPictureRecord::validateRegions() const { 1485 void SkPictureRecord::validateRegions() const {
1473 int count = fRegions.count(); 1486 int count = fRegions.count();
1474 SkASSERT((unsigned) count < 0x1000); 1487 SkASSERT((unsigned) count < 0x1000);
1475 for (int index = 0; index < count; index++) { 1488 for (int index = 0; index < count; index++) {
1476 const SkFlatData* region = fRegions[index]; 1489 const SkFlatData* region = fRegions[index];
1477 SkASSERT(region); 1490 SkASSERT(region);
1478 // region->validate(); 1491 // region->validate();
1479 } 1492 }
1480 } 1493 }
1481 #endif 1494 #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