From 12f4ae6d564a3859a84dcc9afd64e04b5983f89e Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 11 Jan 2024 14:05:22 -0800 Subject: [PATCH] [Impeller] dont accidentally copy shared ptr. (flutter/engine#49731) Copying the shared ptr when we don't need to results in us incrementing/decrementing the ref count which isn't free. --- .../impeller/entity/contents/solid_color_contents.cc | 3 ++- .../flutter/impeller/entity/contents/vertices_contents.cc | 6 ++++-- .../flutter/impeller/entity/geometry/round_rect_geometry.cc | 4 ---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc index 2683bf07e0..38e19c40a1 100644 --- a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc @@ -7,6 +7,7 @@ #include "impeller/entity/contents/clip_contents.h" #include "impeller/entity/contents/content_context.h" #include "impeller/entity/entity.h" +#include "impeller/entity/geometry/geometry.h" #include "impeller/geometry/path.h" #include "impeller/renderer/render_pass.h" @@ -38,7 +39,7 @@ std::optional SolidColorContents::GetCoverage( return std::nullopt; } - auto geometry = GetGeometry(); + const std::shared_ptr& geometry = GetGeometry(); if (geometry == nullptr) { return std::nullopt; } diff --git a/engine/src/flutter/impeller/entity/contents/vertices_contents.cc b/engine/src/flutter/impeller/entity/contents/vertices_contents.cc index 46ff686220..0825ac6b0a 100644 --- a/engine/src/flutter/impeller/entity/contents/vertices_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/vertices_contents.cc @@ -6,6 +6,8 @@ #include "impeller/entity/contents/content_context.h" #include "impeller/entity/contents/filters/color_filter_contents.h" +#include "impeller/entity/geometry/geometry.h" +#include "impeller/entity/geometry/vertices_geometry.h" #include "impeller/entity/position_color.vert.h" #include "impeller/entity/vertices.frag.h" #include "impeller/geometry/color.h" @@ -122,7 +124,7 @@ bool VerticesUVContents::Render(const ContentContext& renderer, Command cmd; DEBUG_COMMAND_INFO(cmd, "VerticesUV"); auto& host_buffer = renderer.GetTransientsBuffer(); - auto geometry = parent_.GetGeometry(); + const std::shared_ptr& geometry = parent_.GetGeometry(); auto coverage = src_contents->GetCoverage(Entity{}); if (!coverage.has_value()) { @@ -176,7 +178,7 @@ bool VerticesColorContents::Render(const ContentContext& renderer, Command cmd; DEBUG_COMMAND_INFO(cmd, "VerticesColors"); auto& host_buffer = renderer.GetTransientsBuffer(); - auto geometry = parent_.GetGeometry(); + const std::shared_ptr& geometry = parent_.GetGeometry(); auto geometry_result = geometry->GetPositionColorBuffer(renderer, entity, pass); diff --git a/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc b/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc index 28cf77d979..edcf12074a 100644 --- a/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/round_rect_geometry.cc @@ -2,12 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include - #include "flutter/impeller/entity/geometry/round_rect_geometry.h" -#include "flutter/impeller/entity/geometry/line_geometry.h" - namespace impeller { RoundRectGeometry::RoundRectGeometry(const Rect& bounds, const Size& radii)