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

Move renderer config to EmbedderTestContext #56699

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

cbracken
Copy link
Member

@cbracken cbracken commented Nov 19, 2024

Moves all backend-specific renderer configuration out of EmbedderConfigBuilder and into the backend-specific subclasses of EmbedderTestContext. EmbedderTestContext is already backend-specific and as of recent patches, also houses compositor configuration, making it the natural home of this code.

As a result, we no longer need backend-specific methods such as SetSoftwareRendererConfig, SetMetalRendererConfig, SetOpenGLRendererConfig, SetVulkanRendererConfig. Nor do we need manual backend initialisation in EmbedderConfigBuilder. Nor does that initialisation any longer require relying on internal backend-specific code within EmbedderTestContext, since we now do that initialisation in the EmbedderTestContext constructor.

Since the bulk of the work previously done by this method now occurs in the EmbedderTestContext constructor, the only work remaining in these methods is surface creation. Further, since this is all now implemented in backend-specific EmbedderTestContext subclasses, they have all been renamed to a single method: SetSurface.

Previously, all of these methods took a surface_size parameter, with two exceptions:

  • SetVulkanRendererConfig also took an optional FlutterVulkanInstanceProcAddressCallback parameter. This has been extracted to a separate method SetVulkanInstanceProcAddressCallback on EmbedderTestContextVulkan.
  • SetSoftwareRendererConfig defaulted the parameter to a size of (1, 1). For consistency, this is no longer defaulted, and all call sites have been updated, consistent with other backends.

Lastly, one nice benefit is that because the render config is initialised in the EmbedderTestContext constructor, there's no longer a requirement to call Set*RendererConfig prior modifying any specific properties on the config, nor is it problematic to call the (replacement) SetSurface method after modifying the config. Where the renderer config was being customised in embedder unit tests, I've pushed that customisation up to the top of the test where the rest of the test context is configured.

This eliminates nearly all remaining #ifdef SHELL_ENABLE_$BACKEND blocks in the EmbedderTest infrastructure.

Issue: flutter/flutter#158998

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

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@cbracken
Copy link
Member Author

If there are cases where we specifically want to test with no renderer config set, I’d like to know about them. It’d be a straightforward tweak to this.

@@ -27,28 +26,6 @@ EmbedderConfigBuilder::EmbedderConfigBuilder(

custom_task_runners_.struct_size = sizeof(FlutterCustomTaskRunners);

InitializeGLRendererConfig();
InitializeMetalRendererConfig();
InitializeVulkanRendererConfig();
Copy link
Member Author

@cbracken cbracken Nov 19, 2024

Choose a reason for hiding this comment

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

The initialise methods above (and the similar software renderer config initialisation below) moved to ctors of EmbedderTestContextMetal etc.

SetSoftwareRendererConfig(surface_size);
break;
}
}
Copy link
Member Author

@cbracken cbracken Nov 19, 2024

Choose a reason for hiding this comment

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

No need for for the type argument anymore since the EmbedderConfigBuilder already took an EmbedderTestContext of that type in its constructor, so we knew the type all along. Renamed all the referenced methods to just EmbedderTestContext{GL,Metal,Sofware,Vulkan}::SetRendererConfig except turns out that now that the initialisation is done in the ctor, all they actually do is create the surface of the right type with the specified size, so renamed them to SetSurface(surface_size).

@@ -217,10 +170,6 @@ void EmbedderConfigBuilder::SetupVsyncCallback() {
};
}

