Flutter Engine
gpu_surface_metal.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_H_
6 #define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
7 
8 #include "flutter/flow/surface.h"
9 #include "flutter/fml/macros.h"
10 #include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
11 #include "third_party/skia/include/gpu/GrDirectContext.h"
12 #include "third_party/skia/include/gpu/mtl/GrMtlTypes.h"
13 
14 namespace flutter {
15 
16 class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetal : public Surface {
17  public:
19  sk_sp<GrDirectContext> context,
20  bool render_to_surface = true);
21 
22  // |Surface|
23  ~GPUSurfaceMetal();
24 
25  // |Surface|
26  bool IsValid() override;
27 
28  private:
30  const MTLRenderTargetType render_target_type_;
31  GrMTLHandle next_drawable_ = nullptr;
32  sk_sp<GrDirectContext> context_;
33  GrDirectContext* precompiled_sksl_context_ = nullptr;
34  // TODO(38466): Refactor GPU surface APIs take into account the fact that an
35  // external view embedder may want to render to the root surface. This is a
36  // hack to make avoid allocating resources for the root surface when an
37  // external view embedder is present.
38  bool render_to_surface_;
39 
40  // |Surface|
41  std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override;
42 
43  // |Surface|
44  SkMatrix GetRootTransformation() const override;
45 
46  // |Surface|
47  GrDirectContext* GetContext() override;
48 
49  // |Surface|
50  std::unique_ptr<GLContextResult> MakeRenderContextCurrent() override;
51 
52  // |Surface|
53  bool AllowsDrawingWhenGpuDisabled() const override;
54 
55  std::unique_ptr<SurfaceFrame> AcquireFrameFromCAMetalLayer(
56  const SkISize& frame_info);
57 
58  std::unique_ptr<SurfaceFrame> AcquireFrameFromMTLTexture(
59  const SkISize& frame_info);
60 
61  void ReleaseUnusedDrawableIfNecessary();
62 
63  void PrecompileKnownSkSLsIfNecessary();
64 
66 };
67 
68 } // namespace flutter
69 
70 #endif // FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
MockDelegate delegate_
Interface implemented by all platform surfaces that can present a metal backing store to the "screen"...
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
static bool IsValid(double value)
Abstract Base Class that represents where we will be rendering content.
Definition: surface.h:18
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27