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
Show all changes
34 commits
Select commit Hold shift + click to select a range
a356b2c
[Impeller] Support Impeller in the Metal embedder API
bdero May 29, 2023
3475eaf
Embedder platform view progress
bdero May 29, 2023
c9bcbe2
Render target wrapping
bdero May 30, 2023
d631207
Add texture-only path
bdero May 30, 2023
3a9d4a5
It's alive!
bdero May 31, 2023
fc9fd89
Derp
bdero May 31, 2023
2167ade
Deps
bdero May 31, 2023
84c2343
Address comments
bdero May 31, 2023
9499a12
Build...
bdero May 31, 2023
367a71e
Build shaders for fuchsia
bdero May 31, 2023
ba6188a
Add iOS version check again
bdero May 31, 2023
0cd0373
Add fuchsia to vulkan backend build check
bdero May 31, 2023
36fc4ae
Revert "Add fuchsia to vulkan backend build check"
bdero May 31, 2023
6fa7e42
Revert "Build shaders for fuchsia"
bdero May 31, 2023
67633cf
Forward declare instead
bdero May 31, 2023
8a53fc8
Metal macro
bdero May 31, 2023
bd56675
Metal
bdero May 31, 2023
6cab1eb
Fix flow impeller include
bdero May 31, 2023
cba3f6a
More build fixes
bdero May 31, 2023
cbdea4d
Build fixes
bdero May 31, 2023
679b888
More build fixes
bdero May 31, 2023
37597b7
Dyn dispatch for EmbedderRenderTarget
bdero Jun 1, 2023
76833bd
Fix includes
bdero Jun 1, 2023
e8b47f2
Build fixes
bdero Jun 1, 2023
fe76983
Make GN understand defines?
bdero Jun 1, 2023
f792fb8
Make GN happy 2
bdero Jun 1, 2023
05d19c7
Fuchsia
bdero Jun 1, 2023
e03bbc8
Fuchsia
bdero Jun 1, 2023
1e4be50
Fuchsia
bdero Jun 1, 2023
4b9b822
Fuchsia
bdero Jun 1, 2023
e7613ef
Fuchsia
bdero Jun 1, 2023
14870a2
Fuchsia
bdero Jun 1, 2023
52964f6
Fuchsia
bdero Jun 1, 2023
248415c
Lint
bdero Jun 1, 2023
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
16 changes: 16 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,8 @@ ORIGIN: ../../../flutter/impeller/renderer/backend/metal/surface_mtl.h + ../../.
ORIGIN: ../../../flutter/impeller/renderer/backend/metal/surface_mtl.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/metal/texture_mtl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/metal/texture_mtl.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/metal/texture_wrapper_mtl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/metal/texture_wrapper_mtl.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/metal/vertex_descriptor_mtl.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/metal/vertex_descriptor_mtl.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/allocator_vk.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -2794,13 +2796,19 @@ ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target.cc + ../
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target_cache.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target_cache.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target_impeller.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target_impeller.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target_skia.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_render_target_skia.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_struct_macros.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface.cc + ../../../flutter/LICENSE
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_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
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_metal_impeller.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_software.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_software.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/embedder/embedder_surface_vulkan.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4139,6 +4147,8 @@ FILE: ../../../flutter/impeller/renderer/backend/metal/surface_mtl.h
FILE: ../../../flutter/impeller/renderer/backend/metal/surface_mtl.mm
FILE: ../../../flutter/impeller/renderer/backend/metal/texture_mtl.h
FILE: ../../../flutter/impeller/renderer/backend/metal/texture_mtl.mm
FILE: ../../../flutter/impeller/renderer/backend/metal/texture_wrapper_mtl.h
FILE: ../../../flutter/impeller/renderer/backend/metal/texture_wrapper_mtl.mm
FILE: ../../../flutter/impeller/renderer/backend/metal/vertex_descriptor_mtl.h
FILE: ../../../flutter/impeller/renderer/backend/metal/vertex_descriptor_mtl.mm
FILE: ../../../flutter/impeller/renderer/backend/vulkan/allocator_vk.cc
Expand Down Expand Up @@ -5469,13 +5479,19 @@ FILE: ../../../flutter/shell/platform/embedder/embedder_render_target.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_render_target.h
FILE: ../../../flutter/shell/platform/embedder/embedder_render_target_cache.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_render_target_cache.h
FILE: ../../../flutter/shell/platform/embedder/embedder_render_target_impeller.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_render_target_impeller.h
FILE: ../../../flutter/shell/platform/embedder/embedder_render_target_skia.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_render_target_skia.h
FILE: ../../../flutter/shell/platform/embedder/embedder_struct_macros.h
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_metal.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_metal.mm
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_metal_impeller.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_metal_impeller.mm
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_software.cc
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_software.h
FILE: ../../../flutter/shell/platform/embedder/embedder_surface_vulkan.cc
Expand Down
5 changes: 5 additions & 0 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import("//build/fuchsia/sdk.gni")
import("//flutter/common/config.gni")
import("//flutter/impeller/tools/impeller.gni")
import("//flutter/shell/config.gni")
import("//flutter/testing/testing.gni")

