| 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_impl.h" | 5 #include "content/renderer/media/android/stream_texture_factory_impl.h" |
| 6 | 6 |
| 7 #include "cc/output/context_provider.h" | 7 #include "cc/output/context_provider.h" |
| 8 #include "content/common/gpu/client/gpu_channel_host.h" | 8 #include "content/common/gpu/client/gpu_channel_host.h" |
| 9 #include "content/common/gpu/gpu_messages.h" | 9 #include "content/common/gpu/gpu_messages.h" |
| 10 #include "content/renderer/gpu/stream_texture_host_android.h" | 10 #include "content/renderer/gpu/stream_texture_host_android.h" |
| 11 #include "gpu/command_buffer/client/gles2_interface.h" | 11 #include "gpu/command_buffer/client/gles2_interface.h" |
| 12 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class StreamTextureProxyImpl : public StreamTextureProxy, | 18 class StreamTextureProxyImpl : public StreamTextureProxy, |
| 19 public StreamTextureHost::Listener { | 19 public StreamTextureHost::Listener { |
| 20 public: | 20 public: |
| 21 explicit StreamTextureProxyImpl(StreamTextureHost* host); | 21 explicit StreamTextureProxyImpl(StreamTextureHost* host); |
| 22 virtual ~StreamTextureProxyImpl(); | 22 virtual ~StreamTextureProxyImpl(); |
| 23 | 23 |
| 24 // StreamTextureProxy implementation: | 24 // StreamTextureProxy implementation: |
| 25 virtual void BindToCurrentThread(int32 stream_id) OVERRIDE; | 25 virtual void BindToLoop(int32 stream_id, |
| 26 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; | 26 cc::VideoFrameProvider::Client* client, |
| 27 scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE; |
| 27 virtual void Release() OVERRIDE; | 28 virtual void Release() OVERRIDE; |
| 28 | 29 |
| 29 // StreamTextureHost::Listener implementation: | 30 // StreamTextureHost::Listener implementation: |
| 30 virtual void OnFrameAvailable() OVERRIDE; | 31 virtual void OnFrameAvailable() OVERRIDE; |
| 31 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; | 32 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 scoped_ptr<StreamTextureHost> host_; | 35 void SetClient(cc::VideoFrameProvider::Client* client); |
| 36 void BindOnThread(int32 stream_id, |
| 37 scoped_refptr<base::MessageLoopProxy> loop); |
| 38 |
| 39 const scoped_ptr<StreamTextureHost> host_; |
| 35 scoped_refptr<base::MessageLoopProxy> loop_; | 40 scoped_refptr<base::MessageLoopProxy> loop_; |
| 36 | 41 |
| 37 base::Lock client_lock_; | 42 base::Lock client_lock_; |
| 38 cc::VideoFrameProvider::Client* client_; | 43 cc::VideoFrameProvider::Client* client_; |
| 39 | 44 |
| 40 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 45 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
| 41 }; | 46 }; |
| 42 | 47 |
| 43 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) | 48 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
| 44 : host_(host), client_(NULL) {} | 49 : host_(host), client_(NULL) {} |
| 45 | 50 |
| 46 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 51 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
| 47 | 52 |
| 48 void StreamTextureProxyImpl::Release() { | 53 void StreamTextureProxyImpl::Release() { |
| 54 // Assumes this is the last reference to this object. So no need to acquire |
| 55 // lock. |
| 49 SetClient(NULL); | 56 SetClient(NULL); |
| 50 if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) | 57 if (!loop_.get() || loop_->BelongsToCurrentThread() || |
| 51 loop_->DeleteSoon(FROM_HERE, this); | 58 !loop_->DeleteSoon(FROM_HERE, this)) { |
| 52 else | |
| 53 delete this; | 59 delete this; |
| 60 } |
| 54 } | 61 } |
| 55 | 62 |
| 56 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { | 63 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
| 57 base::AutoLock lock(client_lock_); | 64 base::AutoLock lock(client_lock_); |
| 58 client_ = client; | 65 client_ = client; |
| 59 } | 66 } |
| 60 | 67 |
| 61 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { | 68 void StreamTextureProxyImpl::BindToLoop( |
| 62 loop_ = base::MessageLoopProxy::current(); | 69 int32 stream_id, |
| 70 cc::VideoFrameProvider::Client* client, |
| 71 scoped_refptr<base::MessageLoopProxy> loop) { |
| 72 DCHECK(loop); |
| 73 SetClient(client); |
| 74 if (loop->BelongsToCurrentThread()) { |
| 75 BindOnThread(stream_id, loop); |
| 76 return; |
| 77 } |
| 78 // Unretained is safe here only because the object is deleted on |loop_| |
| 79 // thread. |
| 80 loop->PostTask(FROM_HERE, |
| 81 base::Bind(&StreamTextureProxyImpl::BindOnThread, |
| 82 base::Unretained(this), |
| 83 stream_id, |
| 84 loop)); |
| 85 } |
| 86 |
| 87 void StreamTextureProxyImpl::BindOnThread( |
| 88 int32 stream_id, |
| 89 scoped_refptr<base::MessageLoopProxy> loop) { |
| 90 DCHECK(!loop_ || (loop == loop_)); |
| 91 loop_ = loop; |
| 63 host_->BindToCurrentThread(stream_id, this); | 92 host_->BindToCurrentThread(stream_id, this); |
| 64 } | 93 } |
| 65 | 94 |
| 66 void StreamTextureProxyImpl::OnFrameAvailable() { | 95 void StreamTextureProxyImpl::OnFrameAvailable() { |
| 67 base::AutoLock lock(client_lock_); | 96 base::AutoLock lock(client_lock_); |
| 68 if (client_) | 97 if (client_) |
| 69 client_->DidReceiveFrame(); | 98 client_->DidReceiveFrame(); |
| 70 } | 99 } |
| 71 | 100 |
| 72 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 101 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 156 |
| 128 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, | 157 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, |
| 129 const gfx::Size& size) { | 158 const gfx::Size& size) { |
| 130 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); | 159 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); |
| 131 } | 160 } |
| 132 | 161 |
| 133 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { | 162 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { |
| 134 return context_provider_->ContextGL(); | 163 return context_provider_->ContextGL(); |
| 135 } | 164 } |
| 136 | 165 |
| 166 void StreamTextureFactoryImpl::AddObserver( |
| 167 StreamTextureFactoryContextObserver* obs) { |
| 168 } |
| 169 |
| 170 void StreamTextureFactoryImpl::RemoveObserver( |
| 171 StreamTextureFactoryContextObserver* obs) { |
| 172 } |
| 173 |
| 137 } // namespace content | 174 } // namespace content |
| OLD | NEW |