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

Commit 3fee72d

Browse files
committed
It's alive!
1 parent 5ec242b commit 3fee72d

File tree

5 files changed

+35
-29
lines changed

5 files changed

+35
-29
lines changed

impeller/renderer/backend/metal/texture_mtl.mm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@
3939
TextureDescriptor desc,
4040
id<MTLTexture> texture,
4141
std::function<void()> deletion_proc) {
42-
return std::shared_ptr<TextureMTL>(new TextureMTL(desc, texture, true),
43-
[deletion_proc = std::move(deletion_proc)](
44-
TextureMTL* t) { deletion_proc(); });
42+
if (deletion_proc) {
43+
return std::shared_ptr<TextureMTL>(
44+
new TextureMTL(desc, texture, true),
45+
[deletion_proc = std::move(deletion_proc)](TextureMTL* t) {
46+
deletion_proc();
47+
});
48+
}
49+
return std::shared_ptr<TextureMTL>(new TextureMTL(desc, texture, true));
4550
}
4651

4752
TextureMTL::~TextureMTL() = default;

impeller/renderer/backend/metal/texture_wrapper_mtl.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
#include <Metal/Metal.h>
88

9+
#include "impeller/renderer/backend/metal/formats_mtl.h"
910
#include "impeller/renderer/backend/metal/texture_mtl.h"
1011

1112
namespace impeller {
1213

1314
std::shared_ptr<Texture> WrapTextureMTL(TextureDescriptor desc,
1415
const void* mtl_texture,
1516
std::function<void()> deletion_proc) {
16-
return TextureMTL::Wrapper(desc, (__bridge id<MTLTexture>)mtl_texture,
17-
std::move(deletion_proc));
17+
auto texture = (__bridge id<MTLTexture>)mtl_texture;
18+
desc.format = FromMTLPixelFormat(texture.pixelFormat);
19+
return TextureMTL::Wrapper(desc, texture, std::move(deletion_proc));
1820
}
1921

2022
} // namespace impeller

shell/platform/embedder/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import("//build/toolchain/clang.gni")
66
import("//flutter/build/zip_bundle.gni")
77
import("//flutter/common/config.gni")
8+
import("//flutter/impeller/tools/impeller.gni")
89
import("//flutter/shell/gpu/gpu.gni")
910
import("//flutter/shell/platform/embedder/embedder.gni")
1011
import("//flutter/testing/testing.gni")
@@ -150,6 +151,7 @@ template("embedder_source_set") {
150151

151152
public_configs += [
152153
":embedder_gpu_configuration_config",
154+
"//flutter/impeller:impeller_public_config",
153155
":embedder_header_config",
154156
"//flutter:config",
155157
]

shell/platform/embedder/embedder.cc

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -928,46 +928,43 @@ MakeImpellerSurfaceFromBackingStore(
928928
}
929929

930930
const auto size = impeller::ISize(config.size.width, config.size.height);
931-
const auto color_format = impeller::PixelFormat::kR8G8B8A8UNormInt;
932-
933-
impeller::TextureDescriptor msaa_tex_desc;
934-
msaa_tex_desc.storage_mode = impeller::StorageMode::kDeviceTransient;
935-
msaa_tex_desc.type = impeller::TextureType::kTexture2DMultisample;
936-
msaa_tex_desc.sample_count = impeller::SampleCount::kCount4;
937-
msaa_tex_desc.format = color_format;
938-
msaa_tex_desc.size = size;
939-
msaa_tex_desc.usage =
940-
static_cast<uint64_t>(impeller::TextureUsage::kRenderTarget);
941-
942-
auto msaa_tex =
943-
aiks_context->GetContext()->GetResourceAllocator()->CreateTexture(
944-
msaa_tex_desc);
945-
if (!msaa_tex) {
946-
FML_LOG(ERROR) << "Could not allocate MSAA color texture.";
947-
return std::nullopt;
948-
}
949-
msaa_tex->SetLabel("ImpellerBackingStoreColorMSAA");
950931

951932
impeller::TextureDescriptor resolve_tex_desc;
952933
resolve_tex_desc.size = size;
953-
resolve_tex_desc.format = color_format;
954-
resolve_tex_desc.mip_count = 0;
955934
resolve_tex_desc.sample_count = impeller::SampleCount::kCount1;
956935
resolve_tex_desc.storage_mode = impeller::StorageMode::kDevicePrivate;
957936
resolve_tex_desc.usage =
958937
static_cast<uint64_t>(impeller::TextureUsage::kRenderTarget) |
959938
static_cast<uint64_t>(impeller::TextureUsage::kShaderRead);
939+
960940
auto resolve_tex = impeller::WrapTextureMTL(
961941
resolve_tex_desc, metal->texture.texture,
962942
[callback = metal->texture.destruction_callback,
963943
user_data = metal->texture.user_data]() { callback(user_data); });
964-
965944
if (!resolve_tex) {
966945
FML_LOG(ERROR) << "Could not wrap embedder supplied Metal render texture.";
967946
return std::nullopt;
968947
}
969948
resolve_tex->SetLabel("ImpellerBackingStoreResolve");
970949

950+
impeller::TextureDescriptor msaa_tex_desc;
951+
msaa_tex_desc.storage_mode = impeller::StorageMode::kDeviceTransient;
952+
msaa_tex_desc.type = impeller::TextureType::kTexture2DMultisample;
953+
msaa_tex_desc.sample_count = impeller::SampleCount::kCount4;
954+
msaa_tex_desc.format = resolve_tex->GetTextureDescriptor().format;
955+
msaa_tex_desc.size = size;
956+
msaa_tex_desc.usage =
957+
static_cast<uint64_t>(impeller::TextureUsage::kRenderTarget);
958+
959+
auto msaa_tex =
960+
aiks_context->GetContext()->GetResourceAllocator()->CreateTexture(
961+
msaa_tex_desc);
962+
if (!msaa_tex) {
963+
FML_LOG(ERROR) << "Could not allocate MSAA color texture.";
964+
return std::nullopt;
965+
}
966+
msaa_tex->SetLabel("ImpellerBackingStoreColorMSAA");
967+
971968
impeller::ColorAttachment color0;
972969
color0.texture = msaa_tex;
973970
color0.clear_color = impeller::Color::DarkSlateGray();

shell/platform/embedder/embedder_external_view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target) {
9595

9696
auto dispatcher = impeller::DlDispatcher();
9797
dispatcher.drawDisplayList(dl_builder.Build(), 1);
98-
aiks_context->Render(dispatcher.EndRecordingAsPicture(), *impeller_target);
99-
return true;
98+
return aiks_context->Render(dispatcher.EndRecordingAsPicture(),
99+
*impeller_target);
100100
}
101101

102102
auto skia_surface = render_target.GetRenderSurface();

0 commit comments

Comments
 (0)