diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 20:34:15 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 20:34:15 +0000 |
commit | f62a5abd6205c7a84a19f8b00b45b0792b767f57 (patch) | |
tree | 100e751f4e0302bbb4ecde919fb1cea272aeb7cf /gpu/command_buffer | |
parent | 97807cbf58afe1e25b2bd014ce758e88e483d08b (diff) | |
download | chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.zip chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.tar.gz chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.tar.bz2 |
GLContext no longer holds a pointer to a GLSurface.
This is part of an ongoing effort to treat GL contexts and GL surfaces as independent entities.
TEST=run WebGL on mac, windows and linux, trybots
BUG=none
Review URL: http://codereview.chromium.org/7021014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86332 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer')
11 files changed, 65 insertions, 27 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 70e0847..25b6696 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -38,6 +38,7 @@ #include "gpu/GLES2/gles2_command_buffer.h" #include "ui/gfx/gl/gl_context.h" #include "ui/gfx/gl/gl_implementation.h" +#include "ui/gfx/gl/gl_surface.h" #if !defined(GL_DEPTH24_STENCIL8) #define GL_DEPTH24_STENCIL8 0x88F0 @@ -671,7 +672,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, virtual const char* GetCommandName(unsigned int command_id) const; // Overridden from GLES2Decoder. - virtual bool Initialize(gfx::GLContext* context, + virtual bool Initialize(gfx::GLSurface* surface, + gfx::GLContext* context, const gfx::Size& size, const DisallowedExtensions& disallowed_extensions, const char* allowed_extensions, @@ -684,6 +686,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, virtual bool MakeCurrent(); virtual GLES2Util* GetGLES2Util() { return &util_; } virtual gfx::GLContext* GetGLContext() { return context_.get(); } + virtual gfx::GLSurface* GetGLSurface() { return surface_.get(); } virtual ContextGroup* GetContextGroup() { return group_.get(); } virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback); @@ -1337,6 +1340,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, #undef GLES2_CMD_OP // The GL context this decoder renders to on behalf of the client. + scoped_ptr<gfx::GLSurface> surface_; scoped_ptr<gfx::GLContext> context_; // The ContextGroup for this decoder uses to track resources. @@ -1827,6 +1831,7 @@ GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) } bool GLES2DecoderImpl::Initialize( + gfx::GLSurface* surface, gfx::GLContext* context, const gfx::Size& size, const DisallowedExtensions& disallowed_extensions, @@ -1837,6 +1842,11 @@ bool GLES2DecoderImpl::Initialize( DCHECK(context); DCHECK(!context_.get()); + // Take ownership of the GLSurface. TODO(apatrick): the decoder should not + // own the surface. It should be possible to freely switch the surface the + // context renders to. + surface_.reset(surface); + // Take ownership of the GLContext. context_.reset(context); @@ -1895,7 +1905,7 @@ bool GLES2DecoderImpl::Initialize( glActiveTexture(GL_TEXTURE0); CHECK_GL_ERROR(); - if (context_->IsOffscreen()) { + if (surface_->IsOffscreen()) { ContextCreationAttribParser attrib_parser; if (!attrib_parser.Parse(attribs)) return false; @@ -2203,7 +2213,7 @@ void GLES2DecoderImpl::DeleteTexturesHelper( // } // anonymous namespace bool GLES2DecoderImpl::MakeCurrent() { - return context_.get() ? context_->MakeCurrent() : false; + return context_.get() ? context_->MakeCurrent(surface_.get()) : false; } void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { @@ -2274,7 +2284,7 @@ gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { } else if (offscreen_target_frame_buffer_.get()) { return offscreen_size_; } else { - return context_->GetSize(); + return surface_->GetSize(); } } @@ -2768,7 +2778,7 @@ void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { } info->MarkAsValid(); } else { - service_id = context_->GetBackingFrameBufferObject(); + service_id = 0; } if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { @@ -6384,7 +6394,7 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers( } } else { TRACE_EVENT1("gpu", "GLContext::SwapBuffers", "frame", this_frame_number); - if (!context_->SwapBuffers()) { + if (!surface_->SwapBuffers()) { LOG(ERROR) << "Context lost because SwapBuffers failed."; return error::kLostContext; } diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h index edc5637..7236cc0 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder.h @@ -17,6 +17,7 @@ namespace gfx { class GLContext; +class GLSurface; } namespace gpu { @@ -55,6 +56,7 @@ class GLES2Decoder : public CommonDecoder { // decoder with a frame buffer that can be referenced from the parent. // Takes ownership of GLContext. // Parameters: + // surface: the GL surface to render to. // context: the GL context to render to. // size: the size if the GL context is offscreen. // allowed_extensions: A string in the same format as @@ -66,7 +68,8 @@ class GLES2Decoder : public CommonDecoder { // parent's namespace. // Returns: // true if successful. - virtual bool Initialize(gfx::GLContext* context, + virtual bool Initialize(gfx::GLSurface* surface, + gfx::GLContext* context, const gfx::Size& size, const DisallowedExtensions& disallowed_extensions, const char* allowed_extensions, @@ -91,6 +94,9 @@ class GLES2Decoder : public CommonDecoder { // Gets the GLES2 Util which holds info. virtual GLES2Util* GetGLES2Util() = 0; + // Gets the associated GLSurface. + virtual gfx::GLSurface* GetGLSurface() = 0; + // Gets the associated GLContext. virtual gfx::GLContext* GetGLContext() = 0; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h index 3ab6f06..425fdce 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_mock.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder_mock.h @@ -14,8 +14,12 @@ #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/size.h" -namespace gpu { +namespace gfx { class GLContext; +class GLSurface; +} + +namespace gpu { namespace gles2 { @@ -25,8 +29,9 @@ class MockGLES2Decoder : public GLES2Decoder { MockGLES2Decoder(); virtual ~MockGLES2Decoder(); - MOCK_METHOD7(Initialize, - bool(gfx::GLContext* context, + MOCK_METHOD8(Initialize, + bool(gfx::GLSurface* surface, + gfx::GLContext* context, const gfx::Size& size, const DisallowedExtensions& disallowed_extensions, const char* allowed_extensions, @@ -39,6 +44,7 @@ class MockGLES2Decoder : public GLES2Decoder { MOCK_METHOD0(MakeCurrent, bool()); MOCK_METHOD1(GetServiceIdForTesting, uint32(uint32 client_id)); MOCK_METHOD0(GetGLES2Util, GLES2Util*()); + MOCK_METHOD0(GetGLSurface, gfx::GLSurface*()); MOCK_METHOD0(GetGLContext, gfx::GLContext*()); MOCK_METHOD0(GetContextGroup, ContextGroup*()); MOCK_METHOD1(SetResizeCallback, void(Callback1<gfx::Size>::Type*)); diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc index 49968a3..298640a 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc @@ -1645,7 +1645,7 @@ TEST_F(GLES2DecoderTest, ReadPixels) { 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, 37, 32, 34, }; - context_->SetSize(gfx::Size(INT_MAX, INT_MAX)); + surface_->SetSize(gfx::Size(INT_MAX, INT_MAX)); ReadPixelsEmulator emu( kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment); @@ -1691,7 +1691,7 @@ TEST_F(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) { 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, }; - context_->SetSize(gfx::Size(INT_MAX, INT_MAX)); + surface_->SetSize(gfx::Size(INT_MAX, INT_MAX)); ReadPixelsEmulator emu( kWidth, kHeight, kBytesPerPixel, kSrcPixels, kExpectedPixels, 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..a38ab8b 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc @@ -33,7 +33,9 @@ namespace gpu { namespace gles2 { GLES2DecoderTestBase::GLES2DecoderTestBase() - : client_buffer_id_(100), + : surface_(NULL), + context_(NULL), + client_buffer_id_(100), client_framebuffer_id_(101), client_program_id_(102), client_renderbuffer_id_(103), @@ -126,12 +128,14 @@ void GLES2DecoderTestBase::InitDecoder( shared_memory_id_ = kSharedMemoryId; shared_memory_base_ = buffer.ptr; + surface_ = new gfx::GLSurfaceStub; + surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); + context_ = new gfx::GLContextStub; - context_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); decoder_.reset(GLES2Decoder::Create(group_.get())); decoder_->Initialize( - context_, context_->GetSize(), DisallowedExtensions(), + surface_, context_, surface_->GetSize(), DisallowedExtensions(), NULL, std::vector<int32>(), NULL, 0); decoder_->set_engine(engine_.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..dc195c8 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h @@ -20,6 +20,7 @@ #include "gpu/GLES2/gles2_command_buffer.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/gl/gl_context_stub.h" +#include "ui/gfx/gl/gl_surface_stub.h" namespace gpu { namespace gles2 { @@ -255,6 +256,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::GLSurfaceStub* surface_; gfx::GLContextStub* context_; scoped_ptr<GLES2Decoder> decoder_; diff --git a/gpu/command_buffer/service/gpu_scheduler.cc b/gpu/command_buffer/service/gpu_scheduler.cc index 54579389a..d8a047c 100644 --- a/gpu/command_buffer/service/gpu_scheduler.cc +++ b/gpu/command_buffer/service/gpu_scheduler.cc @@ -10,6 +10,7 @@ #include "base/message_loop.h" #include "ui/gfx/gl/gl_context.h" #include "ui/gfx/gl/gl_bindings.h" +#include "ui/gfx/gl/gl_surface.h" using ::base::SharedMemory; @@ -52,6 +53,7 @@ GpuScheduler::~GpuScheduler() { } bool GpuScheduler::InitializeCommon( + gfx::GLSurface* surface, gfx::GLContext* context, const gfx::Size& size, const gles2::DisallowedExtensions& disallowed_extensions, @@ -61,12 +63,12 @@ bool GpuScheduler::InitializeCommon( uint32 parent_texture_id) { DCHECK(context); - if (!context->MakeCurrent()) + if (!context->MakeCurrent(surface)) return false; // Do not limit to a certain number of commands before scheduling another // update when rendering onscreen. - if (!context->IsOffscreen()) + if (!surface->IsOffscreen()) commands_per_update_ = INT_MAX; // Map the ring buffer and create the parser. @@ -84,7 +86,10 @@ bool GpuScheduler::InitializeCommon( } // Initialize the decoder with either the view or pbuffer GLContext. - if (!decoder_->Initialize(context, + // TODO(apatrick): The GpuScheduler should know nothing about the surface the + // decoder is rendering to. Get rid of the surface parameter. + if (!decoder_->Initialize(surface, + context, size, disallowed_extensions, allowed_extensions, diff --git a/gpu/command_buffer/service/gpu_scheduler.h b/gpu/command_buffer/service/gpu_scheduler.h index 2e0a699..ebbcc88 100644 --- a/gpu/command_buffer/service/gpu_scheduler.h +++ b/gpu/command_buffer/service/gpu_scheduler.h @@ -27,6 +27,7 @@ namespace gfx { class GLContext; +class GLSurface; } namespace gpu { @@ -136,8 +137,9 @@ class GpuScheduler : public CommandBufferEngine { gles2::GLES2Decoder* decoder() const { return decoder_.get(); } protected: - // Perform common initialization. Takes ownership of GLContext. + // Perform common initialization. Takes ownership of GLSurface and GLContext. bool InitializeCommon( + gfx::GLSurface* surface, gfx::GLContext* context, const gfx::Size& size, const gles2::DisallowedExtensions& disallowed_extensions, diff --git a/gpu/command_buffer/service/gpu_scheduler_linux.cc b/gpu/command_buffer/service/gpu_scheduler_linux.cc index 265c976..3ed89e4 100644 --- a/gpu/command_buffer/service/gpu_scheduler_linux.cc +++ b/gpu/command_buffer/service/gpu_scheduler_linux.cc @@ -48,14 +48,15 @@ bool GpuScheduler::Initialize( // Create a GLContext and attach the surface. scoped_ptr<gfx::GLContext> context( - gfx::GLContext::CreateGLContext(surface.release(), parent_context)); + gfx::GLContext::CreateGLContext(parent_context, surface.get())); if (!context.get()) { LOG(ERROR) << "CreateGLContext failed.\n"; Destroy(); return false; } - return InitializeCommon(context.release(), + return InitializeCommon(surface.release(), + context.release(), size, disallowed_extensions, allowed_extensions, diff --git a/gpu/command_buffer/service/gpu_scheduler_mac.cc b/gpu/command_buffer/service/gpu_scheduler_mac.cc index 53d4851..1e323ec 100644 --- a/gpu/command_buffer/service/gpu_scheduler_mac.cc +++ b/gpu/command_buffer/service/gpu_scheduler_mac.cc @@ -39,7 +39,7 @@ bool GpuScheduler::Initialize( // Create a GLContext and attach the surface. scoped_ptr<gfx::GLContext> context( - gfx::GLContext::CreateGLContext(surface.release(), parent_context)); + gfx::GLContext::CreateGLContext(parent_context, surface.get())); if (!context.get()) { LOG(ERROR) << "CreateGLContext failed.\n"; Destroy(); @@ -66,7 +66,8 @@ bool GpuScheduler::Initialize( } } - return InitializeCommon(context.release(), + return InitializeCommon(surface.release(), + context.release(), size, disallowed_extensions, allowed_extensions, @@ -87,7 +88,7 @@ void GpuScheduler::Destroy() { uint64 GpuScheduler::SetWindowSizeForIOSurface(const gfx::Size& size) { // This is called from an IPC handler, so it's undefined which context is // current. Make sure the right one is. - decoder_->GetGLContext()->MakeCurrent(); + decoder_->GetGLContext()->MakeCurrent(decoder_->GetGLSurface()); ResizeOffscreenFrameBuffer(size); decoder_->UpdateOffscreenFrameBufferSize(); @@ -143,7 +144,7 @@ void GpuScheduler::DidDestroySurface() { void GpuScheduler::WillSwapBuffers() { DCHECK(decoder_.get()); DCHECK(decoder_->GetGLContext()); - DCHECK(decoder_->GetGLContext()->IsCurrent()); + DCHECK(decoder_->GetGLContext()->IsCurrent(decoder_->GetGLSurface())); ++swap_buffers_count_; diff --git a/gpu/command_buffer/service/gpu_scheduler_win.cc b/gpu/command_buffer/service/gpu_scheduler_win.cc index 7a874a2..a6dcc73 100644 --- a/gpu/command_buffer/service/gpu_scheduler_win.cc +++ b/gpu/command_buffer/service/gpu_scheduler_win.cc @@ -47,14 +47,15 @@ bool GpuScheduler::Initialize( // Create a GLContext and attach the surface. scoped_ptr<gfx::GLContext> context( - gfx::GLContext::CreateGLContext(surface.release(), parent_context)); + gfx::GLContext::CreateGLContext(parent_context, surface.get())); if (!context.get()) { LOG(ERROR) << "CreateGLContext failed.\n"; Destroy(); return false; } - return InitializeCommon(context.release(), + return InitializeCommon(surface.release(), + context.release(), size, disallowed_extensions, allowed_extensions, |