Chromium Code Reviews| 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 SkColor fallback_color = SK_ColorTRANSPARENT); | |
|
piman
2017/06/02 20:43:36
At the call site, determining what kind of shader
vmpstr
2017/06/02 20:52:00
Yes, I'll do that. Thanks!
vmpstr
2017/06/05 21:02:06
Done.
| |
| 31 // Creates a radial gradient shader. See SkGradientShader::MakeRadial | |
| 32 PaintShader(const SkPoint& center, | |
| 33 SkScalar radius, | |
| 34 const SkColor colors[], | |
| 35 const SkScalar pos[], | |
| 36 int color_count, | |
| 37 SkShader::TileMode mode, | |
| 38 uint32_t flags = 0, | |
| 39 const SkMatrix* local_matrix = nullptr, | |
| 40 SkColor fallback_color = SK_ColorTRANSPARENT); | |
| 41 // Creates a two point conical gradient shader. See | |
| 42 // SkGradientShader::MakeTwoPointConical. | |
| 43 PaintShader(const SkPoint& start, | |
| 44 SkScalar start_radius, | |
| 45 const SkPoint& end, | |
| 46 SkScalar end_radius, | |
| 47 const SkColor colors[], | |
| 48 const SkScalar pos[], | |
| 49 int color_count, | |
| 50 SkShader::TileMode mode, | |
| 51 uint32_t flags = 0, | |
| 52 const SkMatrix* local_matrix = nullptr, | |
| 53 SkColor fallback_color = SK_ColorTRANSPARENT); | |
| 54 // Creates a sweep gradient shader. See SkGradientShader::MakeSweep. | |
| 55 PaintShader(SkScalar cx, | |
| 56 SkScalar cy, | |
| 57 const SkColor colors[], | |
| 58 const SkScalar pos[], | |
| 59 int color_count, | |
| 60 uint32_t flags = 0, | |
| 61 const SkMatrix* local_matrix = nullptr, | |
| 62 SkColor fallback_color = SK_ColorTRANSPARENT); | |
| 63 // Creates an image shader. See SkImage::makeShader. | |
| 64 PaintShader(sk_sp<const SkImage> image, | |
| 65 SkShader::TileMode tx, | |
| 66 SkShader::TileMode ty, | |
| 67 const SkMatrix* local_matrix); | |
| 68 // Creates a picture shader. See SkShader::MakePictureShader. | |
| 69 PaintShader(sk_sp<PaintRecord> record, | |
| 70 const SkRect& tile, | |
| 71 SkShader::TileMode tx, | |
| 72 SkShader::TileMode ty, | |
| 73 const SkMatrix* local_matrix); | |
| 74 PaintShader(const PaintShader& other); | |
| 75 PaintShader(PaintShader&& other); | |
|
piman
2017/06/02 20:43:36
nit: should we also have copy-assign and move-assi
vmpstr
2017/06/05 21:02:06
Done.
| |
| 76 ~PaintShader(); | |
| 25 | 77 |
| 26 inline sk_sp<PaintShader> MakePaintShaderRecord(sk_sp<PaintRecord> record, | 78 const sk_sp<SkShader>& sk_shader() const { return sk_shader_; } |
| 27 const SkRect& tile, | 79 |
| 28 SkShader::TileMode tx, | 80 private: |
| 29 SkShader::TileMode ty, | 81 explicit PaintShader(sk_sp<SkShader> shader, SkColor fallback_color); |
|
piman
2017/06/02 20:43:36
nit: no need for explicit
vmpstr
2017/06/05 21:02:07
Done.
| |
| 30 const SkMatrix* local_matrix) { | 82 |
| 31 return SkShader::MakePictureShader(ToSkPicture(record, tile), tx, ty, | 83 sk_sp<SkShader> sk_shader_; |
| 32 local_matrix, nullptr); | 84 }; |
| 33 } | |
| 34 | 85 |
| 35 } // namespace cc | 86 } // namespace cc |
| 36 | 87 |
| 37 #endif // CC_PAINT_PAINT_SHADER_H_ | 88 #endif // CC_PAINT_PAINT_SHADER_H_ |
| OLD | NEW |