| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCanvasStack.h" | 7 #include "SkCanvasStack.h" |
| 8 | 8 |
| 9 SkCanvasStack::SkCanvasStack(int width, int height) | 9 SkCanvasStack::SkCanvasStack(int width, int height) |
| 10 : INHERITED(width, height) {} | 10 : INHERITED(width, height) {} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Traverse all canvases (e.g. layers) the stack and ensure that they are clippe
d | 49 * Traverse all canvases (e.g. layers) the stack and ensure that they are clippe
d |
| 50 * to their bounds and that the area covered by any canvas higher in the stack i
s | 50 * to their bounds and that the area covered by any canvas higher in the stack i
s |
| 51 * also clipped out. | 51 * also clipped out. |
| 52 */ | 52 */ |
| 53 void SkCanvasStack::clipToZOrderedBounds() { | 53 void SkCanvasStack::clipToZOrderedBounds() { |
| 54 SkASSERT(fList.count() == fCanvasData.count()); | 54 SkASSERT(fList.count() == fCanvasData.count()); |
| 55 for (int i = 0; i < fList.count(); ++i) { | 55 for (int i = 0; i < fList.count(); ++i) { |
| 56 fList[i]->clipRegion(fCanvasData[i].requiredClip, SkRegion::kIntersect_O
p); | 56 fList[i]->clipRegion(fCanvasData[i].requiredClip); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 //////////////////////////////////////////////////////////////////////////////// | 60 //////////////////////////////////////////////////////////////////////////////// |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * We need to handle setMatrix specially as it overwrites the matrix in each | 63 * We need to handle setMatrix specially as it overwrites the matrix in each |
| 64 * canvas unlike all other matrix operations (i.e. translate, scale, etc) which | 64 * canvas unlike all other matrix operations (i.e. translate, scale, etc) which |
| 65 * just pre-concatenate with the existing matrix. | 65 * just pre-concatenate with the existing matrix. |
| 66 */ | 66 */ |
| 67 void SkCanvasStack::didSetMatrix(const SkMatrix& matrix) { | 67 void SkCanvasStack::didSetMatrix(const SkMatrix& matrix) { |
| 68 SkASSERT(fList.count() == fCanvasData.count()); | 68 SkASSERT(fList.count() == fCanvasData.count()); |
| 69 for (int i = 0; i < fList.count(); ++i) { | 69 for (int i = 0; i < fList.count(); ++i) { |
| 70 | 70 |
| 71 SkMatrix tempMatrix = matrix; | 71 SkMatrix tempMatrix = matrix; |
| 72 tempMatrix.postTranslate(SkIntToScalar(-fCanvasData[i].origin.x()), | 72 tempMatrix.postTranslate(SkIntToScalar(-fCanvasData[i].origin.x()), |
| 73 SkIntToScalar(-fCanvasData[i].origin.y())); | 73 SkIntToScalar(-fCanvasData[i].origin.y())); |
| 74 fList[i]->setMatrix(tempMatrix); | 74 fList[i]->setMatrix(tempMatrix); |
| 75 } | 75 } |
| 76 this->SkCanvas::didSetMatrix(matrix); | 76 this->SkCanvas::didSetMatrix(matrix); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SkCanvasStack::onClipRect(const SkRect& r, SkRegion::Op op, ClipEdgeStyle e
dgeStyle) { | 79 void SkCanvasStack::onClipRect(const SkRect& r, ClipOp op, ClipEdgeStyle edgeSty
le) { |
| 80 this->INHERITED::onClipRect(r, op, edgeStyle); | 80 this->INHERITED::onClipRect(r, op, edgeStyle); |
| 81 this->clipToZOrderedBounds(); | 81 this->clipToZOrderedBounds(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void SkCanvasStack::onClipRRect(const SkRRect& rr, SkRegion::Op op, ClipEdgeStyl
e edgeStyle) { | 84 void SkCanvasStack::onClipRRect(const SkRRect& rr, ClipOp op, ClipEdgeStyle edge
Style) { |
| 85 this->INHERITED::onClipRRect(rr, op, edgeStyle); | 85 this->INHERITED::onClipRRect(rr, op, edgeStyle); |
| 86 this->clipToZOrderedBounds(); | 86 this->clipToZOrderedBounds(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void SkCanvasStack::onClipPath(const SkPath& p, SkRegion::Op op, ClipEdgeStyle e
dgeStyle) { | 89 void SkCanvasStack::onClipPath(const SkPath& p, ClipOp op, ClipEdgeStyle edgeSty
le) { |
| 90 this->INHERITED::onClipPath(p, op, edgeStyle); | 90 this->INHERITED::onClipPath(p, op, edgeStyle); |
| 91 this->clipToZOrderedBounds(); | 91 this->clipToZOrderedBounds(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SkCanvasStack::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { | 94 void SkCanvasStack::onClipRegion(const SkRegion& deviceRgn, ClipOp op) { |
| 95 SkASSERT(fList.count() == fCanvasData.count()); | 95 SkASSERT(fList.count() == fCanvasData.count()); |
| 96 for (int i = 0; i < fList.count(); ++i) { | 96 for (int i = 0; i < fList.count(); ++i) { |
| 97 SkRegion tempRegion; | 97 SkRegion tempRegion; |
| 98 deviceRgn.translate(-fCanvasData[i].origin.x(), | 98 deviceRgn.translate(-fCanvasData[i].origin.x(), |
| 99 -fCanvasData[i].origin.y(), &tempRegion); | 99 -fCanvasData[i].origin.y(), &tempRegion); |
| 100 tempRegion.op(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op); | 100 tempRegion.op(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op); |
| 101 fList[i]->clipRegion(tempRegion, op); | 101 fList[i]->clipRegion(tempRegion, op); |
| 102 } | 102 } |
| 103 this->SkCanvas::onClipRegion(deviceRgn, op); | 103 this->SkCanvas::onClipRegion(deviceRgn, op); |
| 104 } | 104 } |
| OLD | NEW |