| 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 #include "ui/gl/gl_context_osmesa.h" | 5 #include "ui/gl/gl_context_osmesa.h" |
| 6 | 6 |
| 7 #include <GL/osmesa.h> | 7 #include <GL/osmesa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 OSMesaDestroyContext(static_cast<OSMesaContext>(context_)); | 45 OSMesaDestroyContext(static_cast<OSMesaContext>(context_)); |
| 46 context_ = NULL; | 46 context_ = NULL; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool GLContextOSMesa::MakeCurrent(GLSurface* surface) { | 50 bool GLContextOSMesa::MakeCurrent(GLSurface* surface) { |
| 51 DCHECK(context_); | 51 DCHECK(context_); |
| 52 | 52 |
| 53 gfx::Size size = surface->GetSize(); | 53 gfx::Size size = surface->GetSize(); |
| 54 | 54 |
| 55 ScopedReleaseCurrent release_current; |
| 55 if (!OSMesaMakeCurrent(context_, | 56 if (!OSMesaMakeCurrent(context_, |
| 56 surface->GetHandle(), | 57 surface->GetHandle(), |
| 57 GL_UNSIGNED_BYTE, | 58 GL_UNSIGNED_BYTE, |
| 58 size.width(), | 59 size.width(), |
| 59 size.height())) { | 60 size.height())) { |
| 60 LOG(ERROR) << "OSMesaMakeCurrent failed."; | 61 LOG(ERROR) << "OSMesaMakeCurrent failed."; |
| 61 Destroy(); | 62 Destroy(); |
| 62 return false; | 63 return false; |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Set this as soon as the context is current, since we might call into GL. | 66 // Set this as soon as the context is current, since we might call into GL. |
| 66 SetRealGLApi(); | 67 SetRealGLApi(); |
| 67 | 68 |
| 68 // Row 0 is at the top. | 69 // Row 0 is at the top. |
| 69 OSMesaPixelStore(OSMESA_Y_UP, 0); | 70 OSMesaPixelStore(OSMESA_Y_UP, 0); |
| 70 | 71 |
| 71 SetCurrent(surface); | 72 SetCurrent(surface); |
| 72 if (!InitializeDynamicBindings()) { | 73 if (!InitializeDynamicBindings()) { |
| 73 ReleaseCurrent(surface); | |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 | 76 |
| 77 if (!surface->OnMakeCurrent(this)) { | 77 if (!surface->OnMakeCurrent(this)) { |
| 78 LOG(ERROR) << "Could not make current."; | 78 LOG(ERROR) << "Could not make current."; |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 | 81 |
| 82 release_current.Cancel(); |
| 82 return true; | 83 return true; |
| 83 } | 84 } |
| 84 | 85 |
| 85 void GLContextOSMesa::ReleaseCurrent(GLSurface* surface) { | 86 void GLContextOSMesa::ReleaseCurrent(GLSurface* surface) { |
| 86 if (!IsCurrent(surface)) | 87 if (!IsCurrent(surface)) |
| 87 return; | 88 return; |
| 88 | 89 |
| 89 SetCurrent(NULL); | 90 SetCurrent(NULL); |
| 91 // TODO: Calling with NULL here does not work to release the context. |
| 90 OSMesaMakeCurrent(NULL, NULL, GL_UNSIGNED_BYTE, 0, 0); | 92 OSMesaMakeCurrent(NULL, NULL, GL_UNSIGNED_BYTE, 0, 0); |
| 91 } | 93 } |
| 92 | 94 |
| 93 bool GLContextOSMesa::IsCurrent(GLSurface* surface) { | 95 bool GLContextOSMesa::IsCurrent(GLSurface* surface) { |
| 94 DCHECK(context_); | 96 DCHECK(context_); |
| 95 | 97 |
| 96 bool native_context_is_current = | 98 bool native_context_is_current = |
| 97 context_ == OSMesaGetCurrentContext(); | 99 context_ == OSMesaGetCurrentContext(); |
| 98 | 100 |
| 99 // If our context is current then our notion of which GLContext is | 101 // If our context is current then our notion of which GLContext is |
| (...skipping 23 matching lines...) Expand all Loading... |
| 123 | 125 |
| 124 void GLContextOSMesa::SetSwapInterval(int interval) { | 126 void GLContextOSMesa::SetSwapInterval(int interval) { |
| 125 DCHECK(IsCurrent(NULL)); | 127 DCHECK(IsCurrent(NULL)); |
| 126 } | 128 } |
| 127 | 129 |
| 128 GLContextOSMesa::~GLContextOSMesa() { | 130 GLContextOSMesa::~GLContextOSMesa() { |
| 129 Destroy(); | 131 Destroy(); |
| 130 } | 132 } |
| 131 | 133 |
| 132 } // namespace gfx | 134 } // namespace gfx |
| OLD | NEW |