Flutter Engine
The Flutter Engine
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
9#include "flutter/shell/platform/embedder/embedder_surface_metal_skia.h"
10
11#include "flutter/fml/logging.h"
12#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
13#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
15
17namespace flutter {
18
21 GPUMTLCommandQueueHandle command_queue,
22 MetalDispatchTable metal_dispatch_table,
23 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
25 metal_dispatch_table_(std::move(metal_dispatch_table)),
26 external_view_embedder_(std::move(external_view_embedder)) {
27 main_context_ =
28 [FlutterDarwinContextMetalSkia createGrContext:(id<MTLDevice>)device
29 commandQueue:(id<MTLCommandQueue>)command_queue];
30 resource_context_ =
31 [FlutterDarwinContextMetalSkia createGrContext:(id<MTLDevice>)device
32 commandQueue:(id<MTLCommandQueue>)command_queue];
33 valid_ = main_context_ && resource_context_;
34}
35
37
38bool EmbedderSurfaceMetalSkia::IsValid() const {
39 return valid_;
40}
41
42std::unique_ptr<Surface> EmbedderSurfaceMetalSkia::CreateGPUSurface() API_AVAILABLE(ios(13.0)) {
43 if (@available(iOS 13.0, *)) {
44 } else {
45 return nullptr;
46 }
47 if (!IsValid()) {
48 return nullptr;
49 }
50
51 const bool render_to_surface = !external_view_embedder_;
52 auto surface = std::make_unique<GPUSurfaceMetalSkia>(this, main_context_, render_to_surface);
53
54 if (!surface->IsValid()) {
55 return nullptr;
56 }
57
58 return surface;
59}
60
61sk_sp<GrDirectContext> EmbedderSurfaceMetalSkia::CreateResourceContext() const {
62 return resource_context_;
63}
64
65GPUCAMetalLayerHandle EmbedderSurfaceMetalSkia::GetCAMetalLayer(const SkISize& frame_info) const {
66 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
67 return nullptr;
68}
69
70bool EmbedderSurfaceMetalSkia::PresentDrawable(GrMTLHandle drawable) const {
71 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
72 return false;
73}
74
75GPUMTLTextureInfo EmbedderSurfaceMetalSkia::GetMTLTexture(const SkISize& frame_info) const {
76 return metal_dispatch_table_.get_texture(frame_info);
77}
78
79bool EmbedderSurfaceMetalSkia::PresentTexture(GPUMTLTextureInfo texture) const {
80 return metal_dispatch_table_.present(texture);
81}
82
83} // namespace flutter
84
85#endif // !SLIMPELLER
#define FLUTTER_ASSERT_NOT_ARC
Definition: FlutterMacros.h:45
const void * GrMTLHandle
Definition: GrMtlTypes.h:20
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:53
VkSurfaceKHR surface
Definition: main.cc:49
#define FML_CHECK(condition)
Definition: logging.h:85
FlTexture * texture
SK_API sk_sp< SkSurface > ios(9.0)
void * GPUMTLCommandQueueHandle
API_AVAILABLE(ios(14.0), macos(11.0)) static NSString *MTLCommandEncoderErrorStateToString(MTLCommandEncoderErrorState state)
Definition: ref_ptr.h:256
Definition: SkSize.h:16
std::function< GPUMTLTextureInfo(const SkISize &frame_size)> get_texture
std::function< bool(GPUMTLTextureInfo texture)> present