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

Commit 12e83bf

Browse files
committed
iOS: Eliminate fml::scoped_nsobject pointer use
Eliminates use of `fml::scoped_nsobject` now that the codebase has been migrated to ARC. Issue: flutter/flutter#137801
1 parent d7e9289 commit 12e83bf

38 files changed

+162
-213
lines changed

shell/common/shell_test_platform_view_metal.mm

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <utility>
1010

11-
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
1211
#include "flutter/shell/gpu/gpu_surface_metal_impeller.h"
1312
#include "flutter/shell/gpu/gpu_surface_metal_skia.h"
1413
#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h"
@@ -17,14 +16,14 @@
1716
namespace flutter {
1817
namespace testing {
1918

20-
static fml::scoped_nsprotocol<id<MTLTexture>> CreateOffscreenTexture(id<MTLDevice> device) {
19+
static id<MTLTexture> CreateOffscreenTexture(id<MTLDevice> device) {
2120
auto descriptor =
2221
[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
2322
width:800
2423
height:600
2524
mipmapped:NO];
2625
descriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
27-
return fml::scoped_nsprotocol<id<MTLTexture>>{[device newTextureWithDescriptor:descriptor]};
26+
return [device newTextureWithDescriptor:descriptor];
2827
}
2928

3029
// This is out of the header so that shell_test_platform_view_metal.h can be included in
@@ -43,25 +42,23 @@ explicit DarwinContextMetal(
4342

4443
~DarwinContextMetal() = default;
4544

46-
fml::scoped_nsobject<FlutterDarwinContextMetalImpeller> impeller_context() const {
47-
return impeller_context_;
48-
}
45+
const FlutterDarwinContextMetalImpeller* impeller_context() const { return impeller_context_; }
4946

50-
fml::scoped_nsobject<FlutterDarwinContextMetalSkia> context() const { return context_; }
47+
const FlutterDarwinContextMetalSkia* context() const { return context_; }
5148

52-
fml::scoped_nsprotocol<id<MTLTexture>> offscreen_texture() const { return offscreen_texture_; }
49+
id<MTLTexture> offscreen_texture() const { return offscreen_texture_; }
5350

5451
GPUMTLTextureInfo offscreen_texture_info() const {
5552
GPUMTLTextureInfo info = {};
5653
info.texture_id = 0;
57-
info.texture = reinterpret_cast<GPUMTLTextureHandle>(offscreen_texture_.get());
54+
info.texture = (__bridge GPUMTLTextureHandle)offscreen_texture_;
5855
return info;
5956
}
6057

6158
private:
62-
const fml::scoped_nsobject<FlutterDarwinContextMetalSkia> context_;
63-
const fml::scoped_nsobject<FlutterDarwinContextMetalImpeller> impeller_context_;
64-
const fml::scoped_nsprotocol<id<MTLTexture>> offscreen_texture_;
59+
const FlutterDarwinContextMetalSkia* context_;
60+
const FlutterDarwinContextMetalImpeller* impeller_context_;
61+
const id<MTLTexture> offscreen_texture_;
6562

6663
FML_DISALLOW_COPY_AND_ASSIGN(DarwinContextMetal);
6764
};

shell/gpu/gpu_surface_metal_impeller.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "flutter/flow/surface.h"
1111
#include "flutter/fml/macros.h"
12-
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
1312
#include "flutter/impeller/display_list/aiks_context.h"
1413
#include "flutter/impeller/renderer/backend/metal/context_mtl.h"
1514
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"

shell/gpu/gpu_surface_metal_skia.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "flutter/common/graphics/persistent_cache.h"
1616
#include "flutter/fml/make_copyable.h"
1717
#include "flutter/fml/platform/darwin/cf_utils.h"
18-
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
1918
#include "flutter/fml/trace_event.h"
2019
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
2120
#include "third_party/skia/include/core/SkCanvas.h"

shell/platform/darwin/common/buffer_conversions.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#import "flutter/shell/platform/darwin/common/buffer_conversions.h"
66

77
#include "flutter/fml/macros.h"
8-
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
98

109
static_assert(__has_feature(objc_arc), "ARC must be enabled.");
1110

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ - (instancetype)initWithEnableVMServicePublication:(BOOL)enableVMServicePublicat
4141

4242
#include "flutter/fml/logging.h"
4343
#include "flutter/fml/message_loop.h"
44-
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
4544
#include "flutter/runtime/dart_service_isolate.h"
4645
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
4746

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "flutter/flow/surface.h"
1616
#include "flutter/fml/memory/weak_ptr.h"
17-
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
1817
#include "flutter/fml/trace_event.h"
1918
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
2019
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h"

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ @implementation ForwardingGestureRecognizer {
714714
// This gesture recognizer retains the `FlutterViewController` until the
715715
// end of a gesture sequence, that is all the touches in touchesBegan are concluded
716716
// with |touchesCancelled| or |touchesEnded|.
717-
fml::scoped_nsobject<UIViewController<FlutterViewResponder>> _flutterViewController;
717+
UIViewController<FlutterViewResponder>* _flutterViewController;
718718
}
719719

720720
- (instancetype)initWithTarget:(id)target
@@ -741,26 +741,26 @@ - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
741741
// At the start of each gesture sequence, we reset the `_flutterViewController`,
742742
// so that all the touch events in the same sequence are forwarded to the same
743743
// `_flutterViewController`.
744-
_flutterViewController.reset(_platformViewsController->GetFlutterViewController());
744+
_flutterViewController = _platformViewsController->GetFlutterViewController();
745745
}
746-
[_flutterViewController.get() touchesBegan:touches withEvent:event];
746+
[_flutterViewController touchesBegan:touches withEvent:event];
747747
_currentTouchPointersCount += touches.count;
748748
}
749749

750750
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
751-
[_flutterViewController.get() touchesMoved:touches withEvent:event];
751+
[_flutterViewController touchesMoved:touches withEvent:event];
752752
}
753753

