| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef SkRecordPattern_DEFINED | 8 #ifndef SkRecordPattern_DEFINED |
| 9 #define SkRecordPattern_DEFINED | 9 #define SkRecordPattern_DEFINED |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 fPtr = nullptr; | 34 fPtr = nullptr; |
| 35 return false; | 35 return false; |
| 36 } | 36 } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 type* fPtr; | 39 type* fPtr; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // Matches any command that draws, and stores its paint. | 42 // Matches any command that draws, and stores its paint. |
| 43 class IsDraw { | 43 class IsDraw { |
| 44 SK_CREATE_MEMBER_DETECTOR(paint); | |
| 45 public: | 44 public: |
| 46 IsDraw() : fPaint(nullptr) {} | 45 IsDraw() : fPaint(nullptr) {} |
| 47 | 46 |
| 48 typedef SkPaint type; | 47 typedef SkPaint type; |
| 49 type* get() { return fPaint; } | 48 type* get() { return fPaint; } |
| 50 | 49 |
| 51 template <typename T> | 50 template <typename T> |
| 52 SK_WHEN(HasMember_paint<T>, bool) operator()(T* draw) { | 51 SK_WHEN(T::kTags & kDraw_Tag, bool) operator()(T* draw) { |
| 53 fPaint = AsPtr(draw->paint); | 52 fPaint = AsPtr(draw->paint); |
| 54 return true; | 53 return true; |
| 55 } | 54 } |
| 56 | 55 |
| 56 bool operator()(DrawDrawable*) { |
| 57 static_assert(DrawDrawable::kTags & kDraw_Tag, ""); |
| 58 fPaint = nullptr; |
| 59 return true; |
| 60 } |
| 61 |
| 57 template <typename T> | 62 template <typename T> |
| 58 SK_WHEN(!HasMember_paint<T>, bool) operator()(T*) { | 63 SK_WHEN(!(T::kTags & kDraw_Tag), bool) operator()(T* draw) { |
| 59 fPaint = nullptr; | 64 fPaint = nullptr; |
| 60 return false; | 65 return false; |
| 61 } | 66 } |
| 62 | |
| 63 // SaveLayer has an SkPaint named paint, but it's not a draw. | |
| 64 bool operator()(SaveLayer*) { | |
| 65 fPaint = nullptr; | |
| 66 return false; | |
| 67 } | |
| 68 | 67 |
| 69 private: | 68 private: |
| 70 // Abstracts away whether the paint is always part of the command or optiona
l. | 69 // Abstracts away whether the paint is always part of the command or optiona
l. |
| 71 template <typename T> static T* AsPtr(SkRecords::Optional<T>& x) { return x;
} | 70 template <typename T> static T* AsPtr(SkRecords::Optional<T>& x) { return x;
} |
| 72 template <typename T> static T* AsPtr(T& x) { return &x; } | 71 template <typename T> static T* AsPtr(T& x) { return &x; } |
| 73 | 72 |
| 74 type* fPaint; | 73 type* fPaint; |
| 75 }; | 74 }; |
| 76 | 75 |
| 77 // Matches if Matcher doesn't. Stores nothing. | 76 // Matches if Matcher doesn't. Stores nothing. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 197 |
| 199 template <typename A, typename B, typename C, typename D, typename E, typename F
> | 198 template <typename A, typename B, typename C, typename D, typename E, typename F
> |
| 200 struct Pattern6 : Cons<A, Pattern5<B, C, D, E, F> > {}; | 199 struct Pattern6 : Cons<A, Pattern5<B, C, D, E, F> > {}; |
| 201 | 200 |
| 202 template <typename A, typename B, typename C, typename D, typename E, typename F
, typename G> | 201 template <typename A, typename B, typename C, typename D, typename E, typename F
, typename G> |
| 203 struct Pattern7 : Cons<A, Pattern6<B, C, D, E, F, G> > {}; | 202 struct Pattern7 : Cons<A, Pattern6<B, C, D, E, F, G> > {}; |
| 204 | 203 |
| 205 } // namespace SkRecords | 204 } // namespace SkRecords |
| 206 | 205 |
| 207 #endif//SkRecordPattern_DEFINED | 206 #endif//SkRecordPattern_DEFINED |
| OLD | NEW |