| 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 "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  Loading... | 
|   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 } | 
| OLD | NEW |