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

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

Issue 272723007: Add timing to dump_record. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: always walk with fDraw Created 6 years, 7 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 | « src/record/SkRecordDraw.h ('k') | tools/dump_record.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 namespace { 10 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) {
11 for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.next( )) {
12 record.visit<void>(draw.index(), draw);
13 }
14 }
11 15
12 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 16 namespace SkRecords {
13 class Draw : SkNoncopyable {
14 public:
15 explicit Draw(SkCanvas* canvas) : fCanvas(canvas), fIndex(0) {}
16 17
17 unsigned index() const { return fIndex; } 18 bool Draw::skip(const PairedPushCull& r) {
18 void next() { ++fIndex; } 19 if (fCanvas->quickReject(r.base->rect)) {
20 fIndex += r.skip;
21 return true;
22 }
23 return false;
24 }
19 25
20 template <typename T> void operator()(const T& r) { 26 bool Draw::skip(const BoundedDrawPosTextH& r) {
21 if (!this->skip(r)) { 27 return fCanvas->quickRejectY(r.minY, r.maxY);
22 this->draw(r); 28 }
23 }
24 }
25
26 private:
27 // No base case, so we'll be compile-time checked that we implemented all po ssibilities below.
28 template <typename T> void draw(const T&);
29
30 // skip() should return true if we can skip this command, false if not.
31 // It may update fIndex directly to skip more than just this one command.
32
33 // Mostly we just blindly call fCanvas and let it handle quick rejects itsel f.
34 template <typename T> bool skip(const T&) { return false; }
35
36 // We add our own quick rejects for commands added by optimizations.
37 bool skip(const SkRecords::PairedPushCull& r) {
38 if (fCanvas->quickReject(r.base->rect)) {
39 fIndex += r.skip;
40 return true;
41 }
42 return false;
43 }
44 bool skip(const SkRecords::BoundedDrawPosTextH& r) {
45 return fCanvas->quickRejectY(r.minY, r.maxY);
46 }
47
48 SkCanvas* fCanvas;
49 unsigned fIndex;
50 };
51 29
52 // NoOps draw nothing. 30 // NoOps draw nothing.
53 template <> void Draw::draw(const SkRecords::NoOp&) {} 31 template <> void Draw::draw(const NoOp&) {}
54 32
55 #define DRAW(T, call) template <> void Draw::draw(const SkRecords::T& r) { fCanv as->call; } 33 #define DRAW(T, call) template <> void Draw::draw(const T& r) { fCanvas->call; }
56 DRAW(Restore, restore()); 34 DRAW(Restore, restore());
57 DRAW(Save, save(r.flags)); 35 DRAW(Save, save(r.flags));
58 DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags)); 36 DRAW(SaveLayer, saveLayer(r.bounds, r.paint, r.flags));
59 DRAW(PopCull, popCull()); 37 DRAW(PopCull, popCull());
60 DRAW(PushCull, pushCull(r.rect)); 38 DRAW(PushCull, pushCull(r.rect));
61 DRAW(Clear, clear(r.color)); 39 DRAW(Clear, clear(r.color));
62 DRAW(Concat, concat(r.matrix)); 40 DRAW(Concat, concat(r.matrix));
63 DRAW(SetMatrix, setMatrix(r.matrix)); 41 DRAW(SetMatrix, setMatrix(r.matrix));
64 42
65 DRAW(ClipPath, clipPath(r.path, r.op, r.doAA)); 43 DRAW(ClipPath, clipPath(r.path, r.op, r.doAA));
(...skipping 14 matching lines...) Expand all
80 DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint)); 58 DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
81 DRAW(DrawRRect, drawRRect(r.rrect, r.paint)); 59 DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
82 DRAW(DrawRect, drawRect(r.rect, r.paint)); 60 DRAW(DrawRect, drawRect(r.rect, r.paint));
83 DRAW(DrawSprite, drawSprite(r.bitmap, r.left, r.top, r.paint)); 61 DRAW(DrawSprite, drawSprite(r.bitmap, r.left, r.top, r.paint));
84 DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint)); 62 DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint));
85 DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa int)); 63 DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa int));
86 DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co lors, 64 DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co lors,
87 r.xmode.get(), r.indices, r.indexCount, r.paint) ); 65 r.xmode.get(), r.indices, r.indexCount, r.paint) );
88 #undef DRAW 66 #undef DRAW
89 67
90 template <> void Draw::draw(const SkRecords::PairedPushCull& r) { this->draw(*r. base); } 68 template <> void Draw::draw(const PairedPushCull& r) { this->draw(*r.base); }
91 template <> void Draw::draw(const SkRecords::BoundedDrawPosTextH& r) { this->dra w(*r.base); } 69 template <> void Draw::draw(const BoundedDrawPosTextH& r) { this->draw(*r.base); }
92 70
93 } // namespace 71 } // namespace SkRecords
94
95 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) {
96 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) {
97 record.visit<void>(draw.index(), draw);
98 }
99 }
OLDNEW
« no previous file with comments | « src/record/SkRecordDraw.h ('k') | tools/dump_record.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698