34enum class RenderType {
47struct RenderParameters {
48 RenderType render_type =
59void RenderPrimitiveWithStroke(DisplayListBuilder& builder,
60 const RenderParameters&
params) {
64 builder.Rotate(
params.degrees);
73 const DlScalar stroke_radius = base_radius - 10.0f;
76 DlScalar stroke_width = -1) ->
void {
79 if (stroke_width < 0) {
87 DlRect square_bounds = DlRect::MakeCircleBounds(
params.center, radius);
91 switch (
params.render_type) {
92 case RenderType::kSquare:
93 builder.DrawRect(square_bounds, paint);
95 case RenderType::kRectangle:
96 builder.DrawRect(rect_bounds, paint);
98 case RenderType::kCircle:
99 builder.DrawCircle(
params.center, radius, paint);
101 case RenderType::kOval:
102 builder.DrawOval(rect_bounds, paint);
104 case RenderType::kLine: {
110 if (stroke_width < 0) {
111 if (radius <= stroke_radius) {
115 paint.setDrawStyle(DlDrawStyle::kStroke);
116 paint.setStrokeWidth((radius - stroke_radius) * 2.0f);
119 DlPoint fill_offset(radius, 0.0f);
120 builder.DrawLine(
params.center - fill_offset,
121 params.center + fill_offset,
125 case RenderType::kValidCount:
126 case RenderType::kInvalid:
131 draw_shape(fill_radius, DlColor::kBlue());
132 draw_shape(stroke_radius, DlColor::ARGB(1.0f, 0.0f, 0.0f, 0.5f));
133 draw_shape(stroke_radius, DlColor::kWhite(),
params.stroke_width);
148 if (IsGoldenTest()) {
149 GTEST_SKIP() <<
"PrimitiveShapePlayground does not produce a golden image";
153 .render_type = RenderType::kRectangle,
154 .center = GetWindowBounds().GetCenter(),
159 int render_type_index =
static_cast<int>(RenderType::kRectangle);
161 auto callback = [&]() -> sk_sp<DisplayList> {
163 ImGuiWindowFlags_AlwaysAutoResize)) {
164 ImGui::SliderFloat(
"Stroke", &
params.stroke_width, 0.0f, 30.0f);
165 ImGui::SliderFloat(
"X Scale", &
params.scale_x, 1.0f, 3.0f);
166 ImGui::SliderFloat(
"Y Scale", &
params.scale_y, 1.0f, 3.0f);
167 ImGui::SliderFloat(
"X Skew", &
params.skew_x, 0.0f, 1.0f);
168 ImGui::SliderFloat(
"Y Skew", &
params.skew_y, 0.0f, 1.0f);
169 ImGui::SliderFloat(
"Rotation", &
params.degrees, 0.0f, 360.0f);
171 "Shape Type", &render_type_index,
172 [](
void*
data,
int index) {
173 switch (
static_cast<RenderType
>(index)) {
174 case RenderType::kSquare:
176 case RenderType::kRectangle:
178 case RenderType::kCircle:
180 case RenderType::kOval:
182 case RenderType::kLine:
184 case RenderType::kValidCount:
185 case RenderType::kInvalid:
189 nullptr,
static_cast<int>(RenderType::kValidCount), -1);
194 params.render_type =
static_cast<RenderType
>(render_type_index);
197 builder.
Scale(GetContentScale().x, GetContentScale().y);
199 RenderPrimitiveWithStroke(builder,
params);
200 return builder.
Build();
203 ASSERT_TRUE(OpenPlaygroundHere(
callback));
208 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
212 .render_type = RenderType::kCircle,
213 .center = GetWindowBounds().GetCenter(),
217 RenderPrimitiveWithStroke(builder,
params);
219 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
void DrawColor(DlColor color, DlBlendMode mode) override
void Scale(DlScalar sx, DlScalar sy) override
sk_sp< DisplayList > Build()
DlPaint & setColor(DlColor color)
DlPaint & setStrokeWidth(float width)
DlPaint & setDrawStyle(DlDrawStyle style)
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
const EmbeddedViewParams * params
FlutterDesktopBinaryReply callback
#define FML_UNREACHABLE()
impeller::Scalar DlScalar
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
TEST_P(AiksTest, DrawAtlasNoColor)
static constexpr DlColor kBlack()
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.