macOS: ARC bridge casts for FlutterMetalTexture.user_data (flutter/engine#56518)
In `[FlutterSurface asFlutterMetalTexture]` we return a `FlutterMetalTexture` whose `user_data` field holds a `void*` reference to the associated `FlutterSurface`.
For conistency with other parts of the codebase, this now uses ARC bridge casts to perform the additional retain and release of the associated surface rather than CoreFoundation functions `CFBridgingRetain` and `CFBridigingRelease`. In FlutterEngine, for example:
67eb4ae000/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm (L648-L664)
Also migrates the code to initialise and immediately return the struct using field designators, and reorders the assignments to be in the declaration order specified in embedder.h as required by the C++ spec.
No changes to tests since this introduces no semantic change.
Issue: https://github.com/flutter/flutter/issues/137801
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -52,21 +52,21 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
static void ReleaseSurface(void* surface) {
|
||||
if (surface != nullptr) {
|
||||
CFBridgingRelease(surface);
|
||||
}
|
||||
}
|
||||
|
||||
- (FlutterMetalTexture)asFlutterMetalTexture {
|
||||
FlutterMetalTexture res;
|
||||
memset(&res, 0, sizeof(FlutterMetalTexture));
|
||||
res.struct_size = sizeof(FlutterMetalTexture);
|
||||
res.texture = (__bridge void*)_texture;
|
||||
res.texture_id = self.textureId;
|
||||
res.user_data = (void*)CFBridgingRetain(self);
|
||||
res.destruction_callback = ReleaseSurface;
|
||||
return res;
|
||||
return FlutterMetalTexture{
|
||||
.struct_size = sizeof(FlutterMetalTexture),
|
||||
.texture_id = self.textureId,
|
||||
.texture = (__bridge void*)_texture,
|
||||
// Retain for use in [FlutterSurface fromFlutterMetalTexture]. Released in
|
||||
// destruction_callback.
|
||||
.user_data = (__bridge_retained void*)self,
|
||||
.destruction_callback =
|
||||
[](void* user_data) {
|
||||
// Balancing release for the retain when setting user_data above.
|
||||
FlutterSurface* surface = (__bridge_transfer FlutterSurface*)user_data;
|
||||
surface = nil;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+ (FlutterSurface*)fromFlutterMetalTexture:(const FlutterMetalTexture*)texture {
|
||||
|
||||
Reference in New Issue
Block a user