Flutter Engine
angle_surface_manager.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_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_
7 
8 // OpenGL ES and EGL includes
9 #include <EGL/egl.h>
10 #include <EGL/eglext.h>
11 #include <EGL/eglplatform.h>
12 #include <GLES2/gl2.h>
13 #include <GLES2/gl2ext.h>
14 
15 // Windows platform specific includes
16 #include <windows.h>
17 
18 #include "window_binding_handler.h"
19 
20 namespace flutter {
21 
22 // A manager for inializing ANGLE correctly and using it to create and
23 // destroy surfaces
25  public:
26  // Creates a new surface manager retaining reference to the passed-in target
27  // for the lifetime of the manager.
30 
31  // Disallow copy/move.
34 
35  // Creates an EGLSurface wrapper and backing DirectX 11 SwapChain
36  // asociated with window, in the appropriate format for display.
37  // Target represents the visual entity to bind to. Width and
38  // height represent dimensions surface is created at.
39  bool CreateSurface(WindowsRenderTarget* render_target,
40  EGLint width,
41  EGLint height);
42 
43  // Resizes backing surface from current size to newly requested size
44  // based on width and height for the specific case when width and height do
45  // not match current surface dimensions. Target represents the visual entity
46  // to bind to.
47  void ResizeSurface(WindowsRenderTarget* render_target,
48  EGLint width,
49  EGLint height);
50 
51  // queries EGL for the dimensions of surface in physical
52  // pixels returning width and height as out params.
53  void GetSurfaceDimensions(EGLint* width, EGLint* height);
54 
55  // Releases the pass-in EGLSurface wrapping and backing resources if not null.
56  void DestroySurface();
57 
58  // Binds egl_context_ to the current rendering thread and to the draw and read
59  // surfaces returning a boolean result reflecting success.
60  bool MakeCurrent();
61 
62  // Clears current egl_context_
63  bool ClearContext();
64 
65  // Binds egl_resource_context_ to the current rendering thread and to the draw
66  // and read surfaces returning a boolean result reflecting success.
67  bool MakeResourceCurrent();
68 
69  // Swaps the front and back buffers of the DX11 swapchain backing surface if
70  // not null.
71  EGLBoolean SwapBuffers();
72 
73  private:
74  bool Initialize();
75  void CleanUp();
76 
77  private:
78  // EGL representation of native display.
79  EGLDisplay egl_display_;
80 
81  // EGL representation of current rendering context.
82  EGLContext egl_context_;
83 
84  // EGL representation of current rendering context used for async texture
85  // uploads.
86  EGLContext egl_resource_context_;
87 
88  // current frame buffer configuration.
89  EGLConfig egl_config_;
90 
91  // State representing success or failure of display initialization used when
92  // creating surfaces.
93  bool initialize_succeeded_;
94 
95  // Current render_surface that engine will draw into.
96  EGLSurface render_surface_ = EGL_NO_SURFACE;
97 };
98 
99 } // namespace flutter
100 
101 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_
void GetSurfaceDimensions(EGLint *width, EGLint *height)
std::variant< HWND > WindowsRenderTarget
void ResizeSurface(WindowsRenderTarget *render_target, EGLint width, EGLint height)
int32_t height
int32_t width
bool CreateSurface(WindowsRenderTarget *render_target, EGLint width, EGLint height)
AngleSurfaceManager & operator=(const AngleSurfaceManager &)=delete