Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,8 @@ ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface.cc + ../../../
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_gl.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_gl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_gl_impeller.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_gl_impeller.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_metal.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_metal.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_metal_impeller.h + ../../../flutter/LICENSE
Expand Down Expand Up @@ -5522,6 +5524,8 @@ FILE: ../../../flutter/shell/platform/embedder/embedder_surface.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_surface.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_gl.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_gl.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_gl_impeller.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_gl_impeller.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_metal.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_metal.mm
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_metal_impeller.h
Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/backend/gles/render_pass_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ struct RenderPassData {

if (gl.DiscardFramebufferEXT.IsAvailable()) {
std::vector<GLenum> attachments;

if (pass_data.discard_color_attachment) {
attachments.push_back(is_default_fbo ? GL_COLOR_EXT
: GL_COLOR_ATTACHMENT0);
Expand All @@ -460,7 +461,15 @@ struct RenderPassData {
attachments.push_back(is_default_fbo ? GL_DEPTH_EXT
: GL_DEPTH_ATTACHMENT);
}

// TODO(jonahwilliams): discarding the stencil on the default fbo when running
// on Windows causes Angle to discard the entire render target. Until we know
// the reason, default to storing.
#ifdef FML_OS_WIN
if (pass_data.discard_stencil_attachment && !is_default_fbo) {
#else
if (pass_data.discard_stencil_attachment) {
#endif
attachments.push_back(is_default_fbo ? GL_STENCIL_EXT
: GL_STENCIL_ATTACHMENT);
}
Expand Down
1 change: 0 additions & 1 deletion shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ RasterStatus Rasterizer::DrawToSurfaceUnsafe(

auto root_surface_canvas =
embedder_root_canvas ? embedder_root_canvas : frame->Canvas();

auto compositor_frame = compositor_context_->AcquireFrame(
surface_->GetContext(), // skia GrContext
root_surface_canvas, // root surface canvas
Expand Down
2 changes: 1 addition & 1 deletion shell/gpu/gpu_surface_gl_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GPUSurfaceGLDelegate {
virtual std::unique_ptr<GLContextResult> GLContextMakeCurrent() = 0;

// Called to clear the current GL context on the thread. This may be called on
// either the GPU or IO threads.
// either the Raster or IO threads.
virtual bool GLContextClearCurrent() = 0;

// Inform the GL Context that there's going to be no writing beyond
Expand Down
20 changes: 12 additions & 8 deletions shell/gpu/gpu_surface_gl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
delegate = delegate_]() -> bool {
if (weak) {
GLPresentInfo present_info = {
.fbo_id = 0,
.fbo_id = 0u,
.frame_damage = std::nullopt,
// TODO (https://github.com/flutter/flutter/issues/105597): wire-up
// presentation time to impeller backend.
Expand All @@ -80,10 +80,14 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
return nullptr;
}

GLFrameInfo frame_info = {static_cast<uint32_t>(size.width()),
static_cast<uint32_t>(size.height())};
const GLFBOInfo fbo_info = delegate_->GLContextFBO(frame_info);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this is enough to get window resizing working.


auto surface = impeller::SurfaceGLES::WrapFBO(
impeller_context_, // context
swap_callback, // swap_callback
0u, // fbo
fbo_info.fbo_id, // fbo
impeller::PixelFormat::kR8G8B8A8UNormInt, // color_format
impeller::ISize{size.width(), size.height()} // fbo_size
);
Expand Down Expand Up @@ -122,12 +126,12 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGLImpeller::AcquireFrame(
});

return std::make_unique<SurfaceFrame>(
nullptr, // surface
SurfaceFrame::FramebufferInfo{}, // framebuffer info
submit_callback, // submit callback
size, // frame size
std::move(context_switch), // context result
true // display list fallback
nullptr, // surface
delegate_->GLContextFramebufferInfo(), // framebuffer info
submit_callback, // submit callback
size, // frame size
std::move(context_switch), // context result
true // display list fallback
);
}

Expand Down
33 changes: 22 additions & 11 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ template("embedder_source_set") {
]

public_deps = [ ":embedder_headers" ]

if (embedder_enable_gl) {
sources += [
"embedder_external_texture_gl.cc",
"embedder_external_texture_gl.h",
"embedder_surface_gl.cc",
"embedder_surface_gl.h",
]
}

deps = [
":embedder_gpu_configuration",
"//flutter/assets",
Expand All @@ -121,13 +111,33 @@ template("embedder_source_set") {
"//third_party/skia",
]

if (embedder_enable_gl) {
sources += [
"embedder_external_texture_gl.cc",
"embedder_external_texture_gl.h",
"embedder_surface_gl.cc",
"embedder_surface_gl.h",
]

if (impeller_supports_rendering) {
sources += [
"embedder_surface_gl_impeller.cc",
"embedder_surface_gl_impeller.h",
]
deps += [ "//flutter/impeller/renderer/backend/gles" ]
}
}

if (impeller_supports_rendering) {
sources += [
"embedder_render_target_impeller.cc",
"embedder_render_target_impeller.h",
]

deps += [ "//flutter/impeller" ]
deps += [
"//flutter/impeller",
"//flutter/impeller/renderer",
]
}

if (embedder_enable_metal) {
Expand All @@ -143,6 +153,7 @@ template("embedder_source_set") {
"embedder_surface_metal_impeller.h",
"embedder_surface_metal_impeller.mm",
]
deps += [ "//flutter/impeller/renderer/backend/metal" ]
}

cflags_objc = flutter_cflags_objc
Expand Down
122 changes: 108 additions & 14 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ extern const intptr_t kPlatformStrongDillSize;
#include "rapidjson/rapidjson.h"
#include "rapidjson/writer.h"

// Note: the IMPELLER_SUPPORTS_RENDERING may be defined even when the
// embedder/BUILD.gn variable impeller_supports_rendering is disabled.
#ifdef SHELL_ENABLE_GL
#include "flutter/shell/platform/embedder/embedder_external_texture_gl.h"
#endif
#ifdef IMPELLER_SUPPORTS_RENDERING
#include "flutter/shell/platform/embedder/embedder_render_target_impeller.h" // nogncheck
#include "flutter/shell/platform/embedder/embedder_surface_gl_impeller.h" // nogncheck
#include "impeller/core/texture.h" // nogncheck
#include "impeller/renderer/backend/gles/context_gles.h" // nogncheck
#include "impeller/renderer/backend/gles/texture_gles.h" // nogncheck
#include "impeller/renderer/context.h" // nogncheck
#include "impeller/renderer/render_target.h" // nogncheck
Comment on lines +72 to +78
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these nognchecked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushing up a change to remove these to see what complains

#endif // IMPELLER_SUPPORTS_RENDERING
#endif // SHELL_ENABLE_GL

#ifdef SHELL_ENABLE_METAL
#include "flutter/shell/platform/embedder/embedder_surface_metal.h"
Expand Down Expand Up @@ -265,7 +276,8 @@ InferOpenGLPlatformViewCreationCallback(
const flutter::PlatformViewEmbedder::PlatformDispatchTable&
platform_dispatch_table,
std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
external_view_embedder) {
external_view_embedder,
bool enable_impeller) {
#ifdef SHELL_ENABLE_GL
if (config->type != kOpenGL) {
return nullptr;
Expand Down Expand Up @@ -441,15 +453,30 @@ InferOpenGLPlatformViewCreationCallback(

return fml::MakeCopyable(
[gl_dispatch_table, fbo_reset_after_present, platform_dispatch_table,
enable_impeller,
external_view_embedder =
std::move(external_view_embedder)](flutter::Shell& shell) mutable {
std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
std::move(external_view_embedder);
if (enable_impeller) {
return std::make_unique<flutter::PlatformViewEmbedder>(
shell, // delegate
shell.GetTaskRunners(), // task runners
std::make_unique<flutter::EmbedderSurfaceGLImpeller>(
gl_dispatch_table, fbo_reset_after_present,
view_embedder), // embedder_surface
platform_dispatch_table, // embedder platform dispatch table
view_embedder // external view embedder
);
}
return std::make_unique<flutter::PlatformViewEmbedder>(
shell, // delegate
shell.GetTaskRunners(), // task runners
gl_dispatch_table, // embedder GL dispatch table
fbo_reset_after_present, // fbo reset after present
shell, // delegate
shell.GetTaskRunners(), // task runners
std::make_unique<flutter::EmbedderSurfaceGL>(
gl_dispatch_table, fbo_reset_after_present,
view_embedder), // embedder_surface
platform_dispatch_table, // embedder platform dispatch table
std::move(external_view_embedder) // external view embedder
view_embedder // external view embedder
);
});
#else
Expand Down Expand Up @@ -686,7 +713,7 @@ InferPlatformViewCreationCallback(
case kOpenGL:
return InferOpenGLPlatformViewCreationCallback(
config, user_data, platform_dispatch_table,
std::move(external_view_embedder));
std::move(external_view_embedder), enable_impeller);
case kSoftware:
return InferSoftwarePlatformViewCreationCallback(
config, user_data, platform_dispatch_table,
Expand Down Expand Up @@ -924,6 +951,66 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
#endif
}

static std::unique_ptr<flutter::EmbedderRenderTarget>
MakeRenderTargetFromBackingStoreImpeller(
FlutterBackingStore backing_store,
const fml::closure& on_release,
const std::shared_ptr<impeller::AiksContext>& aiks_context,
const FlutterBackingStoreConfig& config,
const FlutterOpenGLFramebuffer* framebuffer) {
#if defined(SHELL_ENABLE_GL) && defined(IMPELLER_SUPPORTS_RENDERING)

const auto& gl_context =
impeller::ContextGLES::Cast(*aiks_context->GetContext());
const auto size = impeller::ISize(config.size.width, config.size.height);

impeller::TextureDescriptor color0_tex;
color0_tex.type = impeller::TextureType::kTexture2D;
color0_tex.format = impeller::PixelFormat::kR8G8B8A8UNormInt;
color0_tex.size = size;
color0_tex.usage = static_cast<impeller::TextureUsageMask>(
impeller::TextureUsage::kRenderTarget);
color0_tex.sample_count = impeller::SampleCount::kCount1;
color0_tex.storage_mode = impeller::StorageMode::kDevicePrivate;

impeller::ColorAttachment color0;
color0.texture = std::make_shared<impeller::TextureGLES>(
gl_context.GetReactor(), color0_tex,
impeller::TextureGLES::IsWrapped::kWrapped);
color0.clear_color = impeller::Color::DarkSlateGray();
color0.load_action = impeller::LoadAction::kClear;
color0.store_action = impeller::StoreAction::kStore;

impeller::TextureDescriptor stencil0_tex;
stencil0_tex.type = impeller::TextureType::kTexture2D;
stencil0_tex.format = impeller::PixelFormat::kR8G8B8A8UNormInt;
stencil0_tex.size = size;
stencil0_tex.usage = static_cast<impeller::TextureUsageMask>(
impeller::TextureUsage::kRenderTarget);
stencil0_tex.sample_count = impeller::SampleCount::kCount1;

impeller::StencilAttachment stencil0;
stencil0.clear_stencil = 0;
stencil0.texture = std::make_shared<impeller::TextureGLES>(
gl_context.GetReactor(), stencil0_tex,
impeller::TextureGLES::IsWrapped::kWrapped);
stencil0.load_action = impeller::LoadAction::kClear;
stencil0.store_action = impeller::StoreAction::kDontCare;

impeller::RenderTarget render_target_desc;

render_target_desc.SetColorAttachment(color0, framebuffer->target);
render_target_desc.SetStencilAttachment(stencil0);

return std::make_unique<flutter::EmbedderRenderTargetImpeller>(
backing_store, aiks_context,
std::make_unique<impeller::RenderTarget>(std::move(render_target_desc)),
on_release);
#else
return nullptr;
#endif
}

static std::unique_ptr<flutter::EmbedderRenderTarget>
MakeRenderTargetFromBackingStoreImpeller(
FlutterBackingStore backing_store,
Expand Down Expand Up @@ -1113,12 +1200,19 @@ CreateEmbedderRenderTarget(
break;
}
case kFlutterOpenGLTargetTypeFramebuffer: {
auto skia_surface = MakeSkSurfaceFromBackingStore(
context, config, &backing_store.open_gl.framebuffer);
render_target = MakeRenderTargetFromSkSurface(
backing_store, std::move(skia_surface),
collect_callback.Release());
break;
if (enable_impeller) {
render_target = MakeRenderTargetFromBackingStoreImpeller(
backing_store, collect_callback.Release(), aiks_context, config,
&backing_store.open_gl.framebuffer);
break;
} else {
auto skia_surface = MakeSkSurfaceFromBackingStore(
context, config, &backing_store.open_gl.framebuffer);
render_target = MakeRenderTargetFromSkSurface(
backing_store, std::move(skia_surface),
collect_callback.Release());
break;
}
}
}
break;
Expand Down
Loading