754754
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
755-
[_flutterViewController.get() touchesEnded:touches withEvent:event];
755+
[_flutterViewController touchesEnded:touches withEvent:event];
756756
_currentTouchPointersCount -= touches.count;
757757
// Touches in one touch sequence are sent to the touchesEnded method separately if different
758758
// fingers stop touching the screen at different time. So one touchesEnded method triggering does
759759
// not necessarially mean the touch sequence has ended. We Only set the state to
760760
// UIGestureRecognizerStateFailed when all the touches in the current touch sequence is ended.
761761
if (_currentTouchPointersCount == 0) {
762762
self.state = UIGestureRecognizerStateFailed;
763-
_flutterViewController.reset(nil);
763+
_flutterViewController = nil;
764764
[self forceResetStateIfNeeded];
765765
}
766766
}
@@ -771,11 +771,11 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
771771
// Flutter needs all the cancelled touches to be "cancelled" change types in order to correctly
772772
// handle gesture sequence.
773773
// We always override the change type to "cancelled".
774-
[_flutterViewController.get() forceTouchesCancelled:touches];
774+
[_flutterViewController forceTouchesCancelled:touches];
775775
_currentTouchPointersCount -= touches.count;
776776
if (_currentTouchPointersCount == 0) {
777777
self.state = UIGestureRecognizerStateFailed;
778-
_flutterViewController.reset(nil);
778+
_flutterViewController = nil;
779779
[self forceResetStateIfNeeded];
780780
}
781781
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "flutter/fml/macros.h"
1616
#include "flutter/fml/memory/weak_ptr.h"
17-
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
1817
#include "flutter/lib/ui/semantics/custom_accessibility_action.h"
1918
#include "flutter/lib/ui/semantics/semantics_node.h"
2019
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
@@ -98,10 +97,8 @@ class AccessibilityBridge final : public AccessibilityBridgeIos {
9897
// (i.e. the status bar or keyboard)
9998
int32_t last_focused_semantics_object_id_;
10099

101-
// TODO(cbracken): https://github.com/flutter/flutter/issues/137801
102-
// Eliminate use of fml::scoped_* wrappers here.
103-
fml::scoped_nsobject<NSMutableDictionary<NSNumber*, SemanticsObject*>> objects_;
104-
fml::scoped_nsprotocol<FlutterBasicMessageChannel*> accessibility_channel_;
100+
NSMutableDictionary<NSNumber*, SemanticsObject*>* objects_;
101+
FlutterBasicMessageChannel* accessibility_channel_;
105102
int32_t previous_route_id_ = 0;
106103
std::unordered_map<int32_t, flutter::CustomAccessibilityAction> actions_;
107104
std::vector<int32_t> previous_routes_;

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
5353
ios_delegate_(ios_delegate ? std::move(ios_delegate)
5454
: std::make_unique<DefaultIosDelegate>()),
5555
weak_factory_(this) {
56-
accessibility_channel_.reset([[FlutterBasicMessageChannel alloc]
56+
accessibility_channel_ = [[FlutterBasicMessageChannel alloc]
5757
initWithName:@"flutter/accessibility"
5858
binaryMessenger:platform_view->GetOwnerViewController().engine.binaryMessenger
59-
codec:[FlutterStandardMessageCodec sharedInstance]]);
60-
[accessibility_channel_.get() setMessageHandler:^(id message, FlutterReply reply) {
59+
codec:[FlutterStandardMessageCodec sharedInstance]];
60+
[accessibility_channel_ setMessageHandler:^(id message, FlutterReply reply) {
6161
HandleEvent((NSDictionary*)message);
6262
}];
6363
}
6464

6565
AccessibilityBridge::~AccessibilityBridge() {
66-
[accessibility_channel_.get() setMessageHandler:nil];
66+
[accessibility_channel_ setMessageHandler:nil];
6767
clearState();
6868
view_controller_.viewIfLoaded.accessibilityElements = nil;
6969
}
@@ -74,7 +74,7 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
7474

7575
void AccessibilityBridge::AccessibilityObjectDidBecomeFocused(int32_t id) {
7676
last_focused_semantics_object_id_ = id;
77-
[accessibility_channel_.get() sendMessage:@{@"type" : @"didGainFocus", @"nodeId" : @(id)}];
77+
[accessibility_channel_ sendMessage:@{@"type" : @"didGainFocus", @"nodeId" : @(id)}];
7878
}
7979

8080
void AccessibilityBridge::AccessibilityObjectDidLoseFocus(int32_t id) {
@@ -152,7 +152,7 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
152152
}
153153
}
154154

155-
SemanticsObject* root = objects_.get()[@(kRootNodeId)];
155+
SemanticsObject* root = objects_[@(kRootNodeId)];
156156

157157
bool routeChanged = false;
158158
SemanticsObject* lastAdded = nil;
@@ -196,13 +196,13 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
196196
view_controller_.viewIfLoaded.accessibilityElements = nil;
197197
}
198198

199-
NSMutableArray<NSNumber*>* doomed_uids = [NSMutableArray arrayWithArray:[objects_ allKeys]];
199+
NSMutableArray<NSNumber*>* doomed_uids = [NSMutableArray arrayWithArray:objects_.allKeys];
200200
if (root) {
201201
VisitObjectsRecursivelyAndRemove(root, doomed_uids);
202202
}
203203
[objects_ removeObjectsForKeys:doomed_uids];
204204

205-
for (SemanticsObject* object in [objects_ allValues]) {
205+
for (SemanticsObject* object in objects_.allValues) {
206206
[object accessibilityBridgeDidFinishUpdate];
207207
}
208208

@@ -217,8 +217,7 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
217217

218218
if (layoutChanged) {
219219
SemanticsObject* next = FindNextFocusableIfNecessary();
220-
SemanticsObject* lastFocused =
221-
[objects_.get() objectForKey:@(last_focused_semantics_object_id_)];
220+
SemanticsObject* lastFocused = [objects_ objectForKey:@(last_focused_semantics_object_id_)];
222221
// Only specify the focus item if the new focus is different, avoiding double focuses on the
223222
// same item. See: https://github.com/flutter/flutter/issues/104176. If there is a route
224223
// change, we always refocus.
@@ -290,10 +289,10 @@ static bool DidFlagChange(const flutter::SemanticsNode& oldNode,
290289

291290
SemanticsObject* AccessibilityBridge::GetOrCreateObject(int32_t uid,
292291
flutter::SemanticsNodeUpdates& updates) {
293-
SemanticsObject* object = objects_.get()[@(uid)];
292+
SemanticsObject* object = objects_[@(uid)];
294293
if (!object) {
295294
object = CreateObject(updates[uid], GetWeakPtr());
296-
objects_.get()[@(uid)] = object;
295+
objects_[@(uid)] = object;
297296
} else {
298297
// Existing node case
299298
auto nodeEntry = updates.find(object.node.id);
@@ -309,7 +308,7 @@ static bool DidFlagChange(const flutter::SemanticsNode& oldNode,
309308
// SemanticsObject implementation. Instead, we replace it with a new
310309
// instance.
311310
SemanticsObject* newSemanticsObject = CreateObject(node, GetWeakPtr());
312-
ReplaceSemanticsObject(object, newSemanticsObject, objects_.get());
311+
ReplaceSemanticsObject(object, newSemanticsObject, objects_);
313312
object = newSemanticsObject;
314313
}
315314
}
@@ -332,11 +331,11 @@ static bool DidFlagChange(const flutter::SemanticsNode& oldNode,
332331
}
333332

334333
// Tries to refocus the previous focused semantics object to avoid random jumps.
335-
return FindFirstFocusable([objects_.get() objectForKey:@(last_focused_semantics_object_id_)]);
334+
return FindFirstFocusable([objects_ objectForKey:@(last_focused_semantics_object_id_)]);
336335
}
337336

338337
SemanticsObject* AccessibilityBridge::FindFirstFocusable(SemanticsObject* parent) {
339-
SemanticsObject* currentObject = parent ?: objects_.get()[@(kRootNodeId)];
338+
SemanticsObject* currentObject = parent ?: objects_[@(kRootNodeId)];
340339
if (!currentObject) {
341340
return nil;
342341
}
@@ -360,7 +359,7 @@ static bool DidFlagChange(const flutter::SemanticsNode& oldNode,
360359
ios_delegate_->PostAccessibilityNotification(UIAccessibilityAnnouncementNotification, message);
361360
}
362361
if ([type isEqualToString:@"focus"]) {
363-
SemanticsObject* node = objects_.get()[annotatedEvent[@"nodeId"]];
362+
SemanticsObject* node = objects_[annotatedEvent[@"nodeId"]];
364363
ios_delegate_->PostAccessibilityNotification(UIAccessibilityLayoutChangedNotification, node);
365364
}
366365
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#import <UIKit/UIKit.h>
1212

1313
#include "flow/surface.h"
14-
#include "fml/platform/darwin/scoped_nsobject.h"
1514

1615
#import "flutter/shell/platform/darwin/ios/ios_context.h"
1716

@@ -21,15 +20,15 @@ class IOSSurface;
2120

2221
/// @brief State holder for a Flutter overlay layer.
2322
struct OverlayLayer {
24-
OverlayLayer(const fml::scoped_nsobject<UIView>& overlay_view,
25-
const fml::scoped_nsobject<UIView>& overlay_view_wrapper,
23+
OverlayLayer(UIView* overlay_view,
24+
UIView* overlay_view_wrapper,
2625
std::unique_ptr<IOSSurface> ios_surface,
2726
std::unique_ptr<Surface> surface);
2827

2928
~OverlayLayer() = default;
3029

31-
fml::scoped_nsobject<UIView> overlay_view;
32-
fml::scoped_nsobject<UIView> overlay_view_wrapper;
30+
UIView* overlay_view;
31+
UIView* overlay_view_wrapper;
3332
std::unique_ptr<IOSSurface> ios_surface;
3433
std::unique_ptr<Surface> surface;
3534

0 commit comments

Comments
 (0)