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 "SkLayerInfo.h" | 8 #include "SkLayerInfo.h" |
9 #include "SkRecordDraw.h" | 9 #include "SkRecordDraw.h" |
10 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
11 | 11 |
12 void SkRecordDraw(const SkRecord& record, | 12 void SkRecordDraw(const SkRecord& record, |
13 SkCanvas* canvas, | 13 SkCanvas* canvas, |
14 SkPicture const* const drawablePicts[], | 14 SkPicture const* const drawablePicts[], |
15 SkCanvasDrawable* const drawables[], | 15 SkCanvasDrawable* const drawables[], |
16 int drawableCount, | 16 int drawableCount, |
17 const SkBBoxHierarchy* bbh, | 17 const SkBBoxHierarchy* bbh, |
18 SkDrawPictureCallback* callback) { | 18 SkDrawPictureCallback* callback) { |
19 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 19 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
20 | 20 |
21 if (bbh) { | 21 if (bbh) { |
22 // Draw only ops that affect pixels in the canvas's current clip. | 22 // Draw only ops that affect pixels in the canvas's current clip. |
23 // The SkRecord and BBH were recorded in identity space. This canvas | 23 // The SkRecord and BBH were recorded in identity space. This canvas |
24 // is not necessarily in that same space. getClipBounds() returns us | 24 // is not necessarily in that same space. getClipBounds() returns us |
25 // this canvas' clip bounds transformed back into identity space, which | 25 // this canvas' clip bounds transformed back into identity space, which |
26 // lets us query the BBH. | 26 // lets us query the BBH. |
27 SkRect query; | 27 SkRect query; |
28 if (!canvas->getClipBounds(&query)) { | 28 if (!canvas->getClipBounds(&query)) { |
29 // We want to make sure our query rectangle is never totally empty. | 29 query.setEmpty(); |
30 // Clear ignores the clip, so it must draw even if the clip is logic
ally empty. | |
31 query = SkRect::MakeWH(SK_ScalarNearlyZero, SK_ScalarNearlyZero); | |
32 } | 30 } |
33 | 31 |
34 SkTDArray<unsigned> ops; | 32 SkTDArray<unsigned> ops; |
35 bbh->search(query, &ops); | 33 bbh->search(query, &ops); |
36 | 34 |
37 SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount); | 35 SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount); |
38 for (int i = 0; i < ops.count(); i++) { | 36 for (int i = 0; i < ops.count(); i++) { |
39 if (callback && callback->abortDrawing()) { | 37 if (callback && callback->abortDrawing()) { |
40 return; | 38 return; |
41 } | 39 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 72 |
75 namespace SkRecords { | 73 namespace SkRecords { |
76 | 74 |
77 // NoOps draw nothing. | 75 // NoOps draw nothing. |
78 template <> void Draw::draw(const NoOp&) {} | 76 template <> void Draw::draw(const NoOp&) {} |
79 | 77 |
80 #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } | 78 #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; } |
81 DRAW(Restore, restore()); | 79 DRAW(Restore, restore()); |
82 DRAW(Save, save()); | 80 DRAW(Save, save()); |
83 DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); | 81 DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); |
84 DRAW(Clear, clear(r.color)); | |
85 DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); | 82 DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix))); |
86 | 83 |
87 DRAW(ClipPath, clipPath(r.path, r.opAA.op, r.opAA.aa)); | 84 DRAW(ClipPath, clipPath(r.path, r.opAA.op, r.opAA.aa)); |
88 DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op, r.opAA.aa)); | 85 DRAW(ClipRRect, clipRRect(r.rrect, r.opAA.op, r.opAA.aa)); |
89 DRAW(ClipRect, clipRect(r.rect, r.opAA.op, r.opAA.aa)); | 86 DRAW(ClipRect, clipRect(r.rect, r.opAA.op, r.opAA.aa)); |
90 DRAW(ClipRegion, clipRegion(r.region, r.op)); | 87 DRAW(ClipRegion, clipRegion(r.region, r.op)); |
91 | 88 |
92 DRAW(BeginCommentGroup, beginCommentGroup(r.description)); | 89 DRAW(BeginCommentGroup, beginCommentGroup(r.description)); |
93 DRAW(AddComment, addComment(r.key, r.value)); | 90 DRAW(AddComment, addComment(r.key, r.value)); |
94 DRAW(EndCommentGroup, endCommentGroup()); | 91 DRAW(EndCommentGroup, endCommentGroup()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // Adjust rect for all the paints from the SaveLayers we're inside. | 208 // Adjust rect for all the paints from the SaveLayers we're inside. |
212 if (!this->adjustForSaveLayerPaints(&rect)) { | 209 if (!this->adjustForSaveLayerPaints(&rect)) { |
213 // Same deal as above. | 210 // Same deal as above. |
214 return fCurrentClipBounds; | 211 return fCurrentClipBounds; |
215 } | 212 } |
216 | 213 |
217 // Map the rect back to identity space. | 214 // Map the rect back to identity space. |
218 fCTM->mapRect(&rect); | 215 fCTM->mapRect(&rect); |
219 | 216 |
220 // Nothing can draw outside the current clip. | 217 // Nothing can draw outside the current clip. |
221 // (Only bounded ops call into this method, so oddballs like Clear don't
matter here.) | |
222 if (!rect.intersect(fCurrentClipBounds)) { | 218 if (!rect.intersect(fCurrentClipBounds)) { |
223 return Bounds::MakeEmpty(); | 219 return Bounds::MakeEmpty(); |
224 } | 220 } |
225 | 221 |
226 return rect; | 222 return rect; |
227 } | 223 } |
228 | 224 |
229 private: | 225 private: |
230 struct SaveBounds { | 226 struct SaveBounds { |
231 int controlOps; // Number of control ops in this Save block, incl
uding the Save. | 227 int controlOps; // Number of control ops in this Save block, incl
uding the Save. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 void updateSaveBounds(const Bounds& bounds) { | 377 void updateSaveBounds(const Bounds& bounds) { |
382 // If we're in a Save block, expand its bounds to cover these bounds too
. | 378 // If we're in a Save block, expand its bounds to cover these bounds too
. |
383 if (!fSaveStack.isEmpty()) { | 379 if (!fSaveStack.isEmpty()) { |
384 fSaveStack.top().bounds.join(bounds); | 380 fSaveStack.top().bounds.join(bounds); |
385 } | 381 } |
386 } | 382 } |
387 | 383 |
388 // FIXME: this method could use better bounds | 384 // FIXME: this method could use better bounds |
389 Bounds bounds(const DrawText&) const { return fCurrentClipBounds; } | 385 Bounds bounds(const DrawText&) const { return fCurrentClipBounds; } |
390 | 386 |
391 Bounds bounds(const Clear&) const { return fCullRect; } // Ignor
es the clip. | |
392 Bounds bounds(const DrawPaint&) const { return fCurrentClipBounds; } | 387 Bounds bounds(const DrawPaint&) const { return fCurrentClipBounds; } |
393 Bounds bounds(const NoOp&) const { return Bounds::MakeEmpty(); } // NoOp
s don't draw. | 388 Bounds bounds(const NoOp&) const { return Bounds::MakeEmpty(); } // NoOp
s don't draw. |
394 | 389 |
395 Bounds bounds(const DrawSprite& op) const { // Ignores the matrix. | 390 Bounds bounds(const DrawSprite& op) const { // Ignores the matrix. |
396 return Bounds::MakeXYWH(op.left, op.top, op.bitmap.width(), op.bitmap.he
ight()); | 391 return Bounds::MakeXYWH(op.left, op.top, op.bitmap.width(), op.bitmap.he
ight()); |
397 } | 392 } |
398 | 393 |
399 Bounds bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect,
&op.paint); } | 394 Bounds bounds(const DrawRect& op) const { return this->adjustAndMap(op.rect,
&op.paint); } |
400 Bounds bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval,
&op.paint); } | 395 Bounds bounds(const DrawOval& op) const { return this->adjustAndMap(op.oval,
&op.paint); } |
401 Bounds bounds(const DrawRRect& op) const { | 396 Bounds bounds(const DrawRRect& op) const { |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 SkRecords::CollectLayers visitor(cullRect, record, pictList, data); | 787 SkRecords::CollectLayers visitor(cullRect, record, pictList, data); |
793 | 788 |
794 for (unsigned curOp = 0; curOp < record.count(); curOp++) { | 789 for (unsigned curOp = 0; curOp < record.count(); curOp++) { |
795 visitor.setCurrentOp(curOp); | 790 visitor.setCurrentOp(curOp); |
796 record.visit<void>(curOp, visitor); | 791 record.visit<void>(curOp, visitor); |
797 } | 792 } |
798 | 793 |
799 visitor.cleanUp(bbh); | 794 visitor.cleanUp(bbh); |
800 } | 795 } |
801 | 796 |
OLD | NEW |