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_GL_DELEGATE_H_ |
6 | #define FLUTTER_SHELL_GPU_GPU_SURFACE_GL_DELEGATE_H_ |
7 | |
8 | #include "flutter/flow/embedded_views.h" |
9 | #include "flutter/flow/gl_context_switch.h" |
10 | #include "flutter/fml/macros.h" |
11 | #include "flutter/shell/gpu/gpu_surface_delegate.h" |
12 | #include "third_party/skia/include/core/SkMatrix.h" |
13 | #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
14 | |
15 | namespace flutter { |
16 | |
17 | class GPUSurfaceGLDelegate : public GPUSurfaceDelegate { |
18 | public: |
19 | ~GPUSurfaceGLDelegate() override; |
20 | |
21 | // |GPUSurfaceDelegate| |
22 | ExternalViewEmbedder* GetExternalViewEmbedder() override; |
23 | |
24 | // Called to make the main GL context current on the current thread. |
25 | virtual std::unique_ptr<GLContextResult> GLContextMakeCurrent() = 0; |
26 | |
27 | // Called to clear the current GL context on the thread. This may be called on |
28 | // either the GPU or IO threads. |
29 | virtual bool GLContextClearCurrent() = 0; |
30 | |
31 | // Called to present the main GL surface. This is only called for the main GL |
32 | // context and not any of the contexts dedicated for IO. |
33 | virtual bool GLContextPresent() = 0; |
34 | |
35 | // The ID of the main window bound framebuffer. Typically FBO0. |
36 | virtual intptr_t GLContextFBO() const = 0; |
37 | |
38 | // The rendering subsystem assumes that the ID of the main window bound |
39 | // framebuffer remains constant throughout. If this assumption in incorrect, |
40 | // embedders are required to return true from this method. In such cases, |
41 | // GLContextFBO() will be called again to acquire the new FBO ID for rendering |
42 | // subsequent frames. |
43 | virtual bool GLContextFBOResetAfterPresent() const; |
44 | |
45 | // Indicates whether or not the surface supports pixel readback as used in |
46 | // circumstances such as a BackdropFilter. |
47 | virtual bool SurfaceSupportsReadback() const; |
48 | |
49 | // A transformation applied to the onscreen surface before the canvas is |
50 | // flushed. |
51 | virtual SkMatrix GLContextSurfaceTransformation() const; |
52 | |
53 | sk_sp<const GrGLInterface> GetGLInterface() const; |
54 | |
55 | // TODO(chinmaygarde): The presence of this method is to work around the fact |
56 | // that not all platforms can accept a custom GL proc table. Migrate all |
57 | // platforms to move GL proc resolution to the embedder and remove this |
58 | // method. |
59 | static sk_sp<const GrGLInterface> GetDefaultPlatformGLInterface(); |
60 | |
61 | using GLProcResolver = |
62 | std::function<void* /* proc name */ (const char* /* proc address */)>; |
63 | // Provide a custom GL proc resolver. If no such resolver is present, Skia |
64 | // will attempt to do GL proc address resolution on its own. Embedders that |
65 | // have specific opinions on GL API selection or need to add their own |
66 | // instrumentation to specific GL calls can specify custom GL functions |
67 | // here. |
68 | virtual GLProcResolver GetGLProcResolver() const; |
69 | }; |
70 | |
71 | } // namespace flutter |
72 | |
73 | #endif // FLUTTER_SHELL_GPU_GPU_SURFACE_GL_DELEGATE_H_ |
74 | |