summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-11 19:41:58 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-11 19:41:58 +0000
commit333c5c9ca65425d1796d9d13abda37ecbce2c9fb (patch)
tree85b92482a6ed18f7be48b153352436be89eb5b3e /ui
parent374d9094395c15cd3b337de5c36587312fcc8a1e (diff)
downloadchromium_src-333c5c9ca65425d1796d9d13abda37ecbce2c9fb.zip
chromium_src-333c5c9ca65425d1796d9d13abda37ecbce2c9fb.tar.gz
chromium_src-333c5c9ca65425d1796d9d13abda37ecbce2c9fb.tar.bz2
Revert 85013 - Split GLContext::Create*GLContext into GLSurface::Create*GLSurface plus a surface type independent GLContext::CreateGLContext.
TEST=webgl on windows and mac, trybots BUG=none Review URL: http://codereview.chromium.org/6997003 TBR=apatrick@chromium.org Review URL: http://codereview.chromium.org/7015003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85016 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/gl/gl.gyp5
-rw-r--r--ui/gfx/gl/gl_context.h21
-rw-r--r--ui/gfx/gl/gl_context_linux.cc314
-rw-r--r--ui/gfx/gl/gl_context_mac.cc52
-rw-r--r--ui/gfx/gl/gl_context_stub.cc20
-rw-r--r--ui/gfx/gl/gl_context_stub.h8
-rw-r--r--ui/gfx/gl/gl_context_win.cc230
-rw-r--r--ui/gfx/gl/gl_surface.cc6
-rw-r--r--ui/gfx/gl/gl_surface.h14
-rw-r--r--ui/gfx/gl/gl_surface_linux.cc306
-rw-r--r--ui/gfx/gl/gl_surface_mac.cc103
-rw-r--r--ui/gfx/gl/gl_surface_stub.cc31
-rw-r--r--ui/gfx/gl/gl_surface_stub.h33
-rw-r--r--ui/gfx/gl/gl_surface_win.cc231
-rw-r--r--ui/gfx/surface/accelerated_surface_mac.cc17
15 files changed, 593 insertions, 798 deletions
diff --git a/ui/gfx/gl/gl.gyp b/ui/gfx/gl/gl.gyp
index 83acee4..4e45a72 100644
--- a/ui/gfx/gl/gl.gyp
+++ b/ui/gfx/gl/gl.gyp
@@ -76,11 +76,6 @@
'gl_interface.h',
'gl_surface.cc',
'gl_surface.h',
- 'gl_surface_linux.cc',
- 'gl_surface_mac.cc',
- 'gl_surface_stub.cc',
- 'gl_surface_stub.h',
- 'gl_surface_win.cc',
'gl_surface_osmesa.cc',
'gl_surface_osmesa.h',
'gl_switches.cc',
diff --git a/ui/gfx/gl/gl_context.h b/ui/gfx/gl/gl_context.h
index 548b6ae..b27f8c9 100644
--- a/ui/gfx/gl/gl_context.h
+++ b/ui/gfx/gl/gl_context.h
@@ -66,14 +66,19 @@ class GLContext {
// context must be current.
bool HasExtension(const char* name);
- // Create a GL context that is compatible with the given surface.
- // |share_context|, if non-NULL, is a context which the
- // internally created OpenGL context shares textures and other resources.
- // TODO(apatrick): For the time being, the context will take ownership of the
- // surface and the surface will be made the current read and draw surface
- // when the context is made current.
- static GLContext* CreateGLContext(GLSurface* compatible_surface,
- GLContext* shared_context);
+ static bool InitializeOneOff();
+
+#if !defined(OS_MACOSX)
+ // Create a GL context that renders directly to a view.
+ static GLContext* CreateViewGLContext(gfx::PluginWindowHandle window,
+ bool multisampled);
+#endif
+
+ // Create 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.
+ // |share_context|, if non-NULL, is a context which the internally created
+ // OpenGL context shares textures and other resources.
+ static GLContext* CreateOffscreenGLContext(GLContext* shared_context);
static bool LosesAllContextsOnContextLost();
diff --git a/ui/gfx/gl/gl_context_linux.cc b/ui/gfx/gl/gl_context_linux.cc
index feb735c..deac474 100644
--- a/ui/gfx/gl/gl_context_linux.cc
+++ b/ui/gfx/gl/gl_context_linux.cc
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/gfx/gl/gl_context.h"
+#include <GL/osmesa.h>
+#include "base/basictypes.h"
#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "third_party/mesa/MesaLib/include/GL/osmesa.h"
+#include "ui/base/x/x11_util.h"
#include "ui/gfx/gl/gl_bindings.h"
+#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_context_egl.h"
#include "ui/gfx/gl/gl_context_glx.h"
#include "ui/gfx/gl/gl_context_osmesa.h"
@@ -15,41 +16,322 @@
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface_egl.h"
#include "ui/gfx/gl/gl_surface_glx.h"
-#include "ui/gfx/gl/gl_surface_stub.h"
#include "ui/gfx/gl/gl_surface_osmesa.h"
namespace gfx {
-GLContext* GLContext::CreateGLContext(GLSurface* compatible_surface,
- GLContext* shared_context) {
+namespace {
+Display* g_osmesa_display;
+} // namespace anonymous
+
+// This OSMesa GL surface can use XLib to swap the contents of the buffer to a
+// view.
+class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
+ public:
+ explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window);
+ virtual ~NativeViewGLSurfaceOSMesa();
+
+ static bool InitializeOneOff();
+
+ // Initializes the GL context.
+ bool Initialize();
+
+ // Implement a subset of GLSurface.
+ virtual void Destroy();
+ virtual bool IsOffscreen();
+ virtual bool SwapBuffers();
+
+ private:
+ bool UpdateSize();
+
+ GC window_graphics_context_;
+ gfx::PluginWindowHandle window_;
+ GC pixmap_graphics_context_;
+ Pixmap pixmap_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa);
+};
+
+bool GLContext::InitializeOneOff() {
+ static bool initialized = false;
+ if (initialized)
+ return true;
+
+ static const GLImplementation kAllowedGLImplementations[] = {
+ kGLImplementationDesktopGL,
+ kGLImplementationEGLGLES2,
+ kGLImplementationOSMesaGL
+ };
+
+ if (!InitializeRequestedGLBindings(
+ kAllowedGLImplementations,
+ kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
+ kGLImplementationDesktopGL)) {
+ LOG(ERROR) << "InitializeRequestedGLBindings failed.";
+ return false;
+ }
+
switch (GetGLImplementation()) {
- case kGLImplementationOSMesaGL: {
- scoped_ptr<GLContextOSMesa> context(
- new GLContextOSMesa(static_cast<GLSurfaceOSMesa*>(
- compatible_surface)));
- if (!context->Initialize(OSMESA_RGBA, shared_context))
+ case kGLImplementationDesktopGL:
+ if (!GLSurfaceGLX::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ case kGLImplementationEGLGLES2:
+ if (!GLSurfaceEGL::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ case kGLImplementationOSMesaGL:
+ if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) {
+ LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ default:
+ break;
+ }
+
+ initialized = true;
+ return true;
+}
+
+NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
+ gfx::PluginWindowHandle window)
+ : window_graphics_context_(0),
+ window_(window),
+ pixmap_graphics_context_(0),
+ pixmap_(0) {
+ DCHECK(window);
+}
+
+NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() {
+ Destroy();
+}
+
+bool NativeViewGLSurfaceOSMesa::InitializeOneOff() {
+ static bool initialized = false;
+ if (initialized)
+ return true;
+
+ g_osmesa_display = XOpenDisplay(NULL);
+ if (!g_osmesa_display) {
+ LOG(ERROR) << "XOpenDisplay failed.";
+ return false;
+ }
+
+ initialized = true;
+ return true;
+}
+
+bool NativeViewGLSurfaceOSMesa::Initialize() {
+ window_graphics_context_ = XCreateGC(g_osmesa_display,
+ window_,
+ 0,
+ NULL);
+ if (!window_graphics_context_) {
+ LOG(ERROR) << "XCreateGC failed.";
+ Destroy();
+ return false;
+ }
+
+ UpdateSize();
+
+ return true;
+}
+
+void NativeViewGLSurfaceOSMesa::Destroy() {
+ if (pixmap_graphics_context_) {
+ XFreeGC(g_osmesa_display, pixmap_graphics_context_);
+ pixmap_graphics_context_ = NULL;
+ }
+
+ if (pixmap_) {
+ XFreePixmap(g_osmesa_display, pixmap_);
+ pixmap_ = 0;
+ }
+
+ if (window_graphics_context_) {
+ XFreeGC(g_osmesa_display, window_graphics_context_);
+ window_graphics_context_ = NULL;
+ }
+}
+
+bool NativeViewGLSurfaceOSMesa::IsOffscreen() {
+ return false;
+}
+
+bool NativeViewGLSurfaceOSMesa::SwapBuffers() {
+ // Update the size before blitting so that the blit size is exactly the same
+ // as the window.
+ if (!UpdateSize()) {
+ LOG(ERROR) << "Failed to update size of GLContextOSMesa.";
+ return false;
+ }
+
+ gfx::Size size = GetSize();
+
+ // Copy the frame into the pixmap.
+ XWindowAttributes attributes;
+ XGetWindowAttributes(g_osmesa_display, window_, &attributes);
+ ui::PutARGBImage(g_osmesa_display,
+ attributes.visual,
+ attributes.depth,
+ pixmap_,
+ pixmap_graphics_context_,
+ static_cast<const uint8*>(GetHandle()),
+ size.width(),
+ size.height());
+
+ // Copy the pixmap to the window.
+ XCopyArea(g_osmesa_display,
+ pixmap_,
+ window_,
+ window_graphics_context_,
+ 0, 0,
+ size.width(), size.height(),
+ 0, 0);
+
+ return true;
+}
+
+bool NativeViewGLSurfaceOSMesa::UpdateSize() {
+ // Get the window size.
+ XWindowAttributes attributes;
+ XGetWindowAttributes(g_osmesa_display, window_, &attributes);
+ gfx::Size window_size = gfx::Size(std::max(1, attributes.width),
+ std::max(1, attributes.height));
+
+ // Early out if the size has not changed.
+ gfx::Size osmesa_size = GetSize();
+ if (pixmap_graphics_context_ && pixmap_ && window_size == osmesa_size)
+ return true;
+
+ // Change osmesa surface size to that of window.
+ Resize(window_size);
+
+ // Destroy the previous pixmap and graphics context.
+ if (pixmap_graphics_context_) {
+ XFreeGC(g_osmesa_display, pixmap_graphics_context_);
+ pixmap_graphics_context_ = NULL;
+ }
+ if (pixmap_) {
+ XFreePixmap(g_osmesa_display, pixmap_);
+ pixmap_ = 0;
+ }
+
+ // Recreate a pixmap to hold the frame.
+ pixmap_ = XCreatePixmap(g_osmesa_display,
+ window_,
+ window_size.width(),
+ window_size.height(),
+ attributes.depth);
+ if (!pixmap_) {
+ LOG(ERROR) << "XCreatePixmap failed.";
+ return false;
+ }
+
+ // Recreate a graphics context for the pixmap.
+ pixmap_graphics_context_ = XCreateGC(g_osmesa_display, pixmap_, 0, NULL);
+ if (!pixmap_graphics_context_) {
+ LOG(ERROR) << "XCreateGC failed";
+ return false;
+ }
+
+ return true;
+}
+
+GLContext* GLContext::CreateViewGLContext(gfx::PluginWindowHandle window,
+ bool multisampled) {
+ switch (GetGLImplementation()) {
+ case kGLImplementationDesktopGL: {
+ scoped_ptr<GLSurfaceGLX> surface(new NativeViewGLSurfaceGLX(window));
+ if (!surface->Initialize()) {
+ return NULL;
+ }
+
+ scoped_ptr<GLContextGLX> context(
+ new GLContextGLX(surface.release()));
+ if (!context->Initialize(NULL))
return NULL;
return context.release();
}
case kGLImplementationEGLGLES2: {
+ scoped_ptr<NativeViewGLSurfaceEGL> surface(new NativeViewGLSurfaceEGL(
+ window));
+ if (!surface->Initialize())
+ return NULL;
+
scoped_ptr<GLContextEGL> context(
- new GLContextEGL(static_cast<GLSurfaceEGL*>(compatible_surface)));
- if (!context->Initialize(shared_context))
+ new GLContextEGL(surface.release()));
+ if (!context->Initialize(NULL))
+ return NULL;
+
+ return context.release();
+ }
+ case kGLImplementationOSMesaGL: {
+ scoped_ptr<NativeViewGLSurfaceOSMesa> surface(
+ new NativeViewGLSurfaceOSMesa(window));
+ if (!surface->Initialize())
+ return NULL;
+
+ scoped_ptr<GLContextOSMesa> context(
+ new GLContextOSMesa(surface.release()));
+ if (!context->Initialize(OSMESA_BGRA, NULL))
return NULL;
return context.release();
}
+ case kGLImplementationMockGL:
+ return new StubGLContext;
+ default:
+ NOTREACHED();
+ return NULL;
+ }
+}
+
+GLContext* GLContext::CreateOffscreenGLContext(GLContext* shared_context) {
+ switch (GetGLImplementation()) {
case kGLImplementationDesktopGL: {
- scoped_ptr<GLContextGLX> context(
- new GLContextGLX(static_cast<GLSurfaceGLX*>(compatible_surface)));
+ scoped_ptr<PbufferGLSurfaceGLX> surface(new PbufferGLSurfaceGLX(
+ gfx::Size(1, 1)));
+ if (!surface->Initialize())
+ return NULL;
+
+ scoped_ptr<GLContextGLX> context(new GLContextGLX(surface.release()));
+ if (!context->Initialize(shared_context))
+ return NULL;
+
+ return context.release();
+ }
+ case kGLImplementationEGLGLES2: {
+ scoped_ptr<PbufferGLSurfaceEGL> surface(new PbufferGLSurfaceEGL(
+ gfx::Size(1, 1)));
+ if (!surface->Initialize())
+ return NULL;
+
+ scoped_ptr<GLContextEGL> context(new GLContextEGL(surface.release()));
if (!context->Initialize(shared_context))
return NULL;
return context.release();
}
+ case kGLImplementationOSMesaGL: {
+ scoped_ptr<GLSurfaceOSMesa> surface(new GLSurfaceOSMesa());
+ surface->Resize(gfx::Size(1, 1));
+
+ scoped_ptr<GLContextOSMesa> context(
+ new GLContextOSMesa(surface.release()));
+ if (!context->Initialize(OSMESA_BGRA, shared_context))
+ return NULL;
+
+ return context.release();
+ }
case kGLImplementationMockGL:
- return new GLContextStub;
+ return new StubGLContext;
default:
NOTREACHED();
return NULL;
diff --git a/ui/gfx/gl/gl_context_mac.cc b/ui/gfx/gl/gl_context_mac.cc
index ba72080..fbb18b0 100644
--- a/ui/gfx/gl/gl_context_mac.cc
+++ b/ui/gfx/gl/gl_context_mac.cc
@@ -16,28 +16,66 @@
namespace gfx {
-GLContext* GLContext::CreateGLContext(GLSurface* compatible_surface,
- GLContext* shared_context) {
+bool GLContext::InitializeOneOff() {
+ static bool initialized = false;
+ if (initialized)
+ return true;
+
+ static const GLImplementation kAllowedGLImplementations[] = {
+ kGLImplementationDesktopGL,
+ kGLImplementationOSMesaGL
+ };
+
+ if (!InitializeRequestedGLBindings(
+ kAllowedGLImplementations,
+ kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
+ kGLImplementationDesktopGL)) {
+ LOG(ERROR) << "InitializeRequestedGLBindings failed.";
+ return false;
+ }
+
+ switch (GetGLImplementation()) {
+ case kGLImplementationDesktopGL:
+ if (!GLSurfaceCGL::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ default:
+ break;
+ }
+
+ initialized = true;
+ return true;
+}
+
+GLContext* GLContext::CreateOffscreenGLContext(GLContext* shared_context) {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL: {
- scoped_ptr<GLContextCGL> context(
- new GLContextCGL(static_cast<GLSurfaceCGL*>(compatible_surface)));
+ scoped_ptr<PbufferGLSurfaceCGL> surface(new PbufferGLSurfaceCGL(
+ gfx::Size(1, 1)));
+ if (!surface->Initialize())
+ return false;
+
+ scoped_ptr<GLContextCGL> context(new GLContextCGL(surface.release()));
if (!context->Initialize(shared_context))
return NULL;
return context.release();
}
case kGLImplementationOSMesaGL: {
+ scoped_ptr<GLSurfaceOSMesa> surface(new GLSurfaceOSMesa());
+ surface->Resize(gfx::Size(1, 1));
+
scoped_ptr<GLContextOSMesa> context(
- new GLContextOSMesa(
- static_cast<GLSurfaceOSMesa*>(compatible_surface)));
+ new GLContextOSMesa(surface.release()));
if (!context->Initialize(OSMESA_RGBA, shared_context))
return NULL;
return context.release();
}
case kGLImplementationMockGL:
- return new GLContextStub;
+ return new StubGLContext;
default:
NOTREACHED();
return NULL;
diff --git a/ui/gfx/gl/gl_context_stub.cc b/ui/gfx/gl/gl_context_stub.cc
index 4154cdd..6462f61 100644
--- a/ui/gfx/gl/gl_context_stub.cc
+++ b/ui/gfx/gl/gl_context_stub.cc
@@ -6,37 +6,33 @@
namespace gfx {
-GLContextStub::GLContextStub() {
-}
-
-GLContextStub::~GLContextStub() {
-}
+StubGLContext::~StubGLContext() {}
-bool GLContextStub::MakeCurrent() {
+bool StubGLContext::MakeCurrent() {
return true;
}
-bool GLContextStub::IsCurrent() {
+bool StubGLContext::IsCurrent() {
return true;
}
-bool GLContextStub::IsOffscreen() {
+bool StubGLContext::IsOffscreen() {
return false;
}
-bool GLContextStub::SwapBuffers() {
+bool StubGLContext::SwapBuffers() {
return true;
}
-gfx::Size GLContextStub::GetSize() {
+gfx::Size StubGLContext::GetSize() {
return size_;
}
-void* GLContextStub::GetHandle() {
+void* StubGLContext::GetHandle() {
return NULL;
}
-std::string GLContextStub::GetExtensions() {
+std::string StubGLContext::GetExtensions() {
return std::string();
}
diff --git a/ui/gfx/gl/gl_context_stub.h b/ui/gfx/gl/gl_context_stub.h
index 37c49d1..03e5cf4 100644
--- a/ui/gfx/gl/gl_context_stub.h
+++ b/ui/gfx/gl/gl_context_stub.h
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// This file implements the StubGLContext.
+
#ifndef UI_GFX_GL_GL_CONTEXT_STUB_H_
#define UI_GFX_GL_GL_CONTEXT_STUB_H_
#pragma once
@@ -11,10 +13,9 @@
namespace gfx {
// A GLContext that does nothing for unit tests.
-class GLContextStub : public GLContext {
+class StubGLContext : public gfx::GLContext {
public:
- GLContextStub();
- virtual ~GLContextStub();
+ virtual ~StubGLContext();
void SetSize(const gfx::Size& size) { size_ = size; }
@@ -31,7 +32,6 @@ class GLContextStub : public GLContext {
private:
gfx::Size size_;
- DISALLOW_COPY_AND_ASSIGN(GLContextStub);
};
} // namespace gfx
diff --git a/ui/gfx/gl/gl_context_win.cc b/ui/gfx/gl/gl_context_win.cc
index 944bb8c..83e4198 100644
--- a/ui/gfx/gl/gl_context_win.cc
+++ b/ui/gfx/gl/gl_context_win.cc
@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// This file implements the NativeViewGLContext and PbufferGLContext classes.
+
+#include <algorithm>
+
#include "ui/gfx/gl/gl_context.h"
#include "base/logging.h"
@@ -15,41 +19,247 @@
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface_egl.h"
#include "ui/gfx/gl/gl_surface_osmesa.h"
-#include "ui/gfx/gl/gl_surface_stub.h"
#include "ui/gfx/gl/gl_surface_wgl.h"
namespace gfx {
-GLContext* GLContext::CreateGLContext(GLSurface* compatible_surface,
- GLContext* shared_context) {
+// This OSMesa GL surface can use GDI to swap the contents of the buffer to a
+// view.
+class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
+ public:
+ explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window);
+ virtual ~NativeViewGLSurfaceOSMesa();
+
+ // Initializes the GL context.
+ bool Initialize();
+
+ // Implement subset of GLSurface.
+ virtual void Destroy();
+ virtual bool IsOffscreen();
+ virtual bool SwapBuffers();
+
+ private:
+ void UpdateSize();
+
+ gfx::PluginWindowHandle window_;
+ HDC device_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa);
+};
+
+// Helper routine that does one-off initialization like determining the
+// pixel format and initializing the GL bindings.
+bool GLContext::InitializeOneOff() {
+ static bool initialized = false;
+ if (initialized)
+ return true;
+
+ static const GLImplementation kAllowedGLImplementations[] = {
+ kGLImplementationEGLGLES2,
+ kGLImplementationDesktopGL,
+ kGLImplementationOSMesaGL
+ };
+
+ if (!InitializeRequestedGLBindings(
+ kAllowedGLImplementations,
+ kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
+ kGLImplementationEGLGLES2)) {
+ LOG(ERROR) << "InitializeRequestedGLBindings failed.";
+ return false;
+ }
+
+ switch (GetGLImplementation()) {
+ case kGLImplementationDesktopGL:
+ if (!GLSurfaceWGL::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ case kGLImplementationEGLGLES2:
+ if (!GLSurfaceEGL::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ }
+
+ initialized = true;
+ return true;
+}
+
+NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
+ gfx::PluginWindowHandle window)
+ : window_(window),
+ device_context_(NULL) {
+ DCHECK(window);
+}
+
+NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() {
+ Destroy();
+}
+
+bool NativeViewGLSurfaceOSMesa::Initialize() {
+ device_context_ = GetDC(window_);
+ UpdateSize();
+ return true;
+}
+
+void NativeViewGLSurfaceOSMesa::Destroy() {
+ if (window_ && device_context_)
+ ReleaseDC(window_, device_context_);
+
+ window_ = NULL;
+ device_context_ = NULL;
+
+ GLSurfaceOSMesa::Destroy();
+}
+
+bool NativeViewGLSurfaceOSMesa::IsOffscreen() {
+ return false;
+}
+
+bool NativeViewGLSurfaceOSMesa::SwapBuffers() {
+ DCHECK(device_context_);
+
+ // Update the size before blitting so that the blit size is exactly the same
+ // as the window.
+ UpdateSize();
+
+ gfx::Size size = GetSize();
+
+ // Note: negating the height below causes GDI to treat the bitmap data as row
+ // 0 being at the top.
+ BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) };
+ info.bV4Width = size.width();
+ info.bV4Height = -size.height();
+ info.bV4Planes = 1;
+ info.bV4BitCount = 32;
+ info.bV4V4Compression = BI_BITFIELDS;
+ info.bV4RedMask = 0x000000FF;
+ info.bV4GreenMask = 0x0000FF00;
+ info.bV4BlueMask = 0x00FF0000;
+ info.bV4AlphaMask = 0xFF000000;
+
+ // Copy the back buffer to the window's device context. Do not check whether
+ // StretchDIBits succeeds or not. It will fail if the window has been
+ // destroyed but it is preferable to allow rendering to silently fail if the
+ // window is destroyed. This is because the primary application of this
+ // class of GLContext is for testing and we do not want every GL related ui /
+ // browser test to become flaky if there is a race condition between GL
+ // context destruction and window destruction.
+ StretchDIBits(device_context_,
+ 0, 0, size.width(), size.height(),
+ 0, 0, size.width(), size.height(),
+ GetHandle(),
+ reinterpret_cast<BITMAPINFO*>(&info),
+ DIB_RGB_COLORS,
+ SRCCOPY);
+
+ return true;
+}
+
+void NativeViewGLSurfaceOSMesa::UpdateSize() {
+ // Change back buffer size to that of window. If window handle is invalid, do
+ // not change the back buffer size.
+ RECT rect;
+ if (!GetClientRect(window_, &rect))
+ return;
+
+ gfx::Size window_size = gfx::Size(
+ std::max(1, static_cast<int>(rect.right - rect.left)),
+ std::max(1, static_cast<int>(rect.bottom - rect.top)));
+ Resize(window_size);
+}
+
+GLContext* GLContext::CreateViewGLContext(gfx::PluginWindowHandle window,
+ bool multisampled) {
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
+ scoped_ptr<NativeViewGLSurfaceOSMesa> surface(
+ new NativeViewGLSurfaceOSMesa(window));
+ if (!surface->Initialize())
+ return NULL;
+
scoped_ptr<GLContextOSMesa> context(
- new GLContextOSMesa(static_cast<GLSurfaceOSMesa*>(
- compatible_surface)));
- if (!context->Initialize(OSMESA_RGBA, shared_context))
+ new GLContextOSMesa(surface.release()));
+ if (!context->Initialize(OSMESA_RGBA, NULL))
return NULL;
return context.release();
}
case kGLImplementationEGLGLES2: {
+ scoped_ptr<NativeViewGLSurfaceEGL> surface(new NativeViewGLSurfaceEGL(
+ window));
+ if (!surface->Initialize())
+ return NULL;
+
scoped_ptr<GLContextEGL> context(
- new GLContextEGL(static_cast<GLSurfaceEGL*>(compatible_surface)));
- if (!context->Initialize(shared_context))
+ new GLContextEGL(surface.release()));
+ if (!context->Initialize(NULL))
return NULL;
return context.release();
}
case kGLImplementationDesktopGL: {
+ scoped_ptr<NativeViewGLSurfaceWGL> surface(new NativeViewGLSurfaceWGL(
+ window));
+ if (!surface->Initialize())
+ return NULL;
+
scoped_ptr<GLContextWGL> context(
- new GLContextWGL(static_cast<GLSurfaceWGL*>(compatible_surface)));
+ new GLContextWGL(surface.release()));
+ if (!context->Initialize(NULL))
+ return NULL;
+
+ return context.release();
+ }
+ case kGLImplementationMockGL:
+ return new StubGLContext;
+ default:
+ NOTREACHED();
+ return NULL;
+ }
+}
+
+GLContext* GLContext::CreateOffscreenGLContext(GLContext* shared_context) {
+ switch (GetGLImplementation()) {
+ case kGLImplementationOSMesaGL: {
+ scoped_ptr<GLSurfaceOSMesa> surface(new GLSurfaceOSMesa());
+ surface->Resize(gfx::Size(1, 1));
+
+ scoped_ptr<GLContextOSMesa> context(
+ new GLContextOSMesa(surface.release()));
+ if (!context->Initialize(OSMESA_RGBA, shared_context))
+ return NULL;
+
+ return context.release();
+ }
+ case kGLImplementationEGLGLES2: {
+ scoped_ptr<PbufferGLSurfaceEGL> surface(new PbufferGLSurfaceEGL(
+ gfx::Size(1, 1)));
+ if (!surface->Initialize())
+ return NULL;
+
+ scoped_ptr<GLContextEGL> context(new GLContextEGL(surface.release()));
+ if (!context->Initialize(shared_context))
+ return NULL;
+
+ return context.release();
+ }
+ case kGLImplementationDesktopGL: {
+ scoped_ptr<PbufferGLSurfaceWGL> surface(new PbufferGLSurfaceWGL(
+ gfx::Size(1, 1)));
+ if (!surface->Initialize())
+ return NULL;
+
+ scoped_ptr<GLContextWGL> context(new GLContextWGL(surface.release()));
if (!context->Initialize(shared_context))
return NULL;
return context.release();
}
case kGLImplementationMockGL:
- return new GLContextStub;
+ return new StubGLContext;
default:
NOTREACHED();
return NULL;
diff --git a/ui/gfx/gl/gl_surface.cc b/ui/gfx/gl/gl_surface.cc
index 3e4cb7e..de4b8a2 100644
--- a/ui/gfx/gl/gl_surface.cc
+++ b/ui/gfx/gl/gl_surface.cc
@@ -6,12 +6,6 @@
namespace gfx {
-GLSurface::GLSurface() {
-}
-
-GLSurface::~GLSurface() {
-}
-
bool GLSurface::Initialize()
{
return true;
diff --git a/ui/gfx/gl/gl_surface.h b/ui/gfx/gl/gl_surface.h
index 9c1dcc4..ca8afd1 100644
--- a/ui/gfx/gl/gl_surface.h
+++ b/ui/gfx/gl/gl_surface.h
@@ -16,8 +16,8 @@ namespace gfx {
// specific management.
class GLSurface {
public:
- GLSurface();
- virtual ~GLSurface();
+ GLSurface() {}
+ virtual ~GLSurface() {}
// (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the
// EGL surface associated to be recreated without destroying the associated
@@ -45,16 +45,6 @@ class GLSurface {
// FBO. Otherwise returns 0.
virtual unsigned int GetBackingFrameBufferObject();
- static bool InitializeOneOff();
-
-#if !defined(OS_MACOSX)
- // Create a GL surface that renders directly to a view.
- static GLSurface* CreateViewGLSurface(gfx::PluginWindowHandle window);
-#endif
-
- // Create a GL surface used for offscreen rendering.
- static GLSurface* CreateOffscreenGLSurface(const gfx::Size& size);
-
private:
DISALLOW_COPY_AND_ASSIGN(GLSurface);
};
diff --git a/ui/gfx/gl/gl_surface_linux.cc b/ui/gfx/gl/gl_surface_linux.cc
deleted file mode 100644
index b1f6db1..0000000
--- a/ui/gfx/gl/gl_surface_linux.cc
+++ /dev/null
@@ -1,306 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/gfx/gl/gl_surface.h"
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "third_party/mesa/MesaLib/include/GL/osmesa.h"
-#include "ui/gfx/gl/gl_bindings.h"
-#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface_egl.h"
-#include "ui/gfx/gl/gl_surface_glx.h"
-#include "ui/gfx/gl/gl_surface_osmesa.h"
-#include "ui/gfx/gl/gl_surface_stub.h"
-
-namespace gfx {
-
-namespace {
-Display* g_osmesa_display;
-} // namespace anonymous
-
-// This OSMesa GL surface can use XLib to swap the contents of the buffer to a
-// view.
-class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
- public:
- explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window);
- virtual ~NativeViewGLSurfaceOSMesa();
-
- static bool InitializeOneOff();
-
- // Initializes the GL context.
- bool Initialize();
-
- // Implement a subset of GLSurface.
- virtual void Destroy();
- virtual bool IsOffscreen();
- virtual bool SwapBuffers();
-
- private:
- bool UpdateSize();
-
- GC window_graphics_context_;
- gfx::PluginWindowHandle window_;
- GC pixmap_graphics_context_;
- Pixmap pixmap_;
-
- DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa);
-};
-
-bool GLSurface::InitializeOneOff() {
- static bool initialized = false;
- if (initialized)
- return true;
-
- static const GLImplementation kAllowedGLImplementations[] = {
- kGLImplementationDesktopGL,
- kGLImplementationEGLGLES2,
- kGLImplementationOSMesaGL
- };
-
- if (!InitializeRequestedGLBindings(
- kAllowedGLImplementations,
- kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
- kGLImplementationDesktopGL)) {
- LOG(ERROR) << "InitializeRequestedGLBindings failed.";
- return false;
- }
-
- switch (GetGLImplementation()) {
- case kGLImplementationDesktopGL:
- if (!GLSurfaceGLX::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed.";
- return false;
- }
- break;
- case kGLImplementationEGLGLES2:
- if (!GLSurfaceEGL::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
- return false;
- }
- break;
- case kGLImplementationOSMesaGL:
- if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) {
- LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed.";
- return false;
- }
- break;
- default:
- break;
- }
-
- initialized = true;
- return true;
-}
-
-NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
- gfx::PluginWindowHandle window)
- : window_graphics_context_(0),
- window_(window),
- pixmap_graphics_context_(0),
- pixmap_(0) {
- DCHECK(window);
-}
-
-NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() {
- Destroy();
-}
-
-bool NativeViewGLSurfaceOSMesa::InitializeOneOff() {
- static bool initialized = false;
- if (initialized)
- return true;
-
- g_osmesa_display = XOpenDisplay(NULL);
- if (!g_osmesa_display) {
- LOG(ERROR) << "XOpenDisplay failed.";
- return false;
- }
-
- initialized = true;
- return true;
-}
-
-bool NativeViewGLSurfaceOSMesa::Initialize() {
- window_graphics_context_ = XCreateGC(g_osmesa_display,
- window_,
- 0,
- NULL);
- if (!window_graphics_context_) {
- LOG(ERROR) << "XCreateGC failed.";
- Destroy();
- return false;
- }
-
- UpdateSize();
-
- return true;
-}
-
-void NativeViewGLSurfaceOSMesa::Destroy() {
- if (pixmap_graphics_context_) {
- XFreeGC(g_osmesa_display, pixmap_graphics_context_);
- pixmap_graphics_context_ = NULL;
- }
-
- if (pixmap_) {
- XFreePixmap(g_osmesa_display, pixmap_);
- pixmap_ = 0;
- }
-
- if (window_graphics_context_) {
- XFreeGC(g_osmesa_display, window_graphics_context_);
- window_graphics_context_ = NULL;
- }
-}
-
-bool NativeViewGLSurfaceOSMesa::IsOffscreen() {
- return false;
-}
-
-bool NativeViewGLSurfaceOSMesa::SwapBuffers() {
- // Update the size before blitting so that the blit size is exactly the same
- // as the window.
- if (!UpdateSize()) {
- LOG(ERROR) << "Failed to update size of GLContextOSMesa.";
- return false;
- }
-
- gfx::Size size = GetSize();
-
- // Copy the frame into the pixmap.
- XWindowAttributes attributes;
- XGetWindowAttributes(g_osmesa_display, window_, &attributes);
- ui::PutARGBImage(g_osmesa_display,
- attributes.visual,
- attributes.depth,
- pixmap_,
- pixmap_graphics_context_,
- static_cast<const uint8*>(GetHandle()),
- size.width(),
- size.height());
-
- // Copy the pixmap to the window.
- XCopyArea(g_osmesa_display,
- pixmap_,
- window_,
- window_graphics_context_,
- 0, 0,
- size.width(), size.height(),
- 0, 0);
-
- return true;
-}
-
-bool NativeViewGLSurfaceOSMesa::UpdateSize() {
- // Get the window size.
- XWindowAttributes attributes;
- XGetWindowAttributes(g_osmesa_display, window_, &attributes);
- gfx::Size window_size = gfx::Size(std::max(1, attributes.width),
- std::max(1, attributes.height));
-
- // Early out if the size has not changed.
- gfx::Size osmesa_size = GetSize();
- if (pixmap_graphics_context_ && pixmap_ && window_size == osmesa_size)
- return true;
-
- // Change osmesa surface size to that of window.
- Resize(window_size);
-
- // Destroy the previous pixmap and graphics context.
- if (pixmap_graphics_context_) {
- XFreeGC(g_osmesa_display, pixmap_graphics_context_);
- pixmap_graphics_context_ = NULL;
- }
- if (pixmap_) {
- XFreePixmap(g_osmesa_display, pixmap_);
- pixmap_ = 0;
- }
-
- // Recreate a pixmap to hold the frame.
- pixmap_ = XCreatePixmap(g_osmesa_display,
- window_,
- window_size.width(),
- window_size.height(),
- attributes.depth);
- if (!pixmap_) {
- LOG(ERROR) << "XCreatePixmap failed.";
- return false;
- }
-
- // Recreate a graphics context for the pixmap.
- pixmap_graphics_context_ = XCreateGC(g_osmesa_display, pixmap_, 0, NULL);
- if (!pixmap_graphics_context_) {
- LOG(ERROR) << "XCreateGC failed";
- return false;
- }
-
- return true;
-}
-
-GLSurface* GLSurface::CreateViewGLSurface(gfx::PluginWindowHandle window) {
- switch (GetGLImplementation()) {
- case kGLImplementationOSMesaGL: {
- scoped_ptr<NativeViewGLSurfaceOSMesa> surface(
- new NativeViewGLSurfaceOSMesa(window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationEGLGLES2: {
- scoped_ptr<NativeViewGLSurfaceEGL> surface(new NativeViewGLSurfaceEGL(
- window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationDesktopGL: {
- scoped_ptr<NativeViewGLSurfaceGLX> surface(new NativeViewGLSurfaceGLX(
- window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationMockGL:
- return new GLSurfaceStub;
- default:
- NOTREACHED();
- return NULL;
- }
-}
-
-GLSurface* GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) {
- switch (GetGLImplementation()) {
- case kGLImplementationOSMesaGL: {
- scoped_ptr<GLSurfaceOSMesa> surface(new GLSurfaceOSMesa());
- surface->Resize(size);
-
- return surface.release();
- }
- case kGLImplementationEGLGLES2: {
- scoped_ptr<PbufferGLSurfaceEGL> surface(new PbufferGLSurfaceEGL(size));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationDesktopGL: {
- scoped_ptr<PbufferGLSurfaceGLX> surface(new PbufferGLSurfaceGLX(size));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationMockGL:
- return new GLSurfaceStub;
- default:
- NOTREACHED();
- return NULL;
- }
-}
-
-} // namespace gfx
diff --git a/ui/gfx/gl/gl_surface_mac.cc b/ui/gfx/gl/gl_surface_mac.cc
deleted file mode 100644
index 2fe1f0e..0000000
--- a/ui/gfx/gl/gl_surface_mac.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/gfx/gl/gl_surface.h"
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "third_party/mesa/MesaLib/include/GL/osmesa.h"
-#include "ui/gfx/gl/gl_bindings.h"
-#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface_cgl.h"
-#include "ui/gfx/gl/gl_surface_osmesa.h"
-#include "ui/gfx/gl/gl_surface_stub.h"
-
-namespace gfx {
-
-bool GLSurface::InitializeOneOff() {
- static bool initialized = false;
- if (initialized)
- return true;
-
- static const GLImplementation kAllowedGLImplementations[] = {
- kGLImplementationDesktopGL,
- kGLImplementationOSMesaGL
- };
-
- if (!InitializeRequestedGLBindings(
- kAllowedGLImplementations,
- kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
- kGLImplementationDesktopGL)) {
- LOG(ERROR) << "InitializeRequestedGLBindings failed.";
- return false;
- }
-
- switch (GetGLImplementation()) {
- case kGLImplementationDesktopGL:
- if (!GLSurfaceCGL::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
- return false;
- }
- break;
- default:
- break;
- }
-
- initialized = true;
- return true;
-}
-
-// TODO(apatrick): support ViewGLSurface on mac.
-#if 0
-GLSurface* GLSurface::CreateViewGLSurface(gfx::PluginWindowHandle window) {
- switch (GetGLImplementation()) {
- case kGLImplementationOSMesaGL: {
- scoped_ptr<NativeViewGLSurfaceOSMesa> surface(
- new NativeViewGLSurfaceOSMesa(window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationDesktopGL: {
- scoped_ptr<NativeViewGLSurfaceCGL> surface(new NativeViewGLSurfaceCGL(
- window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationMockGL:
- return new GLSurfaceStub;
- default:
- NOTREACHED();
- return NULL;
- }
-}
-#endif
-
-GLSurface* GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) {
- switch (GetGLImplementation()) {
- case kGLImplementationOSMesaGL: {
- scoped_ptr<GLSurfaceOSMesa> surface(new GLSurfaceOSMesa());
- surface->Resize(size);
-
- return surface.release();
- }
- case kGLImplementationDesktopGL: {
- scoped_ptr<PbufferGLSurfaceCGL> surface(new PbufferGLSurfaceCGL(size));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationMockGL:
- return new GLSurfaceStub;
- default:
- NOTREACHED();
- return NULL;
- }
-}
-
-} // namespace gfx
diff --git a/ui/gfx/gl/gl_surface_stub.cc b/ui/gfx/gl/gl_surface_stub.cc
deleted file mode 100644
index bdea1bd..0000000
--- a/ui/gfx/gl/gl_surface_stub.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/gfx/gl/gl_surface_stub.h"
-
-namespace gfx {
-
-GLSurfaceStub::~GLSurfaceStub() {
-}
-
-void GLSurfaceStub::Destroy() {
-}
-
-bool GLSurfaceStub::IsOffscreen() {
- return false;
-}
-
-bool GLSurfaceStub::SwapBuffers() {
- return true;
-}
-
-gfx::Size GLSurfaceStub::GetSize() {
- return size_;
-}
-
-void* GLSurfaceStub::GetHandle() {
- return NULL;
-}
-
-} // namespace gfx
diff --git a/ui/gfx/gl/gl_surface_stub.h b/ui/gfx/gl/gl_surface_stub.h
deleted file mode 100644
index da494be..0000000
--- a/ui/gfx/gl/gl_surface_stub.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_GFX_GL_GL_SURFACE_STUB_H_
-#define UI_GFX_GL_GL_SURFACE_STUB_H_
-#pragma once
-
-#include "ui/gfx/gl/gl_surface.h"
-
-namespace gfx {
-
-// A GLSurface that does nothing for unit tests.
-class GLSurfaceStub : public GLSurface {
- public:
- virtual ~GLSurfaceStub();
-
- void SetSize(const gfx::Size& size) { size_ = size; }
-
- // Implement GLSurface.
- virtual void Destroy();
- virtual bool IsOffscreen();
- virtual bool SwapBuffers();
- virtual gfx::Size GetSize();
- virtual void* GetHandle();
-
- private:
- gfx::Size size_;
-};
-
-} // namespace gfx
-
-#endif // UI_GFX_GL_GL_SURFACE_STUB_H_
diff --git a/ui/gfx/gl/gl_surface_win.cc b/ui/gfx/gl/gl_surface_win.cc
deleted file mode 100644
index 4c0b15d..0000000
--- a/ui/gfx/gl/gl_surface_win.cc
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/gfx/gl/gl_surface.h"
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "third_party/mesa/MesaLib/include/GL/osmesa.h"
-#include "ui/gfx/gl/gl_bindings.h"
-#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface_egl.h"
-#include "ui/gfx/gl/gl_surface_osmesa.h"
-#include "ui/gfx/gl/gl_surface_stub.h"
-#include "ui/gfx/gl/gl_surface_wgl.h"
-
-namespace gfx {
-
-// This OSMesa GL surface can use GDI to swap the contents of the buffer to a
-// view.
-class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
- public:
- explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window);
- virtual ~NativeViewGLSurfaceOSMesa();
-
- // Initializes the GL context.
- bool Initialize();
-
- // Implement subset of GLSurface.
- virtual void Destroy();
- virtual bool IsOffscreen();
- virtual bool SwapBuffers();
-
- private:
- void UpdateSize();
-
- gfx::PluginWindowHandle window_;
- HDC device_context_;
-
- DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa);
-};
-
-// Helper routine that does one-off initialization like determining the
-// pixel format and initializing the GL bindings.
-bool GLSurface::InitializeOneOff() {
- static bool initialized = false;
- if (initialized)
- return true;
-
- static const GLImplementation kAllowedGLImplementations[] = {
- kGLImplementationEGLGLES2,
- kGLImplementationDesktopGL,
- kGLImplementationOSMesaGL
- };
-
- if (!InitializeRequestedGLBindings(
- kAllowedGLImplementations,
- kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
- kGLImplementationEGLGLES2)) {
- LOG(ERROR) << "InitializeRequestedGLBindings failed.";
- return false;
- }
-
- switch (GetGLImplementation()) {
- case kGLImplementationDesktopGL:
- if (!GLSurfaceWGL::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed.";
- return false;
- }
- break;
- case kGLImplementationEGLGLES2:
- if (!GLSurfaceEGL::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
- return false;
- }
- break;
- }
-
- initialized = true;
- return true;
-}
-
-NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
- gfx::PluginWindowHandle window)
- : window_(window),
- device_context_(NULL) {
- DCHECK(window);
-}
-
-NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() {
- Destroy();
-}
-
-bool NativeViewGLSurfaceOSMesa::Initialize() {
- device_context_ = GetDC(window_);
- UpdateSize();
- return true;
-}
-
-void NativeViewGLSurfaceOSMesa::Destroy() {
- if (window_ && device_context_)
- ReleaseDC(window_, device_context_);
-
- window_ = NULL;
- device_context_ = NULL;
-
- GLSurfaceOSMesa::Destroy();
-}
-
-bool NativeViewGLSurfaceOSMesa::IsOffscreen() {
- return false;
-}
-
-bool NativeViewGLSurfaceOSMesa::SwapBuffers() {
- DCHECK(device_context_);
-
- // Update the size before blitting so that the blit size is exactly the same
- // as the window.
- UpdateSize();
-
- gfx::Size size = GetSize();
-
- // Note: negating the height below causes GDI to treat the bitmap data as row
- // 0 being at the top.
- BITMAPV4HEADER info = { sizeof(BITMAPV4HEADER) };
- info.bV4Width = size.width();
- info.bV4Height = -size.height();
- info.bV4Planes = 1;
- info.bV4BitCount = 32;
- info.bV4V4Compression = BI_BITFIELDS;
- info.bV4RedMask = 0x000000FF;
- info.bV4GreenMask = 0x0000FF00;
- info.bV4BlueMask = 0x00FF0000;
- info.bV4AlphaMask = 0xFF000000;
-
- // Copy the back buffer to the window's device context. Do not check whether
- // StretchDIBits succeeds or not. It will fail if the window has been
- // destroyed but it is preferable to allow rendering to silently fail if the
- // window is destroyed. This is because the primary application of this
- // class of GLContext is for testing and we do not want every GL related ui /
- // browser test to become flaky if there is a race condition between GL
- // context destruction and window destruction.
- StretchDIBits(device_context_,
- 0, 0, size.width(), size.height(),
- 0, 0, size.width(), size.height(),
- GetHandle(),
- reinterpret_cast<BITMAPINFO*>(&info),
- DIB_RGB_COLORS,
- SRCCOPY);
-
- return true;
-}
-
-void NativeViewGLSurfaceOSMesa::UpdateSize() {
- // Change back buffer size to that of window. If window handle is invalid, do
- // not change the back buffer size.
- RECT rect;
- if (!GetClientRect(window_, &rect))
- return;
-
- gfx::Size window_size = gfx::Size(
- std::max(1, static_cast<int>(rect.right - rect.left)),
- std::max(1, static_cast<int>(rect.bottom - rect.top)));
- Resize(window_size);
-}
-
-GLSurface* GLSurface::CreateViewGLSurface(gfx::PluginWindowHandle window) {
- switch (GetGLImplementation()) {
- case kGLImplementationOSMesaGL: {
- scoped_ptr<NativeViewGLSurfaceOSMesa> surface(
- new NativeViewGLSurfaceOSMesa(window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationEGLGLES2: {
- scoped_ptr<NativeViewGLSurfaceEGL> surface(new NativeViewGLSurfaceEGL(
- window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationDesktopGL: {
- scoped_ptr<NativeViewGLSurfaceWGL> surface(new NativeViewGLSurfaceWGL(
- window));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationMockGL:
- return new GLSurfaceStub;
- default:
- NOTREACHED();
- return NULL;
- }
-}
-
-GLSurface* GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) {
- switch (GetGLImplementation()) {
- case kGLImplementationOSMesaGL: {
- scoped_ptr<GLSurfaceOSMesa> surface(new GLSurfaceOSMesa());
- surface->Resize(size);
-
- return surface.release();
- }
- case kGLImplementationEGLGLES2: {
- scoped_ptr<PbufferGLSurfaceEGL> surface(new PbufferGLSurfaceEGL(size));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationDesktopGL: {
- scoped_ptr<PbufferGLSurfaceWGL> surface(new PbufferGLSurfaceWGL(size));
- if (!surface->Initialize())
- return NULL;
-
- return surface.release();
- }
- case kGLImplementationMockGL:
- return new GLSurfaceStub;
- default:
- NOTREACHED();
- return NULL;
- }
-}
-
-} // namespace gfx
diff --git a/ui/gfx/surface/accelerated_surface_mac.cc b/ui/gfx/surface/accelerated_surface_mac.cc
index 2210a6f..43c6890 100644
--- a/ui/gfx/surface/accelerated_surface_mac.cc
+++ b/ui/gfx/surface/accelerated_surface_mac.cc
@@ -8,7 +8,6 @@
#include "base/mac/scoped_cftyperef.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/surface/io_surface_support_mac.h"
@@ -27,7 +26,7 @@ bool AcceleratedSurface::Initialize(gfx::GLContext* share_context,
allocate_fbo_ = allocate_fbo;
// Ensure GL is initialized before trying to create an offscreen GL context.
- if (!gfx::GLSurface::InitializeOneOff())
+ if (!gfx::GLContext::InitializeOneOff())
return false;
// Drawing to IOSurfaces via OpenGL only works with desktop GL and
@@ -35,19 +34,9 @@ bool AcceleratedSurface::Initialize(gfx::GLContext* share_context,
if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL)
return false;
- scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface(
- gfx::Size(1, 1)));
- if (!surface.get()) {
- Destroy();
- return false;
- }
-
- gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(),
- share_context));
- if (!gl_context_.get()) {
- Destroy();
+ gl_context_.reset(gfx::GLContext::CreateOffscreenGLContext(share_context));
+ if (!gl_context_.get())
return false;
- }
// Now we're ready to handle SetSurfaceSize calls, which will
// allocate and/or reallocate the IOSurface and associated offscreen