| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_PAINT_PAINT_OP_BUFFER_H_ | 5 #ifndef CC_PAINT_PAINT_OP_BUFFER_H_ |
| 6 #define CC_PAINT_PAINT_OP_BUFFER_H_ | 6 #define CC_PAINT_PAINT_OP_BUFFER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "cc/paint/paint_canvas.h" | 11 #include "cc/paint/paint_canvas.h" |
| 12 #include "cc/paint/paint_export.h" | 12 #include "cc/paint/paint_export.h" |
| 13 #include "cc/paint/paint_flags.h" | 13 #include "cc/paint/paint_flags.h" |
| 14 #include "third_party/skia/include/core/SkPicture.h" | 14 #include "third_party/skia/include/core/SkPicture.h" |
| 15 #include "third_party/skia/include/core/SkRect.h" | 15 #include "third_party/skia/include/core/SkRect.h" |
| 16 #include "third_party/skia/include/core/SkTextBlob.h" | 16 #include "third_party/skia/include/core/SkTextBlob.h" |
| 17 | 17 |
| 18 // PaintOpBuffer is a reimplementation of SkLiteDL. | 18 // PaintOpBuffer is a reimplementation of SkLiteDL. |
| 19 // See: third_party/skia/src/core/SkLiteDL.h. | 19 // See: third_party/skia/src/core/SkLiteDL.h. |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 | 22 |
| 23 class DisplayItemList; | 23 class DisplayItemList; |
| 24 | 24 |
| 25 class ThreadsafeMatrix : public SkMatrix { | 25 class CC_PAINT_EXPORT ThreadsafeMatrix : public SkMatrix { |
| 26 public: | 26 public: |
| 27 explicit ThreadsafeMatrix(const SkMatrix& matrix) : SkMatrix(matrix) { | 27 explicit ThreadsafeMatrix(const SkMatrix& matrix) : SkMatrix(matrix) { |
| 28 (void)getType(); | 28 (void)getType(); |
| 29 } | 29 } |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 class ThreadsafePath : public SkPath { | 32 class CC_PAINT_EXPORT ThreadsafePath : public SkPath { |
| 33 public: | 33 public: |
| 34 explicit ThreadsafePath(const SkPath& path) : SkPath(path) { | 34 explicit ThreadsafePath(const SkPath& path) : SkPath(path) { |
| 35 updateBoundsCache(); | 35 updateBoundsCache(); |
| 36 } | 36 } |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 enum class PaintOpType : uint8_t { | 39 enum class PaintOpType : uint8_t { |
| 40 Annotate, | 40 Annotate, |
| 41 ClipPath, | 41 ClipPath, |
| 42 ClipRect, | 42 ClipRect, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 size_t AdditionalBytesUsed() const { return 0; } | 90 size_t AdditionalBytesUsed() const { return 0; } |
| 91 | 91 |
| 92 static constexpr bool kIsDrawOp = false; | 92 static constexpr bool kIsDrawOp = false; |
| 93 // If an op has |kHasPaintFlags| set to true, it must: | 93 // If an op has |kHasPaintFlags| set to true, it must: |
| 94 // (1) Provide a PaintFlags member called |flags| | 94 // (1) Provide a PaintFlags member called |flags| |
| 95 // (2) Provide a RasterWithFlags function instead of a Raster function. | 95 // (2) Provide a RasterWithFlags function instead of a Raster function. |
| 96 static constexpr bool kHasPaintFlags = false; | 96 static constexpr bool kHasPaintFlags = false; |
| 97 static SkRect kUnsetRect; | 97 static SkRect kUnsetRect; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 struct PaintOpWithData : PaintOp { | 100 struct CC_PAINT_EXPORT PaintOpWithData : PaintOp { |
| 101 // Having data is just a helper for ops that have a varying amount of data and | 101 // Having data is just a helper for ops that have a varying amount of data and |
| 102 // want a way to store that inline. This is for ops that pass in a | 102 // want a way to store that inline. This is for ops that pass in a |
| 103 // void* and a length. | 103 // void* and a length. |
| 104 explicit PaintOpWithData(size_t bytes) : bytes(bytes) {} | 104 explicit PaintOpWithData(size_t bytes) : bytes(bytes) {} |
| 105 | 105 |
| 106 // Get data out by calling paint_op_data. This can't be part of the class | 106 // Get data out by calling paint_op_data. This can't be part of the class |
| 107 // because it needs to know the size of the derived type. | 107 // because it needs to know the size of the derived type. |
| 108 size_t bytes; | 108 size_t bytes; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 template <typename T> | 111 template <typename T> |
| 112 const void* paint_op_data(const T* op) { | 112 const void* paint_op_data(const T* op) { |
| 113 static_assert(std::is_convertible<T, PaintOpWithData>::value, | 113 static_assert(std::is_convertible<T, PaintOpWithData>::value, |
| 114 "T is not a PaintOpWithData"); | 114 "T is not a PaintOpWithData"); |
| 115 // Arbitrary data for a PaintOp is stored after the PaintOp itself | 115 // Arbitrary data for a PaintOp is stored after the PaintOp itself |
| 116 // in the PaintOpBuffer. Therefore, to access this data, it's | 116 // in the PaintOpBuffer. Therefore, to access this data, it's |
| 117 // pointer math to increment past the size of T. Accessing the | 117 // pointer math to increment past the size of T. Accessing the |
| 118 // next op in the buffer is ((char*)op) + op->skip, with the data | 118 // next op in the buffer is ((char*)op) + op->skip, with the data |
| 119 // fitting between. | 119 // fitting between. |
| 120 return op + 1; | 120 return op + 1; |
| 121 } | 121 } |
| 122 | 122 |
| 123 template <typename T> | 123 template <typename T> |
| 124 void* paint_op_data(T* op) { | 124 void* paint_op_data(T* op) { |
| 125 static_assert(std::is_convertible<T, PaintOpWithData>::value, | 125 static_assert(std::is_convertible<T, PaintOpWithData>::value, |
| 126 "T is not a PaintOpWithData"); | 126 "T is not a PaintOpWithData"); |
| 127 return op + 1; | 127 return op + 1; |
| 128 } | 128 } |
| 129 | 129 |
| 130 struct PaintOpWithDataArrayBase : PaintOpWithData { | 130 struct CC_PAINT_EXPORT PaintOpWithDataArrayBase : PaintOpWithData { |
| 131 // Helper class for static asserts in push functions. | 131 // Helper class for static asserts in push functions. |
| 132 using PaintOpWithData::PaintOpWithData; | 132 using PaintOpWithData::PaintOpWithData; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 template <typename T> | 135 template <typename T> |
| 136 struct PaintOpWithDataArray : PaintOpWithDataArrayBase { | 136 struct CC_PAINT_EXPORT PaintOpWithDataArray : PaintOpWithDataArrayBase { |
| 137 // Paint op that has a T[count] and a char[bytes]. | 137 // Paint op that has a T[count] and a char[bytes]. |
| 138 PaintOpWithDataArray(size_t bytes, size_t count) | 138 PaintOpWithDataArray(size_t bytes, size_t count) |
| 139 : PaintOpWithDataArrayBase(bytes), count(count) {} | 139 : PaintOpWithDataArrayBase(bytes), count(count) {} |
| 140 // Use paint_op_array to get array data. | 140 // Use paint_op_array to get array data. |
| 141 | 141 |
| 142 size_t count; | 142 size_t count; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 template <typename M, typename T> | 145 template <typename M, typename T> |
| 146 const M* paint_op_array(const T* op) { | 146 const M* paint_op_array(const T* op) { |
| 147 static_assert(std::is_convertible<T, PaintOpWithDataArrayBase>::value, | 147 static_assert(std::is_convertible<T, PaintOpWithDataArrayBase>::value, |
| 148 "T is not a PaintOpWithDataArray"); | 148 "T is not a PaintOpWithDataArray"); |
| 149 // See comment in paint_op_data. Array data is stored after | 149 // See comment in paint_op_data. Array data is stored after |
| 150 // any void* data. Memory layout here is: |op|data|array data|next op| | 150 // any void* data. Memory layout here is: |op|data|array data|next op| |
| 151 return SkTAddOffset<const M>(op + 1, op->bytes); | 151 return SkTAddOffset<const M>(op + 1, op->bytes); |
| 152 } | 152 } |
| 153 template <typename M, typename T> | 153 template <typename M, typename T> |
| 154 M* paint_op_array(T* op) { | 154 M* paint_op_array(T* op) { |
| 155 static_assert(std::is_convertible<T, PaintOpWithDataArrayBase>::value, | 155 static_assert(std::is_convertible<T, PaintOpWithDataArrayBase>::value, |
| 156 "T is not a PaintOpWithDataArray"); | 156 "T is not a PaintOpWithDataArray"); |
| 157 return SkTAddOffset<M>(op + 1, op->bytes); | 157 return SkTAddOffset<M>(op + 1, op->bytes); |
| 158 } | 158 } |
| 159 | 159 |
| 160 struct AnnotateOp final : PaintOp { | 160 struct CC_PAINT_EXPORT AnnotateOp final : PaintOp { |
| 161 enum class AnnotationType { | 161 enum class AnnotationType { |
| 162 URL, | 162 URL, |
| 163 LinkToDestination, | 163 LinkToDestination, |
| 164 NamedDestination, | 164 NamedDestination, |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 static constexpr PaintOpType kType = PaintOpType::Annotate; | 167 static constexpr PaintOpType kType = PaintOpType::Annotate; |
| 168 AnnotateOp(PaintCanvas::AnnotationType annotation_type, | 168 AnnotateOp(PaintCanvas::AnnotationType annotation_type, |
| 169 const SkRect& rect, | 169 const SkRect& rect, |
| 170 sk_sp<SkData> data); | 170 sk_sp<SkData> data); |
| 171 ~AnnotateOp(); | 171 ~AnnotateOp(); |
| 172 void Raster(SkCanvas* canvas) const; | 172 void Raster(SkCanvas* canvas) const; |
| 173 | 173 |
| 174 PaintCanvas::AnnotationType annotation_type; | 174 PaintCanvas::AnnotationType annotation_type; |
| 175 SkRect rect; | 175 SkRect rect; |
| 176 sk_sp<SkData> data; | 176 sk_sp<SkData> data; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 struct ClipPathOp final : PaintOp { | 179 struct CC_PAINT_EXPORT ClipPathOp final : PaintOp { |
| 180 static constexpr PaintOpType kType = PaintOpType::ClipPath; | 180 static constexpr PaintOpType kType = PaintOpType::ClipPath; |
| 181 ClipPathOp(SkPath path, SkClipOp op, bool antialias) | 181 ClipPathOp(SkPath path, SkClipOp op, bool antialias) |
| 182 : path(path), op(op), antialias(antialias) {} | 182 : path(path), op(op), antialias(antialias) {} |
| 183 void Raster(SkCanvas* canvas) const; | 183 void Raster(SkCanvas* canvas) const; |
| 184 int CountSlowPaths() const; | 184 int CountSlowPaths() const; |
| 185 | 185 |
| 186 ThreadsafePath path; | 186 ThreadsafePath path; |
| 187 SkClipOp op; | 187 SkClipOp op; |
| 188 bool antialias; | 188 bool antialias; |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 struct ClipRectOp final : PaintOp { | 191 struct CC_PAINT_EXPORT ClipRectOp final : PaintOp { |
| 192 static constexpr PaintOpType kType = PaintOpType::ClipRect; | 192 static constexpr PaintOpType kType = PaintOpType::ClipRect; |
| 193 ClipRectOp(const SkRect& rect, SkClipOp op, bool antialias) | 193 ClipRectOp(const SkRect& rect, SkClipOp op, bool antialias) |
| 194 : rect(rect), op(op), antialias(antialias) {} | 194 : rect(rect), op(op), antialias(antialias) {} |
| 195 void Raster(SkCanvas* canvas) const; | 195 void Raster(SkCanvas* canvas) const; |
| 196 | 196 |
| 197 SkRect rect; | 197 SkRect rect; |
| 198 SkClipOp op; | 198 SkClipOp op; |
| 199 bool antialias; | 199 bool antialias; |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 struct ClipRRectOp final : PaintOp { | 202 struct CC_PAINT_EXPORT ClipRRectOp final : PaintOp { |
| 203 static constexpr PaintOpType kType = PaintOpType::ClipRRect; | 203 static constexpr PaintOpType kType = PaintOpType::ClipRRect; |
| 204 ClipRRectOp(const SkRRect& rrect, SkClipOp op, bool antialias) | 204 ClipRRectOp(const SkRRect& rrect, SkClipOp op, bool antialias) |
| 205 : rrect(rrect), op(op), antialias(antialias) {} | 205 : rrect(rrect), op(op), antialias(antialias) {} |
| 206 void Raster(SkCanvas* canvas) const; | 206 void Raster(SkCanvas* canvas) const; |
| 207 | 207 |
| 208 SkRRect rrect; | 208 SkRRect rrect; |
| 209 SkClipOp op; | 209 SkClipOp op; |
| 210 bool antialias; | 210 bool antialias; |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 struct ConcatOp final : PaintOp { | 213 struct CC_PAINT_EXPORT ConcatOp final : PaintOp { |
| 214 static constexpr PaintOpType kType = PaintOpType::Concat; | 214 static constexpr PaintOpType kType = PaintOpType::Concat; |
| 215 explicit ConcatOp(const SkMatrix& matrix) : matrix(matrix) {} | 215 explicit ConcatOp(const SkMatrix& matrix) : matrix(matrix) {} |
| 216 void Raster(SkCanvas* canvas) const; | 216 void Raster(SkCanvas* canvas) const; |
| 217 | 217 |
| 218 ThreadsafeMatrix matrix; | 218 ThreadsafeMatrix matrix; |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 struct DrawArcOp final : PaintOp { | 221 struct CC_PAINT_EXPORT DrawArcOp final : PaintOp { |
| 222 static constexpr PaintOpType kType = PaintOpType::DrawArc; | 222 static constexpr PaintOpType kType = PaintOpType::DrawArc; |
| 223 static constexpr bool kIsDrawOp = true; | 223 static constexpr bool kIsDrawOp = true; |
| 224 static constexpr bool kHasPaintFlags = true; | 224 static constexpr bool kHasPaintFlags = true; |
| 225 DrawArcOp(const SkRect& oval, | 225 DrawArcOp(const SkRect& oval, |
| 226 SkScalar start_angle, | 226 SkScalar start_angle, |
| 227 SkScalar sweep_angle, | 227 SkScalar sweep_angle, |
| 228 bool use_center, | 228 bool use_center, |
| 229 const PaintFlags& flags) | 229 const PaintFlags& flags) |
| 230 : oval(oval), | 230 : oval(oval), |
| 231 start_angle(start_angle), | 231 start_angle(start_angle), |
| 232 sweep_angle(sweep_angle), | 232 sweep_angle(sweep_angle), |
| 233 use_center(use_center), | 233 use_center(use_center), |
| 234 flags(flags) {} | 234 flags(flags) {} |
| 235 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 235 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 236 | 236 |
| 237 SkRect oval; | 237 SkRect oval; |
| 238 SkScalar start_angle; | 238 SkScalar start_angle; |
| 239 SkScalar sweep_angle; | 239 SkScalar sweep_angle; |
| 240 bool use_center; | 240 bool use_center; |
| 241 PaintFlags flags; | 241 PaintFlags flags; |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 struct DrawCircleOp final : PaintOp { | 244 struct CC_PAINT_EXPORT DrawCircleOp final : PaintOp { |
| 245 static constexpr PaintOpType kType = PaintOpType::DrawCircle; | 245 static constexpr PaintOpType kType = PaintOpType::DrawCircle; |
| 246 static constexpr bool kIsDrawOp = true; | 246 static constexpr bool kIsDrawOp = true; |
| 247 static constexpr bool kHasPaintFlags = true; | 247 static constexpr bool kHasPaintFlags = true; |
| 248 DrawCircleOp(SkScalar cx, | 248 DrawCircleOp(SkScalar cx, |
| 249 SkScalar cy, | 249 SkScalar cy, |
| 250 SkScalar radius, | 250 SkScalar radius, |
| 251 const PaintFlags& flags) | 251 const PaintFlags& flags) |
| 252 : cx(cx), cy(cy), radius(radius), flags(flags) {} | 252 : cx(cx), cy(cy), radius(radius), flags(flags) {} |
| 253 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 253 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 254 | 254 |
| 255 SkScalar cx; | 255 SkScalar cx; |
| 256 SkScalar cy; | 256 SkScalar cy; |
| 257 SkScalar radius; | 257 SkScalar radius; |
| 258 PaintFlags flags; | 258 PaintFlags flags; |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 struct DrawColorOp final : PaintOp { | 261 struct CC_PAINT_EXPORT DrawColorOp final : PaintOp { |
| 262 static constexpr PaintOpType kType = PaintOpType::DrawColor; | 262 static constexpr PaintOpType kType = PaintOpType::DrawColor; |
| 263 static constexpr bool kIsDrawOp = true; | 263 static constexpr bool kIsDrawOp = true; |
| 264 DrawColorOp(SkColor color, SkBlendMode mode) : color(color), mode(mode) {} | 264 DrawColorOp(SkColor color, SkBlendMode mode) : color(color), mode(mode) {} |
| 265 void Raster(SkCanvas* canvas) const; | 265 void Raster(SkCanvas* canvas) const; |
| 266 | 266 |
| 267 SkColor color; | 267 SkColor color; |
| 268 SkBlendMode mode; | 268 SkBlendMode mode; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 struct DrawDisplayItemListOp final : PaintOp { | 271 struct CC_PAINT_EXPORT DrawDisplayItemListOp final : PaintOp { |
| 272 static constexpr PaintOpType kType = PaintOpType::DrawDisplayItemList; | 272 static constexpr PaintOpType kType = PaintOpType::DrawDisplayItemList; |
| 273 static constexpr bool kIsDrawOp = true; | 273 static constexpr bool kIsDrawOp = true; |
| 274 explicit DrawDisplayItemListOp(scoped_refptr<DisplayItemList> list); | 274 explicit DrawDisplayItemListOp(scoped_refptr<DisplayItemList> list); |
| 275 // Windows wants to generate these when types are exported, so |
| 276 // provide them here explicitly so that DisplayItemList doesn't have |
| 277 // to be defined in this header. |
| 278 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); |
| 279 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); |
| 275 ~DrawDisplayItemListOp(); | 280 ~DrawDisplayItemListOp(); |
| 276 void Raster(SkCanvas* canvas) const; | 281 void Raster(SkCanvas* canvas) const; |
| 277 size_t AdditionalBytesUsed() const; | 282 size_t AdditionalBytesUsed() const; |
| 278 // TODO(enne): DisplayItemList should know number of slow paths. | 283 // TODO(enne): DisplayItemList should know number of slow paths. |
| 279 | 284 |
| 280 scoped_refptr<DisplayItemList> list; | 285 scoped_refptr<DisplayItemList> list; |
| 281 }; | 286 }; |
| 282 | 287 |
| 283 struct DrawDRRectOp final : PaintOp { | 288 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOp { |
| 284 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; | 289 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; |
| 285 static constexpr bool kIsDrawOp = true; | 290 static constexpr bool kIsDrawOp = true; |
| 286 static constexpr bool kHasPaintFlags = true; | 291 static constexpr bool kHasPaintFlags = true; |
| 287 DrawDRRectOp(const SkRRect& outer, | 292 DrawDRRectOp(const SkRRect& outer, |
| 288 const SkRRect& inner, | 293 const SkRRect& inner, |
| 289 const PaintFlags& flags) | 294 const PaintFlags& flags) |
| 290 : outer(outer), inner(inner), flags(flags) {} | 295 : outer(outer), inner(inner), flags(flags) {} |
| 291 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 296 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 292 | 297 |
| 293 SkRRect outer; | 298 SkRRect outer; |
| 294 SkRRect inner; | 299 SkRRect inner; |
| 295 PaintFlags flags; | 300 PaintFlags flags; |
| 296 }; | 301 }; |
| 297 | 302 |
| 298 struct DrawImageOp final : PaintOp { | 303 struct CC_PAINT_EXPORT DrawImageOp final : PaintOp { |
| 299 static constexpr PaintOpType kType = PaintOpType::DrawImage; | 304 static constexpr PaintOpType kType = PaintOpType::DrawImage; |
| 300 static constexpr bool kIsDrawOp = true; | 305 static constexpr bool kIsDrawOp = true; |
| 301 static constexpr bool kHasPaintFlags = true; | 306 static constexpr bool kHasPaintFlags = true; |
| 302 DrawImageOp(const PaintImage& image, | 307 DrawImageOp(const PaintImage& image, |
| 303 SkScalar left, | 308 SkScalar left, |
| 304 SkScalar top, | 309 SkScalar top, |
| 305 const PaintFlags* flags); | 310 const PaintFlags* flags); |
| 306 ~DrawImageOp(); | 311 ~DrawImageOp(); |
| 307 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 312 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 308 | 313 |
| 309 PaintImage image; | 314 PaintImage image; |
| 310 SkScalar left; | 315 SkScalar left; |
| 311 SkScalar top; | 316 SkScalar top; |
| 312 PaintFlags flags; | 317 PaintFlags flags; |
| 313 }; | 318 }; |
| 314 | 319 |
| 315 struct DrawImageRectOp final : PaintOp { | 320 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOp { |
| 316 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; | 321 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; |
| 317 static constexpr bool kIsDrawOp = true; | 322 static constexpr bool kIsDrawOp = true; |
| 318 static constexpr bool kHasPaintFlags = true; | 323 static constexpr bool kHasPaintFlags = true; |
| 319 DrawImageRectOp(const PaintImage& image, | 324 DrawImageRectOp(const PaintImage& image, |
| 320 const SkRect& src, | 325 const SkRect& src, |
| 321 const SkRect& dst, | 326 const SkRect& dst, |
| 322 const PaintFlags* flags, | 327 const PaintFlags* flags, |
| 323 PaintCanvas::SrcRectConstraint constraint); | 328 PaintCanvas::SrcRectConstraint constraint); |
| 324 ~DrawImageRectOp(); | 329 ~DrawImageRectOp(); |
| 325 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 330 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 326 | 331 |
| 327 PaintImage image; | 332 PaintImage image; |
| 328 PaintFlags flags; | 333 PaintFlags flags; |
| 329 SkRect src; | 334 SkRect src; |
| 330 SkRect dst; | 335 SkRect dst; |
| 331 PaintCanvas::SrcRectConstraint constraint; | 336 PaintCanvas::SrcRectConstraint constraint; |
| 332 }; | 337 }; |
| 333 | 338 |
| 334 struct DrawIRectOp final : PaintOp { | 339 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOp { |
| 335 static constexpr PaintOpType kType = PaintOpType::DrawIRect; | 340 static constexpr PaintOpType kType = PaintOpType::DrawIRect; |
| 336 static constexpr bool kIsDrawOp = true; | 341 static constexpr bool kIsDrawOp = true; |
| 337 static constexpr bool kHasPaintFlags = true; | 342 static constexpr bool kHasPaintFlags = true; |
| 338 DrawIRectOp(const SkIRect& rect, const PaintFlags& flags) | 343 DrawIRectOp(const SkIRect& rect, const PaintFlags& flags) |
| 339 : rect(rect), flags(flags) {} | 344 : rect(rect), flags(flags) {} |
| 340 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 345 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 341 | 346 |
| 342 SkIRect rect; | 347 SkIRect rect; |
| 343 PaintFlags flags; | 348 PaintFlags flags; |
| 344 }; | 349 }; |
| 345 | 350 |
| 346 struct DrawLineOp final : PaintOp { | 351 struct CC_PAINT_EXPORT DrawLineOp final : PaintOp { |
| 347 static constexpr PaintOpType kType = PaintOpType::DrawLine; | 352 static constexpr PaintOpType kType = PaintOpType::DrawLine; |
| 348 static constexpr bool kIsDrawOp = true; | 353 static constexpr bool kIsDrawOp = true; |
| 349 static constexpr bool kHasPaintFlags = true; | 354 static constexpr bool kHasPaintFlags = true; |
| 350 DrawLineOp(SkScalar x0, | 355 DrawLineOp(SkScalar x0, |
| 351 SkScalar y0, | 356 SkScalar y0, |
| 352 SkScalar x1, | 357 SkScalar x1, |
| 353 SkScalar y1, | 358 SkScalar y1, |
| 354 const PaintFlags& flags) | 359 const PaintFlags& flags) |
| 355 : x0(x0), y0(y0), x1(x1), y1(y1), flags(flags) {} | 360 : x0(x0), y0(y0), x1(x1), y1(y1), flags(flags) {} |
| 356 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 361 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 357 int CountSlowPaths() const; | 362 int CountSlowPaths() const; |
| 358 | 363 |
| 359 SkScalar x0; | 364 SkScalar x0; |
| 360 SkScalar y0; | 365 SkScalar y0; |
| 361 SkScalar x1; | 366 SkScalar x1; |
| 362 SkScalar y1; | 367 SkScalar y1; |
| 363 PaintFlags flags; | 368 PaintFlags flags; |
| 364 }; | 369 }; |
| 365 | 370 |
| 366 struct DrawOvalOp final : PaintOp { | 371 struct CC_PAINT_EXPORT DrawOvalOp final : PaintOp { |
| 367 static constexpr PaintOpType kType = PaintOpType::DrawOval; | 372 static constexpr PaintOpType kType = PaintOpType::DrawOval; |
| 368 static constexpr bool kIsDrawOp = true; | 373 static constexpr bool kIsDrawOp = true; |
| 369 static constexpr bool kHasPaintFlags = true; | 374 static constexpr bool kHasPaintFlags = true; |
| 370 DrawOvalOp(const SkRect& oval, const PaintFlags& flags) | 375 DrawOvalOp(const SkRect& oval, const PaintFlags& flags) |
| 371 : oval(oval), flags(flags) {} | 376 : oval(oval), flags(flags) {} |
| 372 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 377 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 373 | 378 |
| 374 SkRect oval; | 379 SkRect oval; |
| 375 PaintFlags flags; | 380 PaintFlags flags; |
| 376 }; | 381 }; |
| 377 | 382 |
| 378 struct DrawPathOp final : PaintOp { | 383 struct CC_PAINT_EXPORT DrawPathOp final : PaintOp { |
| 379 static constexpr PaintOpType kType = PaintOpType::DrawPath; | 384 static constexpr PaintOpType kType = PaintOpType::DrawPath; |
| 380 static constexpr bool kIsDrawOp = true; | 385 static constexpr bool kIsDrawOp = true; |
| 381 static constexpr bool kHasPaintFlags = true; | 386 static constexpr bool kHasPaintFlags = true; |
| 382 DrawPathOp(const SkPath& path, const PaintFlags& flags) | 387 DrawPathOp(const SkPath& path, const PaintFlags& flags) |
| 383 : path(path), flags(flags) {} | 388 : path(path), flags(flags) {} |
| 384 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 389 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 385 int CountSlowPaths() const; | 390 int CountSlowPaths() const; |
| 386 | 391 |
| 387 ThreadsafePath path; | 392 ThreadsafePath path; |
| 388 PaintFlags flags; | 393 PaintFlags flags; |
| 389 }; | 394 }; |
| 390 | 395 |
| 391 struct DrawPosTextOp final : PaintOpWithDataArray<SkPoint> { | 396 struct CC_PAINT_EXPORT DrawPosTextOp final : PaintOpWithDataArray<SkPoint> { |
| 392 static constexpr PaintOpType kType = PaintOpType::DrawPosText; | 397 static constexpr PaintOpType kType = PaintOpType::DrawPosText; |
| 393 static constexpr bool kIsDrawOp = true; | 398 static constexpr bool kIsDrawOp = true; |
| 394 static constexpr bool kHasPaintFlags = true; | 399 static constexpr bool kHasPaintFlags = true; |
| 395 DrawPosTextOp(size_t bytes, size_t count, const PaintFlags& flags); | 400 DrawPosTextOp(size_t bytes, size_t count, const PaintFlags& flags); |
| 396 ~DrawPosTextOp(); | 401 ~DrawPosTextOp(); |
| 397 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 402 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 398 | 403 |
| 399 PaintFlags flags; | 404 PaintFlags flags; |
| 400 }; | 405 }; |
| 401 | 406 |
| 402 struct DrawRecordOp final : PaintOp { | 407 struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp { |
| 403 static constexpr PaintOpType kType = PaintOpType::DrawRecord; | 408 static constexpr PaintOpType kType = PaintOpType::DrawRecord; |
| 404 static constexpr bool kIsDrawOp = true; | 409 static constexpr bool kIsDrawOp = true; |
| 405 explicit DrawRecordOp(sk_sp<const PaintRecord> record); | 410 explicit DrawRecordOp(sk_sp<const PaintRecord> record); |
| 406 ~DrawRecordOp(); | 411 ~DrawRecordOp(); |
| 407 void Raster(SkCanvas* canvas) const; | 412 void Raster(SkCanvas* canvas) const; |
| 408 size_t AdditionalBytesUsed() const; | 413 size_t AdditionalBytesUsed() const; |
| 409 | 414 |
| 410 sk_sp<const PaintRecord> record; | 415 sk_sp<const PaintRecord> record; |
| 411 }; | 416 }; |
| 412 | 417 |
| 413 struct DrawRectOp final : PaintOp { | 418 struct CC_PAINT_EXPORT DrawRectOp final : PaintOp { |
| 414 static constexpr PaintOpType kType = PaintOpType::DrawRect; | 419 static constexpr PaintOpType kType = PaintOpType::DrawRect; |
| 415 static constexpr bool kIsDrawOp = true; | 420 static constexpr bool kIsDrawOp = true; |
| 416 static constexpr bool kHasPaintFlags = true; | 421 static constexpr bool kHasPaintFlags = true; |
| 417 DrawRectOp(const SkRect& rect, const PaintFlags& flags) | 422 DrawRectOp(const SkRect& rect, const PaintFlags& flags) |
| 418 : rect(rect), flags(flags) {} | 423 : rect(rect), flags(flags) {} |
| 419 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 424 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 420 | 425 |
| 421 SkRect rect; | 426 SkRect rect; |
| 422 PaintFlags flags; | 427 PaintFlags flags; |
| 423 }; | 428 }; |
| 424 | 429 |
| 425 struct DrawRRectOp final : PaintOp { | 430 struct CC_PAINT_EXPORT DrawRRectOp final : PaintOp { |
| 426 static constexpr PaintOpType kType = PaintOpType::DrawRRect; | 431 static constexpr PaintOpType kType = PaintOpType::DrawRRect; |
| 427 static constexpr bool kIsDrawOp = true; | 432 static constexpr bool kIsDrawOp = true; |
| 428 static constexpr bool kHasPaintFlags = true; | 433 static constexpr bool kHasPaintFlags = true; |
| 429 DrawRRectOp(const SkRRect& rrect, const PaintFlags& flags) | 434 DrawRRectOp(const SkRRect& rrect, const PaintFlags& flags) |
| 430 : rrect(rrect), flags(flags) {} | 435 : rrect(rrect), flags(flags) {} |
| 431 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 436 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 432 | 437 |
| 433 SkRRect rrect; | 438 SkRRect rrect; |
| 434 PaintFlags flags; | 439 PaintFlags flags; |
| 435 }; | 440 }; |
| 436 | 441 |
| 437 struct DrawTextOp final : PaintOpWithData { | 442 struct CC_PAINT_EXPORT DrawTextOp final : PaintOpWithData { |
| 438 static constexpr PaintOpType kType = PaintOpType::DrawText; | 443 static constexpr PaintOpType kType = PaintOpType::DrawText; |
| 439 static constexpr bool kIsDrawOp = true; | 444 static constexpr bool kIsDrawOp = true; |
| 440 static constexpr bool kHasPaintFlags = true; | 445 static constexpr bool kHasPaintFlags = true; |
| 441 DrawTextOp(size_t bytes, SkScalar x, SkScalar y, const PaintFlags& flags) | 446 DrawTextOp(size_t bytes, SkScalar x, SkScalar y, const PaintFlags& flags) |
| 442 : PaintOpWithData(bytes), x(x), y(y), flags(flags) {} | 447 : PaintOpWithData(bytes), x(x), y(y), flags(flags) {} |
| 443 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 448 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 444 | 449 |
| 445 SkScalar x; | 450 SkScalar x; |
| 446 SkScalar y; | 451 SkScalar y; |
| 447 PaintFlags flags; | 452 PaintFlags flags; |
| 448 }; | 453 }; |
| 449 | 454 |
| 450 struct DrawTextBlobOp final : PaintOp { | 455 struct CC_PAINT_EXPORT DrawTextBlobOp final : PaintOp { |
| 451 static constexpr PaintOpType kType = PaintOpType::DrawTextBlob; | 456 static constexpr PaintOpType kType = PaintOpType::DrawTextBlob; |
| 452 static constexpr bool kIsDrawOp = true; | 457 static constexpr bool kIsDrawOp = true; |
| 453 static constexpr bool kHasPaintFlags = true; | 458 static constexpr bool kHasPaintFlags = true; |
| 454 DrawTextBlobOp(sk_sp<SkTextBlob> blob, | 459 DrawTextBlobOp(sk_sp<SkTextBlob> blob, |
| 455 SkScalar x, | 460 SkScalar x, |
| 456 SkScalar y, | 461 SkScalar y, |
| 457 const PaintFlags& flags); | 462 const PaintFlags& flags); |
| 458 ~DrawTextBlobOp(); | 463 ~DrawTextBlobOp(); |
| 459 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 464 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 460 | 465 |
| 461 sk_sp<SkTextBlob> blob; | 466 sk_sp<SkTextBlob> blob; |
| 462 SkScalar x; | 467 SkScalar x; |
| 463 SkScalar y; | 468 SkScalar y; |
| 464 PaintFlags flags; | 469 PaintFlags flags; |
| 465 }; | 470 }; |
| 466 | 471 |
| 467 struct NoopOp final : PaintOp { | 472 struct CC_PAINT_EXPORT NoopOp final : PaintOp { |
| 468 static constexpr PaintOpType kType = PaintOpType::Noop; | 473 static constexpr PaintOpType kType = PaintOpType::Noop; |
| 469 void Raster(SkCanvas* canvas) const {} | 474 void Raster(SkCanvas* canvas) const {} |
| 470 }; | 475 }; |
| 471 | 476 |
| 472 struct RestoreOp final : PaintOp { | 477 struct CC_PAINT_EXPORT RestoreOp final : PaintOp { |
| 473 static constexpr PaintOpType kType = PaintOpType::Restore; | 478 static constexpr PaintOpType kType = PaintOpType::Restore; |
| 474 void Raster(SkCanvas* canvas) const; | 479 void Raster(SkCanvas* canvas) const; |
| 475 }; | 480 }; |
| 476 | 481 |
| 477 struct RotateOp final : PaintOp { | 482 struct CC_PAINT_EXPORT RotateOp final : PaintOp { |
| 478 static constexpr PaintOpType kType = PaintOpType::Rotate; | 483 static constexpr PaintOpType kType = PaintOpType::Rotate; |
| 479 explicit RotateOp(SkScalar degrees) : degrees(degrees) {} | 484 explicit RotateOp(SkScalar degrees) : degrees(degrees) {} |
| 480 void Raster(SkCanvas* canvas) const; | 485 void Raster(SkCanvas* canvas) const; |
| 481 | 486 |
| 482 SkScalar degrees; | 487 SkScalar degrees; |
| 483 }; | 488 }; |
| 484 | 489 |
| 485 struct SaveOp final : PaintOp { | 490 struct CC_PAINT_EXPORT SaveOp final : PaintOp { |
| 486 static constexpr PaintOpType kType = PaintOpType::Save; | 491 static constexpr PaintOpType kType = PaintOpType::Save; |
| 487 void Raster(SkCanvas* canvas) const; | 492 void Raster(SkCanvas* canvas) const; |
| 488 }; | 493 }; |
| 489 | 494 |
| 490 struct SaveLayerOp final : PaintOp { | 495 struct CC_PAINT_EXPORT SaveLayerOp final : PaintOp { |
| 491 static constexpr PaintOpType kType = PaintOpType::SaveLayer; | 496 static constexpr PaintOpType kType = PaintOpType::SaveLayer; |
| 492 static constexpr bool kHasPaintFlags = true; | 497 static constexpr bool kHasPaintFlags = true; |
| 493 SaveLayerOp(const SkRect* bounds, const PaintFlags* flags) | 498 SaveLayerOp(const SkRect* bounds, const PaintFlags* flags) |
| 494 : bounds(bounds ? *bounds : kUnsetRect) { | 499 : bounds(bounds ? *bounds : kUnsetRect) { |
| 495 if (flags) | 500 if (flags) |
| 496 this->flags = *flags; | 501 this->flags = *flags; |
| 497 } | 502 } |
| 498 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; | 503 void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
| 499 | 504 |
| 500 SkRect bounds; | 505 SkRect bounds; |
| 501 PaintFlags flags; | 506 PaintFlags flags; |
| 502 }; | 507 }; |
| 503 | 508 |
| 504 struct SaveLayerAlphaOp final : PaintOp { | 509 struct CC_PAINT_EXPORT SaveLayerAlphaOp final : PaintOp { |
| 505 static constexpr PaintOpType kType = PaintOpType::SaveLayerAlpha; | 510 static constexpr PaintOpType kType = PaintOpType::SaveLayerAlpha; |
| 506 SaveLayerAlphaOp(const SkRect* bounds, uint8_t alpha) | 511 SaveLayerAlphaOp(const SkRect* bounds, uint8_t alpha) |
| 507 : bounds(bounds ? *bounds : kUnsetRect), alpha(alpha) {} | 512 : bounds(bounds ? *bounds : kUnsetRect), alpha(alpha) {} |
| 508 void Raster(SkCanvas* canvas) const; | 513 void Raster(SkCanvas* canvas) const; |
| 509 | 514 |
| 510 SkRect bounds; | 515 SkRect bounds; |
| 511 uint8_t alpha; | 516 uint8_t alpha; |
| 512 }; | 517 }; |
| 513 | 518 |
| 514 struct ScaleOp final : PaintOp { | 519 struct CC_PAINT_EXPORT ScaleOp final : PaintOp { |
| 515 static constexpr PaintOpType kType = PaintOpType::Scale; | 520 static constexpr PaintOpType kType = PaintOpType::Scale; |
| 516 ScaleOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} | 521 ScaleOp(SkScalar sx, SkScalar sy) : sx(sx), sy(sy) {} |
| 517 void Raster(SkCanvas* canvas) const; | 522 void Raster(SkCanvas* canvas) const; |
| 518 | 523 |
| 519 SkScalar sx; | 524 SkScalar sx; |
| 520 SkScalar sy; | 525 SkScalar sy; |
| 521 }; | 526 }; |
| 522 | 527 |
| 523 struct SetMatrixOp final : PaintOp { | 528 struct CC_PAINT_EXPORT SetMatrixOp final : PaintOp { |
| 524 static constexpr PaintOpType kType = PaintOpType::SetMatrix; | 529 static constexpr PaintOpType kType = PaintOpType::SetMatrix; |
| 525 explicit SetMatrixOp(const SkMatrix& matrix) : matrix(matrix) {} | 530 explicit SetMatrixOp(const SkMatrix& matrix) : matrix(matrix) {} |
| 526 // This is the only op that needs the original ctm of the SkCanvas | 531 // This is the only op that needs the original ctm of the SkCanvas |
| 527 // used for raster (since SetMatrix is relative to the recording origin and | 532 // used for raster (since SetMatrix is relative to the recording origin and |
| 528 // shouldn't clobber the SkCanvas raster origin). | 533 // shouldn't clobber the SkCanvas raster origin). |
| 529 // | 534 // |
| 530 // TODO(enne): Find some cleaner way to do this, possibly by making | 535 // TODO(enne): Find some cleaner way to do this, possibly by making |
| 531 // all SetMatrix calls Concat?? | 536 // all SetMatrix calls Concat?? |
| 532 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; | 537 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; |
| 533 | 538 |
| 534 ThreadsafeMatrix matrix; | 539 ThreadsafeMatrix matrix; |
| 535 }; | 540 }; |
| 536 | 541 |
| 537 struct TranslateOp final : PaintOp { | 542 struct CC_PAINT_EXPORT TranslateOp final : PaintOp { |
| 538 static constexpr PaintOpType kType = PaintOpType::Translate; | 543 static constexpr PaintOpType kType = PaintOpType::Translate; |
| 539 TranslateOp(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {} | 544 TranslateOp(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {} |
| 540 void Raster(SkCanvas* canvas) const; | 545 void Raster(SkCanvas* canvas) const; |
| 541 | 546 |
| 542 SkScalar dx; | 547 SkScalar dx; |
| 543 SkScalar dy; | 548 SkScalar dy; |
| 544 }; | 549 }; |
| 545 | 550 |
| 546 using LargestPaintOp = DrawDRRectOp; | 551 using LargestPaintOp = DrawDRRectOp; |
| 547 | 552 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 // Record additional bytes used by referenced sub-records and display lists. | 778 // Record additional bytes used by referenced sub-records and display lists. |
| 774 size_t subrecord_bytes_used_ = 0; | 779 size_t subrecord_bytes_used_ = 0; |
| 775 SkRect cull_rect_; | 780 SkRect cull_rect_; |
| 776 | 781 |
| 777 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); | 782 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); |
| 778 }; | 783 }; |
| 779 | 784 |
| 780 } // namespace cc | 785 } // namespace cc |
| 781 | 786 |
| 782 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ | 787 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ |
| OLD | NEW |