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 | |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 8 | #include "SkRecordDraw.h" |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 9 | #include "SkPatchUtils.h" |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 10 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 11 | void SkRecordDraw(const SkRecord& record, |
| 12 | SkCanvas* canvas, |
| 13 | const SkBBoxHierarchy* bbh, |
| 14 | SkDrawPictureCallback* callback) { |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 15 | SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 16 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 17 | if (bbh) { |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 18 | // Draw only ops that affect pixels in the canvas's current clip. |
mtklein | 3e8232b | 2014-08-18 13:39:11 -0700 | [diff] [blame] | 19 | // The SkRecord and BBH were recorded in identity space. This canvas |
| 20 | // is not necessarily in that same space. getClipBounds() returns us |
| 21 | // this canvas' clip bounds transformed back into identity space, which |
| 22 | // lets us query the BBH. |
junov | a41d3c3 | 2014-10-30 11:44:19 -0700 | [diff] [blame^] | 23 | SkRect query; |
| 24 | if (!canvas->getClipBounds(&query)) { |
| 25 | return; |
| 26 | } |
mtklein | 3e8232b | 2014-08-18 13:39:11 -0700 | [diff] [blame] | 27 | |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 28 | SkTDArray<unsigned> ops; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 29 | bbh->search(query, &ops); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 30 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 31 | SkRecords::Draw draw(canvas); |
| 32 | for (int i = 0; i < ops.count(); i++) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 33 | if (callback && callback->abortDrawing()) { |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 34 | return; |
| 35 | } |
mtklein | 6bd4196 | 2014-10-02 07:41:56 -0700 | [diff] [blame] | 36 | record.visit<void>(ops[i], draw); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 37 | } |
| 38 | } else { |
| 39 | // Draw all ops. |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 40 | SkRecords::Draw draw(canvas); |
| 41 | for (unsigned i = 0; i < record.count(); i++) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 42 | if (callback && callback->abortDrawing()) { |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 43 | return; |
| 44 | } |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 45 | record.visit<void>(i, draw); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 46 | } |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 47 | } |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 48 | } |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 49 | |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 50 | void SkRecordPartialDraw(const SkRecord& record, |
| 51 | SkCanvas* canvas, |
| 52 | const SkRect& clearRect, |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 53 | unsigned start, unsigned stop, |
| 54 | const SkMatrix& initialCTM) { |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 55 | SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
| 56 | |
| 57 | stop = SkTMin(stop, record.count()); |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 58 | SkRecords::PartialDraw draw(canvas, clearRect, initialCTM); |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 59 | for (unsigned i = start; i < stop; i++) { |
| 60 | record.visit<void>(i, draw); |
| 61 | } |
| 62 | } |
| 63 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 64 | namespace SkRecords { |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 65 | |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 66 | // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multiple threads. |
| 67 | static SkBitmap shallow_copy(const SkBitmap& bitmap) { |
| 68 | return bitmap; |
| 69 | } |
| 70 | |
commit-bot@chromium.org | 2e0c32a | 2014-04-28 16:19:45 +0000 | [diff] [blame] | 71 | // NoOps draw nothing. |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 72 | template <> void Draw::draw(const NoOp&) {} |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 73 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 74 | #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] | 75 | DRAW(Restore, restore()); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 76 | DRAW(Save, save()); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 77 | DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); |
| 78 | DRAW(PopCull, popCull()); |
commit-bot@chromium.org | 88c3e27 | 2014-04-22 16:57:20 +0000 | [diff] [blame] | 79 | DRAW(PushCull, pushCull(r.rect)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 80 | DRAW(Clear, clear(r.color)); |
commit-bot@chromium.org | 99bd7d8 | 2014-05-19 15:51:12 +0000 | [diff] [blame] | 81 | DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 82 | |
| 83 | DRAW(ClipPath, clipPath(r.path, r.op, r.doAA)); |
| 84 | DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA)); |
| 85 | DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA)); |
| 86 | DRAW(ClipRegion, clipRegion(r.region, r.op)); |
| 87 | |
mtklein | 5f0e822 | 2014-08-22 11:44:26 -0700 | [diff] [blame] | 88 | DRAW(BeginCommentGroup, beginCommentGroup(r.description)); |
| 89 | DRAW(AddComment, addComment(r.key, r.value)); |
| 90 | DRAW(EndCommentGroup, endCommentGroup()); |
| 91 | |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 92 | DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint)); |
| 93 | DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.paint)); |
| 94 | DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.paint)); |
| 95 | DRAW(DrawBitmapRectToRect, |
| 96 | drawBitmapRectToRect(shallow_copy(r.bitmap), r.src, r.dst, r.paint, r.flags)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 97 | DRAW(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint)); |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 98 | DRAW(DrawImage, drawImage(r.image, r.left, r.top, r.paint)); |
| 99 | DRAW(DrawImageRect, drawImageRect(r.image, r.src, r.dst, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 100 | DRAW(DrawOval, drawOval(r.oval, r.paint)); |
| 101 | DRAW(DrawPaint, drawPaint(r.paint)); |
| 102 | DRAW(DrawPath, drawPath(r.path, r.paint)); |
mtklein | 9b222a5 | 2014-09-18 11:16:31 -0700 | [diff] [blame] | 103 | DRAW(DrawPatch, drawPatch(r.cubics, r.colors, r.texCoords, r.xmode, r.paint)); |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 104 | DRAW(DrawPicture, drawPicture(r.picture, r.matrix, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 105 | DRAW(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint)); |
| 106 | DRAW(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint)); |
| 107 | DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint)); |
| 108 | DRAW(DrawRRect, drawRRect(r.rrect, r.paint)); |
| 109 | DRAW(DrawRect, drawRect(r.rect, r.paint)); |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 110 | DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 111 | DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint)); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 112 | DRAW(DrawTextBlob, drawTextBlob(r.blob, r.x, r.y, r.paint)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 113 | DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint)); |
| 114 | DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors, |
| 115 | r.xmode.get(), r.indices, r.indexCount, r.paint)); |
mtklein | 29dfaa8 | 2014-09-04 14:12:44 -0700 | [diff] [blame] | 116 | DRAW(DrawData, drawData(r.data, r.length)); |
commit-bot@chromium.org | 73b55eb | 2014-04-14 20:35:12 +0000 | [diff] [blame] | 117 | #undef DRAW |
| 118 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 119 | |
mtklein | 0a528c1 | 2014-10-02 13:03:53 -0700 | [diff] [blame] | 120 | // This looks silly, I know. Why not just use SkRect::MakeLargest()? |
| 121 | // In practice, this is well large enough, and it has a few extra advantages: |
| 122 | // it fits in an SkIRect, and we can munge it a little in both SkRect and |
| 123 | // SKIRect space without worrying about overflow. |
| 124 | static const SkRect kUnbounded = { -2e9f, -2e9f, 2e9f, 2e9f }; |
| 125 | |
| 126 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 127 | // This is an SkRecord visitor that fills an SkBBoxHierarchy. |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 128 | // |
| 129 | // The interesting part here is how to calculate bounds for ops which don't |
| 130 | // have intrinsic bounds. What is the bounds of a Save or a Translate? |
| 131 | // |
| 132 | // We answer this by thinking about a particular definition of bounds: if I |
| 133 | // don't execute this op, pixels in this rectangle might draw incorrectly. So |
| 134 | // the bounds of a Save, a Translate, a Restore, etc. are the union of the |
| 135 | // bounds of Draw* ops that they might have an effect on. For any given |
| 136 | // Save/Restore block, the bounds of the Save, the Restore, and any other |
| 137 | // non-drawing ("control") ops inside are exactly the union of the bounds of |
| 138 | // the drawing ops inside that block. |
| 139 | // |
| 140 | // To implement this, we keep a stack of active Save blocks. As we consume ops |
| 141 | // inside the Save/Restore block, drawing ops are unioned with the bounds of |
| 142 | // the block, and control ops are stashed away for later. When we finish the |
| 143 | // block with a Restore, our bounds are complete, and we go back and fill them |
| 144 | // in for all the control ops we stashed away. |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 145 | class FillBounds : SkNoncopyable { |
| 146 | public: |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 147 | FillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) : fBounds(record.count()) { |
| 148 | // Calculate bounds for all ops. This won't go quite in order, so we'll need |
| 149 | // to store the bounds separately then feed them in to the BBH later in order. |
mtklein | 6332f1d | 2014-08-19 07:09:40 -0700 | [diff] [blame] | 150 | fCTM = &SkMatrix::I(); |
mtklein | 0a528c1 | 2014-10-02 13:03:53 -0700 | [diff] [blame] | 151 | fCurrentClipBounds = kUnbounded; |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 152 | for (fCurrentOp = 0; fCurrentOp < record.count(); fCurrentOp++) { |
| 153 | record.visit<void>(fCurrentOp, *this); |
| 154 | } |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 155 | |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 156 | // If we have any lingering unpaired Saves, simulate restores to make |
| 157 | // sure all ops in those Save blocks have their bounds calculated. |
| 158 | while (!fSaveStack.isEmpty()) { |
| 159 | this->popSaveBlock(); |
| 160 | } |
| 161 | |
| 162 | // Any control ops not part of any Save/Restore block draw everywhere. |
| 163 | while (!fControlIndices.isEmpty()) { |
mtklein | 0a528c1 | 2014-10-02 13:03:53 -0700 | [diff] [blame] | 164 | this->popControl(kUnbounded); |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // Finally feed all stored bounds into the BBH. They'll be returned in this order. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 168 | SkASSERT(bbh); |
mtklein | 4477c3c | 2014-10-27 10:27:10 -0700 | [diff] [blame] | 169 | bbh->insert(&fBounds, record.count()); |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 170 | } |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 171 | |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 172 | template <typename T> void operator()(const T& op) { |
| 173 | this->updateCTM(op); |
| 174 | this->updateClipBounds(op); |
| 175 | this->trackBounds(op); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | private: |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 179 | // In this file, SkRect are in local coordinates, Bounds are translated back to identity space. |
| 180 | typedef SkRect Bounds; |
| 181 | |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 182 | struct SaveBounds { |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 183 | int controlOps; // Number of control ops in this Save block, including the Save. |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 184 | Bounds bounds; // Bounds of everything in the block. |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 185 | 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] | 186 | }; |
| 187 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 188 | // Only Restore and SetMatrix change the CTM. |
| 189 | template <typename T> void updateCTM(const T&) {} |
mtklein | 6332f1d | 2014-08-19 07:09:40 -0700 | [diff] [blame] | 190 | void updateCTM(const Restore& op) { fCTM = &op.matrix; } |
| 191 | void updateCTM(const SetMatrix& op) { fCTM = &op.matrix; } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 192 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 193 | // Most ops don't change the clip. |
| 194 | template <typename T> void updateClipBounds(const T&) {} |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 195 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 196 | // Clip{Path,RRect,Rect,Region} obviously change the clip. They all know their bounds already. |
| 197 | void updateClipBounds(const ClipPath& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
| 198 | void updateClipBounds(const ClipRRect& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
| 199 | void updateClipBounds(const ClipRect& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
| 200 | void updateClipBounds(const ClipRegion& op) { this->updateClipBoundsForClipOp(op.devBounds); } |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 201 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 202 | // The bounds of clip ops need to be adjusted for the paints of saveLayers they're inside. |
| 203 | void updateClipBoundsForClipOp(const SkIRect& devBounds) { |
| 204 | Bounds clip = SkRect::Make(devBounds); |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 205 | // We don't call adjustAndMap() because as its last step it would intersect the adjusted |
| 206 | // clip bounds with the previous clip, exactly what we can't do when the clip grows. |
mtklein | 0a528c1 | 2014-10-02 13:03:53 -0700 | [diff] [blame] | 207 | fCurrentClipBounds = this->adjustForSaveLayerPaints(&clip) ? clip : kUnbounded; |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 208 | } |
| 209 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 210 | // Restore holds the devBounds for the clip after the {save,saveLayer}/restore block completes. |
| 211 | void updateClipBounds(const Restore& op) { |
| 212 | // This is just like the clip ops above, but we need to skip the effects (if any) of our |
| 213 | // paired saveLayer (if it is one); it has not yet been popped off the save stack. Our |
| 214 | // devBounds reflect the state of the world after the saveLayer/restore block is done, |
| 215 | // so they are not affected by the saveLayer's paint. |
| 216 | const int kSavesToIgnore = 1; |
| 217 | Bounds clip = SkRect::Make(op.devBounds); |
| 218 | fCurrentClipBounds = |
mtklein | 0a528c1 | 2014-10-02 13:03:53 -0700 | [diff] [blame] | 219 | this->adjustForSaveLayerPaints(&clip, kSavesToIgnore) ? clip : kUnbounded; |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 222 | // 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] | 223 | void updateClipBounds(const SaveLayer& op) { |
| 224 | if (op.bounds) { |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 225 | // adjustAndMap() intersects these layer bounds with the previous clip for us. |
| 226 | fCurrentClipBounds = this->adjustAndMap(*op.bounds, op.paint); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 229 | |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 230 | // The bounds of these ops must be calculated when we hit the Restore |
| 231 | // from the bounds of the ops in the same Save block. |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 232 | void trackBounds(const Save&) { this->pushSaveBlock(NULL); } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 233 | void trackBounds(const SaveLayer& op) { this->pushSaveBlock(op.paint); } |
| 234 | void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(); } |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 235 | |
mtklein | 68199a2 | 2014-08-25 13:49:29 -0700 | [diff] [blame] | 236 | void trackBounds(const SetMatrix&) { this->pushControl(); } |
| 237 | void trackBounds(const ClipRect&) { this->pushControl(); } |
| 238 | void trackBounds(const ClipRRect&) { this->pushControl(); } |
| 239 | void trackBounds(const ClipPath&) { this->pushControl(); } |
| 240 | void trackBounds(const ClipRegion&) { this->pushControl(); } |
| 241 | void trackBounds(const PushCull&) { this->pushControl(); } |
| 242 | void trackBounds(const PopCull&) { this->pushControl(); } |
| 243 | void trackBounds(const BeginCommentGroup&) { this->pushControl(); } |
| 244 | void trackBounds(const AddComment&) { this->pushControl(); } |
| 245 | void trackBounds(const EndCommentGroup&) { this->pushControl(); } |
mtklein | 29dfaa8 | 2014-09-04 14:12:44 -0700 | [diff] [blame] | 246 | void trackBounds(const DrawData&) { this->pushControl(); } |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 247 | |
| 248 | // For all other ops, we can calculate and store the bounds directly now. |
| 249 | template <typename T> void trackBounds(const T& op) { |
| 250 | fBounds[fCurrentOp] = this->bounds(op); |
| 251 | this->updateSaveBounds(fBounds[fCurrentOp]); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 252 | } |
| 253 | |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 254 | void pushSaveBlock(const SkPaint* paint) { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 255 | // Starting a new Save block. Push a new entry to represent that. |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 256 | SaveBounds sb = { 0, Bounds::MakeEmpty(), paint }; |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 257 | fSaveStack.push(sb); |
| 258 | this->pushControl(); |
| 259 | } |
| 260 | |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 261 | static bool PaintMayAffectTransparentBlack(const SkPaint* paint) { |
dneto | 327f905 | 2014-09-15 10:53:16 -0700 | [diff] [blame] | 262 | if (paint) { |
| 263 | // FIXME: this is very conservative |
| 264 | if (paint->getImageFilter() || paint->getColorFilter()) { |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | // Unusual Xfermodes require us to process a saved layer |
| 269 | // even with operations outisde the clip. |
| 270 | // For example, DstIn is used by masking layers. |
| 271 | // https://code.google.com/p/skia/issues/detail?id=1291 |
| 272 | // https://crbug.com/401593 |
| 273 | SkXfermode* xfermode = paint->getXfermode(); |
| 274 | SkXfermode::Mode mode; |
| 275 | // SrcOver is ok, and is also the common case with a NULL xfermode. |
| 276 | // So we should make that the fast path and bypass the mode extraction |
| 277 | // and test. |
| 278 | if (xfermode && xfermode->asMode(&mode)) { |
| 279 | switch (mode) { |
| 280 | // For each of the following transfer modes, if the source |
| 281 | // alpha is zero (our transparent black), the resulting |
| 282 | // blended alpha is not necessarily equal to the original |
| 283 | // destination alpha. |
| 284 | case SkXfermode::kClear_Mode: |
| 285 | case SkXfermode::kSrc_Mode: |
| 286 | case SkXfermode::kSrcIn_Mode: |
| 287 | case SkXfermode::kDstIn_Mode: |
| 288 | case SkXfermode::kSrcOut_Mode: |
| 289 | case SkXfermode::kDstATop_Mode: |
| 290 | case SkXfermode::kModulate_Mode: |
| 291 | return true; |
| 292 | break; |
| 293 | default: |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | return false; |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 299 | } |
| 300 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 301 | Bounds popSaveBlock() { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 302 | // We're done the Save block. Apply the block's bounds to all control ops inside it. |
| 303 | SaveBounds sb; |
| 304 | fSaveStack.pop(&sb); |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 305 | |
| 306 | // If the paint affects transparent black, we can't trust any of our calculated bounds. |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 307 | const Bounds& bounds = |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 308 | PaintMayAffectTransparentBlack(sb.paint) ? fCurrentClipBounds : sb.bounds; |
| 309 | |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 310 | while (sb.controlOps --> 0) { |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 311 | this->popControl(bounds); |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // This whole Save block may be part another Save block. |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 315 | this->updateSaveBounds(bounds); |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 316 | |
| 317 | // If called from a real Restore (not a phony one for balance), it'll need the bounds. |
mtklein | d910f54 | 2014-08-22 09:06:34 -0700 | [diff] [blame] | 318 | return bounds; |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void pushControl() { |
| 322 | fControlIndices.push(fCurrentOp); |
| 323 | if (!fSaveStack.isEmpty()) { |
| 324 | fSaveStack.top().controlOps++; |
| 325 | } |
| 326 | } |
| 327 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 328 | void popControl(const Bounds& bounds) { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 329 | fBounds[fControlIndices.top()] = bounds; |
| 330 | fControlIndices.pop(); |
| 331 | } |
| 332 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 333 | void updateSaveBounds(const Bounds& bounds) { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 334 | // If we're in a Save block, expand its bounds to cover these bounds too. |
| 335 | if (!fSaveStack.isEmpty()) { |
| 336 | fSaveStack.top().bounds.join(bounds); |
| 337 | } |
| 338 | } |
| 339 | |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 340 | // FIXME: this method could use better bounds |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 341 | Bounds bounds(const DrawText&) const { return fCurrentClipBounds; } |
mtklein | 68199a2 | 2014-08-25 13:49:29 -0700 | [diff] [blame] | 342 | |
mtklein | 0a528c1 | 2014-10-02 13:03:53 -0700 | [diff] [blame] | 343 | Bounds bounds(const Clear&) const { return kUnbounded; } // Ignores the clip. |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 344 | Bounds bounds(const DrawPaint&) const { return fCurrentClipBounds; } |
| 345 | Bounds bounds(const NoOp&) const { return Bounds::MakeEmpty(); } // NoOps don't draw. |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 346 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 347 | Bounds bounds(const DrawSprite& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 348 | const SkBitmap& bm = op.bitmap; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 349 | return Bounds::MakeXYWH(op.left, op.top, bm.width(), bm.height()); // Ignores the matrix. |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 350 | } |
| 351 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 352 | Bounds bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect, &op.paint); } |
| 353 | Bounds bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval, &op.paint); } |
| 354 | Bounds bounds(const DrawRRect& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 355 | return this->adjustAndMap(op.rrect.rect(), &op.paint); |
| 356 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 357 | Bounds bounds(const DrawDRRect& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 358 | return this->adjustAndMap(op.outer.rect(), &op.paint); |
| 359 | } |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 360 | Bounds bounds(const DrawImage& op) const { |
| 361 | const SkImage* image = op.image; |
| 362 | SkRect rect = SkRect::MakeXYWH(op.left, op.top, image->width(), image->height()); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 363 | |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 364 | return this->adjustAndMap(rect, op.paint); |
| 365 | } |
| 366 | Bounds bounds(const DrawImageRect& op) const { |
| 367 | return this->adjustAndMap(op.dst, op.paint); |
| 368 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 369 | Bounds bounds(const DrawBitmapRectToRect& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 370 | return this->adjustAndMap(op.dst, op.paint); |
| 371 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 372 | Bounds bounds(const DrawBitmapNine& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 373 | return this->adjustAndMap(op.dst, op.paint); |
| 374 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 375 | Bounds bounds(const DrawBitmap& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 376 | const SkBitmap& bm = op.bitmap; |
| 377 | return this->adjustAndMap(SkRect::MakeXYWH(op.left, op.top, bm.width(), bm.height()), |
| 378 | op.paint); |
| 379 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 380 | Bounds bounds(const DrawBitmapMatrix& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 381 | const SkBitmap& bm = op.bitmap; |
| 382 | SkRect dst = SkRect::MakeWH(bm.width(), bm.height()); |
| 383 | op.matrix.mapRect(&dst); |
| 384 | return this->adjustAndMap(dst, op.paint); |
| 385 | } |
| 386 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 387 | Bounds bounds(const DrawPath& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 388 | return op.path.isInverseFillType() ? fCurrentClipBounds |
| 389 | : this->adjustAndMap(op.path.getBounds(), &op.paint); |
| 390 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 391 | Bounds bounds(const DrawPoints& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 392 | SkRect dst; |
| 393 | dst.set(op.pts, op.count); |
| 394 | |
| 395 | // Pad the bounding box a little to make sure hairline points' bounds aren't empty. |
| 396 | SkScalar stroke = SkMaxScalar(op.paint.getStrokeWidth(), 0.01f); |
| 397 | dst.outset(stroke/2, stroke/2); |
| 398 | |
| 399 | return this->adjustAndMap(dst, &op.paint); |
| 400 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 401 | Bounds bounds(const DrawPatch& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 402 | SkRect dst; |
| 403 | dst.set(op.cubics, SkPatchUtils::kNumCtrlPts); |
| 404 | return this->adjustAndMap(dst, &op.paint); |
| 405 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 406 | Bounds bounds(const DrawVertices& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 407 | SkRect dst; |
| 408 | dst.set(op.vertices, op.vertexCount); |
| 409 | return this->adjustAndMap(dst, &op.paint); |
| 410 | } |
| 411 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 412 | Bounds bounds(const DrawPicture& op) const { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 413 | SkRect dst = op.picture->cullRect(); |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 414 | if (op.matrix) { |
| 415 | op.matrix->mapRect(&dst); |
| 416 | } |
| 417 | return this->adjustAndMap(dst, op.paint); |
| 418 | } |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 419 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 420 | Bounds bounds(const DrawPosText& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 421 | const int N = op.paint.countText(op.text, op.byteLength); |
| 422 | if (N == 0) { |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 423 | return Bounds::MakeEmpty(); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | SkRect dst; |
mtklein | 937c9c7 | 2014-09-02 15:19:48 -0700 | [diff] [blame] | 427 | dst.set(op.pos, N); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 428 | AdjustTextForFontMetrics(&dst, op.paint); |
| 429 | return this->adjustAndMap(dst, &op.paint); |
| 430 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 431 | Bounds bounds(const DrawPosTextH& op) const { |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 432 | const int N = op.paint.countText(op.text, op.byteLength); |
| 433 | if (N == 0) { |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 434 | return Bounds::MakeEmpty(); |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | SkScalar left = op.xpos[0], right = op.xpos[0]; |
| 438 | for (int i = 1; i < N; i++) { |
| 439 | left = SkMinScalar(left, op.xpos[i]); |
| 440 | right = SkMaxScalar(right, op.xpos[i]); |
| 441 | } |
| 442 | SkRect dst = { left, op.y, right, op.y }; |
| 443 | AdjustTextForFontMetrics(&dst, op.paint); |
| 444 | return this->adjustAndMap(dst, &op.paint); |
| 445 | } |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 446 | Bounds bounds(const DrawTextOnPath& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 447 | SkRect dst = op.path.getBounds(); |
| 448 | |
mtklein | ed167ac | 2014-10-29 16:07:10 -0700 | [diff] [blame] | 449 | // 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] | 450 | SkRect pad = { 0, 0, 0, 0}; |
| 451 | AdjustTextForFontMetrics(&pad, op.paint); |
mtklein | ed167ac | 2014-10-29 16:07:10 -0700 | [diff] [blame] | 452 | |
| 453 | // That maximum padding happens to always be the right pad today. |
| 454 | SkASSERT(pad.fLeft == -pad.fRight); |
| 455 | SkASSERT(pad.fTop == -pad.fBottom); |
| 456 | SkASSERT(pad.fRight > pad.fBottom); |
| 457 | dst.outset(pad.fRight, pad.fRight); |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 458 | |
| 459 | return this->adjustAndMap(dst, &op.paint); |
| 460 | } |
| 461 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 462 | Bounds bounds(const DrawTextBlob& op) const { |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 463 | SkRect dst = op.blob->bounds(); |
| 464 | dst.offset(op.x, op.y); |
mtklein | 131a22b | 2014-08-25 14:16:15 -0700 | [diff] [blame] | 465 | return this->adjustAndMap(dst, &op.paint); |
| 466 | } |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 467 | |
| 468 | static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { |
mtklein | ed167ac | 2014-10-29 16:07:10 -0700 | [diff] [blame] | 469 | #ifdef SK_DEBUG |
| 470 | SkRect correct = *rect; |
| 471 | #endif |
| 472 | // crbug.com/373785 ~~> xPad = 4x yPad |
| 473 | // crbug.com/424824 ~~> bump yPad from 2x text size to 2.5x |
| 474 | const SkScalar yPad = 2.5f * paint.getTextSize(), |
| 475 | xPad = 4.0f * yPad; |
| 476 | rect->outset(xPad, yPad); |
caryclark | 9a657fa | 2014-08-20 05:24:29 -0700 | [diff] [blame] | 477 | #ifdef SK_DEBUG |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 478 | SkPaint::FontMetrics metrics; |
| 479 | paint.getFontMetrics(&metrics); |
mtklein | ed167ac | 2014-10-29 16:07:10 -0700 | [diff] [blame] | 480 | correct.fLeft += metrics.fXMin; |
| 481 | correct.fTop += metrics.fTop; |
| 482 | correct.fRight += metrics.fXMax; |
| 483 | correct.fBottom += metrics.fBottom; |
mtklein | d13291a | 2014-08-21 14:46:49 -0700 | [diff] [blame] | 484 | // See skia:2862 for why we ignore small text sizes. |
mtklein | ed167ac | 2014-10-29 16:07:10 -0700 | [diff] [blame] | 485 | SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct), |
| 486 | "%f %f %f %f vs. %f %f %f %f\n", |
| 487 | -xPad, -yPad, +xPad, +yPad, |
| 488 | metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom); |
mtklein | a19afb4 | 2014-08-19 17:47:14 -0700 | [diff] [blame] | 489 | #endif |
mtklein | 62b67ae | 2014-08-18 11:10:37 -0700 | [diff] [blame] | 490 | } |
| 491 | |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 492 | // Returns true if rect was meaningfully adjusted for the effects of paint, |
| 493 | // false if the paint could affect the rect in unknown ways. |
| 494 | static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 495 | if (paint) { |
| 496 | if (paint->canComputeFastBounds()) { |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 497 | *rect = paint->computeFastBounds(*rect, rect); |
| 498 | return true; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 499 | } |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 500 | return false; |
| 501 | } |
| 502 | return true; |
| 503 | } |
| 504 | |
mtklein | 8e393bf | 2014-10-01 12:48:58 -0700 | [diff] [blame] | 505 | bool adjustForSaveLayerPaints(SkRect* rect, int savesToIgnore = 0) const { |
| 506 | for (int i = fSaveStack.count() - 1 - savesToIgnore; i >= 0; i--) { |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 507 | if (!AdjustForPaint(fSaveStack[i].paint, rect)) { |
| 508 | return false; |
| 509 | } |
| 510 | } |
| 511 | return true; |
| 512 | } |
| 513 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 514 | // Adjust rect for all paints that may affect its geometry, then map it to identity space. |
| 515 | Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const { |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 516 | // Inverted rectangles really confuse our BBHs. |
| 517 | rect.sort(); |
| 518 | |
| 519 | // Adjust the rect for its own paint. |
| 520 | if (!AdjustForPaint(paint, &rect)) { |
| 521 | // The paint could do anything to our bounds. The only safe answer is the current clip. |
| 522 | return fCurrentClipBounds; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | // Adjust rect for all the paints from the SaveLayers we're inside. |
Mike Klein | 271a030 | 2014-09-23 15:28:38 -0400 | [diff] [blame] | 526 | if (!this->adjustForSaveLayerPaints(&rect)) { |
| 527 | // Same deal as above. |
| 528 | return fCurrentClipBounds; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 529 | } |
| 530 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 531 | // Map the rect back to identity space. |
mtklein | 6332f1d | 2014-08-19 07:09:40 -0700 | [diff] [blame] | 532 | fCTM->mapRect(&rect); |
mtklein | 479601b | 2014-08-18 08:45:33 -0700 | [diff] [blame] | 533 | |
| 534 | // Nothing can draw outside the current clip. |
| 535 | // (Only bounded ops call into this method, so oddballs like Clear don't matter here.) |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 536 | rect.intersect(fCurrentClipBounds); |
| 537 | return rect; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 538 | } |
| 539 | |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 540 | // Conservative identity-space bounds for each op in the SkRecord. |
| 541 | SkAutoTMalloc<Bounds> fBounds; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 542 | |
| 543 | // We walk fCurrentOp through the SkRecord, as we go using updateCTM() |
| 544 | // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 545 | // identity-space bounds of the current clip (fCurrentClipBounds). |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 546 | unsigned fCurrentOp; |
mtklein | 6332f1d | 2014-08-19 07:09:40 -0700 | [diff] [blame] | 547 | const SkMatrix* fCTM; |
mtklein | 533eb78 | 2014-08-27 10:39:42 -0700 | [diff] [blame] | 548 | Bounds fCurrentClipBounds; |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 549 | |
| 550 | // 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] | 551 | SkTDArray<SaveBounds> fSaveStack; |
| 552 | SkTDArray<unsigned> fControlIndices; |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 553 | }; |
| 554 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 555 | } // namespace SkRecords |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 556 | |
| 557 | void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) { |
mtklein | 828ce1f | 2014-08-13 12:58:45 -0700 | [diff] [blame] | 558 | SkRecords::FillBounds(record, bbh); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 559 | } |