Flutter Engine
 
Loading...
Searching...
No Matches
embedder_surface_metal_skia.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#if !SLIMPELLER
6
7#include <utility>
8
10
11#include "flutter/fml/logging.h"
14#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
15
17
18namespace flutter {
19
22 GPUMTLCommandQueueHandle command_queue,
23 MetalDispatchTable metal_dispatch_table,
24 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
26 metal_dispatch_table_(std::move(metal_dispatch_table)),
27 external_view_embedder_(std::move(external_view_embedder)) {
28 main_context_ =
29 [FlutterDarwinContextMetalSkia createGrContext:(__bridge id<MTLDevice>)device
30 commandQueue:(__bridge id<MTLCommandQueue>)command_queue];
31 resource_context_ =
32 [FlutterDarwinContextMetalSkia createGrContext:(__bridge id<MTLDevice>)device
33 commandQueue:(__bridge id<MTLCommandQueue>)command_queue];
34 valid_ = main_context_ && resource_context_;
35}
36
38
39bool EmbedderSurfaceMetalSkia::IsValid() const {
40 return valid_;
41}
42
43std::unique_ptr<Surface> EmbedderSurfaceMetalSkia::CreateGPUSurface() API_AVAILABLE(ios(13.0)) {
44 if (!IsValid()) {
45 return nullptr;
46 }
47
48 const bool render_to_surface = !external_view_embedder_;
49 auto surface = std::make_unique<GPUSurfaceMetalSkia>(this, main_context_, render_to_surface);
50
51 if (!surface->IsValid()) {
52 return nullptr;
53 }
54
55 return surface;
56}
57
58sk_sp<GrDirectContext> EmbedderSurfaceMetalSkia::CreateResourceContext() const {
59 return resource_context_;
60}
61
62GPUCAMetalLayerHandle EmbedderSurfaceMetalSkia::GetCAMetalLayer(const DlISize& frame_info) const {
63 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
64 return nullptr;
65}
66
67bool EmbedderSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable) const {
68 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
69 return false;
70}
71
72GPUMTLTextureInfo EmbedderSurfaceMetalSkia::GetMTLTexture(const DlISize& frame_info) const {
73 return metal_dispatch_table_.get_texture(frame_info);
74}
75
76bool EmbedderSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture) const {
77 return metal_dispatch_table_.present(texture);
78}
79
80} // namespace flutter
81
82#endif // !SLIMPELLER
EmbedderSurfaceMetalSkia(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"...
VkDevice device
Definition main.cc:69
VkSurfaceKHR surface
Definition main.cc:65
#define FML_CHECK(condition)
Definition logging.h:104
FlTexture * texture
impeller::ISize32 DlISize
API_AVAILABLE(ios(14.0), macos(11.0)) static NSString *MTLCommandEncoderErrorStateToString(MTLCommandEncoderErrorState state)
Definition ref_ptr.h:261
std::function< bool(GPUMTLTextureInfo texture)> present
std::function< GPUMTLTextureInfo(const DlISize &frame_size)> get_texture