OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "sky/engine/config.h" | |
32 #include "sky/engine/platform/graphics/ReplayingCanvas.h" | |
33 | |
34 #include "third_party/skia/include/core/SkBitmapDevice.h" | |
35 | |
36 namespace blink { | |
37 | |
38 class AutoReplayer { | |
39 public: | |
40 explicit AutoReplayer(ReplayingCanvas*); | |
41 ~AutoReplayer(); | |
42 | |
43 private: | |
44 ReplayingCanvas* m_canvas; | |
45 }; | |
46 | |
47 AutoReplayer::AutoReplayer(ReplayingCanvas* replayingCanvas) : m_canvas(replayin
gCanvas) | |
48 { | |
49 replayingCanvas->m_depthCount++; | |
50 } | |
51 | |
52 AutoReplayer::~AutoReplayer() | |
53 { | |
54 m_canvas->m_depthCount--; | |
55 if (m_canvas->m_depthCount) | |
56 return; | |
57 m_canvas->m_stepCount++; | |
58 m_canvas->updateInRange(); | |
59 } | |
60 | |
61 ReplayingCanvas::ReplayingCanvas(SkBitmap bitmap, unsigned fromStep, unsigned to
Step) | |
62 : InterceptingCanvas(bitmap), m_fromStep(fromStep), m_toStep(toStep), m_step
Count(0), m_abortDrawing(false) | |
63 { | |
64 } | |
65 | |
66 void ReplayingCanvas::resetStepCount() | |
67 { | |
68 m_stepCount = 0; | |
69 } | |
70 | |
71 void ReplayingCanvas::updateInRange() | |
72 { | |
73 if (m_abortDrawing) | |
74 return; | |
75 if (m_toStep && m_stepCount > m_toStep) | |
76 m_abortDrawing = true; | |
77 if (m_stepCount == m_fromStep) | |
78 this->SkCanvas::clear(SkColorSetARGB(255, 255, 255, 255)); // FIXME: fil
l with nine patch instead. | |
79 } | |
80 | |
81 bool ReplayingCanvas::abortDrawing() | |
82 { | |
83 return m_abortDrawing; | |
84 } | |
85 | |
86 void ReplayingCanvas::drawPaint(const SkPaint& paint) | |
87 { | |
88 AutoReplayer replayer(this); | |
89 this->SkCanvas::drawPaint(paint); | |
90 } | |
91 | |
92 void ReplayingCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts
[], const SkPaint& paint) | |
93 { | |
94 AutoReplayer replayer(this); | |
95 this->SkCanvas::drawPoints(mode, count, pts, paint); | |
96 } | |
97 | |
98 void ReplayingCanvas::drawRect(const SkRect& rect, const SkPaint& paint) | |
99 { | |
100 AutoReplayer replayer(this); | |
101 this->SkCanvas::drawRect(rect, paint); | |
102 } | |
103 | |
104 void ReplayingCanvas::drawOval(const SkRect& rect, const SkPaint& paint) | |
105 { | |
106 AutoReplayer replayer(this); | |
107 this->SkCanvas::drawOval(rect, paint); | |
108 } | |
109 | |
110 void ReplayingCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) | |
111 { | |
112 AutoReplayer replayer(this); | |
113 this->SkCanvas::drawRRect(rrect, paint); | |
114 } | |
115 | |
116 void ReplayingCanvas::drawPath(const SkPath& path, const SkPaint& paint) | |
117 { | |
118 AutoReplayer replayer(this); | |
119 this->SkCanvas::drawPath(path, paint); | |
120 } | |
121 | |
122 void ReplayingCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
top, const SkPaint* paint) | |
123 { | |
124 AutoReplayer replayer(this); | |
125 this->SkCanvas::drawBitmap(bitmap, left, top, paint); | |
126 } | |
127 | |
128 void ReplayingCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
src, const SkRect& dst, | |
129 const SkPaint* paint, DrawBitmapRectFlags flags) | |
130 { | |
131 AutoReplayer replayer(this); | |
132 this->SkCanvas::drawBitmapRectToRect(bitmap, src, dst, paint, flags); | |
133 } | |
134 | |
135 void ReplayingCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, const SkRect& dst, const SkPaint* paint) | |
136 { | |
137 AutoReplayer replayer(this); | |
138 this->SkCanvas::drawBitmapNine(bitmap, center, dst, paint); | |
139 } | |
140 | |
141 void ReplayingCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, cons
t SkPaint* paint) | |
142 { | |
143 AutoReplayer replayer(this); | |
144 this->SkCanvas::drawSprite(bitmap, left, top, paint); | |
145 } | |
146 | |
147 void ReplayingCanvas::drawVertices(VertexMode vmode, int vertexCount, const SkPo
int vertices[], const SkPoint texs[], | |
148 const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int ind
exCount, const SkPaint& paint) | |
149 { | |
150 AutoReplayer replayer(this); | |
151 this->SkCanvas::drawVertices(vmode, vertexCount, vertices, texs, colors, xmo
de, indices, indexCount, paint); | |
152 } | |
153 | |
154 void ReplayingCanvas::drawData(const void* data, size_t length) | |
155 { | |
156 AutoReplayer replayer(this); | |
157 this->SkCanvas::drawData(data, length); | |
158 } | |
159 | |
160 void ReplayingCanvas::beginCommentGroup(const char* description) | |
161 { | |
162 AutoReplayer replayer(this); | |
163 this->SkCanvas::beginCommentGroup(description); | |
164 } | |
165 | |
166 void ReplayingCanvas::addComment(const char* keyword, const char* value) | |
167 { | |
168 AutoReplayer replayer(this); | |
169 this->SkCanvas::addComment(keyword, value); | |
170 } | |
171 | |
172 void ReplayingCanvas::endCommentGroup() | |
173 { | |
174 AutoReplayer replayer(this); | |
175 this->SkCanvas::endCommentGroup(); | |
176 } | |
177 | |
178 void ReplayingCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, c
onst SkPaint& paint) | |
179 { | |
180 AutoReplayer replayer(this); | |
181 this->SkCanvas::onDrawDRRect(outer, inner, paint); | |
182 } | |
183 | |
184 void ReplayingCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x
, SkScalar y, const SkPaint& paint) | |
185 { | |
186 AutoReplayer replayer(this); | |
187 this->SkCanvas::onDrawText(text, byteLength, x, y, paint); | |
188 } | |
189 | |
190 void ReplayingCanvas::onDrawPosText(const void* text, size_t byteLength, const S
kPoint pos[], const SkPaint& paint) | |
191 { | |
192 AutoReplayer replayer(this); | |
193 this->SkCanvas::onDrawPosText(text, byteLength, pos, paint); | |
194 } | |
195 | |
196 void ReplayingCanvas::onDrawPosTextH(const void* text, size_t byteLength, const
SkScalar xpos[], SkScalar constY, const SkPaint& paint) | |
197 { | |
198 AutoReplayer replayer(this); | |
199 this->SkCanvas::onDrawPosTextH(text, byteLength, xpos, constY, paint); | |
200 } | |
201 | |
202 void ReplayingCanvas::onDrawTextOnPath(const void* text, size_t byteLength, cons
t SkPath& path, const SkMatrix* matrix, const SkPaint& paint) | |
203 { | |
204 AutoReplayer replayer(this); | |
205 this->SkCanvas::onDrawTextOnPath(text, byteLength, path, matrix, paint); | |
206 } | |
207 | |
208 void ReplayingCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeSt
yle edgeStyle) | |
209 { | |
210 AutoReplayer replayer(this); | |
211 this->SkCanvas::onClipRect(rect, op, edgeStyle); | |
212 } | |
213 | |
214 void ReplayingCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdg
eStyle edgeStyle) | |
215 { | |
216 AutoReplayer replayer(this); | |
217 this->SkCanvas::onClipRRect(rrect, op, edgeStyle); | |
218 } | |
219 | |
220 void ReplayingCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeSt
yle edgeStyle) | |
221 { | |
222 AutoReplayer replayer(this); | |
223 this->SkCanvas::onClipPath(path, op, edgeStyle); | |
224 } | |
225 | |
226 void ReplayingCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) | |
227 { | |
228 AutoReplayer replayer(this); | |
229 this->SkCanvas::onClipRegion(region, op); | |
230 } | |
231 | |
232 void ReplayingCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* ma
trix, const SkPaint* paint) | |
233 { | |
234 AutoReplayer replayer(this); | |
235 this->SkCanvas::onDrawPicture(picture, matrix, paint); | |
236 } | |
237 | |
238 void ReplayingCanvas::didSetMatrix(const SkMatrix& matrix) | |
239 { | |
240 AutoReplayer replayer(this); | |
241 this->SkCanvas::didSetMatrix(matrix); | |
242 } | |
243 | |
244 void ReplayingCanvas::didConcat(const SkMatrix& matrix) | |
245 { | |
246 AutoReplayer replayer(this); | |
247 this->SkCanvas::didConcat(matrix); | |
248 } | |
249 | |
250 void ReplayingCanvas::willSave() | |
251 { | |
252 AutoReplayer replayer(this); | |
253 this->SkCanvas::willSave(); | |
254 } | |
255 | |
256 SkCanvas::SaveLayerStrategy ReplayingCanvas::willSaveLayer(const SkRect* bounds,
const SkPaint* paint, SaveFlags flags) | |
257 { | |
258 AutoReplayer replayer(this); | |
259 // We're about to create a layer and we have not cleared the device yet. | |
260 // Let's clear now, so it has effect on all layers. | |
261 if (m_stepCount < m_fromStep) | |
262 this->SkCanvas::clear(SkColorSetARGB(255, 255, 255, 255)); // FIXME: fil
l with nine patch instead. | |
263 | |
264 return this->SkCanvas::willSaveLayer(bounds, paint, flags); | |
265 } | |
266 | |
267 void ReplayingCanvas::willRestore() | |
268 { | |
269 AutoReplayer replayer(this); | |
270 this->SkCanvas::willRestore(); | |
271 } | |
272 | |
273 } // namespace blink | |
OLD | NEW |