Commit 22f320a2 authored by apatrick@chromium.org's avatar apatrick@chromium.org

Added GPU process "echo" IPC message.

The echo message is essentially an async fence with event based notification. The client gets a notification when the GPU process has completed all the work up to the last flush.

I used it to replace the SwapBuffers / OnSwapBuffers synchronization and got rid of some of the callbacks in the lower layers of the stack.

The SwapBuffers callbacks in the GPU process are only needed on mac now and I will replace them with something more generic soon.
Review URL: http://codereview.chromium.org/7762013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98747 0039d316-1c4b-4281-b951-d872f2087c98
parent c16ed34d
...@@ -260,6 +260,7 @@ bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) { ...@@ -260,6 +260,7 @@ bool GpuChannel::OnControlMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroySurface, OnDestroySurface) IPC_MESSAGE_HANDLER(GpuChannelMsg_DestroySurface, OnDestroySurface)
IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateTransportTexture, IPC_MESSAGE_HANDLER(GpuChannelMsg_CreateTransportTexture,
OnCreateTransportTexture) OnCreateTransportTexture)
IPC_MESSAGE_HANDLER(GpuChannelMsg_Echo, OnEcho);
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
DCHECK(handled) << msg.type(); DCHECK(handled) << msg.type();
...@@ -411,6 +412,11 @@ void GpuChannel::OnCreateTransportTexture(int32 context_route_id, ...@@ -411,6 +412,11 @@ void GpuChannel::OnCreateTransportTexture(int32 context_route_id,
#endif #endif
} }
void GpuChannel::OnEcho(const IPC::Message& message) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnEcho");
Send(new IPC::Message(message));
}
bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop, bool GpuChannel::Init(base::MessageLoopProxy* io_message_loop,
base::WaitableEvent* shutdown_event) { base::WaitableEvent* shutdown_event) {
// Check whether we're already initialized. // Check whether we're already initialized.
......
...@@ -150,6 +150,8 @@ class GpuChannel : public IPC::Channel::Listener, ...@@ -150,6 +150,8 @@ class GpuChannel : public IPC::Channel::Listener,
void OnCreateTransportTexture(int32 context_route_id, int32 host_id); void OnCreateTransportTexture(int32 context_route_id, int32 host_id);
void OnEcho(const IPC::Message& message);
// The lifetime of objects of this class is managed by a GpuChannelManager. // The lifetime of objects of this class is managed by a GpuChannelManager.
// The GpuChannelManager destroy all the GpuChannels that they own when they // The GpuChannelManager destroy all the GpuChannels that they own when they
// are destroyed. So a raw pointer is safe. // are destroyed. So a raw pointer is safe.
......
...@@ -197,8 +197,12 @@ void GpuCommandBufferStub::OnInitialize( ...@@ -197,8 +197,12 @@ void GpuCommandBufferStub::OnInitialize(
NewCallback(this, &GpuCommandBufferStub::OnParseError)); NewCallback(this, &GpuCommandBufferStub::OnParseError));
scheduler_->SetScheduledCallback( scheduler_->SetScheduledCallback(
NewCallback(channel_, &GpuChannel::OnScheduled)); NewCallback(channel_, &GpuChannel::OnScheduled));
#if defined(OS_MACOSX)
scheduler_->SetSwapBuffersCallback( scheduler_->SetSwapBuffersCallback(
NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers));
#endif
// On TOUCH_UI, the ImageTransportSurface handles co-ordinating the // On TOUCH_UI, the ImageTransportSurface handles co-ordinating the
// resize with the browser process. The ImageTransportSurface sets it's // resize with the browser process. The ImageTransportSurface sets it's
// own resize callback, so we shouldn't do it here. // own resize callback, so we shouldn't do it here.
...@@ -407,11 +411,9 @@ void GpuCommandBufferStub::OnGetTransferBuffer( ...@@ -407,11 +411,9 @@ void GpuCommandBufferStub::OnGetTransferBuffer(
Send(reply_message); Send(reply_message);
} }
#if defined(OS_MACOSX)
void GpuCommandBufferStub::OnSwapBuffers() { void GpuCommandBufferStub::OnSwapBuffers() {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSwapBuffers"); TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSwapBuffers");
ReportState();
#if defined(OS_MACOSX)
if (handle_) { if (handle_) {
// To swap on OSX, we have to send a message to the browser to get the // To swap on OSX, we have to send a message to the browser to get the
// context put onscreen. // context put onscreen.
...@@ -427,11 +429,8 @@ void GpuCommandBufferStub::OnSwapBuffers() { ...@@ -427,11 +429,8 @@ void GpuCommandBufferStub::OnSwapBuffers() {
new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params));
scheduler_->SetScheduled(false); scheduler_->SetScheduled(false);
} }
#else
// Notify the upstream commandbuffer that the swapbuffers has completed.
Send(new GpuCommandBufferMsg_SwapBuffers(route_id_));
#endif
} }
#endif
void GpuCommandBufferStub::OnCommandProcessed() { void GpuCommandBufferStub::OnCommandProcessed() {
if (watchdog_) if (watchdog_)
...@@ -455,10 +454,9 @@ void GpuCommandBufferStub::AcceleratedSurfaceBuffersSwapped( ...@@ -455,10 +454,9 @@ void GpuCommandBufferStub::AcceleratedSurfaceBuffersSwapped(
scheduler_->set_acknowledged_swap_buffers_count(swap_buffers_count); scheduler_->set_acknowledged_swap_buffers_count(swap_buffers_count);
for(uint64 i = 0; i < delta; i++) { for(uint64 i = 0; i < delta; i++) {
// Notify the upstream commandbuffer that the swapbuffers has completed. // Wake up the GpuScheduler to start doing work again. When the scheduler
Send(new GpuCommandBufferMsg_SwapBuffers(route_id_)); // wakes up, it will send any deferred echo acknowledgements, triggering
// associated swapbuffer callbacks.
// Wake up the GpuScheduler to start doing work again.
scheduler_->SetScheduled(true); scheduler_->SetScheduled(true);
} }
} }
......
...@@ -102,6 +102,7 @@ class GpuCommandBufferStub ...@@ -102,6 +102,7 @@ class GpuCommandBufferStub
uint32 flush_count, uint32 flush_count,
IPC::Message* reply_message); IPC::Message* reply_message);
void OnAsyncFlush(int32 put_offset, uint32 flush_count); void OnAsyncFlush(int32 put_offset, uint32 flush_count);
void OnEcho(const IPC::Message& message);
void OnRescheduled(); void OnRescheduled();
void OnCreateTransferBuffer(int32 size, void OnCreateTransferBuffer(int32 size,
int32 id_request, int32 id_request,
...@@ -117,7 +118,10 @@ class GpuCommandBufferStub ...@@ -117,7 +118,10 @@ class GpuCommandBufferStub
IPC::Message* reply_message); IPC::Message* reply_message);
void OnDestroyVideoDecoder(int32 decoder_route_id); void OnDestroyVideoDecoder(int32 decoder_route_id);
#if defined(OS_MACOSX)
void OnSwapBuffers(); void OnSwapBuffers();
#endif
void OnCommandProcessed(); void OnCommandProcessed();
void OnParseError(); void OnParseError();
......
...@@ -307,6 +307,10 @@ IPC_MESSAGE_CONTROL2(GpuChannelMsg_CreateTransportTexture, ...@@ -307,6 +307,10 @@ IPC_MESSAGE_CONTROL2(GpuChannelMsg_CreateTransportTexture,
int32, /* context_route_id */ int32, /* context_route_id */
int32 /* host_id */) int32 /* host_id */)
// Request that the GPU process reply with the given message.
IPC_MESSAGE_CONTROL1(GpuChannelMsg_Echo,
IPC::Message /* reply */)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// GPU Command Buffer Messages // GPU Command Buffer Messages
// These are messages between a renderer process to the GPU process relating to // These are messages between a renderer process to the GPU process relating to
...@@ -357,9 +361,6 @@ IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_Rescheduled) ...@@ -357,9 +361,6 @@ IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_Rescheduled)
IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_UpdateState, IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_UpdateState,
gpu::CommandBuffer::State /* state */) 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 // Create a shared memory transfer buffer. Returns an id that can be used to
// identify the transfer buffer from a comment. // identify the transfer buffer from a comment.
IPC_SYNC_MESSAGE_ROUTED2_1(GpuCommandBufferMsg_CreateTransferBuffer, IPC_SYNC_MESSAGE_ROUTED2_1(GpuCommandBufferMsg_CreateTransferBuffer,
...@@ -418,6 +419,9 @@ IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_SetWindowSize, ...@@ -418,6 +419,9 @@ IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_SetWindowSize,
IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_Destroyed, IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_Destroyed,
gpu::error::ContextLostReason /* reason */) gpu::error::ContextLostReason /* reason */)
// Response to a GpuChannelMsg_Echo message.
IPC_MESSAGE_ROUTED0(GpuCommandBufferMsg_EchoAck)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// TransportTexture messages // TransportTexture messages
// //
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/process_util.h" #include "base/process_util.h"
#include "base/shared_memory.h" #include "base/shared_memory.h"
#include "base/stl_util.h"
#include "base/task.h" #include "base/task.h"
#include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/gpu_messages.h"
#include "content/common/plugin_messages.h" #include "content/common/plugin_messages.h"
...@@ -45,9 +46,9 @@ bool CommandBufferProxy::OnMessageReceived(const IPC::Message& message) { ...@@ -45,9 +46,9 @@ bool CommandBufferProxy::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(CommandBufferProxy, message) IPC_BEGIN_MESSAGE_MAP(CommandBufferProxy, message)
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateState, OnUpdateState); IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateState, OnUpdateState);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed); IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffers, OnSwapBuffers);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_NotifyRepaint, IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_NotifyRepaint,
OnNotifyRepaint); OnNotifyRepaint);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_EchoAck, OnEchoAck);
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
...@@ -79,6 +80,13 @@ void CommandBufferProxy::OnDestroyed(gpu::error::ContextLostReason reason) { ...@@ -79,6 +80,13 @@ void CommandBufferProxy::OnDestroyed(gpu::error::ContextLostReason reason) {
} }
} }
void CommandBufferProxy::OnEchoAck() {
DCHECK(!echo_tasks_.empty());
Task* task = echo_tasks_.front().release();
echo_tasks_.pop();
task->Run();
}
void CommandBufferProxy::SetChannelErrorCallback(Callback0::Type* callback) { void CommandBufferProxy::SetChannelErrorCallback(Callback0::Type* callback) {
channel_error_callback_.reset(callback); channel_error_callback_.reset(callback);
} }
...@@ -344,9 +352,20 @@ void CommandBufferProxy::SetContextLostReason( ...@@ -344,9 +352,20 @@ void CommandBufferProxy::SetContextLostReason(
NOTREACHED(); NOTREACHED();
} }
void CommandBufferProxy::OnSwapBuffers() { bool CommandBufferProxy::Echo(Task* task) {
if (swap_buffers_callback_.get()) if (last_state_.error != gpu::error::kNoError) {
swap_buffers_callback_->Run(); delete task;
return false;
}
if (!Send(new GpuChannelMsg_Echo(GpuCommandBufferMsg_EchoAck(route_id_)))) {
delete task;
return false;
}
echo_tasks_.push(linked_ptr<Task>(task));
return true;
} }
bool CommandBufferProxy::SetParent(CommandBufferProxy* parent_command_buffer, bool CommandBufferProxy::SetParent(CommandBufferProxy* parent_command_buffer,
...@@ -376,10 +395,6 @@ bool CommandBufferProxy::SetParent(CommandBufferProxy* parent_command_buffer, ...@@ -376,10 +395,6 @@ bool CommandBufferProxy::SetParent(CommandBufferProxy* parent_command_buffer,
return result; return result;
} }
void CommandBufferProxy::SetSwapBuffersCallback(Callback0::Type* callback) {
swap_buffers_callback_.reset(callback);
}
void CommandBufferProxy::SetNotifyRepaintTask(Task* task) { void CommandBufferProxy::SetNotifyRepaintTask(Task* task) {
notify_repaint_task_.reset(task); notify_repaint_task_.reset(task);
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/memory/linked_ptr.h" #include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/task.h"
#include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h"
#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/common/command_buffer.h"
#include "ipc/ipc_channel.h" #include "ipc/ipc_channel.h"
...@@ -65,7 +66,10 @@ class CommandBufferProxy : public gpu::CommandBuffer, ...@@ -65,7 +66,10 @@ class CommandBufferProxy : public gpu::CommandBuffer,
virtual void SetToken(int32 token); virtual void SetToken(int32 token);
virtual void SetParseError(gpu::error::Error error); virtual void SetParseError(gpu::error::Error error);
virtual void SetContextLostReason(gpu::error::ContextLostReason reason); virtual void SetContextLostReason(gpu::error::ContextLostReason reason);
virtual void OnSwapBuffers();
// Invoke the task when the channel has been flushed. Takes care of deleting
// the task whether the echo succeeds or not.
bool Echo(Task* task);
// Reparent a command buffer. TODO(apatrick): going forward, the notion of // Reparent a command buffer. TODO(apatrick): going forward, the notion of
// the parent / child relationship between command buffers is going away in // the parent / child relationship between command buffers is going away in
...@@ -74,9 +78,6 @@ class CommandBufferProxy : public gpu::CommandBuffer, ...@@ -74,9 +78,6 @@ class CommandBufferProxy : public gpu::CommandBuffer,
virtual bool SetParent(CommandBufferProxy* parent_command_buffer, virtual bool SetParent(CommandBufferProxy* parent_command_buffer,
uint32 parent_texture_id); uint32 parent_texture_id);
// Set a callback that will be invoked when the SwapBuffers call has been
// issued.
void SetSwapBuffersCallback(Callback0::Type* callback);
void SetChannelErrorCallback(Callback0::Type* callback); void SetChannelErrorCallback(Callback0::Type* callback);
// Set a task that will be invoked the next time the window becomes invalid // Set a task that will be invoked the next time the window becomes invalid
...@@ -104,6 +105,7 @@ class CommandBufferProxy : public gpu::CommandBuffer, ...@@ -104,6 +105,7 @@ class CommandBufferProxy : public gpu::CommandBuffer,
void OnUpdateState(const gpu::CommandBuffer::State& state); void OnUpdateState(const gpu::CommandBuffer::State& state);
void OnNotifyRepaint(); void OnNotifyRepaint();
void OnDestroyed(gpu::error::ContextLostReason reason); void OnDestroyed(gpu::error::ContextLostReason reason);
void OnEchoAck();
// As with the service, the client takes ownership of the ring buffer. // As with the service, the client takes ownership of the ring buffer.
int32 num_entries_; int32 num_entries_;
...@@ -127,9 +129,11 @@ class CommandBufferProxy : public gpu::CommandBuffer, ...@@ -127,9 +129,11 @@ class CommandBufferProxy : public gpu::CommandBuffer,
int route_id_; int route_id_;
unsigned int flush_count_; unsigned int flush_count_;
// Tasks to be invoked in echo responses.
std::queue<linked_ptr<Task> > echo_tasks_;
scoped_ptr<Task> notify_repaint_task_; scoped_ptr<Task> notify_repaint_task_;
scoped_ptr<Callback0::Type> swap_buffers_callback_;
scoped_ptr<Callback0::Type> channel_error_callback_; scoped_ptr<Callback0::Type> channel_error_callback_;
DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy); DISALLOW_COPY_AND_ASSIGN(CommandBufferProxy);
......
...@@ -192,10 +192,6 @@ void RendererGLContext::DeleteParentTexture(uint32 texture) { ...@@ -192,10 +192,6 @@ void RendererGLContext::DeleteParentTexture(uint32 texture) {
gles2_implementation_->DeleteTextures(1, &texture); gles2_implementation_->DeleteTextures(1, &texture);
} }
void RendererGLContext::SetSwapBuffersCallback(Callback0::Type* callback) {
swap_buffers_callback_.reset(callback);
}
void RendererGLContext::SetContextLostCallback( void RendererGLContext::SetContextLostCallback(
Callback1<ContextLostReason>::Type* callback) { Callback1<ContextLostReason>::Type* callback) {
context_lost_callback_.reset(callback); context_lost_callback_.reset(callback);
...@@ -229,9 +225,14 @@ bool RendererGLContext::SwapBuffers() { ...@@ -229,9 +225,14 @@ bool RendererGLContext::SwapBuffers() {
return false; return false;
gles2_implementation_->SwapBuffers(); gles2_implementation_->SwapBuffers();
return true; return true;
} }
bool RendererGLContext::Echo(Task* task) {
return command_buffer_->Echo(task);
}
scoped_refptr<TransportTextureHost> scoped_refptr<TransportTextureHost>
RendererGLContext::CreateTransportTextureHost() { RendererGLContext::CreateTransportTextureHost() {
return channel_->transport_texture_service()->CreateTransportTextureHost( return channel_->transport_texture_service()->CreateTransportTextureHost(
...@@ -368,9 +369,6 @@ bool RendererGLContext::Initialize(bool onscreen, ...@@ -368,9 +369,6 @@ bool RendererGLContext::Initialize(bool onscreen,
} }
} }
command_buffer_->SetSwapBuffersCallback(
NewCallback(this, &RendererGLContext::OnSwapBuffers));
command_buffer_->SetChannelErrorCallback( command_buffer_->SetChannelErrorCallback(
NewCallback(this, &RendererGLContext::OnContextLost)); NewCallback(this, &RendererGLContext::OnContextLost));
...@@ -445,11 +443,6 @@ void RendererGLContext::Destroy() { ...@@ -445,11 +443,6 @@ void RendererGLContext::Destroy() {
channel_ = NULL; channel_ = NULL;
} }
void RendererGLContext::OnSwapBuffers() {
if (swap_buffers_callback_.get())
swap_buffers_callback_->Run();
}
void RendererGLContext::OnContextLost() { void RendererGLContext::OnContextLost() {
if (context_lost_callback_.get()) { if (context_lost_callback_.get()) {
RendererGLContext::ContextLostReason reason = kUnknown; RendererGLContext::ContextLostReason reason = kUnknown;
......
...@@ -22,6 +22,7 @@ class GpuChannelHost; ...@@ -22,6 +22,7 @@ class GpuChannelHost;
class MessageLoop; class MessageLoop;
class CommandBufferProxy; class CommandBufferProxy;
class GURL; class GURL;
class Task;
class TransportTextureHost; class TransportTextureHost;
namespace gpu { namespace gpu {
...@@ -140,10 +141,6 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> { ...@@ -140,10 +141,6 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
// Deletes a texture in the parent's RendererGLContext. // Deletes a texture in the parent's RendererGLContext.
void DeleteParentTexture(uint32 texture); void DeleteParentTexture(uint32 texture);
// Provides a callback that will be invoked when SwapBuffers has completed
// service side.
void SetSwapBuffersCallback(Callback0::Type* callback);
void SetContextLostCallback(Callback1<ContextLostReason>::Type* callback); void SetContextLostCallback(Callback1<ContextLostReason>::Type* callback);
// Set the current RendererGLContext for the calling thread. // Set the current RendererGLContext for the calling thread.
...@@ -155,6 +152,10 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> { ...@@ -155,6 +152,10 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
// by the parent RendererGLContext. // by the parent RendererGLContext.
bool SwapBuffers(); bool SwapBuffers();
// Run the task once the channel has been flushed. Takes care of deleting the
// task whether the echo succeeds or not.
bool Echo(Task* task);
// Create a TransportTextureHost object associated with the context. // Create a TransportTextureHost object associated with the context.
scoped_refptr<TransportTextureHost> CreateTransportTextureHost(); scoped_refptr<TransportTextureHost> CreateTransportTextureHost();
...@@ -186,12 +187,10 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> { ...@@ -186,12 +187,10 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
const GURL& active_url); const GURL& active_url);
void Destroy(); void Destroy();
void OnSwapBuffers();
void OnContextLost(); void OnContextLost();
scoped_refptr<GpuChannelHost> channel_; scoped_refptr<GpuChannelHost> channel_;
base::WeakPtr<RendererGLContext> parent_; base::WeakPtr<RendererGLContext> parent_;
scoped_ptr<Callback0::Type> swap_buffers_callback_;
scoped_ptr<Callback1<ContextLostReason>::Type> context_lost_callback_; scoped_ptr<Callback1<ContextLostReason>::Type> context_lost_callback_;
uint32 parent_texture_id_; uint32 parent_texture_id_;
CommandBufferProxy* command_buffer_; CommandBufferProxy* command_buffer_;
......
...@@ -49,7 +49,8 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() ...@@ -49,7 +49,8 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl()
swapbuffers_complete_callback_(0), swapbuffers_complete_callback_(0),
cached_width_(0), cached_width_(0),
cached_height_(0), cached_height_(0),
bound_fbo_(0) { bound_fbo_(0),
method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
} }
WebGraphicsContext3DCommandBufferImpl:: WebGraphicsContext3DCommandBufferImpl::
...@@ -137,11 +138,6 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize( ...@@ -137,11 +138,6 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
preferred_extensions, preferred_extensions,
attribs, attribs,
active_url); active_url);
if (context_) {
context_->SetSwapBuffersCallback(
NewCallback(this,
&WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete));
}
} else { } else {
context_ = RendererGLContext::CreateOffscreenContext( context_ = RendererGLContext::CreateOffscreenContext(
host, host,
...@@ -230,6 +226,8 @@ void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { ...@@ -230,6 +226,8 @@ void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
renderview->OnViewContextSwapBuffersPosted(); renderview->OnViewContextSwapBuffersPosted();
#endif #endif
context_->SwapBuffers(); context_->SwapBuffers();
context_->Echo(method_factory_.NewRunnableMethod(
&WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete));
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// It appears that making the compositor's on-screen context current on // It appears that making the compositor's on-screen context current on
// other platforms implies this flush. TODO(kbr): this means that the // other platforms implies this flush. TODO(kbr): this means that the
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/task.h"
#include "content/renderer/gpu/renderer_gl_context.h" #include "content/renderer/gpu/renderer_gl_context.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
...@@ -468,6 +469,9 @@ class WebGraphicsContext3DCommandBufferImpl ...@@ -468,6 +469,9 @@ class WebGraphicsContext3DCommandBufferImpl
// Errors raised by synthesizeGLError(). // Errors raised by synthesizeGLError().
std::vector<WGC3Denum> synthetic_errors_; std::vector<WGC3Denum> synthetic_errors_;
ScopedRunnableMethodFactory<WebGraphicsContext3DCommandBufferImpl>
method_factory_;
#ifdef FLIP_FRAMEBUFFER_VERTICALLY #ifdef FLIP_FRAMEBUFFER_VERTICALLY
scoped_array<uint8> scanline_; scoped_array<uint8> scanline_;
void FlipVertically(uint8* framebuffer, void FlipVertically(uint8* framebuffer,
......
...@@ -111,11 +111,6 @@ bool PlatformContext3DImpl::Init(const int32* attrib_list) { ...@@ -111,11 +111,6 @@ bool PlatformContext3DImpl::Init(const int32* attrib_list) {
return true; return true;
} }
void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) {
DCHECK(command_buffer_);
command_buffer_->SetSwapBuffersCallback(callback);
}
unsigned PlatformContext3DImpl::GetBackingTextureId() { unsigned PlatformContext3DImpl::GetBackingTextureId() {
DCHECK(command_buffer_); DCHECK(command_buffer_);
return parent_texture_id_; return parent_texture_id_;
...@@ -134,6 +129,10 @@ void PlatformContext3DImpl::SetContextLostCallback(Callback0::Type* callback) { ...@@ -134,6 +129,10 @@ void PlatformContext3DImpl::SetContextLostCallback(Callback0::Type* callback) {
context_lost_callback_.reset(callback); context_lost_callback_.reset(callback);
} }
bool PlatformContext3DImpl::Echo(Task* task) {
return command_buffer_->Echo(task);
}
void PlatformContext3DImpl::OnContextLost() { void PlatformContext3DImpl::OnContextLost() {
DCHECK(command_buffer_); DCHECK(command_buffer_);
......
...@@ -21,6 +21,7 @@ class CommandBuffer; ...@@ -21,6 +21,7 @@ class CommandBuffer;
class CommandBufferProxy; class CommandBufferProxy;
class GpuChannelHost; class GpuChannelHost;
class RendererGLContext; class RendererGLContext;
class Task;
class PlatformContext3DImpl class PlatformContext3DImpl
: public webkit::ppapi::PluginDelegate::PlatformContext3D { : public webkit::ppapi::PluginDelegate::PlatformContext3D {
...@@ -29,11 +30,11 @@ class PlatformContext3DImpl ...@@ -29,11 +30,11 @@ class PlatformContext3DImpl
virtual ~PlatformContext3DImpl(); virtual ~PlatformContext3DImpl();
virtual bool Init(const int32* attrib_list); virtual bool Init(const int32* attrib_list);
virtual void SetSwapBuffersCallback(Callback0::Type* callback);
virtual unsigned GetBackingTextureId(); virtual unsigned GetBackingTextureId();
virtual gpu::CommandBuffer* GetCommandBuffer(); virtual gpu::CommandBuffer* GetCommandBuffer();
virtual int GetCommandBufferRouteId(); virtual int GetCommandBufferRouteId();
virtual void SetContextLostCallback(Callback0::Type* callback); virtual void SetContextLostCallback(Callback0::Type* callback);
virtual bool Echo(Task* task);
private: private:
bool InitRaw(); bool InitRaw();
......
...@@ -227,7 +227,8 @@ RenderWidgetFullscreenPepper::RenderWidgetFullscreenPepper( ...@@ -227,7 +227,8 @@ RenderWidgetFullscreenPepper::RenderWidgetFullscreenPepper(
plugin_(plugin), plugin_(plugin),
context_(NULL), context_(NULL),
buffer_(0), buffer_(0),
program_(0) { program_(0),
method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
} }
RenderWidgetFullscreenPepper::~RenderWidgetFullscreenPepper() { RenderWidgetFullscreenPepper::~RenderWidgetFullscreenPepper() {
...@@ -363,10 +364,6 @@ void RenderWidgetFullscreenPepper::CreateContext() { ...@@ -363,10 +364,6 @@ void RenderWidgetFullscreenPepper::CreateContext() {
context_ = NULL; context_ = NULL;
return; return;
} }
context_->SetSwapBuffersCallback(
NewCallback(this,
&RenderWidgetFullscreenPepper::
OnSwapBuffersCompleteByRendererGLContext));
context_->SetContextLostCallback( context_->SetContextLostCallback(
NewCallback(this, &RenderWidgetFullscreenPepper::OnLostContext)); NewCallback(this, &RenderWidgetFullscreenPepper::OnLostContext));
} }
...@@ -477,6 +474,8 @@ void RenderWidgetFullscreenPepper::SwapBuffers() { ...@@ -477,6 +474,8 @@ void RenderWidgetFullscreenPepper::SwapBuffers() {
DCHECK(context_); DCHECK(context_);
OnSwapBuffersPosted(); OnSwapBuffersPosted();
context_->SwapBuffers(); context_->SwapBuffers();
context_->Echo(method_factory_.NewRunnableMethod(
&RenderWidgetFullscreenPepper::OnSwapBuffersCompleteByRendererGLContext));
} }
void RenderWidgetFullscreenPepper::OnLostContext( void RenderWidgetFullscreenPepper::OnLostContext(
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_ #ifndef CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_
#define CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_ #define CONTENT_RENDERER_RENDER_WIDGET_FULLSCREEN_PEPPER_H_
#include "base/task.h"
#include "content/renderer/render_widget_fullscreen.h" #include "content/renderer/render_widget_fullscreen.h"
#include "content/renderer/gpu/renderer_gl_context.h" #include "content/renderer/gpu/renderer_gl_context.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
...@@ -94,6 +95,8 @@ class RenderWidgetFullscreenPepper : public RenderWidgetFullscreen, ...@@ -94,6 +95,8 @@ class RenderWidgetFullscreenPepper : public RenderWidgetFullscreen,
unsigned int buffer_; unsigned int buffer_;
unsigned int program_; unsigned int program_;
ScopedRunnableMethodFactory<RenderWidgetFullscreenPepper> method_factory_;
DISALLOW_COPY_AND_ASSIGN(RenderWidgetFullscreenPepper); DISALLOW_COPY_AND_ASSIGN(RenderWidgetFullscreenPepper);
}; };
......
...@@ -477,7 +477,11 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, ...@@ -477,7 +477,11 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
virtual ContextGroup* GetContextGroup() { return group_.get(); } virtual ContextGroup* GetContextGroup() { return group_.get(); }
virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback); virtual void SetResizeCallback(Callback1<gfx::Size>::Type* callback);
#if defined(OS_MACOSX)
virtual void SetSwapBuffersCallback(Callback0::Type* callback); virtual void SetSwapBuffersCallback(Callback0::Type* callback);
#endif
virtual bool GetServiceTextureId(uint32 client_texture_id, virtual bool GetServiceTextureId(uint32 client_texture_id,
uint32* service_texture_id); uint32* service_texture_id);
...@@ -1284,7 +1288,10 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, ...@@ -1284,7 +1288,10 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
GLenum offscreen_saved_color_format_; GLenum offscreen_saved_color_format_;
scoped_ptr<Callback1<gfx::Size>::Type> resize_callback_; scoped_ptr<Callback1<gfx::Size>::Type> resize_callback_;
#if defined(OS_MACOSX)
scoped_ptr<Callback0::Type> swap_buffers_callback_; scoped_ptr<Callback0::Type> swap_buffers_callback_;
#endif
// The format of the back buffer_ // The format of the back buffer_
GLenum back_buffer_color_format_; GLenum back_buffer_color_format_;
...@@ -2280,9 +2287,11 @@ void GLES2DecoderImpl::SetResizeCallback( ...@@ -2280,9 +2287,11 @@ void GLES2DecoderImpl::SetResizeCallback(
resize_callback_.reset(callback); resize_callback_.reset(callback);
} }
#if defined(OS_MACOSX)
void GLES2DecoderImpl::SetSwapBuffersCallback(Callback0::Type* callback) { void GLES2DecoderImpl::SetSwapBuffersCallback(Callback0::Type* callback) {
swap_buffers_callback_.reset(callback); swap_buffers_callback_.reset(callback);
} }
#endif
bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id,
uint32* service_texture_id) { uint32* service_texture_id) {
...@@ -6579,9 +6588,11 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers( ...@@ -6579,9 +6588,11 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers(
// For multisampled buffers, bind the resolved frame buffer so that // For multisampled buffers, bind the resolved frame buffer so that
// callbacks can call ReadPixels or CopyTexImage2D. // callbacks can call ReadPixels or CopyTexImage2D.
ScopedResolvedFrameBufferBinder binder(this, true, false); ScopedResolvedFrameBufferBinder binder(this, true, false);
#if defined(OS_MACOSX)
if (swap_buffers_callback_.get()) { if (swap_buffers_callback_.get()) {
swap_buffers_callback_->Run(); swap_buffers_callback_->Run();
} }
#endif
return error::kNoError; return error::kNoError;
} else { } else {
ScopedFrameBufferBinder binder(this, ScopedFrameBufferBinder binder(this,
...@@ -6602,9 +6613,11 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers( ...@@ -6602,9 +6613,11 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers(
// Run the callback with |binder| in scope, so that the callback can call // Run the callback with |binder| in scope, so that the callback can call
// ReadPixels or CopyTexImage2D. // ReadPixels or CopyTexImage2D.
#if defined(OS_MACOSX)
if (swap_buffers_callback_.get()) { if (swap_buffers_callback_.get()) {
swap_buffers_callback_->Run(); swap_buffers_callback_->Run();
} }
#endif
return error::kNoError; return error::kNoError;
} }
} else { } else {
...@@ -6615,9 +6628,11 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers( ...@@ -6615,9 +6628,11 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers(
} }
} }
#if defined(OS_MACOSX)
if (swap_buffers_callback_.get()) { if (swap_buffers_callback_.get()) {
swap_buffers_callback_->Run(); swap_buffers_callback_->Run();
} }
#endif
return error::kNoError; return error::kNoError;
} }
......
...@@ -103,8 +103,10 @@ class GLES2Decoder : public CommonDecoder { ...@@ -103,8 +103,10 @@ class GLES2Decoder : public CommonDecoder {
virtual void SetResizeCallback( virtual void SetResizeCallback(
Callback1<gfx::Size>::Type* callback) = 0; Callback1<gfx::Size>::Type* callback) = 0;
#if defined(OS_MACOSX)
// Sets a callback which is called when a SwapBuffers command is processed. // Sets a callback which is called when a SwapBuffers command is processed.
virtual void SetSwapBuffersCallback(Callback0::Type* callback) = 0; virtual void SetSwapBuffersCallback(Callback0::Type* callback) = 0;
#endif
// Get the service texture ID corresponding to a client texture ID. // Get the service texture ID corresponding to a client texture ID.
// If no such record is found then return false. // If no such record is found then return false.
......
...@@ -233,14 +233,6 @@ void GpuScheduler::SetResizeCallback( ...@@ -233,14 +233,6 @@ void GpuScheduler::SetResizeCallback(
decoder_->SetResizeCallback(callback); decoder_->SetResizeCallback(callback);
} }
void GpuScheduler::SetSwapBuffersCallback(
Callback0::Type* callback) {
wrapped_swap_buffers_callback_.reset(callback);
decoder_->SetSwapBuffersCallback(
NewCallback(this,
&GpuScheduler::WillSwapBuffers));
}
void GpuScheduler::SetCommandProcessedCallback( void GpuScheduler::SetCommandProcessedCallback(
Callback0::Type* callback) { Callback0::Type* callback) {
command_processed_callback_.reset(callback); command_processed_callback_.reset(callback);
......
...@@ -127,16 +127,16 @@ class GpuScheduler : public CommandBufferEngine { ...@@ -127,16 +127,16 @@ class GpuScheduler : public CommandBufferEngine {
virtual uint64 GetSurfaceId(); virtual uint64 GetSurfaceId();
void DidDestroySurface(); void DidDestroySurface();
#endif
// Sets a callback that is called when a glResizeCHROMIUM command
// is processed.
void SetResizeCallback(Callback1<gfx::Size>::Type* callback);
// Sets a callback which is called when a SwapBuffers command is processed. // Sets a callback which is called when a SwapBuffers command is processed.
// Must be called after Initialize(). // Must be called after Initialize().
// It is not defined on which thread this callback is called. // It is not defined on which thread this callback is called.
void SetSwapBuffersCallback(Callback0::Type* callback); void SetSwapBuffersCallback(Callback0::Type* callback);
#endif
// Sets a callback that is called when a glResizeCHROMIUM command
// is processed.
void SetResizeCallback(Callback1<gfx::Size>::Type* callback);
void SetCommandProcessedCallback(Callback0::Type* callback); void SetCommandProcessedCallback(Callback0::Type* callback);
...@@ -149,9 +149,11 @@ class GpuScheduler : public CommandBufferEngine { ...@@ -149,9 +149,11 @@ class GpuScheduler : public CommandBufferEngine {
gles2::GLES2Decoder* decoder, gles2::GLES2Decoder* decoder,
CommandParser* parser); CommandParser* parser);
#if defined(OS_MACOSX)
// Called via a callback just before we are supposed to call the // Called via a callback just before we are supposed to call the
// user's swap buffers callback. // user's swap buffers callback.
void WillSwapBuffers(); void WillSwapBuffers();
#endif
// The GpuScheduler holds a weak reference to the CommandBuffer. The // The GpuScheduler holds a weak reference to the CommandBuffer. The
// CommandBuffer owns the GpuScheduler and holds a strong reference to it // CommandBuffer owns the GpuScheduler and holds a strong reference to it
...@@ -170,10 +172,10 @@ class GpuScheduler : public CommandBufferEngine { ...@@ -170,10 +172,10 @@ class GpuScheduler : public CommandBufferEngine {
uint64 swap_buffers_count_; uint64 swap_buffers_count_;
uint64 acknowledged_swap_buffers_count_; uint64 acknowledged_swap_buffers_count_;
scoped_ptr<AcceleratedSurface> surface_; scoped_ptr<AcceleratedSurface> surface_;
scoped_ptr<Callback0::Type> wrapped_swap_buffers_callback_;
#endif #endif
ScopedRunnableMethodFactory<GpuScheduler> method_factory_; ScopedRunnableMethodFactory<GpuScheduler> method_factory_;
scoped_ptr<Callback0::Type> wrapped_swap_buffers_callback_;
scoped_ptr<Callback0::Type> command_processed_callback_; scoped_ptr<Callback0::Type> command_processed_callback_;
}; };
......
...@@ -58,10 +58,4 @@ void GpuScheduler::Destroy() { ...@@ -58,10 +58,4 @@ void GpuScheduler::Destroy() {
DestroyCommon(); DestroyCommon();
} }
void GpuScheduler::WillSwapBuffers() {
if (wrapped_swap_buffers_callback_.get()) {
wrapped_swap_buffers_callback_->Run();
}
}
} // namespace gpu } // namespace gpu
...@@ -120,6 +120,14 @@ void GpuScheduler::DidDestroySurface() { ...@@ -120,6 +120,14 @@ void GpuScheduler::DidDestroySurface() {
surface_.reset(); surface_.reset();
} }
void GpuScheduler::SetSwapBuffersCallback(
Callback0::Type* callback) {
wrapped_swap_buffers_callback_.reset(callback);
decoder_->SetSwapBuffersCallback(
NewCallback(this,
&GpuScheduler::WillSwapBuffers));
}
void GpuScheduler::WillSwapBuffers() { void GpuScheduler::WillSwapBuffers() {
DCHECK(decoder_.get()); DCHECK(decoder_.get());
DCHECK(decoder_->GetGLContext()); DCHECK(decoder_->GetGLContext());
......
...@@ -57,10 +57,4 @@ void GpuScheduler::Destroy() { ...@@ -57,10 +57,4 @@ void GpuScheduler::Destroy() {
DestroyCommon(); DestroyCommon();
} }
void GpuScheduler::WillSwapBuffers() {
if (wrapped_swap_buffers_callback_.get()) {
wrapped_swap_buffers_callback_->Run();
}
}
} // namespace gpu } // namespace gpu
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
class AudioMessageFilter; class AudioMessageFilter;
class GURL; class GURL;
class SkBitmap; class SkBitmap;
class Task;
namespace base { namespace base {
class MessageLoopProxy; class MessageLoopProxy;
...@@ -165,11 +166,6 @@ class PluginDelegate { ...@@ -165,11 +166,6 @@ class PluginDelegate {
// Initialize the context. // Initialize the context.
virtual bool Init(const int32* attrib_list) = 0; virtual bool Init(const int32* attrib_list) = 0;
// Set an optional callback that will be invoked when the side effects of
// a SwapBuffers call become visible to the compositor. Takes ownership
// of the callback.
virtual void SetSwapBuffersCallback(Callback0::Type* callback) = 0;
// If the plugin instance is backed by an OpenGL, return its ID in the // If the plugin instance is backed by an OpenGL, return its ID in the
// compositors namespace. Otherwise return 0. Returns 0 by default. // compositors namespace. Otherwise return 0. Returns 0 by default.
virtual unsigned GetBackingTextureId() = 0; virtual unsigned GetBackingTextureId() = 0;
...@@ -186,6 +182,10 @@ class PluginDelegate { ...@@ -186,6 +182,10 @@ class PluginDelegate {
// Set an optional callback that will be invoked when the context is lost // Set an optional callback that will be invoked when the context is lost
// (e.g. gpu process crash). Takes ownership of the callback. // (e.g. gpu process crash). Takes ownership of the callback.
virtual void SetContextLostCallback(Callback0::Type* callback) = 0; virtual void SetContextLostCallback(Callback0::Type* callback) = 0;
// Run the task once the channel has been flushed. Takes care of deleting
// the task whether the echo succeeds or not.
virtual bool Echo(Task* task) = 0;
}; };
class PlatformAudio { class PlatformAudio {
......
...@@ -54,7 +54,8 @@ PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) ...@@ -54,7 +54,8 @@ PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance)
: Resource(instance), : Resource(instance),
bound_to_instance_(false), bound_to_instance_(false),
commit_pending_(false), commit_pending_(false),
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
} }
PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() {
...@@ -164,6 +165,9 @@ int32 PPB_Graphics3D_Impl::DoSwapBuffers() { ...@@ -164,6 +165,9 @@ int32 PPB_Graphics3D_Impl::DoSwapBuffers() {
if (gles2_impl()) if (gles2_impl())
gles2_impl()->SwapBuffers(); gles2_impl()->SwapBuffers();
platform_context_->Echo(method_factory_.NewRunnableMethod(
&PPB_Graphics3D_Impl::OnSwapBuffers));
return PP_OK_COMPLETIONPENDING; return PP_OK_COMPLETIONPENDING;
} }
...@@ -199,8 +203,6 @@ bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context, ...@@ -199,8 +203,6 @@ bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context,
platform_context_->SetContextLostCallback( platform_context_->SetContextLostCallback(
callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost)); callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost));
platform_context_->SetSwapBuffersCallback(
callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnSwapBuffers));
return true; return true;
} }
......
...@@ -87,6 +87,7 @@ class PPB_Graphics3D_Impl : public ::ppapi::Resource, ...@@ -87,6 +87,7 @@ class PPB_Graphics3D_Impl : public ::ppapi::Resource,
// PluginDelegate's 3D Context. Responsible for providing the command buffer. // PluginDelegate's 3D Context. Responsible for providing the command buffer.
scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_; scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_;
base::ScopedCallbackFactory<PPB_Graphics3D_Impl> callback_factory_; base::ScopedCallbackFactory<PPB_Graphics3D_Impl> callback_factory_;
ScopedRunnableMethodFactory<PPB_Graphics3D_Impl> method_factory_;
DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl); DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
}; };
......
...@@ -24,7 +24,8 @@ PPB_Surface3D_Impl::PPB_Surface3D_Impl(PP_Instance instance) ...@@ -24,7 +24,8 @@ PPB_Surface3D_Impl::PPB_Surface3D_Impl(PP_Instance instance)
: Resource(instance), : Resource(instance),
bound_to_instance_(false), bound_to_instance_(false),
swap_initiated_(false), swap_initiated_(false),
context_(NULL) { context_(NULL),
method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
} }
PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { PPB_Surface3D_Impl::~PPB_Surface3D_Impl() {
...@@ -81,6 +82,8 @@ int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { ...@@ -81,6 +82,8 @@ int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) {
gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); gpu::gles2::GLES2Implementation* impl = context_->gles2_impl();
if (impl) if (impl)
context_->gles2_impl()->SwapBuffers(); context_->gles2_impl()->SwapBuffers();
context_->platform_context()->Echo(method_factory_.NewRunnableMethod(
&PPB_Surface3D_Impl::OnSwapBuffers));
// |SwapBuffers()| should not call us back synchronously, but double-check. // |SwapBuffers()| should not call us back synchronously, but double-check.
DCHECK(!swap_callback_->completed()); DCHECK(!swap_callback_->completed());
return PP_OK_COMPLETIONPENDING; return PP_OK_COMPLETIONPENDING;
...@@ -108,8 +111,6 @@ bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { ...@@ -108,8 +111,6 @@ bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) {
plugin_instance->BindGraphics(pp_instance(), 0); plugin_instance->BindGraphics(pp_instance(), 0);
// Unbind from the current context. // Unbind from the current context.
if (context_ && context_->platform_context())
context_->platform_context()->SetSwapBuffersCallback(NULL);
if (context && context->platform_context()) { if (context && context->platform_context()) {
// Resize the backing texture to the size of the instance when it is bound. // Resize the backing texture to the size of the instance when it is bound.
// TODO(alokp): This should be the responsibility of plugins. // TODO(alokp): This should be the responsibility of plugins.
...@@ -118,9 +119,6 @@ bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { ...@@ -118,9 +119,6 @@ bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) {
const gfx::Size& size = plugin_instance->position().size(); const gfx::Size& size = plugin_instance->position().size();
impl->ResizeCHROMIUM(size.width(), size.height()); impl->ResizeCHROMIUM(size.width(), size.height());
} }
context->platform_context()->SetSwapBuffersCallback(
NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers));
} }
context_ = context; context_ = context;
return true; return true;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define WEBKIT_PLUGINS_PPAPI_PPB_SURFACE_3D_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_SURFACE_3D_IMPL_H_
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/task.h"
#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/ppb_surface_3d_api.h" #include "ppapi/thunk/ppb_surface_3d_api.h"
#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/callbacks.h"
...@@ -75,6 +76,8 @@ class PPB_Surface3D_Impl : public ::ppapi::Resource, ...@@ -75,6 +76,8 @@ class PPB_Surface3D_Impl : public ::ppapi::Resource,
// The context this surface is currently bound to. // The context this surface is currently bound to.
PPB_Context3D_Impl* context_; PPB_Context3D_Impl* context_;
ScopedRunnableMethodFactory<PPB_Surface3D_Impl> method_factory_;
DISALLOW_COPY_AND_ASSIGN(PPB_Surface3D_Impl); DISALLOW_COPY_AND_ASSIGN(PPB_Surface3D_Impl);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment