Skip to content

Commit

Permalink
Revert "Reland 85013 - Split GLContext::Create*GLContext into GLSurfa…
Browse files Browse the repository at this point in the history
…ce::Create*GLSurface plus a

surface type independent GLContext::CreateGLContext".


git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85124 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
antonm@chromium.org committed May 12, 2011
1 parent cc12116 commit 82642bb
Show file tree
Hide file tree
Showing 33 changed files with 655 additions and 932 deletions.
4 changes: 2 additions & 2 deletions content/common/sandbox_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#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 {

Expand Down Expand Up @@ -252,7 +252,7 @@ bool EscapeSingleChar(char c, std::string* dst) {
{
// Preload either the desktop GL or the osmesa so, depending on the
// --use-gl flag.
gfx::GLSurface::InitializeOneOff();
gfx::GLContext::InitializeOneOff();
}
break;

Expand Down
4 changes: 2 additions & 2 deletions content/gpu/gpu_child_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
39 changes: 20 additions & 19 deletions content/gpu/gpu_info_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,44 @@
#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;
}

return context.release();
// This destroy and delete the GL context.
void FinalizeGLContext(gfx::GLContext** context) {
DCHECK(context);
if (*context) {
(*context)->Destroy();
delete *context;
*context = NULL;
}
}

std::string GetGLString(unsigned int pname) {
Expand Down Expand Up @@ -81,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);
Expand All @@ -94,6 +93,8 @@ bool CollectGraphicsInfoGL(GPUInfo* gpu_info) {
bool validVideoCardInfo = CollectVideoCardInfo(gpu_info);
bool validDriverInfo = CollectDriverInfoGL(gpu_info);

FinalizeGLContext(&context);

return (validGLVersionInfo && validVideoCardInfo && validDriverInfo);
}

Expand Down
4 changes: 2 additions & 2 deletions gpu/command_buffer/client/gles2_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
22 changes: 6 additions & 16 deletions gpu/command_buffer/service/gpu_scheduler_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
17 changes: 2 additions & 15 deletions gpu/command_buffer/service/gpu_scheduler_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
26 changes: 8 additions & 18 deletions gpu/command_buffer/service/gpu_scheduler_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions gpu/demos/framework/main_exe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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));
Expand Down
8 changes: 3 additions & 5 deletions media/tools/shader_bench/shader_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions ui/gfx/compositor/compositor_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/transform.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface.h"

namespace ui {

Expand All @@ -39,10 +38,8 @@ class CompositorGL : public Compositor {
};

CompositorGL::CompositorGL(gfx::AcceleratedWidget widget)
: started_(false) {
scoped_ptr<gfx::GLSurface> surface(
gfx::GLSurface::CreateViewGLSurface(widget));
gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), NULL)),
: gl_context_(gfx::GLContext::CreateViewGLContext(widget, false)),
started_(false) {
}

Texture* CompositorGL::CreateTexture() {
Expand Down Expand Up @@ -92,10 +89,8 @@ class CompositorGL : public Compositor {
};

CompositorGL::CompositorGL(gfx::AcceleratedWidget widget)
: started_(false) {
scoped_ptr<gfx::GLSurface> surface(
gfx::GLSurface::CreateViewGLSurface(widget));
gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), NULL));
: gl_context_(gfx::GLContext::CreateViewGLContext(widget, false)),
started_(false) {
}

void CompositorGL::NotifyStart() {
Expand Down
5 changes: 0 additions & 5 deletions ui/gfx/gl/gl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 13 additions & 8 deletions ui/gfx/gl/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading

0 comments on commit 82642bb

Please sign in to comment.