OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_accelerator_factories.h" | 5 #include "content/renderer/media/renderer_gpu_video_accelerator_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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 // Unretained to avoid ref/deref'ing |*this|, which is not yet | 44 // Unretained to avoid ref/deref'ing |*this|, which is not yet |
45 // stored in a scoped_refptr. Safe because the Wait() below | 45 // stored in a scoped_refptr. Safe because the Wait() below |
46 // keeps us alive until this task completes. | 46 // keeps us alive until this task completes. |
47 base::Unretained(this), | 47 base::Unretained(this), |
48 // OK to pass raw because the pointee is only deleted on the | 48 // OK to pass raw because the pointee is only deleted on the |
49 // compositor thread, and only as the result of a PostTask from | 49 // compositor thread, and only as the result of a PostTask from |
50 // the render thread which can only happen after this function | 50 // the render thread which can only happen after this function |
51 // returns, so our PostTask will run first. | 51 // returns, so our PostTask will run first. |
52 context)); | 52 context)); |
53 message_loop_async_waiter_.Wait(); | 53 message_loop_async_waiter_.Wait(); |
54 | |
55 shm_alloc_thread_.reset( | |
56 new base::Thread("RendererGpuVideoAccelFactsSHMAllocThread")); | |
57 CHECK(shm_alloc_thread_->Start()); | |
58 | |
59 shm_alloc_message_loop_ = shm_alloc_thread_->message_loop_proxy(); | |
54 } | 60 } |
55 | 61 |
56 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories() | 62 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories() |
57 : aborted_waiter_(true, false), | 63 : aborted_waiter_(true, false), |
58 message_loop_async_waiter_(false, false), | 64 message_loop_async_waiter_(false, false), |
59 render_thread_async_waiter_(false, false) {} | 65 render_thread_async_waiter_(false, false) {} |
60 | 66 |
61 void RendererGpuVideoAcceleratorFactories::AsyncGetContext( | 67 void RendererGpuVideoAcceleratorFactories::AsyncGetContext( |
62 WebGraphicsContext3DCommandBufferImpl* context) { | 68 WebGraphicsContext3DCommandBufferImpl* context) { |
63 context_ = context->AsWeakPtr(); | 69 context_ = context->AsWeakPtr(); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 GL_UNSIGNED_BYTE, | 362 GL_UNSIGNED_BYTE, |
357 read_pixels_bitmap_.pixelRef()->pixels()); | 363 read_pixels_bitmap_.pixelRef()->pixels()); |
358 gles2->DeleteFramebuffers(1, &fb); | 364 gles2->DeleteFramebuffers(1, &fb); |
359 gles2->DeleteTextures(1, &tmp_texture); | 365 gles2->DeleteTextures(1, &tmp_texture); |
360 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 366 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
361 message_loop_async_waiter_.Signal(); | 367 message_loop_async_waiter_.Signal(); |
362 } | 368 } |
363 | 369 |
364 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory( | 370 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory( |
365 size_t size) { | 371 size_t size) { |
366 if (main_message_loop_->BelongsToCurrentThread()) { | 372 if (shm_alloc_message_loop_->BelongsToCurrentThread()) { |
367 return ChildThread::current()->AllocateSharedMemory(size); | 373 return ChildThread::current()->AllocateSharedMemory(size); |
368 } | 374 } |
369 main_message_loop_->PostTask( | 375 shm_alloc_message_loop_->PostTask( |
370 FROM_HERE, | 376 FROM_HERE, |
371 base::Bind(&RendererGpuVideoAcceleratorFactories::AsyncCreateSharedMemory, | 377 base::Bind(&RendererGpuVideoAcceleratorFactories::AsyncCreateSharedMemory, |
372 this, | 378 this, |
373 size)); | 379 size)); |
374 | 380 |
375 base::WaitableEvent* objects[] = {&aborted_waiter_, | 381 base::WaitableEvent* objects[] = {&aborted_waiter_, |
376 &render_thread_async_waiter_}; | 382 &render_thread_async_waiter_}; |
377 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) | 383 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) |
378 return NULL; | 384 return NULL; |
379 return shared_memory_segment_.release(); | 385 return shared_memory_segment_.release(); |
380 } | 386 } |
381 | 387 |
382 void RendererGpuVideoAcceleratorFactories::AsyncCreateSharedMemory( | 388 void RendererGpuVideoAcceleratorFactories::AsyncCreateSharedMemory( |
383 size_t size) { | 389 size_t size) { |
384 DCHECK_EQ(base::MessageLoop::current(), | 390 DCHECK(shm_alloc_message_loop_->BelongsToCurrentThread()); |
385 ChildThread::current()->message_loop()); | |
386 | 391 |
387 shared_memory_segment_.reset( | 392 shared_memory_segment_.reset(new base::SharedMemory()); |
388 ChildThread::current()->AllocateSharedMemory(size)); | 393 CHECK(shared_memory_segment_->CreateAndMapAnonymous(size)); |
Ami GONE FROM CHROMIUM
2013/09/04 20:47:56
Do you even sandbox, bro?
How is this working insi
Pawel Osciak
2013/09/05 05:46:33
Real men don't sandbox. Done for all the others.
| |
389 render_thread_async_waiter_.Signal(); | 394 render_thread_async_waiter_.Signal(); |
Ami GONE FROM CHROMIUM
2013/09/04 20:47:56
This is not legit considering it's no longer the r
Pawel Osciak
2013/09/05 05:46:33
Done.
| |
390 } | 395 } |
391 | 396 |
392 scoped_refptr<base::MessageLoopProxy> | 397 scoped_refptr<base::MessageLoopProxy> |
393 RendererGpuVideoAcceleratorFactories::GetMessageLoop() { | 398 RendererGpuVideoAcceleratorFactories::GetMessageLoop() { |
394 return message_loop_; | 399 return message_loop_; |
395 } | 400 } |
396 | 401 |
397 void RendererGpuVideoAcceleratorFactories::Abort() { aborted_waiter_.Signal(); } | 402 void RendererGpuVideoAcceleratorFactories::Abort() { aborted_waiter_.Signal(); } |
398 | 403 |
399 bool RendererGpuVideoAcceleratorFactories::IsAborted() { | 404 bool RendererGpuVideoAcceleratorFactories::IsAborted() { |
400 return aborted_waiter_.IsSignaled(); | 405 return aborted_waiter_.IsSignaled(); |
401 } | 406 } |
402 | 407 |
403 scoped_refptr<RendererGpuVideoAcceleratorFactories> | 408 scoped_refptr<RendererGpuVideoAcceleratorFactories> |
404 RendererGpuVideoAcceleratorFactories::Clone() { | 409 RendererGpuVideoAcceleratorFactories::Clone() { |
405 scoped_refptr<RendererGpuVideoAcceleratorFactories> factories = | 410 scoped_refptr<RendererGpuVideoAcceleratorFactories> factories = |
406 new RendererGpuVideoAcceleratorFactories(); | 411 new RendererGpuVideoAcceleratorFactories(); |
407 factories->message_loop_ = message_loop_; | 412 factories->message_loop_ = message_loop_; |
408 factories->main_message_loop_ = main_message_loop_; | 413 factories->main_message_loop_ = main_message_loop_; |
409 factories->gpu_channel_host_ = gpu_channel_host_; | 414 factories->gpu_channel_host_ = gpu_channel_host_; |
410 factories->context_ = context_; | 415 factories->context_ = context_; |
416 factories->shm_alloc_message_loop_ = shm_alloc_message_loop_; | |
411 return factories; | 417 return factories; |
412 } | 418 } |
413 | 419 |
414 void | 420 void |
415 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoDecodeAccelerator() { | 421 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoDecodeAccelerator() { |
416 // OK to release because Destroy() will delete the VDA instance. | 422 // OK to release because Destroy() will delete the VDA instance. |
417 if (vda_) | 423 if (vda_) |
418 vda_.release()->Destroy(); | 424 vda_.release()->Destroy(); |
419 } | 425 } |
420 | 426 |
421 void | 427 void |
422 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoEncodeAccelerator() { | 428 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoEncodeAccelerator() { |
423 // OK to release because Destroy() will delete the VDA instance. | 429 // OK to release because Destroy() will delete the VDA instance. |
424 if (vea_) | 430 if (vea_) |
425 vea_.release()->Destroy(); | 431 vea_.release()->Destroy(); |
426 } | 432 } |
427 | 433 |
428 } // namespace content | 434 } // namespace content |
OLD | NEW |