diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-01 01:40:48 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-01 01:40:48 +0000 |
commit | 1a2124706a9edab17845a52a34b8123249b1cdae (patch) | |
tree | 6a0c4fa44261e1db2b4b33a620c2ea956a675a1b | |
parent | 2309e91187adda1de77bddebc6e192f9d6c3ed43 (diff) | |
download | chromium_src-1a2124706a9edab17845a52a34b8123249b1cdae.zip chromium_src-1a2124706a9edab17845a52a34b8123249b1cdae.tar.gz chromium_src-1a2124706a9edab17845a52a34b8123249b1cdae.tar.bz2 |
[Android] Restore EGL Context after collecting GPU info
In Android, a short lived EGL context is created on the UI thread during
start up to collect GPU info. One side effect is that if there is an
existing EGL context current, then it is released. This is a problem for
Android WebView but may affect Chrome as well.
This patch saves and restores the existing current context if there is
one.
BUG=
Review URL: https://codereview.chromium.org/25298003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226104 0039d316-1c4b-4281-b951-d872f2087c98
-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); } |