|
|
|
|
|
|
#include "unity_surface_manager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
|
|
|
#include "src/shell/common/shell_io_manager.h"
|
|
|
|
|
|
|
using EGLResult = std::pair<bool, T>; |
|
|
|
|
|
|
|
UnitySurfaceManager::UnitySurfaceManager(IUnityInterfaces *unity_interfaces) |
|
|
|
: // egl_display_(EGL_NO_DISPLAY),
|
|
|
|
egl_context_(EGL_NO_CONTEXT), |
|
|
|
egl_resource_context_(EGL_NO_CONTEXT) |
|
|
|
: egl_context_(EGL_NO_CONTEXT), |
|
|
|
egl_resource_context_(EGL_NO_CONTEXT) |
|
|
|
{ |
|
|
|
initialize_succeeded_ = Initialize(unity_interfaces); |
|
|
|
} |
|
|
|
|
|
|
GLuint UnitySurfaceManager::CreateRenderSurface(void *native_texture_ptr) |
|
|
|
{ |
|
|
|
auto read = eglGetCurrentSurface(EGL_READ); |
|
|
|
auto draw = eglGetCurrentSurface(EGL_DRAW); |
|
|
|
// auto state = eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, egl_context_) == GL_TRUE;
|
|
|
|
|
|
|
|
GLint old_framebuffer_binding; |
|
|
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_framebuffer_binding); |
|
|
|
|
|
|
|
|
|
|
FML_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); |
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, old_framebuffer_binding); |
|
|
|
// eglMakeCurrent(egl_display_, draw, read, egl_unity_context_);
|
|
|
|
|
|
|
|
return fbo_; |
|
|
|
} |
|
|
|
|
|
|
return {context != EGL_NO_CONTEXT, context}; |
|
|
|
} |
|
|
|
|
|
|
|
void UnitySurfaceManager::GetUnityContext(){ |
|
|
|
void UnitySurfaceManager::GetUnityContext() |
|
|
|
{ |
|
|
|
egl_display_ = eglGetCurrentDisplay(); |
|
|
|
egl_unity_context_ = eglGetCurrentContext(); |
|
|
|
FML_CHECK(egl_display_ != EGL_NO_DISPLAY) |
|
|
|
|
|
|
bool UnitySurfaceManager::Initialize(IUnityInterfaces *unity_interfaces) |
|
|
|
{ |
|
|
|
// egl_display_ = eglGetCurrentDisplay();
|
|
|
|
// egl_resource_context_ = eglGetCurrentContext();
|
|
|
|
FML_CHECK(egl_display_ != EGL_NO_DISPLAY) |
|
|
|
<< "Renderer type is invalid"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::tie(success, egl_context_) = CreateContext(egl_display_, egl_config_, egl_unity_context_); |
|
|
|
|
|
|
|
std::tie(success, egl_resource_context_) = CreateContext(egl_display_, egl_config_, egl_context_); |
|
|
|
|
|
|
|
std::tie(success, egl_resource_context_) = CreateContext(egl_display_, egl_config_, egl_context_); |
|
|
|
|
|
|
|
return success; |
|
|
|
} |
|
|
|
|
|
|
if (egl_display_ != EGL_NO_DISPLAY && |
|
|
|
egl_resource_context_ != EGL_NO_CONTEXT) |
|
|
|
{ |
|
|
|
eglDestroyContext(egl_display_, egl_resource_context_); |
|
|
|
egl_resource_context_ = EGL_NO_CONTEXT; |
|
|
|
} |
|
|
|
if (egl_display_ != EGL_NO_DISPLAY && egl_context_ != EGL_NO_CONTEXT) |
|
|
|
{ |
|
|
|
eglDestroyContext(egl_display_, egl_context_); |
|
|
|
egl_context_ = EGL_NO_CONTEXT; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace uiwidgets
|