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

Conversation

@blasten
Copy link

@blasten blasten commented May 29, 2020

This will make the relation between AndroidContext and AndroidSurface closer to IOSContext and IOSSurface.

With this change, every GL surface will own an onscreen and offscreen EGLSurface as opposed to the Android context owning the surfaces.

Fixes flutter/flutter#58269

namespace flutter {

class AndroidContextGL : public fml::RefCountedThreadSafe<AndroidContextGL> {
class AndroidContextGL : public AndroidContext {
Copy link
Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Sound good.

@blasten blasten marked this pull request as ready for review May 29, 2020 21:02
@auto-assign auto-assign bot requested a review from jason-simmons May 29, 2020 21:03
@blasten blasten requested a review from chinmaygarde June 1, 2020 18:03
Copy link
Member

@chinmaygarde chinmaygarde left a 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;
Copy link
Member

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.

Copy link
Author

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.";
Copy link
Member

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.

Copy link
Author

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:
Copy link
Member

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

Copy link
Author

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_;
Copy link
Member

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.

Copy link
Author

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(
Copy link
Member

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) ||
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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 {
Copy link
Member

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@blasten blasten requested a review from chinmaygarde June 3, 2020 00:34
@blasten
Copy link
Author

blasten commented Jun 4, 2020

PTAL

if (!eglQuerySurface(environment_->Display(), surface_, EGL_WIDTH, &width) ||
!eglQuerySurface(environment_->Display(), surface_, EGL_HEIGHT,
&height)) {
if (!eglQuerySurface(environment_->Display(), surface, EGL_WIDTH, &width) ||
Copy link
Member

Choose a reason for hiding this comment

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

Discussed this via chat.

@blasten blasten added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jun 5, 2020
@fluttergithubbot fluttergithubbot merged commit fafccf8 into flutter:master Jun 5, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 5, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 5, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 5, 2020
@blasten blasten deleted the android_context branch June 10, 2020 18:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to share AndroidContext across multiple AndroidSurfaces.

4 participants