Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: content/renderer/media/renderer_gpu_video_decoder_factories.cc

Issue 9639005: HW video decode support for --enable-threaded-compositing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR response. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 gpu_channel_host_(gpu_channel_host), 19 : message_loop_(message_loop),
20 context_(context) { 20 gpu_channel_host_(gpu_channel_host) {
21 if (MessageLoop::current() == message_loop_) {
22 AsyncGetContext(wgc3dcbi, NULL);
23 return;
24 }
25 // Threaded compositor requires us to wait for the context to be acquired.
26 base::WaitableEvent waiter(false, false);
27 message_loop_->PostTask(FROM_HERE, base::Bind(
28 &RendererGpuVideoDecoderFactories::AsyncGetContext,
29 // Unretained to avoid ref/deref'ing |*this|, which is not yet stored in a
30 // scoped_refptr. Safe because the Wait() below keeps us alive until this
31 // task completes.
32 base::Unretained(this), wgc3dcbi, &waiter));
33 waiter.Wait();
34 }
35
36 void RendererGpuVideoDecoderFactories::AsyncGetContext(
37 WebGraphicsContext3DCommandBufferImpl* wgc3dcbi,
38 base::WaitableEvent* waiter) {
39 wgc3dcbi->makeContextCurrent();
40 context_ = wgc3dcbi->context()->AsWeakPtr();
41 if (waiter)
42 waiter->Signal();
21 } 43 }
22 44
23 media::VideoDecodeAccelerator* 45 media::VideoDecodeAccelerator*
24 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator( 46 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator(
25 media::VideoDecodeAccelerator::Profile profile, 47 media::VideoDecodeAccelerator::Profile profile,
26 media::VideoDecodeAccelerator::Client* client) { 48 media::VideoDecodeAccelerator::Client* client) {
49 DCHECK_NE(MessageLoop::current(), message_loop_);
27 media::VideoDecodeAccelerator* vda = NULL; 50 media::VideoDecodeAccelerator* vda = NULL;
28 base::WaitableEvent waiter(false, false); 51 base::WaitableEvent waiter(false, false);
29 message_loop_->PostTask(FROM_HERE, base::Bind( 52 message_loop_->PostTask(FROM_HERE, base::Bind(
30 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator, 53 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator,
31 this, profile, client, &vda, &waiter)); 54 this, profile, client, &vda, &waiter));
32 waiter.Wait(); 55 waiter.Wait();
33 return vda; 56 return vda;
34 } 57 }
35 58
36 void RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator( 59 void RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator(
37 media::VideoDecodeAccelerator::Profile profile, 60 media::VideoDecodeAccelerator::Profile profile,
38 media::VideoDecodeAccelerator::Client* client, 61 media::VideoDecodeAccelerator::Client* client,
39 media::VideoDecodeAccelerator** vda, 62 media::VideoDecodeAccelerator** vda,
40 base::WaitableEvent* waiter) { 63 base::WaitableEvent* waiter) {
64 DCHECK_EQ(MessageLoop::current(), message_loop_);
41 if (context_) { 65 if (context_) {
42 *vda = gpu_channel_host_->CreateVideoDecoder( 66 *vda = gpu_channel_host_->CreateVideoDecoder(
43 context_->GetCommandBufferProxy()->route_id(), profile, client); 67 context_->GetCommandBufferProxy()->route_id(),
68 profile, client);
44 } else { 69 } else {
45 *vda = NULL; 70 *vda = NULL;
46 } 71 }
47 waiter->Signal(); 72 waiter->Signal();
48 } 73 }
49 74
50 bool RendererGpuVideoDecoderFactories::CreateTextures( 75 bool RendererGpuVideoDecoderFactories::CreateTextures(
51 int32 count, const gfx::Size& size, 76 int32 count, const gfx::Size& size,
52 std::vector<uint32>* texture_ids, 77 std::vector<uint32>* texture_ids,
53 uint32* texture_target) { 78 uint32* texture_target) {
79 DCHECK_NE(MessageLoop::current(), message_loop_);
54 bool success = false; 80 bool success = false;
55 base::WaitableEvent waiter(false, false); 81 base::WaitableEvent waiter(false, false);
56 message_loop_->PostTask(FROM_HERE, base::Bind( 82 message_loop_->PostTask(FROM_HERE, base::Bind(
57 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, 83 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this,
58 count, size, texture_ids, texture_target, &success, &waiter)); 84 count, size, texture_ids, texture_target, &success, &waiter));
59 waiter.Wait(); 85 waiter.Wait();
60 return success; 86 return success;
61 } 87 }
62 88
63 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( 89 void RendererGpuVideoDecoderFactories::AsyncCreateTextures(
64 int32 count, const gfx::Size& size, std::vector<uint32>* texture_ids, 90 int32 count, const gfx::Size& size, std::vector<uint32>* texture_ids,
65 uint32* texture_target, bool* success, base::WaitableEvent* waiter) { 91 uint32* texture_target, bool* success, base::WaitableEvent* waiter) {
92 DCHECK_EQ(MessageLoop::current(), message_loop_);
66 if (!context_) { 93 if (!context_) {
67 *success = false; 94 *success = false;
68 waiter->Signal(); 95 waiter->Signal();
69 return; 96 return;
70 } 97 }
71 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); 98 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation();
72 texture_ids->resize(count); 99 texture_ids->resize(count);
73 gles2->GenTextures(count, &texture_ids->at(0)); 100 gles2->GenTextures(count, &texture_ids->at(0));
74 *texture_target = GL_TEXTURE_2D; 101 *texture_target = GL_TEXTURE_2D;
75 for (int i = 0; i < count; ++i) { 102 for (int i = 0; i < count; ++i) {
(...skipping 10 matching lines...) Expand all
86 // We need a glFlush here to guarantee the decoder (in the GPU process) can 113 // 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 114 // use the texture ids we return here. Since textures are expected to be
88 // reused, this should not be unacceptably expensive. 115 // reused, this should not be unacceptably expensive.
89 gles2->Flush(); 116 gles2->Flush();
90 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); 117 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR));
91 *success = true; 118 *success = true;
92 waiter->Signal(); 119 waiter->Signal();
93 } 120 }
94 121
95 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { 122 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) {
123 DCHECK_NE(MessageLoop::current(), message_loop_);
96 message_loop_->PostTask(FROM_HERE, base::Bind( 124 message_loop_->PostTask(FROM_HERE, base::Bind(
97 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); 125 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id));
98 } 126 }
99 127
100 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { 128 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) {
101 DCHECK_EQ(MessageLoop::current(), message_loop_); 129 DCHECK_EQ(MessageLoop::current(), message_loop_);
102 if (!context_) 130 if (!context_)
103 return; 131 return;
104 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); 132 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation();
105 gles2->DeleteTextures(1, &texture_id); 133 gles2->DeleteTextures(1, &texture_id);
106 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); 134 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR));
107 } 135 }
108 136
109 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( 137 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory(
110 size_t size) { 138 size_t size) {
139 DCHECK_NE(MessageLoop::current(), ChildThread::current()->message_loop());
111 base::SharedMemory* shm = NULL; 140 base::SharedMemory* shm = NULL;
112 base::WaitableEvent waiter(false, false); 141 base::WaitableEvent waiter(false, false);
113 message_loop_->PostTask(FROM_HERE, base::Bind( 142 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind(
114 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, 143 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this,
115 size, &shm, &waiter)); 144 size, &shm, &waiter));
116 waiter.Wait(); 145 waiter.Wait();
117 return shm; 146 return shm;
118 } 147 }
119 148
120 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( 149 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory(
121 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { 150 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) {
151 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop());
122 *shm = ChildThread::current()->AllocateSharedMemory(size); 152 *shm = ChildThread::current()->AllocateSharedMemory(size);
123 waiter->Signal(); 153 waiter->Signal();
124 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698