| 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 "base/macros.h" |
| 7 #include "cc/output/context_provider.h" | 8 #include "cc/output/context_provider.h" |
| 8 #include "content/common/gpu/client/context_provider_command_buffer.h" | 9 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 9 #include "content/common/gpu/client/gpu_channel_host.h" | 10 #include "content/common/gpu/client/gpu_channel_host.h" |
| 10 #include "content/common/gpu/gpu_messages.h" | 11 #include "content/common/gpu/gpu_messages.h" |
| 11 #include "content/renderer/gpu/stream_texture_host_android.h" | 12 #include "content/renderer/gpu/stream_texture_host_android.h" |
| 12 #include "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
| 13 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 class StreamTextureProxyImpl : public StreamTextureProxy, | 20 class StreamTextureProxyImpl : public StreamTextureProxy, |
| 20 public StreamTextureHost::Listener { | 21 public StreamTextureHost::Listener { |
| 21 public: | 22 public: |
| 22 explicit StreamTextureProxyImpl(StreamTextureHost* host); | 23 explicit StreamTextureProxyImpl(StreamTextureHost* host); |
| 23 ~StreamTextureProxyImpl() override; | 24 ~StreamTextureProxyImpl() override; |
| 24 | 25 |
| 25 // StreamTextureProxy implementation: | 26 // StreamTextureProxy implementation: |
| 26 void BindToLoop(int32 stream_id, | 27 void BindToLoop(int32_t stream_id, |
| 27 cc::VideoFrameProvider::Client* client, | 28 cc::VideoFrameProvider::Client* client, |
| 28 scoped_refptr<base::SingleThreadTaskRunner> loop) override; | 29 scoped_refptr<base::SingleThreadTaskRunner> loop) override; |
| 29 void Release() override; | 30 void Release() override; |
| 30 | 31 |
| 31 // StreamTextureHost::Listener implementation: | 32 // StreamTextureHost::Listener implementation: |
| 32 void OnFrameAvailable() override; | 33 void OnFrameAvailable() override; |
| 33 void OnMatrixChanged(const float matrix[16]) override; | 34 void OnMatrixChanged(const float matrix[16]) override; |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 void BindOnThread(int32 stream_id); | 37 void BindOnThread(int32_t stream_id); |
| 37 | 38 |
| 38 const scoped_ptr<StreamTextureHost> host_; | 39 const scoped_ptr<StreamTextureHost> host_; |
| 39 | 40 |
| 40 // Protects access to |client_| and |loop_|. | 41 // Protects access to |client_| and |loop_|. |
| 41 base::Lock lock_; | 42 base::Lock lock_; |
| 42 cc::VideoFrameProvider::Client* client_; | 43 cc::VideoFrameProvider::Client* client_; |
| 43 scoped_refptr<base::SingleThreadTaskRunner> loop_; | 44 scoped_refptr<base::SingleThreadTaskRunner> loop_; |
| 44 | 45 |
| 45 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 46 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
| 46 }; | 47 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 60 // Release is analogous to the destructor, so there should be no more external | 61 // Release is analogous to the destructor, so there should be no more external |
| 61 // calls to this object in Release. Therefore there is no need to acquire the | 62 // calls to this object in Release. Therefore there is no need to acquire the |
| 62 // lock to access |loop_|. | 63 // lock to access |loop_|. |
| 63 if (!loop_.get() || loop_->BelongsToCurrentThread() || | 64 if (!loop_.get() || loop_->BelongsToCurrentThread() || |
| 64 !loop_->DeleteSoon(FROM_HERE, this)) { | 65 !loop_->DeleteSoon(FROM_HERE, this)) { |
| 65 delete this; | 66 delete this; |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 void StreamTextureProxyImpl::BindToLoop( | 70 void StreamTextureProxyImpl::BindToLoop( |
| 70 int32 stream_id, | 71 int32_t stream_id, |
| 71 cc::VideoFrameProvider::Client* client, | 72 cc::VideoFrameProvider::Client* client, |
| 72 scoped_refptr<base::SingleThreadTaskRunner> loop) { | 73 scoped_refptr<base::SingleThreadTaskRunner> loop) { |
| 73 DCHECK(loop.get()); | 74 DCHECK(loop.get()); |
| 74 | 75 |
| 75 { | 76 { |
| 76 base::AutoLock lock(lock_); | 77 base::AutoLock lock(lock_); |
| 77 DCHECK(!loop_.get() || (loop.get() == loop_.get())); | 78 DCHECK(!loop_.get() || (loop.get() == loop_.get())); |
| 78 loop_ = loop; | 79 loop_ = loop; |
| 79 client_ = client; | 80 client_ = client; |
| 80 } | 81 } |
| 81 | 82 |
| 82 if (loop->BelongsToCurrentThread()) { | 83 if (loop->BelongsToCurrentThread()) { |
| 83 BindOnThread(stream_id); | 84 BindOnThread(stream_id); |
| 84 return; | 85 return; |
| 85 } | 86 } |
| 86 // Unretained is safe here only because the object is deleted on |loop_| | 87 // Unretained is safe here only because the object is deleted on |loop_| |
| 87 // thread. | 88 // thread. |
| 88 loop->PostTask(FROM_HERE, | 89 loop->PostTask(FROM_HERE, |
| 89 base::Bind(&StreamTextureProxyImpl::BindOnThread, | 90 base::Bind(&StreamTextureProxyImpl::BindOnThread, |
| 90 base::Unretained(this), | 91 base::Unretained(this), |
| 91 stream_id)); | 92 stream_id)); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void StreamTextureProxyImpl::BindOnThread(int32 stream_id) { | 95 void StreamTextureProxyImpl::BindOnThread(int32_t stream_id) { |
| 95 host_->BindToCurrentThread(stream_id, this); | 96 host_->BindToCurrentThread(stream_id, this); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void StreamTextureProxyImpl::OnFrameAvailable() { | 99 void StreamTextureProxyImpl::OnFrameAvailable() { |
| 99 base::AutoLock lock(lock_); | 100 base::AutoLock lock(lock_); |
| 100 if (client_) | 101 if (client_) |
| 101 client_->DidReceiveFrame(); | 102 client_->DidReceiveFrame(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 105 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 124 } | 125 } |
| 125 | 126 |
| 126 StreamTextureFactoryImpl::~StreamTextureFactoryImpl() {} | 127 StreamTextureFactoryImpl::~StreamTextureFactoryImpl() {} |
| 127 | 128 |
| 128 StreamTextureProxy* StreamTextureFactoryImpl::CreateProxy() { | 129 StreamTextureProxy* StreamTextureFactoryImpl::CreateProxy() { |
| 129 DCHECK(channel_.get()); | 130 DCHECK(channel_.get()); |
| 130 StreamTextureHost* host = new StreamTextureHost(channel_.get()); | 131 StreamTextureHost* host = new StreamTextureHost(channel_.get()); |
| 131 return new StreamTextureProxyImpl(host); | 132 return new StreamTextureProxyImpl(host); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void StreamTextureFactoryImpl::EstablishPeer(int32 stream_id, | 135 void StreamTextureFactoryImpl::EstablishPeer(int32_t stream_id, |
| 135 int player_id, | 136 int player_id, |
| 136 int frame_id) { | 137 int frame_id) { |
| 137 DCHECK(channel_.get()); | 138 DCHECK(channel_.get()); |
| 138 channel_->Send( | 139 channel_->Send( |
| 139 new GpuStreamTextureMsg_EstablishPeer(stream_id, frame_id, player_id)); | 140 new GpuStreamTextureMsg_EstablishPeer(stream_id, frame_id, player_id)); |
| 140 } | 141 } |
| 141 | 142 |
| 142 unsigned StreamTextureFactoryImpl::CreateStreamTexture( | 143 unsigned StreamTextureFactoryImpl::CreateStreamTexture( |
| 143 unsigned texture_target, | 144 unsigned texture_target, |
| 144 unsigned* texture_id, | 145 unsigned* texture_id, |
| 145 gpu::Mailbox* texture_mailbox) { | 146 gpu::Mailbox* texture_mailbox) { |
| 146 GLuint stream_id = 0; | 147 GLuint stream_id = 0; |
| 147 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 148 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
| 148 gl->GenTextures(1, texture_id); | 149 gl->GenTextures(1, texture_id); |
| 149 gl->ShallowFlushCHROMIUM(); | 150 gl->ShallowFlushCHROMIUM(); |
| 150 stream_id = context_provider_->GetCommandBufferProxy()->CreateStreamTexture( | 151 stream_id = context_provider_->GetCommandBufferProxy()->CreateStreamTexture( |
| 151 *texture_id); | 152 *texture_id); |
| 152 gl->GenMailboxCHROMIUM(texture_mailbox->name); | 153 gl->GenMailboxCHROMIUM(texture_mailbox->name); |
| 153 gl->ProduceTextureDirectCHROMIUM( | 154 gl->ProduceTextureDirectCHROMIUM( |
| 154 *texture_id, texture_target, texture_mailbox->name); | 155 *texture_id, texture_target, texture_mailbox->name); |
| 155 return stream_id; | 156 return stream_id; |
| 156 } | 157 } |
| 157 | 158 |
| 158 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, | 159 void StreamTextureFactoryImpl::SetStreamTextureSize(int32_t stream_id, |
| 159 const gfx::Size& size) { | 160 const gfx::Size& size) { |
| 160 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); | 161 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); |
| 161 } | 162 } |
| 162 | 163 |
| 163 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { | 164 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { |
| 164 return context_provider_->ContextGL(); | 165 return context_provider_->ContextGL(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 void StreamTextureFactoryImpl::AddObserver( | 168 void StreamTextureFactoryImpl::AddObserver( |
| 168 StreamTextureFactoryContextObserver* obs) { | 169 StreamTextureFactoryContextObserver* obs) { |
| 169 } | 170 } |
| 170 | 171 |
| 171 void StreamTextureFactoryImpl::RemoveObserver( | 172 void StreamTextureFactoryImpl::RemoveObserver( |
| 172 StreamTextureFactoryContextObserver* obs) { | 173 StreamTextureFactoryContextObserver* obs) { |
| 173 } | 174 } |
| 174 | 175 |
| 175 } // namespace content | 176 } // namespace content |
| OLD | NEW |