Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(934)

Side by Side Diff: src/record/SkRecordDraw.cpp

Issue 231653002: SkRecordDraw: skip draw ops when the clip is empty (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pop cull unconditionally Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/tests.gypi ('k') | src/record/SkRecorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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));
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 CASE(PopCull, popCull());
52 #undef CASE
27 53
28 CASE(Restore) { canvas->restore(); } 54 // Nothing fancy below here. These commands respect and don't change the clip.
29 CASE(Save) { canvas->save(r.flags); } 55 #define CASE(T, call) \
30 CASE(SaveLayer) { canvas->saveLayer(r.bounds, r.paint, r.flags); } 56 template <> void Draw::operator()(const SkRecords::T& r) { if (!fClipEmpty) fCanvas->call; }
57 CASE(Concat, concat(r.matrix));
58 CASE(SetMatrix, setMatrix(r.matrix));
31 59
32 CASE(PopCull) { canvas->popCull(); } 60 CASE(DrawBitmap, drawBitmap(r.bitmap, r.left, r.top, r.paint));
33 61 CASE(DrawBitmapMatrix, drawBitmapMatrix(r.bitmap, r.matrix, r.paint));
34 CASE(Concat) { canvas->concat(r.matrix); } 62 CASE(DrawBitmapNine, drawBitmapNine(r.bitmap, r.center, r.dst, r.paint));
35 CASE(SetMatrix) { canvas->setMatrix(r.matrix); } 63 CASE(DrawBitmapRectToRect, drawBitmapRectToRect(r.bitmap, r.src, r.dst, r.paint, r.flags));
36 64 CASE(DrawDRRect, drawDRRect(r.outer, r.inner, r.paint));
37 CASE(ClipPath) { canvas->clipPath(r.path, r.op, r.doAA); } 65 CASE(DrawOval, drawOval(r.oval, r.paint));
38 CASE(ClipRRect) { canvas->clipRRect(r.rrect, r.op, r.doAA); } 66 CASE(DrawPaint, drawPaint(r.paint));
39 CASE(ClipRect) { canvas->clipRect(r.rect, r.op, r.doAA); } 67 CASE(DrawPath, drawPath(r.path, r.paint));
40 CASE(ClipRegion) { canvas->clipRegion(r.region, r.op); } 68 CASE(DrawPoints, drawPoints(r.mode, r.count, r.pts, r.paint));
41 69 CASE(DrawPosText, drawPosText(r.text, r.byteLength, r.pos, r.paint));
42 CASE(Clear) { canvas->clear(r.color); } 70 CASE(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
43 CASE(DrawBitmap) { canvas->drawBitmap(r.bitmap, r.left, r.top, r.paint); } 71 CASE(DrawRRect, drawRRect(r.rrect, r.paint));
44 CASE(DrawBitmapMatrix) { canvas->drawBitmapMatrix(r.bitmap, r.matrix, r.paint); } 72 CASE(DrawRect, drawRect(r.rect, r.paint));
45 CASE(DrawBitmapNine) { canvas->drawBitmapNine(r.bitmap, r.center, r.dst, r.paint ); } 73 CASE(DrawSprite, drawSprite(r.bitmap, r.left, r.top, r.paint));
46 CASE(DrawBitmapRectToRect) { 74 CASE(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint));
47 canvas->drawBitmapRectToRect(r.bitmap, r.src, r.dst, r.paint, r.flags); 75 CASE(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa int));
48 } 76 CASE(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co lors,
49 CASE(DrawDRRect) { canvas->drawDRRect(r.outer, r.inner, r.paint); } 77 r.xmode.get(), r.indices, r.indexCount, r.paint) );
50 CASE(DrawOval) { canvas->drawOval(r.oval, r.paint); }
51 CASE(DrawPaint) { canvas->drawPaint(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 78 #undef CASE
66 79
67 } // namespace 80 } // namespace
68 81
69 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) { 82 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) {
70 Draw draw; 83 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) {
71 draw.canvas = canvas; 84 record.visit(draw.index(), draw);
72
73 for (draw.index = 0; draw.index < record.count(); draw.index++) {
74 record.visit(draw.index, draw);
75 } 85 }
76 } 86 }
OLDNEW
« no previous file with comments | « gyp/tests.gypi ('k') | src/record/SkRecorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698