[Windows] Address #36422 by adding a context for async resource uploading (flutter/engine#11828)

Add a context for async resource uploading.

Fixes flutter/flutter#36422
This commit is contained in:
James Clarke
2019-09-04 15:52:12 -07:00
committed by Greg Spencer
parent d9335c59c7
commit d1fa9b5f40
5 changed files with 50 additions and 4 deletions

View File

@@ -126,13 +126,37 @@ bool AngleSurfaceManager::Initialize() {
return false;
}
egl_resource_context_ = eglCreateContext(
egl_display_, egl_config_, egl_context_, display_context_attributes);
if (egl_resource_context_ == EGL_NO_CONTEXT) {
OutputDebugString(L"EGL: Failed to create EGL resource context");
return false;
}
return true;
}
void AngleSurfaceManager::CleanUp() {
EGLBoolean result = EGL_FALSE;
if (egl_display_ != EGL_NO_DISPLAY && egl_context_ != EGL_NO_CONTEXT) {
eglDestroyContext(egl_display_, egl_context_);
result = eglDestroyContext(egl_display_, egl_context_);
egl_context_ = EGL_NO_CONTEXT;
if (result == EGL_FALSE) {
OutputDebugString(L"EGL: Failed to destroy context");
}
}
if (egl_display_ != EGL_NO_DISPLAY &&
egl_resource_context_ != EGL_NO_CONTEXT) {
result = eglDestroyContext(egl_display_, egl_resource_context_);
egl_resource_context_ = EGL_NO_CONTEXT;
if (result == EGL_FALSE) {
OutputDebugString(L"EGL: Failed to destroy resource context");
}
}
if (egl_display_ != EGL_NO_DISPLAY) {
@@ -184,6 +208,11 @@ bool AngleSurfaceManager::MakeCurrent(const EGLSurface surface) {
EGL_TRUE);
}
bool AngleSurfaceManager::MakeResourceCurrent() {
return (eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
egl_resource_context_) == EGL_TRUE);
}
EGLBoolean AngleSurfaceManager::SwapBuffers(const EGLSurface surface) {
return (eglSwapBuffers(egl_display_, surface));
}

View File

@@ -46,6 +46,10 @@ class AngleSurfaceManager {
// surfaces returning a boolean result reflecting success.
bool MakeCurrent(const EGLSurface surface);
// 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(const EGLSurface surface);
@@ -55,13 +59,17 @@ class AngleSurfaceManager {
void CleanUp();
private:
// EGL representation of native display
// EGL representation of native display.
EGLDisplay egl_display_;
// EGL representation of current rendering context
// EGL representation of current rendering context.
EGLContext egl_context_;
// current frame buffer configuration
// 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

View File

@@ -69,6 +69,10 @@ static FLUTTER_API_SYMBOL(FlutterEngine)
const char* what) -> void* {
return eglGetProcAddress(what);
};
config.open_gl.make_resource_current = [](void* user_data) -> bool {
auto host = static_cast<flutter::Win32FlutterWindow*>(user_data);
return host->MakeResourceCurrent();
};
FlutterProjectArgs args = {};
args.struct_size = sizeof(FlutterProjectArgs);

View File

@@ -279,6 +279,10 @@ bool Win32FlutterWindow::MakeCurrent() {
return surface_manager->MakeCurrent(render_surface);
}
bool Win32FlutterWindow::MakeResourceCurrent() {
return surface_manager->MakeResourceCurrent();
}
bool Win32FlutterWindow::ClearContext() {
return surface_manager->MakeCurrent(nullptr);
}

View File

@@ -85,6 +85,7 @@ class Win32FlutterWindow : public Win32Window {
// Callbacks for clearing context, settings context and swapping buffers.
bool ClearContext();
bool MakeCurrent();
bool MakeResourceCurrent();
bool SwapBuffers();
// Sends a window metrics update to the Flutter engine using current window