diff --git a/engine/src/flutter/impeller/aiks/canvas.cc b/engine/src/flutter/impeller/aiks/canvas.cc index 4a4fc7ad4b..62b63ed26e 100644 --- a/engine/src/flutter/impeller/aiks/canvas.cc +++ b/engine/src/flutter/impeller/aiks/canvas.cc @@ -542,7 +542,7 @@ void Canvas::DrawTextFrame(const TextFrame& text_frame, entity.SetBlendMode(paint.blend_mode); auto text_contents = std::make_shared(); - text_contents->SetTextFrame(text_frame); + text_contents->SetTextFrame(TextFrame(text_frame)); if (paint.color_source.GetType() != ColorSource::Type::kColor) { auto color_text_contents = std::make_shared(); diff --git a/engine/src/flutter/impeller/entity/contents/text_contents.cc b/engine/src/flutter/impeller/entity/contents/text_contents.cc index 9267771b9c..d8e68b2929 100644 --- a/engine/src/flutter/impeller/entity/contents/text_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/text_contents.cc @@ -23,8 +23,8 @@ TextContents::TextContents() = default; TextContents::~TextContents() = default; -void TextContents::SetTextFrame(const TextFrame& frame) { - frame_ = frame; +void TextContents::SetTextFrame(TextFrame&& frame) { + frame_ = std::move(frame); } std::shared_ptr TextContents::ResolveAtlas( @@ -168,22 +168,24 @@ bool TextContents::Render(const ContentContext& renderer, vertex_count * sizeof(VS::PerVertexData), alignof(VS::PerVertexData), [&](uint8_t* contents) { VS::PerVertexData vtx; - size_t vertex_offset = 0; - for (const auto& run : frame_.GetRuns()) { + VS::PerVertexData* vtx_contents = + reinterpret_cast(contents); + for (const TextRun& run : frame_.GetRuns()) { const Font& font = run.GetFont(); - auto rounded_scale = TextFrame::RoundScaledFontSize( + Scalar rounded_scale = TextFrame::RoundScaledFontSize( scale_, font.GetMetrics().point_size); - for (const auto& glyph_position : run.GetGlyphPositions()) { + for (const TextRun::GlyphPosition& glyph_position : + run.GetGlyphPositions()) { FontGlyphPair font_glyph_pair{font, glyph_position.glyph, rounded_scale}; - auto maybe_atlas_glyph_bounds = + std::optional maybe_atlas_glyph_bounds = atlas->FindFontGlyphBounds(font_glyph_pair); if (!maybe_atlas_glyph_bounds.has_value()) { VALIDATION_LOG << "Could not find glyph position in the atlas."; continue; } - auto atlas_glyph_bounds = maybe_atlas_glyph_bounds.value(); + const Rect& atlas_glyph_bounds = maybe_atlas_glyph_bounds.value(); vtx.atlas_glyph_bounds = Vector4( atlas_glyph_bounds.origin.x, atlas_glyph_bounds.origin.y, atlas_glyph_bounds.size.width, atlas_glyph_bounds.size.height); @@ -193,11 +195,9 @@ bool TextContents::Render(const ContentContext& renderer, glyph_position.glyph.bounds.size.height); vtx.glyph_position = glyph_position.position; - for (const auto& point : unit_points) { + for (const Point& point : unit_points) { vtx.unit_position = point; - ::memcpy(contents + vertex_offset, &vtx, - sizeof(VS::PerVertexData)); - vertex_offset += sizeof(VS::PerVertexData); + ::memcpy(vtx_contents++, &vtx, sizeof(VS::PerVertexData)); } } } diff --git a/engine/src/flutter/impeller/entity/contents/text_contents.h b/engine/src/flutter/impeller/entity/contents/text_contents.h index 70f83d10e4..6e3b89d558 100644 --- a/engine/src/flutter/impeller/entity/contents/text_contents.h +++ b/engine/src/flutter/impeller/entity/contents/text_contents.h @@ -26,7 +26,7 @@ class TextContents final : public Contents { ~TextContents(); - void SetTextFrame(const TextFrame& frame); + void SetTextFrame(TextFrame&& frame); void SetColor(Color color); diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index 90edc60222..2c7e34e83f 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -2180,7 +2180,7 @@ TEST_P(EntityTest, InheritOpacityTest) { lazy_glyph_atlas->AddTextFrame(frame, 1.0f); auto text_contents = std::make_shared(); - text_contents->SetTextFrame(frame); + text_contents->SetTextFrame(std::move(frame)); text_contents->SetColor(Color::Blue().WithAlpha(0.5)); ASSERT_TRUE(text_contents->CanInheritOpacity(entity)); diff --git a/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc b/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc index d458499c9d..02dfab82aa 100644 --- a/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc +++ b/engine/src/flutter/impeller/typographer/backends/skia/text_frame_skia.cc @@ -97,7 +97,7 @@ TextFrame TextFrameFromTextBlob(const sk_sp& blob) { FML_DLOG(ERROR) << "Unimplemented."; continue; } - frame.AddTextRun(text_run); + frame.AddTextRun(std::move(text_run)); } return frame; diff --git a/engine/src/flutter/impeller/typographer/text_frame.cc b/engine/src/flutter/impeller/typographer/text_frame.cc index c62023666e..898f69bdfe 100644 --- a/engine/src/flutter/impeller/typographer/text_frame.cc +++ b/engine/src/flutter/impeller/typographer/text_frame.cc @@ -25,12 +25,12 @@ std::optional TextFrame::GetBounds() const { return result; } -bool TextFrame::AddTextRun(const TextRun& run) { +bool TextFrame::AddTextRun(TextRun&& run) { if (!run.IsValid()) { return false; } has_color_ |= run.HasColor(); - runs_.emplace_back(run); + runs_.emplace_back(std::move(run)); return true; } diff --git a/engine/src/flutter/impeller/typographer/text_frame.h b/engine/src/flutter/impeller/typographer/text_frame.h index 834528c72b..54ea12df30 100644 --- a/engine/src/flutter/impeller/typographer/text_frame.h +++ b/engine/src/flutter/impeller/typographer/text_frame.h @@ -48,7 +48,7 @@ class TextFrame { /// /// @return If the text run could be added to this frame. /// - bool AddTextRun(const TextRun& run); + bool AddTextRun(TextRun&& run); //---------------------------------------------------------------------------- /// @brief Returns a reference to all the text runs in this frame. @@ -71,6 +71,10 @@ class TextFrame { /// @brief The type of atlas this run should be emplaced in. GlyphAtlas::Type GetAtlasType() const; + TextFrame& operator=(TextFrame&& other) = default; + + TextFrame(const TextFrame& other) = default; + private: std::vector runs_; bool has_color_ = false;