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 "display_list/dl_color.h"
9 #include "display_list/effects/dl_color_source.h"
10 #include "impeller/core/formats.h"
12 #include "impeller/geometry/path.h"
15 #include "impeller/geometry/rect.h"
16 #include "third_party/skia/include/core/SkColor.h"
17 #include "third_party/skia/include/core/SkColorType.h"
18 #include "third_party/skia/include/core/SkPath.h"
19 #include "third_party/skia/include/core/SkPoint.h"
20 #include "third_party/skia/include/core/SkRRect.h"
21 #include "third_party/skia/include/core/SkRSXform.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 
38 std::vector<Rect> ToRects(const SkRect tex[], int count);
39 
40 std::vector<Point> ToPoints(const SkPoint points[], int count);
41 
42 Point ToPoint(const SkPoint& point);
43 
44 Size ToSize(const SkPoint& point);
45 
46 Color ToColor(const flutter::DlColor& color);
47 
48 std::vector<Matrix> ToRSXForms(const SkRSXform xform[], int count);
49 
50 PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect& rrect);
51 
52 Path ToPath(const SkPath& path, Point shift = Point(0, 0));
53 
54 Path ToPath(const SkRRect& rrect);
55 
56 Path PathDataFromTextBlob(const sk_sp<SkTextBlob>& blob,
57  Point shift = Point(0, 0));
58 
59 std::optional<impeller::PixelFormat> ToPixelFormat(SkColorType type);
60 
61 /// @brief Convert display list colors + stops into impeller colors and stops,
62 /// taking care to ensure that the stops monotonically increase from 0.0 to 1.0.
63 ///
64 /// The general process is:
65 /// * Ensure that the first gradient stop value is 0.0. If not, insert a new
66 /// stop with a value of 0.0 and use the first gradient color as this new
67 /// stops color.
68 /// * Ensure the last gradient stop value is 1.0. If not, insert a new stop
69 /// with a value of 1.0 and use the last gradient color as this stops color.
70 /// * Clamp all gradient values between the values of 0.0 and 1.0.
71 /// * For all stop values, ensure that the values are monotonically increasing
72 /// by clamping each value to a minimum of the previous stop value and itself.
73 /// For example, with stop values of 0.0, 0.5, 0.4, 1.0, we would clamp such
74 /// that the values were 0.0, 0.5, 0.5, 1.0.
75 void ConvertStops(const flutter::DlGradientColorSourceBase* gradient,
76  std::vector<Color>& colors,
77  std::vector<float>& stops);
78 
79 } // namespace skia_conversions
80 } // namespace impeller
81 
82 #endif // FLUTTER_IMPELLER_DISPLAY_LIST_SKIA_CONVERSIONS_H_
path.h
impeller::skia_conversions::PathDataFromTextBlob
Path PathDataFromTextBlob(const sk_sp< SkTextBlob > &blob, Point shift)
Definition: skia_conversions.cc:188
point.h
impeller::skia_conversions::ToPoints
std::vector< Point > ToPoints(const SkPoint points[], int count)
Definition: skia_conversions.cc:45
impeller::skia_conversions::IsNearlySimpleRRect
bool IsNearlySimpleRRect(const SkRRect &rr)
Like SkRRect.isSimple, but allows the corners to differ by kEhCloseEnough.
Definition: skia_conversions.cc:12
impeller::skia_conversions::ToPixelFormat
std::optional< impeller::PixelFormat > ToPixelFormat(SkColorType type)
Definition: skia_conversions.cc:196
impeller::skia_conversions::ConvertStops
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...
Definition: skia_conversions.cc:212
impeller::skia_conversions::ToSize
Size ToSize(const SkPoint &point)
Definition: skia_conversions.cc:158
formats.h
impeller::skia_conversions::ToRects
std::vector< Rect > ToRects(const SkRect tex[], int count)
Definition: skia_conversions.cc:37
impeller::skia_conversions::ToColor
Color ToColor(const flutter::DlColor &color)
Definition: skia_conversions.cc:162
impeller::Size
TSize< Scalar > Size
Definition: size.h:137
path_builder.h
impeller::skia_conversions::ToRect
Rect ToRect(const SkRect &rect)
Definition: skia_conversions.cc:26
impeller::skia_conversions::ToRoundingRadii
PathBuilder::RoundingRadii ToRoundingRadii(const SkRRect &rrect)
Definition: skia_conversions.cc:53
impeller::Point
TPoint< Scalar > Point
Definition: point.h:322
type
GLenum type
Definition: blit_command_gles.cc:126
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:769
impeller::skia_conversions::ToPoint
Point ToPoint(const SkPoint &point)
Definition: skia_conversions.cc:154
rect.h
impeller::skia_conversions::ToRSXForms
std::vector< Matrix > ToRSXForms(const SkRSXform xform[], int count)
Definition: skia_conversions.cc:171
color.h
color
DlColor color
Definition: dl_golden_blur_unittests.cc:23
impeller
Definition: aiks_blend_unittests.cc:18
impeller::skia_conversions::ToPath
Path ToPath(const SkPath &path, Point shift)
Definition: skia_conversions.cc:63