| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <GL/osmesa.h> | 5 #include <GL/osmesa.h> |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include "ui/gfx/gl/gl_context_osmesa.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/gfx/gl/gl_bindings.h" | 10 #include "ui/gfx/gl/gl_bindings.h" |
| 11 #include "ui/gfx/gl/gl_context_osmesa.h" | 11 #include "ui/gfx/gl/gl_surface_osmesa.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 | 14 |
| 15 GLContextOSMesa::GLContextOSMesa(GLSurfaceOSMesa* surface) | 15 GLContextOSMesa::GLContextOSMesa() |
| 16 : surface_(surface), | 16 : context_(NULL) |
| 17 context_(NULL) | |
| 18 { | 17 { |
| 19 } | 18 } |
| 20 | 19 |
| 21 GLContextOSMesa::~GLContextOSMesa() { | 20 GLContextOSMesa::~GLContextOSMesa() { |
| 22 Destroy(); | 21 Destroy(); |
| 23 } | 22 } |
| 24 | 23 |
| 25 bool GLContextOSMesa::Initialize(GLuint format, GLContext* shared_context) { | 24 bool GLContextOSMesa::Initialize(GLuint format, GLContext* shared_context) { |
| 26 DCHECK(!context_); | 25 DCHECK(!context_); |
| 27 | 26 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 40 } | 39 } |
| 41 | 40 |
| 42 return true; | 41 return true; |
| 43 } | 42 } |
| 44 | 43 |
| 45 void GLContextOSMesa::Destroy() { | 44 void GLContextOSMesa::Destroy() { |
| 46 if (context_) { | 45 if (context_) { |
| 47 OSMesaDestroyContext(static_cast<OSMesaContext>(context_)); | 46 OSMesaDestroyContext(static_cast<OSMesaContext>(context_)); |
| 48 context_ = NULL; | 47 context_ = NULL; |
| 49 } | 48 } |
| 50 | |
| 51 if (surface_.get()) { | |
| 52 surface_->Destroy(); | |
| 53 surface_.reset(); | |
| 54 } | |
| 55 } | 49 } |
| 56 | 50 |
| 57 bool GLContextOSMesa::MakeCurrent() { | 51 bool GLContextOSMesa::MakeCurrent(GLSurface* surface) { |
| 58 DCHECK(context_); | 52 DCHECK(context_); |
| 59 | 53 |
| 60 gfx::Size size = surface_->GetSize(); | 54 gfx::Size size = surface->GetSize(); |
| 61 | 55 |
| 62 if (!OSMesaMakeCurrent(static_cast<OSMesaContext>(context_), | 56 if (!OSMesaMakeCurrent(static_cast<OSMesaContext>(context_), |
| 63 surface_->GetHandle(), | 57 surface->GetHandle(), |
| 64 GL_UNSIGNED_BYTE, | 58 GL_UNSIGNED_BYTE, |
| 65 size.width(), size.height())) { | 59 size.width(), |
| 60 size.height())) { |
| 61 LOG(ERROR) << "OSMesaMakeCurrent failed."; |
| 62 Destroy(); |
| 66 return false; | 63 return false; |
| 67 } | 64 } |
| 68 | 65 |
| 69 // Row 0 is at the top. | 66 // Row 0 is at the top. |
| 70 OSMesaPixelStore(OSMESA_Y_UP, 0); | 67 OSMesaPixelStore(OSMESA_Y_UP, 0); |
| 71 | 68 |
| 72 return true; | 69 return true; |
| 73 } | 70 } |
| 74 | 71 |
| 75 bool GLContextOSMesa::IsCurrent() { | 72 void GLContextOSMesa::ReleaseCurrent(GLSurface* surface) { |
| 76 DCHECK(context_); | 73 if (!IsCurrent(surface)) |
| 77 return context_ == OSMesaGetCurrentContext(); | 74 return; |
| 75 |
| 76 OSMesaMakeCurrent(NULL, NULL, GL_UNSIGNED_BYTE, 0, 0); |
| 78 } | 77 } |
| 79 | 78 |
| 80 bool GLContextOSMesa::IsOffscreen() { | 79 bool GLContextOSMesa::IsCurrent(GLSurface* surface) { |
| 81 // TODO(apatrick): remove this from GLContext interface. | 80 DCHECK(context_); |
| 82 return surface_->IsOffscreen(); | 81 if (context_ != OSMesaGetCurrentContext()) |
| 83 } | 82 return false; |
| 84 | 83 |
| 85 bool GLContextOSMesa::SwapBuffers() { | 84 if (surface) { |
| 86 // TODO(apatrick): remove this from GLContext interface. | 85 GLint width; |
| 87 return surface_->SwapBuffers(); | 86 GLint height; |
| 88 } | 87 GLint format; |
| 88 void* buffer = NULL; |
| 89 OSMesaGetColorBuffer(context_, &width, &height, &format, &buffer); |
| 90 if (buffer != surface->GetHandle()) |
| 91 return false; |
| 92 } |
| 89 | 93 |
| 90 gfx::Size GLContextOSMesa::GetSize() { | 94 return true; |
| 91 // TODO(apatrick): remove this from GLContext interface. | |
| 92 return surface_->GetSize(); | |
| 93 } | 95 } |
| 94 | 96 |
| 95 void* GLContextOSMesa::GetHandle() { | 97 void* GLContextOSMesa::GetHandle() { |
| 96 return context_; | 98 return context_; |
| 97 } | 99 } |
| 98 | 100 |
| 99 void GLContextOSMesa::SetSwapInterval(int interval) { | 101 void GLContextOSMesa::SetSwapInterval(int interval) { |
| 100 DCHECK(IsCurrent()); | 102 DCHECK(IsCurrent(NULL)); |
| 101 NOTREACHED() << "Attempt to call SetSwapInterval on an GLContextOSMesa."; | 103 NOTREACHED() << "Attempt to call SetSwapInterval on an GLContextOSMesa."; |
| 102 } | 104 } |
| 103 | 105 |
| 104 } // namespace gfx | 106 } // namespace gfx |
| OLD | NEW |