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

Commit a57a4a7

Browse files
authored
macOS: ARC bridge casts for FlutterMetalTexture.user_data (#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: https://github.com/flutter/engine/blob/a672f971c65930f620c7542be58e15669372e16f/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: flutter/flutter#137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent ff9931a commit a57a4a7

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ - (instancetype)initWithSize:(CGSize)size device:(id<MTLDevice>)device {
5252
return self;
5353
}
5454

55-
static void ReleaseSurface(void* surface) {
56-
if (surface != nullptr) {
57-
CFBridgingRelease(surface);
58-
}
59-
}
60-
6155
- (FlutterMetalTexture)asFlutterMetalTexture {
62-
FlutterMetalTexture res;
63-
memset(&res, 0, sizeof(FlutterMetalTexture));
64-
res.struct_size = sizeof(FlutterMetalTexture);
65-
res.texture = (__bridge void*)_texture;
66-
res.texture_id = self.textureId;
67-
res.user_data = (void*)CFBridgingRetain(self);
68-
res.destruction_callback = ReleaseSurface;
69-
return res;
56+
return FlutterMetalTexture{
57+
.struct_size = sizeof(FlutterMetalTexture),
58+
.texture_id = self.textureId,
59+
.texture = (__bridge void*)_texture,
60+
// Retain for use in [FlutterSurface fromFlutterMetalTexture]. Released in
61+
// destruction_callback.
62+
.user_data = (__bridge_retained void*)self,
63+
.destruction_callback =
64+
[](void* user_data) {
65+
// Balancing release for the retain when setting user_data above.
66+
FlutterSurface* surface = (__bridge_transfer FlutterSurface*)user_data;
67+
surface = nil;
68+
},
69+
};
7070
}
7171

7272
+ (FlutterSurface*)fromFlutterMetalTexture:(const FlutterMetalTexture*)texture {

0 commit comments

Comments
 (0)