@@ -29,18 +29,15 @@ void TextContents::SetTextFrame(const TextFrame& frame) {
2929  frame_ = frame;
3030}
3131
32- void  TextContents::SetGlyphAtlas (std::shared_ptr<LazyGlyphAtlas> atlas) {
33-   lazy_atlas_ = std::move (atlas);
34- }
35- 
3632std::shared_ptr<GlyphAtlas> TextContents::ResolveAtlas (
3733    GlyphAtlas::Type type,
34+     const  std::shared_ptr<LazyGlyphAtlas>& lazy_atlas,
3835    std::shared_ptr<GlyphAtlasContext> atlas_context,
3936    std::shared_ptr<Context> context) const  {
40-   FML_DCHECK (lazy_atlas_ );
41-   if  (lazy_atlas_ ) {
42-     return  lazy_atlas_ ->CreateOrGetGlyphAtlas (type, std::move (atlas_context),
43-                                                std::move (context));
37+   FML_DCHECK (lazy_atlas );
38+   if  (lazy_atlas ) {
39+     return  lazy_atlas ->CreateOrGetGlyphAtlas (type, std::move (atlas_context),
40+                                              std::move (context));
4441  }
4542
4643  return  nullptr ;
@@ -78,14 +75,43 @@ std::optional<Rect> TextContents::GetCoverage(const Entity& entity) const {
7875  return  bounds->TransformBounds (entity.GetTransformation ());
7976}
8077
81- static  bool  CommonRender (const  ContentContext& renderer,
82-                          const  Entity& entity,
83-                          RenderPass& pass,
84-                          const  Color& color,
85-                          const  TextFrame& frame,
86-                          Vector2 offset,
87-                          const  std::shared_ptr<GlyphAtlas>& atlas,
88-                          Command& cmd) {
78+ void  TextContents::PopulateGlyphAtlas (
79+     const  std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
80+     Scalar scale) {
81+   lazy_glyph_atlas->AddTextFrame (frame_, scale);
82+   scale_ = scale;
83+ }
84+ 
85+ bool  TextContents::Render (const  ContentContext& renderer,
86+                           const  Entity& entity,
87+                           RenderPass& pass) const  {
88+   auto  color = GetColor ();
89+   if  (color.IsTransparent ()) {
90+     return  true ;
91+   }
92+ 
93+   auto  type = frame_.GetAtlasType ();
94+   auto  atlas =
95+       ResolveAtlas (type, renderer.GetLazyGlyphAtlas (),
96+                    renderer.GetGlyphAtlasContext (type), renderer.GetContext ());
97+ 
98+   if  (!atlas || !atlas->IsValid ()) {
99+     VALIDATION_LOG << " Cannot render glyphs without prepared atlas."  ;
100+     return  false ;
101+   }
102+ 
103+   //  Information shared by all glyph draw calls.
104+   Command cmd;
105+   cmd.label  = " TextFrame"  ;
106+   auto  opts = OptionsFromPassAndEntity (pass, entity);
107+   opts.primitive_type  = PrimitiveType::kTriangle ;
108+   if  (type == GlyphAtlas::Type::kAlphaBitmap ) {
109+     cmd.pipeline  = renderer.GetGlyphAtlasPipeline (opts);
110+   } else  {
111+     cmd.pipeline  = renderer.GetGlyphAtlasColorPipeline (opts);
112+   }
113+   cmd.stencil_reference  = entity.GetStencilDepth ();
114+ 
89115  using  VS = GlyphAtlasPipeline::VertexShader;
90116  using  FS = GlyphAtlasPipeline::FragmentShader;
91117
@@ -95,7 +121,7 @@ static bool CommonRender(const ContentContext& renderer,
95121  frame_info.atlas_size  =
96122      Vector2{static_cast <Scalar>(atlas->GetTexture ()->GetSize ().width ),
97123              static_cast <Scalar>(atlas->GetTexture ()->GetSize ().height )};
98-   frame_info.offset  = offset ;
124+   frame_info.offset  = offset_ ;
99125  frame_info.is_translation_scale  =
100126      entity.GetTransformation ().IsTranslationScaleOnly ();
101127  frame_info.entity_transform  = entity.GetTransformation ();
@@ -141,7 +167,7 @@ static bool CommonRender(const ContentContext& renderer,
141167
142168  auto & host_buffer = pass.GetTransientsBuffer ();
143169  size_t  vertex_count = 0 ;
144-   for  (const  auto & run : frame .GetRuns ()) {
170+   for  (const  auto & run : frame_ .GetRuns ()) {
145171    vertex_count += run.GetGlyphPositions ().size ();
146172  }
147173  vertex_count *= 6 ;
@@ -151,10 +177,10 @@ static bool CommonRender(const ContentContext& renderer,
151177      [&](uint8_t * contents) {
152178        VS::PerVertexData vtx;
153179        size_t  vertex_offset = 0 ;
154-         for  (const  auto & run : frame .GetRuns ()) {
180+         for  (const  auto & run : frame_ .GetRuns ()) {
155181          const  Font& font = run.GetFont ();
156182          for  (const  auto & glyph_position : run.GetGlyphPositions ()) {
157-             FontGlyphPair font_glyph_pair{font, glyph_position.glyph };
183+             FontGlyphPair font_glyph_pair{font, glyph_position.glyph , scale_ };
158184            auto  maybe_atlas_glyph_bounds =
159185                atlas->FindFontGlyphBounds (font_glyph_pair);
160186            if  (!maybe_atlas_glyph_bounds.has_value ()) {
@@ -191,37 +217,4 @@ static bool CommonRender(const ContentContext& renderer,
191217  return  pass.AddCommand (cmd);
192218}
193219
194- bool  TextContents::Render (const  ContentContext& renderer,
195-                           const  Entity& entity,
196-                           RenderPass& pass) const  {
197-   auto  color = GetColor ();
198-   if  (color.IsTransparent ()) {
199-     return  true ;
200-   }
201- 
202-   auto  type = frame_.GetAtlasType ();
203-   auto  atlas = ResolveAtlas (type, renderer.GetGlyphAtlasContext (type),
204-                             renderer.GetContext ());
205- 
206-   if  (!atlas || !atlas->IsValid ()) {
207-     VALIDATION_LOG << " Cannot render glyphs without prepared atlas."  ;
208-     return  false ;
209-   }
210- 
211-   //  Information shared by all glyph draw calls.
212-   Command cmd;
213-   cmd.label  = " TextFrame"  ;
214-   auto  opts = OptionsFromPassAndEntity (pass, entity);
215-   opts.primitive_type  = PrimitiveType::kTriangle ;
216-   if  (type == GlyphAtlas::Type::kAlphaBitmap ) {
217-     cmd.pipeline  = renderer.GetGlyphAtlasPipeline (opts);
218-   } else  {
219-     cmd.pipeline  = renderer.GetGlyphAtlasColorPipeline (opts);
220-   }
221-   cmd.stencil_reference  = entity.GetStencilDepth ();
222- 
223-   return  CommonRender (renderer, entity, pass, color, frame_, offset_, atlas,
224-                       cmd);
225- }
226- 
227220}  //  namespace impeller
0 commit comments