| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_android.h" | 5 #include "content/renderer/media/android/stream_texture_factory_android_impl.h" |
| 6 | 6 |
| 7 #include "content/common/gpu/client/gpu_channel_host.h" | 7 #include "content/common/gpu/client/gpu_channel_host.h" |
| 8 #include "content/common/gpu/gpu_messages.h" | 8 #include "content/common/gpu/gpu_messages.h" |
| 9 #include "content/renderer/gpu/stream_texture_host_android.h" |
| 9 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 10 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 10 #include "ui/gfx/size.h" | 11 #include "ui/gfx/size.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 StreamTextureProxy::StreamTextureProxy(StreamTextureHost* host) | 15 namespace { |
| 16 |
| 17 class StreamTextureProxyImpl : public StreamTextureProxy, |
| 18 public StreamTextureHost::Listener { |
| 19 public: |
| 20 explicit StreamTextureProxyImpl(StreamTextureHost* host); |
| 21 virtual ~StreamTextureProxyImpl(); |
| 22 |
| 23 virtual void BindToCurrentThread(int32 stream_id) OVERRIDE; |
| 24 virtual bool IsBoundToThread() OVERRIDE { return loop_.get() != NULL; } |
| 25 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; |
| 26 |
| 27 // StreamTextureHost::Listener implementation: |
| 28 virtual void OnFrameAvailable() OVERRIDE; |
| 29 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
| 30 |
| 31 private: |
| 32 virtual void Release() OVERRIDE; |
| 33 |
| 34 scoped_ptr<StreamTextureHost> host_; |
| 35 scoped_refptr<base::MessageLoopProxy> loop_; |
| 36 |
| 37 base::Lock client_lock_; |
| 38 cc::VideoFrameProvider::Client* client_; |
| 39 |
| 40 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
| 41 }; |
| 42 |
| 43 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
| 15 : host_(host), client_(NULL) { | 44 : host_(host), client_(NULL) { |
| 16 host->SetListener(this); | 45 host->SetListener(this); |
| 17 } | 46 } |
| 18 | 47 |
| 19 StreamTextureProxy::~StreamTextureProxy() {} | 48 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
| 20 | 49 |
| 21 void StreamTextureProxy::Release() { | 50 void StreamTextureProxyImpl::Release() { |
| 22 SetClient(NULL); | 51 SetClient(NULL); |
| 23 if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) | 52 if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) |
| 24 loop_->DeleteSoon(FROM_HERE, this); | 53 loop_->DeleteSoon(FROM_HERE, this); |
| 25 else | 54 else |
| 26 delete this; | 55 delete this; |
| 27 } | 56 } |
| 28 | 57 |
| 29 void StreamTextureProxy::SetClient(cc::VideoFrameProvider::Client* client) { | 58 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
| 30 base::AutoLock lock(client_lock_); | 59 base::AutoLock lock(client_lock_); |
| 31 client_ = client; | 60 client_ = client; |
| 32 } | 61 } |
| 33 | 62 |
| 34 void StreamTextureProxy::BindToCurrentThread(int stream_id) { | 63 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { |
| 35 loop_ = base::MessageLoopProxy::current(); | 64 loop_ = base::MessageLoopProxy::current(); |
| 36 host_->Initialize(stream_id); | 65 host_->Initialize(stream_id); |
| 37 } | 66 } |
| 38 | 67 |
| 39 void StreamTextureProxy::OnFrameAvailable() { | 68 void StreamTextureProxyImpl::OnFrameAvailable() { |
| 40 base::AutoLock lock(client_lock_); | 69 base::AutoLock lock(client_lock_); |
| 41 if (client_) | 70 if (client_) |
| 42 client_->DidReceiveFrame(); | 71 client_->DidReceiveFrame(); |
| 43 } | 72 } |
| 44 | 73 |
| 45 void StreamTextureProxy::OnMatrixChanged(const float matrix[16]) { | 74 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
| 46 base::AutoLock lock(client_lock_); | 75 base::AutoLock lock(client_lock_); |
| 47 if (client_) | 76 if (client_) |
| 48 client_->DidUpdateMatrix(matrix); | 77 client_->DidUpdateMatrix(matrix); |
| 49 } | 78 } |
| 50 | 79 |
| 51 StreamTextureFactory::StreamTextureFactory( | 80 } // namespace |
| 81 |
| 82 StreamTextureFactoryImpl::StreamTextureFactoryImpl( |
| 52 WebKit::WebGraphicsContext3D* context, | 83 WebKit::WebGraphicsContext3D* context, |
| 53 GpuChannelHost* channel, | 84 GpuChannelHost* channel, |
| 54 int view_id) | 85 int view_id) |
| 55 : context_(context), channel_(channel), view_id_(view_id) { | 86 : context_(context), channel_(channel), view_id_(view_id) { |
| 56 DCHECK(context_); | 87 DCHECK(context_); |
| 57 DCHECK(channel); | 88 DCHECK(channel); |
| 58 } | 89 } |
| 59 | 90 |
| 60 StreamTextureFactory::~StreamTextureFactory() {} | 91 StreamTextureFactoryImpl::~StreamTextureFactoryImpl() {} |
| 61 | 92 |
| 62 StreamTextureProxy* StreamTextureFactory::CreateProxy() { | 93 StreamTextureProxy* StreamTextureFactoryImpl::CreateProxy() { |
| 63 DCHECK(channel_.get()); | 94 DCHECK(channel_.get()); |
| 64 StreamTextureHost* host = new StreamTextureHost(channel_.get()); | 95 StreamTextureHost* host = new StreamTextureHost(channel_.get()); |
| 65 return new StreamTextureProxy(host); | 96 return new StreamTextureProxyImpl(host); |
| 66 } | 97 } |
| 67 | 98 |
| 68 void StreamTextureFactory::EstablishPeer(int32 stream_id, int player_id) { | 99 void StreamTextureFactoryImpl::EstablishPeer(int32 stream_id, int player_id) { |
| 69 DCHECK(channel_.get()); | 100 DCHECK(channel_.get()); |
| 70 channel_->Send( | 101 channel_->Send( |
| 71 new GpuChannelMsg_EstablishStreamTexture(stream_id, view_id_, player_id)); | 102 new GpuChannelMsg_EstablishStreamTexture(stream_id, view_id_, player_id)); |
| 72 } | 103 } |
| 73 | 104 |
| 74 unsigned StreamTextureFactory::CreateStreamTexture( | 105 unsigned StreamTextureFactoryImpl::CreateStreamTexture( |
| 75 unsigned texture_target, | 106 unsigned texture_target, |
| 76 unsigned* texture_id, | 107 unsigned* texture_id, |
| 77 gpu::Mailbox* texture_mailbox, | 108 gpu::Mailbox* texture_mailbox, |
| 78 unsigned* texture_mailbox_sync_point) { | 109 unsigned* texture_mailbox_sync_point) { |
| 79 unsigned stream_id = 0; | 110 unsigned stream_id = 0; |
| 80 if (context_->makeContextCurrent()) { | 111 if (context_->makeContextCurrent()) { |
| 81 *texture_id = context_->createTexture(); | 112 *texture_id = context_->createTexture(); |
| 82 stream_id = context_->createStreamTextureCHROMIUM(*texture_id); | 113 stream_id = context_->createStreamTextureCHROMIUM(*texture_id); |
| 83 | 114 |
| 84 context_->genMailboxCHROMIUM(texture_mailbox->name); | 115 context_->genMailboxCHROMIUM(texture_mailbox->name); |
| 85 context_->bindTexture(texture_target, *texture_id); | 116 context_->bindTexture(texture_target, *texture_id); |
| 86 context_->produceTextureCHROMIUM(texture_target, texture_mailbox->name); | 117 context_->produceTextureCHROMIUM(texture_target, texture_mailbox->name); |
| 87 | 118 |
| 88 context_->flush(); | 119 context_->flush(); |
| 89 *texture_mailbox_sync_point = context_->insertSyncPoint(); | 120 *texture_mailbox_sync_point = context_->insertSyncPoint(); |
| 90 } | 121 } |
| 91 return stream_id; | 122 return stream_id; |
| 92 } | 123 } |
| 93 | 124 |
| 94 void StreamTextureFactory::DestroyStreamTexture(unsigned texture_id) { | 125 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) { |
| 95 if (context_->makeContextCurrent()) { | 126 if (context_->makeContextCurrent()) { |
| 96 // TODO(sievers): Make the destroyStreamTexture implicit when the last | 127 // TODO(sievers): Make the destroyStreamTexture implicit when the last |
| 97 // texture referencing it is lost. | 128 // texture referencing it is lost. |
| 98 context_->destroyStreamTextureCHROMIUM(texture_id); | 129 context_->destroyStreamTextureCHROMIUM(texture_id); |
| 99 context_->deleteTexture(texture_id); | 130 context_->deleteTexture(texture_id); |
| 100 context_->flush(); | 131 context_->flush(); |
| 101 } | 132 } |
| 102 } | 133 } |
| 103 | 134 |
| 104 void StreamTextureFactory::SetStreamTextureSize( | 135 void StreamTextureFactoryImpl::SetStreamTextureSize( |
| 105 int32 stream_id, const gfx::Size& size) { | 136 int32 stream_id, const gfx::Size& size) { |
| 106 channel_->Send(new GpuChannelMsg_SetStreamTextureSize(stream_id, size)); | 137 channel_->Send(new GpuChannelMsg_SetStreamTextureSize(stream_id, size)); |
| 107 } | 138 } |
| 108 | 139 |
| 109 } // namespace content | 140 } // namespace content |
| OLD | NEW |