blob: 7e35d8a2c7da87867c84079fd19d72ef007c5cbb [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
robertphillips82365912014-11-12 09:32:34 -08008#include "SkLayerInfo.h"
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +00009#include "SkRecordDraw.h"
mtklein131a22b2014-08-25 14:16:15 -070010#include "SkPatchUtils.h"
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000011
mtklein5ad6ee12014-08-11 08:08:43 -070012void SkRecordDraw(const SkRecord& record,
13 SkCanvas* canvas,
reed6be2aa92014-11-18 11:08:05 -080014 SkPicture const* const drawablePicts[], int drawableCount,
mtklein5ad6ee12014-08-11 08:08:43 -070015 const SkBBoxHierarchy* bbh,
16 SkDrawPictureCallback* callback) {
Mike Kleinc11530e2014-06-24 11:29:06 -040017 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
mtklein5ad6ee12014-08-11 08:08:43 -070018
bsalomon49f085d2014-09-05 13:34:00 -070019 if (bbh) {
mtklein5ad6ee12014-08-11 08:08:43 -070020 // Draw only ops that affect pixels in the canvas's current clip.
mtklein3e8232b2014-08-18 13:39:11 -070021 // 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.
mtklein7cc1a342014-11-20 08:01:09 -080025 SkRect query;
26 if (!canvas->getClipBounds(&query)) {
27 // We want to make sure our query rectangle is never totally empty.
28 // Clear ignores the clip, so it must draw even if the clip is logically empty.
29 query = SkRect::MakeWH(SK_ScalarNearlyZero, SK_ScalarNearlyZero);
30 }
mtklein3e8232b2014-08-18 13:39:11 -070031
mtklein6bd41962014-10-02 07:41:56 -070032 SkTDArray<unsigned> ops;
mtkleina723b572014-08-15 11:49:49 -070033 bbh->search(query, &ops);
mtklein5ad6ee12014-08-11 08:08:43 -070034
reed6be2aa92014-11-18 11:08:05 -080035 SkRecords::Draw draw(canvas, drawablePicts, drawableCount);
mtklein5ad6ee12014-08-11 08:08:43 -070036 for (int i = 0; i < ops.count(); i++) {
bsalomon49f085d2014-09-05 13:34:00 -070037 if (callback && callback->abortDrawing()) {
mtklein5ad6ee12014-08-11 08:08:43 -070038 return;
39 }
danakjd239d422014-11-03 12:43:30 -080040 // This visit call uses the SkRecords::Draw::operator() to call
41 // methods on the |canvas|, wrapped by methods defined with the
42 // DRAW() macro.
mtklein6bd41962014-10-02 07:41:56 -070043 record.visit<void>(ops[i], draw);
mtklein5ad6ee12014-08-11 08:08:43 -070044 }
45 } else {
46 // Draw all ops.
reed6be2aa92014-11-18 11:08:05 -080047 SkRecords::Draw draw(canvas, drawablePicts, drawableCount);
mtklein00f30bd2014-09-02 12:03:31 -070048 for (unsigned i = 0; i < record.count(); i++) {
bsalomon49f085d2014-09-05 13:34:00 -070049 if (callback && callback->abortDrawing()) {
mtklein5ad6ee12014-08-11 08:08:43 -070050 return;
51 }
danakjd239d422014-11-03 12:43:30 -080052 // This visit call uses the SkRecords::Draw::operator() to call
53 // methods on the |canvas|, wrapped by methods defined with the
54 // DRAW() macro.
mtklein00f30bd2014-09-02 12:03:31 -070055 record.visit<void>(i, draw);
mtklein5ad6ee12014-08-11 08:08:43 -070056 }
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000057 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000058}
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000059
reed6be2aa92014-11-18 11:08:05 -080060void SkRecordPartialDraw(const SkRecord& record, SkCanvas* canvas,
61 SkPicture const* const drawablePicts[], int drawableCount,
mtklein00f30bd2014-09-02 12:03:31 -070062 const SkRect& clearRect,
robertphillips4815fe52014-09-16 10:32:43 -070063 unsigned start, unsigned stop,
64 const SkMatrix& initialCTM) {
mtklein00f30bd2014-09-02 12:03:31 -070065 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
66
67 stop = SkTMin(stop, record.count());
reed6be2aa92014-11-18 11:08:05 -080068 SkRecords::PartialDraw draw(canvas, NULL, 0, clearRect, initialCTM);
mtklein00f30bd2014-09-02 12:03:31 -070069 for (unsigned i = start; i < stop; i++) {
70 record.visit<void>(i, draw);
71 }
72}
73
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000074namespace SkRecords {
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000075
mtklein7cdc1ee2014-07-07 10:41:04 -070076// FIXME: SkBitmaps are stateful, so we need to copy them to play back in multiple threads.
77static SkBitmap shallow_copy(const SkBitmap& bitmap) {
78 return bitmap;
79}
80
commit-bot@chromium.org2e0c32a2014-04-28 16:19:45 +000081// NoOps draw nothing.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000082template <> void Draw::draw(const NoOp&) {}
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000083
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000084#define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; }
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000085DRAW(Restore, restore());
Florin Malita5f6102d2014-06-30 10:13:28 -040086DRAW(Save, save());
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000087DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags));
88DRAW(PopCull, popCull());
commit-bot@chromium.org88c3e272014-04-22 16:57:20 +000089DRAW(PushCull, pushCull(r.rect));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000090DRAW(Clear, clear(r.color));
commit-bot@chromium.org99bd7d82014-05-19 15:51:12 +000091DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000092
mtkleincdeeb092014-11-20 09:14:28 -080093DRAW(ClipPath, clipPath(r.path, r.opAA.op, r.opAA.aa));
94DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op, r.opAA.aa));
95DRAW(ClipRect, clipRect(r.rect, r.opAA.op, r.opAA.aa));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +000096DRAW(ClipRegion, clipRegion(r.region, r.op));
97
mtklein5f0e8222014-08-22 11:44:26 -070098DRAW(BeginCommentGroup, beginCommentGroup(r.description));
99DRAW(AddComment, addComment(r.key, r.value));
100DRAW(EndCommentGroup, endCommentGroup());
101
mtklein7cdc1ee2014-07-07 10:41:04 -0700102DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint));
103DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.paint));
104DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.paint));
105DRAW(DrawBitmapRectToRect,
mtklein42ddcd42014-11-21 08:48:35 -0800106 drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint,
107 SkCanvas::kNone_DrawBitmapRectFlag));
108DRAW(DrawBitmapRectToRectBleed,
109 drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint,
110 SkCanvas::kBleed_DrawBitmapRectFlag));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +0000111DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
piotaixr65151752014-10-16 11:58:39 -0700112DRAW(DrawImage, drawImage(r.image, r.left, r.top, r.paint));
113DRAW(DrawImageRect, drawImageRect(r.image, r.src, r.dst, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +0000114DRAW(DrawOval, drawOval(r.oval, r.paint));
115DRAW(DrawPaint, drawPaint(r.paint));
116DRAW(DrawPath, drawPath(r.path, r.paint));
mtklein9b222a52014-09-18 11:16:31 -0700117DRAW(DrawPatch, drawPatch(r.cubics, r.colors, r.texCoords, r.xmode, r.paint));
reedd5fa1a42014-08-09 11:08:05 -0700118DRAW(DrawPicture, drawPicture(r.picture, r.matrix, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +0000119DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint));
120DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint));
121DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
122DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
123DRAW(DrawRect, drawRect(r.rect, r.paint));
mtklein7cdc1ee2014-07-07 10:41:04 -0700124DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +0000125DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint));
fmalita00d5c2c2014-08-21 08:53:26 -0700126DRAW(DrawTextBlob, drawTextBlob(r.blob, r.x, r.y, r.paint));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +0000127DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint));
128DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors,
129 r.xmode.get(), r.indices, r.indexCount, r.paint));
mtklein29dfaa82014-09-04 14:12:44 -0700130DRAW(DrawData, drawData(r.data, r.length));
commit-bot@chromium.org73b55eb2014-04-14 20:35:12 +0000131#undef DRAW
132
reed6be2aa92014-11-18 11:08:05 -0800133template <> void Draw::draw(const DrawDrawable& r) {
134 SkASSERT(r.index >= 0);
135 SkASSERT(r.index < fDrawableCount);
136 fCanvas->drawPicture(fDrawablePicts[r.index]);
137}
138
mtklein5ad6ee12014-08-11 08:08:43 -0700139// This is an SkRecord visitor that fills an SkBBoxHierarchy.
mtklein828ce1f2014-08-13 12:58:45 -0700140//
141// The interesting part here is how to calculate bounds for ops which don't
142// have intrinsic bounds. What is the bounds of a Save or a Translate?
143//
144// We answer this by thinking about a particular definition of bounds: if I
145// don't execute this op, pixels in this rectangle might draw incorrectly. So
146// the bounds of a Save, a Translate, a Restore, etc. are the union of the
147// bounds of Draw* ops that they might have an effect on. For any given
148// Save/Restore block, the bounds of the Save, the Restore, and any other
149// non-drawing ("control") ops inside are exactly the union of the bounds of
150// the drawing ops inside that block.
151//
152// To implement this, we keep a stack of active Save blocks. As we consume ops
153// inside the Save/Restore block, drawing ops are unioned with the bounds of
154// the block, and control ops are stashed away for later. When we finish the
155// block with a Restore, our bounds are complete, and we go back and fill them
156// in for all the control ops we stashed away.
mtklein5ad6ee12014-08-11 08:08:43 -0700157class FillBounds : SkNoncopyable {
158public:
robertphillips4e8e3422014-11-12 06:46:08 -0800159 FillBounds(const SkRect& cullRect, const SkRecord& record)
160 : fNumRecords(record.count())
161 , fCullRect(cullRect)
robertphillips4d52afe2014-11-03 08:19:44 -0800162 , fBounds(record.count()) {
mtklein828ce1f2014-08-13 12:58:45 -0700163 // Calculate bounds for all ops. This won't go quite in order, so we'll need
164 // to store the bounds separately then feed them in to the BBH later in order.
mtklein6332f1d2014-08-19 07:09:40 -0700165 fCTM = &SkMatrix::I();
robertphillips4d52afe2014-11-03 08:19:44 -0800166 fCurrentClipBounds = fCullRect;
robertphillips4e8e3422014-11-12 06:46:08 -0800167 }
mtklein5ad6ee12014-08-11 08:08:43 -0700168
robertphillips4e8e3422014-11-12 06:46:08 -0800169 void setCurrentOp(unsigned currentOp) { fCurrentOp = currentOp; }
170
171 void cleanUp(SkBBoxHierarchy* bbh) {
mtklein828ce1f2014-08-13 12:58:45 -0700172 // If we have any lingering unpaired Saves, simulate restores to make
173 // sure all ops in those Save blocks have their bounds calculated.
174 while (!fSaveStack.isEmpty()) {
175 this->popSaveBlock();
176 }
177
178 // Any control ops not part of any Save/Restore block draw everywhere.
179 while (!fControlIndices.isEmpty()) {
robertphillips4d52afe2014-11-03 08:19:44 -0800180 this->popControl(fCullRect);
mtklein828ce1f2014-08-13 12:58:45 -0700181 }
182
183 // Finally feed all stored bounds into the BBH. They'll be returned in this order.
robertphillips89108792014-11-17 08:16:15 -0800184 if (bbh) {
185 bbh->insert(&fBounds, fNumRecords);
186 }
mtklein828ce1f2014-08-13 12:58:45 -0700187 }
mtklein5ad6ee12014-08-11 08:08:43 -0700188
mtkleina723b572014-08-15 11:49:49 -0700189 template <typename T> void operator()(const T& op) {
190 this->updateCTM(op);
191 this->updateClipBounds(op);
192 this->trackBounds(op);
mtklein5ad6ee12014-08-11 08:08:43 -0700193 }
194
mtklein533eb782014-08-27 10:39:42 -0700195 // In this file, SkRect are in local coordinates, Bounds are translated back to identity space.
196 typedef SkRect Bounds;
197
robertphillips4e8e3422014-11-12 06:46:08 -0800198 unsigned currentOp() const { return fCurrentOp; }
199 const SkMatrix& ctm() const { return *fCTM; }
robertphillips4e8e3422014-11-12 06:46:08 -0800200 const Bounds& getBounds(unsigned index) const { return fBounds[index]; }
201
202 // Adjust rect for all paints that may affect its geometry, then map it to identity space.
203 Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const {
204 // Inverted rectangles really confuse our BBHs.
205 rect.sort();
206
207 // Adjust the rect for its own paint.
208 if (!AdjustForPaint(paint, &rect)) {
209 // The paint could do anything to our bounds. The only safe answer is the current clip.
210 return fCurrentClipBounds;
211 }
212
213 // Adjust rect for all the paints from the SaveLayers we're inside.
214 if (!this->adjustForSaveLayerPaints(&rect)) {
215 // Same deal as above.
216 return fCurrentClipBounds;
217 }
218
219 // Map the rect back to identity space.
220 fCTM->mapRect(&rect);
221
222 // Nothing can draw outside the current clip.
223 // (Only bounded ops call into this method, so oddballs like Clear don't matter here.)
224 rect.intersect(fCurrentClipBounds);
225 return rect;
226 }
227
228private:
mtklein828ce1f2014-08-13 12:58:45 -0700229 struct SaveBounds {
mtkleina723b572014-08-15 11:49:49 -0700230 int controlOps; // Number of control ops in this Save block, including the Save.
mtklein533eb782014-08-27 10:39:42 -0700231 Bounds bounds; // Bounds of everything in the block.
mtkleina723b572014-08-15 11:49:49 -0700232 const SkPaint* paint; // Unowned. If set, adjusts the bounds of all ops in this block.
mtklein828ce1f2014-08-13 12:58:45 -0700233 };
234
mtklein8e393bf2014-10-01 12:48:58 -0700235 // Only Restore and SetMatrix change the CTM.
236 template <typename T> void updateCTM(const T&) {}
mtklein6332f1d2014-08-19 07:09:40 -0700237 void updateCTM(const Restore& op) { fCTM = &op.matrix; }
238 void updateCTM(const SetMatrix& op) { fCTM = &op.matrix; }
mtkleina723b572014-08-15 11:49:49 -0700239
mtklein8e393bf2014-10-01 12:48:58 -0700240 // Most ops don't change the clip.
241 template <typename T> void updateClipBounds(const T&) {}
Mike Klein271a0302014-09-23 15:28:38 -0400242
mtklein8e393bf2014-10-01 12:48:58 -0700243 // Clip{Path,RRect,Rect,Region} obviously change the clip. They all know their bounds already.
244 void updateClipBounds(const ClipPath& op) { this->updateClipBoundsForClipOp(op.devBounds); }
245 void updateClipBounds(const ClipRRect& op) { this->updateClipBoundsForClipOp(op.devBounds); }
246 void updateClipBounds(const ClipRect& op) { this->updateClipBoundsForClipOp(op.devBounds); }
247 void updateClipBounds(const ClipRegion& op) { this->updateClipBoundsForClipOp(op.devBounds); }
Mike Klein271a0302014-09-23 15:28:38 -0400248
mtklein8e393bf2014-10-01 12:48:58 -0700249 // The bounds of clip ops need to be adjusted for the paints of saveLayers they're inside.
250 void updateClipBoundsForClipOp(const SkIRect& devBounds) {
251 Bounds clip = SkRect::Make(devBounds);
Mike Klein271a0302014-09-23 15:28:38 -0400252 // We don't call adjustAndMap() because as its last step it would intersect the adjusted
253 // clip bounds with the previous clip, exactly what we can't do when the clip grows.
robertphillips4d52afe2014-11-03 08:19:44 -0800254 fCurrentClipBounds = this->adjustForSaveLayerPaints(&clip) ? clip : fCullRect;
Mike Klein271a0302014-09-23 15:28:38 -0400255 }
256
mtklein8e393bf2014-10-01 12:48:58 -0700257 // Restore holds the devBounds for the clip after the {save,saveLayer}/restore block completes.
258 void updateClipBounds(const Restore& op) {
259 // This is just like the clip ops above, but we need to skip the effects (if any) of our
260 // paired saveLayer (if it is one); it has not yet been popped off the save stack. Our
261 // devBounds reflect the state of the world after the saveLayer/restore block is done,
262 // so they are not affected by the saveLayer's paint.
263 const int kSavesToIgnore = 1;
264 Bounds clip = SkRect::Make(op.devBounds);
265 fCurrentClipBounds =
robertphillips4d52afe2014-11-03 08:19:44 -0800266 this->adjustForSaveLayerPaints(&clip, kSavesToIgnore) ? clip : fCullRect;
mtklein8e393bf2014-10-01 12:48:58 -0700267 }
268
Mike Klein271a0302014-09-23 15:28:38 -0400269 // We also take advantage of SaveLayer bounds when present to further cut the clip down.
mtkleina723b572014-08-15 11:49:49 -0700270 void updateClipBounds(const SaveLayer& op) {
271 if (op.bounds) {
Mike Klein271a0302014-09-23 15:28:38 -0400272 // adjustAndMap() intersects these layer bounds with the previous clip for us.
273 fCurrentClipBounds = this->adjustAndMap(*op.bounds, op.paint);
mtkleina723b572014-08-15 11:49:49 -0700274 }
275 }
mtklein6cfa73a2014-08-13 13:33:49 -0700276
mtklein828ce1f2014-08-13 12:58:45 -0700277 // The bounds of these ops must be calculated when we hit the Restore
278 // from the bounds of the ops in the same Save block.
mtkleina723b572014-08-15 11:49:49 -0700279 void trackBounds(const Save&) { this->pushSaveBlock(NULL); }
mtkleina723b572014-08-15 11:49:49 -0700280 void trackBounds(const SaveLayer& op) { this->pushSaveBlock(op.paint); }
281 void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(); }
mtklein828ce1f2014-08-13 12:58:45 -0700282
mtklein68199a22014-08-25 13:49:29 -0700283 void trackBounds(const SetMatrix&) { this->pushControl(); }
284 void trackBounds(const ClipRect&) { this->pushControl(); }
285 void trackBounds(const ClipRRect&) { this->pushControl(); }
286 void trackBounds(const ClipPath&) { this->pushControl(); }
287 void trackBounds(const ClipRegion&) { this->pushControl(); }
288 void trackBounds(const PushCull&) { this->pushControl(); }
289 void trackBounds(const PopCull&) { this->pushControl(); }
290 void trackBounds(const BeginCommentGroup&) { this->pushControl(); }
291 void trackBounds(const AddComment&) { this->pushControl(); }
292 void trackBounds(const EndCommentGroup&) { this->pushControl(); }
mtklein29dfaa82014-09-04 14:12:44 -0700293 void trackBounds(const DrawData&) { this->pushControl(); }
mtklein828ce1f2014-08-13 12:58:45 -0700294
295 // For all other ops, we can calculate and store the bounds directly now.
296 template <typename T> void trackBounds(const T& op) {
297 fBounds[fCurrentOp] = this->bounds(op);
298 this->updateSaveBounds(fBounds[fCurrentOp]);
mtklein5ad6ee12014-08-11 08:08:43 -0700299 }
300
mtkleina723b572014-08-15 11:49:49 -0700301 void pushSaveBlock(const SkPaint* paint) {
mtklein828ce1f2014-08-13 12:58:45 -0700302 // Starting a new Save block. Push a new entry to represent that.
robertphillips4d52afe2014-11-03 08:19:44 -0800303 SaveBounds sb;
304 sb.controlOps = 0;
305 // If the paint affects transparent black, the bound shouldn't be smaller
306 // than the current clip bounds.
307 sb.bounds =
308 PaintMayAffectTransparentBlack(paint) ? fCurrentClipBounds : Bounds::MakeEmpty();
309 sb.paint = paint;
310
mtklein828ce1f2014-08-13 12:58:45 -0700311 fSaveStack.push(sb);
312 this->pushControl();
313 }
314
mtkleind910f542014-08-22 09:06:34 -0700315 static bool PaintMayAffectTransparentBlack(const SkPaint* paint) {
dneto327f9052014-09-15 10:53:16 -0700316 if (paint) {
317 // FIXME: this is very conservative
318 if (paint->getImageFilter() || paint->getColorFilter()) {
319 return true;
320 }
321
322 // Unusual Xfermodes require us to process a saved layer
323 // even with operations outisde the clip.
324 // For example, DstIn is used by masking layers.
325 // https://code.google.com/p/skia/issues/detail?id=1291
326 // https://crbug.com/401593
327 SkXfermode* xfermode = paint->getXfermode();
328 SkXfermode::Mode mode;
329 // SrcOver is ok, and is also the common case with a NULL xfermode.
330 // So we should make that the fast path and bypass the mode extraction
331 // and test.
332 if (xfermode && xfermode->asMode(&mode)) {
333 switch (mode) {
334 // For each of the following transfer modes, if the source
335 // alpha is zero (our transparent black), the resulting
336 // blended alpha is not necessarily equal to the original
337 // destination alpha.
338 case SkXfermode::kClear_Mode:
339 case SkXfermode::kSrc_Mode:
340 case SkXfermode::kSrcIn_Mode:
341 case SkXfermode::kDstIn_Mode:
342 case SkXfermode::kSrcOut_Mode:
343 case SkXfermode::kDstATop_Mode:
344 case SkXfermode::kModulate_Mode:
345 return true;
346 break;
347 default:
348 break;
349 }
350 }
351 }
352 return false;
mtkleind910f542014-08-22 09:06:34 -0700353 }
354
mtklein533eb782014-08-27 10:39:42 -0700355 Bounds popSaveBlock() {
mtklein828ce1f2014-08-13 12:58:45 -0700356 // We're done the Save block. Apply the block's bounds to all control ops inside it.
357 SaveBounds sb;
358 fSaveStack.pop(&sb);
mtkleind910f542014-08-22 09:06:34 -0700359
mtklein828ce1f2014-08-13 12:58:45 -0700360 while (sb.controlOps --> 0) {
robertphillips4d52afe2014-11-03 08:19:44 -0800361 this->popControl(sb.bounds);
mtklein828ce1f2014-08-13 12:58:45 -0700362 }
363
364 // This whole Save block may be part another Save block.
robertphillips4d52afe2014-11-03 08:19:44 -0800365 this->updateSaveBounds(sb.bounds);
mtklein828ce1f2014-08-13 12:58:45 -0700366
367 // If called from a real Restore (not a phony one for balance), it'll need the bounds.
robertphillips4d52afe2014-11-03 08:19:44 -0800368 return sb.bounds;
mtklein828ce1f2014-08-13 12:58:45 -0700369 }
370
371 void pushControl() {
372 fControlIndices.push(fCurrentOp);
373 if (!fSaveStack.isEmpty()) {
374 fSaveStack.top().controlOps++;
375 }
376 }
377
mtklein533eb782014-08-27 10:39:42 -0700378 void popControl(const Bounds& bounds) {
mtklein828ce1f2014-08-13 12:58:45 -0700379 fBounds[fControlIndices.top()] = bounds;
380 fControlIndices.pop();
381 }
382
mtklein533eb782014-08-27 10:39:42 -0700383 void updateSaveBounds(const Bounds& bounds) {
mtklein828ce1f2014-08-13 12:58:45 -0700384 // If we're in a Save block, expand its bounds to cover these bounds too.
385 if (!fSaveStack.isEmpty()) {
386 fSaveStack.top().bounds.join(bounds);
387 }
388 }
389
mtklein131a22b2014-08-25 14:16:15 -0700390 // FIXME: this method could use better bounds
mtklein533eb782014-08-27 10:39:42 -0700391 Bounds bounds(const DrawText&) const { return fCurrentClipBounds; }
mtklein68199a22014-08-25 13:49:29 -0700392
robertphillips4d52afe2014-11-03 08:19:44 -0800393 Bounds bounds(const Clear&) const { return fCullRect; } // Ignores the clip.
mtklein533eb782014-08-27 10:39:42 -0700394 Bounds bounds(const DrawPaint&) const { return fCurrentClipBounds; }
395 Bounds bounds(const NoOp&) const { return Bounds::MakeEmpty(); } // NoOps don't draw.
mtklein828ce1f2014-08-13 12:58:45 -0700396
mtklein533eb782014-08-27 10:39:42 -0700397 Bounds bounds(const DrawSprite& op) const {
mtklein131a22b2014-08-25 14:16:15 -0700398 const SkBitmap& bm = op.bitmap;
mtklein533eb782014-08-27 10:39:42 -0700399 return Bounds::MakeXYWH(op.left, op.top, bm.width(), bm.height()); // Ignores the matrix.
mtklein131a22b2014-08-25 14:16:15 -0700400 }
401
mtklein533eb782014-08-27 10:39:42 -0700402 Bounds bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect, &op.paint); }
403 Bounds bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval, &op.paint); }
404 Bounds bounds(const DrawRRect& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700405 return this->adjustAndMap(op.rrect.rect(), &op.paint);
406 }
mtklein533eb782014-08-27 10:39:42 -0700407 Bounds bounds(const DrawDRRect& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700408 return this->adjustAndMap(op.outer.rect(), &op.paint);
409 }
piotaixr65151752014-10-16 11:58:39 -0700410 Bounds bounds(const DrawImage& op) const {
411 const SkImage* image = op.image;
412 SkRect rect = SkRect::MakeXYWH(op.left, op.top, image->width(), image->height());
mtklein62b67ae2014-08-18 11:10:37 -0700413
piotaixr65151752014-10-16 11:58:39 -0700414 return this->adjustAndMap(rect, op.paint);
415 }
416 Bounds bounds(const DrawImageRect& op) const {
417 return this->adjustAndMap(op.dst, op.paint);
418 }
mtklein533eb782014-08-27 10:39:42 -0700419 Bounds bounds(const DrawBitmapRectToRect& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700420 return this->adjustAndMap(op.dst, op.paint);
421 }
mtklein42ddcd42014-11-21 08:48:35 -0800422 Bounds bounds(const DrawBitmapRectToRectBleed& op) const {
423 return this->adjustAndMap(op.dst, op.paint);
424 }
mtklein533eb782014-08-27 10:39:42 -0700425 Bounds bounds(const DrawBitmapNine& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700426 return this->adjustAndMap(op.dst, op.paint);
427 }
mtklein533eb782014-08-27 10:39:42 -0700428 Bounds bounds(const DrawBitmap& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700429 const SkBitmap& bm = op.bitmap;
430 return this->adjustAndMap(SkRect::MakeXYWH(op.left, op.top, bm.width(), bm.height()),
431 op.paint);
432 }
mtklein533eb782014-08-27 10:39:42 -0700433 Bounds bounds(const DrawBitmapMatrix& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700434 const SkBitmap& bm = op.bitmap;
435 SkRect dst = SkRect::MakeWH(bm.width(), bm.height());
436 op.matrix.mapRect(&dst);
437 return this->adjustAndMap(dst, op.paint);
438 }
439
mtklein533eb782014-08-27 10:39:42 -0700440 Bounds bounds(const DrawPath& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700441 return op.path.isInverseFillType() ? fCurrentClipBounds
442 : this->adjustAndMap(op.path.getBounds(), &op.paint);
443 }
mtklein533eb782014-08-27 10:39:42 -0700444 Bounds bounds(const DrawPoints& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700445 SkRect dst;
446 dst.set(op.pts, op.count);
447
448 // Pad the bounding box a little to make sure hairline points' bounds aren't empty.
449 SkScalar stroke = SkMaxScalar(op.paint.getStrokeWidth(), 0.01f);
450 dst.outset(stroke/2, stroke/2);
451
452 return this->adjustAndMap(dst, &op.paint);
453 }
mtklein533eb782014-08-27 10:39:42 -0700454 Bounds bounds(const DrawPatch& op) const {
mtklein131a22b2014-08-25 14:16:15 -0700455 SkRect dst;
456 dst.set(op.cubics, SkPatchUtils::kNumCtrlPts);
457 return this->adjustAndMap(dst, &op.paint);
458 }
mtklein533eb782014-08-27 10:39:42 -0700459 Bounds bounds(const DrawVertices& op) const {
mtklein131a22b2014-08-25 14:16:15 -0700460 SkRect dst;
461 dst.set(op.vertices, op.vertexCount);
462 return this->adjustAndMap(dst, &op.paint);
463 }
464
mtklein533eb782014-08-27 10:39:42 -0700465 Bounds bounds(const DrawPicture& op) const {
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700466 SkRect dst = op.picture->cullRect();
mtklein131a22b2014-08-25 14:16:15 -0700467 if (op.matrix) {
468 op.matrix->mapRect(&dst);
469 }
470 return this->adjustAndMap(dst, op.paint);
471 }
mtklein62b67ae2014-08-18 11:10:37 -0700472
mtklein533eb782014-08-27 10:39:42 -0700473 Bounds bounds(const DrawPosText& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700474 const int N = op.paint.countText(op.text, op.byteLength);
475 if (N == 0) {
mtklein533eb782014-08-27 10:39:42 -0700476 return Bounds::MakeEmpty();
mtklein62b67ae2014-08-18 11:10:37 -0700477 }
478
479 SkRect dst;
mtklein937c9c72014-09-02 15:19:48 -0700480 dst.set(op.pos, N);
mtklein62b67ae2014-08-18 11:10:37 -0700481 AdjustTextForFontMetrics(&dst, op.paint);
482 return this->adjustAndMap(dst, &op.paint);
483 }
mtklein533eb782014-08-27 10:39:42 -0700484 Bounds bounds(const DrawPosTextH& op) const {
mtklein62b67ae2014-08-18 11:10:37 -0700485 const int N = op.paint.countText(op.text, op.byteLength);
486 if (N == 0) {
mtklein533eb782014-08-27 10:39:42 -0700487 return Bounds::MakeEmpty();
mtklein62b67ae2014-08-18 11:10:37 -0700488 }
489
490 SkScalar left = op.xpos[0], right = op.xpos[0];
491 for (int i = 1; i < N; i++) {
492 left = SkMinScalar(left, op.xpos[i]);
493 right = SkMaxScalar(right, op.xpos[i]);
494 }
495 SkRect dst = { left, op.y, right, op.y };
496 AdjustTextForFontMetrics(&dst, op.paint);
497 return this->adjustAndMap(dst, &op.paint);
498 }
mtklein533eb782014-08-27 10:39:42 -0700499 Bounds bounds(const DrawTextOnPath& op) const {
mtklein131a22b2014-08-25 14:16:15 -0700500 SkRect dst = op.path.getBounds();
501
mtkleined167ac2014-10-29 16:07:10 -0700502 // Pad all sides by the maximum padding in any direction we'd normally apply.
mtklein131a22b2014-08-25 14:16:15 -0700503 SkRect pad = { 0, 0, 0, 0};
504 AdjustTextForFontMetrics(&pad, op.paint);
mtkleined167ac2014-10-29 16:07:10 -0700505
506 // That maximum padding happens to always be the right pad today.
507 SkASSERT(pad.fLeft == -pad.fRight);
508 SkASSERT(pad.fTop == -pad.fBottom);
509 SkASSERT(pad.fRight > pad.fBottom);
510 dst.outset(pad.fRight, pad.fRight);
mtklein131a22b2014-08-25 14:16:15 -0700511
512 return this->adjustAndMap(dst, &op.paint);
513 }
514
mtklein533eb782014-08-27 10:39:42 -0700515 Bounds bounds(const DrawTextBlob& op) const {
mtklein131a22b2014-08-25 14:16:15 -0700516 SkRect dst = op.blob->bounds();
517 dst.offset(op.x, op.y);
mtklein131a22b2014-08-25 14:16:15 -0700518 return this->adjustAndMap(dst, &op.paint);
519 }
mtklein62b67ae2014-08-18 11:10:37 -0700520
reed6be2aa92014-11-18 11:08:05 -0800521 Bounds bounds(const DrawDrawable& op) const {
522 return this->adjustAndMap(op.worstCaseBounds, NULL);
523 }
524
mtklein62b67ae2014-08-18 11:10:37 -0700525 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) {
mtkleined167ac2014-10-29 16:07:10 -0700526#ifdef SK_DEBUG
527 SkRect correct = *rect;
528#endif
529 // crbug.com/373785 ~~> xPad = 4x yPad
530 // crbug.com/424824 ~~> bump yPad from 2x text size to 2.5x
531 const SkScalar yPad = 2.5f * paint.getTextSize(),
532 xPad = 4.0f * yPad;
533 rect->outset(xPad, yPad);
caryclark9a657fa2014-08-20 05:24:29 -0700534#ifdef SK_DEBUG
mtklein62b67ae2014-08-18 11:10:37 -0700535 SkPaint::FontMetrics metrics;
536 paint.getFontMetrics(&metrics);
mtkleined167ac2014-10-29 16:07:10 -0700537 correct.fLeft += metrics.fXMin;
538 correct.fTop += metrics.fTop;
539 correct.fRight += metrics.fXMax;
540 correct.fBottom += metrics.fBottom;
mtkleind13291a2014-08-21 14:46:49 -0700541 // See skia:2862 for why we ignore small text sizes.
mtkleined167ac2014-10-29 16:07:10 -0700542 SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct),
543 "%f %f %f %f vs. %f %f %f %f\n",
544 -xPad, -yPad, +xPad, +yPad,
545 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom);
mtkleina19afb42014-08-19 17:47:14 -0700546#endif
mtklein62b67ae2014-08-18 11:10:37 -0700547 }
548
mtklein479601b2014-08-18 08:45:33 -0700549 // Returns true if rect was meaningfully adjusted for the effects of paint,
550 // false if the paint could affect the rect in unknown ways.
551 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) {
mtkleina723b572014-08-15 11:49:49 -0700552 if (paint) {
553 if (paint->canComputeFastBounds()) {
mtklein479601b2014-08-18 08:45:33 -0700554 *rect = paint->computeFastBounds(*rect, rect);
555 return true;
mtkleina723b572014-08-15 11:49:49 -0700556 }
mtklein479601b2014-08-18 08:45:33 -0700557 return false;
558 }
559 return true;
560 }
561
mtklein8e393bf2014-10-01 12:48:58 -0700562 bool adjustForSaveLayerPaints(SkRect* rect, int savesToIgnore = 0) const {
563 for (int i = fSaveStack.count() - 1 - savesToIgnore; i >= 0; i--) {
Mike Klein271a0302014-09-23 15:28:38 -0400564 if (!AdjustForPaint(fSaveStack[i].paint, rect)) {
565 return false;
566 }
567 }
568 return true;
569 }
570
robertphillips4e8e3422014-11-12 06:46:08 -0800571 const unsigned fNumRecords;
mtkleina723b572014-08-15 11:49:49 -0700572
robertphillips4d52afe2014-11-03 08:19:44 -0800573 // We do not guarantee anything for operations outside of the cull rect
574 const SkRect fCullRect;
575
mtklein533eb782014-08-27 10:39:42 -0700576 // Conservative identity-space bounds for each op in the SkRecord.
577 SkAutoTMalloc<Bounds> fBounds;
mtkleina723b572014-08-15 11:49:49 -0700578
579 // We walk fCurrentOp through the SkRecord, as we go using updateCTM()
580 // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative
mtklein533eb782014-08-27 10:39:42 -0700581 // identity-space bounds of the current clip (fCurrentClipBounds).
mtklein828ce1f2014-08-13 12:58:45 -0700582 unsigned fCurrentOp;
mtklein6332f1d2014-08-19 07:09:40 -0700583 const SkMatrix* fCTM;
mtklein533eb782014-08-27 10:39:42 -0700584 Bounds fCurrentClipBounds;
mtkleina723b572014-08-15 11:49:49 -0700585
586 // Used to track the bounds of Save/Restore blocks and the control ops inside them.
mtklein828ce1f2014-08-13 12:58:45 -0700587 SkTDArray<SaveBounds> fSaveStack;
588 SkTDArray<unsigned> fControlIndices;
mtklein5ad6ee12014-08-11 08:08:43 -0700589};
590
robertphillips4e8e3422014-11-12 06:46:08 -0800591// SkRecord visitor to gather saveLayer/restore information.
592class CollectLayers : SkNoncopyable {
593public:
robertphillips82365912014-11-12 09:32:34 -0800594 CollectLayers(const SkRect& cullRect, const SkRecord& record, SkLayerInfo* accelData)
robertphillips4e8e3422014-11-12 06:46:08 -0800595 : fSaveLayersInStack(0)
596 , fAccelData(accelData)
597 , fFillBounds(cullRect, record) {
598 }
599
600 void setCurrentOp(unsigned currentOp) { fFillBounds.setCurrentOp(currentOp); }
601
602 void cleanUp(SkBBoxHierarchy* bbh) {
603 // fFillBounds must perform its cleanUp first so that all the bounding
604 // boxes associated with unbalanced restores are updated (prior to
605 // fetching their bound in popSaveLayerInfo).
606 fFillBounds.cleanUp(bbh);
607
608 while (!fSaveLayerStack.isEmpty()) {
609 this->popSaveLayerInfo();
610 }
611 }
612
613 template <typename T> void operator()(const T& op) {
614 fFillBounds(op);
615 this->trackSaveLayers(op);
616 }
617
618private:
619 struct SaveLayerInfo {
620 SaveLayerInfo() { }
robertphillips74576eb2014-11-12 07:25:02 -0800621 SaveLayerInfo(int opIndex, bool isSaveLayer, const SkPaint* paint)
robertphillips4e8e3422014-11-12 06:46:08 -0800622 : fStartIndex(opIndex)
623 , fIsSaveLayer(isSaveLayer)
624 , fHasNestedSaveLayer(false)
robertphillips74576eb2014-11-12 07:25:02 -0800625 , fPaint(paint) {
robertphillips4e8e3422014-11-12 06:46:08 -0800626 }
627
628 int fStartIndex;
629 bool fIsSaveLayer;
630 bool fHasNestedSaveLayer;
631 const SkPaint* fPaint;
robertphillips4e8e3422014-11-12 06:46:08 -0800632 };
633
634 template <typename T> void trackSaveLayers(const T& op) {
635 /* most ops aren't involved in saveLayers */
636 }
637 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL); }
638 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl.paint); }
639 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); }
640
641 void trackSaveLayers(const DrawPicture& dp) {
642 // For sub-pictures, we wrap their layer information within the parent
643 // picture's rendering hierarchy
robertphillips82365912014-11-12 09:32:34 -0800644 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
robertphillips4e8e3422014-11-12 06:46:08 -0800645
robertphillips82365912014-11-12 09:32:34 -0800646 const SkLayerInfo* childData =
647 static_cast<const SkLayerInfo*>(dp.picture->EXPERIMENTAL_getAccelData(key));
robertphillips4e8e3422014-11-12 06:46:08 -0800648 if (!childData) {
649 // If the child layer hasn't been generated with saveLayer data we
650 // assume the worst (i.e., that it does contain layers which nest
651 // inside existing layers). Layers within sub-pictures that don't
652 // have saveLayer data cannot be hoisted.
653 // TODO: could the analysis data be use to fine tune this?
654 this->updateStackForSaveLayer();
655 return;
656 }
657
robertphillips82365912014-11-12 09:32:34 -0800658 for (int i = 0; i < childData->numBlocks(); ++i) {
659 const SkLayerInfo::BlockInfo& src = childData->block(i);
robertphillips4e8e3422014-11-12 06:46:08 -0800660
robertphillips74576eb2014-11-12 07:25:02 -0800661 FillBounds::Bounds newBound = fFillBounds.adjustAndMap(src.fBounds, dp.paint);
662 if (newBound.isEmpty()) {
robertphillips4e8e3422014-11-12 06:46:08 -0800663 continue;
664 }
665
666 this->updateStackForSaveLayer();
667
robertphillips82365912014-11-12 09:32:34 -0800668 SkLayerInfo::BlockInfo& dst = fAccelData->addBlock();
robertphillips4e8e3422014-11-12 06:46:08 -0800669
670 // If src.fPicture is NULL the layer is in dp.picture; otherwise
671 // it belongs to a sub-picture.
672 dst.fPicture = src.fPicture ? src.fPicture : static_cast<const SkPicture*>(dp.picture);
673 dst.fPicture->ref();
robertphillips74576eb2014-11-12 07:25:02 -0800674 dst.fBounds = newBound;
robertphillips4e8e3422014-11-12 06:46:08 -0800675 dst.fLocalMat = src.fLocalMat;
676 dst.fPreMat = src.fPreMat;
677 dst.fPreMat.postConcat(fFillBounds.ctm());
678 if (src.fPaint) {
679 dst.fPaint = SkNEW_ARGS(SkPaint, (*src.fPaint));
680 }
681 dst.fSaveLayerOpID = src.fSaveLayerOpID;
682 dst.fRestoreOpID = src.fRestoreOpID;
683 dst.fHasNestedLayers = src.fHasNestedLayers;
684 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested;
685 }
686 }
687
688 // Inform all the saveLayers already on the stack that they now have a
689 // nested saveLayer inside them
690 void updateStackForSaveLayer() {
691 for (int index = fSaveLayerStack.count() - 1; index >= 0; --index) {
692 if (fSaveLayerStack[index].fHasNestedSaveLayer) {
693 break;
694 }
695 fSaveLayerStack[index].fHasNestedSaveLayer = true;
696 if (fSaveLayerStack[index].fIsSaveLayer) {
697 break;
698 }
699 }
700 }
701
702 void pushSaveLayerInfo(bool isSaveLayer, const SkPaint* paint) {
703 if (isSaveLayer) {
704 this->updateStackForSaveLayer();
705 ++fSaveLayersInStack;
706 }
707
robertphillips74576eb2014-11-12 07:25:02 -0800708 fSaveLayerStack.push(SaveLayerInfo(fFillBounds.currentOp(), isSaveLayer, paint));
robertphillips4e8e3422014-11-12 06:46:08 -0800709 }
710
711 void popSaveLayerInfo() {
712 if (fSaveLayerStack.count() <= 0) {
713 SkASSERT(false);
714 return;
715 }
716
717 SaveLayerInfo sli;
718 fSaveLayerStack.pop(&sli);
719
720 if (!sli.fIsSaveLayer) {
721 return;
722 }
723
724 --fSaveLayersInStack;
725
robertphillips82365912014-11-12 09:32:34 -0800726 SkLayerInfo::BlockInfo& block = fAccelData->addBlock();
robertphillips4e8e3422014-11-12 06:46:08 -0800727
robertphillips82365912014-11-12 09:32:34 -0800728 SkASSERT(NULL == block.fPicture); // This layer is in the top-most picture
robertphillips4e8e3422014-11-12 06:46:08 -0800729
robertphillips82365912014-11-12 09:32:34 -0800730 block.fBounds = fFillBounds.getBounds(sli.fStartIndex);
731 block.fLocalMat = fFillBounds.ctm();
732 block.fPreMat = SkMatrix::I();
robertphillips4e8e3422014-11-12 06:46:08 -0800733 if (sli.fPaint) {
robertphillips82365912014-11-12 09:32:34 -0800734 block.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint));
robertphillips4e8e3422014-11-12 06:46:08 -0800735 }
robertphillips82365912014-11-12 09:32:34 -0800736 block.fSaveLayerOpID = sli.fStartIndex;
737 block.fRestoreOpID = fFillBounds.currentOp();
738 block.fHasNestedLayers = sli.fHasNestedSaveLayer;
739 block.fIsNested = fSaveLayersInStack > 0;
robertphillips4e8e3422014-11-12 06:46:08 -0800740 }
741
742 // Used to collect saveLayer information for layer hoisting
743 int fSaveLayersInStack;
744 SkTDArray<SaveLayerInfo> fSaveLayerStack;
robertphillips82365912014-11-12 09:32:34 -0800745 SkLayerInfo* fAccelData;
robertphillips4e8e3422014-11-12 06:46:08 -0800746
747 SkRecords::FillBounds fFillBounds;
748};
robertphillips4e8e3422014-11-12 06:46:08 -0800749
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +0000750} // namespace SkRecords
mtklein5ad6ee12014-08-11 08:08:43 -0700751
robertphillips4d52afe2014-11-03 08:19:44 -0800752void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkBBoxHierarchy* bbh) {
robertphillips4e8e3422014-11-12 06:46:08 -0800753 SkRecords::FillBounds visitor(cullRect, record);
754
755 for (unsigned curOp = 0; curOp < record.count(); curOp++) {
756 visitor.setCurrentOp(curOp);
757 record.visit<void>(curOp, visitor);
758 }
759
760 visitor.cleanUp(bbh);
mtklein5ad6ee12014-08-11 08:08:43 -0700761}
robertphillips4e8e3422014-11-12 06:46:08 -0800762
robertphillips4e8e3422014-11-12 06:46:08 -0800763void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record,
robertphillips82365912014-11-12 09:32:34 -0800764 SkBBoxHierarchy* bbh, SkLayerInfo* data) {
robertphillips4e8e3422014-11-12 06:46:08 -0800765 SkRecords::CollectLayers visitor(cullRect, record, data);
766
767 for (unsigned curOp = 0; curOp < record.count(); curOp++) {
768 visitor.setCurrentOp(curOp);
769 record.visit<void>(curOp, visitor);
770 }
771
772 visitor.cleanUp(bbh);
773}
robertphillips4e8e3422014-11-12 06:46:08 -0800774