summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/common/sandbox_mac.mm4
-rw-r--r--content/gpu/gpu_child_thread.cc4
-rw-r--r--content/gpu/gpu_info_collector.cc31
-rw-r--r--gpu/command_buffer/client/gles2_demo.cc4
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc2
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h2
-rw-r--r--gpu/command_buffer/service/gpu_scheduler_linux.cc22
-rw-r--r--gpu/command_buffer/service/gpu_scheduler_mac.cc17
-rw-r--r--gpu/command_buffer/service/gpu_scheduler_win.cc26
-rw-r--r--gpu/demos/framework/main_exe.cc4
-rw-r--r--media/tools/shader_bench/shader_bench.cc8
-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
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc18
-rw-r--r--webkit/gpu/webgraphicscontext3d_in_process_impl.cc17
-rw-r--r--webkit/plugins/npapi/plugin_host.cc4
-rw-r--r--webkit/support/webkit_support.cc3
30 files changed, 644 insertions, 913 deletions
diff --git a/content/common/sandbox_mac.mm b/content/common/sandbox_mac.mm
index 59d4871..723a55a 100644
--- a/content/common/sandbox_mac.mm
+++ b/content/common/sandbox_mac.mm
@@ -28,7 +28,7 @@ extern "C" {
#include "content/common/chrome_application_mac.h"
#include "content/common/content_switches.h"
#include "unicode/uchar.h"
-#include "ui/gfx/gl/gl_surface.h"
+#include "ui/gfx/gl/gl_context.h"
namespace {
@@ -252,7 +252,7 @@ void Sandbox::SandboxWarmup(SandboxProcessType sandbox_type) {
{
// Preload either the desktop GL or the osmesa so, depending on the
// --use-gl flag.
- gfx::GLSurface::InitializeOneOff();
+ gfx::GLContext::InitializeOneOff();
}
break;
diff --git a/content/gpu/gpu_child_thread.cc b/content/gpu/gpu_child_thread.cc
index 8612a66..c9a5acd 100644
--- a/content/gpu/gpu_child_thread.cc
+++ b/content/gpu/gpu_child_thread.cc
@@ -18,8 +18,8 @@
#include "content/gpu/gpu_info_collector.h"
#include "content/gpu/gpu_watchdog_thread.h"
#include "ipc/ipc_channel_handle.h"
+#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
#if defined(OS_MACOSX)
#include "content/common/sandbox_init_wrapper.h"
@@ -121,7 +121,7 @@ void GpuChildThread::OnInitialize() {
// Load the GL implementation and locate the bindings before starting the GPU
// watchdog because this can take a lot of time and the GPU watchdog might
// terminate the GPU process.
- if (!gfx::GLSurface::InitializeOneOff()) {
+ if (!gfx::GLContext::InitializeOneOff()) {
LOG(INFO) << "GLContext::InitializeOneOff failed";
MessageLoop::current()->Quit();
return;
diff --git a/content/gpu/gpu_info_collector.cc b/content/gpu/gpu_info_collector.cc
index d3492fd..6b37c27 100644
--- a/content/gpu/gpu_info_collector.cc
+++ b/content/gpu/gpu_info_collector.cc
@@ -7,45 +7,34 @@
#include <string>
#include <vector>
-#include "base/memory/scoped_ptr.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/string_piece.h"
#include "base/string_split.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_context.h"
-#include "ui/gfx/gl/gl_surface.h"
namespace {
// This creates an offscreen GL context for gl queries. Returned GLContext
// should be deleted in FinalizeGLContext.
gfx::GLContext* InitializeGLContext() {
- if (!gfx::GLSurface::InitializeOneOff()) {
+ if (!gfx::GLContext::InitializeOneOff()) {
LOG(ERROR) << "gfx::GLContext::InitializeOneOff() failed";
return NULL;
}
- scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface(
- gfx::Size(1, 1)));
- if (!surface.get()) {
- LOG(ERROR) << "gfx::GLContext::CreateOffscreenGLSurface failed";
+ gfx::GLContext* context = gfx::GLContext::CreateOffscreenGLContext(NULL);
+ if (context == NULL) {
+ LOG(ERROR) << "gfx::GLContext::CreateOffscreenGLContext(NULL) failed";
return NULL;
}
-
- scoped_ptr<gfx::GLContext> context(gfx::GLContext::CreateGLContext(
- surface.release(),
- NULL));
- if (!context.get()) {
- LOG(ERROR) << "gfx::GLContext::CreateGLContext failed";
- return NULL;
- }
-
if (!context->MakeCurrent()) {
LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed";
+ context->Destroy();
+ delete context;
return NULL;
}
-
- return context.release();
+ return context;
}
// This destroy and delete the GL context.
@@ -91,8 +80,8 @@ namespace gpu_info_collector {
bool CollectGraphicsInfoGL(GPUInfo* gpu_info) {
DCHECK(gpu_info);
- scoped_ptr<gfx::GLContext> context(InitializeGLContext());
- if (!context.get())
+ gfx::GLContext* context = InitializeGLContext();
+ if (context == NULL)
return false;
gpu_info->gl_renderer = GetGLString(GL_RENDERER);
@@ -104,6 +93,8 @@ bool CollectGraphicsInfoGL(GPUInfo* gpu_info) {
bool validVideoCardInfo = CollectVideoCardInfo(gpu_info);
bool validDriverInfo = CollectDriverInfoGL(gpu_info);
+ FinalizeGLContext(&context);
+
return (validGLVersionInfo && validVideoCardInfo && validDriverInfo);
}
diff --git a/gpu/command_buffer/client/gles2_demo.cc b/gpu/command_buffer/client/gles2_demo.cc
index 78768dd..54a3b89 100644
--- a/gpu/command_buffer/client/gles2_demo.cc
+++ b/gpu/command_buffer/client/gles2_demo.cc
@@ -25,7 +25,7 @@
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/gles2_demo_c.h"
#include "gpu/command_buffer/client/gles2_demo_cc.h"
-#include "ui/gfx/gl/gl_surface.h"
+#include "ui/gfx/gl/gl_context.h"
using base::SharedMemory;
using gpu::Buffer;
@@ -212,7 +212,7 @@ int main(int argc, char** argv) {
base::AtExitManager at_exit_manager;
MessageLoopForUI message_loop;
- gfx::GLSurface::InitializeOneOff();
+ gfx::GLContext::InitializeOneOff();
GLES2Demo* demo = new GLES2Demo();
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
index 40cb373..f302aa3 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
@@ -126,7 +126,7 @@ void GLES2DecoderTestBase::InitDecoder(
shared_memory_id_ = kSharedMemoryId;
shared_memory_base_ = buffer.ptr;
- context_ = new gfx::GLContextStub;
+ context_ = new gfx::StubGLContext;
context_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
decoder_.reset(GLES2Decoder::Create(group_.get()));
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
index 72a5e71..2d027f7 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
@@ -255,7 +255,7 @@ class GLES2DecoderTestBase : public testing::Test {
// Use StrictMock to make 100% sure we know how GL will be called.
scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
- gfx::GLContextStub* context_;
+ gfx::StubGLContext* context_;
scoped_ptr<GLES2Decoder> decoder_;
GLuint client_buffer_id_;
diff --git a/gpu/command_buffer/service/gpu_scheduler_linux.cc b/gpu/command_buffer/service/gpu_scheduler_linux.cc
index 265c976..48ed470 100644
--- a/gpu/command_buffer/service/gpu_scheduler_linux.cc
+++ b/gpu/command_buffer/service/gpu_scheduler_linux.cc
@@ -4,7 +4,6 @@
#include "gpu/command_buffer/service/gpu_scheduler.h"
#include "ui/gfx/gl/gl_context.h"
-#include "ui/gfx/gl/gl_surface.h"
using ::base::SharedMemory;
@@ -30,28 +29,19 @@ bool GpuScheduler::Initialize(
DCHECK(parent_context);
}
- // Create either a view or pbuffer based GLSurface.
- scoped_ptr<gfx::GLSurface> surface;
+ // Create either a view or pbuffer based GLContext.
+ scoped_ptr<gfx::GLContext> context;
if (window) {
DCHECK(!parent_handle);
- surface.reset(gfx::GLSurface::CreateViewGLSurface(window));
+ // TODO(apatrick): support multisampling.
+ context.reset(gfx::GLContext::CreateViewGLContext(window, false));
} else {
- surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
+ context.reset(gfx::GLContext::CreateOffscreenGLContext(parent_context));
}
- if (!surface.get()) {
- LOG(ERROR) << "GpuScheduler::Initialize failed.\n";
- Destroy();
- return false;
- }
-
- // Create a GLContext and attach the surface.
- scoped_ptr<gfx::GLContext> context(
- gfx::GLContext::CreateGLContext(surface.release(), parent_context));
if (!context.get()) {
- LOG(ERROR) << "CreateGLContext failed.\n";
- Destroy();
+ LOG(ERROR) << "GpuScheduler::Initialize failed";
return false;
}
diff --git a/gpu/command_buffer/service/gpu_scheduler_mac.cc b/gpu/command_buffer/service/gpu_scheduler_mac.cc
index 717230c..f89bfb5 100644
--- a/gpu/command_buffer/service/gpu_scheduler_mac.cc
+++ b/gpu/command_buffer/service/gpu_scheduler_mac.cc
@@ -4,7 +4,6 @@
#include "gpu/command_buffer/service/gpu_scheduler.h"
#include "ui/gfx/gl/gl_context.h"
-#include "ui/gfx/gl/gl_surface.h"
using ::base::SharedMemory;
@@ -29,22 +28,10 @@ bool GpuScheduler::Initialize(
DCHECK(parent_context);
}
- scoped_ptr<gfx::GLSurface> surface(
- gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
- if (!surface.get()) {
- LOG(ERROR) << "CreateOffscreenGLSurface failed.\n";
- Destroy();
- return false;
- }
-
- // Create a GLContext and attach the surface.
scoped_ptr<gfx::GLContext> context(
- gfx::GLContext::CreateGLContext(surface.release(), parent_context));
- if (!context.get()) {
- LOG(ERROR) << "CreateGLContext failed.\n";
- Destroy();
+ gfx::GLContext::CreateOffscreenGLContext(parent_context));
+ if (!context.get())
return false;
- }
// On Mac OS X since we can not render on-screen we don't even
// attempt to create a view based GLContext. The only difference
diff --git a/gpu/command_buffer/service/gpu_scheduler_win.cc b/gpu/command_buffer/service/gpu_scheduler_win.cc
index 7a874a2..23c8782 100644
--- a/gpu/command_buffer/service/gpu_scheduler_win.cc
+++ b/gpu/command_buffer/service/gpu_scheduler_win.cc
@@ -6,7 +6,6 @@
#include "gpu/command_buffer/service/gpu_scheduler.h"
#include "ui/gfx/gl/gl_context.h"
-#include "ui/gfx/gl/gl_surface.h"
using ::base::SharedMemory;
@@ -31,28 +30,19 @@ bool GpuScheduler::Initialize(
DCHECK(parent_context);
}
- // Create either a view or pbuffer based GLSurface.
- scoped_ptr<gfx::GLSurface> surface;
+ // Create either a view or pbuffer based GLContext.
+ scoped_ptr<gfx::GLContext> context;
if (window) {
- surface.reset(gfx::GLSurface::CreateViewGLSurface(window));
- } else {
- surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
- }
+ DCHECK(!parent_context);
- if (!surface.get()) {
- LOG(ERROR) << "GpuScheduler::Initialize failed.\n";
- Destroy();
- return false;
+ // TODO(apatrick): support multisampling.
+ context.reset(gfx::GLContext::CreateViewGLContext(window, false));
+ } else {
+ context.reset(gfx::GLContext::CreateOffscreenGLContext(parent_context));
}
- // Create a GLContext and attach the surface.
- scoped_ptr<gfx::GLContext> context(
- gfx::GLContext::CreateGLContext(surface.release(), parent_context));
- if (!context.get()) {
- LOG(ERROR) << "CreateGLContext failed.\n";
- Destroy();
+ if (!context.get())
return false;
- }
return InitializeCommon(context.release(),
size,
diff --git a/gpu/demos/framework/main_exe.cc b/gpu/demos/framework/main_exe.cc
index 0c54804..93fc51e 100644
--- a/gpu/demos/framework/main_exe.cc
+++ b/gpu/demos/framework/main_exe.cc
@@ -6,7 +6,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "gpu/demos/framework/window.h"
-#include "ui/gfx/gl/gl_surface.h"
+#include "ui/gfx/gl/gl_context.h"
#if defined(OS_LINUX)
#include <gtk/gtk.h>
@@ -28,7 +28,7 @@ int main(int argc, char** argv) {
CommandLine::Init(argc, argv);
- gfx::GLSurface::InitializeOneOff();
+ gfx::GLContext::InitializeOneOff();
gpu::demos::Window window;
CHECK(window.Init(kWindowWidth, kWindowHeight));
diff --git a/media/tools/shader_bench/shader_bench.cc b/media/tools/shader_bench/shader_bench.cc
index 077bfd2..557d18d 100644
--- a/media/tools/shader_bench/shader_bench.cc
+++ b/media/tools/shader_bench/shader_bench.cc
@@ -22,7 +22,6 @@
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
#include "ui/gfx/native_widget_types.h"
#if defined(OS_LINUX)
@@ -131,11 +130,10 @@ int main(int argc, char** argv) {
// Initialize window and graphics context.
base::AtExitManager at_exit_manager;
- gfx::GLSurface::InitializeOneOff();
+ gfx::GLContext::InitializeOneOff();
scoped_ptr<media::Window> window(new media::Window(width, height));
- gfx::GLSurface* surface =
- gfx::GLSurface::CreateViewGLSurface(window->PluginWindow());
- gfx::GLContext* context = gfx::GLContext::CreateGLContext(surface, NULL);
+ gfx::GLContext* context =
+ gfx::GLContext::CreateViewGLContext(window->PluginWindow(), false);
context->MakeCurrent();
// This sets D3DPRESENT_INTERVAL_IMMEDIATE on Windows.
context->SetSwapInterval(0);
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
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc
index 7b43d63..2ee71e8 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc
+++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc
@@ -17,7 +17,6 @@
#include "ui/gfx/gl/gl_bindings_skia_in_process.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
namespace webkit {
namespace gpu {
@@ -103,7 +102,7 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize(
WebGraphicsContext3D::Attributes attributes,
WebView* webView,
bool render_directly_to_web_view) {
- if (!gfx::GLSurface::InitializeOneOff())
+ if (!gfx::GLContext::InitializeOneOff())
return false;
gfx::BindSkiaToInProcessGL();
@@ -133,13 +132,7 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize(
// and from there to the window, and WebViewImpl::paint already
// correctly handles the case where the compositor is active but
// the output needs to go to a WebCanvas.
- scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface(
- gfx::Size(1, 1)));
- if (!surface->Initialize())
- return false;
-
- gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(),
- share_context));
+ gl_context_.reset(gfx::GLContext::CreateOffscreenGLContext(share_context));
if (!gl_context_.get()) {
if (!is_gles2_)
return false;
@@ -152,12 +145,7 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize(
// and force them to drop their contexts, sending a context lost event if
// necessary.
webView->mainFrame()->collectGarbage();
-
- surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
-
- gl_context_.reset(gfx::GLContext::CreateGLContext(
- surface.release(),
- share_context));
+ gl_context_.reset(gfx::GLContext::CreateOffscreenGLContext(share_context));
if (!gl_context_.get())
return false;
}
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
index 08d93ca..2fb703a 100644
--- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
+++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc
@@ -17,7 +17,6 @@
#include "ui/gfx/gl/gl_bindings_skia_in_process.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
namespace webkit {
namespace gpu {
@@ -103,7 +102,7 @@ bool WebGraphicsContext3DInProcessImpl::initialize(
WebGraphicsContext3D::Attributes attributes,
WebView* webView,
bool render_directly_to_web_view) {
- if (!gfx::GLSurface::InitializeOneOff())
+ if (!gfx::GLContext::InitializeOneOff())
return false;
gfx::BindSkiaToInProcessGL();
@@ -133,9 +132,8 @@ bool WebGraphicsContext3DInProcessImpl::initialize(
// and from there to the window, and WebViewImpl::paint already
// correctly handles the case where the compositor is active but
// the output needs to go to a WebCanvas.
- scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface(
- gfx::Size(1, 1)));
- if (!surface.get()) {
+ gl_context_.reset(gfx::GLContext::CreateOffscreenGLContext(share_context));
+ if (!gl_context_.get()) {
if (!is_gles2_)
return false;
@@ -147,16 +145,11 @@ bool WebGraphicsContext3DInProcessImpl::initialize(
// and force them to drop their contexts, sending a context lost event if
// necessary.
webView->mainFrame()->collectGarbage();
- surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
- if (!surface.get())
+ gl_context_.reset(gfx::GLContext::CreateOffscreenGLContext(share_context));
+ if (!gl_context_.get())
return false;
}
- gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(),
- share_context));
- if (!gl_context_.get())
- return false;
-
attributes_ = attributes;
// FIXME: for the moment we disable multisampling for the compositor.
diff --git a/webkit/plugins/npapi/plugin_host.cc b/webkit/plugins/npapi/plugin_host.cc
index e92c22e..b6021d46 100644
--- a/webkit/plugins/npapi/plugin_host.cc
+++ b/webkit/plugins/npapi/plugin_host.cc
@@ -17,8 +17,8 @@
#include "third_party/npapi/bindings/npruntime.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
+#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/plugins/npapi/default_plugin_shared.h"
#include "webkit/plugins/npapi/npapi_extension_thunk.h"
@@ -62,7 +62,7 @@ static bool SupportsSharingAcceleratedSurfaces() {
gfx::GLImplementation implementation = gfx::GetGLImplementation();
if (implementation == gfx::kGLImplementationNone) {
// Not initialized yet.
- if (!gfx::GLSurface::InitializeOneOff()) {
+ if (!gfx::GLContext::InitializeOneOff()) {
return false;
}
implementation = gfx::GetGLImplementation();
diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc
index 8210aaa..520b988 100644
--- a/webkit/support/webkit_support.cc
+++ b/webkit/support/webkit_support.cc
@@ -36,7 +36,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
#include "webkit/appcache/web_application_cache_host_impl.h"
#include "webkit/glue/media/video_renderer_impl.h"
#include "webkit/glue/webkit_constants.h"
@@ -324,7 +323,7 @@ WebKit::WebString GetWebKitRootDir() {
void SetUpGLBindings(GLBindingPreferences bindingPref) {
switch(bindingPref) {
case GL_BINDING_DEFAULT:
- gfx::GLSurface::InitializeOneOff();
+ gfx::GLContext::InitializeOneOff();
break;
case GL_BINDING_SOFTWARE_RENDERER:
gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL);