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" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "content/common/child_thread.h" | 12 #include "content/common/child_thread.h" |
13 #include "content/common/gpu/client/gpu_channel_host.h" | 13 #include "content/common/gpu/client/gpu_channel_host.h" |
14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
15 #include "gpu/command_buffer/client/gles2_implementation.h" | 15 #include "gpu/command_buffer/client/gles2_implementation.h" |
16 #include "gpu/ipc/command_buffer_proxy.h" | 16 #include "gpu/ipc/command_buffer_proxy.h" |
17 | 17 |
18 RendererGpuVideoDecoderFactories::~RendererGpuVideoDecoderFactories() {} | 18 RendererGpuVideoDecoderFactories::~RendererGpuVideoDecoderFactories() {} |
19 RendererGpuVideoDecoderFactories::RendererGpuVideoDecoderFactories( | 19 RendererGpuVideoDecoderFactories::RendererGpuVideoDecoderFactories( |
20 GpuChannelHost* gpu_channel_host, | 20 GpuChannelHost* gpu_channel_host, |
21 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 21 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
22 const base::WeakPtr<WebGraphicsContext3DCommandBufferImpl>& context) | 22 WebGraphicsContext3DCommandBufferImpl* context) |
23 : message_loop_(message_loop), | 23 : message_loop_(message_loop), |
24 gpu_channel_host_(gpu_channel_host), | 24 gpu_channel_host_(gpu_channel_host) { |
25 context_(context) { | |
26 DCHECK(context_); | |
27 context_->DetachFromThread(); | |
28 if (message_loop_->BelongsToCurrentThread()) { | 25 if (message_loop_->BelongsToCurrentThread()) { |
29 AsyncGetContext(NULL); | 26 AsyncGetContext(context, NULL); |
30 return; | 27 return; |
31 } | 28 } |
32 // Threaded compositor requires us to wait for the context to be acquired. | 29 // Threaded compositor requires us to wait for the context to be acquired. |
33 base::WaitableEvent waiter(false, false); | 30 base::WaitableEvent waiter(false, false); |
34 message_loop_->PostTask(FROM_HERE, base::Bind( | 31 message_loop_->PostTask(FROM_HERE, base::Bind( |
35 &RendererGpuVideoDecoderFactories::AsyncGetContext, | 32 &RendererGpuVideoDecoderFactories::AsyncGetContext, |
36 // Unretained to avoid ref/deref'ing |*this|, which is not yet stored in a | 33 // Unretained to avoid ref/deref'ing |*this|, which is not yet stored in a |
37 // scoped_refptr. Safe because the Wait() below keeps us alive until this | 34 // scoped_refptr. Safe because the Wait() below keeps us alive until this |
38 // task completes. | 35 // task completes. |
39 base::Unretained(this), &waiter)); | 36 base::Unretained(this), |
| 37 // OK to pass raw because the pointee is only deleted on the compositor |
| 38 // thread, and only as the result of a PostTask from the render thread |
| 39 // which can only happen after this function returns, so our PostTask will |
| 40 // run first. |
| 41 context, |
| 42 &waiter)); |
40 waiter.Wait(); | 43 waiter.Wait(); |
41 } | 44 } |
42 | 45 |
43 void RendererGpuVideoDecoderFactories::AsyncGetContext( | 46 void RendererGpuVideoDecoderFactories::AsyncGetContext( |
| 47 WebGraphicsContext3DCommandBufferImpl* context, |
44 base::WaitableEvent* waiter) { | 48 base::WaitableEvent* waiter) { |
| 49 context_ = context->AsWeakPtr(); |
45 if (context_) | 50 if (context_) |
46 context_->makeContextCurrent(); | 51 context_->makeContextCurrent(); |
47 if (waiter) | 52 if (waiter) |
48 waiter->Signal(); | 53 waiter->Signal(); |
49 } | 54 } |
50 | 55 |
51 media::VideoDecodeAccelerator* | 56 media::VideoDecodeAccelerator* |
52 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator( | 57 RendererGpuVideoDecoderFactories::CreateVideoDecodeAccelerator( |
53 media::VideoCodecProfile profile, | 58 media::VideoCodecProfile profile, |
54 media::VideoDecodeAccelerator::Client* client) { | 59 media::VideoDecodeAccelerator::Client* client) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 waiter.Wait(); | 158 waiter.Wait(); |
154 return shm; | 159 return shm; |
155 } | 160 } |
156 | 161 |
157 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( | 162 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( |
158 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { | 163 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { |
159 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop()); | 164 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop()); |
160 *shm = ChildThread::current()->AllocateSharedMemory(size); | 165 *shm = ChildThread::current()->AllocateSharedMemory(size); |
161 waiter->Signal(); | 166 waiter->Signal(); |
162 } | 167 } |
OLD | NEW |