FlutterRendererConfig& EmbedderConfigBuilder::GetRendererConfig() {
return renderer_config_;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Unloved and unused now.

@@ -349,52 +299,4 @@ UniqueEngine EmbedderConfigBuilder::SetupEngine(bool run) const {
return UniqueEngine{engine};
}

#ifndef SHELL_ENABLE_GL
Copy link
Member Author

Choose a reason for hiding this comment

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

Everything below here are just methods on the appropriate EmbedderTestContext subclass. People who need GL-specific methods can get them from the GL subclass, etc.

@cbracken cbracken force-pushed the refactor-render-context branch from 143c8c6 to 2239bdb Compare November 19, 2024 15:30
@@ -35,7 +35,7 @@ TEST_F(EmbedderTest, CannotProvideMultipleSemanticsCallbacks) {
{
EmbedderConfigBuilder builder(
GetEmbedderContext(EmbedderTestContextType::kSoftwareContext));
builder.SetSoftwareRendererConfig();
builder.SetSurface(SkISize::Make(1, 1));
Copy link
Member Author

Choose a reason for hiding this comment

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

Here and below (1, 1) was the default parameter value... but we only ever defaulted it for the software renderer, now we're consistent across the board and make people announce what they want so readers don't need to check the method declaration.

@@ -96,6 +96,10 @@ void EmbedderTestContext::SetRootSurfaceTransformation(SkMatrix matrix) {
root_surface_transformation_ = matrix;
}

FlutterRendererConfig& EmbedderTestContext::GetRendererConfig() {
return renderer_config_;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Used by EmbedderConfigBuilder::LaunchEngine.

@@ -72,9 +72,7 @@ class EmbedderTestContext {

void SetRootSurfaceTransformation(SkMatrix matrix);

void SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt);
Copy link
Member Author

Choose a reason for hiding this comment

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

Unused method declaration with no definition. I removed it in #56626 but missed cleaning this up.

@@ -178,8 +179,6 @@ class EmbedderTestContext {

void SetNextSceneCallback(const NextSceneCallback& next_scene_callback);

virtual void SetupSurface(SkISize surface_size) = 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

These methods are no longer necessary because it turns out that all that the Set*RenderConfig methods did was initialise the render config (done in the ctors of this subclass now) and call this method.

},
.populate_existing_damage = nullptr,
};
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Here and in the other EmbedderTestContext subclass ctors: this is just the code from the old Initialize*FooRenderConfig methods except using designated initialiser notation for readability, which also forces the members to be initialised in the order they're declared in embedder.h, hence the reordering.

FlutterPresentInfo{
.fbo_id = 0,
});
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved here from ifdef'ed code on EmbedderConfigBuilder.


void SetupCompositorUsingGLSurfaces();
Copy link
Member Author

Choose a reason for hiding this comment

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

Went looking and this method was never used and had no definition. 🤷‍♂️


private:
Copy link
Member Author

Choose a reason for hiding this comment

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

This stuff is all private now instead of protected since there are no subclasses.

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

RSLGTM

@cbracken cbracken force-pushed the refactor-render-context branch from 2239bdb to 694c855 Compare November 19, 2024 15:46
private:
// This allows the builder to access the hooks.
friend class EmbedderConfigBuilder;
Copy link
Member Author

Choose a reason for hiding this comment

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

Friendship ended with EmbedderConfigBuilder.

FML_CHECK(metal_surface_) << "Set up the Metal surface before setting up a compositor.";
compositor_ =
std::make_unique<EmbedderTestCompositorMetal>(surface_size_, metal_surface_->GetGrContext());
}
Copy link
Member Author

Choose a reason for hiding this comment

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

For consistency with header declaration order, moved these guys down to the bottom given that they're private.

Moves all backend-specific renderer configuration out of
EmbedderConfigBuilder and into the backend-specific subclass of
EmbedderTestContext. EmbedderTestContext is already backend-specific and
as of recent patches, also houses compositor configuration, making it
the natural home of this code.

As a result, we no longer need backend-specific methods such as
SetSoftwareRendererConfig, SetMetalRendererConfig, etc. Nor do we need
manual backend initialization in EmbedderConfigBuilder. Nor does that
initialization any longer require relying on internal backend-specific
code within EmbedderTestContext, since we now do that initialization in
the EmbedderTestContext constructor.

Since the bulk of the work previously done by this method now occurs in
the EmbedderTestContext constructor, the only work remaining in these
methods is surface creation. Further, since theses are now implemented
in backend-specific EmbedderTestContext subclasses, they have all been
renamed to a single method: SetSurface.

Previously, all of these methods took a surface_size parameter with two
exceptions:
* SetVulkanRendererConfig also took an optional
  FlutterVulkanInstanceProcAddressCallback parameter. This has been
  extracted to a separate method SetVulkanInstanceProcAddressCallback on
  EmbedderTestContextVulkan.
* SetSoftwareRendererConfig defaulted the parameter to a size of (1, 1).
  For consistency, this is no longer defaulted, and all call sites have
  been updated, consistent with other backends.

Lastly, one nice benefit is that because the render config is
initialized in the EmbedderTestContext constructor, there's no longer a
requirement to call Set*RendererConfig prior modifying any specific
properties on the config, nor is it problematic to call the updated
SetSurface method after modifying the config. Where the renderer config
was being customised in embedder unittests, I've pushed that
customisation up to the top of the test where the rest of the test
context is configured.

Issue: flutter/flutter#158998
@cbracken cbracken force-pushed the refactor-render-context branch from 694c855 to 9b8236f Compare November 19, 2024 15:51
EmbedderConfigBuilder builder(context);
builder.SetVulkanRendererConfig(
SkISize::Make(1024, 1024),
context.SetVulkanInstanceProcAddressCallback(
Copy link
Member Author

Choose a reason for hiding this comment

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

Vulkan-specific context configuration now occurs on the Vulkan-specific context.


EmbedderConfigBuilder builder(context);
builder.SetOpenGLRendererConfig(SkISize::Make(600, 1024));
builder.SetDartEntrypoint("push_frames_over_and_over");
Copy link
Member Author

@cbracken cbracken Nov 19, 2024

Choose a reason for hiding this comment

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

Here and below: There used to be an unobvious ordering requirement wherein any backend-specific context configuration could only happen after the EmbedderConfigBuilder::Set*RendererConfig() call (otherwise the Set*RendererConfig would stomp it. We no longer have that ordering dependency, so we can now group context configuration together at the top, and builder configuration together afterwards.

Further, a few of the backend-specific calls that used to be exposed on the non-backend-specific EmbedderConfigBuilder are now exposed on the backend-specific EmbedderTestContext, in order to avoid nonsensical calls like setting GL callbacks on a Metal test context.

builder.SetDartEntrypoint("push_frames_over_and_over");

auto& context = static_cast<EmbedderTestContextGL&>(
GetEmbedderContext(EmbedderTestContextType::kOpenGLContext));
Copy link
Member Author

Choose a reason for hiding this comment

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

In a followup patch I'm going to try rewriting this method to be templatised so we can do this and just get the right type out automatically like you can do with std::variant:

auto& context GetEmbedderContext<EmbedderTestContextGL>();

@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2024
@auto-submit auto-submit bot merged commit 3e96ceb into flutter:main Nov 19, 2024
31 checks passed
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2024
@cbracken cbracken deleted the refactor-render-context branch November 19, 2024 16:55
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 19, 2024
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Nov 19, 2024
…159155)

flutter/engine@cff1e75...d5820a6

2024-11-19 skia-flutter-autoroll@skia.org Roll Skia from 0b74a1bb1b55 to
78ef6b7a574f (6 revisions) (flutter/engine#56707)
2024-11-19 chris@bracken.jp Move renderer config to EmbedderTestContext
(flutter/engine#56699)
2024-11-19 skia-flutter-autoroll@skia.org Roll Skia from 8a1a84509501 to
0b74a1bb1b55 (1 revision) (flutter/engine#56702)
2024-11-19 skia-flutter-autoroll@skia.org Roll Dart SDK from
05d58364e92f to b01654fa26c7 (1 revision) (flutter/engine#56694)
2024-11-19 chris@bracken.jp EmbedderTest: Eliminate unused include
(flutter/engine#56698)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC aaclarke@google.com,zra@google.com on the revert to ensure
that a human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
Moves all backend-specific renderer configuration out of `EmbedderConfigBuilder` and into the backend-specific subclasses of `EmbedderTestContext`. `EmbedderTestContext` is already backend-specific and as of recent patches, also houses compositor configuration, making it the natural home of this code.

As a result, we no longer need backend-specific methods such as `SetSoftwareRendererConfig`, `SetMetalRendererConfig`, `SetOpenGLRendererConfig`, `SetVulkanRendererConfig`. Nor do we need manual backend initialisation in `EmbedderConfigBuilder`. Nor does that initialisation any longer require relying on internal backend-specific code within `EmbedderTestContext`, since we now do that initialisation in the `EmbedderTestContext` constructor.

Since the bulk of the work previously done by this method now occurs in the `EmbedderTestContext` constructor, the only work remaining in these methods is surface creation. Further, since this is all now implemented in backend-specific `EmbedderTestContext` subclasses, they have all been renamed to a single method: `SetSurface`.

Previously, all of these methods took a surface_size parameter, with two exceptions:
* `SetVulkanRendererConfig` also took an optional `FlutterVulkanInstanceProcAddressCallback` parameter. This has been extracted to a separate method `SetVulkanInstanceProcAddressCallback` on `EmbedderTestContextVulkan`.
* `SetSoftwareRendererConfig` defaulted the parameter to a size of (1, 1). For consistency, this is no longer defaulted, and all call sites have been updated, consistent with other backends.

Lastly, one nice benefit is that because the render config is initialised in the `EmbedderTestContext` constructor, there's no longer a requirement to call `Set*RendererConfig` prior modifying any specific properties on the config, nor is it problematic to call the (replacement) `SetSurface` method after modifying the config. Where the renderer config was being customised in embedder unit tests, I've pushed that customisation up to the top of the test where the rest of the test context is configured.

This eliminates nearly all remaining `#ifdef SHELL_ENABLE_$BACKEND` blocks in the EmbedderTest infrastructure.

Issue: flutter#158998

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants