| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_gpu_video_decoder_factories.h" | 5 #include "content/renderer/media/renderer_gpu_video_decoder_factories.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
| 10 #include "content/common/gpu/client/command_buffer_proxy.h" | 10 #include "content/common/gpu/client/command_buffer_proxy.h" |
| 11 #include "content/common/gpu/client/gpu_channel_host.h" | 11 #include "content/common/gpu/client/gpu_channel_host.h" |
| 12 #include "content/common/gpu/client/content_gl_context.h" | 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 13 #include "gpu/command_buffer/client/gles2_implementation.h" | 13 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 14 | 14 |
| 15 RendererGpuVideoDecoderFactories::~RendererGpuVideoDecoderFactories() {} | 15 RendererGpuVideoDecoderFactories::~RendererGpuVideoDecoderFactories() {} |
| 16 RendererGpuVideoDecoderFactories::RendererGpuVideoDecoderFactories( | 16 RendererGpuVideoDecoderFactories::RendererGpuVideoDecoderFactories( |
| 17 GpuChannelHost* gpu_channel_host, base::WeakPtr<ContentGLContext> context) | 17 GpuChannelHost* gpu_channel_host, MessageLoop* message_loop, |
| 18 : message_loop_(MessageLoop::current()), | 18 WebGraphicsContext3DCommandBufferImpl* wgc3dcbi) |
| 19 : message_loop_(message_loop), |
| 19 gpu_channel_host_(gpu_channel_host), | 20 gpu_channel_host_(gpu_channel_host), |
| 20 context_(context) { | 21 wgc3dcbi_(wgc3dcbi) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 media::VideoDecodeAccelerator* | 24 media::VideoDecodeAccelerator* |
| 24 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator( | 25 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator( |
| 25 media::VideoDecodeAccelerator::Profile profile, | 26 media::VideoDecodeAccelerator::Profile profile, |
| 26 media::VideoDecodeAccelerator::Client* client) { | 27 media::VideoDecodeAccelerator::Client* client) { |
| 28 DCHECK_NE(MessageLoop::current(), message_loop_); |
| 27 media::VideoDecodeAccelerator* vda = NULL; | 29 media::VideoDecodeAccelerator* vda = NULL; |
| 28 base::WaitableEvent waiter(false, false); | 30 base::WaitableEvent waiter(false, false); |
| 29 message_loop_->PostTask(FROM_HERE, base::Bind( | 31 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 30 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator, | 32 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator, |
| 31 this, profile, client, &vda, &waiter)); | 33 this, profile, client, &vda, &waiter)); |
| 32 waiter.Wait(); | 34 waiter.Wait(); |
| 33 return vda; | 35 return vda; |
| 34 } | 36 } |
| 35 | 37 |
| 36 void RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator( | 38 void RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator( |
| 37 media::VideoDecodeAccelerator::Profile profile, | 39 media::VideoDecodeAccelerator::Profile profile, |
| 38 media::VideoDecodeAccelerator::Client* client, | 40 media::VideoDecodeAccelerator::Client* client, |
| 39 media::VideoDecodeAccelerator** vda, | 41 media::VideoDecodeAccelerator** vda, |
| 40 base::WaitableEvent* waiter) { | 42 base::WaitableEvent* waiter) { |
| 41 if (context_) { | 43 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 44 if (wgc3dcbi_->makeContextCurrent()) { |
| 42 *vda = gpu_channel_host_->CreateVideoDecoder( | 45 *vda = gpu_channel_host_->CreateVideoDecoder( |
| 43 context_->GetCommandBufferProxy()->route_id(), profile, client); | 46 wgc3dcbi_->context()->GetCommandBufferProxy()->route_id(), |
| 47 profile, client); |
| 44 } else { | 48 } else { |
| 45 *vda = NULL; | 49 *vda = NULL; |
| 46 } | 50 } |
| 47 waiter->Signal(); | 51 waiter->Signal(); |
| 48 } | 52 } |
| 49 | 53 |
| 50 bool RendererGpuVideoDecoderFactories::CreateTextures( | 54 bool RendererGpuVideoDecoderFactories::CreateTextures( |
| 51 int32 count, const gfx::Size& size, | 55 int32 count, const gfx::Size& size, |
| 52 std::vector<uint32>* texture_ids, | 56 std::vector<uint32>* texture_ids, |
| 53 uint32* texture_target) { | 57 uint32* texture_target) { |
| 58 DCHECK_NE(MessageLoop::current(), message_loop_); |
| 54 bool success = false; | 59 bool success = false; |
| 55 base::WaitableEvent waiter(false, false); | 60 base::WaitableEvent waiter(false, false); |
| 56 message_loop_->PostTask(FROM_HERE, base::Bind( | 61 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 57 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, | 62 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, |
| 58 count, size, texture_ids, texture_target, &success, &waiter)); | 63 count, size, texture_ids, texture_target, &success, &waiter)); |
| 59 waiter.Wait(); | 64 waiter.Wait(); |
| 60 return success; | 65 return success; |
| 61 } | 66 } |
| 62 | 67 |
| 63 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( | 68 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( |
| 64 int32 count, const gfx::Size& size, std::vector<uint32>* texture_ids, | 69 int32 count, const gfx::Size& size, std::vector<uint32>* texture_ids, |
| 65 uint32* texture_target, bool* success, base::WaitableEvent* waiter) { | 70 uint32* texture_target, bool* success, base::WaitableEvent* waiter) { |
| 66 if (!context_) { | 71 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 72 if (!wgc3dcbi_->makeContextCurrent()) { |
| 67 *success = false; | 73 *success = false; |
| 68 waiter->Signal(); | 74 waiter->Signal(); |
| 69 return; | 75 return; |
| 70 } | 76 } |
| 71 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 77 gpu::gles2::GLES2Implementation* gles2 = |
| 78 wgc3dcbi_->context()->GetImplementation(); |
| 72 texture_ids->resize(count); | 79 texture_ids->resize(count); |
| 73 gles2->GenTextures(count, &texture_ids->at(0)); | 80 gles2->GenTextures(count, &texture_ids->at(0)); |
| 74 *texture_target = GL_TEXTURE_2D; | 81 *texture_target = GL_TEXTURE_2D; |
| 75 for (int i = 0; i < count; ++i) { | 82 for (int i = 0; i < count; ++i) { |
| 76 gles2->ActiveTexture(GL_TEXTURE0); | 83 gles2->ActiveTexture(GL_TEXTURE0); |
| 77 uint32 texture_id = texture_ids->at(i); | 84 uint32 texture_id = texture_ids->at(i); |
| 78 gles2->BindTexture(*texture_target, texture_id); | 85 gles2->BindTexture(*texture_target, texture_id); |
| 79 gles2->TexParameteri(*texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 86 gles2->TexParameteri(*texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 80 gles2->TexParameteri(*texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 87 gles2->TexParameteri(*texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 81 gles2->TexParameterf(*texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 88 gles2->TexParameterf(*texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 82 gles2->TexParameterf(*texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 89 gles2->TexParameterf(*texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 83 gles2->TexImage2D(*texture_target, 0, GL_RGBA, size.width(), size.height(), | 90 gles2->TexImage2D(*texture_target, 0, GL_RGBA, size.width(), size.height(), |
| 84 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 91 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 85 } | 92 } |
| 86 // We need a glFlush here to guarantee the decoder (in the GPU process) can | 93 // We need a glFlush here to guarantee the decoder (in the GPU process) can |
| 87 // use the texture ids we return here. Since textures are expected to be | 94 // use the texture ids we return here. Since textures are expected to be |
| 88 // reused, this should not be unacceptably expensive. | 95 // reused, this should not be unacceptably expensive. |
| 89 gles2->Flush(); | 96 gles2->Flush(); |
| 90 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 97 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 91 *success = true; | 98 *success = true; |
| 92 waiter->Signal(); | 99 waiter->Signal(); |
| 93 } | 100 } |
| 94 | 101 |
| 95 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { | 102 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { |
| 103 DCHECK_NE(MessageLoop::current(), message_loop_); |
| 96 message_loop_->PostTask(FROM_HERE, base::Bind( | 104 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 97 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); | 105 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); |
| 98 } | 106 } |
| 99 | 107 |
| 100 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { | 108 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { |
| 101 DCHECK_EQ(MessageLoop::current(), message_loop_); | 109 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 102 if (!context_) | 110 if (!wgc3dcbi_->makeContextCurrent()) |
| 103 return; | 111 return; |
| 104 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 112 gpu::gles2::GLES2Implementation* gles2 = |
| 113 wgc3dcbi_->context()->GetImplementation(); |
| 105 gles2->DeleteTextures(1, &texture_id); | 114 gles2->DeleteTextures(1, &texture_id); |
| 106 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 115 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 107 } | 116 } |
| 108 | 117 |
| 109 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( | 118 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( |
| 110 size_t size) { | 119 size_t size) { |
| 120 DCHECK_NE(MessageLoop::current(), ChildThread::current()->message_loop()); |
| 111 base::SharedMemory* shm = NULL; | 121 base::SharedMemory* shm = NULL; |
| 112 base::WaitableEvent waiter(false, false); | 122 base::WaitableEvent waiter(false, false); |
| 113 message_loop_->PostTask(FROM_HERE, base::Bind( | 123 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 114 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, | 124 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, |
| 115 size, &shm, &waiter)); | 125 size, &shm, &waiter)); |
| 116 waiter.Wait(); | 126 waiter.Wait(); |
| 117 return shm; | 127 return shm; |
| 118 } | 128 } |
| 119 | 129 |
| 120 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( | 130 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( |
| 121 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { | 131 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { |
| 132 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop()); |
| 122 *shm = ChildThread::current()->AllocateSharedMemory(size); | 133 *shm = ChildThread::current()->AllocateSharedMemory(size); |
| 123 waiter->Signal(); | 134 waiter->Signal(); |
| 124 } | 135 } |
| OLD | NEW |