Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: ui/gfx/gl/gl_context_osmesa.cc

Issue 7021014: GLContext no longer holds a pointer to a GLSurface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/gl/gl_context_osmesa.cc
===================================================================
--- ui/gfx/gl/gl_context_osmesa.cc (revision 86168)
+++ ui/gfx/gl/gl_context_osmesa.cc (working copy)
@@ -4,31 +4,32 @@
#include <GL/osmesa.h>
-#include <algorithm>
+#include "ui/gfx/gl/gl_context_osmesa.h"
#include "base/logging.h"
#include "ui/gfx/gl/gl_bindings.h"
-#include "ui/gfx/gl/gl_context_osmesa.h"
+#include "ui/gfx/gl/gl_surface_osmesa.h"
namespace gfx {
-GLContextOSMesa::GLContextOSMesa(GLSurfaceOSMesa* surface)
- : surface_(surface),
- context_(NULL)
-{
+GLContextOSMesa::GLContextOSMesa()
+ : context_(NULL) {
}
GLContextOSMesa::~GLContextOSMesa() {
Destroy();
}
-bool GLContextOSMesa::Initialize(GLuint format, GLContext* shared_context) {
+bool GLContextOSMesa::Initialize(GLContext* shared_context,
+ GLSurface* compatible_surface) {
DCHECK(!context_);
OSMesaContext shared_handle = NULL;
if (shared_context)
shared_handle = static_cast<OSMesaContext>(shared_context->GetHandle());
+ GLuint format =
+ static_cast<GLSurfaceOSMesa*>(compatible_surface)->GetFormat();
context_ = OSMesaCreateContextExt(format,
24, // depth bits
8, // stencil bits
@@ -47,22 +48,20 @@
OSMesaDestroyContext(static_cast<OSMesaContext>(context_));
context_ = NULL;
}
-
- if (surface_.get()) {
- surface_->Destroy();
- surface_.reset();
- }
}
-bool GLContextOSMesa::MakeCurrent() {
+bool GLContextOSMesa::MakeCurrent(GLSurface* surface) {
DCHECK(context_);
- gfx::Size size = surface_->GetSize();
+ gfx::Size size = surface->GetSize();
if (!OSMesaMakeCurrent(static_cast<OSMesaContext>(context_),
- surface_->GetHandle(),
+ surface->GetHandle(),
GL_UNSIGNED_BYTE,
- size.width(), size.height())) {
+ size.width(),
+ size.height())) {
+ LOG(ERROR) << "OSMesaMakeCurrent failed.";
+ Destroy();
return false;
}
@@ -72,24 +71,29 @@
return true;
}
-bool GLContextOSMesa::IsCurrent() {
- DCHECK(context_);
- return context_ == OSMesaGetCurrentContext();
-}
+void GLContextOSMesa::ReleaseCurrent(GLSurface* surface) {
+ if (!IsCurrent(surface))
+ return;
-bool GLContextOSMesa::IsOffscreen() {
- // TODO(apatrick): remove this from GLContext interface.
- return surface_->IsOffscreen();
+ OSMesaMakeCurrent(NULL, NULL, GL_UNSIGNED_BYTE, 0, 0);
}
-bool GLContextOSMesa::SwapBuffers() {
- // TODO(apatrick): remove this from GLContext interface.
- return surface_->SwapBuffers();
-}
+bool GLContextOSMesa::IsCurrent(GLSurface* surface) {
+ DCHECK(context_);
+ if (context_ != OSMesaGetCurrentContext())
+ return false;
-gfx::Size GLContextOSMesa::GetSize() {
- // TODO(apatrick): remove this from GLContext interface.
- return surface_->GetSize();
+ if (surface) {
+ GLint width;
+ GLint height;
+ GLint format;
+ void* buffer = NULL;
+ OSMesaGetColorBuffer(context_, &width, &height, &format, &buffer);
+ if (buffer != surface->GetHandle())
+ return false;
+ }
+
+ return true;
}
void* GLContextOSMesa::GetHandle() {
@@ -97,7 +101,7 @@
}
void GLContextOSMesa::SetSwapInterval(int interval) {
- DCHECK(IsCurrent());
+ DCHECK(IsCurrent(NULL));
NOTREACHED() << "Attempt to call SetSwapInterval on an GLContextOSMesa.";
}

Powered by Google App Engine
This is Rietveld 408576698