Flutter Engine
 
Loading...
Searching...
No Matches
embedder_surface_metal_impeller.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <memory>
6#include <utility>
7
9
10#include "flutter/fml/logging.h"
16#include "impeller/entity/mtl/entity_shaders.h"
17#include "impeller/entity/mtl/framebuffer_blend_shaders.h"
18#include "impeller/entity/mtl/modern_shaders.h"
22
24
25namespace flutter {
26
29 GPUMTLCommandQueueHandle command_queue,
30 MetalDispatchTable metal_dispatch_table,
31 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
33 metal_dispatch_table_(std::move(metal_dispatch_table)),
34 external_view_embedder_(std::move(external_view_embedder)) {
35 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
36 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
37 impeller_entity_shaders_length),
38 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_data,
39 impeller_modern_shaders_length),
40 std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
41 impeller_framebuffer_blend_shaders_length),
42 };
45 (__bridge id<MTLDevice>)device, // device
46 (__bridge id<MTLCommandQueue>)command_queue, // command_queue
47 shader_mappings, // shader_libraries_data
48 std::make_shared<fml::SyncSwitch>(false), // is_gpu_disabled_sync_switch
49 "Impeller Library" // library_label
50 );
51 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Metal).";
52
53 valid_ = !!context_;
54}
55
57
58bool EmbedderSurfaceMetalImpeller::IsValid() const {
59 return valid_;
60}
61
62std::unique_ptr<Surface> EmbedderSurfaceMetalImpeller::CreateGPUSurface()
64 if (!IsValid()) {
65 return nullptr;
66 }
67 if (!aiks_context_) {
68 aiks_context_ =
69 std::make_shared<impeller::AiksContext>(context_, impeller::TypographerContextSkia::Make());
70 }
71
72 const bool render_to_surface = !external_view_embedder_;
73 auto surface = std::make_unique<GPUSurfaceMetalImpeller>(this, aiks_context_, render_to_surface);
74
75 if (!surface->IsValid()) {
76 return nullptr;
77 }
78
79 return surface;
80}
81
82std::shared_ptr<impeller::Context> EmbedderSurfaceMetalImpeller::CreateImpellerContext() const {
83 return context_;
84}
85
86GPUCAMetalLayerHandle EmbedderSurfaceMetalImpeller::GetCAMetalLayer(
87 const DlISize& frame_info) const {
88 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
89 return nullptr;
90}
91
92bool EmbedderSurfaceMetalImpeller::PresentDrawable(GrMTLHandle drawable) const {
93 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
94 return false;
95}
96
97GPUMTLTextureInfo EmbedderSurfaceMetalImpeller::GetMTLTexture(const DlISize& frame_info) const {
98 return metal_dispatch_table_.get_texture(frame_info);
99}
100
101bool EmbedderSurfaceMetalImpeller::PresentTexture(GPUMTLTextureInfo texture) const {
102 return metal_dispatch_table_.present(texture);
103}
104
105} // namespace flutter
EmbedderSurfaceMetalImpeller(GPUMTLDeviceHandle device, GPUMTLCommandQueueHandle command_queue, MetalDispatchTable dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
Interface implemented by all platform surfaces that can present a metal backing store to the "screen"...
static std::shared_ptr< ContextMTL > Create(const Flags &flags, const std::vector< std::string > &shader_library_paths, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch)
static std::shared_ptr< TypographerContext > Make()
VkDevice device
Definition main.cc:69
VkSurfaceKHR surface
Definition main.cc:65
#define FML_LOG(severity)
Definition logging.h:101
#define FML_CHECK(condition)
Definition logging.h:104
FlTexture * texture
impeller::ISize32 DlISize
Definition ref_ptr.h:261
#define IMPELLER_CA_METAL_LAYER_AVAILABLE
Definition context_mtl.h:30
std::function< GPUMTLTextureInfo(const DlISize &frame_size)> get_texture