Expand Down Expand Up @@ -96,6 +97,10 @@ source_set("flow") {
"//third_party/skia",
]

if (impeller_supports_rendering) {
deps += [ "//flutter/impeller" ]
}

public_deps = [ "//flutter/display_list" ]
}

Expand Down
6 changes: 4 additions & 2 deletions flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ bool DisplayListEmbedderViewSlice::recording_ended() {
return builder_ == nullptr;
}

void ExternalViewEmbedder::SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
void ExternalViewEmbedder::SubmitFrame(
GrDirectContext* context,
Copy link
Member

Choose a reason for hiding this comment

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

Ooh, that's a bit unfortunate. But we can clean this up later.

const std::shared_ptr<impeller::AiksContext>& aiks_context,
std::unique_ptr<SurfaceFrame> frame) {
frame->Submit();
};

Expand Down
17 changes: 15 additions & 2 deletions flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef FLUTTER_FLOW_EMBEDDED_VIEWS_H_
#define FLUTTER_FLOW_EMBEDDED_VIEWS_H_

#include <memory>
#include <vector>

#include "flutter/display_list/dl_builder.h"
Expand All @@ -22,6 +23,16 @@
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/core/SkSurface.h"

#if IMPELLER_SUPPORTS_RENDERING
#include "flutter/impeller/aiks/aiks_context.h" // nogncheck
#include "flutter/impeller/renderer/context.h" // nogncheck
#else // IMPELLER_SUPPORTS_RENDERING
namespace impeller {
class Context;
class AiksContext;
} // namespace impeller
#endif // !IMPELLER_SUPPORTS_RENDERING

class GrDirectContext;

namespace flutter {
Expand Down Expand Up @@ -414,8 +425,10 @@ class ExternalViewEmbedder {
// This method can mutate the root Skia canvas before submitting the frame.
//
// It can also allocate frames for overlay surfaces to compose hybrid views.
virtual void SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame);
virtual void SubmitFrame(
GrDirectContext* context,
const std::shared_ptr<impeller::AiksContext>& aiks_context,
std::unique_ptr<SurfaceFrame> frame);

// This method provides the embedder a way to do additional tasks after
// |SubmitFrame|. For example, merge task runners if `should_resubmit_frame`
Expand Down
2 changes: 1 addition & 1 deletion impeller/playground/backend/metal/playground_impl_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

auto drawable =
SurfaceMTL::GetMetalDrawableAndValidate(context, data_->metal_layer);
return SurfaceMTL::WrapCurrentMetalLayerDrawable(context, drawable);
return SurfaceMTL::MakeFromMetalLayerDrawable(context, drawable);
}

} // namespace impeller
2 changes: 2 additions & 0 deletions impeller/renderer/backend/metal/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ impeller_component("metal") {
"surface_mtl.mm",
"texture_mtl.h",
"texture_mtl.mm",
"texture_wrapper_mtl.h",
"texture_wrapper_mtl.mm",
"vertex_descriptor_mtl.h",
"vertex_descriptor_mtl.mm",
]
Expand Down
15 changes: 15 additions & 0 deletions impeller/renderer/backend/metal/context_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
#include "impeller/renderer/capabilities.h"
#include "impeller/renderer/context.h"

#if TARGET_OS_SIMULATOR
#define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(13.0))
#else // TARGET_OS_SIMULATOR
#define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(8.0))
#endif // TARGET_OS_SIMULATOR

namespace impeller {

class ContextMTL final : public Context,
Expand All @@ -38,6 +44,14 @@ class ContextMTL final : public Context,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& label);

static std::shared_ptr<ContextMTL> Create(
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& label);

// |Context|
~ContextMTL() override;

Expand Down Expand Up @@ -90,6 +104,7 @@ class ContextMTL final : public Context,

ContextMTL(
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
NSArray<id<MTLLibrary>>* shader_libraries,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch);
Expand Down
63 changes: 48 additions & 15 deletions impeller/renderer/backend/metal/context_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

#include <Foundation/Foundation.h>

