| 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 Bind(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, cc::VideoFrameProvider::Client* client); |
| 37 const scoped_ptr<StreamTextureHost> host_; |
| 38 |
| 39 base::Lock lock_; |
| 35 scoped_refptr<base::MessageLoopProxy> loop_; | 40 scoped_refptr<base::MessageLoopProxy> loop_; |
| 36 | |
| 37 base::Lock client_lock_; | |
| 38 cc::VideoFrameProvider::Client* client_; | 41 cc::VideoFrameProvider::Client* client_; |
| 39 | 42 |
| 40 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 43 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
| 41 }; | 44 }; |
| 42 | 45 |
| 43 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) | 46 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
| 44 : host_(host), client_(NULL) {} | 47 : host_(host), client_(NULL) {} |
| 45 | 48 |
| 46 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 49 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
| 47 | 50 |
| 48 void StreamTextureProxyImpl::Release() { | 51 void StreamTextureProxyImpl::Release() { |
| 49 SetClient(NULL); | 52 base::AutoLock lock(lock_); |
| 50 if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) | 53 client_ = NULL; |
| 51 loop_->DeleteSoon(FROM_HERE, this); | 54 if (!loop_.get() || loop_.get() != base::MessageLoopProxy::current() || |
| 52 else | 55 !loop_->DeleteSoon(FROM_HERE, this)) { |
| 53 delete this; | 56 delete this; |
| 57 } |
| 54 } | 58 } |
| 55 | 59 |
| 56 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { | 60 void StreamTextureProxyImpl::Bind(int32 stream_id, |
| 57 base::AutoLock lock(client_lock_); | 61 cc::VideoFrameProvider::Client* client, |
| 58 client_ = client; | 62 scoped_refptr<base::MessageLoopProxy> loop) { |
| 63 base::AutoLock lock(lock_); |
| 64 DCHECK(loop.get()); |
| 65 loop_ = loop; |
| 66 |
| 67 if (loop.get() != base::MessageLoopProxy::current()) { |
| 68 // Unretained is safe here only because the object is deleted on |loop_| |
| 69 // thread. |
| 70 loop->PostTask(FROM_HERE, |
| 71 base::Bind(&StreamTextureProxyImpl::BindOnThread, |
| 72 base::Unretained(this), |
| 73 stream_id, |
| 74 client)); |
| 75 } else { |
| 76 client_ = client; |
| 77 host_->BindToCurrentThread(stream_id, this); |
| 78 } |
| 59 } | 79 } |
| 60 | 80 |
| 61 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { | 81 void StreamTextureProxyImpl::BindOnThread( |
| 62 loop_ = base::MessageLoopProxy::current(); | 82 int32 stream_id, |
| 83 cc::VideoFrameProvider::Client* client) { |
| 84 { |
| 85 base::AutoLock lock(lock_); |
| 86 client_ = client; |
| 87 } |
| 63 host_->BindToCurrentThread(stream_id, this); | 88 host_->BindToCurrentThread(stream_id, this); |
| 64 } | 89 } |
| 65 | 90 |
| 66 void StreamTextureProxyImpl::OnFrameAvailable() { | 91 void StreamTextureProxyImpl::OnFrameAvailable() { |
| 67 base::AutoLock lock(client_lock_); | 92 base::AutoLock lock(lock_); |
| 68 if (client_) | 93 if (client_) |
| 69 client_->DidReceiveFrame(); | 94 client_->DidReceiveFrame(); |
| 70 } | 95 } |
| 71 | 96 |
| 72 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 97 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
| 73 base::AutoLock lock(client_lock_); | 98 base::AutoLock lock(lock_); |
| 74 if (client_) | 99 if (client_) |
| 75 client_->DidUpdateMatrix(matrix); | 100 client_->DidUpdateMatrix(matrix); |
| 76 } | 101 } |
| 77 | 102 |
| 78 } // namespace | 103 } // namespace |
| 79 | 104 |
| 80 // static | 105 // static |
| 81 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( | 106 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( |
| 82 const scoped_refptr<cc::ContextProvider>& context_provider, | 107 const scoped_refptr<cc::ContextProvider>& context_provider, |
| 83 GpuChannelHost* channel, | 108 GpuChannelHost* channel, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 152 |
| 128 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, | 153 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, |
| 129 const gfx::Size& size) { | 154 const gfx::Size& size) { |
| 130 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); | 155 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); |
| 131 } | 156 } |
| 132 | 157 |
| 133 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { | 158 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { |
| 134 return context_provider_->ContextGL(); | 159 return context_provider_->ContextGL(); |
| 135 } | 160 } |
| 136 | 161 |
| 162 void StreamTextureFactoryImpl::AddObserver( |
| 163 StreamTextureFactoryContextObserver* obs) { |
| 164 } |
| 165 |
| 166 void StreamTextureFactoryImpl::RemoveObserver( |
| 167 StreamTextureFactoryContextObserver* obs) { |
| 168 } |
| 169 |
| 137 } // namespace content | 170 } // namespace content |
| OLD | NEW |