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

[WIP]Fix OpenGL leak on Android and iOS #28506

Closed
wants to merge 4 commits into from
Closed

[WIP]Fix OpenGL leak on Android and iOS #28506

wants to merge 4 commits into from

Conversation

linroid
Copy link

@linroid linroid commented Sep 8, 2021

Fix flutter/flutter#89658

Both destructors of AndroidContext and IOSContextGL are called on the platform thread, which is a wrong thread to release OpenGL resources.

Instead, this PR calls GrDirectContext::releaseResourcesAndAbandonContext() explictly on rasiterizer task running.

I'm working on investigating a property solution and adding tests.

Related PRs

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

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

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@linroid
Copy link
Author

linroid commented Sep 8, 2021

cc @xster @gaaclarke for visibility

@jason-simmons
Copy link
Member

See flutter/flutter#87937 (comment)

The engine should not be calling GrDirectContext::releaseResourcesAndAbandonContext on the platform thread (which does not have an EGL context).

This PR is not building though - there is no GPUSurfaceGL constructor that takes a GrDirectContext and a bool.

If the goal is to have AndroidSurfaceGL::CreateGPUSurface return a GPUSurfaceGL with context_owner_ = true when calling SetMainSkiaContext, then I do not think that will be safe if that main_skia_context may later be shared by other GPUSurfaceGL instances.

@linroid
Copy link
Author

linroid commented Sep 8, 2021

@jason-simmons I agree that the change is not safe, what about calling GrDirectContext::releaseResourcesAndAbandonContext() on the rasterizer thread when destructing Shell?

@linroid
Copy link
Author

linroid commented Sep 8, 2021

@jason-simmons I agree that the change is not safe, what about calling GrDirectContext::releaseResourcesAndAbandonContext() on the rasterizer thread when destructing Shell?

@jason-simmons I have updated my PR with this solution, what do you think? If the solution is ok, I'll patch some tests.

@jason-simmons
Copy link
Member

The issue is that the graphics context sharing mechanism allows multiple Shell instances to use the same GrDirectContext. So it will be unsafe for the shell's shutdown process to call releaseResourcesAndAbandonContext if some other shell may still be using the shared GrDirectContext.

@zanderso
Copy link
Member

zanderso commented Oct 7, 2021

I believe this PR has been made obsolete by some work that @gaaclarke has in progress. Please feel free to re-open if I am mistaken.

@zanderso zanderso closed this Oct 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenGL leak on Android and iOS
3 participants