blob: 119f57d3e4f782c7782a13f24585bb2b9d895dda [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_
// OpenGL ES and EGL includes
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglplatform.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
// Windows platform specific includes
#include <windows.h>
#include <memory>
#include "window_binding_handler.h"
namespace flutter {
// A manager for inializing ANGLE correctly and using it to create and
// destroy surfaces
class AngleSurfaceManager {
public:
static std::unique_ptr<AngleSurfaceManager> Create();
~AngleSurfaceManager();
// Disallow copy/move.
AngleSurfaceManager(const AngleSurfaceManager&) = delete;
AngleSurfaceManager& operator=(const AngleSurfaceManager&) = delete;
// Creates an EGLSurface wrapper and backing DirectX 11 SwapChain
// associated with window, in the appropriate format for display.
// Target represents the visual entity to bind to. Width and
// height represent dimensions surface is created at.
bool CreateSurface(WindowsRenderTarget* render_target,
EGLint width,
EGLint height);
// Resizes backing surface from current size to newly requested size
// based on width and height for the specific case when width and height do
// not match current surface dimensions. Target represents the visual entity
// to bind to.
void ResizeSurface(WindowsRenderTarget* render_target,
EGLint width,
EGLint height);
// queries EGL for the dimensions of surface in physical
// pixels returning width and height as out params.
void GetSurfaceDimensions(EGLint* width, EGLint* height);
// Releases the pass-in EGLSurface wrapping and backing resources if not null.
void DestroySurface();
// Binds egl_context_ to the current rendering thread and to the draw and read
// surfaces returning a boolean result reflecting success.
bool MakeCurrent();
// Clears current egl_context_
bool ClearContext();
// Binds egl_resource_context_ to the current rendering thread and to the draw
// and read surfaces returning a boolean result reflecting success.
bool MakeResourceCurrent();
// Swaps the front and back buffers of the DX11 swapchain backing surface if
// not null.
EGLBoolean SwapBuffers();
private:
bool Initialize();
void CleanUp();
private:
// Creates a new surface manager retaining reference to the passed-in target
// for the lifetime of the manager.
AngleSurfaceManager();
// Attempts to initialize EGL using ANGLE.
bool InitializeEGL(
PFNEGLGETPLATFORMDISPLAYEXTPROC egl_get_platform_display_EXT,
const EGLint* config,
bool should_log);
// EGL representation of native display.
EGLDisplay egl_display_;
// EGL representation of current rendering context.
EGLContext egl_context_;
// EGL representation of current rendering context used for async texture
// uploads.
EGLContext egl_resource_context_;
// current frame buffer configuration.
EGLConfig egl_config_;
// State representing success or failure of display initialization used when
// creating surfaces.
bool initialize_succeeded_;
// Current render_surface that engine will draw into.
EGLSurface render_surface_ = EGL_NO_SURFACE;
// Requested dimensions for current surface
EGLint surface_width_ = 0;
EGLint surface_height_ = 0;
// Number of active instances of AngleSurfaceManager
static int instance_count_;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_ANGLE_SURFACE_MANAGER_H_