Flutter Engine
 
Loading...
Searching...
No Matches
gpu_surface_metal_delegate.h
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#ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_
6#define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_
7
8#include <stdint.h>
9
11#include "flutter/fml/macros.h"
12#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h"
13
14namespace flutter {
15
16// expected to be id<MTLDevice>
17typedef void* GPUMTLDeviceHandle;
18
19// expected to be id<MTLCommandQueues>
21
22// expected to be CAMetalLayer*
24
25// expected to be id<MTLTexture>
26typedef const void* GPUMTLTextureHandle;
27
28typedef void (*GPUMTLDestructionCallback)(void* /* destruction_context */);
29
36
38
39//------------------------------------------------------------------------------
40/// @brief Interface implemented by all platform surfaces that can present
41/// a metal backing store to the "screen". The GPU surface
42/// abstraction (which abstracts the client rendering API) uses this
43/// delegation pattern to tell the platform surface (which abstracts
44/// how backing stores fulfilled by the selected client rendering
45/// API end up on the "screen" on a particular platform) when the
46/// rasterizer needs to allocate and present the software backing
47/// store.
48///
49/// @see |IOSurfaceMetal| and |EmbedderSurfaceMetal|.
50///
52 public:
53 //------------------------------------------------------------------------------
54 /// @brief Construct a new GPUSurfaceMetalDelegate object with the specified
55 /// render_target type.
56 ///
57 /// @see |MTLRenderTargetType|
58 ///
59 explicit GPUSurfaceMetalDelegate(MTLRenderTargetType render_target);
60
62
63 //------------------------------------------------------------------------------
64 /// @brief Returns the handle to the CAMetalLayer to render to. This is only
65 /// called when the specified render target type is `kCAMetalLayer`.
66 ///
68 const DlISize& frame_info) const = 0;
69
70 //------------------------------------------------------------------------------
71 /// @brief Presents the drawable to the "screen". The drawable is obtained
72 /// from the CAMetalLayer that given by `GetCAMetalLayer` call. This is only
73 /// called when the specified render target type in `kCAMetalLayer`.
74 ///
75 /// @see |GPUSurfaceMetalDelegate::GetCAMetalLayer|
76 ///
77 virtual bool PresentDrawable(GrMTLHandle drawable) const = 0;
78
79 virtual bool PreparePresent(GrMTLHandle drawable) const { return true; }
80
81 //------------------------------------------------------------------------------
82 /// @brief Returns the handle to the MTLTexture to render to. This is only
83 /// called when the specified render target type is `kMTLTexture`.
84 ///
85 virtual GPUMTLTextureInfo GetMTLTexture(const DlISize& frame_info) const = 0;
86
87 //------------------------------------------------------------------------------
88 /// @brief Presents the texture with `texture_id` to the "screen".
89 /// `texture_id` corresponds to a texture that has been obtained by an earlier
90 /// call to `GetMTLTexture`. This is only called when the specified render
91 /// target type is `kMTLTexture`.
92 ///
93 /// @see |GPUSurfaceMetalDelegate::GetMTLTexture|
94 ///
95 virtual bool PresentTexture(GPUMTLTextureInfo texture) const = 0;
96
97 //------------------------------------------------------------------------------
98 /// @brief Whether to allow drawing to the surface when the GPU is disabled
99 ///
100 virtual bool AllowsDrawingWhenGpuDisabled() const;
101
103
104 private:
105 const MTLRenderTargetType render_target_type_;
106};
107
108} // namespace flutter
109
110#endif // FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_
Interface implemented by all platform surfaces that can present a metal backing store to the "screen"...
virtual bool AllowsDrawingWhenGpuDisabled() const
Whether to allow drawing to the surface when the GPU is disabled.
virtual bool PresentDrawable(GrMTLHandle drawable) const =0
Presents the drawable to the "screen". The drawable is obtained from the CAMetalLayer that given by G...
virtual bool PresentTexture(GPUMTLTextureInfo texture) const =0
Presents the texture with texture_id to the "screen". texture_id corresponds to a texture that has be...
virtual GPUMTLTextureInfo GetMTLTexture(const DlISize &frame_info) const =0
Returns the handle to the MTLTexture to render to. This is only called when the specified render targ...
virtual GPUCAMetalLayerHandle GetCAMetalLayer(const DlISize &frame_info) const =0
Returns the handle to the CAMetalLayer to render to. This is only called when the specified render ta...
virtual bool PreparePresent(GrMTLHandle drawable) const
FlTexture * texture
void(* GPUMTLDestructionCallback)(void *)
const void * GPUMTLTextureHandle
GPUMTLDestructionCallback destruction_callback