@@ -282,7 +282,11 @@ const IRect& TextureContents::GetSourceRect() const {
282
282
******* SolidStrokeContents
283
283
******************************************************************************/
284
284
285
- SolidStrokeContents::SolidStrokeContents () = default ;
285
+ SolidStrokeContents::SolidStrokeContents () {
286
+ SetStrokeCap (Cap::kButt );
287
+ // TODO(99089): Change this to kMiter once implemented.
288
+ SetStrokeJoin (Join::kBevel );
289
+ }
286
290
287
291
SolidStrokeContents::~SolidStrokeContents () = default ;
288
292
@@ -294,32 +298,11 @@ const Color& SolidStrokeContents::GetColor() const {
294
298
return color_;
295
299
}
296
300
297
- static void CreateCap (
298
- VertexBufferBuilder<SolidStrokeVertexShader::PerVertexData>& vtx_builder,
299
- const Point & position,
300
- const Point & normal ) {}
301
-
302
- static void CreateJoin (
303
- VertexBufferBuilder<SolidStrokeVertexShader::PerVertexData>& vtx_builder,
304
- const Point & position,
305
- const Point & start_normal,
306
- const Point & end_normal) {
307
- SolidStrokeVertexShader::PerVertexData vtx;
308
- vtx.vertex_position = position;
309
- vtx.pen_down = 1.0 ;
310
- vtx.vertex_normal = {};
311
- vtx_builder.AppendVertex (vtx);
312
-
313
- // A simple bevel join to start with.
314
- Scalar dir = start_normal.Cross (end_normal) > 0 ? -1 : 1 ;
315
- vtx.vertex_normal = start_normal * dir;
316
- vtx_builder.AppendVertex (vtx);
317
- vtx.vertex_normal = end_normal * dir;
318
- vtx_builder.AppendVertex (vtx);
319
- }
320
-
321
- static VertexBuffer CreateSolidStrokeVertices (const Path& path,
322
- HostBuffer& buffer) {
301
+ static VertexBuffer CreateSolidStrokeVertices (
302
+ const Path& path,
303
+ HostBuffer& buffer,
304
+ const SolidStrokeContents::CapProc& cap_proc,
305
+ const SolidStrokeContents::JoinProc& join_proc) {
323
306
using VS = SolidStrokeVertexShader;
324
307
325
308
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
@@ -372,7 +355,7 @@ static VertexBuffer CreateSolidStrokeVertices(const Path& path,
372
355
373
356
// Generate start cap.
374
357
if (!polyline.contours [contour_i].is_closed ) {
375
- CreateCap (vtx_builder, polyline.points [contour_start_point_i], -normal );
358
+ cap_proc (vtx_builder, polyline.points [contour_start_point_i], -normal );
376
359
}
377
360
378
361
// Generate contour geometry.
@@ -396,18 +379,18 @@ static VertexBuffer CreateSolidStrokeVertices(const Path& path,
396
379
compute_normal (point_i + 1 );
397
380
398
381
// Generate join from the current line to the next line.
399
- CreateJoin (vtx_builder, polyline.points [point_i], previous_normal,
400
- normal );
382
+ join_proc (vtx_builder, polyline.points [point_i], previous_normal,
383
+ normal );
401
384
}
402
385
}
403
386
}
404
387
405
388
// Generate end cap or join.
406
389
if (!polyline.contours [contour_i].is_closed ) {
407
- CreateCap (vtx_builder, polyline.points [contour_end_point_i - 1 ], normal );
390
+ cap_proc (vtx_builder, polyline.points [contour_end_point_i - 1 ], normal );
408
391
} else {
409
- CreateJoin (vtx_builder, polyline.points [contour_start_point_i], normal ,
410
- contour_first_normal);
392
+ join_proc (vtx_builder, polyline.points [contour_start_point_i], normal ,
393
+ contour_first_normal);
411
394
}
412
395
}
413
396
@@ -436,8 +419,8 @@ bool SolidStrokeContents::Render(const ContentContext& renderer,
436
419
cmd.label = " SolidStroke" ;
437
420
cmd.pipeline = renderer.GetSolidStrokePipeline (OptionsFromPass (pass));
438
421
cmd.stencil_reference = entity.GetStencilDepth ();
439
- cmd.BindVertices (
440
- CreateSolidStrokeVertices ( entity.GetPath (), pass.GetTransientsBuffer ()));
422
+ cmd.BindVertices (CreateSolidStrokeVertices (
423
+ entity.GetPath (), pass.GetTransientsBuffer (), cap_proc_, join_proc_ ));
441
424
VS::BindFrameInfo (cmd, pass.GetTransientsBuffer ().EmplaceUniform (frame_info));
442
425
VS::BindStrokeInfo (cmd,
443
426
pass.GetTransientsBuffer ().EmplaceUniform (stroke_info));
@@ -465,6 +448,20 @@ Scalar SolidStrokeContents::GetStrokeMiter(Scalar miter) {
465
448
466
449
void SolidStrokeContents::SetStrokeCap (Cap cap) {
467
450
cap_ = cap;
451
+
452
+ using VS = SolidStrokeVertexShader;
453
+ switch (cap) {
454
+ case Cap::kButt :
455
+ cap_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
456
+ const Point & position, const Point & normal ) {};
457
+ break ;
458
+ case Cap::kRound :
459
+ FML_DLOG (ERROR) << " Unimplemented." ;
460
+ break ;
461
+ case Cap::kSquare :
462
+ FML_DLOG (ERROR) << " Unimplemented." ;
463
+ break ;
464
+ }
468
465
}
469
466
470
467
SolidStrokeContents::Cap SolidStrokeContents::GetStrokeCap () {
@@ -473,6 +470,33 @@ SolidStrokeContents::Cap SolidStrokeContents::GetStrokeCap() {
473
470
474
471
void SolidStrokeContents::SetStrokeJoin (Join join) {
475
472
join_ = join;
473
+
474
+ using VS = SolidStrokeVertexShader;
475
+ switch (join) {
476
+ case Join::kBevel :
477
+ join_proc_ = [](VertexBufferBuilder<VS::PerVertexData>& vtx_builder,
478
+ const Point & position, const Point & start_normal,
479
+ const Point & end_normal) {
480
+ SolidStrokeVertexShader::PerVertexData vtx;
481
+ vtx.vertex_position = position;
482
+ vtx.pen_down = 1.0 ;
483
+ vtx.vertex_normal = {};
484
+ vtx_builder.AppendVertex (vtx);
485
+
486
+ Scalar dir = start_normal.Cross (end_normal) > 0 ? -1 : 1 ;
487
+ vtx.vertex_normal = start_normal * dir;
488
+ vtx_builder.AppendVertex (vtx);
489
+ vtx.vertex_normal = end_normal * dir;
490
+ vtx_builder.AppendVertex (vtx);
491
+ };
492
+ break ;
493
+ case Join::kMiter :
494
+ FML_DLOG (ERROR) << " Unimplemented." ;
495
+ break ;
496
+ case Join::kRound :
497
+ FML_DLOG (ERROR) << " Unimplemented." ;
498
+ break ;
499
+ }
476
500
}
477
501
478
502
SolidStrokeContents::Join SolidStrokeContents::GetStrokeJoin () {
0 commit comments