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

Conversation

@iskakaushik
Copy link
Contributor

Isolate macOS OpenGL renderer config generation to FlutterOpenGLRenderer class.

This reverts commit be7f80e.

@flutter-dashboard
Copy link

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.

@iskakaushik
Copy link
Contributor Author

iskakaushik commented Nov 19, 2020

@stuartmorgan I addressed your feedback in the earlier commit. I also made it a non-breaking change.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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;
}
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@iskakaushik
Copy link
Contributor Author

Fixed the review comments modulo adding a test. I didn't realize that have proc-table based tests. Will add some for this.

@implementation FlutterEngineRegistrar {
NSString* _pluginKey;
FlutterEngine* _flutterEngine;
FlutterEngineProcTable _embedderAPI;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't used.

@iskakaushik
Copy link
Contributor Author

I've added a tests in FlutterEngineTests.mm.

return kSuccess;
});

[engine.openGLRenderer registerTexture:flutterTexture];
Copy link
Contributor

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);
Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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;
Copy link
Contributor

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/)

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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.)

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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.)

Copy link
Contributor Author

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;
Copy link
Contributor

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.)

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: test->text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@iskakaushik
Copy link
Contributor Author

@stuartmorgan I've added more tests for the renderer. PTAL

@chinmaygarde
Copy link
Member

Stuart is OOO till Monday.

@iskakaushik
Copy link
Contributor Author

@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];
Copy link
Contributor

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;
Copy link
Contributor

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];
Copy link
Contributor

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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/bool/BOOL/

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 7, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants