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

Conversation

@cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented May 26, 2020

In my last patch #17941. I introduced a RendererContextManager which manages a stack that pushes and pops GLContext.
This turns out to be problematic, as the stack has to be thread local, because the GLContexts are thread locals. And then if we make the stack thread local, we need to handle the case where 2 flutter shells exists and makes sure they don't interfere the stack.
It gets really complicated.
I think a better an easier way to solve this is to get rid of the manager and stack all together.
Instead, the GLContextSwitch will makes sure to call the SwitchableGLContext's setCurrent and removeCurrent during construction and destruction.
Then the SwitchableGLContext is responsible to reset the GLContext in removeCurrent.

A GLContextDefaultResult is introduced for platforms that are not using context switching yet.(Android, embedder)
Ideally, we should migrate all platforms to use context switching in the future.

@cyanglaz cyanglaz requested a review from chinmaygarde May 26, 2020 17:07
@auto-assign auto-assign bot requested a review from gaaclarke May 26, 2020 17:10
@cyanglaz cyanglaz force-pushed the context_switch_only branch from fd5ac21 to 7ec9c87 Compare May 26, 2020 17:30
@cyanglaz cyanglaz force-pushed the context_switch_only branch from 7ec9c87 to 202afe7 Compare May 26, 2020 17:31
SurfaceFrame(sk_sp<SkSurface> surface,
bool supports_readback,
const SubmitCallback& submit_callback,
std::unique_ptr<GLContextResult> context_result);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a GLContextResult in the constructor, so iOS platform can pass in a GLContectSwitch whose lifecycle is tied to the SurfaceFrame


#if FLUTTER_SHELL_ENABLE_METAL
bool ShouldUseMetalRenderer() {
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

REMOVE BEFORE LANDING!


class IOSSwitchableGLContext final : public SwitchableGLContext {
public:
IOSSwitchableGLContext(EAGLContext& context);
Copy link
Member

Choose a reason for hiding this comment

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

You should avoid passing non-const references, this will soon be a linter error:
https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs

It's especially egregious for NSObjects. This class should retain and release the eaglcontext, too.

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 should actually be const. I'll update. This class doesn't retain the EAGLContext, all the EAGLContexts are retained by IOSRenderTarget and IOSContextGL. This class should just use the context and never out live either of the 2.

FML_DISALLOW_COPY_AND_ASSIGN(SwitchableGLContext);
};

class GLContextResult {
Copy link
Member

Choose a reason for hiding this comment

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

Why have this class instead of using a bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to use GLContextSwitch on iOS to prevent plugins to pollute our context. For methods like MakeFlutterContextCurrent, we need to return a switch instead of a bool. But for platforms that doesn't require the switch (iOS software for example), we still need to return a same object. Making them returning a switch doesn't make sense as they are not actually switching context. So I thought to make this base class so at least the platforms that doesn't require a switch can return a same class.

/// In destruction, it should reset the current context back to what was
/// before the construction of this switch.
///
class GLContextSwitch final : public GLContextResult {
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit confusing a GLContextSwitch is a GLContextResult.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I know :p Need some help with refactoring and naming here :)

// happen in case of software rendering.
surface = SkSurface::MakeRaster(image_info);
} else {
if (!surface_->MakeRenderContextCurrent()) {
Copy link
Member

Choose a reason for hiding this comment

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

This particular change isn't as clear, surface_->MakeRenderContextCurrent is a much more clear verbiage than context_switch->GetResult

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to grab onto a switch object so it can live through out the scope.
The switch object clears the GLContext on destruction.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Hey chris, I don't quite get the value of this change. At face value it just looks like an obfuscation. What am I missing?

}

source_set("surface_frame") {
sources = [
Copy link

Choose a reason for hiding this comment

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

This target now has a different meaning. Something like standalone_common ? The purpose of this target is to avoid the dependency on //flutter/flow because //flutter/flow depends on this target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

offline discussion, we will use common_standalone

"//flutter/fml",
"//flutter/shell/common",
"//third_party/skia",
"//flutter/shell/common:surface_frame"
Copy link

Choose a reason for hiding this comment

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

gn format shell/gpu/BUILD.gn, so it automatically sorts the deps.

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

BUILD files LG + comment

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.

5 participants