| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/android/stream_texture_factory.h" | 5 #include "content/renderer/media/android/stream_texture_factory.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "cc/output/context_provider.h" | 8 #include "cc/output/context_provider.h" |
| 9 #include "content/common/gpu/client/context_provider_command_buffer.h" | 9 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 10 #include "gpu/command_buffer/client/gles2_interface.h" | 10 #include "gpu/command_buffer/client/gles2_interface.h" |
| 11 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 11 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 12 #include "gpu/ipc/client/gpu_channel_host.h" | 12 #include "gpu/ipc/client/gpu_channel_host.h" |
| 13 #include "gpu/ipc/common/gpu_messages.h" | 13 #include "gpu/ipc/common/gpu_messages.h" |
| 14 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 StreamTextureProxy::StreamTextureProxy(StreamTextureHost* host) | 18 StreamTextureProxy::StreamTextureProxy(StreamTextureHost* host) : host_(host) {} |
| 19 : host_(host), client_(NULL) {} | |
| 20 | 19 |
| 21 StreamTextureProxy::~StreamTextureProxy() {} | 20 StreamTextureProxy::~StreamTextureProxy() {} |
| 22 | 21 |
| 23 void StreamTextureProxy::Release() { | 22 void StreamTextureProxy::Release() { |
| 24 { | 23 { |
| 25 // Cannot call into |client_| anymore (from any thread) after returning | 24 // Cannot call |received_frame_cb_| after returning from here. |
| 26 // from here. | |
| 27 base::AutoLock lock(lock_); | 25 base::AutoLock lock(lock_); |
| 28 client_ = NULL; | 26 received_frame_cb_.Reset(); |
| 29 } | 27 } |
| 30 // Release is analogous to the destructor, so there should be no more external | 28 // Release is analogous to the destructor, so there should be no more external |
| 31 // calls to this object in Release. Therefore there is no need to acquire the | 29 // calls to this object in Release. Therefore there is no need to acquire the |
| 32 // lock to access |loop_|. | 30 // lock to access |task_runner_|. |
| 33 if (!loop_.get() || loop_->BelongsToCurrentThread() || | 31 if (!task_runner_.get() || task_runner_->BelongsToCurrentThread() || |
| 34 !loop_->DeleteSoon(FROM_HERE, this)) { | 32 !task_runner_->DeleteSoon(FROM_HERE, this)) { |
| 35 delete this; | 33 delete this; |
| 36 } | 34 } |
| 37 } | 35 } |
| 38 | 36 |
| 39 void StreamTextureProxy::BindToLoop( | 37 void StreamTextureProxy::BindToTaskRunner( |
| 40 int32_t stream_id, | 38 int32_t stream_id, |
| 41 cc::VideoFrameProvider::Client* client, | 39 const base::Closure& received_frame_cb, |
| 42 scoped_refptr<base::SingleThreadTaskRunner> loop) { | 40 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 43 DCHECK(loop.get()); | 41 DCHECK(task_runner.get()); |
| 44 | 42 |
| 45 { | 43 { |
| 46 base::AutoLock lock(lock_); | 44 base::AutoLock lock(lock_); |
| 47 DCHECK(!loop_.get() || (loop.get() == loop_.get())); | 45 DCHECK(!task_runner_.get() || (task_runner.get() == task_runner_.get())); |
| 48 loop_ = loop; | 46 task_runner_ = task_runner; |
| 49 client_ = client; | 47 received_frame_cb_ = received_frame_cb; |
| 50 } | 48 } |
| 51 | 49 |
| 52 if (loop->BelongsToCurrentThread()) { | 50 if (task_runner->BelongsToCurrentThread()) { |
| 53 BindOnThread(stream_id); | 51 BindOnThread(stream_id); |
| 54 return; | 52 return; |
| 55 } | 53 } |
| 56 // Unretained is safe here only because the object is deleted on |loop_| | 54 // Unretained is safe here only because the object is deleted on |loop_| |
| 57 // thread. | 55 // thread. |
| 58 loop->PostTask(FROM_HERE, | 56 task_runner->PostTask(FROM_HERE, |
| 59 base::Bind(&StreamTextureProxy::BindOnThread, | 57 base::Bind(&StreamTextureProxy::BindOnThread, |
| 60 base::Unretained(this), | 58 base::Unretained(this), stream_id)); |
| 61 stream_id)); | |
| 62 } | 59 } |
| 63 | 60 |
| 64 void StreamTextureProxy::BindOnThread(int32_t stream_id) { | 61 void StreamTextureProxy::BindOnThread(int32_t stream_id) { |
| 65 host_->BindToCurrentThread(stream_id, this); | 62 host_->BindToCurrentThread(stream_id, this); |
| 66 } | 63 } |
| 67 | 64 |
| 68 void StreamTextureProxy::OnFrameAvailable() { | 65 void StreamTextureProxy::OnFrameAvailable() { |
| 69 base::AutoLock lock(lock_); | 66 base::AutoLock lock(lock_); |
| 70 if (client_) | 67 if (!received_frame_cb_.is_null()) |
| 71 client_->DidReceiveFrame(); | 68 received_frame_cb_.Run(); |
| 72 } | 69 } |
| 73 | 70 |
| 74 // static | 71 // static |
| 75 scoped_refptr<StreamTextureFactory> StreamTextureFactory::Create( | 72 scoped_refptr<StreamTextureFactory> StreamTextureFactory::Create( |
| 76 scoped_refptr<ContextProviderCommandBuffer> context_provider) { | 73 scoped_refptr<ContextProviderCommandBuffer> context_provider) { |
| 77 return new StreamTextureFactory(std::move(context_provider)); | 74 return new StreamTextureFactory(std::move(context_provider)); |
| 78 } | 75 } |
| 79 | 76 |
| 80 StreamTextureFactory::StreamTextureFactory( | 77 StreamTextureFactory::StreamTextureFactory( |
| 81 scoped_refptr<ContextProviderCommandBuffer> context_provider) | 78 scoped_refptr<ContextProviderCommandBuffer> context_provider) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void StreamTextureFactory::SetStreamTextureSize(int32_t stream_id, | 114 void StreamTextureFactory::SetStreamTextureSize(int32_t stream_id, |
| 118 const gfx::Size& size) { | 115 const gfx::Size& size) { |
| 119 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); | 116 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); |
| 120 } | 117 } |
| 121 | 118 |
| 122 gpu::gles2::GLES2Interface* StreamTextureFactory::ContextGL() { | 119 gpu::gles2::GLES2Interface* StreamTextureFactory::ContextGL() { |
| 123 return context_provider_->ContextGL(); | 120 return context_provider_->ContextGL(); |
| 124 } | 121 } |
| 125 | 122 |
| 126 } // namespace content | 123 } // namespace content |
| OLD | NEW |