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 #include <memory>
18 
19 #include "window_binding_handler.h"
20 
21 namespace flutter {
22 
23 // A manager for inializing ANGLE correctly and using it to create and
24 // destroy surfaces
26  public:
27  static std::unique_ptr<AngleSurfaceManager> Create();
29 
30  // Disallow copy/move.
33 
34  // Creates an EGLSurface wrapper and backing DirectX 11 SwapChain
35  // associated with window, in the appropriate format for display.
36  // Target represents the visual entity to bind to. Width and
37  // height represent dimensions surface is created at.
38  bool CreateSurface(WindowsRenderTarget* render_target,
39  EGLint width,
40  EGLint height);
41 
42  // Resizes backing surface from current size to newly requested size
43  // based on width and height for the specific case when width and height do
44  // not match current surface dimensions. Target represents the visual entity
45  // to bind to.
46  void ResizeSurface(WindowsRenderTarget* render_target,
47  EGLint width,
48  EGLint height);
49 
50  // queries EGL for the dimensions of surface in physical
51  // pixels returning width and height as out params.
52  void GetSurfaceDimensions(EGLint* width, EGLint* height);
53 
54  // Releases the pass-in EGLSurface wrapping and backing resources if not null.
55  void DestroySurface();
56 
57  // Binds egl_context_ to the current rendering thread and to the draw and read
58  // surfaces returning a boolean result reflecting success.
59  bool MakeCurrent();
60 
61  // Clears current egl_context_
62  bool ClearContext();
63 
64  // Binds egl_resource_context_ to the current rendering thread and to the draw
65  // and read surfaces returning a boolean result reflecting success.
66  bool MakeResourceCurrent();
67 
68  // Swaps the front and back buffers of the DX11 swapchain backing surface if
69  // not null.
70  EGLBoolean SwapBuffers();
71 
72  private:
73  bool Initialize();
74  void CleanUp();
75 
76  private:
77  // Creates a new surface manager retaining reference to the passed-in target
78  // for the lifetime of the manager.
80 
81  // Attempts to initialize EGL using ANGLE.
82  bool InitializeEGL(
83  PFNEGLGETPLATFORMDISPLAYEXTPROC egl_get_platform_display_EXT,
84  const EGLint* config,
85  bool should_log);
86 
87  // EGL representation of native display.
88  EGLDisplay egl_display_;
89 
90  // EGL representation of current rendering context.
91  EGLContext egl_context_;
92 
93  // EGL representation of current rendering context used for async texture
94  // uploads.
95  EGLContext egl_resource_context_;
96 
97  // current frame buffer configuration.
98  EGLConfig egl_config_;
99 
100  // State representing success or failure of display initialization used when
101  // creating surfaces.
102  bool initialize_succeeded_;
103 
104  // Current render_surface that engine will draw into.
105  EGLSurface render_surface_ = EGL_NO_SURFACE;
106 
107  // Requested dimensions for current surface
108  EGLint surface_width_ = 0;
109  EGLint surface_height_ = 0;
110 
111  // Number of active instances of AngleSurfaceManager
112  static int instance_count_;
113 };
114 
115 } // namespace flutter
116 
117 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_
static std::unique_ptr< AngleSurfaceManager > Create()
void GetSurfaceDimensions(EGLint *width, EGLint *height)
std::variant< HWND > WindowsRenderTarget
void ResizeSurface(WindowsRenderTarget *render_target, EGLint width, EGLint height)
int32_t width
int32_t height
bool CreateSurface(WindowsRenderTarget *render_target, EGLint width, EGLint height)
AngleSurfaceManager & operator=(const AngleSurfaceManager &)=delete