Commit 88dbf36b authored by Peng Huang's avatar Peng Huang Committed by Chromium LUCI CQ

Support EGL_ANGLE_external_context_and_surface in //ui/gl

This CL adds support for EGL_ANGLE_external_context_and_surface.
With this extension, it wraps a native EGL context to an ANGLE EGL
context, so we can use ANGLE on a native EGL context. And call ANGLE
eglMakeCurrent() with this ANGLE context, will not change the native
EGL current context.
And if this external ANGLE context is created with
EGL_EXTERNAL_CONTEXT_SAVE_STATE_ANGLE. ANGLE will save GL state of
the native GL when this ANGLE context is made current. And ANGLE will
restore the saved GL state of the native context, when this ANGLE
context is released with eglMakeCurrent(EGL_NO_SURFACE, EGL_NO_CONTEXT).

Bug: 1157501
Change-Id: If7bb23dda18f09866fe33d185ef0f21a78a6ba1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638194
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846194}
parent bba4dc0e
...@@ -95,6 +95,16 @@ struct GL_EXPORT GLContextAttribs { ...@@ -95,6 +95,16 @@ struct GL_EXPORT GLContextAttribs {
// (True by default to match previous behavior.) // (True by default to match previous behavior.)
bool lose_context_on_reset = true; bool lose_context_on_reset = true;
// If true, EGL_ANGLE_external_context_and_surface extension will be used to
// create ANGLE context from the current native EGL context.
bool angle_create_from_external_context = false;
// If true, an ANGLE external context will be created with
// EGL_EXTERNAL_CONTEXT_SAVE_STATE_ANGLE is true, so when ReleaseCurrent is
// called, ANGLE will restore the GL state of the native EGL context to the
// state when MakeCurrent was previously called.
bool angle_restore_external_context_state = false;
ContextPriority context_priority = ContextPriorityMedium; ContextPriority context_priority = ContextPriorityMedium;
}; };
......
...@@ -40,6 +40,13 @@ ...@@ -40,6 +40,13 @@
#define EGL_DISPLAY_SEMAPHORE_SHARE_GROUP_ANGLE 0x348D #define EGL_DISPLAY_SEMAPHORE_SHARE_GROUP_ANGLE 0x348D
#endif /* EGL_ANGLE_display_semaphore_share_group */ #endif /* EGL_ANGLE_display_semaphore_share_group */
#ifndef EGL_ANGLE_external_context_and_surface
#define EGL_ANGLE_external_context_and_surface 1
#define EGL_EXTERNAL_CONTEXT_ANGLE 0x348E
#define EGL_EXTERNAL_SURFACE_ANGLE 0x348F
#define EGL_EXTERNAL_CONTEXT_SAVE_STATE_ANGLE 0x3490
#endif /* EGL_ANGLE_external_context_and_surface */
#ifndef EGL_ANGLE_create_context_client_arrays #ifndef EGL_ANGLE_create_context_client_arrays
#define EGL_ANGLE_create_context_client_arrays 1 #define EGL_ANGLE_create_context_client_arrays 1
#define EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE 0x3452 #define EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE 0x3452
...@@ -247,6 +254,17 @@ bool GLContextEGL::Initialize(GLSurface* compatible_surface, ...@@ -247,6 +254,17 @@ bool GLContextEGL::Initialize(GLSurface* compatible_surface,
} }
} }
if (GLSurfaceEGL::IsANGLEExternalContextAndSurfaceSupported()) {
if (attribs.angle_create_from_external_context) {
context_attributes.push_back(EGL_EXTERNAL_CONTEXT_ANGLE);
context_attributes.push_back(EGL_TRUE);
}
if (attribs.angle_restore_external_context_state) {
context_attributes.push_back(EGL_EXTERNAL_CONTEXT_SAVE_STATE_ANGLE);
context_attributes.push_back(EGL_TRUE);
}
}
// Append final EGL_NONE to signal the context attributes are finished // Append final EGL_NONE to signal the context attributes are finished
context_attributes.push_back(EGL_NONE); context_attributes.push_back(EGL_NONE);
context_attributes.push_back(EGL_NONE); context_attributes.push_back(EGL_NONE);
......
...@@ -206,6 +206,7 @@ bool g_egl_android_native_fence_sync_supported = false; ...@@ -206,6 +206,7 @@ bool g_egl_android_native_fence_sync_supported = false;
bool g_egl_ext_pixel_format_float_supported = false; bool g_egl_ext_pixel_format_float_supported = false;
bool g_egl_angle_feature_control_supported = false; bool g_egl_angle_feature_control_supported = false;
bool g_egl_angle_power_preference_supported = false; bool g_egl_angle_power_preference_supported = false;
bool g_egl_angle_external_context_and_surface_supported = false;
EGLGpuSwitchingObserver* g_egl_gpu_switching_observer = nullptr; EGLGpuSwitchingObserver* g_egl_gpu_switching_observer = nullptr;
constexpr const char kSwapEventTraceCategories[] = "gpu"; constexpr const char kSwapEventTraceCategories[] = "gpu";
...@@ -1062,6 +1063,9 @@ bool GLSurfaceEGL::InitializeOneOffCommon() { ...@@ -1062,6 +1063,9 @@ bool GLSurfaceEGL::InitializeOneOffCommon() {
g_egl_angle_power_preference_supported = g_egl_angle_power_preference_supported =
HasEGLExtension("EGL_ANGLE_power_preference"); HasEGLExtension("EGL_ANGLE_power_preference");
g_egl_angle_external_context_and_surface_supported =
HasEGLExtension("EGL_ANGLE_external_context_and_surface");
if (g_egl_angle_power_preference_supported) { if (g_egl_angle_power_preference_supported) {
g_egl_gpu_switching_observer = new EGLGpuSwitchingObserver(); g_egl_gpu_switching_observer = new EGLGpuSwitchingObserver();
ui::GpuSwitchingManager::GetInstance()->AddObserver( ui::GpuSwitchingManager::GetInstance()->AddObserver(
...@@ -1214,7 +1218,11 @@ bool GLSurfaceEGL::IsANGLEPowerPreferenceSupported() { ...@@ -1214,7 +1218,11 @@ bool GLSurfaceEGL::IsANGLEPowerPreferenceSupported() {
return g_egl_angle_power_preference_supported; return g_egl_angle_power_preference_supported;
} }
GLSurfaceEGL::~GLSurfaceEGL() {} bool GLSurfaceEGL::IsANGLEExternalContextAndSurfaceSupported() {
return g_egl_angle_external_context_and_surface_supported;
}
GLSurfaceEGL::~GLSurfaceEGL() = default;
// InitializeDisplay is necessary because the static binding code // InitializeDisplay is necessary because the static binding code
// needs a full Display init before it can query the Display extensions. // needs a full Display init before it can query the Display extensions.
......
...@@ -127,6 +127,7 @@ class GL_EXPORT GLSurfaceEGL : public GLSurface { ...@@ -127,6 +127,7 @@ class GL_EXPORT GLSurfaceEGL : public GLSurface {
static bool IsPixelFormatFloatSupported(); static bool IsPixelFormatFloatSupported();
static bool IsANGLEFeatureControlSupported(); static bool IsANGLEFeatureControlSupported();
static bool IsANGLEPowerPreferenceSupported(); static bool IsANGLEPowerPreferenceSupported();
static bool IsANGLEExternalContextAndSurfaceSupported();
protected: protected:
~GLSurfaceEGL() override; ~GLSurfaceEGL() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment