-
Notifications
You must be signed in to change notification settings - Fork 6k
iOS FlutterTextureRegistry should be a proxy, not the engine itself #37666
Changes from all commits
79fba0b
14feca2
dc1f340
b3beefd
f49856c
857f959
9bde5fc
a754c39
5b91b48
6934d90
446a3ef
784a1e8
1bca083
2e25e93
f18803d
860c244
41d503b
3d43683
bdbe21e
a166525
40324bd
7a69a39
10ab885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" | ||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h" | ||
|
||
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG | ||
FLUTTER_DARWIN_EXPORT | ||
#endif | ||
|
||
/** | ||
* Wrapper around a weakly held collection of registered textures. | ||
* | ||
* Avoids a retain cycle between plugins and the engine. | ||
*/ | ||
@interface FlutterTextureRegistryRelay : NSObject <FlutterTextureRegistry> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment explaining that this relay is used to solve the issue with plugin retaining the engine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use From this comment I don't really understand when this would be used. Returned from what? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jmagman, are these comments ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, this would be better. |
||
|
||
/** | ||
* A weak reference to a FlutterEngine that will be passed texture registration. | ||
*/ | ||
@property(nonatomic, assign) NSObject<FlutterTextureRegistry>* parent; | ||
- (instancetype)initWithParent:(NSObject<FlutterTextureRegistry>*)parent; | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h" | ||
|
||
#include "flutter/fml/logging.h" | ||
|
||
@implementation FlutterTextureRegistryRelay : NSObject | ||
|
||
#pragma mark - FlutterTextureRegistry | ||
|
||
- (instancetype)initWithParent:(NSObject<FlutterTextureRegistry>*)parent { | ||
if (self = [super init]) { | ||
_parent = parent; | ||
} | ||
return self; | ||
} | ||
|
||
- (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture { | ||
if (!self.parent) { | ||
FML_LOG(WARNING) << "Using on an empty registry."; | ||
return 0; | ||
} | ||
return [self.parent registerTexture:texture]; | ||
} | ||
|
||
- (void)textureFrameAvailable:(int64_t)textureId { | ||
if (!self.parent) { | ||
FML_LOG(WARNING) << "Using on an empty registry."; | ||
} | ||
return [self.parent textureFrameAvailable:textureId]; | ||
} | ||
|
||
- (void)unregisterTexture:(int64_t)textureId { | ||
if (!self.parent) { | ||
FML_LOG(WARNING) << "Using on an empty registry."; | ||
} | ||
return [self.parent unregisterTexture:textureId]; | ||
} | ||
|
||
endless7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h" | ||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h" | ||
|
||
#import <OCMock/OCMock.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" | ||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h" | ||
|
||
FLUTTER_ASSERT_ARC | ||
|
||
@interface FlutterTextureRegistryRelayTest : XCTestCase | ||
@end | ||
|
||
@implementation FlutterTextureRegistryRelayTest | ||
endless7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- (void)testCreate { | ||
id textureRegistry = OCMProtocolMock(@protocol(FlutterTextureRegistry)); | ||
FlutterTextureRegistryRelay* relay = | ||
[[FlutterTextureRegistryRelay alloc] initWithParent:textureRegistry]; | ||
XCTAssertNotNil(relay); | ||
XCTAssertEqual(textureRegistry, relay.parent); | ||
} | ||
|
||
- (void)testRegisterTexture { | ||
id textureRegistry = OCMProtocolMock(@protocol(FlutterTextureRegistry)); | ||
FlutterTextureRegistryRelay* relay = | ||
[[FlutterTextureRegistryRelay alloc] initWithParent:textureRegistry]; | ||
id texture = OCMProtocolMock(@protocol(FlutterTexture)); | ||
[relay registerTexture:texture]; | ||
OCMVerify([textureRegistry registerTexture:texture]); | ||
} | ||
|
||
- (void)testTextureFrameAvailable { | ||
id textureRegistry = OCMProtocolMock(@protocol(FlutterTextureRegistry)); | ||
FlutterTextureRegistryRelay* relay = | ||
[[FlutterTextureRegistryRelay alloc] initWithParent:textureRegistry]; | ||
[relay textureFrameAvailable:0]; | ||
OCMVerify([textureRegistry textureFrameAvailable:0]); | ||
} | ||
|
||
- (void)testUnregisterTexture { | ||
id textureRegistry = OCMProtocolMock(@protocol(FlutterTextureRegistry)); | ||
FlutterTextureRegistryRelay* relay = | ||
[[FlutterTextureRegistryRelay alloc] initWithParent:textureRegistry]; | ||
[relay unregisterTexture:0]; | ||
OCMVerify([textureRegistry unregisterTexture:0]); | ||
} | ||
|
||
- (void)testRetainCycle { | ||
__weak FlutterEngine* weakEngine; | ||
NSObject<FlutterTextureRegistry>* strongRelay; | ||
@autoreleasepool { | ||
id project = OCMClassMock([FlutterDartProject class]); | ||
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project]; | ||
strongRelay = [engine textureRegistry]; | ||
weakEngine = engine; | ||
} | ||
XCTAssertNil(weakEngine); | ||
} | ||
|
||
@end |
Uh oh!
There was an error while loading. Please reload this page.