Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: content/common/gpu/media/gpu_video_decode_accelerator.cc

Issue 1796633002: Revert of content gpu refactor: get rid of gpu related content switches. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/gpu/media/gpu_video_decode_accelerator.h" 5 #include "content/common/gpu/media/gpu_video_decode_accelerator.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 18
18 #include "content/common/gpu/gpu_channel.h" 19 #include "content/common/gpu/gpu_channel.h"
19 #include "content/common/gpu/gpu_channel_manager.h"
20 #include "content/common/gpu/media/gpu_video_accelerator_util.h" 20 #include "content/common/gpu/media/gpu_video_accelerator_util.h"
21 #include "content/common/gpu/media/media_messages.h" 21 #include "content/common/gpu/media/media_messages.h"
22 #include "content/public/common/content_switches.h"
22 #include "gpu/command_buffer/common/command_buffer.h" 23 #include "gpu/command_buffer/common/command_buffer.h"
23 #include "gpu/command_buffer/service/gpu_preferences.h"
24 #include "ipc/ipc_message_macros.h" 24 #include "ipc/ipc_message_macros.h"
25 #include "ipc/ipc_message_utils.h" 25 #include "ipc/ipc_message_utils.h"
26 #include "ipc/message_filter.h" 26 #include "ipc/message_filter.h"
27 #include "media/base/limits.h" 27 #include "media/base/limits.h"
28 #include "ui/gl/gl_context.h" 28 #include "ui/gl/gl_context.h"
29 #include "ui/gl/gl_image.h" 29 #include "ui/gl/gl_image.h"
30 #include "ui/gl/gl_surface_egl.h" 30 #include "ui/gl/gl_surface_egl.h"
31 31
32 #if defined(OS_WIN) 32 #if defined(OS_WIN)
33 #include "base/win/windows_version.h" 33 #include "base/win/windows_version.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 145 }
146 146
147 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { 147 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() {
148 // This class can only be self-deleted from OnWillDestroyStub(), which means 148 // This class can only be self-deleted from OnWillDestroyStub(), which means
149 // the VDA has already been destroyed in there. 149 // the VDA has already been destroyed in there.
150 DCHECK(!video_decode_accelerator_); 150 DCHECK(!video_decode_accelerator_);
151 } 151 }
152 152
153 // static 153 // static
154 gpu::VideoDecodeAcceleratorCapabilities 154 gpu::VideoDecodeAcceleratorCapabilities
155 GpuVideoDecodeAccelerator::GetCapabilities( 155 GpuVideoDecodeAccelerator::GetCapabilities() {
156 const gpu::GpuPreferences& gpu_preferences) {
157 media::VideoDecodeAccelerator::Capabilities capabilities; 156 media::VideoDecodeAccelerator::Capabilities capabilities;
158 if (gpu_preferences.disable_accelerated_video_decode) 157 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
158 if (cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
159 return gpu::VideoDecodeAcceleratorCapabilities(); 159 return gpu::VideoDecodeAcceleratorCapabilities();
160 160
161 // Query supported profiles for each VDA. The order of querying VDAs should 161 // Query supported profiles for each VDA. The order of querying VDAs should
162 // be the same as the order of initializing VDAs. Then the returned profile 162 // be the same as the order of initializing VDAs. Then the returned profile
163 // can be initialized by corresponding VDA successfully. 163 // can be initialized by corresponding VDA successfully.
164 #if defined(OS_WIN) 164 #if defined(OS_WIN)
165 capabilities.supported_profiles = 165 capabilities.supported_profiles =
166 DXVAVideoDecodeAccelerator::GetSupportedProfiles(); 166 DXVAVideoDecodeAccelerator::GetSupportedProfiles();
167 #elif defined(OS_CHROMEOS) 167 #elif defined(OS_CHROMEOS)
168 media::VideoDecodeAccelerator::SupportedProfiles vda_profiles; 168 media::VideoDecodeAccelerator::SupportedProfiles vda_profiles;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { 323 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) {
324 if (filter_ && io_task_runner_->BelongsToCurrentThread()) 324 if (filter_ && io_task_runner_->BelongsToCurrentThread())
325 return filter_->SendOnIOThread(message); 325 return filter_->SendOnIOThread(message);
326 DCHECK(child_task_runner_->BelongsToCurrentThread()); 326 DCHECK(child_task_runner_->BelongsToCurrentThread());
327 return stub_->channel()->Send(message); 327 return stub_->channel()->Send(message);
328 } 328 }
329 329
330 bool GpuVideoDecodeAccelerator::Initialize( 330 bool GpuVideoDecodeAccelerator::Initialize(
331 const media::VideoDecodeAccelerator::Config& config) { 331 const media::VideoDecodeAccelerator::Config& config) {
332 const gpu::GpuPreferences& gpu_preferences =
333 stub_->channel()->gpu_channel_manager()->gpu_preferences();
334 if (gpu_preferences.disable_accelerated_video_decode)
335 return false;
336
337 DCHECK(!video_decode_accelerator_); 332 DCHECK(!video_decode_accelerator_);
338 333
339 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { 334 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) {
340 DLOG(ERROR) << "Initialize(): failed to add route"; 335 DLOG(ERROR) << "Initialize(): failed to add route";
341 return false; 336 return false;
342 } 337 }
343 338
344 #if !defined(OS_WIN) 339 #if !defined(OS_WIN)
345 // Ensure we will be able to get a GL context at all before initializing 340 // Ensure we will be able to get a GL context at all before initializing
346 // non-Windows VDAs. 341 // non-Windows VDAs.
347 if (!make_context_current_.Run()) { 342 if (!make_context_current_.Run()) {
348 return false; 343 return false;
349 } 344 }
350 #endif 345 #endif
351 346
352 // Array of Create..VDA() function pointers, maybe applicable to the current 347 // Array of Create..VDA() function pointers, maybe applicable to the current
353 // platform. This list is ordered by priority of use and it should be the 348 // platform. This list is ordered by priority of use and it should be the
354 // same as the order of querying supported profiles of VDAs. 349 // same as the order of querying supported profiles of VDAs.
355 const GpuVideoDecodeAccelerator::CreateVDAFp create_vda_fps[] = { 350 const GpuVideoDecodeAccelerator::CreateVDAFp create_vda_fps[] = {
356 #if defined(OS_WIN) 351 &GpuVideoDecodeAccelerator::CreateDXVAVDA,
357 &GpuVideoDecodeAccelerator::CreateDXVAVDA, 352 &GpuVideoDecodeAccelerator::CreateV4L2VDA,
358 #endif 353 &GpuVideoDecodeAccelerator::CreateV4L2SliceVDA,
359 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) 354 &GpuVideoDecodeAccelerator::CreateVaapiVDA,
360 &GpuVideoDecodeAccelerator::CreateV4L2VDA, 355 &GpuVideoDecodeAccelerator::CreateVTVDA,
361 &GpuVideoDecodeAccelerator::CreateV4L2SliceVDA, 356 &GpuVideoDecodeAccelerator::CreateOzoneVDA,
362 #endif 357 &GpuVideoDecodeAccelerator::CreateAndroidVDA};
363 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
364 &GpuVideoDecodeAccelerator::CreateVaapiVDA,
365 #endif
366 #if defined(OS_MACOSX)
367 &GpuVideoDecodeAccelerator::CreateVTVDA,
368 #endif
369 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
370 &GpuVideoDecodeAccelerator::CreateOzoneVDA,
371 #endif
372 #if defined(OS_ANDROID)
373 &GpuVideoDecodeAccelerator::CreateAndroidVDA,
374 #endif
375 };
376 358
377 for (const auto& create_vda_function : create_vda_fps) { 359 for (const auto& create_vda_function : create_vda_fps) {
378 video_decode_accelerator_ = (this->*create_vda_function)(); 360 video_decode_accelerator_ = (this->*create_vda_function)();
379 if (!video_decode_accelerator_ || 361 if (!video_decode_accelerator_ ||
380 !video_decode_accelerator_->Initialize(config, this)) 362 !video_decode_accelerator_->Initialize(config, this))
381 continue; 363 continue;
382 364
383 if (video_decode_accelerator_->CanDecodeOnIOThread()) { 365 if (video_decode_accelerator_->CanDecodeOnIOThread()) {
384 filter_ = new MessageFilter(this, host_route_id_); 366 filter_ = new MessageFilter(this, host_route_id_);
385 stub_->channel()->AddFilter(filter_.get()); 367 stub_->channel()->AddFilter(filter_.get());
386 } 368 }
387 return true; 369 return true;
388 } 370 }
389 video_decode_accelerator_.reset(); 371 video_decode_accelerator_.reset();
390 LOG(ERROR) << "HW video decode not available for profile " << config.profile 372 LOG(ERROR) << "HW video decode not available for profile " << config.profile
391 << (config.is_encrypted ? " with encryption" : ""); 373 << (config.is_encrypted ? " with encryption" : "");
392 return false; 374 return false;
393 } 375 }
394 376
395 #if defined(OS_WIN)
396 scoped_ptr<media::VideoDecodeAccelerator> 377 scoped_ptr<media::VideoDecodeAccelerator>
397 GpuVideoDecodeAccelerator::CreateDXVAVDA() { 378 GpuVideoDecodeAccelerator::CreateDXVAVDA() {
398 scoped_ptr<media::VideoDecodeAccelerator> decoder; 379 scoped_ptr<media::VideoDecodeAccelerator> decoder;
399 const gpu::GpuPreferences& gpu_preferences = 380 #if defined(OS_WIN)
400 stub_->channel()->gpu_channel_manager()->gpu_preferences();
401 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { 381 if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
402 DVLOG(0) << "Initializing DXVA HW decoder for windows."; 382 DVLOG(0) << "Initializing DXVA HW decoder for windows.";
403 decoder.reset(new DXVAVideoDecodeAccelerator( 383 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_,
404 make_context_current_, stub_->decoder()->GetGLContext(), 384 stub_->decoder()->GetGLContext()));
405 gpu_preferences.enable_accelerated_vpx_decode));
406 } else { 385 } else {
407 NOTIMPLEMENTED() << "HW video decode acceleration not available."; 386 NOTIMPLEMENTED() << "HW video decode acceleration not available.";
408 } 387 }
388 #endif
409 return decoder; 389 return decoder;
410 } 390 }
411 #endif
412 391
413 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
414 scoped_ptr<media::VideoDecodeAccelerator> 392 scoped_ptr<media::VideoDecodeAccelerator>
415 GpuVideoDecodeAccelerator::CreateV4L2VDA() { 393 GpuVideoDecodeAccelerator::CreateV4L2VDA() {
416 scoped_ptr<media::VideoDecodeAccelerator> decoder; 394 scoped_ptr<media::VideoDecodeAccelerator> decoder;
395 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
417 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); 396 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
418 if (device.get()) { 397 if (device.get()) {
419 decoder.reset(new V4L2VideoDecodeAccelerator( 398 decoder.reset(new V4L2VideoDecodeAccelerator(
420 gfx::GLSurfaceEGL::GetHardwareDisplay(), 399 gfx::GLSurfaceEGL::GetHardwareDisplay(),
421 stub_->decoder()->GetGLContext()->GetHandle(), 400 stub_->decoder()->GetGLContext()->GetHandle(),
422 weak_factory_for_io_.GetWeakPtr(), 401 weak_factory_for_io_.GetWeakPtr(),
423 make_context_current_, 402 make_context_current_,
424 device, 403 device,
425 io_task_runner_)); 404 io_task_runner_));
426 } 405 }
406 #endif
427 return decoder; 407 return decoder;
428 } 408 }
429 409
430 scoped_ptr<media::VideoDecodeAccelerator> 410 scoped_ptr<media::VideoDecodeAccelerator>
431 GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() { 411 GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() {
432 scoped_ptr<media::VideoDecodeAccelerator> decoder; 412 scoped_ptr<media::VideoDecodeAccelerator> decoder;
413 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
433 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); 414 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
434 if (device.get()) { 415 if (device.get()) {
435 decoder.reset(new V4L2SliceVideoDecodeAccelerator( 416 decoder.reset(new V4L2SliceVideoDecodeAccelerator(
436 device, 417 device,
437 gfx::GLSurfaceEGL::GetHardwareDisplay(), 418 gfx::GLSurfaceEGL::GetHardwareDisplay(),
438 stub_->decoder()->GetGLContext()->GetHandle(), 419 stub_->decoder()->GetGLContext()->GetHandle(),
439 weak_factory_for_io_.GetWeakPtr(), 420 weak_factory_for_io_.GetWeakPtr(),
440 make_context_current_, 421 make_context_current_,
441 io_task_runner_)); 422 io_task_runner_));
442 } 423 }
424 #endif
443 return decoder; 425 return decoder;
444 } 426 }
445 #endif
446 427
447 #if (defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)) || defined(OS_MACOSX)
448 void GpuVideoDecodeAccelerator::BindImage(uint32_t client_texture_id, 428 void GpuVideoDecodeAccelerator::BindImage(uint32_t client_texture_id,
449 uint32_t texture_target, 429 uint32_t texture_target,
450 scoped_refptr<gl::GLImage> image) { 430 scoped_refptr<gl::GLImage> image) {
451 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); 431 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder();
452 gpu::gles2::TextureManager* texture_manager = 432 gpu::gles2::TextureManager* texture_manager =
453 command_decoder->GetContextGroup()->texture_manager(); 433 command_decoder->GetContextGroup()->texture_manager();
454 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id); 434 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id);
455 if (ref) { 435 if (ref) {
456 texture_manager->SetLevelImage(ref, texture_target, 0, image.get(), 436 texture_manager->SetLevelImage(ref, texture_target, 0, image.get(),
457 gpu::gles2::Texture::BOUND); 437 gpu::gles2::Texture::BOUND);
458 } 438 }
459 } 439 }
460 #endif
461 440
462 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
463 scoped_ptr<media::VideoDecodeAccelerator> 441 scoped_ptr<media::VideoDecodeAccelerator>
464 GpuVideoDecodeAccelerator::CreateVaapiVDA() { 442 GpuVideoDecodeAccelerator::CreateVaapiVDA() {
465 return make_scoped_ptr<media::VideoDecodeAccelerator>( 443 scoped_ptr<media::VideoDecodeAccelerator> decoder;
466 new VaapiVideoDecodeAccelerator( 444 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
467 make_context_current_, 445 decoder.reset(new VaapiVideoDecodeAccelerator(
468 base::Bind(&GpuVideoDecodeAccelerator::BindImage, 446 make_context_current_, base::Bind(&GpuVideoDecodeAccelerator::BindImage,
469 base::Unretained(this)))); 447 base::Unretained(this))));
448 #endif
449 return decoder;
470 } 450 }
471 #endif
472 451
473 #if defined(OS_MACOSX)
474 scoped_ptr<media::VideoDecodeAccelerator> 452 scoped_ptr<media::VideoDecodeAccelerator>
475 GpuVideoDecodeAccelerator::CreateVTVDA() { 453 GpuVideoDecodeAccelerator::CreateVTVDA() {
476 return make_scoped_ptr<media::VideoDecodeAccelerator>( 454 scoped_ptr<media::VideoDecodeAccelerator> decoder;
477 new VTVideoDecodeAccelerator( 455 #if defined(OS_MACOSX)
478 make_context_current_, 456 decoder.reset(new VTVideoDecodeAccelerator(
479 base::Bind(&GpuVideoDecodeAccelerator::BindImage, 457 make_context_current_, base::Bind(&GpuVideoDecodeAccelerator::BindImage,
480 base::Unretained(this)))); 458 base::Unretained(this))));
459 #endif
460 return decoder;
481 } 461 }
482 #endif
483 462
484 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
485 scoped_ptr<media::VideoDecodeAccelerator> 463 scoped_ptr<media::VideoDecodeAccelerator>
486 GpuVideoDecodeAccelerator::CreateOzoneVDA() { 464 GpuVideoDecodeAccelerator::CreateOzoneVDA() {
465 scoped_ptr<media::VideoDecodeAccelerator> decoder;
466 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
487 media::MediaOzonePlatform* platform = 467 media::MediaOzonePlatform* platform =
488 media::MediaOzonePlatform::GetInstance(); 468 media::MediaOzonePlatform::GetInstance();
489 return make_scoped_ptr<media::VideoDecodeAccelerator>( 469 decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_));
490 platform->CreateVideoDecodeAccelerator(make_context_current_)); 470 #endif
471 return decoder;
491 } 472 }
492 #endif
493 473
494 #if defined(OS_ANDROID)
495 scoped_ptr<media::VideoDecodeAccelerator> 474 scoped_ptr<media::VideoDecodeAccelerator>
496 GpuVideoDecodeAccelerator::CreateAndroidVDA() { 475 GpuVideoDecodeAccelerator::CreateAndroidVDA() {
497 return make_scoped_ptr<media::VideoDecodeAccelerator>( 476 scoped_ptr<media::VideoDecodeAccelerator> decoder;
498 new AndroidVideoDecodeAccelerator(stub_->decoder()->AsWeakPtr(), 477 #if defined(OS_ANDROID)
499 make_context_current_)); 478 decoder.reset(new AndroidVideoDecodeAccelerator(stub_->decoder()->AsWeakPtr(),
479 make_context_current_));
480 #endif
481 return decoder;
500 } 482 }
501 #endif
502 483
503 void GpuVideoDecodeAccelerator::OnSetCdm(int cdm_id) { 484 void GpuVideoDecodeAccelerator::OnSetCdm(int cdm_id) {
504 DCHECK(video_decode_accelerator_); 485 DCHECK(video_decode_accelerator_);
505 video_decode_accelerator_->SetCdm(cdm_id); 486 video_decode_accelerator_->SetCdm(cdm_id);
506 } 487 }
507 488
508 void GpuVideoDecodeAccelerator::CallOrPostNotifyError( 489 void GpuVideoDecodeAccelerator::CallOrPostNotifyError(
509 media::VideoDecodeAccelerator::Error error) { 490 media::VideoDecodeAccelerator::Error error) {
510 if (child_task_runner_->BelongsToCurrentThread()) { 491 if (child_task_runner_->BelongsToCurrentThread()) {
511 NotifyError(error); 492 NotifyError(error);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second; 616 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second;
636 GLenum target = texture_ref->texture()->target(); 617 GLenum target = texture_ref->texture()->target();
637 gpu::gles2::TextureManager* texture_manager = 618 gpu::gles2::TextureManager* texture_manager =
638 stub_->decoder()->GetContextGroup()->texture_manager(); 619 stub_->decoder()->GetContextGroup()->texture_manager();
639 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0)); 620 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0));
640 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true); 621 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true);
641 uncleared_textures_.erase(it); 622 uncleared_textures_.erase(it);
642 } 623 }
643 624
644 } // namespace content 625 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/gpu_video_decode_accelerator.h ('k') | content/common/gpu/media/gpu_video_encode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698