-
Notifications
You must be signed in to change notification settings - Fork 6k
Refactor AndroidContextGL, AndroidSurface and AndroidSurfaceGL #18670
Conversation
| namespace flutter { | ||
|
|
||
| class AndroidContextGL : public fml::RefCountedThreadSafe<AndroidContextGL> { | ||
| class AndroidContextGL : public AndroidContext { |
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 isn't a fml::RefCountedThreadSafe anymore. AndroidContextGL will be a shared pointer.
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.
Sound good.
chinmaygarde
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.
Sound direction and thanks for the separation of the surface and the context. Just a few nits and the one comment about making EGLSurface an RAII object.
| } | ||
|
|
||
| bool AndroidContext::IsValid() { | ||
| 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.
What is the point of this method if it is always true? It seems you are not returning a non-valid context from the factory. If you don't plan on adding to this, I'd get rid of this.
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. This has been removed.
| break; | ||
| } | ||
| FML_CHECK(context); | ||
| FML_CHECK(context->IsValid()) << "Could not create an Android 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.
IsValid is not virtual and always returns true. So this check is redundant. I suggest making IsValid a const pure virtual so that AndroidContext itself is abstract. Then in the IsValid override for each, you can return if the context is actually valid.
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.
| context = std::make_shared<AndroidContextGL>( | ||
| rendering_api, fml::MakeRefCounted<AndroidEnvironmentGL>()); | ||
| break; | ||
| case AndroidRenderingAPI::kVulkan: |
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 breaking Vulkan builds right? (its been quite a long time since I have checked those builds BTW, if maintaining those is getting in the way, we should get rid of them).
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.
It shouldn't be a break the build AFAICT.
| bool IsValid(); | ||
|
|
||
| private: | ||
| AndroidRenderingAPI rendering_api_; |
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.
Make this const so its impossible to forget to initialize this ivar.
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.
| const AndroidContextGL* share_context) | ||
| : environment_(env), | ||
| window_(nullptr), | ||
| AndroidContextGL::AndroidContextGL( |
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.
Much cleaner. Thanks!
| if (!eglQuerySurface(environment_->Display(), surface_, EGL_WIDTH, &width) || | ||
| !eglQuerySurface(environment_->Display(), surface_, EGL_HEIGHT, | ||
| &height)) { | ||
| if (!eglQuerySurface(environment_->Display(), surface, EGL_WIDTH, &width) || |
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.
If you are going to make EGLSurface an RAII object, it may make sense to put these behind accessors. Just a thought.
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 tried to use fml/unique_object.h, but I realized it was a bit tricky for one reason:
To destroy an EGLSurface, an instance of EGLDisplay is required. This is currently held by AndroidEnvironmentGL. While we currently just use EGL_DEFAULT_DISPLAY, I shouldn't assume that in a Free(EGLSurface* surface) method.
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.
Discussed this via chat.
| namespace flutter { | ||
|
|
||
| class AndroidContextGL : public fml::RefCountedThreadSafe<AndroidContextGL> { | ||
| class AndroidContextGL : public AndroidContext { |
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.
Sound good.
| bool CreatePBufferSurface(); | ||
| ~AndroidContextGL(); | ||
|
|
||
| EGLSurface CreateOnscreenSurface(fml::RefPtr<AndroidNativeWindow> window); |
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 should be const IMO.
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.
|
PTAL |
| if (!eglQuerySurface(environment_->Display(), surface_, EGL_WIDTH, &width) || | ||
| !eglQuerySurface(environment_->Display(), surface_, EGL_HEIGHT, | ||
| &height)) { | ||
| if (!eglQuerySurface(environment_->Display(), surface, EGL_WIDTH, &width) || |
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.
Discussed this via chat.
This will make the relation between
AndroidContextandAndroidSurfacecloser toIOSContextandIOSSurface.With this change, every GL surface will own an onscreen and offscreen
EGLSurfaceas opposed to the Android context owning the surfaces.Fixes flutter/flutter#58269