iOS: Clean up uses of string literal constants (flutter/engine#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
This commit is contained in:
parent
f04c3db30f
commit
20e0482db7
@ -4,6 +4,7 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.h"
|
||||
|
||||
#include <CoreMedia/CoreMedia.h>
|
||||
#include <IOSurface/IOSurfaceObjC.h>
|
||||
#include <Metal/Metal.h>
|
||||
#include <UIKit/UIKit.h>
|
||||
@ -316,9 +317,9 @@ extern CFTimeInterval display_link_target;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ extern "C" {
|
||||
#define IOKIT
|
||||
#include <device/device_types.h>
|
||||
|
||||
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;
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.h"
|
||||
|
||||
#import <CoreMedia/CoreMedia.h>
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
#import "flutter/fml/platform/darwin/cf_utils.h"
|
||||
@ -74,7 +75,7 @@
|
||||
}
|
||||
|
||||
+ (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 res = IOSurfaceCreate((CFDictionaryRef)options);
|
||||
IOSurfaceSetValue(res, CFSTR("IOSurfaceColorSpace"), kCGColorSpaceSRGB);
|
||||
IOSurfaceSetValue(res, kIOSurfaceColorSpace, kCGColorSpaceSRGB);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user