| 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_impl.h" | 5 #include "content/renderer/media/android/stream_texture_factory_android_impl.h" |
| 6 | 6 |
| 7 #include "cc/output/context_provider.h" |
| 7 #include "content/common/gpu/client/gpu_channel_host.h" | 8 #include "content/common/gpu/client/gpu_channel_host.h" |
| 8 #include "content/common/gpu/gpu_messages.h" | 9 #include "content/common/gpu/gpu_messages.h" |
| 9 #include "content/renderer/gpu/stream_texture_host_android.h" | 10 #include "content/renderer/gpu/stream_texture_host_android.h" |
| 10 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 11 #include "gpu/command_buffer/client/gles2_interface.h" |
| 11 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 class StreamTextureProxyImpl : public StreamTextureProxy, | 18 class StreamTextureProxyImpl : public StreamTextureProxy, |
| 18 public StreamTextureHost::Listener { | 19 public StreamTextureHost::Listener { |
| 19 public: | 20 public: |
| 20 explicit StreamTextureProxyImpl(StreamTextureHost* host); | 21 explicit StreamTextureProxyImpl(StreamTextureHost* host); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 74 |
| 74 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 75 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
| 75 base::AutoLock lock(client_lock_); | 76 base::AutoLock lock(client_lock_); |
| 76 if (client_) | 77 if (client_) |
| 77 client_->DidUpdateMatrix(matrix); | 78 client_->DidUpdateMatrix(matrix); |
| 78 } | 79 } |
| 79 | 80 |
| 80 } // namespace | 81 } // namespace |
| 81 | 82 |
| 82 StreamTextureFactoryImpl::StreamTextureFactoryImpl( | 83 StreamTextureFactoryImpl::StreamTextureFactoryImpl( |
| 83 blink::WebGraphicsContext3D* context, | 84 const scoped_refptr<cc::ContextProvider>& context_provider, |
| 84 GpuChannelHost* channel, | 85 GpuChannelHost* channel, |
| 85 int view_id) | 86 int view_id) |
| 86 : context_(context), channel_(channel), view_id_(view_id) { | 87 : context_provider_(context_provider), |
| 87 DCHECK(context_); | 88 channel_(channel), |
| 89 view_id_(view_id) { |
| 88 DCHECK(channel); | 90 DCHECK(channel); |
| 89 } | 91 } |
| 90 | 92 |
| 91 StreamTextureFactoryImpl::~StreamTextureFactoryImpl() {} | 93 StreamTextureFactoryImpl::~StreamTextureFactoryImpl() {} |
| 92 | 94 |
| 93 StreamTextureProxy* StreamTextureFactoryImpl::CreateProxy() { | 95 StreamTextureProxy* StreamTextureFactoryImpl::CreateProxy() { |
| 94 DCHECK(channel_.get()); | 96 DCHECK(channel_.get()); |
| 95 StreamTextureHost* host = new StreamTextureHost(channel_.get()); | 97 StreamTextureHost* host = new StreamTextureHost(channel_.get()); |
| 96 return new StreamTextureProxyImpl(host); | 98 return new StreamTextureProxyImpl(host); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void StreamTextureFactoryImpl::EstablishPeer(int32 stream_id, int player_id) { | 101 void StreamTextureFactoryImpl::EstablishPeer(int32 stream_id, int player_id) { |
| 100 DCHECK(channel_.get()); | 102 DCHECK(channel_.get()); |
| 101 channel_->Send( | 103 channel_->Send( |
| 102 new GpuChannelMsg_EstablishStreamTexture(stream_id, view_id_, player_id)); | 104 new GpuChannelMsg_EstablishStreamTexture(stream_id, view_id_, player_id)); |
| 103 } | 105 } |
| 104 | 106 |
| 105 unsigned StreamTextureFactoryImpl::CreateStreamTexture( | 107 unsigned StreamTextureFactoryImpl::CreateStreamTexture( |
| 106 unsigned texture_target, | 108 unsigned texture_target, |
| 107 unsigned* texture_id, | 109 unsigned* texture_id, |
| 108 gpu::Mailbox* texture_mailbox, | 110 gpu::Mailbox* texture_mailbox, |
| 109 unsigned* texture_mailbox_sync_point) { | 111 unsigned* texture_mailbox_sync_point) { |
| 110 unsigned stream_id = 0; | 112 GLuint stream_id = 0; |
| 111 if (context_->makeContextCurrent()) { | 113 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
| 112 *texture_id = context_->createTexture(); | 114 gl->GenTextures(1, texture_id); |
| 113 stream_id = context_->createStreamTextureCHROMIUM(*texture_id); | |
| 114 | 115 |
| 115 context_->genMailboxCHROMIUM(texture_mailbox->name); | 116 stream_id = gl->CreateStreamTextureCHROMIUM(*texture_id); |
| 116 context_->bindTexture(texture_target, *texture_id); | |
| 117 context_->produceTextureCHROMIUM(texture_target, texture_mailbox->name); | |
| 118 | 117 |
| 119 context_->flush(); | 118 gl->GenMailboxCHROMIUM(texture_mailbox->name); |
| 120 *texture_mailbox_sync_point = context_->insertSyncPoint(); | 119 gl->BindTexture(texture_target, *texture_id); |
| 121 } | 120 gl->ProduceTextureCHROMIUM(texture_target, texture_mailbox->name); |
| 121 |
| 122 gl->Flush(); |
| 123 *texture_mailbox_sync_point = gl->InsertSyncPointCHROMIUM(); |
| 122 return stream_id; | 124 return stream_id; |
| 123 } | 125 } |
| 124 | 126 |
| 125 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) { | 127 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) { |
| 126 if (context_->makeContextCurrent()) { | 128 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
| 127 // TODO(sievers): Make the destroyStreamTexture implicit when the last | 129 // TODO(sievers): Make the DestroyStreamTexture implicit when the last |
| 128 // texture referencing it is lost. | 130 // texture referencing it is lost. |
| 129 context_->destroyStreamTextureCHROMIUM(texture_id); | 131 gl->DestroyStreamTextureCHROMIUM(texture_id); |
| 130 context_->deleteTexture(texture_id); | 132 gl->DeleteTextures(1, &texture_id); |
| 131 context_->flush(); | 133 gl->Flush(); |
| 132 } | |
| 133 } | 134 } |
| 134 | 135 |
| 135 void StreamTextureFactoryImpl::SetStreamTextureSize( | 136 void StreamTextureFactoryImpl::SetStreamTextureSize( |
| 136 int32 stream_id, const gfx::Size& size) { | 137 int32 stream_id, const gfx::Size& size) { |
| 137 channel_->Send(new GpuChannelMsg_SetStreamTextureSize(stream_id, size)); | 138 channel_->Send(new GpuChannelMsg_SetStreamTextureSize(stream_id, size)); |
| 138 } | 139 } |
| 139 | 140 |
| 140 blink::WebGraphicsContext3D* StreamTextureFactoryImpl::Context3d() { | 141 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { |
| 141 return context_; | 142 return context_provider_->ContextGL(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 } // namespace content | 145 } // namespace content |
| OLD | NEW |