Flutter Engine
 
Loading...
Searching...
No Matches
dl_geometry_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_DISPLAY_LIST_GEOMETRY_DL_GEOMETRY_CONVERSIONS_H_
6#define FLUTTER_DISPLAY_LIST_GEOMETRY_DL_GEOMETRY_CONVERSIONS_H_
7
9
10#include "flutter/third_party/skia/include/core/SkM44.h"
11#include "flutter/third_party/skia/include/core/SkMatrix.h"
12#include "flutter/third_party/skia/include/core/SkRRect.h"
13#include "flutter/third_party/skia/include/core/SkRect.h"
14#include "flutter/third_party/skia/include/core/SkSize.h"
15
16namespace flutter {
17
18static_assert(sizeof(SkPoint) == sizeof(DlPoint));
19static_assert(sizeof(SkIPoint) == sizeof(DlIPoint));
20static_assert(sizeof(SkSize) == sizeof(DlSize));
21static_assert(sizeof(SkISize) == sizeof(DlISize));
22static_assert(sizeof(SkRect) == sizeof(DlRect));
23static_assert(sizeof(SkIRect) == sizeof(DlIRect));
24static_assert(sizeof(SkVector) == sizeof(DlSize));
25
26inline const DlPoint& ToDlPoint(const SkPoint& point) {
27 return *reinterpret_cast<const DlPoint*>(&point);
28}
29
30inline const DlRect& ToDlRect(const SkRect& rect) {
31 return *reinterpret_cast<const DlRect*>(&rect);
32}
33
34inline const DlRect ToDlRect(const SkIRect& rect) {
35 return DlRect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
36}
37
38inline const DlIRect& ToDlIRect(const SkIRect& rect) {
39 return *reinterpret_cast<const DlIRect*>(&rect);
40}
41
42inline const DlISize& ToDlISize(const SkISize& size) {
43 return *reinterpret_cast<const DlISize*>(&size);
44}
45
46inline const DlSize& ToDlSize(const SkVector& vector) {
47 return *reinterpret_cast<const DlSize*>(&vector);
48}
49
50inline const DlRoundRect ToDlRoundRect(const SkRRect& rrect) {
52 ToDlRect(rrect.rect()),
53 {
54 .top_left = ToDlSize(rrect.radii(SkRRect::kUpperLeft_Corner)),
55 .top_right = ToDlSize(rrect.radii(SkRRect::kUpperRight_Corner)),
56 .bottom_left = ToDlSize(rrect.radii(SkRRect::kLowerLeft_Corner)),
57 .bottom_right = ToDlSize(rrect.radii(SkRRect::kLowerRight_Corner)),
58 });
59}
60
61inline DlMatrix ToDlMatrix(const SkMatrix& matrix) {
62 // clang-format off
64 matrix[SkMatrix::kMScaleX], matrix[SkMatrix::kMSkewY], 0.0f, matrix[SkMatrix::kMPersp0],
65 matrix[SkMatrix::kMSkewX], matrix[SkMatrix::kMScaleY], 0.0f, matrix[SkMatrix::kMPersp1],
66 0.0f, 0.0f, 1.0f, 0.0f,
67 matrix[SkMatrix::kMTransX], matrix[SkMatrix::kMTransY], 0.0f, matrix[SkMatrix::kMPersp2]
68 );
69 // clang-format on
70}
71
72inline DlMatrix ToDlMatrix(const SkM44& matrix) {
73 DlMatrix dl_matrix;
74 matrix.getColMajor(dl_matrix.m);
75 return dl_matrix;
76}
77
78inline const SkPoint& ToSkPoint(const DlPoint& point) {
79 return *reinterpret_cast<const SkPoint*>(&point);
80}
81
82inline const SkPoint* ToSkPoints(const DlPoint* points) {
83 return points == nullptr ? nullptr : reinterpret_cast<const SkPoint*>(points);
84}
85
86inline SkPoint* ToSkPoints(DlPoint* points) {
87 return points == nullptr ? nullptr : reinterpret_cast<SkPoint*>(points);
88}
89
90inline const SkRect& ToSkRect(const DlRect& rect) {
91 return *reinterpret_cast<const SkRect*>(&rect);
92}
93
94inline const SkIRect& ToSkIRect(const DlIRect& rect) {
95 return *reinterpret_cast<const SkIRect*>(&rect);
96}
97
98inline std::optional<const SkIRect> ToOptSkIRect(
99 std::optional<const DlIRect> rect) {
100 return rect.has_value() ? std::optional(ToSkIRect(*rect)) : std::nullopt;
101}
102
103inline const SkRect* ToSkRect(const DlRect* rect) {
104 return rect == nullptr ? nullptr : reinterpret_cast<const SkRect*>(rect);
105}
106
107inline const SkRect* ToSkRect(const std::optional<DlRect>& rect) {
108 return rect.has_value() ? &ToSkRect(rect.value()) : nullptr;
109}
110
111inline SkRect* ToSkRect(DlRect* rect) {
112 return rect == nullptr ? nullptr : reinterpret_cast<SkRect*>(rect);
113}
114
115inline const SkRect* ToSkRects(const DlRect* rects) {
116 return rects == nullptr ? nullptr : reinterpret_cast<const SkRect*>(rects);
117}
118
119inline const SkIRect* ToSkIRects(const DlIRect* rects) {
120 return rects == nullptr ? nullptr : reinterpret_cast<const SkIRect*>(rects);
121}
122
123inline const SkSize& ToSkSize(const DlSize& size) {
124 return *reinterpret_cast<const SkSize*>(&size);
125}
126
127inline const SkISize& ToSkISize(const DlISize& size) {
128 return *reinterpret_cast<const SkISize*>(&size);
129}
130
131inline const SkVector& ToSkVector(const DlSize& size) {
132 return *reinterpret_cast<const SkVector*>(&size);
133}
134
135inline const SkRRect ToSkRRect(const DlRoundRect& round_rect) {
136 SkVector radii[4];
137 radii[SkRRect::kUpperLeft_Corner] =
138 ToSkVector(round_rect.GetRadii().top_left);
139 radii[SkRRect::kUpperRight_Corner] =
140 ToSkVector(round_rect.GetRadii().top_right);
141 radii[SkRRect::kLowerLeft_Corner] =
142 ToSkVector(round_rect.GetRadii().bottom_left);
143 radii[SkRRect::kLowerRight_Corner] =
144 ToSkVector(round_rect.GetRadii().bottom_right);
145 SkRRect rrect;
146 rrect.setRectRadii(ToSkRect(round_rect.GetBounds()), radii);
147 return rrect;
148};
149
150// Approximates a rounded superellipse with a round rectangle to the
151// best practical accuracy.
152//
153// Skia does not support rounded superellipses directly, so rendering
154// `DlRoundSuperellipses` on Skia requires falling back to RRect.
155inline const SkRRect ToApproximateSkRRect(const DlRoundSuperellipse& rse) {
156 return ToSkRRect(rse.ToApproximateRoundRect());
157};
158
159inline SkMatrix ToSkMatrix(const DlMatrix& matrix) {
160 return SkMatrix::MakeAll(matrix.m[0], matrix.m[4], matrix.m[12], //
161 matrix.m[1], matrix.m[5], matrix.m[13], //
162 matrix.m[3], matrix.m[7], matrix.m[15]);
163}
164
165inline SkM44 ToSkM44(const DlMatrix& matrix) {
166 return SkM44::ColMajor(matrix.m);
167}
168
169} // namespace flutter
170
171#endif // FLUTTER_DISPLAY_LIST_GEOMETRY_DL_GEOMETRY_CONVERSIONS_H_
const SkPoint & ToSkPoint(const DlPoint &point)
const DlISize & ToDlISize(const SkISize &size)
const DlPoint & ToDlPoint(const SkPoint &point)
const SkSize & ToSkSize(const DlSize &size)
impeller::Rect DlRect
impeller::ISize32 DlISize
const SkIRect & ToSkIRect(const DlIRect &rect)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
const SkRRect ToApproximateSkRRect(const DlRoundSuperellipse &rse)
const DlSize & ToDlSize(const SkVector &vector)
impeller::Size DlSize
SkMatrix ToSkMatrix(const DlMatrix &matrix)
impeller::IRect32 DlIRect
const DlIRect & ToDlIRect(const SkIRect &rect)
impeller::IPoint32 DlIPoint
const SkPoint * ToSkPoints(const DlPoint *points)
const SkVector & ToSkVector(const DlSize &size)
const SkRect * ToSkRects(const DlRect *rects)
std::optional< const SkIRect > ToOptSkIRect(std::optional< const DlIRect > rect)
const DlRoundRect ToDlRoundRect(const SkRRect &rrect)
const SkIRect * ToSkIRects(const DlIRect *rects)
const SkRRect ToSkRRect(const DlRoundRect &round_rect)
DlMatrix ToDlMatrix(const SkMatrix &matrix)
impeller::Point DlPoint
SkM44 ToSkM44(const DlMatrix &matrix)
const DlRect & ToDlRect(const SkRect &rect)
const SkRect & ToSkRect(const DlRect &rect)
const SkISize & ToSkISize(const DlISize &size)
A 4x4 matrix using column-major storage.
Definition matrix.h:37
Scalar m[16]
Definition matrix.h:39
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition matrix.h:69
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition round_rect.cc:9
constexpr const RoundingRadii & GetRadii() const
Definition round_rect.h:55
constexpr const Rect & GetBounds() const
Definition round_rect.h:53
RoundRect ToApproximateRoundRect() const
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129
std::vector< Point > points