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

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

Issue 258183002: Don't bother doing the empty clip check in SkRecordDraw. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments and tests 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 | « no previous file | tests/RecordDrawTest.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 #include "SkRecordTraits.h"
11
12 namespace { 10 namespace {
13 11
14 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 12 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
15 class Draw : SkNoncopyable { 13 class Draw : SkNoncopyable {
16 public: 14 public:
17 explicit Draw(SkCanvas* canvas) : fCanvas(canvas), fIndex(0) {} 15 explicit Draw(SkCanvas* canvas) : fCanvas(canvas), fIndex(0) {}
18 16
19 unsigned index() const { return fIndex; } 17 unsigned index() const { return fIndex; }
20 void next() { ++fIndex; } 18 void next() { ++fIndex; }
21 19
22 template <typename T> void operator()(const T& r) { 20 template <typename T> void operator()(const T& r) {
23 if (!this->skip(r)) { 21 if (!this->skip(r)) {
24 this->draw(r); 22 this->draw(r);
25 } 23 }
26 } 24 }
27 25
28 private: 26 private:
29 // No base case, so we'll be compile-time checked that we implemented all po ssibilities below. 27 // No base case, so we'll be compile-time checked that we implemented all po ssibilities below.
30 template <typename T> void draw(const T&); 28 template <typename T> void draw(const T&);
31 29
32 // skip() returns true if we can skip this command, false if not. 30 // skip() should return true if we can skip this command, false if not.
33 // Update fIndex directly to skip more than just this one command. 31 // It may update fIndex directly to skip more than just this one command.
34 32
35 // If we're drawing into an empty clip, we can skip it. Otherwise, run the command. 33 // Mostly we just blindly call fCanvas and let it handle quick rejects itsel f.
36 template <typename T> 34 template <typename T> bool skip(const T&) { return false; }
37 SK_WHEN(SkRecords::IsDraw<T>, bool) skip(const T&) { return fCanvas->isClipE mpty(); }
38 35
39 template <typename T> 36 // We add our own quick rejects for commands added by optimizations.
40 SK_WHEN(!SkRecords::IsDraw<T>, bool) skip(const T&) { return false; }
41
42 // Special versions for commands added by optimizations.
43 bool skip(const SkRecords::PairedPushCull& r) { 37 bool skip(const SkRecords::PairedPushCull& r) {
44 if (fCanvas->quickReject(r.base->rect)) { 38 if (fCanvas->quickReject(r.base->rect)) {
45 fIndex += r.skip; 39 fIndex += r.skip;
46 return true; 40 return true;
47 } 41 }
48 return this->skip(*r.base); 42 return false;
49 } 43 }
50
51 bool skip(const SkRecords::BoundedDrawPosTextH& r) { 44 bool skip(const SkRecords::BoundedDrawPosTextH& r) {
52 return this->skip(*r.base) || fCanvas->quickRejectY(r.minY, r.maxY); 45 return fCanvas->quickRejectY(r.minY, r.maxY);
53 } 46 }
54 47
55 SkCanvas* fCanvas; 48 SkCanvas* fCanvas;
56 unsigned fIndex; 49 unsigned fIndex;
57 }; 50 };
58 51
59 // NoOps draw nothing. 52 // NoOps draw nothing.
60 template <> void Draw::draw(const SkRecords::NoOp&) {} 53 template <> void Draw::draw(const SkRecords::NoOp&) {}
61 54
62 #define DRAW(T, call) template <> void Draw::draw(const SkRecords::T& r) { fCanv as->call; } 55 #define DRAW(T, call) template <> void Draw::draw(const SkRecords::T& r) { fCanv as->call; }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 template <> void Draw::draw(const SkRecords::PairedPushCull& r) { this->draw(*r. base); } 90 template <> void Draw::draw(const SkRecords::PairedPushCull& r) { this->draw(*r. base); }
98 template <> void Draw::draw(const SkRecords::BoundedDrawPosTextH& r) { this->dra w(*r.base); } 91 template <> void Draw::draw(const SkRecords::BoundedDrawPosTextH& r) { this->dra w(*r.base); }
99 92
100 } // namespace 93 } // namespace
101 94
102 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) { 95 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas) {
103 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) { 96 for (Draw draw(canvas); draw.index() < record.count(); draw.next()) {
104 record.visit(draw.index(), draw); 97 record.visit(draw.index(), draw);
105 } 98 }
106 } 99 }
OLDNEW
« no previous file with comments | « no previous file | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698