OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 extern "C" { | 5 extern "C" { |
6 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
7 } | 7 } |
8 | 8 |
9 #include "ui/gl/gl_context_glx.h" | 9 #include "ui/gl/gl_context_glx.h" |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 static_cast<GLXContext>(context_)); | 91 static_cast<GLXContext>(context_)); |
92 context_ = NULL; | 92 context_ = NULL; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 bool GLContextGLX::MakeCurrent(GLSurface* surface) { | 96 bool GLContextGLX::MakeCurrent(GLSurface* surface) { |
97 DCHECK(context_); | 97 DCHECK(context_); |
98 if (IsCurrent(surface)) | 98 if (IsCurrent(surface)) |
99 return true; | 99 return true; |
100 | 100 |
| 101 ScopedReleaseCurrent release_current; |
101 TRACE_EVENT0("gpu", "GLContextGLX::MakeCurrent"); | 102 TRACE_EVENT0("gpu", "GLContextGLX::MakeCurrent"); |
102 if (!glXMakeContextCurrent( | 103 if (!glXMakeContextCurrent( |
103 display_, | 104 display_, |
104 reinterpret_cast<GLXDrawable>(surface->GetHandle()), | 105 reinterpret_cast<GLXDrawable>(surface->GetHandle()), |
105 reinterpret_cast<GLXDrawable>(surface->GetHandle()), | 106 reinterpret_cast<GLXDrawable>(surface->GetHandle()), |
106 static_cast<GLXContext>(context_))) { | 107 static_cast<GLXContext>(context_))) { |
107 LOG(ERROR) << "Couldn't make context current with X drawable."; | 108 LOG(ERROR) << "Couldn't make context current with X drawable."; |
108 Destroy(); | 109 Destroy(); |
109 return false; | 110 return false; |
110 } | 111 } |
111 | 112 |
112 // Set this as soon as the context is current, since we might call into GL. | 113 // Set this as soon as the context is current, since we might call into GL. |
113 SetRealGLApi(); | 114 SetRealGLApi(); |
114 | 115 |
115 SetCurrent(surface); | 116 SetCurrent(surface); |
116 if (!InitializeDynamicBindings()) { | 117 if (!InitializeDynamicBindings()) { |
117 ReleaseCurrent(surface); | |
118 Destroy(); | 118 Destroy(); |
119 return false; | 119 return false; |
120 } | 120 } |
121 | 121 |
122 if (!surface->OnMakeCurrent(this)) { | 122 if (!surface->OnMakeCurrent(this)) { |
123 LOG(ERROR) << "Could not make current."; | 123 LOG(ERROR) << "Could not make current."; |
124 ReleaseCurrent(surface); | |
125 Destroy(); | 124 Destroy(); |
126 return false; | 125 return false; |
127 } | 126 } |
128 | 127 |
| 128 release_current.Cancel(); |
129 return true; | 129 return true; |
130 } | 130 } |
131 | 131 |
132 void GLContextGLX::ReleaseCurrent(GLSurface* surface) { | 132 void GLContextGLX::ReleaseCurrent(GLSurface* surface) { |
133 if (!IsCurrent(surface)) | 133 if (!IsCurrent(surface)) |
134 return; | 134 return; |
135 | 135 |
136 SetCurrent(NULL); | 136 SetCurrent(NULL); |
137 if (!glXMakeContextCurrent(display_, 0, 0, 0)) | 137 if (!glXMakeContextCurrent(display_, 0, 0, 0)) |
138 LOG(ERROR) << "glXMakeCurrent failed in ReleaseCurrent"; | 138 LOG(ERROR) << "glXMakeCurrent failed in ReleaseCurrent"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 bool GLContextGLX::WasAllocatedUsingRobustnessExtension() { | 208 bool GLContextGLX::WasAllocatedUsingRobustnessExtension() { |
209 return GLSurfaceGLX::IsCreateContextRobustnessSupported(); | 209 return GLSurfaceGLX::IsCreateContextRobustnessSupported(); |
210 } | 210 } |
211 | 211 |
212 GLContextGLX::~GLContextGLX() { | 212 GLContextGLX::~GLContextGLX() { |
213 Destroy(); | 213 Destroy(); |
214 } | 214 } |
215 | 215 |
216 } // namespace gfx | 216 } // namespace gfx |
OLD | NEW |