| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 std::unique_ptr<RendererGpuVideoAcceleratorFactories> | 47 std::unique_ptr<RendererGpuVideoAcceleratorFactories> |
| 48 RendererGpuVideoAcceleratorFactories::Create( | 48 RendererGpuVideoAcceleratorFactories::Create( |
| 49 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 49 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 50 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, | 50 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, |
| 51 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 51 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 52 const scoped_refptr<ui::ContextProviderCommandBuffer>& context_provider, | 52 const scoped_refptr<ui::ContextProviderCommandBuffer>& context_provider, |
| 53 bool enable_gpu_memory_buffer_video_frames, | 53 bool enable_gpu_memory_buffer_video_frames, |
| 54 const cc::BufferToTextureTargetMap& image_texture_targets, | 54 const cc::BufferToTextureTargetMap& image_texture_targets, |
| 55 bool enable_video_accelerator) { | 55 bool enable_video_decode_accelerator) { |
| 56 RecordContextProviderPhaseUmaEnum( | 56 RecordContextProviderPhaseUmaEnum( |
| 57 ContextProviderPhase::CONTEXT_PROVIDER_ACQUIRED); | 57 ContextProviderPhase::CONTEXT_PROVIDER_ACQUIRED); |
| 58 return base::WrapUnique(new RendererGpuVideoAcceleratorFactories( | 58 return base::WrapUnique(new RendererGpuVideoAcceleratorFactories( |
| 59 std::move(gpu_channel_host), main_thread_task_runner, task_runner, | 59 std::move(gpu_channel_host), main_thread_task_runner, task_runner, |
| 60 context_provider, enable_gpu_memory_buffer_video_frames, | 60 context_provider, enable_gpu_memory_buffer_video_frames, |
| 61 image_texture_targets, enable_video_accelerator)); | 61 image_texture_targets, enable_video_decode_accelerator)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories( | 64 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories( |
| 65 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 65 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 66 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner, |
| 67 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 67 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 68 const scoped_refptr<ui::ContextProviderCommandBuffer>& context_provider, | 68 const scoped_refptr<ui::ContextProviderCommandBuffer>& context_provider, |
| 69 bool enable_gpu_memory_buffer_video_frames, | 69 bool enable_gpu_memory_buffer_video_frames, |
| 70 const cc::BufferToTextureTargetMap& image_texture_targets, | 70 const cc::BufferToTextureTargetMap& image_texture_targets, |
| 71 bool enable_video_accelerator) | 71 bool enable_video_decode_accelerator) |
| 72 : main_thread_task_runner_(main_thread_task_runner), | 72 : main_thread_task_runner_(main_thread_task_runner), |
| 73 task_runner_(task_runner), | 73 task_runner_(task_runner), |
| 74 gpu_channel_host_(std::move(gpu_channel_host)), | 74 gpu_channel_host_(std::move(gpu_channel_host)), |
| 75 context_provider_refptr_(context_provider), | 75 context_provider_refptr_(context_provider), |
| 76 context_provider_(context_provider.get()), | 76 context_provider_(context_provider.get()), |
| 77 enable_gpu_memory_buffer_video_frames_( | 77 enable_gpu_memory_buffer_video_frames_( |
| 78 enable_gpu_memory_buffer_video_frames), | 78 enable_gpu_memory_buffer_video_frames), |
| 79 image_texture_targets_(image_texture_targets), | 79 image_texture_targets_(image_texture_targets), |
| 80 video_accelerator_enabled_(enable_video_accelerator), | 80 video_decode_accelerator_enabled_(enable_video_decode_accelerator), |
| 81 gpu_memory_buffer_manager_( | 81 gpu_memory_buffer_manager_( |
| 82 RenderThreadImpl::current()->GetGpuMemoryBufferManager()), | 82 RenderThreadImpl::current()->GetGpuMemoryBufferManager()), |
| 83 thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) { | 83 thread_safe_sender_(ChildThreadImpl::current()->thread_safe_sender()) { |
| 84 DCHECK(main_thread_task_runner_); | 84 DCHECK(main_thread_task_runner_); |
| 85 DCHECK(gpu_channel_host_); | 85 DCHECK(gpu_channel_host_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 RendererGpuVideoAcceleratorFactories::~RendererGpuVideoAcceleratorFactories() {} | 88 RendererGpuVideoAcceleratorFactories::~RendererGpuVideoAcceleratorFactories() {} |
| 89 | 89 |
| 90 bool RendererGpuVideoAcceleratorFactories::CheckContextLost() { | 90 bool RendererGpuVideoAcceleratorFactories::CheckContextLost() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 103 main_thread_task_runner_->PostTask( | 103 main_thread_task_runner_->PostTask( |
| 104 FROM_HERE, | 104 FROM_HERE, |
| 105 base::Bind( | 105 base::Bind( |
| 106 &RendererGpuVideoAcceleratorFactories::ReleaseContextProvider, | 106 &RendererGpuVideoAcceleratorFactories::ReleaseContextProvider, |
| 107 base::Unretained(this))); | 107 base::Unretained(this))); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 return !context_provider_; | 110 return !context_provider_; |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool RendererGpuVideoAcceleratorFactories::IsGpuVideoAcceleratorEnabled() { | 113 bool RendererGpuVideoAcceleratorFactories:: |
| 114 return video_accelerator_enabled_; | 114 IsGpuVideoDecodeAcceleratorEnabled() { |
| 115 return video_decode_accelerator_enabled_; |
| 115 } | 116 } |
| 116 | 117 |
| 117 base::UnguessableToken RendererGpuVideoAcceleratorFactories::GetChannelToken() { | 118 base::UnguessableToken RendererGpuVideoAcceleratorFactories::GetChannelToken() { |
| 118 DCHECK(task_runner_->BelongsToCurrentThread()); | 119 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 119 if (CheckContextLost()) | 120 if (CheckContextLost()) |
| 120 return base::UnguessableToken(); | 121 return base::UnguessableToken(); |
| 121 | 122 |
| 122 if (channel_token_.is_empty()) { | 123 if (channel_token_.is_empty()) { |
| 123 context_provider_->GetCommandBufferProxy()->channel()->Send( | 124 context_provider_->GetCommandBufferProxy()->channel()->Send( |
| 124 new GpuCommandBufferMsg_GetChannelToken(&channel_token_)); | 125 new GpuCommandBufferMsg_GetChannelToken(&channel_token_)); |
| 125 } | 126 } |
| 126 | 127 |
| 127 return channel_token_; | 128 return channel_token_; |
| 128 } | 129 } |
| 129 | 130 |
| 130 int32_t RendererGpuVideoAcceleratorFactories::GetCommandBufferRouteId() { | 131 int32_t RendererGpuVideoAcceleratorFactories::GetCommandBufferRouteId() { |
| 131 DCHECK(task_runner_->BelongsToCurrentThread()); | 132 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 132 if (CheckContextLost()) | 133 if (CheckContextLost()) |
| 133 return 0; | 134 return 0; |
| 134 return context_provider_->GetCommandBufferProxy()->route_id(); | 135 return context_provider_->GetCommandBufferProxy()->route_id(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 std::unique_ptr<media::VideoDecodeAccelerator> | 138 std::unique_ptr<media::VideoDecodeAccelerator> |
| 138 RendererGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() { | 139 RendererGpuVideoAcceleratorFactories::CreateVideoDecodeAccelerator() { |
| 139 DCHECK(video_accelerator_enabled_); | 140 DCHECK(video_decode_accelerator_enabled_); |
| 140 DCHECK(task_runner_->BelongsToCurrentThread()); | 141 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 141 if (CheckContextLost()) | 142 if (CheckContextLost()) |
| 142 return nullptr; | 143 return nullptr; |
| 143 | 144 |
| 144 return std::unique_ptr<media::VideoDecodeAccelerator>( | 145 return std::unique_ptr<media::VideoDecodeAccelerator>( |
| 145 new media::GpuVideoDecodeAcceleratorHost( | 146 new media::GpuVideoDecodeAcceleratorHost( |
| 146 context_provider_->GetCommandBufferProxy())); | 147 context_provider_->GetCommandBufferProxy())); |
| 147 } | 148 } |
| 148 | 149 |
| 149 std::unique_ptr<media::VideoEncodeAccelerator> | 150 std::unique_ptr<media::VideoEncodeAccelerator> |
| 150 RendererGpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator() { | 151 RendererGpuVideoAcceleratorFactories::CreateVideoEncodeAccelerator() { |
| 151 DCHECK(video_accelerator_enabled_); | |
| 152 DCHECK(task_runner_->BelongsToCurrentThread()); | 152 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 153 if (CheckContextLost()) | 153 if (CheckContextLost()) |
| 154 return nullptr; | 154 return nullptr; |
| 155 | 155 |
| 156 return std::unique_ptr<media::VideoEncodeAccelerator>( | 156 return std::unique_ptr<media::VideoEncodeAccelerator>( |
| 157 new media::GpuVideoEncodeAcceleratorHost( | 157 new media::GpuVideoEncodeAcceleratorHost( |
| 158 context_provider_->GetCommandBufferProxy())); | 158 context_provider_->GetCommandBufferProxy())); |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool RendererGpuVideoAcceleratorFactories::CreateTextures( | 161 bool RendererGpuVideoAcceleratorFactories::CreateTextures( |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 context_provider_refptr_ = nullptr; | 337 context_provider_refptr_ = nullptr; |
| 338 } | 338 } |
| 339 | 339 |
| 340 scoped_refptr<ui::ContextProviderCommandBuffer> | 340 scoped_refptr<ui::ContextProviderCommandBuffer> |
| 341 RendererGpuVideoAcceleratorFactories::ContextProviderMainThread() { | 341 RendererGpuVideoAcceleratorFactories::ContextProviderMainThread() { |
| 342 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 342 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 343 return context_provider_refptr_; | 343 return context_provider_refptr_; |
| 344 } | 344 } |
| 345 | 345 |
| 346 } // namespace content | 346 } // namespace content |
| OLD | NEW |