From 4be4a44534708628da79e779f36dc8be578c3509 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:31:01 -0800 Subject: [PATCH] Started using bgr10_xr for opaque surfaces. (flutter/engine#39727) * Started using bgr10_xr for opaque surfaces. * bdero feedback --- .../darwin/ios/framework/Source/FlutterView.mm | 4 +--- .../darwin/ios/ios_surface_metal_impeller.mm | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm index f365e87ff8..d0377d0033 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -87,9 +87,7 @@ static BOOL IsWideGamutSupported() { layer.colorspace = srgb; CFRelease(srgb); if (self.opaque) { - // TODO(https://github.com/flutter/flutter/issues/120641): Switch to - // MTLPixelFormatBGR10_XR to save memory. - layer.pixelFormat = MTLPixelFormatBGRA10_XR; + layer.pixelFormat = MTLPixelFormatBGR10_XR; } else { layer.pixelFormat = MTLPixelFormatBGRA10_XR; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.mm index 4a3d5d3761..c1696ff309 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_impeller.mm @@ -8,9 +8,19 @@ #include "flutter/impeller/renderer/context.h" #include "flutter/shell/gpu/gpu_surface_metal_impeller.h" +namespace { +impeller::PixelFormat InferOffscreenLayerPixelFormat(impeller::PixelFormat pixel_format) { + switch (pixel_format) { + case impeller::PixelFormat::kB10G10R10XR: + return impeller::PixelFormat::kB10G10R10A10XR; + default: + return pixel_format; + } +} +} // namespace + namespace impeller { namespace { - // This appears to be the only safe way to override the // GetColorAttachmentPixelFormat method. It is assumed in the Context that // there will be one pixel format for the whole app which is not true. So, it @@ -96,7 +106,8 @@ void IOSSurfaceMetalImpeller::UpdateStorageSizeIfNecessary() { // |IOSSurface| std::unique_ptr IOSSurfaceMetalImpeller::CreateGPUSurface(GrDirectContext*) { auto context = std::make_shared( - impeller_context_, FromMTLPixelFormat(layer_.get().pixelFormat)); + impeller_context_, + InferOffscreenLayerPixelFormat(FromMTLPixelFormat(layer_.get().pixelFormat))); return std::make_unique(this, // context // );