-
Notifications
You must be signed in to change notification settings - Fork 6k
[macos] Re-land FlutterOpenGLRenderer isolation #22607
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
@stuartmorgan I addressed your feedback in the earlier commit. I also made it a non-breaking change. |
767967a to
d677997
Compare
stuartmorgan-g
left a comment
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.
Now that we have the ability to write proc-table-based unit tests, is there a reason this change can't be tested?
| [_openGLRenderer clearResourceContext]; | ||
| [self shutDownEngine]; | ||
| _resourceContext = nil; | ||
| } |
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 is a codepath here (nil controller, _allowHeadlessExecution true) wher you aren't updating the renderer.
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.
Fixed it to clear the resource context when we don't have a view controller.
|
|
||
| FlutterView* _flutterView; | ||
|
|
||
| // The context that is owned by the currently displayed FlutterView. This is stashed |
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.
Is this comment still accurate? This class is creating the context.
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.
This was valid during an earlier iteration, fixed it now.
| FlutterExternalTextureGL* FlutterTexture = | ||
| [[FlutterExternalTextureGL alloc] initWithFlutterTexture:texture]; | ||
| int64_t textureID = [FlutterTexture textureID]; | ||
| auto success = _embedderAPI.RegisterExternalTexture(_engine, textureID); |
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.
Please use explicit types rather than auto everywhere for embedder API results; the type of the return value is not obvious from just the code on the RHS, which is the suggested use case for auto in the style guide.
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
|
Fixed the review comments modulo adding a test. I didn't realize that have proc-table based tests. Will add some for this. |
d9d893e to
07e866e
Compare
shell/platform/darwin/macos/framework/Source/FlutterExternalTextureGL.mm
Show resolved
Hide resolved
| @implementation FlutterEngineRegistrar { | ||
| NSString* _pluginKey; | ||
| FlutterEngine* _flutterEngine; | ||
| FlutterEngineProcTable _embedderAPI; |
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.
This wasn't used.
|
I've added a tests in |
| return kSuccess; | ||
| }); | ||
|
|
||
| [engine.openGLRenderer registerTexture:flutterTexture]; |
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.
These tests are all testing the OpenGL renderer, so should be in a new test file for that class rather than going through the engine.
| [[FlutterExternalTextureGL alloc] initWithFlutterTexture:texture]; | ||
| int64_t textureID = [FlutterTexture textureID]; | ||
| FlutterEngineResult success = | ||
| _flutterEngine.embedderAPI.RegisterExternalTexture(_engine, textureID); |
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.
These calls should be wrapped as private FlutterEngine methods, rather than having other classes calling into embedderAPI directly.
| } | ||
| } | ||
|
|
||
| #pragma mark - Helper methods to create rendering config for embedder. |
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.
This kind of comment belongs on the specific declaration; if anyone adds another private method they are unlikely to notice and update this, at which point it will be actively misleading. You can just use #pragma mark - Private methods
0daf9a2 to
64183a6
Compare
stuartmorgan-g
left a comment
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.
Code mostly looks good; some nits below. On the testing front, why is so little of the new renderer class tested? It seems like with some simple ObjC mocks you could test many of the core methods. E.g., that fboForFrameInfo: works as expected depending on whether or not attachToFlutterView: has beend called.
| /** | ||
| * Registers an external texture with the given id. Returns true on success. | ||
| */ | ||
| - (bool)embedderRegisterTextureWithId:(int64_t)textureId; |
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.
Nit for all three: use BOOL for ObjC interfaces unless there's a compelling reason not to. (Comments should then be updated to s/true/YES/)
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
| /** | ||
| * Registers an external texture with the given id. Returns true on success. | ||
| */ | ||
| - (bool)embedderRegisterTextureWithId:(int64_t)textureId; |
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.
Starting the names with embedder is unusual ObjC naming (other than for cases like protocols), and all of the methods in this header are for talking to the embedder API so it's odd to prefix some of them. I would just call them registerTextureWithID:, etc.
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
| /** | ||
| * Registers an external texture with the given id. Returns true on success. | ||
| */ | ||
| - (bool)embedderRegisterTextureWithId:(int64_t)textureId; |
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.
s/Id/ID/ in both method name and param name. ObjC capitalizes acronyms differently than C++ style. (Or use Identifier; either is fine.)
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
| #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" | ||
| #import "flutter/shell/platform/embedder/embedder.h" | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN |
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.
I despise this macro; it makes important information non-local when people are reading code--especially when reviewing and context is collapsed by default--and have never used it in the macOS code. Please use explicit annotations.
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
|
|
||
| @implementation FlutterOpenGLRenderer { | ||
| // The embedding-API-level engine object. | ||
| FLUTTER_API_SYMBOL(FlutterEngine) _engine; |
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.
You should be able to remove this now, including from the constructor making it just initWithEngine: (and thus also remove the embedder.h include in the header, I believe.)
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.
Removed this, but not embedder.h from the header since there is a helper method in this class that returuns FlutterRendererConfig.
| /** | ||
| * Called by the engine to make the context the engine should draw into current. | ||
| */ | ||
| - (bool)makeCurrent; |
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.
These can all be BOOLs as well, and the implementations updated to YES/NO. (I should really have done that before when the statics were updated to call directly to ObjC versions; this is a good time to fix it.)
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
| namespace flutter::testing { | ||
|
|
||
| namespace { | ||
| // Returns an engine configured for the text fixture resource configuration. |
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.
Typo: test->text
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
|
@stuartmorgan I've added more tests for the renderer. PTAL |
|
Stuart is OOO till Monday. |
|
@stuartmorgan friendly ping on this |
| .open_gl.make_resource_current = (BoolCallback)OnMakeResourceCurrent, | ||
| .open_gl.gl_external_texture_frame_callback = (TextureFrameCallback)OnAcquireExternalTexture, | ||
| }; | ||
| [_openGLRenderer attachToFlutterView:_viewController.flutterView]; |
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.
attachToFlutterView:'s parameter is marked non-null, but there's no guarantee that there's a _viewController. You need the same logic you have in setViewController: here as well. Alternately, you could make this kind of mistake impossible and remove duplicated code by having attachToFlutterView: allow nil (maybe changing its name to setFlutterView:), and remove clearResourceContext.
|
|
||
| - (BOOL)makeResourceCurrent { | ||
| [self.resourceContext makeCurrentContext]; | ||
| return true; |
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.
s/true/YES/
| } | ||
|
|
||
| - (void)textureFrameAvailable:(int64_t)textureID { | ||
| bool success = [_flutterEngine markTextureFrameAvailable:textureID]; |
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.
s/bool/BOOL/
| } | ||
|
|
||
| - (void)unregisterTexture:(int64_t)textureID { | ||
| bool success = [_flutterEngine unregisterTextureWithID:textureID]; |
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.
s/bool/BOOL/
This reverts commit be7f80e.
68ca69d to
a7f1609
Compare
stuartmorgan-g
left a comment
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.
Changes LGTM
Isolate macOS OpenGL renderer config generation to
FlutterOpenGLRendererclass.This reverts commit be7f80e.