diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-06 20:36:07 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-06 20:36:07 +0000 |
commit | 69cd41f227734e0d4bbb11aa1f78add9733ba30d (patch) | |
tree | b0cf52a5e16a05188c4854314c1e38e44b3c64b3 /chrome | |
parent | 1ec686313f0230d1de89cd8e6c48198ccf409260 (diff) | |
download | chromium_src-69cd41f227734e0d4bbb11aa1f78add9733ba30d.zip chromium_src-69cd41f227734e0d4bbb11aa1f78add9733ba30d.tar.gz chromium_src-69cd41f227734e0d4bbb11aa1f78add9733ba30d.tar.bz2 |
SwapBuffers notification is sent from GPU process to renderer process.
Once the notification has been received, it is safe to bind an offscreen "front buffer" in its parent context. Binding before the notification is received might result in getting the previous frame.
TEST=try, WebGL
BUG=none
Review URL: http://codereview.chromium.org/3083017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/gpu_messages_internal.h | 7 | ||||
-rw-r--r-- | chrome/gpu/gpu_command_buffer_stub.cc | 6 | ||||
-rw-r--r-- | chrome/gpu/gpu_command_buffer_stub.h | 2 | ||||
-rw-r--r-- | chrome/renderer/command_buffer_proxy.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/command_buffer_proxy.h | 8 | ||||
-rw-r--r-- | chrome/renderer/ggl/ggl.cc | 22 | ||||
-rw-r--r-- | chrome/renderer/ggl/ggl.h | 6 |
7 files changed, 59 insertions, 2 deletions
diff --git a/chrome/common/gpu_messages_internal.h b/chrome/common/gpu_messages_internal.h index ac669aa..b17135b 100644 --- a/chrome/common/gpu_messages_internal.h +++ b/chrome/common/gpu_messages_internal.h @@ -159,8 +159,8 @@ IPC_END_MESSAGES(GpuChannel) //------------------------------------------------------------------------------ // GPU Command Buffer Messages -// These are messages from a renderer process to the GPU process relating to a -// single OpenGL context. +// These are messages between a renderer process to the GPU process relating to +// a single OpenGL context. IPC_BEGIN_MESSAGES(GpuCommandBuffer) // Initialize a command buffer with the given number of command entries. // Returns the shared memory handle for the command buffer mapped to the @@ -195,6 +195,9 @@ IPC_BEGIN_MESSAGES(GpuCommandBuffer) IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_UpdateState, gpu::CommandBuffer::State /* state */) + // Indicates that a SwapBuffers call has been issued. + IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_SwapBuffers) + // Create a shared memory transfer buffer. Returns an id that can be used to // identify the transfer buffer from a comment. IPC_SYNC_MESSAGE_ROUTED1_1(GpuCommandBufferMsg_CreateTransferBuffer, diff --git a/chrome/gpu/gpu_command_buffer_stub.cc b/chrome/gpu/gpu_command_buffer_stub.cc index 3ed834f..9445074 100644 --- a/chrome/gpu/gpu_command_buffer_stub.cc +++ b/chrome/gpu/gpu_command_buffer_stub.cc @@ -89,6 +89,8 @@ void GpuCommandBufferStub::OnInitialize( command_buffer_->SetPutOffsetChangeCallback( NewCallback(processor_.get(), &gpu::GPUProcessor::ProcessCommands)); + processor_->SetSwapBuffersCallback( + NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); // Assume service is responsible for duplicating the handle from the // calling process. @@ -161,6 +163,10 @@ void GpuCommandBufferStub::OnResizeOffscreenFrameBuffer(const gfx::Size& size) { processor_->ResizeOffscreenFrameBuffer(size); } +void GpuCommandBufferStub::OnSwapBuffers() { + Send(new GpuCommandBufferMsg_SwapBuffers(route_id_)); +} + #if defined(OS_MACOSX) void GpuCommandBufferStub::OnSetWindowSize(const gfx::Size& size) { ChildThread* gpu_thread = ChildThread::current(); diff --git a/chrome/gpu/gpu_command_buffer_stub.h b/chrome/gpu/gpu_command_buffer_stub.h index 621c8de..f0e1461 100644 --- a/chrome/gpu/gpu_command_buffer_stub.h +++ b/chrome/gpu/gpu_command_buffer_stub.h @@ -57,6 +57,8 @@ class GpuCommandBufferStub uint32* size); void OnResizeOffscreenFrameBuffer(const gfx::Size& size); + void OnSwapBuffers(); + #if defined(OS_MACOSX) void OnSetWindowSize(const gfx::Size& size); void SwapBuffersCallback(); diff --git a/chrome/renderer/command_buffer_proxy.cc b/chrome/renderer/command_buffer_proxy.cc index f561be9..00138a6 100644 --- a/chrome/renderer/command_buffer_proxy.cc +++ b/chrome/renderer/command_buffer_proxy.cc @@ -34,6 +34,7 @@ CommandBufferProxy::~CommandBufferProxy() { void CommandBufferProxy::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(CommandBufferProxy, message) IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateState, OnUpdateState); + IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffers, OnSwapBuffers); IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_NotifyRepaint, OnNotifyRepaint); IPC_MESSAGE_UNHANDLED_ERROR() @@ -183,6 +184,15 @@ void CommandBufferProxy::SetParseError( NOTREACHED(); } +void CommandBufferProxy::OnSwapBuffers() { + if (swap_buffers_callback_.get()) + swap_buffers_callback_->Run(); +} + +void CommandBufferProxy::SetSwapBuffersCallback(Callback0::Type* callback) { + swap_buffers_callback_.reset(callback); +} + void CommandBufferProxy::ResizeOffscreenFrameBuffer(const gfx::Size& size) { IPC::Message* message = new GpuCommandBufferMsg_ResizeOffscreenFrameBuffer(route_id_, size); diff --git a/chrome/renderer/command_buffer_proxy.h b/chrome/renderer/command_buffer_proxy.h index 9d0fcb2..39421c7 100644 --- a/chrome/renderer/command_buffer_proxy.h +++ b/chrome/renderer/command_buffer_proxy.h @@ -11,6 +11,7 @@ #include <map> #include <queue> +#include "base/callback.h" #include "base/linked_ptr.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" @@ -52,6 +53,11 @@ class CommandBufferProxy : public gpu::CommandBuffer, virtual gpu::Buffer GetTransferBuffer(int32 handle); virtual void SetToken(int32 token); virtual void SetParseError(gpu::error::Error error); + virtual void OnSwapBuffers(); + + // Set a callback that will be invoked when the SwapBuffers call has been + // issued. + void SetSwapBuffersCallback(Callback0::Type* callback); // Asynchronously resizes an offscreen frame buffer. void ResizeOffscreenFrameBuffer(const gfx::Size& size); @@ -104,6 +110,8 @@ class CommandBufferProxy : public gpu::CommandBuffer, scoped_ptr<Task> notify_repaint_task_; + scoped_ptr<Callback0::Type> swap_buffers_callback_; + DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy); }; diff --git a/chrome/renderer/ggl/ggl.cc b/chrome/renderer/ggl/ggl.cc index 011b5f5..834a1ae 100644 --- a/chrome/renderer/ggl/ggl.cc +++ b/chrome/renderer/ggl/ggl.cc @@ -71,6 +71,12 @@ class Context : public base::SupportsWeakPtr<Context> { // Asynchronously resizes an offscreen frame buffer. void ResizeOffscreen(const gfx::Size& size); + // Provides a callback that will be invoked when SwapBuffers has completed + // service side. + void SetSwapBuffersCallback(Callback1<Context*>::Type* callback) { + swap_buffers_callback_.reset(callback); + } + // For an offscreen frame buffer context, return the frame buffer ID with // respect to the parent. uint32 parent_texture_id() const { @@ -95,8 +101,11 @@ class Context : public base::SupportsWeakPtr<Context> { void DisableShaderTranslation(); private: + void OnSwapBuffers(); + scoped_refptr<GpuChannelHost> channel_; base::WeakPtr<Context> parent_; + scoped_ptr<Callback1<Context*>::Type> swap_buffers_callback_; uint32 parent_texture_id_; CommandBufferProxy* command_buffer_; gpu::gles2::GLES2CmdHelper* gles2_helper_; @@ -164,6 +173,9 @@ bool Context::Initialize(gfx::NativeViewId view, return false; } + command_buffer_->SetSwapBuffersCallback(NewCallback(this, + &Context::OnSwapBuffers)); + // Create the GLES2 helper, which writes the command buffer protocol. gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_); if (!gles2_helper_->Initialize(kCommandBufferSize)) { @@ -279,6 +291,11 @@ void Context::DisableShaderTranslation() { gles2_implementation_->CommandBufferEnable(PEPPER3D_SKIP_GLSL_TRANSLATION); } +void Context::OnSwapBuffers() { + if (swap_buffers_callback_.get()) + swap_buffers_callback_->Run(this); +} + #endif // ENABLE_GPU Context* CreateViewContext(GpuChannelHost* channel, @@ -331,6 +348,11 @@ uint32 GetParentTextureId(Context* context) { #endif } +void SetSwapBuffersCallback(Context* context, + Callback1<Context*>::Type* callback) { + context->SetSwapBuffersCallback(callback); +} + bool MakeCurrent(Context* context) { #if defined(ENABLE_GPU) return Context::MakeCurrent(context); diff --git a/chrome/renderer/ggl/ggl.h b/chrome/renderer/ggl/ggl.h index ce34c7f..b005d56 100644 --- a/chrome/renderer/ggl/ggl.h +++ b/chrome/renderer/ggl/ggl.h @@ -11,6 +11,7 @@ #define CHROME_RENDERER_GGL_GGL_H_ #pragma once +#include "base/callback.h" #include "gfx/native_widget_types.h" #include "gfx/size.h" @@ -83,6 +84,11 @@ void ResizeOffscreenContext(Context* context, const gfx::Size& size); // parent. uint32 GetParentTextureId(Context* context); +// Provides a callback that will be invoked when SwapBuffers has completed +// service side. +void SetSwapBuffersCallback(Context* context, + Callback1<Context*>::Type* callback); + // Set the current GGL context for the calling thread. bool MakeCurrent(Context* context); |