commit-bot@chromium.org | c4b21e6 | 2014-04-11 18:33:31 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 8 | #include "SkLayerInfo.h" |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 9 | #include "SkRecordDraw.h" |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 10 | #include "SkPatchUtils.h" |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 11 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 12 | void SkRecordDraw(const SkRecord& record, |
| 13 | SkCanvas* canvas, |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 14 | SkPicture const* const drawablePicts[], |
reed | 3cb3840 | 2015-02-06 08:36:15 -0800 | [diff] [blame] | 15 | SkDrawable* const drawables[], |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 16 | int drawableCount, |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 17 | const SkBBoxHierarchy* bbh, |
robertphillips | 783fe16 | 2015-01-07 07:28:41 -0800 | [diff] [blame] | 18 | SkPicture::AbortCallback* callback) { |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 19 | SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 20 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 21 | if (bbh) { |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 22 | // Draw only ops that affect pixels in the canvas's current clip. |
mtklein | 3e8232b | 2014-08-18 13:39:11 -0700 | [diff] [blame] | 23 | // The SkRecord and BBH were recorded in identity space. This canvas |
| 24 | // is not necessarily in that same space. getClipBounds() returns us |
| 25 | // this canvas' clip bounds transformed back into identity space, which |
| 26 | // lets us query the BBH. |
mtklein | 7cc1a34 | 2014-11-20 08:01:09 -0800 | [diff] [blame] | 27 | SkRect query; |
| 28 | if (!canvas->getClipBounds(&query)) { |
mtklein | 49aabde | 2015-01-05 07:02:45 -0800 | [diff] [blame] | 29 | query.setEmpty(); |
mtklein | 7cc1a34 | 2014-11-20 08:01:09 -0800 | [diff] [blame] | 30 | } |
mtklein | 3e8232b | 2014-08-18 13:39:11 -0700 | [diff] [blame] | 31 | |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 32 | SkTDArray<int> ops; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 33 | bbh->search(query, &ops); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 34 | |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 35 | SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 36 | for (int i = 0; i < ops.count(); i++) { |
robertphillips | 783fe16 | 2015-01-07 07:28:41 -0800 | [diff] [blame] | 37 | if (callback && callback->abort()) { |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 38 | return; |
| 39 | } |
danakj | d239d42 | 2014-11-03 12:43:30 -0800 | [diff] [blame] | 40 | // This visit call uses the SkRecords::Draw::operator() to call |
| 41 | // methods on the |canvas|, wrapped by methods defined with the |
| 42 | // DRAW() macro. |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 43 | record.visit<void>(ops[i], draw); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 44 | } |
| 45 | } else { |
| 46 | // Draw all ops. |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 47 | SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 48 | for (int i = 0; i < record.count(); i++) { |
robertphillips | 783fe16 | 2015-01-07 07:28:41 -0800 | [diff] [blame] | 49 | if (callback && callback->abort()) { |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 50 | return; |
| 51 | } |
danakj | d239d42 | 2014-11-03 12:43:30 -0800 | [diff] [blame] | 52 | // This visit call uses the SkRecords::Draw::operator() to call |
| 53 | // methods on the |canvas|, wrapped by methods defined with the |
| 54 | // DRAW() macro. |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 55 | record.visit<void>(i, draw); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 56 | } |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 57 | } |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 58 | } |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 59 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 60 | void SkRecordPartialDraw(const SkRecord& record, SkCanvas* canvas, |
| 61 | SkPicture const* const drawablePicts[], int drawableCount, |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 62 | int start, int stop, |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 63 | const SkMatrix& initialCTM) { |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 64 | SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
| 65 | |
| 66 | stop = SkTMin(stop, record.count()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 67 | SkRecords::Draw draw(canvas, drawablePicts, nullptr, drawableCount, &initialCTM); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 68 | for (int i = start; i < stop; i++) { |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 69 | record.visit<void>(i, draw); |
| 70 | } |
| 71 | } |
| 72 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 73 | namespace SkRecords { |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 74 | |
commit-bot@chromium.org | 2e0c32a | 2014-04-28 16:19:45 +0000 | [diff] [blame] | 75 | // NoOps draw nothing. |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 76 | template <> void Draw::draw(const NoOp&) {} |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 77 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 78 | #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 79 | DRAW(Restore, restore()); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 80 | DRAW(Save, save()); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 81 | DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); |
commit-bot@chromium.org | 99bd7d8 | 2014-05-19 15:51:12 +0000 | [diff] [blame] | 82 | DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 83 | DRAW(Concat, concat(r.matrix)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 84 | |
mtklein | cdeeb09 | 2014-11-20 09:14:28 -0800 | [diff] [blame] | 85 | DRAW(ClipPath, clipPath(r.path, r.opAA.op, r.opAA.aa)); |
| 86 | DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op, r.opAA.aa)); |
| 87 | DRAW(ClipRect, clipRect(r.rect, r.opAA.op, r.opAA.aa)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 88 | DRAW(ClipRegion, clipRegion(r.region, r.op)); |
| 89 | |
mtklein | f55c314 | 2014-12-11 12:43:04 -0800 | [diff] [blame] | 90 | DRAW(DrawBitmap, drawBitmap(r.bitmap.shallowCopy(), r.left, r.top, r.paint)); |
| 91 | DRAW(DrawBitmapNine, drawBitmapNine(r.bitmap.shallowCopy(), r.center, r.dst, r.paint)); |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 92 | DRAW(DrawBitmapRect, |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 93 | legacy_drawBitmapRect(r.bitmap.shallowCopy(), r.src, r.dst, r.paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 94 | SkCanvas::kStrict_SrcRectConstraint)); |
| 95 | DRAW(DrawBitmapRectFast, |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 96 | legacy_drawBitmapRect(r.bitmap.shallowCopy(), r.src, r.dst, r.paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 97 | SkCanvas::kFast_SrcRectConstraint)); |
| 98 | DRAW(DrawBitmapRectFixedSize, |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 99 | legacy_drawBitmapRect(r.bitmap.shallowCopy(), &r.src, r.dst, &r.paint, r.constraint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 100 | DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint)); |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 101 | DRAW(DrawImage, drawImage(r.image, r.left, r.top, r.paint)); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 102 | DRAW(DrawImageRect, legacy_drawImageRect(r.image, r.src, r.dst, r.paint, r.constraint)); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 103 | DRAW(DrawImageNine, drawImageNine(r.image, r.center, r.dst, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 104 | DRAW(DrawOval, drawOval(r.oval, r.paint)); |
| 105 | DRAW(DrawPaint, drawPaint(r.paint)); |
| 106 | DRAW(DrawPath, drawPath(r.path, r.paint)); |
mtklein | 9b222a5 | 2014-09-18 11:16:31 -0700 | [diff] [blame] | 107 | DRAW(DrawPatch, drawPatch(r.cubics, r.colors, r.texCoords, r.xmode, r.paint)); |
mtklein | af57903 | 2014-12-01 11:03:37 -0800 | [diff] [blame] | 108 | DRAW(DrawPicture, drawPicture(r.picture, &r.matrix, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 109 | DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint)); |
| 110 | DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint)); |
| 111 | DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint)); |
| 112 | DRAW(DrawRRect, drawRRect(r.rrect, r.paint)); |
| 113 | DRAW(DrawRect, drawRect(r.rect, r.paint)); |
mtklein | f55c314 | 2014-12-11 12:43:04 -0800 | [diff] [blame] | 114 | DRAW(DrawSprite, drawSprite(r.bitmap.shallowCopy(), r.left, r.top, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 115 | DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint)); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 116 | DRAW(DrawTextBlob, drawTextBlob(r.blob, r.x, r.y, r.paint)); |
mtklein | af57903 | 2014-12-01 11:03:37 -0800 | [diff] [blame] | 117 | DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, &r.matrix, r.paint)); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 118 | DRAW(DrawAtlas, drawAtlas(r.atlas, r.xforms, r.texs, r.colors, r.count, r.mode, r.cull, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 119 | DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors, |
mtklein | 449d9b7 | 2015-09-28 10:33:02 -0700 | [diff] [blame] | 120 | r.xmode, r.indices, r.indexCount, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 121 | #undef DRAW |
| 122 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 123 | template <> void Draw::draw(const DrawDrawable& r) { |
| 124 | SkASSERT(r.index >= 0); |
| 125 | SkASSERT(r.index < fDrawableCount); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 126 | if (fDrawables) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 127 | SkASSERT(nullptr == fDrawablePicts); |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 128 | fCanvas->drawDrawable(fDrawables[r.index], r.matrix); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 129 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 130 | fCanvas->drawPicture(fDrawablePicts[r.index], r.matrix, nullptr); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 131 | } |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 132 | } |
| 133 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 134 | // This is an SkRecord visitor that fills an SkBBoxHierarchy. |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 135 | // |
| 136 | // The interesting part here is how to calculate bounds for ops which don't |
| 137 | // have intrinsic bounds. What is the bounds of a Save or a Translate? |
| 138 | // |
| 139 | // We answer this by thinking about a particular definition of bounds: if I |
| 140 | // don't execute this op, pixels in this rectangle might draw incorrectly. So |
| 141 | // the bounds of a Save, a Translate, a Restore, etc. are the union of the |
| 142 | // bounds of Draw* ops that they might have an effect on. For any given |
| 143 | // Save/Restore block, the bounds of the Save, the Restore, and any other |
| 144 | // non-drawing ("control") ops inside are exactly the union of the bounds of |
| 145 | // the drawing ops inside that block. |
| 146 | // |
| 147 | // To implement this, we keep a stack of active Save blocks. As we consume ops |
| 148 | // inside the Save/Restore block, drawing ops are unioned with the bounds of |
| 149 | // the block, and control ops are stashed away for later. When we finish the |
| 150 | // block with a Restore, our bounds are complete, and we go back and fill them |
| 151 | // in for all the control ops we stashed away. |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 152 | class FillBounds : SkNoncopyable { |
| 153 | public: |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 154 | FillBounds(const SkRect& cullRect, const SkRecord& record, SkRect bounds[]) |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 155 | : fNumRecords(record.count()) |
| 156 | , fCullRect(cullRect) |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 157 | , fBounds(bounds) { |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 158 | fCTM = SkMatrix::I(); |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 159 | fCurrentClipBounds = fCullRect; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 160 | } |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 161 | |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 162 | void cleanUp() { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 163 | // If we have any lingering unpaired Saves, simulate restores to make |
| 164 | // sure all ops in those Save blocks have their bounds calculated. |
| 165 | while (!fSaveStack.isEmpty()) { |
| 166 | this->popSaveBlock(); |
| 167 | } |
| 168 | |
| 169 | // Any control ops not part of any Save/Restore block draw everywhere. |
| 170 | while (!fControlIndices.isEmpty()) { |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 171 | this->popControl(fCullRect); |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 172 | } |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 173 | } |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 174 | |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 175 | void setCurrentOp(int currentOp) { fCurrentOp = currentOp; } |
| 176 | |
| 177 | |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 178 | template <typename T> void operator()(const T& op) { |
| 179 | this->updateCTM(op); |
| 180 | this->updateClipBounds(op); |
| 181 | this->trackBounds(op); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 182 | } |
| 183 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 184 | // In this file, SkRect are in local coordinates, Bounds are translated back to identity space. |
| 185 | typedef SkRect Bounds; |
| 186 | |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 187 | int currentOp() const { return fCurrentOp; } |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 188 | const SkMatrix& ctm() const { return fCTM; } |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 189 | const Bounds& getBounds(int index) const { return fBounds[index]; } |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 190 | |
| 191 | // Adjust rect for all paints that may affect its geometry, then map it to identity space. |
| 192 | Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const { |
| 193 | // Inverted rectangles really confuse our BBHs. |
| 194 | rect.sort(); |
| 195 | |
| 196 | // Adjust the rect for its own paint. |
| 197 | if (!AdjustForPaint(paint, &rect)) { |
| 198 | // The paint could do anything to our bounds. The only safe answer is the current clip. |
| 199 | return fCurrentClipBounds; |
| 200 | } |
| 201 | |
| 202 | // Adjust rect for all the paints from the SaveLayers we're inside. |
| 203 | if (!this->adjustForSaveLayerPaints(&rect)) { |
| 204 | // Same deal as above. |
| 205 | return fCurrentClipBounds; |
| 206 | } |
| 207 | |
| 208 | // Map the rect back to identity space. |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 209 | fCTM.mapRect(&rect); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 210 | |
| 211 | // Nothing can draw outside the current clip. |
robertphillips | c187a3c | 2014-12-30 13:53:51 -0800 | [diff] [blame] | 212 | if (!rect.intersect(fCurrentClipBounds)) { |
| 213 | return Bounds::MakeEmpty(); |
| 214 | } |
| 215 | |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 216 | return rect; |
| 217 | } |
| 218 | |
| 219 | private: |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 220 | struct SaveBounds { |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 221 | int controlOps; // Number of control ops in this Save block, including the Save. |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 222 | Bounds bounds; // Bounds of everything in the block. |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 223 | const SkPaint* paint; // Unowned. If set, adjusts the bounds of all ops in this block. |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 224 | }; |
| 225 | |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 226 | // Only Restore, SetMatrix, and Concat change the CTM. |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 227 | template <typename T> void updateCTM(const T&) {} |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 228 | void updateCTM(const Restore& op) { fCTM = op.matrix; } |
| 229 | void updateCTM(const SetMatrix& op) { fCTM = op.matrix; } |
| 230 | void updateCTM(const Concat& op) { fCTM.preConcat(op.matrix); } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 231 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 232 | // Most ops don't change the clip. |
| 233 | template <typename T> void updateClipBounds(const T&) {} |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 234 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 235 | // Clip{Path,RRect,Rect,Region} obviously change the clip. They all know their bounds already. |
| 236 | void updateClipBounds(const ClipPath& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
| 237 | void updateClipBounds(const ClipRRect& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
| 238 | void updateClipBounds(const ClipRect& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
| 239 | void updateClipBounds(const ClipRegion& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 240 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 241 | // The bounds of clip ops need to be adjusted for the paints of saveLayers they're inside. |
| 242 | void updateClipBoundsForClipOp(const SkIRect& devBounds) { |
| 243 | Bounds clip = SkRect::Make(devBounds); |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 244 | // We don't call adjustAndMap() because as its last step it would intersect the adjusted |
| 245 | // clip bounds with the previous clip, exactly what we can't do when the clip grows. |
schenney | 23d8593 | 2015-03-06 16:20:28 -0800 | [diff] [blame] | 246 | if (this->adjustForSaveLayerPaints(&clip)) { |
| 247 | fCurrentClipBounds = clip.intersect(fCullRect) ? clip : Bounds::MakeEmpty(); |
| 248 | } else { |
| 249 | fCurrentClipBounds = fCullRect; |
| 250 | } |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 251 | } |
| 252 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 253 | // Restore holds the devBounds for the clip after the {save,saveLayer}/restore block completes. |
| 254 | void updateClipBounds(const Restore& op) { |
| 255 | // This is just like the clip ops above, but we need to skip the effects (if any) of our |
| 256 | // paired saveLayer (if it is one); it has not yet been popped off the save stack. Our |
| 257 | // devBounds reflect the state of the world after the saveLayer/restore block is done, |
| 258 | // so they are not affected by the saveLayer's paint. |
| 259 | const int kSavesToIgnore = 1; |
| 260 | Bounds clip = SkRect::Make(op.devBounds); |
schenney | 23d8593 | 2015-03-06 16:20:28 -0800 | [diff] [blame] | 261 | if (this->adjustForSaveLayerPaints(&clip, kSavesToIgnore)) { |
| 262 | fCurrentClipBounds = clip.intersect(fCullRect) ? clip : Bounds::MakeEmpty(); |
| 263 | } else { |
| 264 | fCurrentClipBounds = fCullRect; |
| 265 | } |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 268 | // We also take advantage of SaveLayer bounds when present to further cut the clip down. |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 269 | void updateClipBounds(const SaveLayer& op) { |
| 270 | if (op.bounds) { |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 271 | // adjustAndMap() intersects these layer bounds with the previous clip for us. |
| 272 | fCurrentClipBounds = this->adjustAndMap(*op.bounds, op.paint); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 273 | } |
| 274 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 275 | |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 276 | // The bounds of these ops must be calculated when we hit the Restore |
| 277 | // from the bounds of the ops in the same Save block. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 278 | void trackBounds(const Save&) { this->pushSaveBlock(nullptr); } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 279 | void trackBounds(const SaveLayer& op) { this->pushSaveBlock(op.paint); } |
| 280 | void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(); } |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 281 | |
mtklein | 68199a2 | 2014-08-25 13:49:29 -0700 | [diff] [blame] | 282 | void trackBounds(const SetMatrix&) { this->pushControl(); } |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 283 | void trackBounds(const Concat&) { this->pushControl(); } |
mtklein | 68199a2 | 2014-08-25 13:49:29 -0700 | [diff] [blame] | 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(); } |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 288 | |
| 289 | // For all other ops, we can calculate and store the bounds directly now. |
| 290 | template <typename T> void trackBounds(const T& op) { |
| 291 | fBounds[fCurrentOp] = this->bounds(op); |
| 292 | this->updateSaveBounds(fBounds[fCurrentOp]); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 293 | } |
| 294 | |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 295 | void pushSaveBlock(const SkPaint* paint) { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 296 | // Starting a new Save block. Push a new entry to represent that. |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 297 | SaveBounds sb; |
| 298 | sb.controlOps = 0; |
| 299 | // If the paint affects transparent black, the bound shouldn't be smaller |
| 300 | // than the current clip bounds. |
| 301 | sb.bounds = |
| 302 | PaintMayAffectTransparentBlack(paint) ? fCurrentClipBounds : Bounds::MakeEmpty(); |
| 303 | sb.paint = paint; |
| 304 | |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 305 | fSaveStack.push(sb); |
| 306 | this->pushControl(); |
| 307 | } |
| 308 | |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 309 | static bool PaintMayAffectTransparentBlack(const SkPaint* paint) { |
dneto | 327f905 | 2014-09-15 10:53:16 -0700 | [diff] [blame] | 310 | if (paint) { |
| 311 | // FIXME: this is very conservative |
| 312 | if (paint->getImageFilter() || paint->getColorFilter()) { |
| 313 | return true; |
| 314 | } |
| 315 | |
| 316 | // Unusual Xfermodes require us to process a saved layer |
| 317 | // even with operations outisde the clip. |
| 318 | // For example, DstIn is used by masking layers. |
| 319 | // https://code.google.com/p/skia/issues/detail?id=1291 |
| 320 | // https://crbug.com/401593 |
| 321 | SkXfermode* xfermode = paint->getXfermode(); |
| 322 | SkXfermode::Mode mode; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 323 | // SrcOver is ok, and is also the common case with a nullptr xfermode. |
dneto | 327f905 | 2014-09-15 10:53:16 -0700 | [diff] [blame] | 324 | // So we should make that the fast path and bypass the mode extraction |
| 325 | // and test. |
| 326 | if (xfermode && xfermode->asMode(&mode)) { |
| 327 | switch (mode) { |
| 328 | // For each of the following transfer modes, if the source |
| 329 | // alpha is zero (our transparent black), the resulting |
| 330 | // blended alpha is not necessarily equal to the original |
| 331 | // destination alpha. |
| 332 | case SkXfermode::kClear_Mode: |
| 333 | case SkXfermode::kSrc_Mode: |
| 334 | case SkXfermode::kSrcIn_Mode: |
| 335 | case SkXfermode::kDstIn_Mode: |
| 336 | case SkXfermode::kSrcOut_Mode: |
| 337 | case SkXfermode::kDstATop_Mode: |
| 338 | case SkXfermode::kModulate_Mode: |
| 339 | return true; |
| 340 | break; |
| 341 | default: |
| 342 | break; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | return false; |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 347 | } |
| 348 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 349 | Bounds popSaveBlock() { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 350 | // We're done the Save block. Apply the block's bounds to all control ops inside it. |
| 351 | SaveBounds sb; |
| 352 | fSaveStack.pop(&sb); |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 353 | |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 354 | while (sb.controlOps --> 0) { |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 355 | this->popControl(sb.bounds); |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | // This whole Save block may be part another Save block. |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 359 | this->updateSaveBounds(sb.bounds); |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 360 | |
| 361 | // If called from a real Restore (not a phony one for balance), it'll need the bounds. |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 362 | return sb.bounds; |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void pushControl() { |
| 366 | fControlIndices.push(fCurrentOp); |
| 367 | if (!fSaveStack.isEmpty()) { |
| 368 | fSaveStack.top().controlOps++; |
| 369 | } |
| 370 | } |
| 371 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 372 | void popControl(const Bounds& bounds) { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 373 | fBounds[fControlIndices.top()] = bounds; |
| 374 | fControlIndices.pop(); |
| 375 | } |
| 376 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 377 | void updateSaveBounds(const Bounds& bounds) { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 378 | // If we're in a Save block, expand its bounds to cover these bounds too. |
| 379 | if (!fSaveStack.isEmpty()) { |
| 380 | fSaveStack.top().bounds.join(bounds); |
| 381 | } |
| 382 | } |
| 383 | |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 384 | // FIXME: this method could use better bounds |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 385 | Bounds bounds(const DrawText&) const { return fCurrentClipBounds; } |
mtklein | 68199a2 | 2014-08-25 13:49:29 -0700 | [diff] [blame] | 386 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 387 | Bounds bounds(const DrawPaint&) const { return fCurrentClipBounds; } |
| 388 | Bounds bounds(const NoOp&) const { return Bounds::MakeEmpty(); } // NoOps don't draw. |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 389 | |
schenney | 23d8593 | 2015-03-06 16:20:28 -0800 | [diff] [blame] | 390 | Bounds bounds(const DrawSprite& op) const { // Ignores the matrix, but respects the clip. |
| 391 | SkRect rect = Bounds::MakeXYWH(op.left, op.top, op.bitmap.width(), op.bitmap.height()); |
| 392 | if (!rect.intersect(fCurrentClipBounds)) { |
| 393 | return Bounds::MakeEmpty(); |
| 394 | } |
| 395 | return rect; |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 396 | } |
| 397 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 398 | Bounds bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect, &op.paint); } |
| 399 | Bounds bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval, &op.paint); } |
| 400 | Bounds bounds(const DrawRRect& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 401 | return this->adjustAndMap(op.rrect.rect(), &op.paint); |
| 402 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 403 | Bounds bounds(const DrawDRRect& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 404 | return this->adjustAndMap(op.outer.rect(), &op.paint); |
| 405 | } |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 406 | Bounds bounds(const DrawImage& op) const { |
| 407 | const SkImage* image = op.image; |
| 408 | SkRect rect = SkRect::MakeXYWH(op.left, op.top, image->width(), image->height()); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 409 | |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 410 | return this->adjustAndMap(rect, op.paint); |
| 411 | } |
| 412 | Bounds bounds(const DrawImageRect& op) const { |
| 413 | return this->adjustAndMap(op.dst, op.paint); |
| 414 | } |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 415 | Bounds bounds(const DrawImageNine& op) const { |
| 416 | return this->adjustAndMap(op.dst, op.paint); |
| 417 | } |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 418 | Bounds bounds(const DrawBitmapRect& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 419 | return this->adjustAndMap(op.dst, op.paint); |
| 420 | } |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 421 | Bounds bounds(const DrawBitmapRectFast& op) const { |
mtklein | 42ddcd4 | 2014-11-21 08:48:35 -0800 | [diff] [blame] | 422 | return this->adjustAndMap(op.dst, op.paint); |
| 423 | } |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 424 | Bounds bounds(const DrawBitmapRectFixedSize& op) const { |
mtklein | 64b4c78 | 2015-07-01 13:56:53 -0700 | [diff] [blame] | 425 | return this->adjustAndMap(op.dst, &op.paint); |
| 426 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 427 | Bounds bounds(const DrawBitmapNine& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 428 | return this->adjustAndMap(op.dst, op.paint); |
| 429 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 430 | Bounds bounds(const DrawBitmap& op) const { |
mtklein | af57903 | 2014-12-01 11:03:37 -0800 | [diff] [blame] | 431 | return this->adjustAndMap( |
| 432 | SkRect::MakeXYWH(op.left, op.top, op.bitmap.width(), op.bitmap.height()), |
| 433 | op.paint); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 434 | } |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 435 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 436 | Bounds bounds(const DrawPath& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 437 | return op.path.isInverseFillType() ? fCurrentClipBounds |
| 438 | : this->adjustAndMap(op.path.getBounds(), &op.paint); |
| 439 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 440 | Bounds bounds(const DrawPoints& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 441 | SkRect dst; |
| 442 | dst.set(op.pts, op.count); |
| 443 | |
| 444 | // Pad the bounding box a little to make sure hairline points' bounds aren't empty. |
| 445 | SkScalar stroke = SkMaxScalar(op.paint.getStrokeWidth(), 0.01f); |
| 446 | dst.outset(stroke/2, stroke/2); |
| 447 | |
| 448 | return this->adjustAndMap(dst, &op.paint); |
| 449 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 450 | Bounds bounds(const DrawPatch& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 451 | SkRect dst; |
| 452 | dst.set(op.cubics, SkPatchUtils::kNumCtrlPts); |
| 453 | return this->adjustAndMap(dst, &op.paint); |
| 454 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 455 | Bounds bounds(const DrawVertices& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 456 | SkRect dst; |
| 457 | dst.set(op.vertices, op.vertexCount); |
| 458 | return this->adjustAndMap(dst, &op.paint); |
| 459 | } |
mtklein | 64b4c78 | 2015-07-01 13:56:53 -0700 | [diff] [blame] | 460 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 461 | Bounds bounds(const DrawAtlas& op) const { |
| 462 | if (op.cull) { |
| 463 | return this->adjustAndMap(*op.cull, op.paint); |
| 464 | } else { |
| 465 | return fCurrentClipBounds; |
| 466 | } |
| 467 | } |
mtklein | 64b4c78 | 2015-07-01 13:56:53 -0700 | [diff] [blame] | 468 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 469 | Bounds bounds(const DrawPicture& op) const { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 470 | SkRect dst = op.picture->cullRect(); |
mtklein | af57903 | 2014-12-01 11:03:37 -0800 | [diff] [blame] | 471 | op.matrix.mapRect(&dst); |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 472 | return this->adjustAndMap(dst, op.paint); |
| 473 | } |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 474 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 475 | Bounds bounds(const DrawPosText& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 476 | const int N = op.paint.countText(op.text, op.byteLength); |
| 477 | if (N == 0) { |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 478 | return Bounds::MakeEmpty(); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | SkRect dst; |
mtklein | 937c9c7 | 2014-09-02 15:19:48 -0700 | [diff] [blame] | 482 | dst.set(op.pos, N); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 483 | AdjustTextForFontMetrics(&dst, op.paint); |
| 484 | return this->adjustAndMap(dst, &op.paint); |
| 485 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 486 | Bounds bounds(const DrawPosTextH& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 487 | const int N = op.paint.countText(op.text, op.byteLength); |
| 488 | if (N == 0) { |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 489 | return Bounds::MakeEmpty(); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | SkScalar left = op.xpos[0], right = op.xpos[0]; |
| 493 | for (int i = 1; i < N; i++) { |
| 494 | left = SkMinScalar(left, op.xpos[i]); |
| 495 | right = SkMaxScalar(right, op.xpos[i]); |
| 496 | } |
| 497 | SkRect dst = { left, op.y, right, op.y }; |
| 498 | AdjustTextForFontMetrics(&dst, op.paint); |
| 499 | return this->adjustAndMap(dst, &op.paint); |
| 500 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 501 | Bounds bounds(const DrawTextOnPath& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 502 | SkRect dst = op.path.getBounds(); |
| 503 | |
mtklein | 9a5380d | 2014-12-16 06:31:01 -0800 | [diff] [blame] | 504 | // Pad all sides by the maximum padding in any direction we'd normally apply. |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 505 | SkRect pad = { 0, 0, 0, 0}; |
| 506 | AdjustTextForFontMetrics(&pad, op.paint); |
mtklein | 9a5380d | 2014-12-16 06:31:01 -0800 | [diff] [blame] | 507 | |
| 508 | // That maximum padding happens to always be the right pad today. |
| 509 | SkASSERT(pad.fLeft == -pad.fRight); |
| 510 | SkASSERT(pad.fTop == -pad.fBottom); |
| 511 | SkASSERT(pad.fRight > pad.fBottom); |
| 512 | dst.outset(pad.fRight, pad.fRight); |
| 513 | |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 514 | return this->adjustAndMap(dst, &op.paint); |
| 515 | } |
| 516 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 517 | Bounds bounds(const DrawTextBlob& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 518 | SkRect dst = op.blob->bounds(); |
| 519 | dst.offset(op.x, op.y); |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 520 | return this->adjustAndMap(dst, &op.paint); |
| 521 | } |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 522 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 523 | Bounds bounds(const DrawDrawable& op) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 524 | return this->adjustAndMap(op.worstCaseBounds, nullptr); |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 525 | } |
| 526 | |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 527 | static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { |
mtklein | 9a5380d | 2014-12-16 06:31:01 -0800 | [diff] [blame] | 528 | #ifdef SK_DEBUG |
| 529 | SkRect correct = *rect; |
| 530 | #endif |
| 531 | // crbug.com/373785 ~~> xPad = 4x yPad |
| 532 | // crbug.com/424824 ~~> bump yPad from 2x text size to 2.5x |
| 533 | const SkScalar yPad = 2.5f * paint.getTextSize(), |
| 534 | xPad = 4.0f * yPad; |
| 535 | rect->outset(xPad, yPad); |
caryclark | 9a657fa | 2014-08-20 05:24:29 -0700 | [diff] [blame] | 536 | #ifdef SK_DEBUG |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 537 | SkPaint::FontMetrics metrics; |
| 538 | paint.getFontMetrics(&metrics); |
mtklein | 9a5380d | 2014-12-16 06:31:01 -0800 | [diff] [blame] | 539 | correct.fLeft += metrics.fXMin; |
| 540 | correct.fTop += metrics.fTop; |
| 541 | correct.fRight += metrics.fXMax; |
| 542 | correct.fBottom += metrics.fBottom; |
mtklein | d13291a | 2014-08-21 14:46:49 -0700 | [diff] [blame] | 543 | // See skia:2862 for why we ignore small text sizes. |
mtklein | 9a5380d | 2014-12-16 06:31:01 -0800 | [diff] [blame] | 544 | SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct), |
mtklein | ed167ac | 2014-10-29 16:07:10 -0700 | [diff] [blame] | 545 | "%f %f %f %f vs. %f %f %f %f\n", |
mtklein | 9a5380d | 2014-12-16 06:31:01 -0800 | [diff] [blame] | 546 | -xPad, -yPad, +xPad, +yPad, |
mtklein | ed167ac | 2014-10-29 16:07:10 -0700 | [diff] [blame] | 547 | metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom); |
mtklein | a19afb4 | 2014-08-19 17:47:14 -0700 | [diff] [blame] | 548 | #endif |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 549 | } |
| 550 | |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 551 | // Returns true if rect was meaningfully adjusted for the effects of paint, |
| 552 | // false if the paint could affect the rect in unknown ways. |
| 553 | static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 554 | if (paint) { |
| 555 | if (paint->canComputeFastBounds()) { |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 556 | *rect = paint->computeFastBounds(*rect, rect); |
| 557 | return true; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 558 | } |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 559 | return false; |
| 560 | } |
| 561 | return true; |
| 562 | } |
| 563 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 564 | bool adjustForSaveLayerPaints(SkRect* rect, int savesToIgnore = 0) const { |
| 565 | for (int i = fSaveStack.count() - 1 - savesToIgnore; i >= 0; i--) { |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 566 | if (!AdjustForPaint(fSaveStack[i].paint, rect)) { |
| 567 | return false; |
| 568 | } |
| 569 | } |
| 570 | return true; |
| 571 | } |
| 572 | |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 573 | const int fNumRecords; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 574 | |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 575 | // We do not guarantee anything for operations outside of the cull rect |
| 576 | const SkRect fCullRect; |
| 577 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 578 | // Conservative identity-space bounds for each op in the SkRecord. |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 579 | Bounds* fBounds; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 580 | |
| 581 | // We walk fCurrentOp through the SkRecord, as we go using updateCTM() |
| 582 | // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 583 | // identity-space bounds of the current clip (fCurrentClipBounds). |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 584 | int fCurrentOp; |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 585 | SkMatrix fCTM; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 586 | Bounds fCurrentClipBounds; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 587 | |
| 588 | // Used to track the bounds of Save/Restore blocks and the control ops inside them. |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 589 | SkTDArray<SaveBounds> fSaveStack; |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 590 | SkTDArray<int> fControlIndices; |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 591 | }; |
| 592 | |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 593 | // SkRecord visitor to gather saveLayer/restore information. |
| 594 | class CollectLayers : SkNoncopyable { |
| 595 | public: |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 596 | CollectLayers(const SkRect& cullRect, const SkRecord& record, SkRect bounds[], |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 597 | const SkBigPicture::SnapshotArray* pictList, SkLayerInfo* accelData) |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 598 | : fSaveLayersInStack(0) |
| 599 | , fAccelData(accelData) |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 600 | , fPictList(pictList) |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 601 | , fFillBounds(cullRect, record, bounds) |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 602 | {} |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 603 | |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 604 | void cleanUp() { |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 605 | // fFillBounds must perform its cleanUp first so that all the bounding |
| 606 | // boxes associated with unbalanced restores are updated (prior to |
| 607 | // fetching their bound in popSaveLayerInfo). |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 608 | fFillBounds.cleanUp(); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 609 | while (!fSaveLayerStack.isEmpty()) { |
| 610 | this->popSaveLayerInfo(); |
| 611 | } |
| 612 | } |
| 613 | |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 614 | void setCurrentOp(int currentOp) { fFillBounds.setCurrentOp(currentOp); } |
| 615 | |
| 616 | |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 617 | template <typename T> void operator()(const T& op) { |
| 618 | fFillBounds(op); |
| 619 | this->trackSaveLayers(op); |
| 620 | } |
| 621 | |
| 622 | private: |
| 623 | struct SaveLayerInfo { |
| 624 | SaveLayerInfo() { } |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 625 | SaveLayerInfo(int opIndex, bool isSaveLayer, const SkRect* bounds, const SkPaint* paint) |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 626 | : fStartIndex(opIndex) |
| 627 | , fIsSaveLayer(isSaveLayer) |
| 628 | , fHasNestedSaveLayer(false) |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 629 | , fBounds(bounds ? *bounds : SkRect::MakeEmpty()) |
robertphillips | 74576eb | 2014-11-12 07:25:02 -0800 | [diff] [blame] | 630 | , fPaint(paint) { |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | int fStartIndex; |
| 634 | bool fIsSaveLayer; |
| 635 | bool fHasNestedSaveLayer; |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 636 | SkRect fBounds; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 637 | const SkPaint* fPaint; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 638 | }; |
| 639 | |
| 640 | template <typename T> void trackSaveLayers(const T& op) { |
| 641 | /* most ops aren't involved in saveLayers */ |
| 642 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 643 | void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, nullptr, nullptr); } |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 644 | void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl.bounds, sl.paint); } |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 645 | void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } |
| 646 | |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 647 | void trackSaveLayersForPicture(const SkPicture* picture, const SkPaint* paint) { |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 648 | // For sub-pictures, we wrap their layer information within the parent |
| 649 | // picture's rendering hierarchy |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 650 | const SkLayerInfo* childData = nullptr; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 651 | if (const SkBigPicture* bp = picture->asSkBigPicture()) { |
| 652 | childData = static_cast<const SkLayerInfo*>(bp->accelData()); |
| 653 | } |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 654 | if (!childData) { |
| 655 | // If the child layer hasn't been generated with saveLayer data we |
| 656 | // assume the worst (i.e., that it does contain layers which nest |
| 657 | // inside existing layers). Layers within sub-pictures that don't |
| 658 | // have saveLayer data cannot be hoisted. |
| 659 | // TODO: could the analysis data be use to fine tune this? |
| 660 | this->updateStackForSaveLayer(); |
| 661 | return; |
| 662 | } |
| 663 | |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 664 | for (int i = 0; i < childData->numBlocks(); ++i) { |
| 665 | const SkLayerInfo::BlockInfo& src = childData->block(i); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 666 | |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 667 | FillBounds::Bounds newBound = fFillBounds.adjustAndMap(src.fBounds, paint); |
robertphillips | 74576eb | 2014-11-12 07:25:02 -0800 | [diff] [blame] | 668 | if (newBound.isEmpty()) { |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 669 | continue; |
| 670 | } |
| 671 | |
| 672 | this->updateStackForSaveLayer(); |
| 673 | |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 674 | SkLayerInfo::BlockInfo& dst = fAccelData->addBlock(); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 675 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 676 | // If src.fPicture is nullptr the layer is in dp.picture; otherwise |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 677 | // it belongs to a sub-picture. |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 678 | dst.fPicture = src.fPicture ? src.fPicture : picture; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 679 | dst.fPicture->ref(); |
robertphillips | 74576eb | 2014-11-12 07:25:02 -0800 | [diff] [blame] | 680 | dst.fBounds = newBound; |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 681 | dst.fSrcBounds = src.fSrcBounds; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 682 | dst.fLocalMat = src.fLocalMat; |
| 683 | dst.fPreMat = src.fPreMat; |
| 684 | dst.fPreMat.postConcat(fFillBounds.ctm()); |
| 685 | if (src.fPaint) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 686 | dst.fPaint = new SkPaint(*src.fPaint); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 687 | } |
| 688 | dst.fSaveLayerOpID = src.fSaveLayerOpID; |
| 689 | dst.fRestoreOpID = src.fRestoreOpID; |
| 690 | dst.fHasNestedLayers = src.fHasNestedLayers; |
| 691 | dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested; |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 692 | |
| 693 | // Store 'saveLayer ops from enclosing picture' + drawPict op + 'ops from sub-picture' |
| 694 | dst.fKeySize = fSaveLayerOpStack.count() + src.fKeySize + 1; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 695 | dst.fKey = new int[dst.fKeySize]; |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 696 | memcpy(dst.fKey, fSaveLayerOpStack.begin(), fSaveLayerOpStack.count() * sizeof(int)); |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 697 | dst.fKey[fSaveLayerOpStack.count()] = fFillBounds.currentOp(); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 698 | memcpy(&dst.fKey[fSaveLayerOpStack.count()+1], src.fKey, src.fKeySize * sizeof(int)); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 702 | void trackSaveLayers(const DrawPicture& dp) { |
| 703 | this->trackSaveLayersForPicture(dp.picture, dp.paint); |
| 704 | } |
| 705 | |
| 706 | void trackSaveLayers(const DrawDrawable& dp) { |
| 707 | SkASSERT(fPictList); |
| 708 | SkASSERT(dp.index >= 0 && dp.index < fPictList->count()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 709 | const SkPaint* paint = nullptr; // drawables don't get a side-car paint |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 710 | this->trackSaveLayersForPicture(fPictList->begin()[dp.index], paint); |
| 711 | } |
| 712 | |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 713 | // Inform all the saveLayers already on the stack that they now have a |
| 714 | // nested saveLayer inside them |
| 715 | void updateStackForSaveLayer() { |
| 716 | for (int index = fSaveLayerStack.count() - 1; index >= 0; --index) { |
| 717 | if (fSaveLayerStack[index].fHasNestedSaveLayer) { |
| 718 | break; |
| 719 | } |
| 720 | fSaveLayerStack[index].fHasNestedSaveLayer = true; |
| 721 | if (fSaveLayerStack[index].fIsSaveLayer) { |
| 722 | break; |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 727 | void pushSaveLayerInfo(bool isSaveLayer, const SkRect* bounds, const SkPaint* paint) { |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 728 | if (isSaveLayer) { |
| 729 | this->updateStackForSaveLayer(); |
| 730 | ++fSaveLayersInStack; |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 731 | fSaveLayerOpStack.push(fFillBounds.currentOp()); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 732 | } |
| 733 | |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 734 | fSaveLayerStack.push(SaveLayerInfo(fFillBounds.currentOp(), isSaveLayer, bounds, paint)); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | void popSaveLayerInfo() { |
| 738 | if (fSaveLayerStack.count() <= 0) { |
| 739 | SkASSERT(false); |
| 740 | return; |
| 741 | } |
| 742 | |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 743 | SkASSERT(fSaveLayersInStack == fSaveLayerOpStack.count()); |
| 744 | |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 745 | SaveLayerInfo sli; |
| 746 | fSaveLayerStack.pop(&sli); |
| 747 | |
| 748 | if (!sli.fIsSaveLayer) { |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | --fSaveLayersInStack; |
| 753 | |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 754 | SkLayerInfo::BlockInfo& block = fAccelData->addBlock(); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 755 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 756 | SkASSERT(nullptr == block.fPicture); // This layer is in the top-most picture |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 757 | |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 758 | block.fBounds = fFillBounds.getBounds(sli.fStartIndex); |
| 759 | block.fLocalMat = fFillBounds.ctm(); |
| 760 | block.fPreMat = SkMatrix::I(); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 761 | if (sli.fPaint) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 762 | block.fPaint = new SkPaint(*sli.fPaint); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 763 | } |
robertphillips | 478dd72 | 2014-12-16 08:25:55 -0800 | [diff] [blame] | 764 | |
| 765 | block.fSrcBounds = sli.fBounds; |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 766 | block.fSaveLayerOpID = sli.fStartIndex; |
| 767 | block.fRestoreOpID = fFillBounds.currentOp(); |
| 768 | block.fHasNestedLayers = sli.fHasNestedSaveLayer; |
| 769 | block.fIsNested = fSaveLayersInStack > 0; |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 770 | |
| 771 | block.fKeySize = fSaveLayerOpStack.count(); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 772 | block.fKey = new int[block.fKeySize]; |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 773 | memcpy(block.fKey, fSaveLayerOpStack.begin(), block.fKeySize * sizeof(int)); |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 774 | |
| 775 | fSaveLayerOpStack.pop(); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | // Used to collect saveLayer information for layer hoisting |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 779 | int fSaveLayersInStack; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 780 | SkTDArray<SaveLayerInfo> fSaveLayerStack; |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 781 | // The op code indices of all the currently active saveLayers |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 782 | SkTDArray<int> fSaveLayerOpStack; |
robertphillips | 01d6e5f | 2014-12-01 09:09:27 -0800 | [diff] [blame] | 783 | SkLayerInfo* fAccelData; |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 784 | const SkBigPicture::SnapshotArray* fPictList; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 785 | |
| 786 | SkRecords::FillBounds fFillBounds; |
| 787 | }; |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 788 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 789 | } // namespace SkRecords |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 790 | |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 791 | void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkRect bounds[]) { |
| 792 | SkRecords::FillBounds visitor(cullRect, record, bounds); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 793 | for (int curOp = 0; curOp < record.count(); curOp++) { |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 794 | visitor.setCurrentOp(curOp); |
| 795 | record.visit<void>(curOp, visitor); |
| 796 | } |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 797 | visitor.cleanUp(); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 798 | } |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 799 | |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 800 | void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, SkRect bounds[], |
| 801 | const SkBigPicture::SnapshotArray* pictList, SkLayerInfo* data) { |
| 802 | SkRecords::CollectLayers visitor(cullRect, record, bounds, pictList, data); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 803 | for (int curOp = 0; curOp < record.count(); curOp++) { |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 804 | visitor.setCurrentOp(curOp); |
| 805 | record.visit<void>(curOp, visitor); |
| 806 | } |
mtklein | 40732b3 | 2015-10-24 07:45:47 -0700 | [diff] [blame] | 807 | visitor.cleanUp(); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 808 | } |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 809 | |