| Flutter Impeller |

dl_builder.cc
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 #include "impeller/toolkit/interop/dl_builder.h"
6
7 #include "impeller/toolkit/interop/formats.h"
8
9 namespace impeller::interop {
10
11 DisplayListBuilder::DisplayListBuilder(const ImpellerRect* rect)
12 : builder_(ToSkiaType(rect).value_or(
13 flutter::DisplayListBuilder::kMaxCullRect)) {}
14
15 DisplayListBuilder::~DisplayListBuilder() = default;
16
17 void DisplayListBuilder::Save() {
18 builder_.Save();
19 }
20
21 void DisplayListBuilder::SaveLayer(const Rect& bounds,
22 const Paint* paint,
23 const ImageFilter* backdrop) {
24 const auto sk_bounds = ToSkiaType(bounds);
25 builder_.SaveLayer(
26 &sk_bounds, //
27 paint == nullptr ? nullptr : &paint->GetPaint(), //
28 backdrop == nullptr ? nullptr : backdrop->GetImageFilter().get());
29 }
30
31 void DisplayListBuilder::Restore() {
32 builder_.Restore();
33 }
34
35 void DisplayListBuilder::Scale(Size scale) {
36 builder_.Scale(scale.width, scale.height);
37 }
38
39 void DisplayListBuilder::Rotate(Degrees angle) {
40 builder_.Rotate(angle.degrees);
41 }
42
43 void DisplayListBuilder::Translate(Point translation) {
44 builder_.Translate(translation.x, translation.y);
45 }
46
47 Matrix DisplayListBuilder::GetTransform() const {
48 Matrix matrix;
49 builder_.GetTransformFullPerspective().getColMajor(matrix.m);
50 return matrix;
51 }
52
53 void DisplayListBuilder::SetTransform(const Matrix& matrix) {
54 const auto sk_matrix = SkM44::ColMajor(matrix.m);
55 builder_.SetTransform(&sk_matrix);
56 }
57
58 void DisplayListBuilder::ResetTransform() {
59 builder_.TransformReset();
60 }
61
62 uint32_t DisplayListBuilder::GetSaveCount() const {
63 return builder_.GetSaveCount();
64 }
65
66 void DisplayListBuilder::RestoreToCount(uint32_t count) {
67 builder_.RestoreToCount(count);
68 }
69
70 void DisplayListBuilder::ClipRect(const Rect& rect,
71 flutter::DlCanvas::ClipOp op) {
72 builder_.ClipRect(ToSkiaType(rect), op);
73 }
74
75 void DisplayListBuilder::ClipOval(const Rect& rect,
76 flutter::DlCanvas::ClipOp op) {
77 builder_.ClipOval(ToSkiaType(rect), op);
78 }
79
80 void DisplayListBuilder::ClipRoundedRect(
81 const Rect& rect,
82 const impeller::PathBuilder::RoundingRadii& radii,
83 flutter::DlCanvas::ClipOp op) {
84 builder_.ClipRRect(ToSkiaType(rect, radii), op);
85 }
86
87 void DisplayListBuilder::ClipPath(const Path& path,
88 flutter::DlCanvas::ClipOp op) {
89 builder_.ClipPath(path.GetPath(), op);
90 }
91
92 void DisplayListBuilder::DrawRect(const Rect& rect, const Paint& paint) {
93 builder_.DrawRect(ToSkiaType(rect), paint.GetPaint());
94 }
95
96 void DisplayListBuilder::DrawOval(const Rect& oval_bounds, const Paint& paint) {
97 builder_.DrawOval(ToSkiaType(oval_bounds), paint.GetPaint());
98 }
99
100 void DisplayListBuilder::DrawRoundedRect(
101 const Rect& rect,
102 const impeller::PathBuilder::RoundingRadii& radii,
103 const Paint& paint) {
104 builder_.DrawRRect(ToSkiaType(rect, radii), paint.GetPaint());
105 }
106
107 void DisplayListBuilder::DrawRoundedRectDifference(
108 const Rect& outer_rect,
109 const impeller::PathBuilder::RoundingRadii& outer_radii,
110 const Rect& inner_rect,
111 const impeller::PathBuilder::RoundingRadii& inner_radii,
112 const Paint& paint) {
113 builder_.DrawDRRect(ToSkiaType(outer_rect, outer_radii), //
114 ToSkiaType(inner_rect, inner_radii), //
115 paint.GetPaint() //
116 );
117 }
118
119 void DisplayListBuilder::DrawPath(const Path& path, const Paint& paint) {
120 builder_.DrawPath(path.GetPath(), paint.GetPaint());
121 }
122
123 void DisplayListBuilder::DrawPaint(const Paint& paint) {
124 builder_.DrawPaint(paint.GetPaint());
125 }
126
127 void DisplayListBuilder::DrawLine(const Point& from,
128 const Point& to,
129 const Paint& paint) {
130 builder_.DrawLine(ToSkiaType(from), ToSkiaType(to), paint.GetPaint());
131 }
132
133 void DisplayListBuilder::DrawDashedLine(const Point& from,
134 const Point& to,
135 Scalar on_length,
136 Scalar off_length,
137 const Paint& paint) {
138 builder_.DrawDashedLine(from, //
139 to, //
140 on_length, //
141 off_length, //
142 paint.GetPaint() //
143 );
144 }
145
146 ScopedObject<DisplayList> DisplayListBuilder::Build() {
147 return Create<DisplayList>(builder_.Build());
148 }
149
150 void DisplayListBuilder::DrawDisplayList(const DisplayList& dl,
151 Scalar opacity) {
152 builder_.DrawDisplayList(dl.GetDisplayList(), opacity);
153 }
154
155 void DisplayListBuilder::DrawTexture(const Texture& texture,
156 const Point& point,
157 flutter::DlImageSampling sampling,
158 const Paint* paint) {
159 builder_.DrawImage(texture.MakeImage(), //
160 ToSkiaType(point), //
161 sampling, //
162 paint == nullptr ? nullptr : &paint->GetPaint() //
163 );
164 }
165
166 void DisplayListBuilder::DrawTextureRect(const Texture& texture,
167 const Rect& src_rect,
168 const Rect& dst_rect,
169 flutter::DlImageSampling sampling,
170 const Paint* paint) {
171 builder_.DrawImageRect(texture.MakeImage(), //
172 ToSkiaType(src_rect), //
173 ToSkiaType(dst_rect), //
174 sampling, //
175 paint == nullptr ? nullptr : &paint->GetPaint() //
176 );
177 }
178
179 void DisplayListBuilder::DrawParagraph(const Paragraph& paragraph,
180 Point point) {
181 const auto& handle = paragraph.GetHandle();
182 if (!handle) {
183 return;
184 }
185 handle->Paint(&builder_, point.x, point.y);
186 }
187
188 } // namespace impeller::interop
impeller::Matrix::m
Scalar m[16]
Definition: matrix.h:39
impeller::interop::DisplayListBuilder::ClipRoundedRect
void ClipRoundedRect(const Rect &rect, const impeller::PathBuilder::RoundingRadii &radii, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:80
impeller::interop::DisplayListBuilder::DrawParagraph
void DrawParagraph(const Paragraph &paragraph, Point point)
Definition: dl_builder.cc:179
impeller::interop::DisplayListBuilder::ClipPath
void ClipPath(const Path &path, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:87
impeller::TPoint::y
Type y
Definition: point.h:31
dl_builder.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Degrees::degrees
Scalar degrees
Definition: scalar.h:52
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop::DisplayListBuilder::DrawDisplayList
void DrawDisplayList(const DisplayList &dl, Scalar opacity)
Definition: dl_builder.cc:150
impeller::interop::DisplayListBuilder::~DisplayListBuilder
~DisplayListBuilder() override
impeller::interop::DisplayListBuilder::Translate
void Translate(Point translation)
Definition: dl_builder.cc:43
impeller::interop::DisplayListBuilder::ClipOval
void ClipOval(const Rect &rect, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:75
impeller::interop::DisplayListBuilder::DisplayListBuilder
DisplayListBuilder(const ImpellerRect *rect)
Definition: dl_builder.cc:11
ImpellerRect
Definition: impeller.h:234
impeller::interop::DisplayListBuilder::DrawOval
void DrawOval(const Rect &oval_bounds, const Paint &paint)
Definition: dl_builder.cc:96
impeller::interop::DisplayListBuilder::DrawTextureRect
void DrawTextureRect(const Texture &texture, const Rect &src_rect, const Rect &dst_rect, flutter::DlImageSampling sampling, const Paint *paint)
Definition: dl_builder.cc:166
impeller::interop::DisplayListBuilder::Rotate
void Rotate(Degrees angle)
Definition: dl_builder.cc:39
impeller::interop::DisplayListBuilder::ClipRect
void ClipRect(const Rect &rect, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:70
impeller::interop::DisplayListBuilder::DrawRoundedRect
void DrawRoundedRect(const Rect &rect, const impeller::PathBuilder::RoundingRadii &radii, const Paint &paint)
Definition: dl_builder.cc:100
impeller::interop
Definition: color_filter.cc:7
impeller::interop::Texture::MakeImage
sk_sp< DlImageImpeller > MakeImage() const
Definition: texture.cc:46
impeller::interop::DisplayListBuilder::SetTransform
void SetTransform(const Matrix &matrix)
Definition: dl_builder.cc:53
impeller::interop::Paragraph::GetHandle
const std::unique_ptr< txt::Paragraph > & GetHandle() const
Definition: paragraph.cc:46
impeller::interop::DisplayListBuilder
Definition: dl_builder.h:24
impeller::interop::DisplayListBuilder::DrawTexture
void DrawTexture(const Texture &texture, const Point &point, flutter::DlImageSampling sampling, const Paint *paint)
Definition: dl_builder.cc:155
impeller::PathBuilder::RoundingRadii
Definition: path_builder.h:105
impeller::interop::DisplayListBuilder::DrawRect
void DrawRect(const Rect &rect, const Paint &paint)
Definition: dl_builder.cc:92
impeller::TSize< Scalar >
impeller::interop::DisplayListBuilder::GetTransform
Matrix GetTransform() const
Definition: dl_builder.cc:47
impeller::interop::ToSkiaType
constexpr std::optional< SkRect > ToSkiaType(const ImpellerRect *rect)
Definition: formats.h:26
impeller::interop::DisplayListBuilder::GetSaveCount
uint32_t GetSaveCount() const
Definition: dl_builder.cc:62
impeller::interop::DisplayList
Definition: dl.h:14
formats.h
impeller::interop::ImageFilter
Definition: image_filter.h:15
flutter
Definition: dl_golden_blur_unittests.cc:15
impeller::interop::DisplayListBuilder::Scale
void Scale(Size scale)
Definition: dl_builder.cc:35
impeller::interop::Path::GetPath
const SkPath & GetPath() const
Definition: path.cc:13
impeller::interop::DisplayListBuilder::DrawLine
void DrawLine(const Point &from, const Point &to, const Paint &paint)
Definition: dl_builder.cc:127
impeller::interop::DisplayListBuilder::Build
ScopedObject< DisplayList > Build()
Definition: dl_builder.cc:146
impeller::interop::DisplayListBuilder::SaveLayer
void SaveLayer(const Rect &bounds, const Paint *paint, const ImageFilter *backdrop)
Definition: dl_builder.cc:21
impeller::interop::DisplayListBuilder::DrawPath
void DrawPath(const Path &path, const Paint &paint)
Definition: dl_builder.cc:119
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::interop::DisplayListBuilder::Restore
void Restore()
Definition: dl_builder.cc:31
impeller::interop::Texture
Definition: texture.h:16
impeller::interop::Paragraph
Definition: paragraph.h:14
impeller::interop::DisplayList::GetDisplayList
const sk_sp< flutter::DisplayList > GetDisplayList() const
Definition: dl.cc:18
impeller::interop::Paint
Definition: paint.h:21
impeller::interop::DisplayListBuilder::DrawRoundedRectDifference
void DrawRoundedRectDifference(const Rect &outer_rect, const impeller::PathBuilder::RoundingRadii &outer_radii, const Rect &inner_rect, const impeller::PathBuilder::RoundingRadii &inner_radii, const Paint &paint)
Definition: dl_builder.cc:107
impeller::TPoint< Scalar >
impeller::interop::Path
Definition: path.h:15
impeller::interop::ImageFilter::GetImageFilter
const std::shared_ptr< const flutter::DlImageFilter > & GetImageFilter() const
Definition: image_filter.cc:64
impeller::interop::Paint::GetPaint
const flutter::DlPaint & GetPaint() const
Definition: paint.cc:13
scale
const Scalar scale
Definition: stroke_path_geometry.cc:301
impeller::interop::DisplayListBuilder::Save
void Save()
Definition: dl_builder.cc:17
impeller::Degrees
Definition: scalar.h:51
impeller::interop::DisplayListBuilder::RestoreToCount
void RestoreToCount(uint32_t count)
Definition: dl_builder.cc:66
impeller::interop::DisplayListBuilder::DrawDashedLine
void DrawDashedLine(const Point &from, const Point &to, Scalar on_length, Scalar off_length, const Paint &paint)
Definition: dl_builder.cc:133
impeller::interop::DisplayListBuilder::ResetTransform
void ResetTransform()
Definition: dl_builder.cc:58
impeller::interop::DisplayListBuilder::DrawPaint
void DrawPaint(const Paint &paint)
Definition: dl_builder.cc:123
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37