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

Implement the render_to_surface flag in GPUSurfaceGLImpeller #50669

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion shell/gpu/gpu_surface_gl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace flutter {

GPUSurfaceGLImpeller::GPUSurfaceGLImpeller(
GPUSurfaceGLDelegate* delegate,
std::shared_ptr<impeller::Context> context)
std::shared_ptr<impeller::Context> context,
bool render_to_surface)
: weak_factory_(this) {
if (delegate == nullptr) {
return;
Expand All @@ -38,6 +39,7 @@ GPUSurfaceGLImpeller::GPUSurfaceGLImpeller(

delegate_ = delegate;
impeller_context_ = std::move(context);
render_to_surface_ = render_to_surface;
impeller_renderer_ = std::move(renderer);
aiks_context_ = std::move(aiks_context);
is_valid_ = true;
Expand Down Expand Up @@ -82,6 +84,15 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
return nullptr;
}

if (!render_to_surface_) {
return std::make_unique<SurfaceFrame>(
nullptr, SurfaceFrame::FramebufferInfo{.supports_readback = true},
[](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
return true;
},
size);
}

GLFrameInfo frame_info = {static_cast<uint32_t>(size.width()),
static_cast<uint32_t>(size.height())};
const GLFBOInfo fbo_info = delegate_->GLContextFBO(frame_info);
Expand Down
4 changes: 3 additions & 1 deletion shell/gpu/gpu_surface_gl_impeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace flutter {
class GPUSurfaceGLImpeller final : public Surface {
public:
explicit GPUSurfaceGLImpeller(GPUSurfaceGLDelegate* delegate,
std::shared_ptr<impeller::Context> context);
std::shared_ptr<impeller::Context> context,
bool render_to_surface);

// |Surface|
~GPUSurfaceGLImpeller() override;
Expand All @@ -29,6 +30,7 @@ class GPUSurfaceGLImpeller final : public Surface {
private:
GPUSurfaceGLDelegate* delegate_ = nullptr;
std::shared_ptr<impeller::Context> impeller_context_;
bool render_to_surface_ = true;
std::shared_ptr<impeller::Renderer> impeller_renderer_;
std::shared_ptr<impeller::AiksContext> aiks_context_;
bool is_valid_ = false;
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/android/android_surface_gl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ bool AndroidSurfaceGLImpeller::IsValid() const {
std::unique_ptr<Surface> AndroidSurfaceGLImpeller::CreateGPUSurface(
GrDirectContext* gr_context) {
auto surface = std::make_unique<GPUSurfaceGLImpeller>(
this, // delegate
android_context_->GetImpellerContext() // context
this, // delegate
android_context_->GetImpellerContext(), // context
true // render to surface
);
if (!surface->IsValid()) {
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ test_fixtures("fixtures") {
"fixtures/dpr_noxform.png",
"fixtures/dpr_xform.png",
"fixtures/gradient.png",
"fixtures/impeller_gl_gradient.png",
"fixtures/vk_dpr_noxform.png",
"fixtures/vk_gradient.png",
"fixtures/gradient_metal.png",
Expand All @@ -250,7 +251,6 @@ test_fixtures("fixtures") {
"fixtures/scene_without_custom_compositor.png",
"fixtures/scene_without_custom_compositor_with_xform.png",
"fixtures/snapshot_large_scene.png",
"fixtures/solid_red.png",
"fixtures/verifyb143464703.png",
"fixtures/verifyb143464703_soft_noxform.png",
]
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/embedder/embedder_surface_gl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ EmbedderSurfaceGLImpeller::GLContextFramebufferInfo() const {
// |EmbedderSurface|
std::unique_ptr<Surface> EmbedderSurfaceGLImpeller::CreateGPUSurface() {
return std::make_unique<GPUSurfaceGLImpeller>(
this, // GPU surface GL delegate
impeller_context_ // render to surface
this, // GPU surface GL delegate
impeller_context_, // Impeller context
!external_view_embedder_ // render to surface
);
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed shell/platform/embedder/fixtures/solid_red.png
Binary file not shown.
14 changes: 12 additions & 2 deletions shell/platform/embedder/tests/embedder_gl_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4704,8 +4704,14 @@ TEST_F(EmbedderTest, CanRenderWithImpellerOpenGL) {
auto& context = GetEmbedderContext(EmbedderTestContextType::kOpenGLContext);
EmbedderConfigBuilder builder(context);

bool present_called = false;
static_cast<EmbedderTestContextGL&>(context).SetGLPresentCallback(
[&present_called](FlutterPresentInfo present_info) {
present_called = true;
});

builder.AddCommandLineArgument("--enable-impeller");
builder.SetDartEntrypoint("draw_solid_red");
builder.SetDartEntrypoint("render_gradient");
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
builder.SetCompositor();
builder.SetRenderTargetType(
Expand All @@ -4727,8 +4733,12 @@ TEST_F(EmbedderTest, CanRenderWithImpellerOpenGL) {

ASSERT_TRUE(ImageMatchesFixture(
FixtureNameForBackend(EmbedderTestContextType::kOpenGLContext,
"solid_red.png"),
"impeller_gl_gradient.png"),
rendered_scene));

// The scene will be rendered by the compositor, and the surface present
// callback should not be invoked.
ASSERT_FALSE(present_called);
}

INSTANTIATE_TEST_SUITE_P(
Expand Down