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

Side by Side Diff: src/utils/SkCanvasStack.cpp

Issue 23865004: Add SkCanvasStack and update the Canvas utilities to use it. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 | « src/utils/SkCanvasStack.h ('k') | src/utils/SkCanvasStateUtils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "SkCanvasStack.h"
9
10 SkCanvasStack::SkCanvasStack(int width, int height)
11 : INHERITED(width, height) {}
12
13 SkCanvasStack::~SkCanvasStack() {
14 this->removeAll();
15 }
16
17 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.
18 if (canvas) {
19 // compute the bounds of this canvas
20 const SkIRect canvasBounds = SkIRect::MakeSize(canvas->getDeviceSize());
21
22 // push the canvas onto the stack
23 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.
24
25 // push the canvas data onto the stack
26 CanvasData* data = &fCanvasData.push_back();
27 data->origin = origin;
28 data->requiredClip.setRect(canvasBounds);
29
30 // subtract this region from the canvas objects already on the stack.
31 // This ensures they do not draw into the space occupied by the layers
32 // above them.
33 for (int i = fList.count() - 1; i > 0; --i) {
34 SkIRect localBounds = canvasBounds;
35 localBounds.offset(origin - fCanvasData[i-1].origin);
36
37 fCanvasData[i-1].requiredClip.op(localBounds, SkRegion::kDifference_ Op);
38 fList[i-i]->clipRegion(fCanvasData[i-1].requiredClip);
39 }
40 }
41 SkASSERT(fList.count() == fCanvasData.count());
42 }
43
44 void SkCanvasStack::removeAll() {
45 fCanvasData.reset();
46 SkNWayCanvas::removeAll();
reed1 2013/09/04 13:00:56 nit: this->...
djsollen 2013/09/04 13:34:43 Done.
47 }
48
49 ////////////////////////////////////////////////////////////////////////////////
50
51 void SkCanvasStack::setMatrix(const SkMatrix& matrix) {
reed1 2013/09/04 13:00:56 Perhaps a comment-block nearby explaining why we h
52 SkASSERT(fList.count() == fCanvasData.count());
53 for (int i = 0; i < fList.count(); ++i) {
54
55 SkMatrix tempMatrix = matrix;
56 tempMatrix.postTranslate(SkIntToScalar(-fCanvasData[i].origin.x()),
57 SkIntToScalar(-fCanvasData[i].origin.y()));
58 fList[i]->setMatrix(tempMatrix);
59 }
60 this->SkCanvas::setMatrix(matrix);
61 }
62
63 bool SkCanvasStack::clipRect(const SkRect& r, SkRegion::Op op, bool aa) {
64 bool result = SkNWayCanvas::clipRect(r, op, aa);
65
66 SkASSERT(fList.count() == fCanvasData.count());
67 for (int i = 0; i < fList.count(); ++i) {
68 fList[i]->clipRegion(fCanvasData[i].requiredClip, SkRegion::kIntersect_O p);
reed1 2013/09/04 13:00:56 simple comment explaining why we need this Interse
djsollen 2013/09/04 13:34:43 Done.
69 }
70 return result;
71 }
72
73 bool SkCanvasStack::clipRRect(const SkRRect& rr, SkRegion::Op op, bool aa) {
74 bool result = SkNWayCanvas::clipRRect(rr, op, aa);
75
76 SkASSERT(fList.count() == fCanvasData.count());
77 for (int i = 0; i < fList.count(); ++i) {
78 fList[i]->clipRegion(fCanvasData[i].requiredClip, SkRegion::kIntersect_O p);
79 }
80 return result;
81 }
82
83 bool SkCanvasStack::clipPath(const SkPath& p, SkRegion::Op op, bool aa) {
84 bool result = SkNWayCanvas::clipPath(p, op, aa);
85
86 SkASSERT(fList.count() == fCanvasData.count());
87 for (int i = 0; i < fList.count(); ++i) {
88 fList[i]->clipRegion(fCanvasData[i].requiredClip, SkRegion::kIntersect_O p);
89 }
90 return result;
91 }
92
93 bool SkCanvasStack::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
94 SkASSERT(fList.count() == fCanvasData.count());
95 for (int i = 0; i < fList.count(); ++i) {
96 SkRegion tempRegion;
97 deviceRgn.translate(-fCanvasData[i].origin.x(),
98 -fCanvasData[i].origin.y(), &tempRegion);
99 tempRegion.op(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op);
100 fList[i]->clipRegion(tempRegion, op);
101 }
102 return this->SkCanvas::clipRegion(deviceRgn, op);
103 }
OLDNEW
« no previous file with comments | « src/utils/SkCanvasStack.h ('k') | src/utils/SkCanvasStateUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698