Flutter Engine
gpu_surface_gl.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 SHELL_GPU_GPU_SURFACE_GL_H_
6 #define SHELL_GPU_GPU_SURFACE_GL_H_
7 
8 #include <functional>
9 #include <memory>
10 
11 #include "flutter/common/graphics/gl_context_switch.h"
12 #include "flutter/flow/embedded_views.h"
13 #include "flutter/flow/surface.h"
14 #include "flutter/fml/macros.h"
15 #include "flutter/fml/memory/weak_ptr.h"
16 #include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
17 #include "third_party/skia/include/gpu/GrDirectContext.h"
18 
19 namespace flutter {
20 
21 class GPUSurfaceGL : public Surface {
22  public:
23  static sk_sp<GrDirectContext> MakeGLContext(GPUSurfaceGLDelegate* delegate);
24 
25  GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, bool render_to_surface);
26 
27  // Creates a new GL surface reusing an existing GrDirectContext.
28  GPUSurfaceGL(sk_sp<GrDirectContext> gr_context,
29  GPUSurfaceGLDelegate* delegate,
30  bool render_to_surface);
31 
32  // |Surface|
33  ~GPUSurfaceGL() override;
34 
35  // |Surface|
36  bool IsValid() override;
37 
38  // |Surface|
39  std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override;
40 
41  // |Surface|
42  SkMatrix GetRootTransformation() const override;
43 
44  // |Surface|
45  GrDirectContext* GetContext() override;
46 
47  // |Surface|
48  std::unique_ptr<GLContextResult> MakeRenderContextCurrent() override;
49 
50  // |Surface|
51  bool ClearRenderContext() override;
52 
53  // |Surface|
54  bool AllowsDrawingWhenGpuDisabled() const override;
55 
56  private:
57  GPUSurfaceGLDelegate* delegate_;
58  sk_sp<GrDirectContext> context_;
59  sk_sp<SkSurface> onscreen_surface_;
60  /// FBO backing the current `onscreen_surface_`.
61  uint32_t fbo_id_ = 0;
62  bool context_owner_ = false;
63  // TODO(38466): Refactor GPU surface APIs take into account the fact that an
64  // external view embedder may want to render to the root surface. This is a
65  // hack to make avoid allocating resources for the root surface when an
66  // external view embedder is present.
67  const bool render_to_surface_ = true;
68  bool valid_ = false;
70 
71  bool CreateOrUpdateSurfaces(const SkISize& size);
72 
73  sk_sp<SkSurface> AcquireRenderSurface(
74  const SkISize& untransformed_size,
75  const SkMatrix& root_surface_transformation);
76 
77  bool PresentSurface(SkCanvas* canvas);
78 
79  FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
80 };
81 
82 } // namespace flutter
83 
84 #endif // SHELL_GPU_GPU_SURFACE_GL_H_
GrDirectContext * GetContext() override
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
SkMatrix GetRootTransformation() const override
Abstract Base Class that represents where we will be rendering content.
Definition: surface.h:18
bool AllowsDrawingWhenGpuDisabled() const override
static sk_sp< GrDirectContext > MakeGLContext(GPUSurfaceGLDelegate *delegate)
bool ClearRenderContext() override
GPUSurfaceGL(GPUSurfaceGLDelegate *delegate, bool render_to_surface)
std::unique_ptr< GLContextResult > MakeRenderContextCurrent() override
std::unique_ptr< SurfaceFrame > AcquireFrame(const SkISize &size) override
bool IsValid() override