Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1635)

Unified Diff: content/common/gpu/media/gpu_arc_accelerator.cc

Issue 1451353002: Implement GpuArcVideoService for arc video accelerator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/gpu_arc_accelerator.cc
diff --git a/content/common/gpu/media/gpu_arc_accelerator.cc b/content/common/gpu/media/gpu_arc_accelerator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e11a2a9aa2ec453182c554e2eb18a8399b0b517a
--- /dev/null
+++ b/content/common/gpu/media/gpu_arc_accelerator.cc
@@ -0,0 +1,222 @@
+// Copyright 2015 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 "content/common/gpu/media/gpu_arc_accelerator.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
+#include "content/common/gpu/gpu_channel.h"
+#include "content/common/gpu/gpu_messages.h"
+#include "ipc/ipc_listener.h"
+#include "ipc/ipc_message_macros.h"
+#include "base/synchronization/waitable_event.h"
+
+// HACK remove this before commit
+namespace media {
+ArcVideoAccelerator::Client::~Client() {}
+}
+
+namespace content {
+
+// Client's all methods are running on arc thread.
+class GpuArcAccelerator::Client : public IPC::Listener,
+ public IPC::Sender,
+ public media::ArcVideoAccelerator::Client,
+ public base::NonThreadSafe {
+ public:
+ // |owner| outlives Client.
+ Client(GpuArcAccelerator* owner,
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
+ : owner_(owner),
+ io_task_runner_(io_task_runner),
+ arc_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
+
+ ~Client() override {
+ DCHECK(CalledOnValidThread());
+ accelerator_.reset();
+ channel_->Close();
+ }
+
+ void Initialize(base::WaitableEvent* shutdown_event,
+ uint32_t device_type,
+ GpuChannel* gpu_channel) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!channel_);
+
+ IPC::ChannelHandle handle;
+ channel_ = IPC::SyncChannel::Create(handle, IPC::Channel::MODE_SERVER, this,
+ io_task_runner_, false, shutdown_event);
+#if defined(OS_POSIX)
+ base::ScopedFD client_fd = channel_->TakeClientFileDescriptor();
+ DCHECK(client_fd.is_valid());
+ handle.socket = base::FileDescriptor(client_fd.Pass());
+#endif
+
+#if 0
+ accelerator_.reset(new ArcVideoAcceleratorImp());
+#endif
+ uint32_t result = accelerator_->initialize(device_type, this);
+
+ gpu_channel->Send(new GpuHostMsg_ArcAcceleratorCreated(handle, result));
+ }
+
+ // IPC::Sender implementation:
+ bool Send(IPC::Message* msg) override {
+ DCHECK(msg);
+ return channel_->Send(msg);
+ }
+
+ // IPC::Listener implementation:
+ void OnChannelError() override {
+ DCHECK(CalledOnValidThread());
+ // RemoveClientOnArcThread will delete |this|.
+ owner_->RemoveClientOnArcThread(this);
+ }
+
+ // ArcVideoAccelerator::Client implementation:
+ void onBufferDone(size_t index) override {
+ DCHECK(CalledOnValidThread());
+ // channel_->Send(new ArcAcceleratorHostMsg_BufferDone(index));
+ }
+
+ void onOutputFormatChanged(
+ const media::ArcVideoAccelerator::VideoFormat& format) override {
+ DCHECK(CalledOnValidThread());
+ // channel_->Send(new ArcAcceleratorHostMsg_OutputFormatChanged(format));
+ }
+
+ // IPC::Listener implementation:
+ bool OnMessageReceived(const IPC::Message& msg) override {
+ DCHECK(CalledOnValidThread());
+
+ IPC_BEGIN_MESSAGE_MAP(Client, msg)
+ IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_BindSharedBuffer,
+ OnBindSharedBuffer)
+ IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_BindGraphicBuffer,
+ OnBindGraphicBuffer)
+ IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_UseBuffer, OnUseBuffer)
+ IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_SetBufferCount, OnSetBufferCount)
+ IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_Reset, OnReset)
+ IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_SetPixelFormat, OnSetPixelFormat)
+ IPC_MESSAGE_UNHANDLED(return false;)
+ IPC_END_MESSAGE_MAP()
+ return true;
+ }
+
+ void OnBindSharedBuffer(uint32_t port,
+ size_t index,
+ base::FileDescriptor ashmem_fd,
+ size_t offset,
+ size_t length,
+ uint32_t* result) {
+ *result = accelerator_->bindSharedBuffer(port, index, ashmem_fd.fd, offset,
+ length);
+ }
+
+ void OnBindGraphicBuffer(uint32_t port,
+ size_t index,
+ base::FileDescriptor dmabuf_fd,
+ uint32_t* result) {
+ *result = accelerator_->bindGraphicBuffer(port, index, dmabuf_fd.fd);
+ }
+
+ void OnUseBuffer(uint32_t port, size_t index, uint32_t* result) {
+ *result = accelerator_->useBuffer(port, index);
+ }
+
+ void OnSetBufferCount(uint32_t port,
+ size_t in_count,
+ size_t* out_count,
+ uint32_t* result) {
+ size_t count = in_count;
+ *result = accelerator_->setBufferCount(port, &count);
+ *out_count = count;
+ }
+
+ void OnReset() { accelerator_->reset(); }
+
+ void OnSetPixelFormat(uint32_t port,
+ uint32_t pixel_format,
+ uint32_t image_size,
+ uint32_t memory_type,
+ uint32_t* result) {
+ media::ArcVideoAccelerator::PixelFormat format = {
+ pixel_format, image_size, memory_type,
+ };
+ *result = accelerator_->setPixelFormat(port, &format);
+ }
+
+ private:
+ scoped_ptr<IPC::SyncChannel> channel_;
+ GpuArcAccelerator* owner_;
+ const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
+ const scoped_refptr<base::SingleThreadTaskRunner> arc_task_runner_;
+ scoped_ptr<media::ArcVideoAccelerator> accelerator_;
+};
+
+GpuArcAccelerator::GpuArcAccelerator(
+ GpuChannel* gpu_channel,
+ base::WaitableEvent* shutdown_event,
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
+ : gpu_channel_(gpu_channel),
+ shutdown_event_(shutdown_event),
+ io_task_runner_(io_task_runner),
+ task_runner_(base::ThreadTaskRunnerHandle::Get()),
+ arc_accelerator_thread_("ArcAcceleratorThread") {}
+
+GpuArcAccelerator::~GpuArcAccelerator() {
+ DCHECK(CalledOnValidThread());
+
+ if (!arc_accelerator_thread_.IsRunning())
+ return;
+
+ base::WaitableEvent done(false, false);
+ arc_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&GpuArcAccelerator::RemoveAllClientsOnArcThread,
+ base::Unretained(this), base::Unretained(&done)));
+ done.Wait();
+
+ arc_accelerator_thread_.Stop();
+}
+
+void GpuArcAccelerator::Initialize() {
+ DCHECK(CalledOnValidThread());
+
+ arc_accelerator_thread_.Start();
+ arc_task_runner_ = arc_accelerator_thread_.task_runner();
+}
+
+void GpuArcAccelerator::CreateClient(uint32_t device_type) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(arc_task_runner_);
+
+ // It's safe to Unretained |this| because the thread is owned by |this|.
+ arc_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&GpuArcAccelerator::CreateClientOnArcThread,
+ base::Unretained(this), device_type));
+}
+
+void GpuArcAccelerator::CreateClientOnArcThread(uint32_t device_type) {
+ DCHECK(arc_task_runner_->BelongsToCurrentThread());
+ scoped_ptr<Client> client(new Client(this, io_task_runner_));
+ clients_[client.get()] = client.Pass();
+
+ client->Initialize(shutdown_event_, device_type, gpu_channel_);
+}
+
+void GpuArcAccelerator::RemoveClientOnArcThread(Client* client) {
+ DCHECK(arc_task_runner_->BelongsToCurrentThread());
+ clients_.erase(client);
+}
+
+void GpuArcAccelerator::RemoveAllClientsOnArcThread(base::WaitableEvent* done) {
+ DCHECK(arc_task_runner_->BelongsToCurrentThread());
+ clients_.clear();
+ done->Signal();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698