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| |
46 | flutter::ExternalViewEmbedder* GetExternalViewEmbedder() override; |
47 | |
48 | // |Surface| |
49 | std::unique_ptr<GLContextResult> MakeRenderContextCurrent() override; |
50 | |
51 | private: |
52 | GPUSurfaceGLDelegate* delegate_; |
53 | sk_sp<GrDirectContext> context_; |
54 | sk_sp<SkSurface> onscreen_surface_; |
55 | bool context_owner_; |
56 | // TODO(38466): Refactor GPU surface APIs take into account the fact that an |
57 | // external view embedder may want to render to the root surface. This is a |
58 | // hack to make avoid allocating resources for the root surface when an |
59 | // external view embedder is present. |
60 | const bool render_to_surface_; |
61 | bool valid_ = false; |
62 | fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceGL> weak_factory_; |
63 | |
64 | bool CreateOrUpdateSurfaces(const SkISize& size); |
65 | |
66 | sk_sp<SkSurface> AcquireRenderSurface( |
67 | const SkISize& untransformed_size, |
68 | const SkMatrix& root_surface_transformation); |
69 | |
70 | bool PresentSurface(SkCanvas* canvas); |
71 | |
72 | FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL); |
73 | }; |
74 | |
75 | } // namespace flutter |
76 | |
77 | #endif // SHELL_GPU_GPU_SURFACE_GL_H_ |
78 |