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