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