OLD | NEW |
---|---|
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 "SkBBoxHierarchyRecord.h" | 9 #include "SkBBoxHierarchyRecord.h" |
10 #include "SkPictureStateTree.h" | 10 #include "SkPictureStateTree.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 } | 30 } |
31 | 31 |
32 SkCanvas::SaveLayerStrategy SkBBoxHierarchyRecord::willSaveLayer(const SkRect* b ounds, | 32 SkCanvas::SaveLayerStrategy SkBBoxHierarchyRecord::willSaveLayer(const SkRect* b ounds, |
33 const SkPaint* paint, | 33 const SkPaint* paint, |
34 SaveFlags flags ) { | 34 SaveFlags flags ) { |
35 // For now, assume all filters affect transparent black. | 35 // For now, assume all filters affect transparent black. |
36 // FIXME: This could be made less conservative as an optimization. | 36 // FIXME: This could be made less conservative as an optimization. |
37 bool paintAffectsTransparentBlack = paint && | 37 bool paintAffectsTransparentBlack = paint && |
38 ((paint->getImageFilter()) || | 38 ((paint->getImageFilter()) || |
39 (paint->getColorFilter())); | 39 (paint->getColorFilter())); |
40 bool needToHandleBBox = paintAffectsTransparentBlack; | |
41 if (!needToHandleBBox && paint) { | |
dneto
2014/09/12 18:23:03
The obvious thing would be to commonize this Xferm
mtklein
2014/09/12 19:20:08
SGTM. In fact, at ToT you should now see the new
| |
42 // Unusual Xfermodes require us to process a saved layer | |
mtklein
2014/09/12 19:20:08
Can you copy (or move) this comment over to SkReco
dneto
2014/09/12 20:41:42
Done.
| |
43 // even with operations outisde the clip. | |
44 // For example, DstIn is used by masking layers. | |
45 // https://code.google.com/p/skia/issues/detail?id=1291 | |
46 SkXfermode* xfermode = paint->getXfermode(); | |
47 SkXfermode::Mode mode; | |
48 // SrcOver is the common case with a NULL xfermode, so we should | |
49 // make that the fast path and bypass the mode extraction and test. | |
50 if (xfermode && xfermode->asMode(&mode)) { | |
51 switch (mode) { | |
52 case SkXfermode::kClear_Mode: | |
Justin Novosad
2014/09/12 20:17:06
I feel this logic belongs in a more central locati
mtklein
2014/09/12 20:23:07
Let's hold off on that for another CL. This dupli
dneto
2014/09/12 20:41:42
Acknowledged.
| |
53 case SkXfermode::kSrc_Mode: | |
54 case SkXfermode::kSrcIn_Mode: | |
55 case SkXfermode::kDstIn_Mode: | |
56 case SkXfermode::kSrcOut_Mode: | |
57 case SkXfermode::kDstATop_Mode: | |
58 case SkXfermode::kModulate_Mode: | |
59 needToHandleBBox = true; | |
60 break; | |
61 default: | |
62 break; | |
63 } | |
64 } | |
65 } | |
66 | |
40 SkRect drawBounds; | 67 SkRect drawBounds; |
41 if (paintAffectsTransparentBlack) { | 68 if (needToHandleBBox) { |
42 SkIRect deviceBounds; | 69 SkIRect deviceBounds; |
43 this->getClipDeviceBounds(&deviceBounds); | 70 this->getClipDeviceBounds(&deviceBounds); |
44 drawBounds.set(deviceBounds); | 71 drawBounds.set(deviceBounds); |
45 } | 72 } |
46 fStateTree->appendSaveLayer(this->writeStream().bytesWritten()); | 73 fStateTree->appendSaveLayer(this->writeStream().bytesWritten()); |
47 SkCanvas::SaveLayerStrategy strategy = this->INHERITED::willSaveLayer(bounds , paint, flags); | 74 SkCanvas::SaveLayerStrategy strategy = this->INHERITED::willSaveLayer(bounds , paint, flags); |
48 if (paintAffectsTransparentBlack) { | 75 if (needToHandleBBox) { |
49 this->handleBBox(drawBounds); | 76 this->handleBBox(drawBounds); |
50 this->addNoOp(); | 77 this->addNoOp(); |
51 } | 78 } |
52 return strategy; | 79 return strategy; |
53 } | 80 } |
54 | 81 |
55 void SkBBoxHierarchyRecord::willRestore() { | 82 void SkBBoxHierarchyRecord::willRestore() { |
56 fStateTree->appendRestore(); | 83 fStateTree->appendRestore(); |
57 this->INHERITED::willRestore(); | 84 this->INHERITED::willRestore(); |
58 } | 85 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 123 |
97 bool SkBBoxHierarchyRecord::shouldRewind(void* data) { | 124 bool SkBBoxHierarchyRecord::shouldRewind(void* data) { |
98 // SkBBoxHierarchy::rewindInserts is called by SkPicture after the | 125 // SkBBoxHierarchy::rewindInserts is called by SkPicture after the |
99 // SkPicture has rewound its command stream. To match that rewind in the | 126 // SkPicture has rewound its command stream. To match that rewind in the |
100 // BBH, we rewind all draws that reference commands that were recorded | 127 // BBH, we rewind all draws that reference commands that were recorded |
101 // past the point to which the SkPicture has rewound, which is given by | 128 // past the point to which the SkPicture has rewound, which is given by |
102 // writeStream().bytesWritten(). | 129 // writeStream().bytesWritten(). |
103 SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data ); | 130 SkPictureStateTree::Draw* draw = static_cast<SkPictureStateTree::Draw*>(data ); |
104 return draw->fOffset >= writeStream().bytesWritten(); | 131 return draw->fOffset >= writeStream().bytesWritten(); |
105 } | 132 } |
OLD | NEW |