| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef FLUTTER_LIB_UI_PAINTING_GRADIENT_H_ |
| 6 | #define FLUTTER_LIB_UI_PAINTING_GRADIENT_H_ |
| 7 | |
| 8 | #include "flutter/display_list/effects/dl_color_source.h" |
| 9 | #include "flutter/lib/ui/painting/matrix.h" |
| 10 | #include "flutter/lib/ui/painting/shader.h" |
| 11 | #include "third_party/tonic/typed_data/typed_list.h" |
| 12 | |
| 13 | namespace flutter { |
| 14 | |
| 15 | class CanvasGradient : public Shader { |
| 16 | DEFINE_WRAPPERTYPEINFO(); |
| 17 | FML_FRIEND_MAKE_REF_COUNTED(CanvasGradient); |
| 18 | |
| 19 | public: |
| 20 | ~CanvasGradient() override; |
| 21 | static void Create(Dart_Handle wrapper); |
| 22 | |
| 23 | void initLinear(const tonic::Float32List& end_points, |
| 24 | const tonic::Int32List& colors, |
| 25 | const tonic::Float32List& color_stops, |
| 26 | DlTileMode tile_mode, |
| 27 | const tonic::Float64List& matrix4); |
| 28 | |
| 29 | void initRadial(double center_x, |
| 30 | double center_y, |
| 31 | double radius, |
| 32 | const tonic::Int32List& colors, |
| 33 | const tonic::Float32List& color_stops, |
| 34 | DlTileMode tile_mode, |
| 35 | const tonic::Float64List& matrix4); |
| 36 | |
| 37 | void initSweep(double center_x, |
| 38 | double center_y, |
| 39 | const tonic::Int32List& colors, |
| 40 | const tonic::Float32List& color_stops, |
| 41 | DlTileMode tile_mode, |
| 42 | double start_angle, |
| 43 | double end_angle, |
| 44 | const tonic::Float64List& matrix4); |
| 45 | |
| 46 | void initTwoPointConical(double start_x, |
| 47 | double start_y, |
| 48 | double start_radius, |
| 49 | double end_x, |
| 50 | double end_y, |
| 51 | double end_radius, |
| 52 | const tonic::Int32List& colors, |
| 53 | const tonic::Float32List& color_stops, |
| 54 | DlTileMode tile_mode, |
| 55 | const tonic::Float64List& matrix4); |
| 56 | |
| 57 | std::shared_ptr<DlColorSource> shader(DlImageSampling sampling) override { |
| 58 | // Gradient color sources do not have image sampling variants... |
| 59 | return dl_shader_; |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | CanvasGradient(); |
| 64 | std::shared_ptr<DlColorSource> dl_shader_; |
| 65 | }; |
| 66 | |
| 67 | } // namespace flutter |
| 68 | |
| 69 | #endif // FLUTTER_LIB_UI_PAINTING_GRADIENT_H_ |
| 70 | |