#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/file.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/paths.h"
#include "flutter/fml/synchronization/sync_switch.h"
#include "impeller/core/sampler_descriptor.h"
#include "impeller/renderer/backend/metal/sampler_library_mtl.h"
#include "impeller/renderer/capabilities.h"
Expand Down Expand Up @@ -67,10 +69,12 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {

ContextMTL::ContextMTL(
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
NSArray<id<MTLLibrary>>* shader_libraries,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch)
: device_(device),
command_queue_(command_queue),
worker_task_runner_(std::move(worker_task_runner)),
is_gpu_disabled_sync_switch_(std::move(is_gpu_disabled_sync_switch)) {
// Validate device.
Expand All @@ -96,16 +100,6 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
shader_library_ = std::move(library);
}

// Setup command queue.
{
command_queue_ = device_.newCommandQueue;
if (!command_queue_) {
VALIDATION_LOG << "Could not setup the command queue.";
return;
}
command_queue_.label = @"Impeller Command Queue";
}

// Setup the pipeline library.
{
pipeline_library_ =
Expand Down Expand Up @@ -204,13 +198,28 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
return ::MTLCreateSystemDefaultDevice();
}

static id<MTLCommandQueue> CreateMetalCommandQueue(id<MTLDevice> device) {
auto command_queue = device.newCommandQueue;
if (!command_queue) {
VALIDATION_LOG << "Could not setup the command queue.";
return nullptr;
}
command_queue.label = @"Impeller Command Queue";
return command_queue;
}

std::shared_ptr<ContextMTL> ContextMTL::Create(
const std::vector<std::string>& shader_library_paths,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch) {
auto device = CreateMetalDevice();
auto command_queue = CreateMetalCommandQueue(device);
if (!command_queue) {
return nullptr;
}
auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
device, MTLShaderLibraryFromFilePaths(device, shader_library_paths),
device, command_queue,
MTLShaderLibraryFromFilePaths(device, shader_library_paths),
std::move(worker_task_runner), std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
Expand All @@ -223,12 +232,36 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& label) {
const std::string& library_label) {
auto device = CreateMetalDevice();
auto command_queue = CreateMetalCommandQueue(device);
if (!command_queue) {
return nullptr;
}
auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
device,
MTLShaderLibraryFromFileData(device, shader_libraries_data, label),
worker_task_runner, std::move(is_gpu_disabled_sync_switch)));
device, command_queue,
MTLShaderLibraryFromFileData(device, shader_libraries_data,
library_label),
std::move(worker_task_runner), std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
return nullptr;
}
return context;
}

std::shared_ptr<ContextMTL> ContextMTL::Create(
id<MTLDevice> device,
id<MTLCommandQueue> command_queue,
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_data,
std::shared_ptr<fml::ConcurrentTaskRunner> worker_task_runner,
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch,
const std::string& library_label) {
auto context = std::shared_ptr<ContextMTL>(new ContextMTL(
device, command_queue,
MTLShaderLibraryFromFileData(device, shader_libraries_data,
library_label),
std::move(worker_task_runner), std::move(is_gpu_disabled_sync_switch)));
if (!context->IsValid()) {
FML_LOG(ERROR) << "Could not create Metal context.";
return nullptr;
Expand Down
12 changes: 11 additions & 1 deletion impeller/renderer/backend/metal/surface_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <QuartzCore/CAMetalLayer.h>
#include <memory>

#include "flutter/fml/macros.h"
#include "impeller/geometry/rect.h"
Expand Down Expand Up @@ -37,10 +38,15 @@ class SurfaceMTL final : public Surface {
const std::shared_ptr<Context>& context,
CAMetalLayer* layer);

static std::unique_ptr<SurfaceMTL> WrapCurrentMetalLayerDrawable(
static std::unique_ptr<SurfaceMTL> MakeFromMetalLayerDrawable(
const std::shared_ptr<Context>& context,
id<CAMetalDrawable> drawable,
std::optional<IRect> clip_rect = std::nullopt);

static std::unique_ptr<SurfaceMTL> MakeFromTexture(
const std::shared_ptr<Context>& context,
id<MTLTexture> texture,
std::optional<IRect> clip_rect);
#pragma GCC diagnostic pop

// |Surface|
Expand All @@ -58,6 +64,8 @@ class SurfaceMTL final : public Surface {
std::weak_ptr<Context> context_;
std::shared_ptr<Texture> resolve_texture_;
id<CAMetalDrawable> drawable_ = nil;
std::shared_ptr<Texture> source_texture_;
std::shared_ptr<Texture> destination_texture_;
bool requires_blit_ = false;
std::optional<IRect> clip_rect_;

Expand All @@ -67,6 +75,8 @@ class SurfaceMTL final : public Surface {
const RenderTarget& target,
std::shared_ptr<Texture> resolve_texture,
id<CAMetalDrawable> drawable,
std::shared_ptr<Texture> source_texture,
std::shared_ptr<Texture> destination_texture,
bool requires_blit,
std::optional<IRect> clip_rect);

Expand Down
Loading