From 07104cbded94dfcbea9097f47e3dcf0cd5490cae Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Sun, 17 Nov 2024 07:10:22 -0800 Subject: [PATCH] iOS: Clean up uses of string literal constants Three changes related to string constants: 1. Uses the kIOSurfaceColorSpace constant, which is a CFStringRef pointing to the string "IOSurfaceColorSpace" 2. Uses the kCVPixelFormatType_32BGRA enum value from the CoreVideo headers (which is equal to 'BGRA') in place of hardcoding the string. From the headers: ``` kCVPixelFormatType_32BGRA = 'BGRA', /* 32 bit BGRA */ ``` 3. Declares kIOServicePlane as a `constexpr const char*` rather than `static const char*`, this ensures only a single instance is created, rather than one per translation unit into which the header is included. This string is part of IOKit, but see the comment at the top of the header as to why it's apparently needed. No test changes since there are no semantic changes. --- .../darwin/ios/framework/Source/FlutterMetalLayer.mm | 5 +++-- shell/platform/darwin/ios/framework/Source/IOKit.h | 2 +- .../platform/darwin/macos/framework/Source/FlutterSurface.mm | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.mm b/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.mm index b26df26ca9a8c..a4abff98d5fb7 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.mm @@ -4,6 +4,7 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.h" +#include #include #include #include @@ -316,9 +317,9 @@ - (IOSurface*)createIOSurface { if (self.colorspace != nil) { CFStringRef name = CGColorSpaceGetName(self.colorspace); - IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), name); + IOSurfaceSetValue(res, kIOSurfaceColorSpace, name); } else { - IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB); + IOSurfaceSetValue(res, kIOSurfaceColorSpace, kCGColorSpaceSRGB); } return (__bridge_transfer IOSurface*)res; } diff --git a/shell/platform/darwin/ios/framework/Source/IOKit.h b/shell/platform/darwin/ios/framework/Source/IOKit.h index 53e8fe1b35eb4..4b1e8446af4b6 100644 --- a/shell/platform/darwin/ios/framework/Source/IOKit.h +++ b/shell/platform/darwin/ios/framework/Source/IOKit.h @@ -25,7 +25,7 @@ extern "C" { #define IOKIT #include -static const char* kIOServicePlane = "IOService"; +constexpr const char* kIOServicePlane = "IOService"; typedef io_object_t io_registry_entry_t; typedef io_object_t io_service_t; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurface.mm b/shell/platform/darwin/macos/framework/Source/FlutterSurface.mm index 109740942621d..83c4ea2f8ebb6 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurface.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurface.mm @@ -4,6 +4,7 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.h" +#import #import #import "flutter/fml/platform/darwin/cf_utils.h" @@ -74,7 +75,7 @@ + (FlutterSurface*)fromFlutterMetalTexture:(const FlutterMetalTexture*)texture { } + (IOSurfaceRef)createIOSurfaceWithSize:(CGSize)size { - unsigned pixelFormat = 'BGRA'; + unsigned pixelFormat = kCVPixelFormatType_32BGRA; unsigned bytesPerElement = 4; size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.width * bytesPerElement); @@ -89,7 +90,7 @@ + (IOSurfaceRef)createIOSurfaceWithSize:(CGSize)size { }; IOSurfaceRef res = IOSurfaceCreate((CFDictionaryRef)options); - IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB); + IOSurfaceSetValue(res, kIOSurfaceColorSpace, kCGColorSpaceSRGB); return res; }