Chromium Code Reviews| Index: src/utils/SkCanvasStack.cpp |
| diff --git a/src/utils/SkCanvasStack.cpp b/src/utils/SkCanvasStack.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c5a79536407bf55d56c57638f13e150e519c5901 |
| --- /dev/null |
| +++ b/src/utils/SkCanvasStack.cpp |
| @@ -0,0 +1,103 @@ |
| + |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| +#include "SkCanvasStack.h" |
| + |
| +SkCanvasStack::SkCanvasStack(int width, int height) |
| + : INHERITED(width, height) {} |
| + |
| +SkCanvasStack::~SkCanvasStack() { |
| + this->removeAll(); |
| +} |
| + |
| +void SkCanvasStack::pushCanvas(SkCanvas* canvas, SkIPoint origin) { |
|
reed1
2013/09/04 13:00:56
nit: const SkIPoint& origin
djsollen
2013/09/04 13:34:43
Done.
|
| + if (canvas) { |
| + // compute the bounds of this canvas |
| + const SkIRect canvasBounds = SkIRect::MakeSize(canvas->getDeviceSize()); |
| + |
| + // push the canvas onto the stack |
| + SkNWayCanvas::addCanvas(canvas); |
|
reed1
2013/09/04 13:00:56
nit: this->...
perhaps use INHERITED instead of S
djsollen
2013/09/04 13:34:43
Done.
|
| + |
| + // push the canvas data onto the stack |
| + CanvasData* data = &fCanvasData.push_back(); |
| + data->origin = origin; |
| + data->requiredClip.setRect(canvasBounds); |
| + |
| + // subtract this region from the canvas objects already on the stack. |
| + // This ensures they do not draw into the space occupied by the layers |
| + // above them. |
| + for (int i = fList.count() - 1; i > 0; --i) { |
| + SkIRect localBounds = canvasBounds; |
| + localBounds.offset(origin - fCanvasData[i-1].origin); |
| + |
| + fCanvasData[i-1].requiredClip.op(localBounds, SkRegion::kDifference_Op); |
| + fList[i-i]->clipRegion(fCanvasData[i-1].requiredClip); |
| + } |
| + } |
| + SkASSERT(fList.count() == fCanvasData.count()); |
| +} |
| + |
| +void SkCanvasStack::removeAll() { |
| + fCanvasData.reset(); |
| + SkNWayCanvas::removeAll(); |
|
reed1
2013/09/04 13:00:56
nit: this->...
djsollen
2013/09/04 13:34:43
Done.
|
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| + |
| +void SkCanvasStack::setMatrix(const SkMatrix& matrix) { |
|
reed1
2013/09/04 13:00:56
Perhaps a comment-block nearby explaining why we h
|
| + SkASSERT(fList.count() == fCanvasData.count()); |
| + for (int i = 0; i < fList.count(); ++i) { |
| + |
| + SkMatrix tempMatrix = matrix; |
| + tempMatrix.postTranslate(SkIntToScalar(-fCanvasData[i].origin.x()), |
| + SkIntToScalar(-fCanvasData[i].origin.y())); |
| + fList[i]->setMatrix(tempMatrix); |
| + } |
| + this->SkCanvas::setMatrix(matrix); |
| +} |
| + |
| +bool SkCanvasStack::clipRect(const SkRect& r, SkRegion::Op op, bool aa) { |
| + bool result = SkNWayCanvas::clipRect(r, op, aa); |
| + |
| + SkASSERT(fList.count() == fCanvasData.count()); |
| + for (int i = 0; i < fList.count(); ++i) { |
| + fList[i]->clipRegion(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op); |
|
reed1
2013/09/04 13:00:56
simple comment explaining why we need this Interse
djsollen
2013/09/04 13:34:43
Done.
|
| + } |
| + return result; |
| +} |
| + |
| +bool SkCanvasStack::clipRRect(const SkRRect& rr, SkRegion::Op op, bool aa) { |
| + bool result = SkNWayCanvas::clipRRect(rr, op, aa); |
| + |
| + SkASSERT(fList.count() == fCanvasData.count()); |
| + for (int i = 0; i < fList.count(); ++i) { |
| + fList[i]->clipRegion(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op); |
| + } |
| + return result; |
| +} |
| + |
| +bool SkCanvasStack::clipPath(const SkPath& p, SkRegion::Op op, bool aa) { |
| + bool result = SkNWayCanvas::clipPath(p, op, aa); |
| + |
| + SkASSERT(fList.count() == fCanvasData.count()); |
| + for (int i = 0; i < fList.count(); ++i) { |
| + fList[i]->clipRegion(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op); |
| + } |
| + return result; |
| +} |
| + |
| +bool SkCanvasStack::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
| + SkASSERT(fList.count() == fCanvasData.count()); |
| + for (int i = 0; i < fList.count(); ++i) { |
| + SkRegion tempRegion; |
| + deviceRgn.translate(-fCanvasData[i].origin.x(), |
| + -fCanvasData[i].origin.y(), &tempRegion); |
| + tempRegion.op(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op); |
| + fList[i]->clipRegion(tempRegion, op); |
| + } |
| + return this->SkCanvas::clipRegion(deviceRgn, op); |
| +} |