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/lib/ui/dart_wrapper.h" 9 #include "flutter/lib/ui/painting/matrix.h" 10 #include "flutter/lib/ui/painting/shader.h" 11 #include "third_party/skia/include/effects/SkGradientShader.h" 12 13 namespace tonic { 14 class DartLibraryNatives; 15 } // namespace tonic 16 17 namespace flutter { 18 19 // TODO: update this if/when Skia adds Decal mode skbug.com/7638 20 #ifdef USE_SYSTEM_SKIA 21 static_assert(SkShader::kTileModeCount >= 3, "Need to update tile mode enum"); 22 using SkTileMode = SkShader::TileMode; 23 #else 24 static_assert(kSkTileModeCount >= 3, "Need to update tile mode enum"); 25 #endif 26 27 class CanvasGradient : public Shader { 28 DEFINE_WRAPPERTYPEINFO(); 29 FML_FRIEND_MAKE_REF_COUNTED(CanvasGradient); 30 31 public: 32 ~CanvasGradient() override; 33 static fml::RefPtr<CanvasGradient> Create(); 34 35 void initLinear(const tonic::Float32List& end_points, 36 const tonic::Int32List& colors, 37 const tonic::Float32List& color_stops, 38 SkTileMode tile_mode, 39 const tonic::Float64List& matrix4); 40 41 void initRadial(double center_x, 42 double center_y, 43 double radius, 44 const tonic::Int32List& colors, 45 const tonic::Float32List& color_stops, 46 SkTileMode tile_mode, 47 const tonic::Float64List& matrix4); 48 49 void initSweep(double center_x, 50 double center_y, 51 const tonic::Int32List& colors, 52 const tonic::Float32List& color_stops, 53 SkTileMode tile_mode, 54 double start_angle, 55 double end_angle, 56 const tonic::Float64List& matrix4); 57 58 void initTwoPointConical(double start_x, 59 double start_y, 60 double start_radius, 61 double end_x, 62 double end_y, 63 double end_radius, 64 const tonic::Int32List& colors, 65 const tonic::Float32List& color_stops, 66 SkTileMode tile_mode, 67 const tonic::Float64List& matrix4); 68 69 static void RegisterNatives(tonic::DartLibraryNatives* natives); 70 71 private: 72 CanvasGradient(); 73 }; 74 75 } // namespace flutter 76 77 #endif // FLUTTER_LIB_UI_PAINTING_GRADIENT_H_ 78