summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/service/gl_context_mac.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gpu/command_buffer/service/gl_context_mac.cc')
-rw-r--r--gpu/command_buffer/service/gl_context_mac.cc145
1 files changed, 64 insertions, 81 deletions
diff --git a/gpu/command_buffer/service/gl_context_mac.cc b/gpu/command_buffer/service/gl_context_mac.cc
index 509e965..7fed885 100644
--- a/gpu/command_buffer/service/gl_context_mac.cc
+++ b/gpu/command_buffer/service/gl_context_mac.cc
@@ -4,84 +4,59 @@
// This file implements the ViewGLContext and PbufferGLContext classes.
-#include "gpu/command_buffer/service/gl_context.h"
-#include "gpu/command_buffer/common/logging.h"
+// Ensure that gl_utils.h is included before any GL headers.
+#include "gpu/command_buffer/service/gl_utils.h"
-#if !defined(UNIT_TEST)
#include "app/surface/accelerated_surface_mac.h"
-#endif
+#include "base/scoped_ptr.h"
+#include "gpu/command_buffer/service/gl_context.h"
+#include "gpu/command_buffer/service/gl_context_osmesa.h"
+#include "gpu/command_buffer/common/logging.h"
namespace gpu {
-static const char* error_message =
- "ViewGLContext not supported on Mac platform.";
+typedef CGLContextObj GLContextHandle;
+typedef CGLPBufferObj PbufferHandle;
+
+// This class is a wrapper around a GL context used for offscreen rendering.
+// It is initially backed by a 1x1 pbuffer. Use it to create an FBO to do useful
+// rendering.
+class PbufferGLContext : public GLContext {
+ public:
+ PbufferGLContext()
+ : context_(NULL),
+ pbuffer_(NULL) {
+ }
-bool ViewGLContext::Initialize(bool multisampled) {
-#if !defined(UNIT_TEST)
- NOTIMPLEMENTED() << error_message;
- return false;
-#else
- return true;
-#endif // UNIT_TEST
-}
+ // Initializes the GL context.
+ bool Initialize(void* shared_handle);
-void ViewGLContext::Destroy() {
-#if !defined(UNIT_TEST)
- NOTIMPLEMENTED() << error_message;
-#endif // UNIT_TEST
-}
+ virtual void Destroy();
+ virtual bool MakeCurrent();
+ virtual bool IsCurrent();
+ virtual bool IsOffscreen();
+ virtual void SwapBuffers();
+ virtual gfx::Size GetSize();
+ virtual void* GetHandle();
-bool ViewGLContext::MakeCurrent() {
-#if !defined(UNIT_TEST)
- NOTIMPLEMENTED() << error_message;
- return false;
-#else
- return true;
-#endif
-}
+ private:
+ GLContextHandle context_;
+ PbufferHandle pbuffer_;
-bool ViewGLContext::IsCurrent() {
-#if !defined(UNIT_TEST)
- NOTIMPLEMENTED() << error_message;
- return false;
-#else
- return true;
-#endif
-}
+ DISALLOW_COPY_AND_ASSIGN(PbufferGLContext);
+};
-bool ViewGLContext::IsOffscreen() {
- NOTIMPLEMENTED() << error_message;
- return false;
-}
-
-void ViewGLContext::SwapBuffers() {
-#if !defined(UNIT_TEST)
- NOTIMPLEMENTED() << error_message;
-#endif // UNIT_TEST
-}
+static bool InitializeOneOff() {
+ static bool initialized = false;
+ if (initialized)
+ return true;
-gfx::Size ViewGLContext::GetSize() {
-#if !defined(UNIT_TEST)
- NOTIMPLEMENTED() << error_message;
- return gfx::Size();
-#else
- return gfx::Size();
-#endif // UNIT_TEST
-}
-
-GLContextHandle ViewGLContext::GetHandle() {
-#if !defined(UNIT_TEST)
- NOTIMPLEMENTED() << error_message;
-#endif // UNIT_TEST
- return NULL;
-}
-
-bool PbufferGLContext::Initialize(GLContext* shared_context) {
- return Initialize(shared_context ? shared_context->GetHandle() : NULL);
+ osmewInit();
+ initialized = true;
+ return true;
}
-bool PbufferGLContext::Initialize(GLContextHandle shared_handle) {
-#if !defined(UNIT_TEST)
+bool PbufferGLContext::Initialize(void* shared_handle) {
// Create a 1x1 pbuffer and associated context to bootstrap things.
static const CGLPixelFormatAttribute attribs[] = {
(CGLPixelFormatAttribute) kCGLPFAPBuffer,
@@ -99,7 +74,9 @@ bool PbufferGLContext::Initialize(GLContextHandle shared_handle) {
if (!pixel_format) {
return false;
}
- CGLError res = CGLCreateContext(pixel_format, shared_handle, &context_);
+ CGLError res = CGLCreateContext(pixel_format,
+ static_cast<GLContextHandle>(shared_handle),
+ &context_);
CGLDestroyPixelFormat(pixel_format);
if (res != kCGLNoError) {
DLOG(ERROR) << "Error creating context.";
@@ -135,13 +112,10 @@ bool PbufferGLContext::Initialize(GLContextHandle shared_handle) {
return false;
}
-#endif // UNIT_TEST
-
return true;
}
void PbufferGLContext::Destroy() {
-#if !defined(UNIT_TEST)
if (context_) {
CGLDestroyContext(context_);
context_ = NULL;
@@ -151,28 +125,21 @@ void PbufferGLContext::Destroy() {
CGLDestroyPBuffer(pbuffer_);
pbuffer_ = NULL;
}
-#endif // UNIT_TEST
}
bool PbufferGLContext::MakeCurrent() {
-#if !defined(UNIT_TEST)
if (!IsCurrent()) {
if (CGLSetCurrentContext(context_) != kCGLNoError) {
DLOG(ERROR) << "Unable to make gl context current.";
return false;
}
}
-#endif // UNIT_TEST
return true;
}
bool PbufferGLContext::IsCurrent() {
-#if !defined(UNIT_TEST)
return CGLGetCurrentContext() == context_;
-#else
- return true;
-#endif
}
bool PbufferGLContext::IsOffscreen() {
@@ -188,12 +155,28 @@ gfx::Size PbufferGLContext::GetSize() {
return gfx::Size(1, 1);
}
-GLContextHandle PbufferGLContext::GetHandle() {
-#if !defined(UNIT_TEST)
+void* PbufferGLContext::GetHandle() {
return context_;
-#else
- return NULL;
-#endif // UNIT_TEST
+}
+
+GLContext* GLContext::CreateOffscreenGLContext(void* shared_handle) {
+ if (!InitializeOneOff())
+ return NULL;
+
+ if (OSMesaCreateContext) {
+ scoped_ptr<OSMesaGLContext> context(new OSMesaGLContext);
+
+ if (!context->Initialize(shared_handle))
+ return NULL;
+
+ return context.release();
+ } else {
+ scoped_ptr<PbufferGLContext> context(new PbufferGLContext);
+ if (!context->Initialize(shared_handle))
+ return NULL;
+
+ return context.release();
+ }
}
} // namespace gpu