1010#include " impeller/entity/content_renderer.h"
1111#include " impeller/entity/entity.h"
1212#include " impeller/geometry/path_builder.h"
13+ #include " impeller/geometry/vector.h"
1314#include " impeller/renderer/render_pass.h"
1415#include " impeller/renderer/sampler_library.h"
1516#include " impeller/renderer/surface.h"
@@ -236,13 +237,11 @@ bool TextureContents::Render(const ContentRenderer& renderer,
236237 frame_info.mvp =
237238 Matrix::MakeOrthographic (surface.GetSize ()) * entity.GetTransformation ();
238239
239- auto frame_info_view = host_buffer.EmplaceUniform (frame_info);
240-
241240 Command cmd;
242241 cmd.label = " TextureFill" ;
243242 cmd.pipeline = renderer.GetTexturePipeline ();
244243 cmd.BindVertices (vertex_builder.CreateVertexBuffer (host_buffer));
245- VS::BindFrameInfo (cmd, frame_info_view );
244+ VS::BindFrameInfo (cmd, host_buffer. EmplaceUniform (frame_info) );
246245 FS::BindTextureSampler (
247246 cmd, texture_,
248247 renderer.GetContext ()->GetSamplerLibrary ()->GetSampler ({}));
@@ -275,6 +274,45 @@ const Color& SolidStrokeContents::GetColor() const {
275274 return color_;
276275}
277276
277+ static VertexBuffer CreateSolidStrokeVertices (const Path& path,
278+ HostBuffer& buffer) {
279+ using VS = SolidStrokeVertexShader;
280+
281+ VertexBufferBuilder<VS::PerVertexData> vtx_builder;
282+ auto polyline = path.CreatePolyline ();
283+
284+ for (size_t i = 0 , polyline_size = polyline.size (); i < polyline_size; i++) {
285+ const auto is_last_point = i == polyline_size - 1 ;
286+
287+ const auto & p1 = polyline[i];
288+ const auto & p2 = is_last_point ? polyline[i - 1 ] : polyline[i + 1 ];
289+
290+ const auto diff = p2 - p1;
291+
292+ const Scalar direction = is_last_point ? -1.0 : 1.0 ;
293+
294+ const auto normal =
295+ Point{-diff.y * direction, diff.x * direction}.Normalize ();
296+
297+ VS::PerVertexData vtx;
298+ vtx.vertex_position = p1;
299+
300+ if (i == 0 ) {
301+ vtx.vertex_normal = -normal;
302+ vtx_builder.AppendVertex (vtx);
303+ vtx.vertex_normal = normal;
304+ vtx_builder.AppendVertex (vtx);
305+ }
306+
307+ vtx.vertex_normal = normal;
308+ vtx_builder.AppendVertex (vtx);
309+ vtx.vertex_normal = -normal;
310+ vtx_builder.AppendVertex (vtx);
311+ }
312+
313+ return vtx_builder.CreateVertexBuffer (buffer);
314+ }
315+
278316bool SolidStrokeContents::Render (const ContentRenderer& renderer,
279317 const Entity& entity,
280318 const Surface& surface,
@@ -283,7 +321,29 @@ bool SolidStrokeContents::Render(const ContentRenderer& renderer,
283321 return true ;
284322 }
285323
286- return false ;
324+ using VS = SolidStrokeVertexShader;
325+
326+ VS::FrameInfo frame_info;
327+ frame_info.mvp =
328+ Matrix::MakeOrthographic (surface.GetSize ()) * entity.GetTransformation ();
329+
330+ VS::StrokeInfo stroke_info;
331+ stroke_info.color = color_;
332+ stroke_info.size = stroke_size_;
333+
334+ Command cmd;
335+ cmd.primitive_type = PrimitiveType::kTriangleStrip ;
336+ cmd.label = " SolidStroke" ;
337+ cmd.pipeline = renderer.GetSolidStrokePipeline ();
338+ cmd.BindVertices (
339+ CreateSolidStrokeVertices (entity.GetPath (), pass.GetTransientsBuffer ()));
340+ VS::BindFrameInfo (cmd, pass.GetTransientsBuffer ().EmplaceUniform (frame_info));
341+ VS::BindStrokeInfo (cmd,
342+ pass.GetTransientsBuffer ().EmplaceUniform (stroke_info));
343+
344+ pass.AddCommand (std::move (cmd));
345+
346+ return true ;
287347}
288348
289349void SolidStrokeContents::SetStrokeSize (Scalar size) {
0 commit comments