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