blob: 1101fb424d0d7d9e2897534b91a0deee8c67c985 [file] [log] [blame]
commit-bot@chromium.orgc4b21e62014-04-11 18:33:31 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +00008#include "SkRecordDraw.h"
mtklein5ad6ee12014-08-11 08:08:43 -07009#include "SkTSort.h"
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000010
mtklein5ad6ee12014-08-11 08:08:43 -070011void SkRecordDraw(const SkRecord& record,
12 SkCanvas* canvas,
13 const SkBBoxHierarchy* bbh,
14 SkDrawPictureCallback* callback) {
Mike Kleinc11530e2014-06-24 11:29:06 -040015 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
mtklein5ad6ee12014-08-11 08:08:43 -070016
17 if (NULL != bbh) {
mtklein5ad6ee12014-08-11 08:08:43 -070018 // Draw only ops that affect pixels in the canvas's current clip.
mtkleina723b572014-08-15 11:49:49 -070019 SkIRect query;
mtklein3e8232b2014-08-18 13:39:11 -070020
21 // The SkRecord and BBH were recorded in identity space. This canvas
22 // is not necessarily in that same space. getClipBounds() returns us
23 // this canvas' clip bounds transformed back into identity space, which
24 // lets us query the BBH.
25 SkRect clipBounds = { 0, 0, 0, 0 };
26 (void)canvas->getClipBounds(&clipBounds);
mtkleina723b572014-08-15 11:49:49 -070027 clipBounds.roundOut(&query);
mtklein3e8232b2014-08-18 13:39:11 -070028
mtklein5ad6ee12014-08-11 08:08:43 -070029 SkTDArray<void*> ops;
mtkleina723b572014-08-15 11:49:49 -070030 bbh->search(query, &ops);
mtklein5ad6ee12014-08-11 08:08:43 -070031
mtklein5ad6ee12014-08-11 08:08:43 -070032 SkRecords::Draw draw(canvas);
33 for (int i = 0; i < ops.count(); i++) {
34 if (NULL != callback && callback->abortDrawing()) {
35 return;
36 }
37 record.visit<void>((uintptr_t)ops[i], draw); // See FillBounds below.
38 }
39 } else {
40 // Draw all ops.
41 for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.next()) {
42 if (NULL != callback && callback->abortDrawing()) {
43 return;
44 }
45 record.visit<void>(draw.index(), draw);
46 }
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000047 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000048}
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000049
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000050namespace SkRecords {
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000051
mtklein7cdc1ee2014-07-07 10:41:04 -070052// FIXME: SkBitmaps are stateful, so we need to copy them to play back in multiple threads.
53static SkBitmap shallow_copy(const SkBitmap& bitmap) {
54 return bitmap;
55}
56
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000057// NoOps draw nothing.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000058template <> void Draw::draw(const NoOp&) {}
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000059
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000060#define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; }
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000061DRAW(Restore, restore());
Florin Malita5f6102d2014-06-30 10:13:28 -040062DRAW(Save, save());
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000063DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags));
64DRAW(PopCull, popCull());
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000065DRAW(PushCull, pushCull(r.rect));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000066DRAW(Clear, clear(r.color));
commit-bot@chromium.org99bd7d82014-05-19 15:51:12 +000067DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000068
69DRAW(ClipPath, clipPath(r.path, r.op, r.doAA));
70DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA));
71DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA));
72DRAW(ClipRegion, clipRegion(r.region, r.op));
73
mtklein5f0e8222014-08-22 11:44:26 -070074DRAW(BeginCommentGroup, beginCommentGroup(r.description));
75DRAW(AddComment, addComment(r.key, r.value));
76DRAW(EndCommentGroup, endCommentGroup());
77
mtklein7cdc1ee2014-07-07 10:41:04 -070078DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint));
79DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.paint));
80DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.paint));
81DRAW(DrawBitmapRectToRect,
82 drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint, r.flags));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000083DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
84DRAW(DrawOval, drawOval(r.oval, r.paint));
85DRAW(DrawPaint, drawPaint(r.paint));
86DRAW(DrawPath, drawPath(r.path, r.paint));
dandovb3c9d1c2014-08-12 08:34:29 -070087DRAW(DrawPatch, drawPatch(r.cubics, r.colors, r.texCoords, r.xmode.get(), r.paint));
reedd5fa1a42014-08-09 11:08:05 -070088DRAW(DrawPicture, drawPicture(r.picture, r.matrix, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000089DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint));
90DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint));
91DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
92DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
93DRAW(DrawRect, drawRect(r.rect, r.paint));
mtklein7cdc1ee2014-07-07 10:41:04 -070094DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000095DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint));
fmalita00d5c2c2014-08-21 08:53:26 -070096DRAW(DrawTextBlob, drawTextBlob(r.blob, r.x, r.y, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000097DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint));
98DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors,
99 r.xmode.get(), r.indices, r.indexCount, r.paint));
100#undef DRAW
101
mtklein5ad6ee12014-08-11 08:08:43 -0700102
103// This is an SkRecord visitor that fills an SkBBoxHierarchy.
mtklein828ce1f2014-08-13 12:58:45 -0700104//
105// The interesting part here is how to calculate bounds for ops which don't
106// have intrinsic bounds. What is the bounds of a Save or a Translate?
107//
108// We answer this by thinking about a particular definition of bounds: if I
109// don't execute this op, pixels in this rectangle might draw incorrectly. So
110// the bounds of a Save, a Translate, a Restore, etc. are the union of the
111// bounds of Draw* ops that they might have an effect on. For any given
112// Save/Restore block, the bounds of the Save, the Restore, and any other
113// non-drawing ("control") ops inside are exactly the union of the bounds of
114// the drawing ops inside that block.
115//
116// To implement this, we keep a stack of active Save blocks. As we consume ops
117// inside the Save/Restore block, drawing ops are unioned with the bounds of
118// the block, and control ops are stashed away for later. When we finish the
119// block with a Restore, our bounds are complete, and we go back and fill them
120// in for all the control ops we stashed away.
mtklein5ad6ee12014-08-11 08:08:43 -0700121class FillBounds : SkNoncopyable {
122public:
mtklein828ce1f2014-08-13 12:58:45 -0700123 FillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) : fBounds(record.count()) {
124 // Calculate bounds for all ops. This won't go quite in order, so we'll need
125 // to store the bounds separately then feed them in to the BBH later in order.
mtkleina723b572014-08-15 11:49:49 -0700126 const SkIRect largest = SkIRect::MakeLargest();
mtklein6332f1d2014-08-19 07:09:40 -0700127 fCTM = &SkMatrix::I();
mtkleina723b572014-08-15 11:49:49 -0700128 fCurrentClipBounds = largest;
mtklein828ce1f2014-08-13 12:58:45 -0700129 for (fCurrentOp = 0; fCurrentOp < record.count(); fCurrentOp++) {
130 record.visit<void>(fCurrentOp, *this);
131 }
mtklein5ad6ee12014-08-11 08:08:43 -0700132
mtklein828ce1f2014-08-13 12:58:45 -0700133 // If we have any lingering unpaired Saves, simulate restores to make
134 // sure all ops in those Save blocks have their bounds calculated.
135 while (!fSaveStack.isEmpty()) {
136 this->popSaveBlock();
137 }
138
139 // Any control ops not part of any Save/Restore block draw everywhere.
140 while (!fControlIndices.isEmpty()) {
mtkleina723b572014-08-15 11:49:49 -0700141 this->popControl(largest);
mtklein828ce1f2014-08-13 12:58:45 -0700142 }
143
144 // Finally feed all stored bounds into the BBH. They'll be returned in this order.
145 SkASSERT(NULL != bbh);
146 for (uintptr_t i = 0; i < record.count(); i++) {
147 if (!fBounds[i].isEmpty()) {
148 bbh->insert((void*)i, fBounds[i], true/*ok to defer*/);
149 }
150 }
151 bbh->flushDeferredInserts();
152 }
mtklein5ad6ee12014-08-11 08:08:43 -0700153
mtkleina723b572014-08-15 11:49:49 -0700154 template <typename T> void operator()(const T& op) {
155 this->updateCTM(op);
156 this->updateClipBounds(op);
157 this->trackBounds(op);
mtklein5ad6ee12014-08-11 08:08:43 -0700158 }
159
160private:
mtklein828ce1f2014-08-13 12:58:45 -0700161 struct SaveBounds {
mtkleina723b572014-08-15 11:49:49 -0700162 int controlOps; // Number of control ops in this Save block, including the Save.
163 SkIRect bounds; // Bounds of everything in the block.
164 const SkPaint* paint; // Unowned. If set, adjusts the bounds of all ops in this block.
mtklein828ce1f2014-08-13 12:58:45 -0700165 };
166
mtklein6cfa73a2014-08-13 13:33:49 -0700167 template <typename T> void updateCTM(const T&) { /* most ops don't change the CTM */ }
mtklein6332f1d2014-08-19 07:09:40 -0700168 void updateCTM(const Restore& op) { fCTM = &op.matrix; }
169 void updateCTM(const SetMatrix& op) { fCTM = &op.matrix; }
mtkleina723b572014-08-15 11:49:49 -0700170
171 template <typename T> void updateClipBounds(const T&) { /* most ops don't change the clip */ }
172 // Each of these devBounds fields is the state of the device bounds after the op.
173 // So Restore's devBounds are those bounds saved by its paired Save or SaveLayer.
174 void updateClipBounds(const Restore& op) { fCurrentClipBounds = op.devBounds; }
175 void updateClipBounds(const ClipPath& op) { fCurrentClipBounds = op.devBounds; }
176 void updateClipBounds(const ClipRRect& op) { fCurrentClipBounds = op.devBounds; }
177 void updateClipBounds(const ClipRect& op) { fCurrentClipBounds = op.devBounds; }
178 void updateClipBounds(const ClipRegion& op) { fCurrentClipBounds = op.devBounds; }
179 void updateClipBounds(const SaveLayer& op) {
180 if (op.bounds) {
181 fCurrentClipBounds.intersect(this->adjustAndMap(*op.bounds, op.paint));
182 }
183 }
mtklein6cfa73a2014-08-13 13:33:49 -0700184
mtklein828ce1f2014-08-13 12:58:45 -0700185 // The bounds of these ops must be calculated when we hit the Restore
186 // from the bounds of the ops in the same Save block.
mtkleina723b572014-08-15 11:49:49 -0700187 void trackBounds(const Save&) { this->pushSaveBlock(NULL); }
mtklein828ce1f2014-08-13 12:58:45 -0700188 // TODO: bounds of SaveLayer may be more complicated?
mtkleina723b572014-08-15 11:49:49 -0700189 void trackBounds(const SaveLayer& op) { this->pushSaveBlock(op.paint); }
190 void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(); }
mtklein828ce1f2014-08-13 12:58:45 -0700191
mtklein828ce1f2014-08-13 12:58:45 -0700192 void trackBounds(const SetMatrix&) { this->pushControl(); }
193 void trackBounds(const ClipRect&) { this->pushControl(); }
194 void trackBounds(const ClipRRect&) { this->pushControl(); }
195 void trackBounds(const ClipPath&) { this->pushControl(); }
196 void trackBounds(const ClipRegion&) { this->pushControl(); }
197
198 // For all other ops, we can calculate and store the bounds directly now.
199 template <typename T> void trackBounds(const T& op) {
200 fBounds[fCurrentOp] = this->bounds(op);
201 this->updateSaveBounds(fBounds[fCurrentOp]);
mtklein5ad6ee12014-08-11 08:08:43 -0700202 }
203
mtkleina723b572014-08-15 11:49:49 -0700204 void pushSaveBlock(const SkPaint* paint) {
mtklein828ce1f2014-08-13 12:58:45 -0700205 // Starting a new Save block. Push a new entry to represent that.
mtkleina723b572014-08-15 11:49:49 -0700206 SaveBounds sb = { 0, SkIRect::MakeEmpty(), paint };
mtklein828ce1f2014-08-13 12:58:45 -0700207 fSaveStack.push(sb);
208 this->pushControl();
209 }
210
mtkleind910f542014-08-22 09:06:34 -0700211 static bool PaintMayAffectTransparentBlack(const SkPaint* paint) {
212 // FIXME: this is very conservative
213 return paint && (paint->getImageFilter() || paint->getColorFilter());
214 }
215
mtklein828ce1f2014-08-13 12:58:45 -0700216 SkIRect popSaveBlock() {
217 // We're done the Save block. Apply the block's bounds to all control ops inside it.
218 SaveBounds sb;
219 fSaveStack.pop(&sb);
mtkleind910f542014-08-22 09:06:34 -0700220
221 // If the paint affects transparent black, we can't trust any of our calculated bounds.
222 const SkIRect& bounds =
223 PaintMayAffectTransparentBlack(sb.paint) ? fCurrentClipBounds : sb.bounds;
224
mtklein828ce1f2014-08-13 12:58:45 -0700225 while (sb.controlOps --> 0) {
mtkleind910f542014-08-22 09:06:34 -0700226 this->popControl(bounds);
mtklein828ce1f2014-08-13 12:58:45 -0700227 }
228
229 // This whole Save block may be part another Save block.
mtkleind910f542014-08-22 09:06:34 -0700230 this->updateSaveBounds(bounds);
mtklein828ce1f2014-08-13 12:58:45 -0700231
232 // If called from a real Restore (not a phony one for balance), it'll need the bounds.
mtkleind910f542014-08-22 09:06:34 -0700233 return bounds;
mtklein828ce1f2014-08-13 12:58:45 -0700234 }
235
236 void pushControl() {
237 fControlIndices.push(fCurrentOp);
238 if (!fSaveStack.isEmpty()) {
239 fSaveStack.top().controlOps++;
240 }
241 }
242
243 void popControl(const SkIRect& bounds) {
244 fBounds[fControlIndices.top()] = bounds;
245 fControlIndices.pop();
246 }
247
248 void updateSaveBounds(const SkIRect& bounds) {
249 // If we're in a Save block, expand its bounds to cover these bounds too.
250 if (!fSaveStack.isEmpty()) {
251 fSaveStack.top().bounds.join(bounds);
252 }
253 }
254
mtklein62b67ae2014-08-18 11:10:37 -0700255 // TODO(mtklein): Remove this default when done bounding all ops.
mtklein479601b2014-08-18 08:45:33 -0700256 template <typename T> SkIRect bounds(const T&) const { return fCurrentClipBounds; }
257 SkIRect bounds(const Clear&) const { return SkIRect::MakeLargest(); } // Ignores the clip
258 SkIRect bounds(const NoOp&) const { return SkIRect::MakeEmpty(); } // NoOps don't draw.
mtklein828ce1f2014-08-13 12:58:45 -0700259
mtklein62b67ae2014-08-18 11:10:37 -0700260 SkIRect bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect, &op.paint); }
261 SkIRect bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval, &op.paint); }
262 SkIRect bounds(const DrawRRect& op) const {
263 return this->adjustAndMap(op.rrect.rect(), &op.paint);
264 }
265 SkIRect bounds(const DrawDRRect& op) const {
266 return this->adjustAndMap(op.outer.rect(), &op.paint);
267 }
268
269 SkIRect bounds(const DrawBitmapRectToRect& op) const {
270 return this->adjustAndMap(op.dst, op.paint);
271 }
272 SkIRect bounds(const DrawBitmapNine& op) const {
273 return this->adjustAndMap(op.dst, op.paint);
274 }
275 SkIRect bounds(const DrawBitmap& op) const {
276 const SkBitmap& bm = op.bitmap;
277 return this->adjustAndMap(SkRect::MakeXYWH(op.left, op.top, bm.width(), bm.height()),
278 op.paint);
279 }
280 SkIRect bounds(const DrawBitmapMatrix& op) const {
281 const SkBitmap& bm = op.bitmap;
282 SkRect dst = SkRect::MakeWH(bm.width(), bm.height());
283 op.matrix.mapRect(&dst);
284 return this->adjustAndMap(dst, op.paint);
285 }
286
287 SkIRect bounds(const DrawPath& op) const {
288 return op.path.isInverseFillType() ? fCurrentClipBounds
289 : this->adjustAndMap(op.path.getBounds(), &op.paint);
290 }
291 SkIRect bounds(const DrawPoints& op) const {
292 SkRect dst;
293 dst.set(op.pts, op.count);
294
295 // Pad the bounding box a little to make sure hairline points' bounds aren't empty.
296 SkScalar stroke = SkMaxScalar(op.paint.getStrokeWidth(), 0.01f);
297 dst.outset(stroke/2, stroke/2);
298
299 return this->adjustAndMap(dst, &op.paint);
300 }
301
302 SkIRect bounds(const DrawPosText& op) const {
303 const int N = op.paint.countText(op.text, op.byteLength);
304 if (N == 0) {
305 return SkIRect::MakeEmpty();
306 }
307
308 SkRect dst;
309 dst.set(op.pos, op.paint.countText(op.text, N));
310 AdjustTextForFontMetrics(&dst, op.paint);
311 return this->adjustAndMap(dst, &op.paint);
312 }
313 SkIRect bounds(const DrawPosTextH& op) const {
314 const int N = op.paint.countText(op.text, op.byteLength);
315 if (N == 0) {
316 return SkIRect::MakeEmpty();
317 }
318
319 SkScalar left = op.xpos[0], right = op.xpos[0];
320 for (int i = 1; i < N; i++) {
321 left = SkMinScalar(left, op.xpos[i]);
322 right = SkMaxScalar(right, op.xpos[i]);
323 }
324 SkRect dst = { left, op.y, right, op.y };
325 AdjustTextForFontMetrics(&dst, op.paint);
326 return this->adjustAndMap(dst, &op.paint);
327 }
328
329 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) {
caryclark9a657fa2014-08-20 05:24:29 -0700330#ifdef SK_DEBUG
mtkleina19afb42014-08-19 17:47:14 -0700331 SkRect correct = *rect;
332#endif
mtkleinc8460492014-08-21 16:39:12 -0700333 const SkScalar yPad = 2.0f * paint.getTextSize(), // In practice, this seems to be enough.
mtkleina19afb42014-08-19 17:47:14 -0700334 xPad = 4.0f * yPad; // Hack for very wide Github logo font.
335 rect->outset(xPad, yPad);
caryclark9a657fa2014-08-20 05:24:29 -0700336#ifdef SK_DEBUG
mtklein62b67ae2014-08-18 11:10:37 -0700337 SkPaint::FontMetrics metrics;
338 paint.getFontMetrics(&metrics);
mtkleina19afb42014-08-19 17:47:14 -0700339 correct.fLeft += metrics.fXMin;
340 correct.fTop += metrics.fTop;
341 correct.fRight += metrics.fXMax;
342 correct.fBottom += metrics.fBottom;
mtkleind13291a2014-08-21 14:46:49 -0700343 // See skia:2862 for why we ignore small text sizes.
344 SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct),
345 "%f %f %f %f vs. %f %f %f %f\n",
mtkleina19afb42014-08-19 17:47:14 -0700346 -xPad, -yPad, +xPad, +yPad,
347 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom);
348#endif
mtklein62b67ae2014-08-18 11:10:37 -0700349 }
350
mtklein479601b2014-08-18 08:45:33 -0700351 // Returns true if rect was meaningfully adjusted for the effects of paint,
352 // false if the paint could affect the rect in unknown ways.
353 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) {
mtkleina723b572014-08-15 11:49:49 -0700354 if (paint) {
355 if (paint->canComputeFastBounds()) {
mtklein479601b2014-08-18 08:45:33 -0700356 *rect = paint->computeFastBounds(*rect, rect);
357 return true;
mtkleina723b572014-08-15 11:49:49 -0700358 }
mtklein479601b2014-08-18 08:45:33 -0700359 return false;
360 }
361 return true;
362 }
363
364 // Adjust rect for all paints that may affect its geometry, then map it to device space.
365 SkIRect adjustAndMap(SkRect rect, const SkPaint* paint) const {
366 // Inverted rectangles really confuse our BBHs.
367 rect.sort();
368
369 // Adjust the rect for its own paint.
370 if (!AdjustForPaint(paint, &rect)) {
371 // The paint could do anything to our bounds. The only safe answer is the current clip.
372 return fCurrentClipBounds;
mtkleina723b572014-08-15 11:49:49 -0700373 }
374
375 // Adjust rect for all the paints from the SaveLayers we're inside.
mtkleina723b572014-08-15 11:49:49 -0700376 for (int i = fSaveStack.count() - 1; i >= 0; i--) {
mtklein479601b2014-08-18 08:45:33 -0700377 if (!AdjustForPaint(fSaveStack[i].paint, &rect)) {
378 // Same deal as above.
379 return fCurrentClipBounds;
mtkleina723b572014-08-15 11:49:49 -0700380 }
381 }
382
383 // Map the rect back to device space.
mtklein6332f1d2014-08-19 07:09:40 -0700384 fCTM->mapRect(&rect);
mtkleina723b572014-08-15 11:49:49 -0700385 SkIRect devRect;
386 rect.roundOut(&devRect);
mtklein479601b2014-08-18 08:45:33 -0700387
388 // Nothing can draw outside the current clip.
389 // (Only bounded ops call into this method, so oddballs like Clear don't matter here.)
390 devRect.intersect(fCurrentClipBounds);
mtkleina723b572014-08-15 11:49:49 -0700391 return devRect;
392 }
393
394 // Conservative device bounds for each op in the SkRecord.
395 SkAutoTMalloc<SkIRect> fBounds;
396
397 // We walk fCurrentOp through the SkRecord, as we go using updateCTM()
398 // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative
399 // device bounds of the current clip (fCurrentClipBounds).
mtklein828ce1f2014-08-13 12:58:45 -0700400 unsigned fCurrentOp;
mtklein6332f1d2014-08-19 07:09:40 -0700401 const SkMatrix* fCTM;
mtkleina723b572014-08-15 11:49:49 -0700402 SkIRect fCurrentClipBounds;
403
404 // Used to track the bounds of Save/Restore blocks and the control ops inside them.
mtklein828ce1f2014-08-13 12:58:45 -0700405 SkTDArray<SaveBounds> fSaveStack;
406 SkTDArray<unsigned> fControlIndices;
mtklein5ad6ee12014-08-11 08:08:43 -0700407};
408
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +0000409} // namespace SkRecords
mtklein5ad6ee12014-08-11 08:08:43 -0700410
411void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) {
mtklein828ce1f2014-08-13 12:58:45 -0700412 SkRecords::FillBounds(record, bbh);
mtklein5ad6ee12014-08-11 08:08:43 -0700413}