From a81c24c6c04e6f86dc3f2b902c69f4df4f8d614f Mon Sep 17 00:00:00 2001 From: "vrk@google.com" Date: Thu, 28 Jul 2011 22:16:30 +0000 Subject: [PATCH] Remove ReadWriteTokens from GpuVideoDecodeAccelerator + fallout With apatrick's changes in r93066, we no longer need to manually sync up with the command buffer before handling IPC messages in GpuVideoDecodeAccelerator. BUG=none TEST=gles2 example runs without crashing Review URL: http://codereview.chromium.org/7521015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94561 0039d316-1c4b-4281-b951-d872f2087c98 --- content/common/gpu/gpu_command_buffer_stub.cc | 13 ---- content/common/gpu/gpu_command_buffer_stub.h | 15 ---- content/common/gpu/gpu_messages.h | 31 ++------ .../gpu/media/gpu_video_decode_accelerator.cc | 71 +------------------ .../gpu/media/gpu_video_decode_accelerator.h | 28 ++------ content/renderer/gpu/command_buffer_proxy.cc | 3 +- content/renderer/gpu/command_buffer_proxy.h | 1 - content/renderer/gpu/gpu_channel_host.cc | 3 +- content/renderer/gpu/gpu_channel_host.h | 1 - .../gpu/gpu_video_decode_accelerator_host.cc | 43 ++--------- .../gpu/gpu_video_decode_accelerator_host.h | 22 ------ .../pepper_platform_video_decoder_impl.cc | 8 +-- .../pepper_platform_video_decoder_impl.h | 11 +-- .../renderer/pepper_plugin_delegate_impl.cc | 6 +- .../renderer/pepper_plugin_delegate_impl.h | 7 +- gpu/command_buffer/common/command_buffer.cc | 31 -------- gpu/command_buffer/common/command_buffer.h | 21 ------ gpu/command_buffer/service/gpu_scheduler.cc | 8 --- gpu/command_buffer/service/gpu_scheduler.h | 6 -- gpu/gpu.gyp | 1 - webkit/plugins/ppapi/mock_plugin_delegate.cc | 3 +- webkit/plugins/ppapi/mock_plugin_delegate.h | 7 +- webkit/plugins/ppapi/plugin_delegate.h | 4 +- .../plugins/ppapi/ppb_video_decoder_impl.cc | 32 +++++++-- webkit/plugins/ppapi/ppb_video_decoder_impl.h | 16 +++++ 25 files changed, 75 insertions(+), 317 deletions(-) delete mode 100644 gpu/command_buffer/common/command_buffer.cc diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc index a93c1738843508..721b3b0909dedd 100644 --- a/content/common/gpu/gpu_command_buffer_stub.cc +++ b/content/common/gpu/gpu_command_buffer_stub.cc @@ -5,7 +5,6 @@ #if defined(ENABLE_GPU) #include "base/bind.h" -#include "base/callback.h" #include "base/debug/trace_event.h" #include "base/process_util.h" #include "base/shared_memory.h" @@ -202,8 +201,6 @@ void GpuCommandBufferStub::OnInitialize( NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); scheduler_->SetScheduledCallback( NewCallback(channel_, &GpuChannel::OnScheduled)); - scheduler_->SetTokenCallback(base::Bind( - &GpuCommandBufferStub::OnSetToken, base::Unretained(this))); if (watchdog_) scheduler_->SetCommandProcessedCallback( NewCallback(this, &GpuCommandBufferStub::OnCommandProcessed)); @@ -502,16 +499,6 @@ void GpuCommandBufferStub::AcceleratedSurfaceBuffersSwapped( } #endif // defined(OS_MACOSX) -void GpuCommandBufferStub::AddSetTokenCallback( - const base::Callback& callback) { - set_token_callbacks_.push_back(callback); -} - -void GpuCommandBufferStub::OnSetToken(int32 token) { - for (size_t i = 0; i < set_token_callbacks_.size(); ++i) - set_token_callbacks_[i].Run(token); -} - void GpuCommandBufferStub::ResizeCallback(gfx::Size size) { if (handle_ == gfx::kNullPluginWindow) { scheduler_->decoder()->ResizeOffscreenFrameBuffer(size); diff --git a/content/common/gpu/gpu_command_buffer_stub.h b/content/common/gpu/gpu_command_buffer_stub.h index 26dd64b2db3e7f..dd84f5d6c47424 100644 --- a/content/common/gpu/gpu_command_buffer_stub.h +++ b/content/common/gpu/gpu_command_buffer_stub.h @@ -71,12 +71,6 @@ class GpuCommandBufferStub // to the same renderer process. int32 route_id() const { return route_id_; } - // Return the current token in the underlying command buffer, or 0 if not yet - // initialized. - int32 token() const { - return command_buffer_.get() ? command_buffer_->GetState().token : 0; - } - #if defined(OS_WIN) // Called only by the compositor window's window proc void OnCompositorWindowPainted(); @@ -89,11 +83,6 @@ class GpuCommandBufferStub void AcceleratedSurfaceBuffersSwapped(uint64 swap_buffers_count); #endif // defined(OS_MACOSX) - // Register a callback to be Run() whenever the underlying scheduler receives - // a set_token() call. The callback will be Run() with the just-set token as - // its only parameter. Multiple callbacks may be registered. - void AddSetTokenCallback(const base::Callback& callback); - private: // Cleans up and sends reply if OnInitialize failed. void OnInitializeFailed(IPC::Message* reply_message); @@ -138,9 +127,6 @@ class GpuCommandBufferStub void ResizeCallback(gfx::Size size); void ReportState(); - // Callback registered with GpuScheduler to receive set_token() notifications. - void OnSetToken(int32 token); - // The lifetime of objects of this class is managed by a GpuChannel. The // GpuChannels destroy all the GpuCommandBufferStubs that they own when they // are destroyed. So a raw pointer is safe. @@ -162,7 +148,6 @@ class GpuCommandBufferStub scoped_ptr command_buffer_; scoped_ptr scheduler_; - std::vector > set_token_callbacks_; // SetParent may be called before Initialize, in which case we need to keep // around the parent stub, so that Initialize can set the parent correctly. diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h index 416655314df895..477f0db0f533d4 100644 --- a/content/common/gpu/gpu_messages.h +++ b/content/common/gpu/gpu_messages.h @@ -100,11 +100,6 @@ IPC_STRUCT_TRAITS_BEGIN(GPUInfo) #endif IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(gpu::ReadWriteTokens) - IPC_STRUCT_TRAITS_MEMBER(last_token_read) - IPC_STRUCT_TRAITS_MEMBER(last_token_written) -IPC_STRUCT_TRAITS_END() - IPC_ENUM_TRAITS(content::CauseForGpuLaunch) IPC_ENUM_TRAITS(gpu::error::ContextLostReason) @@ -458,45 +453,33 @@ IPC_MESSAGE_ROUTED1(GpuTransportTextureHostMsg_TextureUpdated, //------------------------------------------------------------------------------ // Accelerated Video Decoder Messages // These messages are sent from Renderer process to GPU process. -// -// These messages defer execution until |tokens.last_token_written| is -// seen (using |tokens.last_token_read| as a wrap-around indicator). The -// implementation REQUIRES that |tokens| be the first parameter of these -// messages. // Send input buffer for decoding. -IPC_MESSAGE_ROUTED4(AcceleratedVideoDecoderMsg_Decode, - gpu::ReadWriteTokens, /* tokens */ +IPC_MESSAGE_ROUTED3(AcceleratedVideoDecoderMsg_Decode, base::SharedMemoryHandle, /* input_buffer_handle */ int32, /* bitstream_buffer_id */ int32) /* size */ // Sent from Renderer process to the GPU process to give the texture IDs for -// the textures the decoder will use for output. Delays evaluation until -// |token.second| is seen. -IPC_MESSAGE_ROUTED4(AcceleratedVideoDecoderMsg_AssignPictureBuffers, - gpu::ReadWriteTokens, /* tokens */ +// the textures the decoder will use for output. +IPC_MESSAGE_ROUTED3(AcceleratedVideoDecoderMsg_AssignPictureBuffers, std::vector, /* Picture buffer ID */ std::vector, /* Texture ID */ std::vector) /* Size */ // Send from Renderer process to the GPU process to recycle the given picture // buffer for further decoding. -IPC_MESSAGE_ROUTED2(AcceleratedVideoDecoderMsg_ReusePictureBuffer, - gpu::ReadWriteTokens, /* tokens */ +IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderMsg_ReusePictureBuffer, int32) /* Picture buffer ID */ // Send flush request to the decoder. -IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderMsg_Flush, - gpu::ReadWriteTokens) /* tokens */ +IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderMsg_Flush) // Send reset request to the decoder. -IPC_MESSAGE_ROUTED1(AcceleratedVideoDecoderMsg_Reset, - gpu::ReadWriteTokens) /* tokens */ +IPC_MESSAGE_ROUTED0(AcceleratedVideoDecoderMsg_Reset) // Send destroy request to the decoder. -IPC_SYNC_MESSAGE_ROUTED1_0(AcceleratedVideoDecoderMsg_Destroy, - gpu::ReadWriteTokens) /* tokens */ +IPC_SYNC_MESSAGE_ROUTED0_0(AcceleratedVideoDecoderMsg_Destroy) //------------------------------------------------------------------------------ // Accelerated Video Decoder Host Messages diff --git a/content/common/gpu/media/gpu_video_decode_accelerator.cc b/content/common/gpu/media/gpu_video_decode_accelerator.cc index cfc4c0f9db78fd..855041b44afd02 100644 --- a/content/common/gpu/media/gpu_video_decode_accelerator.cc +++ b/content/common/gpu/media/gpu_video_decode_accelerator.cc @@ -29,63 +29,12 @@ GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator( host_route_id_(host_route_id), stub_(stub), video_decode_accelerator_(NULL) { - // stub_ owns and will always outlive this object. - stub_->AddSetTokenCallback(base::Bind( - &GpuVideoDecodeAccelerator::OnSetToken, base::Unretained(this))); } GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { - STLDeleteElements(&deferred_messages_); - // TODO(fischman/vrk): We need to synchronously wait for the OMX decoder - // to finish shutting down. -} - -void GpuVideoDecodeAccelerator::OnSetToken(int32 token) { - // Note: this always retries all deferred messages on every token arrival. - // There's an optimization to be done here by only trying messages which are - // waiting for tokens which are earlier than |token|. - std::vector deferred_messages_copy; - std::swap(deferred_messages_copy, deferred_messages_); - for (size_t i = 0; i < deferred_messages_copy.size(); ++i) - OnMessageReceived(*deferred_messages_copy[i]); - STLDeleteElements(&deferred_messages_copy); -} - -bool GpuVideoDecodeAccelerator::DeferMessageIfNeeded( - const IPC::Message& msg, bool* deferred) { - // Only consider deferring for message types that need it. - switch (msg.type()) { - case AcceleratedVideoDecoderMsg_Decode::ID: - case AcceleratedVideoDecoderMsg_AssignPictureBuffers::ID: - case AcceleratedVideoDecoderMsg_ReusePictureBuffer::ID: - case AcceleratedVideoDecoderMsg_Flush::ID: - case AcceleratedVideoDecoderMsg_Reset::ID: - case AcceleratedVideoDecoderMsg_Destroy::ID: - break; - default: - return false; - } - - gpu::ReadWriteTokens tokens; - void* iter = NULL; - if (!IPC::ParamTraits::Read(&msg, &iter, &tokens)) - return false; - if (tokens.InRange(stub_->token())) { - deferred_messages_.push_back(new IPC::Message(msg)); - *deferred = true; - } else { - *deferred = false; - } - return true; } bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { - bool deferred = false; - if (!DeferMessageIfNeeded(msg, &deferred)) - return false; - if (deferred) - return true; - bool handled = true; IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) @@ -101,14 +50,6 @@ bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { return handled; } -void GpuVideoDecodeAccelerator::OnChannelConnected(int32 peer_pid) { - // TODO(vmr): Do we have to react on channel connections? -} - -void GpuVideoDecodeAccelerator::OnChannelError() { - // TODO(vmr): Do we have to react on channel errors? -} - void GpuVideoDecodeAccelerator::ProvidePictureBuffers( uint32 requested_num_of_buffers, const gfx::Size& dimensions) { if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers( @@ -167,14 +108,12 @@ void GpuVideoDecodeAccelerator::Initialize(const std::vector& configs) { } void GpuVideoDecodeAccelerator::OnDecode( - const gpu::ReadWriteTokens&, /* tokens */ base::SharedMemoryHandle handle, int32 id, int32 size) { DCHECK(video_decode_accelerator_.get()); video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size)); } void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( - const gpu::ReadWriteTokens& /* tokens */, const std::vector& buffer_ids, const std::vector& texture_ids, const std::vector& sizes) { @@ -197,26 +136,22 @@ void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( } void GpuVideoDecodeAccelerator::OnReusePictureBuffer( - const gpu::ReadWriteTokens& /* tokens */, int32 picture_buffer_id) { DCHECK(video_decode_accelerator_.get()); video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id); } -void GpuVideoDecodeAccelerator::OnFlush( - const gpu::ReadWriteTokens& /* tokens */) { +void GpuVideoDecodeAccelerator::OnFlush() { DCHECK(video_decode_accelerator_.get()); video_decode_accelerator_->Flush(); } -void GpuVideoDecodeAccelerator::OnReset( - const gpu::ReadWriteTokens& /* tokens */) { +void GpuVideoDecodeAccelerator::OnReset() { DCHECK(video_decode_accelerator_.get()); video_decode_accelerator_->Reset(); } -void GpuVideoDecodeAccelerator::OnDestroy( - const gpu::ReadWriteTokens& /* tokens */) { +void GpuVideoDecodeAccelerator::OnDestroy() { DCHECK(video_decode_accelerator_.get()); video_decode_accelerator_->Destroy(); } diff --git a/content/common/gpu/media/gpu_video_decode_accelerator.h b/content/common/gpu/media/gpu_video_decode_accelerator.h index f92df105ffcb86..6c06432fe542d4 100644 --- a/content/common/gpu/media/gpu_video_decode_accelerator.h +++ b/content/common/gpu/media/gpu_video_decode_accelerator.h @@ -13,10 +13,6 @@ #include "ipc/ipc_message.h" #include "media/video/video_decode_accelerator.h" -namespace gpu { -class ReadWriteTokens; -} - class GpuCommandBufferStub; class GpuVideoDecodeAccelerator @@ -31,8 +27,6 @@ class GpuVideoDecodeAccelerator // IPC::Channel::Listener implementation. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; - virtual void OnChannelError() OVERRIDE; // media::VideoDecodeAccelerator::Client implementation. virtual void ProvidePictureBuffers( @@ -49,33 +43,22 @@ class GpuVideoDecodeAccelerator // Function to delegate sending to actual sender. virtual bool Send(IPC::Message* message); - // Callback to be fired when the underlying stub receives a new token. - void OnSetToken(int32 token); - // Initialize the accelerator with the given configuration. void Initialize(const std::vector& configs); private: - // Defers |msg| for later processing if it specifies a write token that hasn't - // come to pass yet, and set |*deferred| to true. Return false if the message - // failed to parse. - bool DeferMessageIfNeeded(const IPC::Message& msg, bool* deferred); // Handlers for IPC messages. - void OnDecode( - const gpu::ReadWriteTokens& /* tokens */, - base::SharedMemoryHandle handle, int32 id, int32 size); + void OnDecode(base::SharedMemoryHandle handle, int32 id, int32 size); void OnAssignPictureBuffers( - const gpu::ReadWriteTokens& /* tokens */, const std::vector& buffer_ids, const std::vector& texture_ids, const std::vector& sizes); void OnReusePictureBuffer( - const gpu::ReadWriteTokens& /* tokens */, int32 picture_buffer_id); - void OnFlush(const gpu::ReadWriteTokens& /* tokens */); - void OnReset(const gpu::ReadWriteTokens& /* tokens */); - void OnDestroy(const gpu::ReadWriteTokens& /* tokens */); + void OnFlush(); + void OnReset(); + void OnDestroy(); // Pointer to the IPC message sender. IPC::Message::Sender* sender_; @@ -83,9 +66,6 @@ class GpuVideoDecodeAccelerator // Route ID to communicate with the host. int32 host_route_id_; - // Messages deferred for later processing when their tokens have come to pass. - std::vector deferred_messages_; - // Unowned pointer to the underlying GpuCommandBufferStub. GpuCommandBufferStub* stub_; diff --git a/content/renderer/gpu/command_buffer_proxy.cc b/content/renderer/gpu/command_buffer_proxy.cc index 53b7f674ff4584..c4ec7a7667361a 100644 --- a/content/renderer/gpu/command_buffer_proxy.cc +++ b/content/renderer/gpu/command_buffer_proxy.cc @@ -394,10 +394,9 @@ void CommandBufferProxy::SetNotifyRepaintTask(Task* task) { scoped_refptr CommandBufferProxy::CreateVideoDecoder( const std::vector& configs, - gpu::CommandBufferHelper* cmd_buffer_helper, media::VideoDecodeAccelerator::Client* client) { video_decoder_host_ = new GpuVideoDecodeAcceleratorHost( - channel_, route_id_, cmd_buffer_helper, client); + channel_, route_id_, client); if (!Send(new GpuCommandBufferMsg_CreateVideoDecoder(route_id_, configs))) { LOG(ERROR) << "Send(GpuChannelMsg_CreateVideoDecoder) failed"; diff --git a/content/renderer/gpu/command_buffer_proxy.h b/content/renderer/gpu/command_buffer_proxy.h index 3ae3ff5827ade2..c8600f8a84f33d 100644 --- a/content/renderer/gpu/command_buffer_proxy.h +++ b/content/renderer/gpu/command_buffer_proxy.h @@ -91,7 +91,6 @@ class CommandBufferProxy : public gpu::CommandBuffer, // notified of an error later. scoped_refptr CreateVideoDecoder( const std::vector& configs, - gpu::CommandBufferHelper* cmd_buffer_helper, media::VideoDecodeAccelerator::Client* client); #if defined(OS_MACOSX) diff --git a/content/renderer/gpu/gpu_channel_host.cc b/content/renderer/gpu/gpu_channel_host.cc index 6b17fbcbedf2bc..ee79249cff227a 100644 --- a/content/renderer/gpu/gpu_channel_host.cc +++ b/content/renderer/gpu/gpu_channel_host.cc @@ -131,12 +131,11 @@ CommandBufferProxy* GpuChannelHost::CreateViewCommandBuffer( GpuVideoDecodeAcceleratorHost* GpuChannelHost::CreateVideoDecoder( int command_buffer_route_id, const std::vector& configs, - gpu::CommandBufferHelper* cmd_buffer_helper, media::VideoDecodeAccelerator::Client* client) { ProxyMap::iterator it = proxies_.find(command_buffer_route_id); DCHECK(it != proxies_.end()); CommandBufferProxy* proxy = it->second; - return proxy->CreateVideoDecoder(configs, cmd_buffer_helper, client); + return proxy->CreateVideoDecoder(configs, client); } CommandBufferProxy* GpuChannelHost::CreateOffscreenCommandBuffer( diff --git a/content/renderer/gpu/gpu_channel_host.h b/content/renderer/gpu/gpu_channel_host.h index 6688566272b333..c2eb9ff3378147 100644 --- a/content/renderer/gpu/gpu_channel_host.h +++ b/content/renderer/gpu/gpu_channel_host.h @@ -85,7 +85,6 @@ class GpuChannelHost : public IPC::Channel::Listener, GpuVideoDecodeAcceleratorHost* CreateVideoDecoder( int command_buffer_route_id, const std::vector& configs, - gpu::CommandBufferHelper* cmd_buffer_helper, media::VideoDecodeAccelerator::Client* client); // Destroy a command buffer created by this channel. diff --git a/content/renderer/gpu/gpu_video_decode_accelerator_host.cc b/content/renderer/gpu/gpu_video_decode_accelerator_host.cc index 4e77e8d84c174c..1b083aa53e6601 100644 --- a/content/renderer/gpu/gpu_video_decode_accelerator_host.cc +++ b/content/renderer/gpu/gpu_video_decode_accelerator_host.cc @@ -7,30 +7,23 @@ #include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" -#include "base/shared_memory.h" #include "base/task.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/view_messages.h" #include "content/renderer/render_thread.h" -#include "gpu/command_buffer/client/cmd_buffer_helper.h" -#include "gpu/command_buffer/common/command_buffer.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" -#include "ipc/ipc_platform_file.h" using media::VideoDecodeAccelerator; GpuVideoDecodeAcceleratorHost::GpuVideoDecodeAcceleratorHost( IPC::Message::Sender* ipc_sender, int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper, VideoDecodeAccelerator::Client* client) : ipc_sender_(ipc_sender), command_buffer_route_id_(command_buffer_route_id), - cmd_buffer_helper_(cmd_buffer_helper), client_(client) { DCHECK(ipc_sender_); - DCHECK(cmd_buffer_helper_); DCHECK(client_); DCHECK(RenderThread::current()); DCHECK_EQ(RenderThread::current()->message_loop(), MessageLoop::current()); @@ -39,7 +32,6 @@ GpuVideoDecodeAcceleratorHost::GpuVideoDecodeAcceleratorHost( GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() {} void GpuVideoDecodeAcceleratorHost::OnChannelError() { - cmd_buffer_helper_ = NULL; ipc_sender_ = NULL; } @@ -69,26 +61,6 @@ bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { return handled; } -gpu::ReadWriteTokens GpuVideoDecodeAcceleratorHost::SyncTokens() { - DCHECK(CalledOnValidThread()); - DCHECK(cmd_buffer_helper_); - - // SyncTokens() is only called when creating new IPC messages. - // Calling SyncTokens() with a NULL command buffer means that the client is - // trying to send an IPC message over a channel that is no longer - // valid, so the error message that is sent in Send() for a null - // |ipc_sender| also accounts for the error case below. - if (!cmd_buffer_helper_) - return gpu::ReadWriteTokens(); - - // Note that the order below matters. InsertToken() must happen before - // Flush() and last_token_read() should be read before InsertToken(). - int32 read = cmd_buffer_helper_->last_token_read(); - int32 written = cmd_buffer_helper_->InsertToken(); - cmd_buffer_helper_->Flush(); - return gpu::ReadWriteTokens(read, written); -} - bool GpuVideoDecodeAcceleratorHost::Initialize( const std::vector& configs) { NOTREACHED(); @@ -99,7 +71,7 @@ void GpuVideoDecodeAcceleratorHost::Decode( const media::BitstreamBuffer& bitstream_buffer) { DCHECK(CalledOnValidThread()); Send(new AcceleratedVideoDecoderMsg_Decode( - command_buffer_route_id_, SyncTokens(), bitstream_buffer.handle(), + command_buffer_route_id_, bitstream_buffer.handle(), bitstream_buffer.id(), bitstream_buffer.size())); } @@ -117,32 +89,29 @@ void GpuVideoDecodeAcceleratorHost::AssignPictureBuffers( sizes.push_back(buffer.size()); } Send(new AcceleratedVideoDecoderMsg_AssignPictureBuffers( - command_buffer_route_id_, SyncTokens(), buffer_ids, texture_ids, sizes)); + command_buffer_route_id_, buffer_ids, texture_ids, sizes)); } void GpuVideoDecodeAcceleratorHost::ReusePictureBuffer( int32 picture_buffer_id) { DCHECK(CalledOnValidThread()); Send(new AcceleratedVideoDecoderMsg_ReusePictureBuffer( - command_buffer_route_id_, SyncTokens(), picture_buffer_id)); + command_buffer_route_id_, picture_buffer_id)); } void GpuVideoDecodeAcceleratorHost::Flush() { DCHECK(CalledOnValidThread()); - Send(new AcceleratedVideoDecoderMsg_Flush( - command_buffer_route_id_, SyncTokens())); + Send(new AcceleratedVideoDecoderMsg_Flush(command_buffer_route_id_)); } void GpuVideoDecodeAcceleratorHost::Reset() { DCHECK(CalledOnValidThread()); - Send(new AcceleratedVideoDecoderMsg_Reset( - command_buffer_route_id_, SyncTokens())); + Send(new AcceleratedVideoDecoderMsg_Reset(command_buffer_route_id_)); } void GpuVideoDecodeAcceleratorHost::Destroy() { DCHECK(CalledOnValidThread()); - Send(new AcceleratedVideoDecoderMsg_Destroy( - command_buffer_route_id_, SyncTokens())); + Send(new AcceleratedVideoDecoderMsg_Destroy(command_buffer_route_id_)); } void GpuVideoDecodeAcceleratorHost::Send(IPC::Message* message) { diff --git a/content/renderer/gpu/gpu_video_decode_accelerator_host.h b/content/renderer/gpu/gpu_video_decode_accelerator_host.h index 9f65da8a8f36c6..5a913ae4623b23 100644 --- a/content/renderer/gpu/gpu_video_decode_accelerator_host.h +++ b/content/renderer/gpu/gpu_video_decode_accelerator_host.h @@ -7,19 +7,10 @@ #include -#include "base/memory/scoped_ptr.h" -#include "base/shared_memory.h" #include "base/threading/non_thread_safe.h" #include "ipc/ipc_channel.h" #include "media/video/video_decode_accelerator.h" -class MessageLoop; -class MessageRouter; -namespace gpu { -class CommandBufferHelper; -class ReadWriteTokens; -} - // This class is used to talk to VideoDecodeAccelerator in the Gpu process // through IPC messages. class GpuVideoDecodeAcceleratorHost @@ -31,7 +22,6 @@ class GpuVideoDecodeAcceleratorHost // |ipc_sender| is used to send IPC messages to Gpu process. GpuVideoDecodeAcceleratorHost(IPC::Message::Sender* ipc_sender, int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper, media::VideoDecodeAccelerator::Client* client); virtual ~GpuVideoDecodeAcceleratorHost(); @@ -50,10 +40,6 @@ class GpuVideoDecodeAcceleratorHost virtual void Destroy() OVERRIDE; private: - // Insert a token into the command buffer and return a token-pair suitable for - // sending over IPC for synchronization with the command buffer. - gpu::ReadWriteTokens SyncTokens(); - void Send(IPC::Message* message); void OnBitstreamBufferProcessed(int32 bitstream_buffer_id); @@ -78,14 +64,6 @@ class GpuVideoDecodeAcceleratorHost // attempting to use an outdated or reused route id. int32 command_buffer_route_id_; - // Helper for the command buffer associated with the context the GPU Video - // Decoder uses. - // TODO(fischman): in the out-of-process case, this won't work - // (context3d->gles2_impl() will be NULL), and will have to be replaced with a - // dedicated message such as WaitForToken, which will serialize subsequent - // message processing behind it. - gpu::CommandBufferHelper* cmd_buffer_helper_; - // Reference to the client that will receive callbacks from the decoder. media::VideoDecodeAccelerator::Client* client_; diff --git a/content/renderer/pepper_platform_video_decoder_impl.cc b/content/renderer/pepper_platform_video_decoder_impl.cc index 43079d9075fb6d..29667ffe528864 100644 --- a/content/renderer/pepper_platform_video_decoder_impl.cc +++ b/content/renderer/pepper_platform_video_decoder_impl.cc @@ -16,11 +16,9 @@ using media::BitstreamBuffer; PlatformVideoDecoderImpl::PlatformVideoDecoderImpl( VideoDecodeAccelerator::Client* client, - int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper) + int32 command_buffer_route_id) : client_(client), - command_buffer_route_id_(command_buffer_route_id), - cmd_buffer_helper_(cmd_buffer_helper) { + command_buffer_route_id_(command_buffer_route_id) { DCHECK(client); } @@ -47,7 +45,7 @@ bool PlatformVideoDecoderImpl::Initialize(const std::vector& configs) { // Send IPC message to initialize decoder in GPU process. decoder_ = channel->CreateVideoDecoder( - command_buffer_route_id_, configs, cmd_buffer_helper_, this); + command_buffer_route_id_, configs, this); return true; } diff --git a/content/renderer/pepper_platform_video_decoder_impl.h b/content/renderer/pepper_platform_video_decoder_impl.h index 8f6a45434a3b42..d1e8e55f24f492 100644 --- a/content/renderer/pepper_platform_video_decoder_impl.h +++ b/content/renderer/pepper_platform_video_decoder_impl.h @@ -12,19 +12,13 @@ #include "media/video/video_decode_accelerator.h" #include "webkit/plugins/ppapi/plugin_delegate.h" -class GpuChannelHost; -namespace gpu { -class CommandBufferHelper; -} - class PlatformVideoDecoderImpl : public webkit::ppapi::PluginDelegate::PlatformVideoDecoder, public media::VideoDecodeAccelerator::Client { public: PlatformVideoDecoderImpl( media::VideoDecodeAccelerator::Client* client, - int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper); + int32 command_buffer_route_id); // PlatformVideoDecoder (a.k.a. VideoDecodeAccelerator) implementation. virtual bool Initialize(const std::vector& configs) OVERRIDE; @@ -62,9 +56,6 @@ class PlatformVideoDecoderImpl // Route ID for the command buffer associated with video decoder's context. int32 command_buffer_route_id_; - // Helper for the command buffer associated with video decoder's context. - gpu::CommandBufferHelper* cmd_buffer_helper_; - // Holds a GpuVideoDecodeAcceleratorHost. scoped_refptr decoder_; diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc index 6ba3f63be92004..3edf654bca58ac 100644 --- a/content/renderer/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper_plugin_delegate_impl.cc @@ -835,10 +835,8 @@ webkit::ppapi::PluginDelegate::PlatformContext3D* webkit::ppapi::PluginDelegate::PlatformVideoDecoder* PepperPluginDelegateImpl::CreateVideoDecoder( media::VideoDecodeAccelerator::Client* client, - int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper) { - return new PlatformVideoDecoderImpl( - client, command_buffer_route_id, cmd_buffer_helper); + int32 command_buffer_route_id) { + return new PlatformVideoDecoderImpl(client, command_buffer_route_id); } void PepperPluginDelegateImpl::NumberOfFindResultsChanged(int identifier, diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h index e920c4665b8b1d..6e351520a122c8 100644 --- a/content/renderer/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper_plugin_delegate_impl.h @@ -29,10 +29,6 @@ class Point; class Rect; } -namespace gpu { -class CommandBufferHelper; -} - namespace IPC { struct ChannelHandle; } @@ -184,8 +180,7 @@ class PepperPluginDelegateImpl virtual PlatformContext3D* CreateContext3D(); virtual PlatformVideoDecoder* CreateVideoDecoder( media::VideoDecodeAccelerator::Client* client, - int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper); + int32 command_buffer_route_id); virtual PpapiBroker* ConnectToPpapiBroker( webkit::ppapi::PPB_Broker_Impl* client); virtual void NumberOfFindResultsChanged(int identifier, diff --git a/gpu/command_buffer/common/command_buffer.cc b/gpu/command_buffer/common/command_buffer.cc deleted file mode 100644 index 5a12ed1f958e39..00000000000000 --- a/gpu/command_buffer/common/command_buffer.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 "../common/command_buffer.h" -#include "../common/logging.h" - -namespace gpu { - -ReadWriteTokens::ReadWriteTokens() - : last_token_read(-1), last_token_written(-1) { -} - -ReadWriteTokens::ReadWriteTokens(int32 read, int32 written) - : last_token_read(read), last_token_written(written) { -} - -bool ReadWriteTokens::InRange(int32 token) const { - int32 min = last_token_read; - int32 max = last_token_written; - GPU_DCHECK_GE(min, 0); - GPU_DCHECK_GE(max, 0); - if (min <= max) { - // token should be in [min .. max) - return (token >= min) && (token < max); - } - // token should be in [0 .. max) or [min .. wrap token) - return (token >= min) || (token < max); -} - -} // namespace gpu diff --git a/gpu/command_buffer/common/command_buffer.h b/gpu/command_buffer/common/command_buffer.h index 2eff201af4935f..b2997eeff02751 100644 --- a/gpu/command_buffer/common/command_buffer.h +++ b/gpu/command_buffer/common/command_buffer.h @@ -139,27 +139,6 @@ class CommandBuffer { DISALLOW_COPY_AND_ASSIGN(CommandBuffer); }; -// Synchronizing other mechanisms (such as IPC) with the CommandBuffer requires -// inserting (writing) a token into the buffer and knowing what the last token -// read at that point was. ReadWriteTokens is a convenience struct for passing -// these pairs around. Expected usage is to compare a current token to -// [last_token_read,last_token_written). -class ReadWriteTokens { - public: - ReadWriteTokens(int32 read, int32 written); - // Required to support pickling. Use by anything else will DCHECK in InRange. - ReadWriteTokens(); - - // Return true iff |value| is in the range described by |tokens|, accounting - // for (up to) one wrap-around. - bool InRange(int32 token) const; - - // These want to be private (and const) but can't in order to support - // pickling. - int32 last_token_read; - int32 last_token_written; -}; - } // namespace gpu #endif // GPU_COMMAND_BUFFER_COMMON_COMMAND_BUFFER_H_ diff --git a/gpu/command_buffer/service/gpu_scheduler.cc b/gpu/command_buffer/service/gpu_scheduler.cc index 8809b0548573da..15316eae4b8bc2 100644 --- a/gpu/command_buffer/service/gpu_scheduler.cc +++ b/gpu/command_buffer/service/gpu_scheduler.cc @@ -214,8 +214,6 @@ Buffer GpuScheduler::GetSharedMemoryBuffer(int32 shm_id) { void GpuScheduler::set_token(int32 token) { command_buffer_->SetToken(token); - if (!set_token_callback_.is_null()) - set_token_callback_.Run(token); } bool GpuScheduler::SetGetOffset(int32 offset) { @@ -251,12 +249,6 @@ void GpuScheduler::SetCommandProcessedCallback( command_processed_callback_.reset(callback); } -void GpuScheduler::SetTokenCallback( - const base::Callback& callback) { - DCHECK(set_token_callback_.is_null()); - set_token_callback_ = callback; -} - GpuScheduler::GpuScheduler(CommandBuffer* command_buffer, gles2::GLES2Decoder* decoder, CommandParser* parser) diff --git a/gpu/command_buffer/service/gpu_scheduler.h b/gpu/command_buffer/service/gpu_scheduler.h index 4ff0f3df2edef9..75ccc632df6b57 100644 --- a/gpu/command_buffer/service/gpu_scheduler.h +++ b/gpu/command_buffer/service/gpu_scheduler.h @@ -143,11 +143,6 @@ class GpuScheduler : public CommandBufferEngine { void SetCommandProcessedCallback(Callback0::Type* callback); - // Sets a callback which is called when set_token() is called, and passes the - // just-set token to the callback. DCHECKs that no callback has previously - // been registered for this notification. - void SetTokenCallback(const base::Callback& callback); - // Get the GLES2Decoder associated with this scheduler. gles2::GLES2Decoder* decoder() const { return decoder_.get(); } @@ -183,7 +178,6 @@ class GpuScheduler : public CommandBufferEngine { ScopedRunnableMethodFactory method_factory_; scoped_ptr wrapped_swap_buffers_callback_; scoped_ptr command_processed_callback_; - base::Callback set_token_callback_; }; } // namespace gpu diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index 22f0215e37d5d1..2c4bbfd0f418b3 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -46,7 +46,6 @@ 'command_buffer/common/buffer.h', 'command_buffer/common/cmd_buffer_common.h', 'command_buffer/common/cmd_buffer_common.cc', - 'command_buffer/common/command_buffer.cc', 'command_buffer/common/command_buffer.h', 'command_buffer/common/constants.h', 'command_buffer/common/gles2_cmd_ids_autogen.h', diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 1270504c47f754..9fe11e6d1d2716 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -46,8 +46,7 @@ MockPluginDelegate::PlatformContext3D* MockPluginDelegate::CreateContext3D() { MockPluginDelegate::PlatformVideoDecoder* MockPluginDelegate::CreateVideoDecoder( media::VideoDecodeAccelerator::Client* client, - int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper) { + int32 command_buffer_route_id) { return NULL; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index c58d4fdd4aead2..5a6c9f87916624 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -7,10 +7,6 @@ #include "webkit/plugins/ppapi/plugin_delegate.h" -namespace gpu { -class CommandBufferHelper; -} - namespace webkit { namespace ppapi { @@ -28,8 +24,7 @@ class MockPluginDelegate : public PluginDelegate { virtual PlatformContext3D* CreateContext3D(); virtual PlatformVideoDecoder* CreateVideoDecoder( media::VideoDecodeAccelerator::Client* client, - int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper); + int32 command_buffer_route_id); virtual PlatformAudio* CreateAudio(uint32_t sample_rate, uint32_t sample_count, PlatformAudio::Client* client); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index ebfda188af936f..7c2ad189559f16 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -46,7 +46,6 @@ class Rect; namespace gpu { class CommandBuffer; -class CommandBufferHelper; } namespace ppapi { @@ -264,8 +263,7 @@ class PluginDelegate { // The caller will own the pointer returned from this. virtual PlatformVideoDecoder* CreateVideoDecoder( media::VideoDecodeAccelerator::Client* client, - int32 command_buffer_route_id, - gpu::CommandBufferHelper* cmd_buffer_helper) = 0; + int32 command_buffer_route_id) = 0; // The caller is responsible for calling Shutdown() on the returned pointer // to clean up the corresponding resources allocated during this call. diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc index 849e5b8961cefa..4874998bb38ffd 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc @@ -37,15 +37,14 @@ PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), context3d_id_(0), flush_callback_(PP_BlockUntilComplete()), - reset_callback_(PP_BlockUntilComplete()) { + reset_callback_(PP_BlockUntilComplete()), + gles2_impl_(NULL) { ppp_videodecoder_ = static_cast(instance->module()-> GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); } PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { - if (context3d_id_) - ResourceTracker::Get()->UnrefResource(context3d_id_); } PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { @@ -70,13 +69,15 @@ int32_t PPB_VideoDecoder_Impl::Initialize( context3d_id_ = context_id; ResourceTracker::Get()->AddRefResource(context3d_id_); + int command_buffer_route_id = context3d->platform_context()->GetCommandBufferRouteId(); if (command_buffer_route_id == 0) return PP_ERROR_FAILED; - platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( - this, command_buffer_route_id, context3d->gles2_impl()->helper()); + this, command_buffer_route_id); + + gles2_impl_ = context3d->gles2_impl(); if (!platform_video_decoder_) return PP_ERROR_FAILED; @@ -95,6 +96,7 @@ int32_t PPB_VideoDecoder_Impl::Initialize( copied.push_back(static_cast(*current)); } + FlushCommandBuffer(); if (platform_video_decoder_->Initialize(copied)) { initialization_callback_ = callback; return PP_OK_COMPLETIONPENDING; @@ -120,6 +122,7 @@ int32_t PPB_VideoDecoder_Impl::Decode( CHECK(bitstream_buffer_callbacks_.insert(std::make_pair( bitstream_buffer->id, callback)).second); + FlushCommandBuffer(); platform_video_decoder_->Decode(decode_buffer); return PP_OK_COMPLETIONPENDING; } @@ -139,12 +142,16 @@ void PPB_VideoDecoder_Impl::AssignPictureBuffers( in_buf.texture_id); wrapped_buffers.push_back(buffer); } + + FlushCommandBuffer(); platform_video_decoder_->AssignPictureBuffers(wrapped_buffers); } void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { if (!platform_video_decoder_) return; + + FlushCommandBuffer(); platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); } @@ -156,6 +163,7 @@ int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { // TODO(fischman,vrk): consider implications of already-outstanding callback. flush_callback_ = callback; + FlushCommandBuffer(); platform_video_decoder_->Flush(); return PP_OK_COMPLETIONPENDING; } @@ -168,6 +176,7 @@ int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) { // TODO(fischman,vrk): consider implications of already-outstanding callback. reset_callback_ = callback; + FlushCommandBuffer(); platform_video_decoder_->Reset(); return PP_OK_COMPLETIONPENDING; } @@ -175,7 +184,12 @@ int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) { void PPB_VideoDecoder_Impl::Destroy() { if (!platform_video_decoder_) return; + + FlushCommandBuffer(); platform_video_decoder_->Destroy(); + gles2_impl_ = NULL; + if (context3d_id_) + ResourceTracker::Get()->UnrefResource(context3d_id_); platform_video_decoder_ = NULL; ppp_videodecoder_ = NULL; } @@ -268,5 +282,13 @@ void PPB_VideoDecoder_Impl::NotifyInitializeDone() { PP_RunAndClearCompletionCallback(&initialization_callback_, PP_OK); } +void PPB_VideoDecoder_Impl::FlushCommandBuffer() { + // For the out-of-process case, |gles2_impl_| will be NULL in the renderer + // process. The VideoDecoder_Proxy is charged with the responsibility of + // doing this Flush() in the analogous places in the plugin process. + if (gles2_impl_) + gles2_impl_->Flush(); +} + } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.h b/webkit/plugins/ppapi/ppb_video_decoder_impl.h index a1e2f07de40828..b6193e73e4f44a 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.h +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.h @@ -23,6 +23,12 @@ struct PP_VideoBitstreamBuffer_Dev; struct PPB_VideoDecoder_Dev; struct PPP_VideoDecoder_Dev; +namespace gpu { +namespace gles2 { +class GLES2Implementation; +} +} + namespace webkit { namespace ppapi { @@ -69,6 +75,9 @@ class PPB_VideoDecoder_Impl : public Resource, // done. typedef std::map CallbackById; + // Tell command buffer to process all commands it has received so far. + void FlushCommandBuffer(); + // This is NULL before initialization, and if this PPB_VideoDecoder_Impl is // swapped with another. scoped_refptr platform_video_decoder_; @@ -88,6 +97,13 @@ class PPB_VideoDecoder_Impl : public Resource, // Reference to the plugin requesting this interface. const PPP_VideoDecoder_Dev* ppp_videodecoder_; + // Reference to the GLES2Implementation owned by PPB_Context3D_Impl. + // PPB_Context3D_Impl is guaranteed to be alive for the lifetime of this + // class. + // In the out-of-process case, Context3D's gles2_impl() exists in the plugin + // process only, so gles2_impl_ is NULL in that case. + gpu::gles2::GLES2Implementation* gles2_impl_; + DISALLOW_COPY_AND_ASSIGN(PPB_VideoDecoder_Impl); };