Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_surface_metal.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 <utility>
6
7#include "flutter/shell/platform/embedder/embedder_surface_metal.h"
8
9#include "flutter/fml/logging.h"
10#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
11#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
13
15namespace flutter {
16
19 GPUMTLCommandQueueHandle command_queue,
20 MetalDispatchTable metal_dispatch_table,
21 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
23 metal_dispatch_table_(std::move(metal_dispatch_table)),
24 external_view_embedder_(std::move(external_view_embedder)) {
25 main_context_ =
26 [FlutterDarwinContextMetalSkia createGrContext:(id<MTLDevice>)device
27 commandQueue:(id<MTLCommandQueue>)command_queue];
28 resource_context_ =
29 [FlutterDarwinContextMetalSkia createGrContext:(id<MTLDevice>)device
30 commandQueue:(id<MTLCommandQueue>)command_queue];
31 valid_ = main_context_ && resource_context_;
32}
33
35
37 return valid_;
38}
39
40std::unique_ptr<Surface> EmbedderSurfaceMetal::CreateGPUSurface() API_AVAILABLE(ios(13.0)) {
41 if (@available(iOS 13.0, *)) {
42 } else {
43 return nullptr;
44 }
45 if (!IsValid()) {
46 return nullptr;
47 }
48
49 const bool render_to_surface = !external_view_embedder_;
50 auto surface = std::make_unique<GPUSurfaceMetalSkia>(this, main_context_, MsaaSampleCount::kNone,
51 render_to_surface);
52
53 if (!surface->IsValid()) {
54 return nullptr;
55 }
56
57 return surface;
58}
59
63
65 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
66 return nullptr;
67}
68
70 FML_CHECK(false) << "Only rendering to MTLTexture is supported.";
71 return false;
72}
73
75 return metal_dispatch_table_.get_texture(frame_info);
76}
77
79 return metal_dispatch_table_.present(texture);
80}
81
82} // namespace flutter
#define FLUTTER_ASSERT_NOT_ARC
const void * GrMTLHandle
Definition GrMtlTypes.h:20
std::unique_ptr< Surface > CreateGPUSurface() override
EmbedderSurfaceMetal(GPUMTLDeviceHandle device, GPUMTLCommandQueueHandle command_queue, MetalDispatchTable dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
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...
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...
sk_sp< GrDirectContext > CreateResourceContext() const override
bool PresentTexture(GPUMTLTextureInfo texture) const override
Presents the texture with texture_id to the "screen". texture_id corresponds to a texture that has be...
bool PresentDrawable(GrMTLHandle drawable) const override
Presents the drawable to the "screen". The drawable is obtained from the CAMetalLayer that given by G...
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
UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0))
FlTexture * texture
Definition ref_ptr.h:256
std::function< GPUMTLTextureInfo(const SkISize &frame_size)> get_texture
std::function< bool(GPUMTLTextureInfo texture)> present