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 <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 GpuChannelHost* gpu_channel_host, | 22 GpuChannelHost* gpu_channel_host, |
23 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 23 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
24 WebGraphicsContext3DCommandBufferImpl* context) | 24 WebGraphicsContext3DCommandBufferImpl* context) |
25 : message_loop_(message_loop), | 25 : message_loop_(message_loop), |
26 gpu_channel_host_(gpu_channel_host), | 26 gpu_channel_host_(gpu_channel_host), |
27 aborted_waiter_(true, false), | 27 aborted_waiter_(true, false), |
28 compositor_loop_async_waiter_(false, false), | 28 compositor_loop_async_waiter_(false, false), |
29 render_thread_async_waiter_(false, false) { | 29 render_thread_async_waiter_(false, false) { |
30 if (message_loop_->BelongsToCurrentThread()) { | 30 if (message_loop_->BelongsToCurrentThread()) { |
31 AsyncGetContext(context); | 31 AsyncGetContext(context); |
32 compositor_loop_async_waiter_.Reset(); | |
32 return; | 33 return; |
33 } | 34 } |
34 // Threaded compositor requires us to wait for the context to be acquired. | 35 // Threaded compositor requires us to wait for the context to be acquired. |
35 message_loop_->PostTask(FROM_HERE, base::Bind( | 36 message_loop_->PostTask(FROM_HERE, base::Bind( |
36 &RendererGpuVideoDecoderFactories::AsyncGetContext, | 37 &RendererGpuVideoDecoderFactories::AsyncGetContext, |
37 // Unretained to avoid ref/deref'ing |*this|, which is not yet stored in a | 38 // Unretained to avoid ref/deref'ing |*this|, which is not yet stored in a |
38 // scoped_refptr. Safe because the Wait() below keeps us alive until this | 39 // scoped_refptr. Safe because the Wait() below keeps us alive until this |
39 // task completes. | 40 // task completes. |
40 base::Unretained(this), | 41 base::Unretained(this), |
41 // OK to pass raw because the pointee is only deleted on the compositor | 42 // OK to pass raw because the pointee is only deleted on the compositor |
(...skipping 14 matching lines...) Expand all Loading... | |
56 context_->insertEventMarkerEXT("GpuVDAContext3D"); | 57 context_->insertEventMarkerEXT("GpuVDAContext3D"); |
57 } | 58 } |
58 } | 59 } |
59 compositor_loop_async_waiter_.Signal(); | 60 compositor_loop_async_waiter_.Signal(); |
60 } | 61 } |
61 | 62 |
62 media::VideoDecodeAccelerator* | 63 media::VideoDecodeAccelerator* |
63 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator( | 64 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator( |
64 media::VideoCodecProfile profile, | 65 media::VideoCodecProfile profile, |
65 media::VideoDecodeAccelerator::Client* client) { | 66 media::VideoDecodeAccelerator::Client* client) { |
66 DCHECK(!message_loop_->BelongsToCurrentThread()); | 67 if (message_loop_->BelongsToCurrentThread()) { |
68 AsyncCreateVideoDecodeAccelerator(profile, client); | |
69 compositor_loop_async_waiter_.Reset(); | |
70 return vda_.release(); | |
Ami GONE FROM CHROMIUM
2013/05/29 21:11:46
For consistency with the other similar codepaths b
wuchengli
2013/06/10 12:33:42
I removed DCHECK(!message_loop_->BelongsToCurrentT
| |
71 } | |
67 // The VDA is returned in the vda_ member variable by the | 72 // The VDA is returned in the vda_ member variable by the |
68 // AsyncCreateVideoDecodeAccelerator() function. | 73 // AsyncCreateVideoDecodeAccelerator() function. |
69 message_loop_->PostTask(FROM_HERE, base::Bind( | 74 message_loop_->PostTask(FROM_HERE, base::Bind( |
70 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator, | 75 &RendererGpuVideoDecoderFactories::AsyncCreateVideoDecodeAccelerator, |
71 this, profile, client)); | 76 this, profile, client)); |
72 | 77 |
73 base::WaitableEvent* objects[] = {&aborted_waiter_, | 78 base::WaitableEvent* objects[] = {&aborted_waiter_, |
74 &compositor_loop_async_waiter_}; | 79 &compositor_loop_async_waiter_}; |
75 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) { | 80 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) { |
76 // If we are aborting and the VDA is created by the | 81 // If we are aborting and the VDA is created by the |
(...skipping 17 matching lines...) Expand all Loading... | |
94 context_->GetCommandBufferProxy()->GetRouteID(), | 99 context_->GetCommandBufferProxy()->GetRouteID(), |
95 profile, client); | 100 profile, client); |
96 } | 101 } |
97 compositor_loop_async_waiter_.Signal(); | 102 compositor_loop_async_waiter_.Signal(); |
98 } | 103 } |
99 | 104 |
100 bool RendererGpuVideoDecoderFactories::CreateTextures( | 105 bool RendererGpuVideoDecoderFactories::CreateTextures( |
101 int32 count, const gfx::Size& size, | 106 int32 count, const gfx::Size& size, |
102 std::vector<uint32>* texture_ids, | 107 std::vector<uint32>* texture_ids, |
103 uint32 texture_target) { | 108 uint32 texture_target) { |
109 if (message_loop_->BelongsToCurrentThread()) { | |
110 AsyncCreateTextures(count, size, texture_target); | |
111 texture_ids->swap(created_textures_); | |
112 compositor_loop_async_waiter_.Reset(); | |
113 return true; | |
114 } | |
104 DCHECK(!message_loop_->BelongsToCurrentThread()); | 115 DCHECK(!message_loop_->BelongsToCurrentThread()); |
105 message_loop_->PostTask(FROM_HERE, base::Bind( | 116 message_loop_->PostTask(FROM_HERE, base::Bind( |
106 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, | 117 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, |
107 count, size, texture_target)); | 118 count, size, texture_target)); |
108 | 119 |
109 base::WaitableEvent* objects[] = {&aborted_waiter_, | 120 base::WaitableEvent* objects[] = {&aborted_waiter_, |
110 &compositor_loop_async_waiter_}; | 121 &compositor_loop_async_waiter_}; |
111 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) | 122 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) |
112 return false; | 123 return false; |
113 texture_ids->swap(created_textures_); | 124 texture_ids->swap(created_textures_); |
(...skipping 27 matching lines...) Expand all Loading... | |
141 } | 152 } |
142 // We need a glFlush here to guarantee the decoder (in the GPU process) can | 153 // We need a glFlush here to guarantee the decoder (in the GPU process) can |
143 // use the texture ids we return here. Since textures are expected to be | 154 // use the texture ids we return here. Since textures are expected to be |
144 // reused, this should not be unacceptably expensive. | 155 // reused, this should not be unacceptably expensive. |
145 gles2->Flush(); | 156 gles2->Flush(); |
146 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 157 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
147 compositor_loop_async_waiter_.Signal(); | 158 compositor_loop_async_waiter_.Signal(); |
148 } | 159 } |
149 | 160 |
150 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { | 161 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { |
162 if (message_loop_->BelongsToCurrentThread()) { | |
163 AsyncDeleteTexture(texture_id); | |
164 return; | |
165 } | |
151 DCHECK(!message_loop_->BelongsToCurrentThread()); | 166 DCHECK(!message_loop_->BelongsToCurrentThread()); |
152 message_loop_->PostTask(FROM_HERE, base::Bind( | 167 message_loop_->PostTask(FROM_HERE, base::Bind( |
153 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); | 168 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); |
154 } | 169 } |
155 | 170 |
156 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { | 171 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { |
157 DCHECK(message_loop_->BelongsToCurrentThread()); | 172 DCHECK(message_loop_->BelongsToCurrentThread()); |
158 if (!context_) | 173 if (!context_) |
159 return; | 174 return; |
160 | 175 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 return aborted_waiter_.IsSignaled(); | 272 return aborted_waiter_.IsSignaled(); |
258 } | 273 } |
259 | 274 |
260 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { | 275 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { |
261 // OK to release because Destroy() will delete the VDA instance. | 276 // OK to release because Destroy() will delete the VDA instance. |
262 if (vda_) | 277 if (vda_) |
263 vda_.release()->Destroy(); | 278 vda_.release()->Destroy(); |
264 } | 279 } |
265 | 280 |
266 } // namespace content | 281 } // namespace content |
OLD | NEW |