| 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" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "cc/output/context_provider.h" | 12 #include "cc/output/context_provider.h" |
| 13 #include "content/child/child_gpu_memory_buffer_manager.h" | 13 #include "content/child/child_gpu_memory_buffer_manager.h" |
| 14 #include "content/child/child_thread_impl.h" | 14 #include "content/child/child_thread_impl.h" |
| 15 #include "content/common/gpu/client/context_provider_command_buffer.h" | 15 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 16 #include "content/common/gpu/client/gpu_channel_host.h" | |
| 17 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h" | 16 #include "content/common/gpu/client/gpu_video_decode_accelerator_host.h" |
| 18 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | 17 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
| 19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 18 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 20 #include "content/common/gpu/media/gpu_video_accelerator_util.h" | 19 #include "content/common/gpu/media/gpu_video_accelerator_util.h" |
| 21 #include "content/renderer/render_thread_impl.h" | 20 #include "content/renderer/render_thread_impl.h" |
| 22 #include "gpu/command_buffer/client/gles2_interface.h" | 21 #include "gpu/command_buffer/client/gles2_interface.h" |
| 23 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 22 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 23 #include "gpu/ipc/client/gpu_channel_host.h" |
| 24 #include "media/video/video_decode_accelerator.h" | 24 #include "media/video/video_decode_accelerator.h" |
| 25 #include "media/video/video_encode_accelerator.h" | 25 #include "media/video/video_encode_accelerator.h" |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // This enum values match ContextProviderPhase in histograms.xml | 31 // This enum values match ContextProviderPhase in histograms.xml |
| 32 enum ContextProviderPhase { | 32 enum ContextProviderPhase { |
| 33 CONTEXT_PROVIDER_ACQUIRED = 0, | 33 CONTEXT_PROVIDER_ACQUIRED = 0, |
| 34 CONTEXT_PROVIDER_RELEASED = 1, | 34 CONTEXT_PROVIDER_RELEASED = 1, |
| 35 CONTEXT_PROVIDER_RELEASED_MAX_VALUE = CONTEXT_PROVIDER_RELEASED, | 35 CONTEXT_PROVIDER_RELEASED_MAX_VALUE = CONTEXT_PROVIDER_RELEASED, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 void RecordContextProviderPhaseUmaEnum(const ContextProviderPhase phase) { | 38 void RecordContextProviderPhaseUmaEnum(const ContextProviderPhase phase) { |
| 39 UMA_HISTOGRAM_ENUMERATION("Media.GPU.HasEverLostContext", phase, | 39 UMA_HISTOGRAM_ENUMERATION("Media.GPU.HasEverLostContext", phase, |
| 40 CONTEXT_PROVIDER_RELEASED_MAX_VALUE + 1); | 40 CONTEXT_PROVIDER_RELEASED_MAX_VALUE + 1); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 // static | 45 // static |
| 46 scoped_ptr<RendererGpuVideoAcceleratorFactories> | 46 scoped_ptr<RendererGpuVideoAcceleratorFactories> |
| 47 RendererGpuVideoAcceleratorFactories::Create( | 47 RendererGpuVideoAcceleratorFactories::Create( |
| 48 GpuChannelHost* gpu_channel_host, | 48 gpu::GpuChannelHost* gpu_channel_host, |
| 49 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, | 49 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, |
| 50 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 50 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 51 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 51 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
| 52 bool enable_gpu_memory_buffer_video_frames, | 52 bool enable_gpu_memory_buffer_video_frames, |
| 53 std::vector<unsigned> image_texture_targets, | 53 std::vector<unsigned> image_texture_targets, |
| 54 bool enable_video_accelerator) { | 54 bool enable_video_accelerator) { |
| 55 RecordContextProviderPhaseUmaEnum( | 55 RecordContextProviderPhaseUmaEnum( |
| 56 ContextProviderPhase::CONTEXT_PROVIDER_ACQUIRED); | 56 ContextProviderPhase::CONTEXT_PROVIDER_ACQUIRED); |
| 57 return make_scoped_ptr(new RendererGpuVideoAcceleratorFactories( | 57 return make_scoped_ptr(new RendererGpuVideoAcceleratorFactories( |
| 58 gpu_channel_host, main_thread_task_runner, task_runner, context_provider, | 58 gpu_channel_host, main_thread_task_runner, task_runner, context_provider, |
| 59 enable_gpu_memory_buffer_video_frames, image_texture_targets, | 59 enable_gpu_memory_buffer_video_frames, image_texture_targets, |
| 60 enable_video_accelerator)); | 60 enable_video_accelerator)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories( | 63 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories( |
| 64 GpuChannelHost* gpu_channel_host, | 64 gpu::GpuChannelHost* gpu_channel_host, |
| 65 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, | 65 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, |
| 66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 67 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 67 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
| 68 bool enable_gpu_memory_buffer_video_frames, | 68 bool enable_gpu_memory_buffer_video_frames, |
| 69 std::vector<unsigned> image_texture_targets, | 69 std::vector<unsigned> image_texture_targets, |
| 70 bool enable_video_accelerator) | 70 bool enable_video_accelerator) |
| 71 : main_thread_task_runner_(main_thread_task_runner), | 71 : main_thread_task_runner_(main_thread_task_runner), |
| 72 task_runner_(task_runner), | 72 task_runner_(task_runner), |
| 73 gpu_channel_host_(gpu_channel_host), | 73 gpu_channel_host_(gpu_channel_host), |
| 74 context_provider_refptr_(context_provider), | 74 context_provider_refptr_(context_provider), |
| 75 context_provider_(context_provider.get()), | 75 context_provider_(context_provider.get()), |
| 76 enable_gpu_memory_buffer_video_frames_( | 76 enable_gpu_memory_buffer_video_frames_( |
| 77 enable_gpu_memory_buffer_video_frames), | 77 enable_gpu_memory_buffer_video_frames), |
| 78 image_texture_targets_(image_texture_targets), | 78 image_texture_targets_(image_texture_targets), |
| 79 video_accelerator_enabled_(enable_video_accelerator), | 79 video_accelerator_enabled_(enable_video_accelerator), |
| 80 gpu_memory_buffer_manager_(ChildThreadImpl::current() | 80 gpu_memory_buffer_manager_( |
| 81 ->gpu_memory_buffer_manager()), | 81 ChildThreadImpl::current()->gpu_memory_buffer_manager()), |
| 82 thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) { | 82 thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) { |
| 83 DCHECK(main_thread_task_runner_); | 83 DCHECK(main_thread_task_runner_); |
| 84 DCHECK(gpu_channel_host_); | 84 DCHECK(gpu_channel_host_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 RendererGpuVideoAcceleratorFactories::~RendererGpuVideoAcceleratorFactories() {} | 87 RendererGpuVideoAcceleratorFactories::~RendererGpuVideoAcceleratorFactories() {} |
| 88 | 88 |
| 89 bool RendererGpuVideoAcceleratorFactories::CheckContextLost() { | 89 bool RendererGpuVideoAcceleratorFactories::CheckContextLost() { |
| 90 DCHECK(task_runner_->BelongsToCurrentThread()); | 90 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 91 if (context_provider_) { | 91 if (context_provider_) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 107 return video_accelerator_enabled_; | 107 return video_accelerator_enabled_; |
| 108 } | 108 } |
| 109 | 109 |
| 110 scoped_ptr<media::VideoDecodeAccelerator> | 110 scoped_ptr<media::VideoDecodeAccelerator> |
| 111 RendererGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() { | 111 RendererGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() { |
| 112 DCHECK(video_accelerator_enabled_); | 112 DCHECK(video_accelerator_enabled_); |
| 113 DCHECK(task_runner_->BelongsToCurrentThread()); | 113 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 114 if (CheckContextLost()) | 114 if (CheckContextLost()) |
| 115 return nullptr; | 115 return nullptr; |
| 116 | 116 |
| 117 GpuChannelHost* channel = | 117 gpu::GpuChannelHost* channel = |
| 118 context_provider_->GetCommandBufferProxy()->channel(); | 118 context_provider_->GetCommandBufferProxy()->channel(); |
| 119 DCHECK(channel); | 119 DCHECK(channel); |
| 120 | 120 |
| 121 return scoped_ptr<media::VideoDecodeAccelerator>( | 121 return scoped_ptr<media::VideoDecodeAccelerator>( |
| 122 new GpuVideoDecodeAcceleratorHost( | 122 new GpuVideoDecodeAcceleratorHost( |
| 123 channel, context_provider_->GetCommandBufferProxy())); | 123 channel, context_provider_->GetCommandBufferProxy())); |
| 124 } | 124 } |
| 125 | 125 |
| 126 scoped_ptr<media::VideoEncodeAccelerator> | 126 scoped_ptr<media::VideoEncodeAccelerator> |
| 127 RendererGpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator() { | 127 RendererGpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator() { |
| 128 DCHECK(video_accelerator_enabled_); | 128 DCHECK(video_accelerator_enabled_); |
| 129 DCHECK(task_runner_->BelongsToCurrentThread()); | 129 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 130 if (CheckContextLost()) | 130 if (CheckContextLost()) |
| 131 return nullptr; | 131 return nullptr; |
| 132 | 132 |
| 133 GpuChannelHost* channel = | 133 gpu::GpuChannelHost* channel = |
| 134 context_provider_->GetCommandBufferProxy()->channel(); | 134 context_provider_->GetCommandBufferProxy()->channel(); |
| 135 DCHECK(channel); | 135 DCHECK(channel); |
| 136 | 136 |
| 137 return scoped_ptr<media::VideoEncodeAccelerator>( | 137 return scoped_ptr<media::VideoEncodeAccelerator>( |
| 138 new GpuVideoEncodeAcceleratorHost( | 138 new GpuVideoEncodeAcceleratorHost( |
| 139 channel, context_provider_->GetCommandBufferProxy())); | 139 channel, context_provider_->GetCommandBufferProxy())); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool RendererGpuVideoAcceleratorFactories::CreateTextures( | 142 bool RendererGpuVideoAcceleratorFactories::CreateTextures( |
| 143 int32_t count, | 143 int32_t count, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 context_provider_refptr_ = nullptr; | 304 context_provider_refptr_ = nullptr; |
| 305 } | 305 } |
| 306 | 306 |
| 307 scoped_refptr<ContextProviderCommandBuffer> | 307 scoped_refptr<ContextProviderCommandBuffer> |
| 308 RendererGpuVideoAcceleratorFactories::ContextProviderMainThread() { | 308 RendererGpuVideoAcceleratorFactories::ContextProviderMainThread() { |
| 309 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 309 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 310 return context_provider_refptr_; | 310 return context_provider_refptr_; |
| 311 } | 311 } |
| 312 | 312 |
| 313 } // namespace content | 313 } // namespace content |
| OLD | NEW |