OLD | NEW |
---|---|
1 #include "SkRecordDraw.h" | 1 #include "SkRecordDraw.h" |
2 | 2 |
3 namespace { | 3 namespace { |
4 | 4 |
5 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. | 5 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
6 struct Draw { | 6 class Draw : SkNoncopyable { |
7 unsigned index; | 7 public: |
8 SkCanvas* canvas; | 8 explicit Draw(SkCanvas* canvas) : fCanvas(canvas), fIndex(0), fClipEmpty(fal se) {} |
9 | |
10 unsigned index() const { return fIndex; } | |
11 void next() { ++fIndex; } | |
9 | 12 |
10 // No base case, so we'll be compile-time checked that we implemented all po ssibilities below. | 13 // No base case, so we'll be compile-time checked that we implemented all po ssibilities below. |
11 template <typename T> void operator()(const T&); | 14 template <typename T> void operator()(const T&); |
15 | |
16 private: | |
17 // Must be called after any potential clip change. | |
18 void updateClip() { fClipEmpty = fCanvas->isClipEmpty(); } | |
19 | |
20 SkCanvas* fCanvas; | |
21 unsigned fIndex; | |
22 bool fClipEmpty; | |
12 }; | 23 }; |
13 | 24 |
14 template <> void Draw::operator()(const SkRecords::PushCull& pushCull) { | 25 template <> void Draw::operator()(const SkRecords::PushCull& r) { |
15 if (pushCull.popOffset != SkRecords::kUnsetPopOffset && | 26 if (r.popOffset != SkRecords::kUnsetPopOffset && |
16 canvas->quickReject(pushCull.rect)) { | 27 fCanvas->quickReject(r.rect)) { |
17 // We skip to the popCull, then the loop moves us just beyond it. | 28 // We skip to the popCull, then the loop moves us just beyond it. |
18 index += pushCull.popOffset; | 29 fIndex += r.popOffset; |
19 } else { | 30 } else { |
20 canvas->pushCull(pushCull.rect); | 31 fCanvas->pushCull(r.rect); |
21 } | 32 } |
22 } | 33 } |
23 | 34 |
24 // Nothing fancy below here. | 35 // These commands might change the clip. |
36 #define CASE(T, call) \ | |
37 template <> void Draw::operator()(const SkRecords::T& r) { fCanvas->call; th is->updateClip(); } | |
38 CASE(Restore, restore()); | |
39 CASE(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); | |
40 CASE(ClipPath, clipPath(r.path, r.op, r.doAA)); | |
41 CASE(ClipRRect, clipRRect(r.rrect, r.op, r.doAA)); | |
42 CASE(ClipRect, clipRect(r.rect, r.op, r.doAA)); | |
43 CASE(ClipRegion, clipRegion(r.region, r.op)); | |
f(malita)
2014/04/09 21:44:28
We could optimize Clip* some: they can be skipped
mtklein
2014/04/09 21:52:12
Smart. Will follow up with this.
| |
44 #undef CASE | |
25 | 45 |
26 #define CASE(T) template <> void Draw::operator()(const SkRecords::T& r) | 46 // Commands which must run regardless of the clip. |
47 #define CASE(T, call) \ | |
48 template <> void Draw::operator()(const SkRecords::T& r) { fCanvas->call; } | |
49 CASE(Save, save(r.flags)); | |
50 CASE(Clear, clear(r.color)); | |
51 #undef CASE | |
27 | 52 |
28 CASE(Restore) { canvas->restore(); } | 53 // Nothing fancy below here. These commands respect and don't change the clip. |
29 CASE(Save) { canvas->save(r.flags); } | 54 #define CASE(T, call) \ |
30 CASE(SaveLayer) { canvas->saveLayer(r.bounds, r.paint, r.flags); } | 55 template <> void Draw::operator()(const SkRecords::T& r) { if (!fClipEmpty) fCanvas->call; } |
56 CASE(PopCull, popCull()); | |
f(malita)
2014/04/09 21:44:28
I think popCull should also execute unconditionall
mtklein
2014/04/09 21:52:12
Done.
| |
31 | 57 |
32 CASE(PopCull) { canvas->popCull(); } | 58 CASE(Concat, concat(r.matrix)); |
59 CASE(SetMatrix, setMatrix(r.matrix)); | |
33 | 60 |
34 CASE(Concat) { canvas->concat(r.matrix); } | 61 CASE(DrawBitmap, drawBitmap(r.bitmap, r.left, r.top, r.paint)); |
35 CASE(SetMatrix) { canvas->setMatrix(r.matrix); } | 62 CASE(DrawBitmapMatrix, drawBitmapMatrix(r.bitmap, r.matrix, r.paint)); |
36 | 63 CASE(DrawBitmapNine, drawBitmapNine(r.bitmap, r.center, r.dst, r.paint)); |
37 CASE(ClipPath) { canvas->clipPath(r.path, r.op, r.doAA); } | 64 CASE(DrawBitmapRectToRect, drawBitmapRectToRect(r.bitmap, r.src, r.dst, r.paint, r.flags)); |
38 CASE(ClipRRect) { canvas->clipRRect(r.rrect, r.op, r.doAA); } | 65 CASE(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint)); |
39 CASE(ClipRect) { canvas->clipRect(r.rect, r.op, r.doAA); } | 66 CASE(DrawOval, drawOval(r.oval, r.paint)); |
40 CASE(ClipRegion) { canvas->clipRegion(r.region, r.op); } | 67 CASE(DrawPaint, drawPaint(r.paint)); |
41 | 68 CASE(DrawPath, drawPath(r.path, r.paint)); |
42 CASE(Clear) { canvas->clear(r.color); } | 69 CASE(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint)); |
43 CASE(DrawBitmap) { canvas->drawBitmap(r.bitmap, r.left, r.top, r.paint); } | 70 CASE(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint)); |
44 CASE(DrawBitmapMatrix) { canvas->drawBitmapMatrix(r.bitmap, r.matrix, r.paint); } | 71 CASE(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint)); |
45 CASE(DrawBitmapNine) { canvas->drawBitmapNine(r.bitmap, r.center, r.dst, r.paint ); } | 72 CASE(DrawRRect, drawRRect(r.rrect, r.paint)); |
46 CASE(DrawBitmapRectToRect) { | 73 CASE(DrawRect, drawRect(r.rect, r.paint)); |
47 canvas->drawBitmapRectToRect(r.bitmap, r.src, r.dst, r.paint, r.flags); | 74 CASE(DrawSprite, drawSprite(r.bitmap, r.left, r.top, r.paint)); |
48 } | 75 CASE(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint)); |
49 CASE(DrawDRRect) { canvas->drawDRRect(r.outer, r.inner, r.paint); } | 76 CASE(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa int)); |
50 CASE(DrawOval) { canvas->drawOval(r.oval, r.paint); } | 77 CASE(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co lors, |
51 CASE(DrawPaint) { canvas->drawPaint(r.paint); } | 78 r.xmode.get(), r.indices, r.indexCount, r.paint) ); |
52 CASE(DrawPath) { canvas->drawPath(r.path, r.paint); } | |
53 CASE(DrawPoints) { canvas->drawPoints(r.mode, r.count, r.pts, r.paint); } | |
54 CASE(DrawPosText) { canvas->drawPosText(r.text, r.byteLength, r.pos, r.paint); } | |
55 CASE(DrawPosTextH) { canvas->drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.p aint); } | |
56 CASE(DrawRRect) { canvas->drawRRect(r.rrect, r.paint); } | |
57 CASE(DrawRect) { canvas->drawRect(r.rect, r.paint); } | |
58 CASE(DrawSprite) { canvas->drawSprite(r.bitmap, r.left, r.top, r.paint); } | |
59 CASE(DrawText) { canvas->drawText(r.text, r.byteLength, r.x, r.y, r.paint); } | |
60 CASE(DrawTextOnPath) { canvas->drawTextOnPath(r.text, r.byteLength, r.path, r.ma trix, r.paint); } | |
61 CASE(DrawVertices) { | |
62 canvas->drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors, | |
63 r.xmode.get(), r.indices, r.indexCount, r.paint); | |
64 } | |
65 #undef CASE | 79 #undef CASE |
66 | 80 |
67 } // namespace | 81 } // namespace |
68 | 82 |
69 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) { | 83 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) { |
70 Draw draw; | 84 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) { |
71 draw.canvas = canvas; | 85 record.visit(draw.index(), draw); |
72 | |
73 for (draw.index = 0; draw.index < record.count(); draw.index++) { | |
74 record.visit(draw.index, draw); | |
75 } | 86 } |
76 } | 87 } |
OLD | NEW |