OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This class implements the XWindowWrapper class. | 5 // This class implements the XWindowWrapper class. |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 | 8 |
9 #include "gpu/command_buffer/service/precompile.h" | 9 #include "gpu/command_buffer/service/precompile.h" |
10 #include "gpu/command_buffer/common/logging.h" | 10 #include "gpu/command_buffer/common/logging.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 if (!glewIsSupported("GL_VERSION_2_0")) { | 68 if (!glewIsSupported("GL_VERSION_2_0")) { |
69 LOG(ERROR) << "GL implementation doesn't support GL version 2.0"; | 69 LOG(ERROR) << "GL implementation doesn't support GL version 2.0"; |
70 return false; | 70 return false; |
71 } | 71 } |
72 | 72 |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
76 bool XWindowWrapper::MakeCurrent() { | 76 bool XWindowWrapper::MakeCurrent() { |
| 77 if (glXGetCurrentDrawable() == window && |
| 78 glXGetCurrentContext() == context_) { |
| 79 return true; |
| 80 } |
77 if (glXMakeCurrent(display_, window_, context_) != True) { | 81 if (glXMakeCurrent(display_, window_, context_) != True) { |
78 glXDestroyContext(display_, context_); | 82 glXDestroyContext(display_, context_); |
79 context_ = 0; | 83 context_ = 0; |
80 DLOG(ERROR) << "Couldn't make context current."; | 84 DLOG(ERROR) << "Couldn't make context current."; |
81 return false; | 85 return false; |
82 } | 86 } |
83 return true; | 87 return true; |
84 } | 88 } |
85 | 89 |
86 void XWindowWrapper::Destroy() { | 90 void XWindowWrapper::Destroy() { |
87 Bool result = glXMakeCurrent(display_, 0, 0); | 91 Bool result = glXMakeCurrent(display_, 0, 0); |
88 // glXMakeCurrent isn't supposed to fail when unsetting the context, unless | 92 // glXMakeCurrent isn't supposed to fail when unsetting the context, unless |
89 // we have pending draws on an invalid window - which shouldn't be the case | 93 // we have pending draws on an invalid window - which shouldn't be the case |
90 // here. | 94 // here. |
91 DCHECK(result); | 95 DCHECK(result); |
92 if (context_) { | 96 if (context_) { |
93 glXDestroyContext(display_, context_); | 97 glXDestroyContext(display_, context_); |
94 context_ = 0; | 98 context_ = 0; |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
98 void XWindowWrapper::SwapBuffers() { | 102 void XWindowWrapper::SwapBuffers() { |
99 glXSwapBuffers(display_, window_); | 103 glXSwapBuffers(display_, window_); |
100 } | 104 } |
101 | 105 |
102 } // namespace gpu | 106 } // namespace gpu |
OLD | NEW |