| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkRecordDraw.h" | 8 #include "SkRecordDraw.h" |
| 9 #include "SkTSort.h" | 9 #include "SkTSort.h" |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // NoOps draw nothing. | 57 // NoOps draw nothing. |
| 58 template <> void Draw::draw(const NoOp&) {} | 58 template <> void Draw::draw(const NoOp&) {} |
| 59 | 59 |
| 60 #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } | 60 #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } |
| 61 DRAW(Restore, restore()); | 61 DRAW(Restore, restore()); |
| 62 DRAW(Save, save()); | 62 DRAW(Save, save()); |
| 63 DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); | 63 DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); |
| 64 DRAW(PopCull, popCull()); | 64 DRAW(PopCull, popCull()); |
| 65 DRAW(PushCull, pushCull(r.rect)); | 65 DRAW(PushCull, pushCull(r.rect)); |
| 66 DRAW(Clear, clear(r.color)); | 66 DRAW(Clear, clear(r.color)); |
| 67 DRAW(Concat, concat(r.matrix)); | |
| 68 DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); | 67 DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); |
| 69 | 68 |
| 70 DRAW(ClipPath, clipPath(r.path, r.op, r.doAA)); | 69 DRAW(ClipPath, clipPath(r.path, r.op, r.doAA)); |
| 71 DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA)); | 70 DRAW(ClipRRect, clipRRect(r.rrect, r.op, r.doAA)); |
| 72 DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA)); | 71 DRAW(ClipRect, clipRect(r.rect, r.op, r.doAA)); |
| 73 DRAW(ClipRegion, clipRegion(r.region, r.op)); | 72 DRAW(ClipRegion, clipRegion(r.region, r.op)); |
| 74 | 73 |
| 75 DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint)); | 74 DRAW(DrawBitmap, drawBitmap(shallow_copy(r.bitmap), r.left, r.top, r.paint)); |
| 76 DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.pain
t)); | 75 DRAW(DrawBitmapMatrix, drawBitmapMatrix(shallow_copy(r.bitmap), r.matrix, r.pain
t)); |
| 77 DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.p
aint)); | 76 DRAW(DrawBitmapNine, drawBitmapNine(shallow_copy(r.bitmap), r.center, r.dst, r.p
aint)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // inside the Save/Restore block, drawing ops are unioned with the bounds of | 112 // inside the Save/Restore block, drawing ops are unioned with the bounds of |
| 114 // the block, and control ops are stashed away for later. When we finish the | 113 // the block, and control ops are stashed away for later. When we finish the |
| 115 // block with a Restore, our bounds are complete, and we go back and fill them | 114 // block with a Restore, our bounds are complete, and we go back and fill them |
| 116 // in for all the control ops we stashed away. | 115 // in for all the control ops we stashed away. |
| 117 class FillBounds : SkNoncopyable { | 116 class FillBounds : SkNoncopyable { |
| 118 public: | 117 public: |
| 119 FillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) : fBounds(record.co
unt()) { | 118 FillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) : fBounds(record.co
unt()) { |
| 120 // Calculate bounds for all ops. This won't go quite in order, so we'll
need | 119 // Calculate bounds for all ops. This won't go quite in order, so we'll
need |
| 121 // to store the bounds separately then feed them in to the BBH later in
order. | 120 // to store the bounds separately then feed them in to the BBH later in
order. |
| 122 const SkIRect largest = SkIRect::MakeLargest(); | 121 const SkIRect largest = SkIRect::MakeLargest(); |
| 123 fCTM.setIdentity(); | 122 fCTM = &SkMatrix::I(); |
| 124 fCurrentClipBounds = largest; | 123 fCurrentClipBounds = largest; |
| 125 for (fCurrentOp = 0; fCurrentOp < record.count(); fCurrentOp++) { | 124 for (fCurrentOp = 0; fCurrentOp < record.count(); fCurrentOp++) { |
| 126 record.visit<void>(fCurrentOp, *this); | 125 record.visit<void>(fCurrentOp, *this); |
| 127 } | 126 } |
| 128 | 127 |
| 129 // If we have any lingering unpaired Saves, simulate restores to make | 128 // If we have any lingering unpaired Saves, simulate restores to make |
| 130 // sure all ops in those Save blocks have their bounds calculated. | 129 // sure all ops in those Save blocks have their bounds calculated. |
| 131 while (!fSaveStack.isEmpty()) { | 130 while (!fSaveStack.isEmpty()) { |
| 132 this->popSaveBlock(); | 131 this->popSaveBlock(); |
| 133 } | 132 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 154 } | 153 } |
| 155 | 154 |
| 156 private: | 155 private: |
| 157 struct SaveBounds { | 156 struct SaveBounds { |
| 158 int controlOps; // Number of control ops in this Save block, incl
uding the Save. | 157 int controlOps; // Number of control ops in this Save block, incl
uding the Save. |
| 159 SkIRect bounds; // Bounds of everything in the block. | 158 SkIRect bounds; // Bounds of everything in the block. |
| 160 const SkPaint* paint; // Unowned. If set, adjusts the bounds of all op
s in this block. | 159 const SkPaint* paint; // Unowned. If set, adjusts the bounds of all op
s in this block. |
| 161 }; | 160 }; |
| 162 | 161 |
| 163 template <typename T> void updateCTM(const T&) { /* most ops don't change th
e CTM */ } | 162 template <typename T> void updateCTM(const T&) { /* most ops don't change th
e CTM */ } |
| 164 void updateCTM(const Restore& op) { fCTM = op.matrix; } | 163 void updateCTM(const Restore& op) { fCTM = &op.matrix; } |
| 165 void updateCTM(const SetMatrix& op) { fCTM = op.matrix; } | 164 void updateCTM(const SetMatrix& op) { fCTM = &op.matrix; } |
| 166 void updateCTM(const Concat& op) { fCTM.preConcat(op.matrix); } | |
| 167 | 165 |
| 168 template <typename T> void updateClipBounds(const T&) { /* most ops don't ch
ange the clip */ } | 166 template <typename T> void updateClipBounds(const T&) { /* most ops don't ch
ange the clip */ } |
| 169 // Each of these devBounds fields is the state of the device bounds after th
e op. | 167 // Each of these devBounds fields is the state of the device bounds after th
e op. |
| 170 // So Restore's devBounds are those bounds saved by its paired Save or SaveL
ayer. | 168 // So Restore's devBounds are those bounds saved by its paired Save or SaveL
ayer. |
| 171 void updateClipBounds(const Restore& op) { fCurrentClipBounds = op.devBou
nds; } | 169 void updateClipBounds(const Restore& op) { fCurrentClipBounds = op.devBou
nds; } |
| 172 void updateClipBounds(const ClipPath& op) { fCurrentClipBounds = op.devBou
nds; } | 170 void updateClipBounds(const ClipPath& op) { fCurrentClipBounds = op.devBou
nds; } |
| 173 void updateClipBounds(const ClipRRect& op) { fCurrentClipBounds = op.devBou
nds; } | 171 void updateClipBounds(const ClipRRect& op) { fCurrentClipBounds = op.devBou
nds; } |
| 174 void updateClipBounds(const ClipRect& op) { fCurrentClipBounds = op.devBou
nds; } | 172 void updateClipBounds(const ClipRect& op) { fCurrentClipBounds = op.devBou
nds; } |
| 175 void updateClipBounds(const ClipRegion& op) { fCurrentClipBounds = op.devBou
nds; } | 173 void updateClipBounds(const ClipRegion& op) { fCurrentClipBounds = op.devBou
nds; } |
| 176 void updateClipBounds(const SaveLayer& op) { | 174 void updateClipBounds(const SaveLayer& op) { |
| 177 if (op.bounds) { | 175 if (op.bounds) { |
| 178 fCurrentClipBounds.intersect(this->adjustAndMap(*op.bounds, op.paint
)); | 176 fCurrentClipBounds.intersect(this->adjustAndMap(*op.bounds, op.paint
)); |
| 179 } | 177 } |
| 180 } | 178 } |
| 181 | 179 |
| 182 // The bounds of these ops must be calculated when we hit the Restore | 180 // The bounds of these ops must be calculated when we hit the Restore |
| 183 // from the bounds of the ops in the same Save block. | 181 // from the bounds of the ops in the same Save block. |
| 184 void trackBounds(const Save&) { this->pushSaveBlock(NULL); } | 182 void trackBounds(const Save&) { this->pushSaveBlock(NULL); } |
| 185 // TODO: bounds of SaveLayer may be more complicated? | 183 // TODO: bounds of SaveLayer may be more complicated? |
| 186 void trackBounds(const SaveLayer& op) { this->pushSaveBlock(op.paint); } | 184 void trackBounds(const SaveLayer& op) { this->pushSaveBlock(op.paint); } |
| 187 void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(
); } | 185 void trackBounds(const Restore&) { fBounds[fCurrentOp] = this->popSaveBlock(
); } |
| 188 | 186 |
| 189 void trackBounds(const Concat&) { this->pushControl(); } | |
| 190 void trackBounds(const SetMatrix&) { this->pushControl(); } | 187 void trackBounds(const SetMatrix&) { this->pushControl(); } |
| 191 void trackBounds(const ClipRect&) { this->pushControl(); } | 188 void trackBounds(const ClipRect&) { this->pushControl(); } |
| 192 void trackBounds(const ClipRRect&) { this->pushControl(); } | 189 void trackBounds(const ClipRRect&) { this->pushControl(); } |
| 193 void trackBounds(const ClipPath&) { this->pushControl(); } | 190 void trackBounds(const ClipPath&) { this->pushControl(); } |
| 194 void trackBounds(const ClipRegion&) { this->pushControl(); } | 191 void trackBounds(const ClipRegion&) { this->pushControl(); } |
| 195 | 192 |
| 196 // For all other ops, we can calculate and store the bounds directly now. | 193 // For all other ops, we can calculate and store the bounds directly now. |
| 197 template <typename T> void trackBounds(const T& op) { | 194 template <typename T> void trackBounds(const T& op) { |
| 198 fBounds[fCurrentOp] = this->bounds(op); | 195 fBounds[fCurrentOp] = this->bounds(op); |
| 199 this->updateSaveBounds(fBounds[fCurrentOp]); | 196 this->updateSaveBounds(fBounds[fCurrentOp]); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 349 |
| 353 // Adjust rect for all the paints from the SaveLayers we're inside. | 350 // Adjust rect for all the paints from the SaveLayers we're inside. |
| 354 for (int i = fSaveStack.count() - 1; i >= 0; i--) { | 351 for (int i = fSaveStack.count() - 1; i >= 0; i--) { |
| 355 if (!AdjustForPaint(fSaveStack[i].paint, &rect)) { | 352 if (!AdjustForPaint(fSaveStack[i].paint, &rect)) { |
| 356 // Same deal as above. | 353 // Same deal as above. |
| 357 return fCurrentClipBounds; | 354 return fCurrentClipBounds; |
| 358 } | 355 } |
| 359 } | 356 } |
| 360 | 357 |
| 361 // Map the rect back to device space. | 358 // Map the rect back to device space. |
| 362 fCTM.mapRect(&rect); | 359 fCTM->mapRect(&rect); |
| 363 SkIRect devRect; | 360 SkIRect devRect; |
| 364 rect.roundOut(&devRect); | 361 rect.roundOut(&devRect); |
| 365 | 362 |
| 366 // Nothing can draw outside the current clip. | 363 // Nothing can draw outside the current clip. |
| 367 // (Only bounded ops call into this method, so oddballs like Clear don't
matter here.) | 364 // (Only bounded ops call into this method, so oddballs like Clear don't
matter here.) |
| 368 devRect.intersect(fCurrentClipBounds); | 365 devRect.intersect(fCurrentClipBounds); |
| 369 return devRect; | 366 return devRect; |
| 370 } | 367 } |
| 371 | 368 |
| 372 // Conservative device bounds for each op in the SkRecord. | 369 // Conservative device bounds for each op in the SkRecord. |
| 373 SkAutoTMalloc<SkIRect> fBounds; | 370 SkAutoTMalloc<SkIRect> fBounds; |
| 374 | 371 |
| 375 // We walk fCurrentOp through the SkRecord, as we go using updateCTM() | 372 // We walk fCurrentOp through the SkRecord, as we go using updateCTM() |
| 376 // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative | 373 // and updateClipBounds() to maintain the exact CTM (fCTM) and conservative |
| 377 // device bounds of the current clip (fCurrentClipBounds). | 374 // device bounds of the current clip (fCurrentClipBounds). |
| 378 unsigned fCurrentOp; | 375 unsigned fCurrentOp; |
| 379 SkMatrix fCTM; | 376 const SkMatrix* fCTM; |
| 380 SkIRect fCurrentClipBounds; | 377 SkIRect fCurrentClipBounds; |
| 381 | 378 |
| 382 // Used to track the bounds of Save/Restore blocks and the control ops insid
e them. | 379 // Used to track the bounds of Save/Restore blocks and the control ops insid
e them. |
| 383 SkTDArray<SaveBounds> fSaveStack; | 380 SkTDArray<SaveBounds> fSaveStack; |
| 384 SkTDArray<unsigned> fControlIndices; | 381 SkTDArray<unsigned> fControlIndices; |
| 385 }; | 382 }; |
| 386 | 383 |
| 387 } // namespace SkRecords | 384 } // namespace SkRecords |
| 388 | 385 |
| 389 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) { | 386 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) { |
| 390 SkRecords::FillBounds(record, bbh); | 387 SkRecords::FillBounds(record, bbh); |
| 391 } | 388 } |
| OLD | NEW |