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 1 commit
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
Next Next commit
[Impeller] support Impeller via GL/Angle on Windows.
  • Loading branch information
Jonah Williams committed Jul 3, 2023
commit a21ab7649fafb50965050590ec08395942d4b46b
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
14 changes: 7 additions & 7 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 Down Expand Up @@ -122,12 +122,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
27 changes: 17 additions & 10 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,6 +111,23 @@ 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",
]
}
}

if (impeller_supports_rendering) {
sources += [
"embedder_render_target_impeller.cc",
Expand Down
120 changes: 106 additions & 14 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ extern const intptr_t kPlatformStrongDillSize;

#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 @@ -263,7 +272,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 @@ -439,15 +449,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 @@ -684,7 +709,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 @@ -922,6 +947,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 @@ -1111,12 +1196,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