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

Commit 77605fa

Browse files
authored
Migrate ios_surface files to ARC (#52139)
Smart pointers support ARC as of #47612, and the unit tests were migrated in #48162. Migrate `ios_surface` classes from MRC to ARC. Decorate C functions that take or return Objective-C objects or structs containing Objective-C objects with [`cf_audited_transfer`](https://clang.llvm.org/docs/AutomaticReferenceCounting.html#auditing-of-c-retainable-pointer-interfaces). Part of flutter/flutter#137801.
1 parent c603f03 commit 77605fa

7 files changed

+45
-33
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ source_set("flutter_framework_source_arc") {
109109
"ios_context_software.mm",
110110
"ios_external_texture_metal.h",
111111
"ios_external_texture_metal.mm",
112+
"ios_surface.h",
113+
"ios_surface.mm",
114+
"ios_surface_metal_impeller.h",
115+
"ios_surface_metal_impeller.mm",
116+
"ios_surface_metal_skia.h",
117+
"ios_surface_metal_skia.mm",
118+
"ios_surface_software.h",
119+
"ios_surface_software.mm",
112120
"rendering_api_selection.h",
113121
"rendering_api_selection.mm",
114122
]
@@ -172,14 +180,6 @@ source_set("flutter_framework_source") {
172180
"framework/Source/accessibility_text_entry.mm",
173181
"ios_external_view_embedder.h",
174182
"ios_external_view_embedder.mm",
175-
"ios_surface.h",
176-
"ios_surface.mm",
177-
"ios_surface_metal_impeller.h",
178-
"ios_surface_metal_impeller.mm",
179-
"ios_surface_metal_skia.h",
180-
"ios_surface_metal_skia.mm",
181-
"ios_surface_software.h",
182-
"ios_surface_software.mm",
183183
"platform_message_handler_ios.h",
184184
"platform_message_handler_ios.mm",
185185
"platform_view_ios.h",

shell/platform/darwin/ios/ios_surface.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#import "flutter/shell/platform/darwin/ios/ios_surface_software.h"
1010
#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
1111

12+
FLUTTER_ASSERT_ARC
13+
1214
namespace flutter {
1315

1416
std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> context,
@@ -21,16 +23,14 @@
2123
switch (context->GetBackend()) {
2224
case IOSRenderingBackend::kSkia:
2325
return std::make_unique<IOSSurfaceMetalSkia>(
24-
fml::scoped_nsobject<CAMetalLayer>(
25-
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
26-
std::move(context) // context
26+
fml::scoped_nsobject<CAMetalLayer>((CAMetalLayer*)layer.get()), // Metal layer
27+
std::move(context) // context
2728
);
2829
break;
2930
case IOSRenderingBackend::kImpeller:
3031
return std::make_unique<IOSSurfaceMetalImpeller>(
31-
fml::scoped_nsobject<CAMetalLayer>(
32-
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
33-
std::move(context) // context
32+
fml::scoped_nsobject<CAMetalLayer>((CAMetalLayer*)layer.get()), // Metal layer
33+
std::move(context) // context
3434
);
3535
}
3636
}

shell/platform/darwin/ios/ios_surface_metal_impeller.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,19 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetalImpeller final
4242
std::unique_ptr<Surface> CreateGPUSurface(GrDirectContext* gr_context) override;
4343

4444
// |GPUSurfaceMetalDelegate|
45-
GPUCAMetalLayerHandle GetCAMetalLayer(const SkISize& frame_info) const override;
45+
GPUCAMetalLayerHandle GetCAMetalLayer(const SkISize& frame_info) const override
46+
__attribute__((cf_audited_transfer));
4647

4748
// |GPUSurfaceMetalDelegate|
48-
bool PresentDrawable(GrMTLHandle drawable) const override;
49+
bool PresentDrawable(GrMTLHandle drawable) const override __attribute__((cf_audited_transfer));
4950

5051
// |GPUSurfaceMetalDelegate|
51-
GPUMTLTextureInfo GetMTLTexture(const SkISize& frame_info) const override;
52+
GPUMTLTextureInfo GetMTLTexture(const SkISize& frame_info) const override
53+
__attribute__((cf_audited_transfer));
5254

5355
// |GPUSurfaceMetalDelegate|
54-
bool PresentTexture(GPUMTLTextureInfo texture) const override;
56+
bool PresentTexture(GPUMTLTextureInfo texture) const override
57+
__attribute__((cf_audited_transfer));
5558

5659
// |GPUSurfaceMetalDelegate|
5760
bool AllowsDrawingWhenGpuDisabled() const override;

shell/platform/darwin/ios/ios_surface_metal_impeller.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "flutter/impeller/renderer/context.h"
99
#include "flutter/shell/gpu/gpu_surface_metal_impeller.h"
1010

11+
FLUTTER_ASSERT_ARC
12+
1113
namespace flutter {
1214

1315
IOSSurfaceMetalImpeller::IOSSurfaceMetalImpeller(const fml::scoped_nsobject<CAMetalLayer>& layer,
@@ -64,7 +66,7 @@
6466
// exit the app.
6567
layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
6668

67-
return layer;
69+
return (__bridge GPUCAMetalLayerHandle)layer;
6870
}
6971

7072
// |GPUSurfaceMetalDelegate|

shell/platform/darwin/ios/ios_surface_metal_skia.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,19 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetalSkia final : public IOSSurf
3939
std::unique_ptr<Surface> CreateGPUSurface(GrDirectContext* gr_context) override;
4040

4141
// |GPUSurfaceMetalDelegate|
42-
GPUCAMetalLayerHandle GetCAMetalLayer(const SkISize& frame_info) const override;
42+
GPUCAMetalLayerHandle GetCAMetalLayer(const SkISize& frame_info) const override
43+
__attribute__((cf_audited_transfer));
4344

4445
// |GPUSurfaceMetalDelegate|
45-
bool PresentDrawable(GrMTLHandle drawable) const override;
46+
bool PresentDrawable(GrMTLHandle drawable) const override __attribute__((cf_audited_transfer));
4647

4748
// |GPUSurfaceMetalDelegate|
48-
GPUMTLTextureInfo GetMTLTexture(const SkISize& frame_info) const override;
49+
GPUMTLTextureInfo GetMTLTexture(const SkISize& frame_info) const override
50+
__attribute__((cf_audited_transfer));
4951

5052
// |GPUSurfaceMetalDelegate|
51-
bool PresentTexture(GPUMTLTextureInfo texture) const override;
53+
bool PresentTexture(GPUMTLTextureInfo texture) const override
54+
__attribute__((cf_audited_transfer));
5255

5356
// |GPUSurfaceMetalDelegate|
5457
bool AllowsDrawingWhenGpuDisabled() const override;

shell/platform/darwin/ios/ios_surface_metal_skia.mm

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
99
#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
1010

11+
FLUTTER_ASSERT_ARC
12+
1113
@protocol FlutterMetalDrawable <MTLDrawable>
1214
- (void)flutterPrepareForPresent:(nonnull id<MTLCommandBuffer>)commandBuffer;
1315
@end
1416

1517
namespace flutter {
1618

17-
static IOSContextMetalSkia* CastToMetalContext(const std::shared_ptr<IOSContext>& context) {
18-
return reinterpret_cast<IOSContextMetalSkia*>(context.get());
19+
static IOSContextMetalSkia* CastToMetalContext(const std::shared_ptr<IOSContext>& context)
20+
__attribute__((cf_audited_transfer)) {
21+
return (IOSContextMetalSkia*)context.get();
1922
}
2023

2124
IOSSurfaceMetalSkia::IOSSurfaceMetalSkia(const fml::scoped_nsobject<CAMetalLayer>& layer,
@@ -72,7 +75,7 @@ - (void)flutterPrepareForPresent:(nonnull id<MTLCommandBuffer>)commandBuffer;
7275
// the raster thread, there is no such transaction.
7376
layer.presentsWithTransaction = [[NSThread currentThread] isMainThread];
7477

75-
return layer;
78+
return (__bridge GPUCAMetalLayerHandle)layer;
7679
}
7780

7881
// |GPUSurfaceMetalDelegate|
@@ -82,16 +85,15 @@ - (void)flutterPrepareForPresent:(nonnull id<MTLCommandBuffer>)commandBuffer;
8285
return false;
8386
}
8487

85-
auto command_buffer =
86-
fml::scoped_nsprotocol<id<MTLCommandBuffer>>([[command_queue_ commandBuffer] retain]);
88+
id<MTLCommandBuffer> command_buffer = [command_queue_ commandBuffer];
8789

88-
id<CAMetalDrawable> metal_drawable = reinterpret_cast<id<CAMetalDrawable>>(drawable);
90+
id<CAMetalDrawable> metal_drawable = (__bridge id<CAMetalDrawable>)drawable;
8991
if ([metal_drawable conformsToProtocol:@protocol(FlutterMetalDrawable)]) {
90-
[(id<FlutterMetalDrawable>)metal_drawable flutterPrepareForPresent:command_buffer.get()];
92+
[(id<FlutterMetalDrawable>)metal_drawable flutterPrepareForPresent:command_buffer];
9193
}
9294

93-
[command_buffer.get() commit];
94-
[command_buffer.get() waitUntilScheduled];
95+
[command_buffer commit];
96+
[command_buffer waitUntilScheduled];
9597

9698
[metal_drawable present];
9799
return true;

shell/platform/darwin/ios/ios_surface_software.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "third_party/skia/include/core/SkSurface.h"
1616
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
1717

18+
FLUTTER_ASSERT_ARC
19+
1820
namespace flutter {
1921

2022
IOSSurfaceSoftware::IOSSurfaceSoftware(const fml::scoped_nsobject<CALayer>& layer,
@@ -118,7 +120,7 @@
118120
return false;
119121
}
120122

121-
layer_.get().contents = reinterpret_cast<id>(static_cast<CGImageRef>(pixmap_image));
123+
layer_.get().contents = (__bridge id)(static_cast<CGImageRef>(pixmap_image));
122124

123125
return true;
124126
}

0 commit comments

Comments
 (0)