Chromium Code Reviews| 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) { |
| 27 media::VideoDecodeAccelerator* vda = NULL; | 28 media::VideoDecodeAccelerator* vda = NULL; |
| 28 base::WaitableEvent waiter(false, false); | 29 base::WaitableEvent waiter(false, false); |
| 29 message_loop_->PostTask(FROM_HERE, base::Bind( | 30 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 30 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator, | 31 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator, |
| 31 this, profile, client, &vda, &waiter)); | 32 this, profile, client, &vda, &waiter)); |
| 32 waiter.Wait(); | 33 waiter.Wait(); |
|
jamesr
2012/03/08 05:34:06
wait, it's async but we block on it? that looks mo
Ami GONE FROM CHROMIUM
2012/03/08 17:39:50
*this* method is sync; the called method is async.
| |
| 33 return vda; | 34 return vda; |
| 34 } | 35 } |
| 35 | 36 |
| 36 void RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator( | 37 void RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator( |
| 37 media::VideoDecodeAccelerator::Profile profile, | 38 media::VideoDecodeAccelerator::Profile profile, |
| 38 media::VideoDecodeAccelerator::Client* client, | 39 media::VideoDecodeAccelerator::Client* client, |
| 39 media::VideoDecodeAccelerator** vda, | 40 media::VideoDecodeAccelerator** vda, |
| 40 base::WaitableEvent* waiter) { | 41 base::WaitableEvent* waiter) { |
| 41 if (context_) { | 42 if (wgc3dcbi_->makeContextCurrent()) { |
|
jamesr
2012/03/08 05:34:06
in chromium land is it typical practice to DCHECK(
Ami GONE FROM CHROMIUM
2012/03/08 17:39:50
Done.
| |
| 42 *vda = gpu_channel_host_->CreateVideoDecoder( | 43 *vda = gpu_channel_host_->CreateVideoDecoder( |
| 43 context_->GetCommandBufferProxy()->route_id(), profile, client); | 44 wgc3dcbi_->context()->GetCommandBufferProxy()->route_id(), |
| 45 profile, client); | |
| 44 } else { | 46 } else { |
| 45 *vda = NULL; | 47 *vda = NULL; |
| 46 } | 48 } |
| 47 waiter->Signal(); | 49 waiter->Signal(); |
| 48 } | 50 } |
| 49 | 51 |
| 50 bool RendererGpuVideoDecoderFactories::CreateTextures( | 52 bool RendererGpuVideoDecoderFactories::CreateTextures( |
| 51 int32 count, const gfx::Size& size, | 53 int32 count, const gfx::Size& size, |
| 52 std::vector<uint32>* texture_ids, | 54 std::vector<uint32>* texture_ids, |
| 53 uint32* texture_target) { | 55 uint32* texture_target) { |
| 54 bool success = false; | 56 bool success = false; |
| 55 base::WaitableEvent waiter(false, false); | 57 base::WaitableEvent waiter(false, false); |
| 56 message_loop_->PostTask(FROM_HERE, base::Bind( | 58 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 57 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, | 59 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, |
| 58 count, size, texture_ids, texture_target, &success, &waiter)); | 60 count, size, texture_ids, texture_target, &success, &waiter)); |
| 59 waiter.Wait(); | 61 waiter.Wait(); |
| 60 return success; | 62 return success; |
| 61 } | 63 } |
| 62 | 64 |
| 63 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( | 65 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( |
| 64 int32 count, const gfx::Size& size, std::vector<uint32>* texture_ids, | 66 int32 count, const gfx::Size& size, std::vector<uint32>* texture_ids, |
| 65 uint32* texture_target, bool* success, base::WaitableEvent* waiter) { | 67 uint32* texture_target, bool* success, base::WaitableEvent* waiter) { |
| 66 if (!context_) { | 68 if (!wgc3dcbi_->makeContextCurrent()) { |
| 67 *success = false; | 69 *success = false; |
| 68 waiter->Signal(); | 70 waiter->Signal(); |
| 69 return; | 71 return; |
| 70 } | 72 } |
| 71 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 73 gpu::gles2::GLES2Implementation* gles2 = |
| 74 wgc3dcbi_->context()->GetImplementation(); | |
| 72 texture_ids->resize(count); | 75 texture_ids->resize(count); |
| 73 gles2->GenTextures(count, &texture_ids->at(0)); | 76 gles2->GenTextures(count, &texture_ids->at(0)); |
| 74 *texture_target = GL_TEXTURE_2D; | 77 *texture_target = GL_TEXTURE_2D; |
| 75 for (int i = 0; i < count; ++i) { | 78 for (int i = 0; i < count; ++i) { |
| 76 gles2->ActiveTexture(GL_TEXTURE0); | 79 gles2->ActiveTexture(GL_TEXTURE0); |
| 77 uint32 texture_id = texture_ids->at(i); | 80 uint32 texture_id = texture_ids->at(i); |
| 78 gles2->BindTexture(*texture_target, texture_id); | 81 gles2->BindTexture(*texture_target, texture_id); |
| 79 gles2->TexParameteri(*texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 82 gles2->TexParameteri(*texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 80 gles2->TexParameteri(*texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 83 gles2->TexParameteri(*texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 81 gles2->TexParameterf(*texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 84 gles2->TexParameterf(*texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 92 waiter->Signal(); | 95 waiter->Signal(); |
| 93 } | 96 } |
| 94 | 97 |
| 95 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { | 98 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { |
| 96 message_loop_->PostTask(FROM_HERE, base::Bind( | 99 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 97 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); | 100 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { | 103 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { |
| 101 DCHECK_EQ(MessageLoop::current(), message_loop_); | 104 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 102 if (!context_) | 105 if (!wgc3dcbi_->makeContextCurrent()) |
| 103 return; | 106 return; |
| 104 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 107 gpu::gles2::GLES2Implementation* gles2 = |
| 108 wgc3dcbi_->context()->GetImplementation(); | |
| 105 gles2->DeleteTextures(1, &texture_id); | 109 gles2->DeleteTextures(1, &texture_id); |
| 106 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 110 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 107 } | 111 } |
| 108 | 112 |
| 109 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( | 113 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( |
| 110 size_t size) { | 114 size_t size) { |
| 111 base::SharedMemory* shm = NULL; | 115 base::SharedMemory* shm = NULL; |
| 112 base::WaitableEvent waiter(false, false); | 116 base::WaitableEvent waiter(false, false); |
| 113 message_loop_->PostTask(FROM_HERE, base::Bind( | 117 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 114 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, | 118 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, |
| 115 size, &shm, &waiter)); | 119 size, &shm, &waiter)); |
| 116 waiter.Wait(); | 120 waiter.Wait(); |
| 117 return shm; | 121 return shm; |
| 118 } | 122 } |
| 119 | 123 |
| 120 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( | 124 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( |
| 121 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { | 125 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { |
| 122 *shm = ChildThread::current()->AllocateSharedMemory(size); | 126 *shm = ChildThread::current()->AllocateSharedMemory(size); |
| 123 waiter->Signal(); | 127 waiter->Signal(); |
| 124 } | 128 } |
| OLD | NEW |