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 #ifndef SkRecords_DEFINED | 8 #ifndef SkRecords_DEFINED |
9 #define SkRecords_DEFINED | 9 #define SkRecords_DEFINED |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 enum Type { SK_RECORD_TYPES(ENUM) }; | 68 enum Type { SK_RECORD_TYPES(ENUM) }; |
69 #undef ENUM | 69 #undef ENUM |
70 | 70 |
71 // Macros to make it easier to define a record for a draw call with 0 args, 1 ar
gs, 2 args, etc. | 71 // Macros to make it easier to define a record for a draw call with 0 args, 1 ar
gs, 2 args, etc. |
72 // These should be clearer when you look at their use below. | 72 // These should be clearer when you look at their use below. |
73 #define RECORD0(T) \ | 73 #define RECORD0(T) \ |
74 struct T { \ | 74 struct T { \ |
75 static const Type kType = T##_Type; \ | 75 static const Type kType = T##_Type; \ |
76 }; | 76 }; |
77 | 77 |
78 // We try to be flexible about the types the constructors take. Instead of requ
ring the exact type | 78 // Instead of requring the exact type A here, we take any type Z which implicitl
y casts to A. |
79 // A here, we take any type Z which implicitly casts to A. This allows the dela
y_copy() trick to | 79 // This lets our wrappers like ImmutableBitmap work seamlessly. |
80 // work, allowing the caller to decide whether to pass by value or by const&. | |
81 | 80 |
82 #define RECORD1(T, A, a) \ | 81 #define RECORD1(T, A, a) \ |
83 struct T { \ | 82 struct T { \ |
84 static const Type kType = T##_Type; \ | 83 static const Type kType = T##_Type; \ |
85 T() {} \ | 84 T() {} \ |
86 template <typename Z> \ | 85 template <typename Z> \ |
87 T(Z a) : a(a) {} \ | 86 T(const Z& a) : a(a) {} \ |
88 A a; \ | 87 A a; \ |
89 }; | 88 }; |
90 | 89 |
91 #define RECORD2(T, A, a, B, b) \ | 90 #define RECORD2(T, A, a, B, b) \ |
92 struct T { \ | 91 struct T { \ |
93 static const Type kType = T##_Type; \ | 92 static const Type kType = T##_Type; \ |
94 T() {} \ | 93 T() {} \ |
95 template <typename Z, typename Y> \ | 94 template <typename Z, typename Y> \ |
96 T(Z a, Y b) : a(a), b(b) {} \ | 95 T(const Z& a, const Y& b) : a(a), b(b) {} \ |
97 A a; B b; \ | 96 A a; B b; \ |
98 }; | 97 }; |
99 | 98 |
100 #define RECORD3(T, A, a, B, b, C, c) \ | 99 #define RECORD3(T, A, a, B, b, C, c) \ |
101 struct T { \ | 100 struct T { \ |
102 static const Type kType = T##_Type; \ | 101 static const Type kType = T##_Type; \ |
103 T() {} \ | 102 T() {} \ |
104 template <typename Z, typename Y, typename X> \ | 103 template <typename Z, typename Y, typename X> \ |
105 T(Z a, Y b, X c) : a(a), b(b), c(c) {} \ | 104 T(const Z& a, const Y& b, const X& c) : a(a), b(b), c(c) {} \ |
106 A a; B b; C c; \ | 105 A a; B b; C c; \ |
107 }; | 106 }; |
108 | 107 |
109 #define RECORD4(T, A, a, B, b, C, c, D, d) \ | 108 #define RECORD4(T, A, a, B, b, C, c, D, d)
\ |
110 struct T { \ | 109 struct T {
\ |
111 static const Type kType = T##_Type; \ | 110 static const Type kType = T##_Type;
\ |
112 T() {} \ | 111 T() {}
\ |
113 template <typename Z, typename Y, typename X, typename W> \ | 112 template <typename Z, typename Y, typename X, typename W>
\ |
114 T(Z a, Y b, X c, W d) : a(a), b(b), c(c), d(d) {} \ | 113 T(const Z& a, const Y& b, const X& c, const W& d) : a(a), b(b), c(c), d(d) {
} \ |
115 A a; B b; C c; D d; \ | 114 A a; B b; C c; D d;
\ |
116 }; | 115 }; |
117 | 116 |
118 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \ | 117 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \ |
119 struct T { \ | 118 struct T { \ |
120 static const Type kType = T##_Type; \ | 119 static const Type kType = T##_Type; \ |
121 T() {} \ | 120 T() {} \ |
122 template <typename Z, typename Y, typename X, typename W, typename V> \ | 121 template <typename Z, typename Y, typename X, typename W, typename V> \ |
123 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \ | 122 T(const Z& a, const Y& b, const X& c, const W& d, const V& e) \ |
| 123 : a(a), b(b), c(c), d(d), e(e) {} \ |
124 A a; B b; C c; D d; E e; \ | 124 A a; B b; C c; D d; E e; \ |
125 }; | 125 }; |
126 | 126 |
127 #define RECORD8(T, A, a, B, b, C, c, D, d, E, e, F, f, G, g, H, h) \ | 127 #define RECORD8(T, A, a, B, b, C, c, D, d, E, e, F, f, G, g, H, h) \ |
128 struct T { \ | 128 struct T { \ |
129 static const Type kType = T##_Type; \ | 129 static const Type kType = T##_Type; \ |
130 T() {} \ | 130 T() {} \ |
131 template <typename Z, typename Y, typename X, typename W, typename V, typena
me U, typename S, typename R> \ | 131 template <typename Z, typename Y, typename X, typename W, \ |
132 T(Z a, Y b, X c, W d, V e, U f, S g, R h) : a(a), b(b), c(c), d(d), e(e), f(
f), g(g), h(h) {} \ | 132 typename V, typename U, typename S, typename R> \ |
133 A a; B b; C c; D d; E e; F f; G g; H h; \ | 133 T(const Z& a, const Y& b, const X& c, const W& d, \ |
| 134 const V& e, const U& f, const S& g, const R& h) \ |
| 135 : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h) {} \ |
| 136 A a; B b; C c; D d; E e; F f; G g; H h; \ |
134 }; | 137 }; |
135 | 138 |
136 #define ACT_AS_PTR(ptr) \ | 139 #define ACT_AS_PTR(ptr) \ |
137 operator T*() const { return ptr; } \ | 140 operator T*() const { return ptr; } \ |
138 T* operator->() const { return ptr; } | 141 T* operator->() const { return ptr; } |
139 | 142 |
140 template <typename T> | 143 template <typename T> |
141 class RefBox : SkNoncopyable { | 144 class RefBox : SkNoncopyable { |
142 public: | 145 public: |
143 RefBox() {} | 146 RefBox() {} |
144 RefBox(T* obj) : fObj(SkSafeRef(obj)) {} | 147 RefBox(T* obj) : fObj(SkSafeRef(obj)) {} |
145 ~RefBox() { SkSafeUnref(fObj); } | 148 ~RefBox() { SkSafeUnref(fObj); } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 #undef RECORD1 | 383 #undef RECORD1 |
381 #undef RECORD2 | 384 #undef RECORD2 |
382 #undef RECORD3 | 385 #undef RECORD3 |
383 #undef RECORD4 | 386 #undef RECORD4 |
384 #undef RECORD5 | 387 #undef RECORD5 |
385 #undef RECORD8 | 388 #undef RECORD8 |
386 | 389 |
387 } // namespace SkRecords | 390 } // namespace SkRecords |
388 | 391 |
389 #endif//SkRecords_DEFINED | 392 #endif//SkRecords_DEFINED |
OLD | NEW |