Flutter Impeller
skia_conversions.h
Go to the documentation of this file.
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_IMPELLER_DISPLAY_LIST_SKIA_CONVERSIONS_H_
6 #define FLUTTER_IMPELLER_DISPLAY_LIST_SKIA_CONVERSIONS_H_
7 
8 #include "flutter/display_list/dl_blend_mode.h"
9 #include "flutter/display_list/dl_color.h"
10 #include "flutter/display_list/effects/dl_color_sources.h"
11 #include "impeller/core/formats.h"
14 #include "impeller/geometry/path.h"
17 #include "impeller/geometry/rect.h"
18 #include "third_party/skia/include/core/SkColorType.h"
19 #include "third_party/skia/include/core/SkPath.h"
20 #include "third_party/skia/include/core/SkPoint.h"
21 #include "third_party/skia/include/core/SkRRect.h"
22 #include "third_party/skia/include/core/SkTextBlob.h"
23 
24 namespace impeller {
25 namespace skia_conversions {
26 
27 /// @brief Like SkRRect.isSimple, but allows the corners to differ by
28 /// kEhCloseEnough.
29 ///
30 /// An RRect is simple if all corner radii are approximately
31 /// equal.
32 bool IsNearlySimpleRRect(const SkRRect& rr);
33 
34 Rect ToRect(const SkRect& rect);
35 
36 std::optional<Rect> ToRect(const SkRect* rect);
37 std::optional<const Rect> ToRect(const flutter::DlRect* rect);
38 
39 std::vector<Rect> ToRects(const SkRect tex[], int count);
40 std::vector<Rect> ToRects(const flutter::DlRect tex[], int count);
41 
42 std::vector<Point> ToPoints(const SkPoint points[], int count);
43 std::vector<Point> ToPoints(const flutter::DlPoint points[], int count);
44 
45 Point ToPoint(const SkPoint& point);
46 
47 Size ToSize(const SkPoint& point);
48 
49 Color ToColor(const flutter::DlColor& color);
50 
51 std::optional<impeller::PixelFormat> ToPixelFormat(SkColorType type);
52 
54  const flutter::DlImageSampling options);
55 
56 Matrix ToMatrix(const SkMatrix& m);
57 
58 BlendMode ToBlendMode(flutter::DlBlendMode mode);
59 
60 /// @brief Convert display list colors + stops into impeller colors and stops,
61 /// taking care to ensure that the stops monotonically increase from 0.0 to 1.0.
62 ///
63 /// The general process is:
64 /// * Ensure that the first gradient stop value is 0.0. If not, insert a new
65 /// stop with a value of 0.0 and use the first gradient color as this new
66 /// stops color.
67 /// * Ensure the last gradient stop value is 1.0. If not, insert a new stop
68 /// with a value of 1.0 and use the last gradient color as this stops color.
69 /// * Clamp all gradient values between the values of 0.0 and 1.0.
70 /// * For all stop values, ensure that the values are monotonically increasing
71 /// by clamping each value to a minimum of the previous stop value and itself.
72 /// For example, with stop values of 0.0, 0.5, 0.4, 1.0, we would clamp such
73 /// that the values were 0.0, 0.5, 0.5, 1.0.
74 void ConvertStops(const flutter::DlGradientColorSourceBase* gradient,
75  std::vector<Color>& colors,
76  std::vector<float>& stops);
77 
78 } // namespace skia_conversions
79 } // namespace impeller
80 
81 #endif // FLUTTER_IMPELLER_DISPLAY_LIST_SKIA_CONVERSIONS_H_
GLenum type
Matrix ToMatrix(const SkMatrix &m)
BlendMode ToBlendMode(flutter::DlBlendMode mode)
std::optional< impeller::PixelFormat > ToPixelFormat(SkColorType type)
std::vector< Point > ToPoints(const SkPoint points[], int count)
void ConvertStops(const flutter::DlGradientColorSourceBase *gradient, std::vector< Color > &colors, std::vector< float > &stops)
Convert display list colors + stops into impeller colors and stops, taking care to ensure that the st...
Point ToPoint(const SkPoint &point)
Size ToSize(const SkPoint &point)
std::vector< Rect > ToRects(const SkRect tex[], int count)
impeller::SamplerDescriptor ToSamplerDescriptor(const flutter::DlImageSampling options)
bool IsNearlySimpleRRect(const SkRRect &rr)
Like SkRRect.isSimple, but allows the corners to differ by kEhCloseEnough.
Rect ToRect(const SkRect &rect)
Color ToColor(const flutter::DlColor &color)
flutter::DlRect DlRect
Definition: dl_dispatcher.h:25
TRect< Scalar > Rect
Definition: rect.h:792
TPoint< Scalar > Point
Definition: point.h:327
flutter::DlPoint DlPoint
Definition: dl_dispatcher.h:24
BlendMode
Definition: color.h:58
TSize< Scalar > Size
Definition: size.h:171