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_SHADER_H_ | 5 #ifndef CC_PAINT_PAINT_SHADER_H_ |
6 #define CC_PAINT_PAINT_SHADER_H_ | 6 #define CC_PAINT_PAINT_SHADER_H_ |
7 | 7 |
8 #include "cc/paint/paint_record.h" | 8 #include "cc/paint/paint_export.h" |
9 #include "third_party/skia/include/core/SkImage.h" | 9 #include "third_party/skia/include/core/SkImage.h" |
| 10 #include "third_party/skia/include/core/SkScalar.h" |
10 #include "third_party/skia/include/core/SkShader.h" | 11 #include "third_party/skia/include/core/SkShader.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 using PaintShader = SkShader; | |
14 | 14 |
15 inline sk_sp<PaintShader> WrapSkShader(sk_sp<SkShader> shader) { | 15 class PaintOpBuffer; |
16 return shader; | 16 using PaintRecord = PaintOpBuffer; |
17 } | |
18 | 17 |
19 inline sk_sp<PaintShader> MakePaintShaderImage(sk_sp<const SkImage> image, | 18 class CC_PAINT_EXPORT PaintShader { |
20 SkShader::TileMode tx, | 19 public: |
21 SkShader::TileMode ty, | 20 // Creates a color shader. See SkShader::MakeColorShader. |
22 const SkMatrix* local_matrix) { | 21 explicit PaintShader(SkColor color); |
23 return image->makeShader(tx, ty, local_matrix); | 22 // Creates a linear gradient shader. See SkGradientShader::MakeLinear. |
24 } | 23 PaintShader(const SkPoint points[], |
| 24 const SkColor colors[], |
| 25 const SkScalar pos[], |
| 26 int count, |
| 27 SkShader::TileMode mode, |
| 28 uint32_t flags = 0, |
| 29 const SkMatrix* local_matrix = nullptr); |
| 30 // Creates a radial gradient shader. See SkGradientShader::MakeRadial |
| 31 PaintShader(const SkPoint& center, |
| 32 SkScalar radius, |
| 33 const SkColor colors[], |
| 34 const SkScalar pos[], |
| 35 int color_count, |
| 36 SkShader::TileMode mode, |
| 37 uint32_t flags = 0, |
| 38 const SkMatrix* local_matrix = nullptr); |
| 39 // Creates a two point conical gradient shader. See |
| 40 // SkGradientShader::MakeTwoPointConical. |
| 41 PaintShader(const SkPoint& start, |
| 42 SkScalar start_radius, |
| 43 const SkPoint& end, |
| 44 SkScalar end_radius, |
| 45 const SkColor colors[], |
| 46 const SkScalar pos[], |
| 47 int color_count, |
| 48 SkShader::TileMode mode, |
| 49 uint32_t flags, |
| 50 const SkMatrix* local_matrix); |
| 51 // Creates a sweep gradient shader. See SkGradientShader::MakeSweep. |
| 52 PaintShader(SkScalar cx, |
| 53 SkScalar cy, |
| 54 const SkColor colors[], |
| 55 const SkScalar pos[], |
| 56 int color_count, |
| 57 uint32_t flags, |
| 58 const SkMatrix* local_matrix); |
| 59 // Creates an image shader. See SkImage::makeShader. |
| 60 PaintShader(sk_sp<const SkImage> image, |
| 61 SkShader::TileMode tx, |
| 62 SkShader::TileMode ty, |
| 63 const SkMatrix* local_matrix); |
| 64 // Creates a picture shader. See SkShader::MakePictureShader. |
| 65 PaintShader(sk_sp<PaintRecord> record, |
| 66 SkShader::TileMode tx, |
| 67 SkShader::TileMode ty, |
| 68 const SkMatrix* local_matrix, |
| 69 const SkRect* tile); |
| 70 PaintShader(const PaintShader& other); |
| 71 PaintShader(PaintShader&& other); |
| 72 ~PaintShader(); |
25 | 73 |
26 inline sk_sp<PaintShader> MakePaintShaderRecord(sk_sp<PaintRecord> record, | 74 // TODO(vmpstr): Can we always determine this without constructing an |
27 SkShader::TileMode tx, | 75 // |sk_shader_|? |
28 SkShader::TileMode ty, | 76 bool is_valid() const { return !!sk_shader_; } |
29 const SkMatrix* local_matrix, | 77 const sk_sp<SkShader>& sk_shader() const { return sk_shader_; } |
30 const SkRect* tile) { | 78 |
31 return SkShader::MakePictureShader(ToSkPicture(record), tx, ty, local_matrix, | 79 private: |
32 tile); | 80 explicit PaintShader(sk_sp<SkShader> shader); |
33 } | 81 |
| 82 sk_sp<SkShader> sk_shader_; |
| 83 }; |
34 | 84 |
35 } // namespace cc | 85 } // namespace cc |
36 | 86 |
37 #endif // CC_PAINT_PAINT_SHADER_H_ | 87 #endif // CC_PAINT_PAINT_SHADER_H_ |
OLD | NEW |