@@ -207,49 +207,173 @@ TEST_P(DisplayListTest, CanDrawArc) {
207207}
208208
209209TEST_P (DisplayListTest, StrokedPathsDrawCorrectly) {
210- flutter::DisplayListBuilder builder;
211- builder. setColor (SK_ColorRED) ;
212- builder.setStyle (flutter::DlDrawStyle:: kStroke );
213- builder.setStrokeWidth ( 10 );
210+ auto callback = [&]() {
211+ flutter::DisplayListBuilder builder;
212+ builder.setColor (SK_ColorRED );
213+ builder.setStyle (flutter::DlDrawStyle:: kStroke );
214214
215- // Rectangle
216- builder.translate (100 , 100 );
217- builder.drawRect (SkRect::MakeSize ({100 , 100 }));
215+ static float stroke_width = 10 .0f ;
216+ static int selected_stroke_type = 0 ;
217+ static int selected_join_type = 0 ;
218+ const char * stroke_types[] = {" Butte" , " Round" , " Square" };
219+ const char * join_type[] = {" kMiter" , " Round" , " kBevel" };
218220
219- // Rounded rectangle
220- builder.translate (150 , 0 );
221- builder.drawRRect (SkRRect::MakeRectXY (SkRect::MakeSize ({100 , 50 }), 10 , 10 ));
221+ ImGui::Begin (" Controls" , nullptr , ImGuiWindowFlags_AlwaysAutoResize);
222+ ImGui::Combo (" Cap" , &selected_stroke_type, stroke_types,
223+ sizeof (stroke_types) / sizeof (char *));
224+ ImGui::Combo (" Join" , &selected_join_type, join_type,
225+ sizeof (join_type) / sizeof (char *));
226+ ImGui::SliderFloat (" Stroke Width" , &stroke_width, 10 .0f , 50 .0f );
227+ ImGui::End ();
222228
223- // Double rounded rectangle
224- builder.translate (150 , 0 );
225- builder.drawDRRect (
226- SkRRect::MakeRectXY (SkRect::MakeSize ({100 , 50 }), 10 , 10 ),
227- SkRRect::MakeRectXY (SkRect::MakeXYWH (10 , 10 , 80 , 30 ), 10 , 10 ));
229+ flutter::DlStrokeCap cap;
230+ flutter::DlStrokeJoin join;
231+ switch (selected_stroke_type) {
232+ case 0 :
233+ cap = flutter::DlStrokeCap::kButt ;
234+ break ;
235+ case 1 :
236+ cap = flutter::DlStrokeCap::kRound ;
237+ break ;
238+ case 2 :
239+ cap = flutter::DlStrokeCap::kSquare ;
240+ break ;
241+ default :
242+ cap = flutter::DlStrokeCap::kButt ;
243+ break ;
244+ }
245+ switch (selected_join_type) {
246+ case 0 :
247+ join = flutter::DlStrokeJoin::kMiter ;
248+ break ;
249+ case 1 :
250+ join = flutter::DlStrokeJoin::kRound ;
251+ break ;
252+ case 2 :
253+ join = flutter::DlStrokeJoin::kBevel ;
254+ break ;
255+ default :
256+ join = flutter::DlStrokeJoin::kMiter ;
257+ break ;
258+ }
259+ builder.setStrokeCap (cap);
260+ builder.setStrokeJoin (join);
261+ builder.setStrokeWidth (stroke_width);
228262
229- // Contour with duplicate join points
230- {
263+ // Make rendering better to watch.
264+ builder.scale (1 .5f , 1 .5f );
265+
266+ // Rectangle
267+ builder.translate (100 , 100 );
268+ builder.drawRect (SkRect::MakeSize ({100 , 100 }));
269+
270+ // Rounded rectangle
231271 builder.translate (150 , 0 );
232- SkPath path;
233- path.lineTo ({100 , 0 });
234- path.lineTo ({100 , 0 });
235- path.lineTo ({100 , 100 });
236- builder.drawPath (path);
237- }
272+ builder.drawRRect (SkRRect::MakeRectXY (SkRect::MakeSize ({100 , 50 }), 10 , 10 ));
238273
239- // Contour with duplicate end points
240- {
241- builder.setStrokeCap (flutter::DlStrokeCap::kRound );
274+ // Double rounded rectangle
242275 builder.translate (150 , 0 );
243- SkPath path;
244- path.moveTo (0 , 0 );
245- path.lineTo ({0 , 0 });
246- path.lineTo ({50 , 50 });
247- path.lineTo ({100 , 0 });
248- path.lineTo ({100 , 0 });
249- builder.drawPath (path);
250- }
276+ builder.drawDRRect (
277+ SkRRect::MakeRectXY (SkRect::MakeSize ({100 , 50 }), 10 , 10 ),
278+ SkRRect::MakeRectXY (SkRect::MakeXYWH (10 , 10 , 80 , 30 ), 10 , 10 ));
251279
252- ASSERT_TRUE (OpenPlaygroundHere (builder.Build ()));
280+ // Contour with duplicate join points
281+ {
282+ builder.translate (150 , 0 );
283+ SkPath path;
284+ path.moveTo (0 , 0 );
285+ path.lineTo (0 , 0 );
286+ path.lineTo ({100 , 0 });
287+ path.lineTo ({100 , 0 });
288+ path.lineTo ({100 , 100 });
289+ builder.drawPath (path);
290+ }
291+
292+ // Contour with duplicate start and end points
293+
294+ // Line.
295+ builder.translate (200 , 0 );
296+ {
297+ builder.save ();
298+
299+ SkPath line_path;
300+ line_path.moveTo (0 , 0 );
301+ line_path.moveTo (0 , 0 );
302+ line_path.lineTo ({0 , 0 });
303+ line_path.lineTo ({0 , 0 });
304+ line_path.lineTo ({50 , 50 });
305+ line_path.lineTo ({50 , 50 });
306+ line_path.lineTo ({100 , 0 });
307+ line_path.lineTo ({100 , 0 });
308+ builder.drawPath (line_path);
309+
310+ builder.translate (0 , 100 );
311+ builder.drawPath (line_path);
312+
313+ builder.translate (0 , 100 );
314+ SkPath line_path2;
315+ line_path2.moveTo (0 , 0 );
316+ line_path2.lineTo (0 , 0 );
317+ line_path2.lineTo (0 , 0 );
318+ builder.drawPath (line_path2);
319+
320+ builder.restore ();
321+ }
322+
323+ // Cubic.
324+ builder.translate (150 , 0 );
325+ {
326+ builder.save ();
327+
328+ SkPath cubic_path;
329+ cubic_path.moveTo ({0 , 0 });
330+ cubic_path.cubicTo (0 , 0 , 140.0 , 100.0 , 140 , 20 );
331+ builder.drawPath (cubic_path);
332+
333+ builder.translate (0 , 100 );
334+ SkPath cubic_path2;
335+ cubic_path2.moveTo ({0 , 0 });
336+ cubic_path2.cubicTo (0 , 0 , 0 , 0 , 150 , 150 );
337+ builder.drawPath (cubic_path2);
338+
339+ builder.translate (0 , 100 );
340+ SkPath cubic_path3;
341+ cubic_path3.moveTo ({0 , 0 });
342+ cubic_path3.cubicTo (0 , 0 , 0 , 0 , 0 , 0 );
343+ builder.drawPath (cubic_path3);
344+
345+ builder.restore ();
346+ }
347+
348+ // Quad.
349+ builder.translate (200 , 0 );
350+ {
351+ builder.save ();
352+
353+ SkPath quad_path;
354+ quad_path.moveTo (0 , 0 );
355+ quad_path.moveTo (0 , 0 );
356+ quad_path.quadTo ({100 , 40 }, {50 , 80 });
357+ builder.drawPath (quad_path);
358+
359+ builder.translate (0 , 150 );
360+ SkPath quad_path2;
361+ quad_path2.moveTo (0 , 0 );
362+ quad_path2.moveTo (0 , 0 );
363+ quad_path2.quadTo ({0 , 0 }, {100 , 100 });
364+ builder.drawPath (quad_path2);
365+
366+ builder.translate (0 , 100 );
367+ SkPath quad_path3;
368+ quad_path3.moveTo (0 , 0 );
369+ quad_path3.quadTo ({0 , 0 }, {0 , 0 });
370+ builder.drawPath (quad_path3);
371+
372+ builder.restore ();
373+ }
374+ return builder.Build ();
375+ };
376+ ASSERT_TRUE (OpenPlaygroundHere (callback));
253377}
254378
255379TEST_P (DisplayListTest, CanDrawWithOddPathWinding) {
0 commit comments