| 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 <memory> | 8 #include "cc/paint/paint_record.h" |
| 9 | |
| 10 #include "cc/paint/paint_export.h" | |
| 11 #include "third_party/skia/include/core/SkImage.h" | 9 #include "third_party/skia/include/core/SkImage.h" |
| 12 #include "third_party/skia/include/core/SkScalar.h" | |
| 13 #include "third_party/skia/include/core/SkShader.h" | 10 #include "third_party/skia/include/core/SkShader.h" |
| 14 | 11 |
| 15 namespace cc { | 12 namespace cc { |
| 13 using PaintShader = SkShader; |
| 16 | 14 |
| 17 class PaintOpBuffer; | 15 inline sk_sp<PaintShader> WrapSkShader(sk_sp<SkShader> shader) { |
| 18 using PaintRecord = PaintOpBuffer; | 16 return shader; |
| 17 } |
| 19 | 18 |
| 20 class CC_PAINT_EXPORT PaintShader { | 19 inline sk_sp<PaintShader> MakePaintShaderImage(sk_sp<const SkImage> image, |
| 21 public: | 20 SkShader::TileMode tx, |
| 22 static std::unique_ptr<PaintShader> MakeColor(SkColor color); | 21 SkShader::TileMode ty, |
| 22 const SkMatrix* local_matrix) { |
| 23 return image->makeShader(tx, ty, local_matrix); |
| 24 } |
| 23 | 25 |
| 24 static std::unique_ptr<PaintShader> MakeLinearGradient( | 26 inline sk_sp<PaintShader> MakePaintShaderRecord(sk_sp<PaintRecord> record, |
| 25 const SkPoint points[], | 27 const SkRect& tile, |
| 26 const SkColor colors[], | |
| 27 const SkScalar pos[], | |
| 28 int count, | |
| 29 SkShader::TileMode mode, | |
| 30 uint32_t flags = 0, | |
| 31 const SkMatrix* local_matrix = nullptr, | |
| 32 SkColor fallback_color = SK_ColorTRANSPARENT); | |
| 33 | |
| 34 static std::unique_ptr<PaintShader> MakeRadialGradient( | |
| 35 const SkPoint& center, | |
| 36 SkScalar radius, | |
| 37 const SkColor colors[], | |
| 38 const SkScalar pos[], | |
| 39 int color_count, | |
| 40 SkShader::TileMode mode, | |
| 41 uint32_t flags = 0, | |
| 42 const SkMatrix* local_matrix = nullptr, | |
| 43 SkColor fallback_color = SK_ColorTRANSPARENT); | |
| 44 | |
| 45 static std::unique_ptr<PaintShader> MakeTwoPointConicalGradient( | |
| 46 const SkPoint& start, | |
| 47 SkScalar start_radius, | |
| 48 const SkPoint& end, | |
| 49 SkScalar end_radius, | |
| 50 const SkColor colors[], | |
| 51 const SkScalar pos[], | |
| 52 int color_count, | |
| 53 SkShader::TileMode mode, | |
| 54 uint32_t flags = 0, | |
| 55 const SkMatrix* local_matrix = nullptr, | |
| 56 SkColor fallback_color = SK_ColorTRANSPARENT); | |
| 57 | |
| 58 static std::unique_ptr<PaintShader> MakeSweepGradient( | |
| 59 SkScalar cx, | |
| 60 SkScalar cy, | |
| 61 const SkColor colors[], | |
| 62 const SkScalar pos[], | |
| 63 int color_count, | |
| 64 uint32_t flags = 0, | |
| 65 const SkMatrix* local_matrix = nullptr, | |
| 66 SkColor fallback_color = SK_ColorTRANSPARENT); | |
| 67 | |
| 68 static std::unique_ptr<PaintShader> MakeImage(sk_sp<const SkImage> image, | |
| 69 SkShader::TileMode tx, | 28 SkShader::TileMode tx, |
| 70 SkShader::TileMode ty, | 29 SkShader::TileMode ty, |
| 71 const SkMatrix* local_matrix); | 30 const SkMatrix* local_matrix) { |
| 72 | 31 return SkShader::MakePictureShader(ToSkPicture(record, tile), tx, ty, |
| 73 static std::unique_ptr<PaintShader> MakePaintRecord( | 32 local_matrix, nullptr); |
| 74 sk_sp<PaintRecord> record, | 33 } |
| 75 const SkRect& tile, | |
| 76 SkShader::TileMode tx, | |
| 77 SkShader::TileMode ty, | |
| 78 const SkMatrix* local_matrix); | |
| 79 | |
| 80 PaintShader(const PaintShader& other); | |
| 81 PaintShader(PaintShader&& other); | |
| 82 ~PaintShader(); | |
| 83 | |
| 84 PaintShader& operator=(const PaintShader& other); | |
| 85 PaintShader& operator=(PaintShader&& other); | |
| 86 | |
| 87 const sk_sp<SkShader>& sk_shader() const { return sk_shader_; } | |
| 88 | |
| 89 private: | |
| 90 PaintShader(sk_sp<SkShader> shader, SkColor fallback_color); | |
| 91 | |
| 92 sk_sp<SkShader> sk_shader_; | |
| 93 }; | |
| 94 | 34 |
| 95 } // namespace cc | 35 } // namespace cc |
| 96 | 36 |
| 97 #endif // CC_PAINT_PAINT_SHADER_H_ | 37 #endif // CC_PAINT_PAINT_SHADER_H_ |
| OLD | NEW |