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/flow/embedded_views.h"
12 #include "flutter/flow/gl_context_switch.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  GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, bool render_to_surface);
24 
25  // Creates a new GL surface reusing an existing GrDirectContext.
26  GPUSurfaceGL(sk_sp<GrDirectContext> gr_context,
27  GPUSurfaceGLDelegate* delegate,
28  bool render_to_surface);
29 
30  // |Surface|
31  ~GPUSurfaceGL() override;
32 
33  // |Surface|
34  bool IsValid() override;
35 
36  // |Surface|
37  std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override;
38 
39  // |Surface|
40  SkMatrix GetRootTransformation() const override;
41 
42  // |Surface|
43  GrDirectContext* GetContext() override;
44 
45  // |Surface|
47 
48  // |Surface|
49  std::unique_ptr<GLContextResult> MakeRenderContextCurrent() override;
50 
51  // |Surface|
52  bool ClearRenderContext() override;
53 
54  private:
55  GPUSurfaceGLDelegate* delegate_;
56  sk_sp<GrDirectContext> context_;
57  sk_sp<SkSurface> onscreen_surface_;
58  /// FBO backing the current `onscreen_surface_`.
59  uint32_t fbo_id_;
60  bool context_owner_;
61  // TODO(38466): Refactor GPU surface APIs take into account the fact that an
62  // external view embedder may want to render to the root surface. This is a
63  // hack to make avoid allocating resources for the root surface when an
64  // external view embedder is present.
65  const bool render_to_surface_;
66  bool valid_ = false;
68 
69  bool CreateOrUpdateSurfaces(const SkISize& size);
70 
71  sk_sp<SkSurface> AcquireRenderSurface(
72  const SkISize& untransformed_size,
73  const SkMatrix& root_surface_transformation);
74 
75  bool PresentSurface(SkCanvas* canvas);
76 
77  FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
78 };
79 
80 } // namespace flutter
81 
82 #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
flutter::ExternalViewEmbedder * GetExternalViewEmbedder() override
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