| 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,
70 flutter::DlCanvas::ClipOp op) {
71 builder_.ClipRect(rect, op);
72 }
73
74 void DisplayListBuilder::ClipOval(const Rect& rect,
75 flutter::DlCanvas::ClipOp op) {
76 builder_.ClipOval(rect, op);
77 }
78
79 void DisplayListBuilder::ClipRoundedRect(const Rect& rect,
80 const RoundingRadii& radii,
81 flutter::DlCanvas::ClipOp op) {
82 builder_.ClipRoundRect(RoundRect::MakeRectRadii(rect, radii), op);
83 }
84
85 void DisplayListBuilder::ClipPath(const Path& path,
86 flutter::DlCanvas::ClipOp op) {
87 builder_.ClipPath(flutter::DlPath(path.GetPath()), op);
88 }
89
90 void DisplayListBuilder::DrawRect(const Rect& rect, const Paint& paint) {
91 builder_.DrawRect(rect, paint.GetPaint());
92 }
93
94 void DisplayListBuilder::DrawOval(const Rect& oval_bounds, const Paint& paint) {
95 builder_.DrawOval(oval_bounds, paint.GetPaint());
96 }
97
98 void DisplayListBuilder::DrawRoundedRect(const Rect& rect,
99 const RoundingRadii& radii,
100 const Paint& paint) {
101 builder_.DrawRoundRect(RoundRect::MakeRectRadii(rect, radii),
102 paint.GetPaint());
103 }
104
105 void DisplayListBuilder::DrawRoundedRectDifference(
106 const Rect& outer_rect,
107 const RoundingRadii& outer_radii,
108 const Rect& inner_rect,
109 const RoundingRadii& inner_radii,
110 const Paint& paint) {
111 builder_.DrawDiffRoundRect(
112 RoundRect::MakeRectRadii(outer_rect, outer_radii), //
113 RoundRect::MakeRectRadii(inner_rect, inner_radii), //
114 paint.GetPaint() //
115 );
116 }
117
118 void DisplayListBuilder::DrawPath(const Path& path, const Paint& paint) {
119 builder_.DrawPath(flutter::DlPath(path.GetPath()), paint.GetPaint());
120 }
121
122 void DisplayListBuilder::DrawPaint(const Paint& paint) {
123 builder_.DrawPaint(paint.GetPaint());
124 }
125
126 void DisplayListBuilder::DrawLine(const Point& from,
127 const Point& to,
128 const Paint& paint) {
129 builder_.DrawLine(from, to, paint.GetPaint());
130 }
131
132 void DisplayListBuilder::DrawDashedLine(const Point& from,
133 const Point& to,
134 Scalar on_length,
135 Scalar off_length,
136 const Paint& paint) {
137 builder_.DrawDashedLine(from, //
138 to, //
139 on_length, //
140 off_length, //
141 paint.GetPaint() //
142 );
143 }
144
145 ScopedObject<DisplayList> DisplayListBuilder::Build() {
146 return Create<DisplayList>(builder_.Build());
147 }
148
149 void DisplayListBuilder::DrawDisplayList(const DisplayList& dl,
150 Scalar opacity) {
151 builder_.DrawDisplayList(dl.GetDisplayList(), opacity);
152 }
153
154 void DisplayListBuilder::DrawTexture(const Texture& texture,
155 const Point& point,
156 flutter::DlImageSampling sampling,
157 const Paint* paint) {
158 builder_.DrawImage(texture.MakeImage(), //
159 point, //
160 sampling, //
161 paint == nullptr ? nullptr : &paint->GetPaint() //
162 );
163 }
164
165 void DisplayListBuilder::DrawTextureRect(const Texture& texture,
166 const Rect& src_rect,
167 const Rect& dst_rect,
168 flutter::DlImageSampling sampling,
169 const Paint* paint) {
170 builder_.DrawImageRect(texture.MakeImage(), //
171 src_rect, //
172 dst_rect, //
173 sampling, //
174 paint == nullptr ? nullptr : &paint->GetPaint() //
175 );
176 }
177
178 void DisplayListBuilder::DrawParagraph(const Paragraph& paragraph,
179 Point point) {
180 const auto& handle = paragraph.GetHandle();
181 if (!handle) {
182 return;
183 }
184 handle->Paint(&builder_, point.x, point.y);
185 }
186
187 } // namespace impeller::interop
impeller::interop::DisplayListBuilder::DrawRoundedRect
void DrawRoundedRect(const Rect &rect, const RoundingRadii &radii, const Paint &paint)
Definition: dl_builder.cc:98
impeller::RoundingRadii
Definition: rounding_radii.h:14
impeller::interop::DisplayListBuilder::DrawParagraph
void DrawParagraph(const Paragraph &paragraph, Point point)
Definition: dl_builder.cc:178
impeller::interop::DisplayListBuilder::ClipPath
void ClipPath(const Path &path, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:85
impeller::TPoint::y
Type y
Definition: point.h:31
dl_builder.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
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:105
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:149
impeller::interop::DisplayListBuilder::~DisplayListBuilder
~DisplayListBuilder() override
impeller::interop::DisplayListBuilder::Translate
void Translate(Point translation)
Definition: dl_builder.cc:41
impeller::DlPath
flutter::DlPath DlPath
Definition: dl_dispatcher.h:28
impeller::interop::DisplayListBuilder::ClipOval
void ClipOval(const Rect &rect, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:74
impeller::interop::DisplayListBuilder::DisplayListBuilder
DisplayListBuilder(const ImpellerRect *rect)
Definition: dl_builder.cc:11
ImpellerRect
Definition: impeller.h:440
impeller::interop::DisplayListBuilder::DrawOval
void DrawOval(const Rect &oval_bounds, const Paint &paint)
Definition: dl_builder.cc:94
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:165
impeller::interop::DisplayListBuilder::Rotate
void Rotate(Degrees angle)
Definition: dl_builder.cc:37
impeller::interop::DisplayListBuilder::ClipRect
void ClipRect(const Rect &rect, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:69
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:49
impeller::interop::Paragraph::GetHandle
const std::unique_ptr< txt::Paragraph > & GetHandle() const
Definition: paragraph.cc:46
impeller::interop::DisplayListBuilder::DrawTexture
void DrawTexture(const Texture &texture, const Point &point, flutter::DlImageSampling sampling, const Paint *paint)
Definition: dl_builder.cc:154
impeller::interop::DisplayListBuilder::DrawRect
void DrawRect(const Rect &rect, const Paint &paint)
Definition: dl_builder.cc:90
impeller::TSize< Scalar >
impeller::interop::DisplayListBuilder::GetTransform
Matrix GetTransform() const
Definition: dl_builder.cc:45
impeller::interop::DisplayListBuilder::Transform
void Transform(const Matrix &matrix)
Definition: dl_builder.cc:53
impeller::interop::DisplayListBuilder::ClipRoundedRect
void ClipRoundedRect(const Rect &rect, const RoundingRadii &radii, flutter::DlCanvas::ClipOp op)
Definition: dl_builder.cc:79
impeller::interop::ImageFilter::GetImageFilter
const std::shared_ptr< flutter::DlImageFilter > & GetImageFilter() const
Definition: image_filter.cc:64
impeller::interop::DisplayListBuilder::GetSaveCount
uint32_t GetSaveCount() const
Definition: dl_builder.cc:61
impeller::interop::DisplayList
Definition: dl.h:14
formats.h
impeller::interop::ImageFilter
Definition: image_filter.h:15
impeller::interop::DisplayListBuilder::Scale
void Scale(Size scale)
Definition: dl_builder.cc:33
impeller::interop::Path::GetPath
const SkPath & GetPath() const
Definition: path.cc:13
impeller::RoundRect::MakeRectRadii
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition: round_rect.cc:9
impeller::interop::DisplayListBuilder::DrawLine
void DrawLine(const Point &from, const Point &to, const Paint &paint)
Definition: dl_builder.cc:126
impeller::interop::DisplayListBuilder::Build
ScopedObject< DisplayList > Build()
Definition: dl_builder.cc:145
impeller::interop::DisplayListBuilder::SaveLayer
void SaveLayer(const Rect &bounds, const Paint *paint, const ImageFilter *backdrop)
Definition: dl_builder.cc:20
impeller::interop::DisplayListBuilder::DrawPath
void DrawPath(const Path &path, const Paint &paint)
Definition: dl_builder.cc:118
impeller::TPoint::x
Type x
Definition: point.h:30
impeller::interop::DisplayListBuilder::Restore
void Restore()
Definition: dl_builder.cc:29
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::TPoint< Scalar >
impeller::interop::Path
Definition: path.h:15
impeller::interop::Paint::GetPaint
const flutter::DlPaint & GetPaint() const
Definition: paint.cc:13
scale
const Scalar scale
Definition: stroke_path_geometry.cc:316
impeller::interop::DisplayListBuilder::Save
void Save()
Definition: dl_builder.cc:16
impeller::Degrees
Definition: scalar.h:51
impeller::interop::DisplayListBuilder::RestoreToCount
void RestoreToCount(uint32_t count)
Definition: dl_builder.cc:65
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:132
impeller::interop::DisplayListBuilder::ResetTransform
void ResetTransform()
Definition: dl_builder.cc:57
impeller::interop::DisplayListBuilder::DrawPaint
void DrawPaint(const Paint &paint)
Definition: dl_builder.cc:122
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37