diff options
-rw-r--r-- | gpu/config/gpu_info_collector_android.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gpu/config/gpu_info_collector_android.cc b/gpu/config/gpu_info_collector_android.cc index a26606a..f90797b 100644 --- a/gpu/config/gpu_info_collector_android.cc +++ b/gpu/config/gpu_info_collector_android.cc @@ -11,6 +11,9 @@ #include "base/strings/string_piece.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" +#include "ui/gl/gl_bindings.h" +#include "ui/gl/gl_context.h" +#include "ui/gl/gl_surface.h" namespace { @@ -41,6 +44,46 @@ std::string GetDriverVersionFromString(const std::string& version_string) { return pieces[0] + "." + pieces[1]; } +class ScopedRestoreNonOwnedEGLContext { + public: + ScopedRestoreNonOwnedEGLContext(); + ~ScopedRestoreNonOwnedEGLContext(); + + private: + EGLContext context_; + EGLDisplay display_; + EGLSurface draw_surface_; + EGLSurface read_surface_; +}; + +ScopedRestoreNonOwnedEGLContext::ScopedRestoreNonOwnedEGLContext() + : context_(EGL_NO_CONTEXT), + display_(EGL_NO_DISPLAY), + draw_surface_(EGL_NO_SURFACE), + read_surface_(EGL_NO_SURFACE) { + // This should only used to restore a context that is not created or owned by + // Chromium native code, but created by Android system itself. + DCHECK(!gfx::GLContext::GetCurrent()); + + if (gfx::GLSurface::InitializeOneOff()) { + context_ = eglGetCurrentContext(); + display_ = eglGetCurrentDisplay(); + draw_surface_ = eglGetCurrentSurface(EGL_DRAW); + read_surface_ = eglGetCurrentSurface(EGL_READ); + } +} + +ScopedRestoreNonOwnedEGLContext::~ScopedRestoreNonOwnedEGLContext() { + if (context_ == EGL_NO_CONTEXT || display_ == EGL_NO_DISPLAY || + draw_surface_ == EGL_NO_SURFACE || read_surface_ == EGL_NO_SURFACE) { + return; + } + + if (!eglMakeCurrent(display_, draw_surface_, read_surface_, context_)) { + LOG(WARNING) << "Failed to restore EGL context"; + } +} + } namespace gpu { @@ -63,6 +106,8 @@ bool CollectBasicGraphicsInfo(GPUInfo* gpu_info) { gpu_info->machine_model = base::android::BuildInfo::GetInstance()->model(); // Create a short-lived context on the UI thread to collect the GL strings. + // Make sure we restore the existing context if there is one. + ScopedRestoreNonOwnedEGLContext restore_context; return CollectGraphicsInfoGL(gpu_info); } |