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 namespace flutter { 19 20 // An manager for inializing ANGLE correctly and using it to create and 21 // destroy surfaces 22 class AngleSurfaceManager { 23 public: 24 AngleSurfaceManager(); 25 ~AngleSurfaceManager(); 26 27 // Disallow copy/move. 28 AngleSurfaceManager(const AngleSurfaceManager&) = delete; 29 AngleSurfaceManager& operator=(const AngleSurfaceManager&) = delete; 30 31 // Creates and returns an EGLSurface wrapper and backing DirectX 11 SwapChain 32 // asociated with window, in the appropriate format for display in a 33 // HWND-backed window. 34 EGLSurface CreateSurface(HWND window); 35 36 // queries EGL for the dimensions of surface in physical 37 // pixels returning width and height as out params. 38 void GetSurfaceDimensions(const EGLSurface surface, 39 EGLint* width, 40 EGLint* height); 41 42 // Releases the pass-in EGLSurface wrapping and backing resources if not null. 43 void DestroySurface(const EGLSurface surface); 44 45 // Binds egl_context_ to the current rendering thread and to the draw and read 46 // surfaces returning a boolean result reflecting success. 47 bool MakeCurrent(const EGLSurface surface); 48 49 // Swaps the front and back buffers of the DX11 swapchain backing surface if 50 // not null. 51 EGLBoolean SwapBuffers(const EGLSurface surface); 52 53 private: 54 bool Initialize(); 55 void CleanUp(); 56 57 private: 58 // EGL representation of native display 59 EGLDisplay egl_display_; 60 61 // EGL representation of current rendering context 62 EGLContext egl_context_; 63 64 // current frame buffer configuration 65 EGLConfig egl_config_; 66 67 // State representing success or failure of display initialization used when 68 // creating surfaces. 69 bool initialize_succeeded_; 70 }; 71 72 } // namespace flutter 73 74 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_ 75