| 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 |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 | 12 |
| 13 namespace SkRecords { | 13 namespace SkRecords { |
| 14 | 14 |
| 15 // A list of all the types of canvas calls we can record. | 15 // A list of all the types of canvas calls we can record. |
| 16 // Each of these is reified into a struct below. | 16 // Each of these is reified into a struct below. |
| 17 // | 17 // |
| 18 // (We're using the macro-of-macro trick here to do several different things wit
h the same list.) | 18 // (We're using the macro-of-macro trick here to do several different things wit
h the same list.) |
| 19 // | 19 // |
| 20 // We leave this SK_RECORD_TYPES macro defined for use by code that wants to ope
rate on SkRecords | 20 // We leave this SK_RECORD_TYPES macro defined for use by code that wants to ope
rate on SkRecords |
| 21 // types polymorphically. (See SkRecord::Record::{visit,mutate} for an example.
) | 21 // types polymorphically. (See SkRecord::Record::{visit,mutate} for an example.
) |
| 22 #define SK_RECORD_TYPES(M) \ | 22 #define SK_RECORD_TYPES(M) \ |
| 23 M(Restore) \ | 23 M(NoOp) \ |
| 24 M(Save) \ | 24 M(Restore) \ |
| 25 M(SaveLayer) \ | 25 M(Save) \ |
| 26 M(Concat) \ | 26 M(SaveLayer) \ |
| 27 M(SetMatrix) \ | 27 M(Concat) \ |
| 28 M(ClipPath) \ | 28 M(SetMatrix) \ |
| 29 M(ClipRRect) \ | 29 M(ClipPath) \ |
| 30 M(ClipRect) \ | 30 M(ClipRRect) \ |
| 31 M(ClipRegion) \ | 31 M(ClipRect) \ |
| 32 M(Clear) \ | 32 M(ClipRegion) \ |
| 33 M(DrawBitmap) \ | 33 M(Clear) \ |
| 34 M(DrawBitmapMatrix) \ | 34 M(DrawBitmap) \ |
| 35 M(DrawBitmapNine) \ | 35 M(DrawBitmapMatrix) \ |
| 36 M(DrawBitmapRectToRect) \ | 36 M(DrawBitmapNine) \ |
| 37 M(DrawDRRect) \ | 37 M(DrawBitmapRectToRect) \ |
| 38 M(DrawOval) \ | 38 M(DrawDRRect) \ |
| 39 M(DrawPaint) \ | 39 M(DrawOval) \ |
| 40 M(DrawPath) \ | 40 M(DrawPaint) \ |
| 41 M(DrawPoints) \ | 41 M(DrawPath) \ |
| 42 M(DrawPosText) \ | 42 M(DrawPoints) \ |
| 43 M(DrawPosTextH) \ | 43 M(DrawPosText) \ |
| 44 M(DrawRRect) \ | 44 M(DrawPosTextH) \ |
| 45 M(DrawRect) \ | 45 M(DrawRRect) \ |
| 46 M(DrawSprite) \ | 46 M(DrawRect) \ |
| 47 M(DrawText) \ | 47 M(DrawSprite) \ |
| 48 M(DrawTextOnPath) \ | 48 M(DrawText) \ |
| 49 M(DrawVertices) \ | 49 M(DrawTextOnPath) \ |
| 50 M(PushCull) \ | 50 M(DrawVertices) \ |
| 51 M(PopCull) | 51 M(PushCull) \ |
| 52 M(PopCull) \ |
| 53 M(PairedPushCull) /*From SkRecordAnnotateCullingPairs*/ \ |
| 54 M(BoundedDrawPosTextH) /*From SkRecordBoundDrawPosTextH*/ |
| 52 | 55 |
| 53 // Defines SkRecords::Type, an enum of all record types. | 56 // Defines SkRecords::Type, an enum of all record types. |
| 54 #define ENUM(T) T##_Type, | 57 #define ENUM(T) T##_Type, |
| 55 enum Type { SK_RECORD_TYPES(ENUM) }; | 58 enum Type { SK_RECORD_TYPES(ENUM) }; |
| 56 #undef ENUM | 59 #undef ENUM |
| 57 | 60 |
| 58 // Macros to make it easier to define a record for a draw call with 0 args, 1 ar
gs, 2 args, etc. | 61 // Macros to make it easier to define a record for a draw call with 0 args, 1 ar
gs, 2 args, etc. |
| 59 // These should be clearer when you look at their use below. | 62 // These should be clearer when you look at their use below. |
| 60 #define RECORD0(T) \ | 63 #define RECORD0(T) \ |
| 61 struct T { \ | 64 struct T { \ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 }; | 103 }; |
| 101 | 104 |
| 102 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \ | 105 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \ |
| 103 struct T { \ | 106 struct T { \ |
| 104 static const Type kType = T##_Type; \ | 107 static const Type kType = T##_Type; \ |
| 105 template <typename Z, typename Y, typename X, typename W, typename V> \ | 108 template <typename Z, typename Y, typename X, typename W, typename V> \ |
| 106 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \ | 109 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \ |
| 107 A a; B b; C c; D d; E e; \ | 110 A a; B b; C c; D d; E e; \ |
| 108 }; | 111 }; |
| 109 | 112 |
| 113 #define ACT_AS_PTR(ptr) \ |
| 114 operator T*() { return ptr; } \ |
| 115 operator const T*() const { return ptr; } \ |
| 116 T* operator->() { return ptr; } \ |
| 117 const T* operator->() const { return ptr; } |
| 118 |
| 110 // An Optional doesn't own the pointer's memory, but may need to destroy non-POD
data. | 119 // An Optional doesn't own the pointer's memory, but may need to destroy non-POD
data. |
| 111 template <typename T> | 120 template <typename T> |
| 112 class Optional : SkNoncopyable { | 121 class Optional : SkNoncopyable { |
| 113 public: | 122 public: |
| 114 Optional(T* ptr) : fPtr(ptr) {} | 123 Optional(T* ptr) : fPtr(ptr) {} |
| 115 ~Optional() { if (fPtr) fPtr->~T(); } | 124 ~Optional() { if (fPtr) fPtr->~T(); } |
| 116 | 125 |
| 117 operator T*() { return fPtr; } | 126 ACT_AS_PTR(fPtr); |
| 118 operator const T*() const { return fPtr; } | |
| 119 private: | 127 private: |
| 120 T* fPtr; | 128 T* fPtr; |
| 121 }; | 129 }; |
| 130 |
| 131 // Like Optional, but ptr must not be NULL. |
| 132 template <typename T> |
| 133 class Adopted : SkNoncopyable { |
| 134 public: |
| 135 Adopted(T* ptr) : fPtr(ptr) { SkASSERT(fPtr); } |
| 136 ~Adopted() { fPtr->~T(); } |
| 137 |
| 138 ACT_AS_PTR(fPtr); |
| 139 private: |
| 140 T* fPtr; |
| 141 }; |
| 122 | 142 |
| 123 // PODArray doesn't own the pointer's memory, and we assume the data is POD. | 143 // PODArray doesn't own the pointer's memory, and we assume the data is POD. |
| 124 template <typename T> | 144 template <typename T> |
| 125 class PODArray : SkNoncopyable { | 145 class PODArray : SkNoncopyable { |
| 126 public: | 146 public: |
| 127 PODArray(T* ptr) : fPtr(ptr) {} | 147 PODArray(T* ptr) : fPtr(ptr) {} |
| 128 | 148 |
| 129 operator T*() { return fPtr; } | 149 ACT_AS_PTR(fPtr); |
| 130 operator const T*() const { return fPtr; } | |
| 131 private: | 150 private: |
| 132 T* fPtr; | 151 T* fPtr; |
| 133 }; | 152 }; |
| 134 | 153 |
| 135 // Like SkBitmap, but deep copies pixels if they're not immutable. | 154 // Like SkBitmap, but deep copies pixels if they're not immutable. |
| 136 // Using this, we guarantee the immutability of all bitmaps we record. | 155 // Using this, we guarantee the immutability of all bitmaps we record. |
| 137 class ImmutableBitmap { | 156 class ImmutableBitmap { |
| 138 public: | 157 public: |
| 139 explicit ImmutableBitmap(const SkBitmap& bitmap) { | 158 explicit ImmutableBitmap(const SkBitmap& bitmap) { |
| 140 if (bitmap.isImmutable()) { | 159 if (bitmap.isImmutable()) { |
| 141 fBitmap = bitmap; | 160 fBitmap = bitmap; |
| 142 } else { | 161 } else { |
| 143 bitmap.copyTo(&fBitmap); | 162 bitmap.copyTo(&fBitmap); |
| 144 } | 163 } |
| 145 fBitmap.setImmutable(); | 164 fBitmap.setImmutable(); |
| 146 } | 165 } |
| 147 | 166 |
| 148 operator const SkBitmap& () const { return fBitmap; } | 167 operator const SkBitmap& () const { return fBitmap; } |
| 149 | 168 |
| 150 private: | 169 private: |
| 151 SkBitmap fBitmap; | 170 SkBitmap fBitmap; |
| 152 }; | 171 }; |
| 153 | 172 |
| 154 // None of these records manages the lifetimes of pointers, except for DrawVerti
ces handling its | 173 RECORD0(NoOp); |
| 155 // Xfermode specially. | |
| 156 | 174 |
| 157 RECORD0(Restore); | 175 RECORD0(Restore); |
| 158 RECORD1(Save, SkCanvas::SaveFlags, flags); | 176 RECORD1(Save, SkCanvas::SaveFlags, flags); |
| 159 RECORD3(SaveLayer, Optional<SkRect>, bounds, Optional<SkPaint>, paint, SkCanvas:
:SaveFlags, flags); | 177 RECORD3(SaveLayer, Optional<SkRect>, bounds, Optional<SkPaint>, paint, SkCanvas:
:SaveFlags, flags); |
| 160 | 178 |
| 161 static const unsigned kUnsetPopOffset = 0; | 179 RECORD1(PushCull, SkRect, rect); |
| 162 RECORD2(PushCull, SkRect, rect, unsigned, popOffset); | |
| 163 RECORD0(PopCull); | 180 RECORD0(PopCull); |
| 164 | 181 |
| 165 RECORD1(Concat, SkMatrix, matrix); | 182 RECORD1(Concat, SkMatrix, matrix); |
| 166 RECORD1(SetMatrix, SkMatrix, matrix); | 183 RECORD1(SetMatrix, SkMatrix, matrix); |
| 167 | 184 |
| 168 RECORD3(ClipPath, SkPath, path, SkRegion::Op, op, bool, doAA); | 185 RECORD3(ClipPath, SkPath, path, SkRegion::Op, op, bool, doAA); |
| 169 RECORD3(ClipRRect, SkRRect, rrect, SkRegion::Op, op, bool, doAA); | 186 RECORD3(ClipRRect, SkRRect, rrect, SkRegion::Op, op, bool, doAA); |
| 170 RECORD3(ClipRect, SkRect, rect, SkRegion::Op, op, bool, doAA); | 187 RECORD3(ClipRect, SkRect, rect, SkRegion::Op, op, bool, doAA); |
| 171 RECORD2(ClipRegion, SkRegion, region, SkRegion::Op, op); | 188 RECORD2(ClipRegion, SkRegion, region, SkRegion::Op, op); |
| 172 | 189 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 int vertexCount; | 257 int vertexCount; |
| 241 PODArray<SkPoint> vertices; | 258 PODArray<SkPoint> vertices; |
| 242 PODArray<SkPoint> texs; | 259 PODArray<SkPoint> texs; |
| 243 PODArray<SkColor> colors; | 260 PODArray<SkColor> colors; |
| 244 SkAutoTUnref<SkXfermode> xmode; | 261 SkAutoTUnref<SkXfermode> xmode; |
| 245 PODArray<uint16_t> indices; | 262 PODArray<uint16_t> indices; |
| 246 int indexCount; | 263 int indexCount; |
| 247 SkPaint paint; | 264 SkPaint paint; |
| 248 }; | 265 }; |
| 249 | 266 |
| 267 // Records added by optimizations. |
| 268 RECORD2(PairedPushCull, Adopted<PushCull>, base, unsigned, skip); |
| 269 RECORD3(BoundedDrawPosTextH, Adopted<DrawPosTextH>, base, SkScalar, minY, SkScal
ar, maxY); |
| 270 |
| 250 #undef RECORD0 | 271 #undef RECORD0 |
| 251 #undef RECORD1 | 272 #undef RECORD1 |
| 252 #undef RECORD2 | 273 #undef RECORD2 |
| 253 #undef RECORD3 | 274 #undef RECORD3 |
| 254 #undef RECORD4 | 275 #undef RECORD4 |
| 255 #undef RECORD5 | 276 #undef RECORD5 |
| 256 | 277 |
| 257 } // namespace SkRecords | 278 } // namespace SkRecords |
| 258 | 279 |
| 259 #endif//SkRecords_DEFINED | 280 #endif//SkRecords_DEFINED |
| OLD | NEW |