Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e86b989

Browse files
authored
iOS: Clean up uses of string literal constants (#56658)
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. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 4878f1c commit e86b989

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.h"
66

7+
#include <CoreMedia/CoreMedia.h>
78
#include <IOSurface/IOSurfaceObjC.h>
89
#include <Metal/Metal.h>
910
#include <UIKit/UIKit.h>
@@ -316,9 +317,9 @@ - (IOSurface*)createIOSurface {
316317

317318
if (self.colorspace != nil) {
318319
CFStringRef name = CGColorSpaceGetName(self.colorspace);
319-
IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), name);
320+
IOSurfaceSetValue(res, kIOSurfaceColorSpace, name);
320321
} else {
321-
IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB);
322+
IOSurfaceSetValue(res, kIOSurfaceColorSpace, kCGColorSpaceSRGB);
322323
}
323324
return (__bridge_transfer IOSurface*)res;
324325
}

shell/platform/darwin/ios/framework/Source/IOKit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" {
2525
#define IOKIT
2626
#include <device/device_types.h>
2727

28-
static const char* kIOServicePlane = "IOService";
28+
constexpr const char* kIOServicePlane = "IOService";
2929

3030
typedef io_object_t io_registry_entry_t;
3131
typedef io_object_t io_service_t;

shell/platform/darwin/macos/framework/Source/FlutterSurface.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.h"
66

7+
#import <CoreMedia/CoreMedia.h>
78
#import <Metal/Metal.h>
89

910
#import "flutter/fml/platform/darwin/cf_utils.h"
@@ -74,7 +75,7 @@ + (FlutterSurface*)fromFlutterMetalTexture:(const FlutterMetalTexture*)texture {
7475
}
7576

7677
+ (IOSurfaceRef)createIOSurfaceWithSize:(CGSize)size {
77-
unsigned pixelFormat = 'BGRA';
78+
unsigned pixelFormat = kCVPixelFormatType_32BGRA;
7879
unsigned bytesPerElement = 4;
7980

8081
size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.width * bytesPerElement);
@@ -89,7 +90,7 @@ + (IOSurfaceRef)createIOSurfaceWithSize:(CGSize)size {
8990
};
9091

9192
IOSurfaceRef res = IOSurfaceCreate((CFDictionaryRef)options);
92-
IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB);
93+
IOSurfaceSetValue(res, kIOSurfaceColorSpace, kCGColorSpaceSRGB);
9394
return res;
9495
}
9596

0 commit comments

Comments
 (0)