Flutter Engine
The 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
8#include "flutter/shell/platform/embedder/embedder_surface_metal_impeller.h"
9
10#include "flutter/fml/logging.h"
11#include "flutter/fml/synchronization/sync_switch.h"
12#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
13#include "flutter/shell/gpu/gpu_surface_metal_impeller.h"
14#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h"
15#include "impeller/entity/mtl/entity_shaders.h"
16#include "impeller/entity/mtl/framebuffer_blend_shaders.h"
17#include "impeller/entity/mtl/modern_shaders.h"
19
20#if IMPELLER_ENABLE_3D
21#include "impeller/scene/shaders/mtl/scene_shaders.h" // nogncheck
22#endif // IMPELLER_ENABLE_3D
23
25
26namespace flutter {
27
30 GPUMTLCommandQueueHandle command_queue,
31 MetalDispatchTable metal_dispatch_table,
32 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
34 metal_dispatch_table_(std::move(metal_dispatch_table)),
35 external_view_embedder_(std::move(external_view_embedder)) {
36 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
37 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_data,
38 impeller_entity_shaders_length),
39#if IMPELLER_ENABLE_3D
40 std::make_shared<fml::NonOwnedMapping>(impeller_scene_shaders_data,
41 impeller_scene_shaders_length),
42#endif // IMPELLER_ENABLE_3D
43 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_data,
44 impeller_modern_shaders_length),
45 std::make_shared<fml::NonOwnedMapping>(impeller_framebuffer_blend_shaders_data,
46 impeller_framebuffer_blend_shaders_length),
47 };
49 (id<MTLDevice>)device, // device
50 (id<MTLCommandQueue>)command_queue, // command_queue
51 shader_mappings, // shader_libraries_data
52 std::make_shared<fml::SyncSwitch>(false), // is_gpu_disabled_sync_switch
53 "Impeller Library" // library_label
54 );
55 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Metal).";
56
57 valid_ = !!context_;
58}
59
61
63 return valid_;
64}
65
68 if (!IsValid()) {
69 return nullptr;
70 }
71
72 const bool render_to_surface = !external_view_embedder_;
73 auto surface = std::make_unique<GPUSurfaceMetalImpeller>(this, 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
87 const SkISize& frame_info) const {
88 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
89 return nullptr;
90}
91
93 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
94 return false;
95}
96
98 return metal_dispatch_table_.get_texture(frame_info);
99}
100
102 return metal_dispatch_table_.present(texture);
103}
104
105} // namespace flutter
#define FLUTTER_ASSERT_NOT_ARC
const void * GrMTLHandle
Definition GrMtlTypes.h:20
GPUMTLTextureInfo GetMTLTexture(const SkISize &frame_size) const override
Returns the handle to the MTLTexture to render to. This is only called when the specified render targ...
GPUCAMetalLayerHandle GetCAMetalLayer(const SkISize &frame_size) const override
Returns the handle to the CAMetalLayer to render to. This is only called when the specified render ta...
bool PresentTexture(GPUMTLTextureInfo texture) const override
Presents the texture with texture_id to the "screen". texture_id corresponds to a texture that has be...
std::unique_ptr< Surface > CreateGPUSurface() override
EmbedderSurfaceMetalImpeller(GPUMTLDeviceHandle device, GPUMTLCommandQueueHandle command_queue, MetalDispatchTable dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
bool PresentDrawable(GrMTLHandle drawable) const override
Presents the drawable to the "screen". The drawable is obtained from the CAMetalLayer that given by G...
std::shared_ptr< impeller::Context > CreateImpellerContext() const override
Interface implemented by all platform surfaces that can present a metal backing store to the "screen"...
static std::shared_ptr< ContextMTL > Create(const std::vector< std::string > &shader_library_paths, std::shared_ptr< const fml::SyncSwitch > is_gpu_disabled_sync_switch)
#define IMPELLER_CA_METAL_LAYER_AVAILABLE
Definition context_mtl.h:30
VkDevice device
Definition main.cc:53
VkSurfaceKHR surface
Definition main.cc:49
#define FML_LOG(severity)
Definition logging.h:82
#define FML_CHECK(condition)
Definition logging.h:85
FlTexture * texture
Definition ref_ptr.h:256
std::function< GPUMTLTextureInfo(const SkISize &frame_size)> get_texture