summaryrefslogtreecommitdiffstats
path: root/ui/gl
diff options
context:
space:
mode:
authorccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-07 01:36:45 +0000
committerccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-07 01:36:45 +0000
commit8aa5f0d132fa32fd33a8ec04a68ffb00c6107ba7 (patch)
tree4ab063a166ea4aa8693b208f3046e42994f1a24c /ui/gl
parentb8cd205b2b0a95cb3521acd99a3fc162e92451ed (diff)
downloadchromium_src-8aa5f0d132fa32fd33a8ec04a68ffb00c6107ba7.zip
chromium_src-8aa5f0d132fa32fd33a8ec04a68ffb00c6107ba7.tar.gz
chromium_src-8aa5f0d132fa32fd33a8ec04a68ffb00c6107ba7.tar.bz2
Explicitly create the GLX window for onscreen surfaces.
Always use glXCreateContextAttribsARB to create GLX contexts. This will allow us to explicitly destroy hibernated GLX windows, which will hopefully plug some GPU memory leaks that were causing instability. BUG=145600 Review URL: https://chromiumcodereview.appspot.com/11467008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171679 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gl')
-rw-r--r--ui/gl/gl_context_glx.cc93
-rw-r--r--ui/gl/gl_surface_glx.cc24
-rw-r--r--ui/gl/gl_surface_glx.h1
3 files changed, 37 insertions, 81 deletions
diff --git a/ui/gl/gl_context_glx.cc b/ui/gl/gl_context_glx.cc
index c675263..db5f0ac 100644
--- a/ui/gl/gl_context_glx.cc
+++ b/ui/gl/gl_context_glx.cc
@@ -49,85 +49,25 @@ bool GLContextGLX::Initialize(
GLXContext share_handle = static_cast<GLXContext>(
share_group() ? share_group()->GetHandle() : NULL);
+ std::vector<int> attribs;
if (GLSurfaceGLX::IsCreateContextRobustnessSupported()) {
DVLOG(1) << "GLX_ARB_create_context_robustness supported.";
-
- std::vector<int> attribs;
attribs.push_back(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB);
attribs.push_back(GLX_LOSE_CONTEXT_ON_RESET_ARB);
- attribs.push_back(0);
- context_ = glXCreateContextAttribsARB(
- display_,
- static_cast<GLXFBConfig>(compatible_surface->GetConfig()),
- share_handle,
- True,
- &attribs.front());
- if (context_) {
- DVLOG(1) << " Successfully allocated "
- << (compatible_surface->IsOffscreen() ?
- "offscreen" : "onscreen")
- << " GL context with LOSE_CONTEXT_ON_RESET_ARB";
- } else {
- // TODO(kbr): it is not expected that things will work properly
- // in this case, since we will likely allocate our offscreen
- // contexts with this bit set and the onscreen contexts without,
- // and won't be able to put them in the same share group.
- // Consider what to do here; force loss of all contexts and
- // reallocation without ARB_robustness?
- LOG(ERROR) <<
- " FAILED to allocate GL context with LOSE_CONTEXT_ON_RESET_ARB";
- }
- }
-
- if (!context_) {
- // The means by which the context is created depends on whether
- // the drawable type works reliably with GLX 1.3. If it does not
- // then fall back to GLX 1.2.
- if (compatible_surface->IsOffscreen()) {
- context_ = glXCreateNewContext(
- display_,
- static_cast<GLXFBConfig>(compatible_surface->GetConfig()),
- GLX_RGBA_TYPE,
- share_handle,
- True);
- } else {
- // Get the visuals for the X drawable.
- XWindowAttributes attributes;
- if (!XGetWindowAttributes(
- display_,
- reinterpret_cast<GLXDrawable>(compatible_surface->GetHandle()),
- &attributes)) {
- LOG(ERROR) << "XGetWindowAttributes failed for window " <<
- reinterpret_cast<GLXDrawable>(
- compatible_surface->GetHandle()) << ".";
- return false;
- }
-
- XVisualInfo visual_info_template;
- visual_info_template.visualid = XVisualIDFromVisual(attributes.visual);
-
- int visual_info_count = 0;
- scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info_list(
- XGetVisualInfo(display_, VisualIDMask,
- &visual_info_template,
- &visual_info_count));
-
- DCHECK(visual_info_list.get());
- if (visual_info_count == 0) {
- LOG(ERROR) << "No visual info for visual ID.";
- return false;
- }
-
- // Attempt to create a context with each visual in turn until one works.
- context_ = glXCreateContext(
- display_,
- visual_info_list.get(),
- share_handle,
- True);
- }
}
-
- if (!context_) {
+ attribs.push_back(0);
+ context_ = glXCreateContextAttribsARB(
+ display_,
+ static_cast<GLXFBConfig>(compatible_surface->GetConfig()),
+ share_handle,
+ True,
+ &attribs.front());
+ if (context_) {
+ DVLOG(1) << " Successfully allocated "
+ << (compatible_surface->IsOffscreen() ?
+ "offscreen" : "onscreen")
+ << " GL context with LOSE_CONTEXT_ON_RESET_ARB";
+ } else {
LOG(ERROR) << "Couldn't create GL context.";
return false;
}
@@ -156,9 +96,10 @@ bool GLContextGLX::MakeCurrent(GLSurface* surface) {
return true;
TRACE_EVENT0("gpu", "GLContextGLX::MakeCurrent");
- if (!glXMakeCurrent(
+ if (!glXMakeContextCurrent(
display_,
reinterpret_cast<GLXDrawable>(surface->GetHandle()),
+ reinterpret_cast<GLXDrawable>(surface->GetHandle()),
static_cast<GLXContext>(context_))) {
LOG(ERROR) << "Couldn't make context current with X drawable.";
Destroy();
@@ -188,7 +129,7 @@ void GLContextGLX::ReleaseCurrent(GLSurface* surface) {
return;
SetCurrent(NULL, NULL);
- if (!glXMakeCurrent(display_, 0, 0))
+ if (!glXMakeContextCurrent(display_, 0, 0, 0))
LOG(ERROR) << "glXMakeCurrent failed in ReleaseCurrent";
}
diff --git a/ui/gl/gl_surface_glx.cc b/ui/gl/gl_surface_glx.cc
index b349e7c..a933e1f 100644
--- a/ui/gl/gl_surface_glx.cc
+++ b/ui/gl/gl_surface_glx.cc
@@ -451,10 +451,24 @@ bool NativeViewGLSurfaceGLX::Initialize() {
else if (g_glx_sgi_video_sync_supported)
vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_));
+ glx_window_ = glXCreateWindow(
+ g_display,
+ static_cast<GLXFBConfig>(GetConfig()),
+ window_,
+ NULL);
+ if (!glx_window_) {
+ LOG(ERROR) << "glXCreateWindow failed for window " << window_ << ".";
+ return false;
+ }
+
return true;
}
void NativeViewGLSurfaceGLX::Destroy() {
+ if (glx_window_) {
+ glXDestroyWindow(g_display, glx_window_);
+ glx_window_ = 0;
+ }
}
bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) {
@@ -472,7 +486,7 @@ bool NativeViewGLSurfaceGLX::IsOffscreen() {
}
bool NativeViewGLSurfaceGLX::SwapBuffers() {
- glXSwapBuffers(g_display, window_);
+ glXSwapBuffers(g_display, glx_window_);
// For latency_tests.cc:
UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete");
return true;
@@ -483,7 +497,7 @@ gfx::Size NativeViewGLSurfaceGLX::GetSize() {
}
void* NativeViewGLSurfaceGLX::GetHandle() {
- return reinterpret_cast<void*>(window_);
+ return reinterpret_cast<void*>(glx_window_);
}
std::string NativeViewGLSurfaceGLX::GetExtensions() {
@@ -512,10 +526,10 @@ void* NativeViewGLSurfaceGLX::GetConfig() {
XWindowAttributes attributes;
if (!XGetWindowAttributes(
g_display,
- reinterpret_cast<GLXDrawable>(GetHandle()),
+ window_,
&attributes)) {
LOG(ERROR) << "XGetWindowAttributes failed for window " <<
- reinterpret_cast<GLXDrawable>(GetHandle()) << ".";
+ window_ << ".";
return NULL;
}
@@ -559,7 +573,7 @@ void* NativeViewGLSurfaceGLX::GetConfig() {
bool NativeViewGLSurfaceGLX::PostSubBuffer(
int x, int y, int width, int height) {
DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer);
- glXCopySubBufferMESA(g_display, window_, x, y, width, height);
+ glXCopySubBufferMESA(g_display, glx_window_, x, y, width, height);
return true;
}
diff --git a/ui/gl/gl_surface_glx.h b/ui/gl/gl_surface_glx.h
index 76a8f81..7840834 100644
--- a/ui/gl/gl_surface_glx.h
+++ b/ui/gl/gl_surface_glx.h
@@ -76,6 +76,7 @@ class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX {
virtual ~NativeViewGLSurfaceGLX();
gfx::AcceleratedWidget window_;
+ XID glx_window_;
private:
void* config_;