-
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 7 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,14 @@ | ||
| // 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 | ||
| @interface FlutterTextureRegistryRelay : NSObject <FlutterTextureRegistry> | ||
|
Contributor
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?
Contributor
Author
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.
Member
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?
Contributor
Author
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?
Member
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:
Contributor
Author
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. |
||
| @property(nonatomic, assign) NSObject<FlutterTextureRegistry>* parent; | ||
| - (instancetype)initWithParent:(NSObject<FlutterTextureRegistry>*)parent; | ||
| @end | ||
|
endless7 marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||||||||||||||
| // 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 { | ||||||||||||||||||||||||
| self = [super init]; | ||||||||||||||||||||||||
| if (self != nil) { | ||||||||||||||||||||||||
|
Contributor
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. optional nits:
Suggested change
this is following the pattern in the objc document: https://developer.apple.com/documentation/objectivec/nsobject/1418641-init?language=objc
Contributor
Author
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 |
||||||||||||||||||||||||
| self.parent = parent; | ||||||||||||||||||||||||
|
Member
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.
Suggested change
Contributor
Author
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. |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return self; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - (int64_t)registerTexture:(NSObject<FlutterTexture>*)texture { | ||||||||||||||||||||||||
| if (self.parent) { | ||||||||||||||||||||||||
| return [self.parent registerTexture:texture]; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| FML_LOG(WARNING) << "Using on an empty registry."; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||
|
Contributor
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. optional nits, escape early:
Suggested change
Contributor
Author
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 |
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - (void)textureFrameAvailable:(int64_t)textureId { | ||||||||||||||||||||||||
| if (self.parent) { | ||||||||||||||||||||||||
| return [self.parent textureFrameAvailable:textureId]; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| FML_LOG(WARNING) << "Using on an empty registry."; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - (void)unregisterTexture:(int64_t)textureId { | ||||||||||||||||||||||||
| if (self.parent) { | ||||||||||||||||||||||||
| return [self.parent unregisterTexture:textureId]; | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| FML_LOG(WARNING) << "Using on an empty registry."; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
endless7 marked this conversation as resolved.
|
||||||||||||||||||||||||
| @end | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // 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" | ||
|
|
||
| #import <OCMock/OCMock.h> | ||
| #import <XCTest/XCTest.h> | ||
|
|
||
| #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" | ||
|
|
||
| FLUTTER_ASSERT_ARC | ||
|
|
||
| @interface FlutterTextureRegistryRelayTest : XCTestCase | ||
| @end | ||
|
|
||
| @implementation FlutterTextureRegistryRelayTest | ||
|
endless7 marked this conversation as 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]); | ||
| } | ||
|
|
||
| @end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.