From fa1643d9130f3d0128734173b0e357d311390b14 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 7 Nov 2023 17:50:12 -0800 Subject: [PATCH] [macOS] Allocate textures as unique_ptr earlier This cleans up several places where instead of allocating a std::unique_ptr immediately, we were making allocations with the new operator, then later wrapping in a unique_ptr. The previous code was correct but there was no reason not to allocate a unique_ptr immediately. This code makes no semantic changes; just applies a stylistic improvement that makes the code very slightly safer. --- .../FlutterEmbedderExternalTextureTest.mm | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm index 6554a03576dbb..5031021c86b26 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEmbedderExternalTextureTest.mm @@ -108,15 +108,14 @@ - (CVPixelBufferRef)pixelBuffer { EXPECT_TRUE(w == width); EXPECT_TRUE(h == height); - FlutterMetalExternalTexture* texture = new FlutterMetalExternalTexture(); + auto texture = std::make_unique(); texture->struct_size = sizeof(FlutterMetalExternalTexture); texture->num_textures = 1; texture->height = h; texture->width = w; texture->pixel_format = FlutterMetalExternalTexturePixelFormat::kRGBA; texture->textures = textures.data(); - - return std::unique_ptr(texture); + return texture; }; // Render the texture. @@ -164,14 +163,13 @@ - (CVPixelBufferRef)pixelBuffer { EXPECT_TRUE(w == width); EXPECT_TRUE(h == height); - FlutterMetalExternalTexture* texture = new FlutterMetalExternalTexture(); - [textureHolder populateTexture:texture]; + auto texture = std::make_unique(); + [textureHolder populateTexture:texture.get()]; EXPECT_TRUE(texture->num_textures == 1); EXPECT_TRUE(texture->textures != nullptr); EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kRGBA); - - return std::unique_ptr(texture); + return texture; }; // Render the texture. @@ -217,16 +215,15 @@ - (CVPixelBufferRef)pixelBuffer { EXPECT_TRUE(w == width); EXPECT_TRUE(h == height); - FlutterMetalExternalTexture* texture = new FlutterMetalExternalTexture(); - [textureHolder populateTexture:texture]; + auto texture = std::make_unique(); + [textureHolder populateTexture:texture.get()]; EXPECT_TRUE(texture->num_textures == 2); EXPECT_TRUE(texture->textures != nullptr); EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA); EXPECT_TRUE(texture->yuv_color_space == FlutterMetalExternalTextureYUVColorSpace::kBT601LimitedRange); - - return std::unique_ptr(texture); + return texture; }; // Render the texture. @@ -272,16 +269,15 @@ - (CVPixelBufferRef)pixelBuffer { EXPECT_TRUE(w == width); EXPECT_TRUE(h == height); - FlutterMetalExternalTexture* texture = new FlutterMetalExternalTexture(); - [textureHolder populateTexture:texture]; + auto texture = std::make_unique(); + [textureHolder populateTexture:texture.get()]; EXPECT_TRUE(texture->num_textures == 2); EXPECT_TRUE(texture->textures != nullptr); EXPECT_TRUE(texture->pixel_format == FlutterMetalExternalTexturePixelFormat::kYUVA); EXPECT_TRUE(texture->yuv_color_space == FlutterMetalExternalTextureYUVColorSpace::kBT601FullRange); - - return std::unique_ptr(texture); + return texture; }; // Render the texture.