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 (!IsPlaygroundEnabled()) {
149 GTEST_SKIP() <<
"PrimitiveShapePlayground is only for on-screen use";
154 SetEnableWriteGolden(
false);
157 .render_type = RenderType::kRectangle,
158 .center = GetWindowBounds().GetCenter(),
163 int render_type_index =
static_cast<int>(RenderType::kRectangle);
165 auto callback = [&]() -> sk_sp<DisplayList> {
167 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
168 ImGui::SliderFloat(
"Stroke", &
params.stroke_width, 0.0f, 30.0f);
169 ImGui::SliderFloat(
"X Scale", &
params.scale_x, 1.0f, 3.0f);
170 ImGui::SliderFloat(
"Y Scale", &
params.scale_y, 1.0f, 3.0f);
171 ImGui::SliderFloat(
"X Skew", &
params.skew_x, 0.0f, 1.0f);
172 ImGui::SliderFloat(
"Y Skew", &
params.skew_y, 0.0f, 1.0f);
173 ImGui::SliderFloat(
"Rotation", &
params.degrees, 0.0f, 360.0f);
175 "Shape Type", &render_type_index,
176 [](
void*
data,
int index) {
177 switch (
static_cast<RenderType
>(index)) {
178 case RenderType::kSquare:
180 case RenderType::kRectangle:
182 case RenderType::kCircle:
184 case RenderType::kOval:
186 case RenderType::kLine:
188 case RenderType::kValidCount:
189 case RenderType::kInvalid:
193 nullptr,
static_cast<int>(RenderType::kValidCount), -1);
197 params.render_type =
static_cast<RenderType
>(render_type_index);
200 builder.
Scale(GetContentScale().x, GetContentScale().y);
202 RenderPrimitiveWithStroke(builder,
params);
203 return builder.
Build();
206 ASSERT_TRUE(OpenPlaygroundHere(
callback));
211 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
215 .render_type = RenderType::kCircle,
216 .center = GetWindowBounds().GetCenter(),
220 RenderPrimitiveWithStroke(builder,
params);
222 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)
const EmbeddedViewParams * params
FlutterDesktopBinaryReply callback
#define FML_CHECK(condition)
#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.