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 "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 VideoResourceUpdater::NewHalfFloatMaker(int bits_per_channel) { | 372 VideoResourceUpdater::NewHalfFloatMaker(int bits_per_channel) { |
373 if (bits_per_channel < 11) { | 373 if (bits_per_channel < 11) { |
374 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( | 374 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( |
375 new HalfFloatMaker_xor(bits_per_channel)); | 375 new HalfFloatMaker_xor(bits_per_channel)); |
376 } else { | 376 } else { |
377 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( | 377 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( |
378 new HalfFloatMaker_libyuv(bits_per_channel)); | 378 new HalfFloatMaker_libyuv(bits_per_channel)); |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 ResourceFormat VideoResourceUpdater::YuvResourceFormat(int bits) const { | |
383 if (!context_provider_) | |
384 return LUMINANCE_8; | |
385 | |
386 const auto caps = context_provider_->ContextCapabilities(); | |
387 if (caps.disable_one_component_textures) | |
388 return RGBA_8888; | |
389 | |
390 ResourceFormat yuv_resource_format = caps.texture_rg ? RED_8 : LUMINANCE_8; | |
391 if (bits <= 8) | |
392 return yuv_resource_format; | |
393 | |
394 if (caps.texture_half_float_linear) | |
395 return LUMINANCE_F16; | |
396 | |
397 return yuv_resource_format; | |
398 } | |
399 | |
400 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 382 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
401 scoped_refptr<media::VideoFrame> video_frame) { | 383 scoped_refptr<media::VideoFrame> video_frame) { |
402 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); | 384 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); |
403 const media::VideoPixelFormat input_frame_format = video_frame->format(); | 385 const media::VideoPixelFormat input_frame_format = video_frame->format(); |
404 | 386 |
405 // TODO(hubbe): Make this a video frame method. | 387 // TODO(hubbe): Make this a video frame method. |
406 int bits_per_channel = 0; | 388 int bits_per_channel = 0; |
407 switch (input_frame_format) { | 389 switch (input_frame_format) { |
408 case media::PIXEL_FORMAT_UNKNOWN: | 390 case media::PIXEL_FORMAT_UNKNOWN: |
409 NOTREACHED(); | 391 NOTREACHED(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 430 |
449 // TODO(dshwang): support PIXEL_FORMAT_Y16. crbug.com/624436 | 431 // TODO(dshwang): support PIXEL_FORMAT_Y16. crbug.com/624436 |
450 DCHECK_NE(bits_per_channel, 16); | 432 DCHECK_NE(bits_per_channel, 16); |
451 | 433 |
452 // Only YUV software video frames are supported. | 434 // Only YUV software video frames are supported. |
453 if (!media::IsYuvPlanar(input_frame_format)) { | 435 if (!media::IsYuvPlanar(input_frame_format)) { |
454 NOTREACHED() << media::VideoPixelFormatToString(input_frame_format); | 436 NOTREACHED() << media::VideoPixelFormatToString(input_frame_format); |
455 return VideoFrameExternalResources(); | 437 return VideoFrameExternalResources(); |
456 } | 438 } |
457 | 439 |
458 const bool software_compositor = context_provider_ == nullptr; | 440 const bool software_compositor = context_provider_ == NULL; |
459 bool disable_one_component_textures = true; | |
460 if (!software_compositor) { | |
461 const auto caps = context_provider_->ContextCapabilities(); | |
462 disable_one_component_textures = caps.disable_one_component_textures; | |
463 } | |
464 | 441 |
465 ResourceFormat output_resource_format = YuvResourceFormat(bits_per_channel); | 442 ResourceFormat output_resource_format = |
| 443 resource_provider_->YuvResourceFormat(bits_per_channel); |
466 | 444 |
467 // If GPU compositing is enabled, but the output resource format | 445 // If GPU compositing is enabled, but the output resource format |
468 // returned by the resource provider is RGBA_8888, then a GPU driver | 446 // returned by the resource provider is RGBA_8888, then a GPU driver |
469 // bug workaround requires that YUV frames must be converted to RGB | 447 // bug workaround requires that YUV frames must be converted to RGB |
470 // before texture upload. | 448 // before texture upload. |
471 bool texture_needs_rgb_conversion = | 449 bool texture_needs_rgb_conversion = |
472 !software_compositor && disable_one_component_textures; | 450 !software_compositor && |
| 451 output_resource_format == ResourceFormat::RGBA_8888; |
473 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); | 452 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); |
474 | 453 |
475 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB | 454 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB |
476 // conversion here. That involves an extra copy of each frame to a bitmap. | 455 // conversion here. That involves an extra copy of each frame to a bitmap. |
477 // Obviously, this is suboptimal and should be addressed once ubercompositor | 456 // Obviously, this is suboptimal and should be addressed once ubercompositor |
478 // starts shaping up. | 457 // starts shaping up. |
479 if (software_compositor || texture_needs_rgb_conversion) { | 458 if (software_compositor || texture_needs_rgb_conversion) { |
480 output_resource_format = kRGBResourceFormat; | 459 output_resource_format = kRGBResourceFormat; |
481 output_plane_count = 1; | 460 output_plane_count = 1; |
482 bits_per_channel = 8; | 461 bits_per_channel = 8; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 // by software. | 517 // by software. |
539 video_renderer_->Copy(video_frame, &canvas, media::Context3D()); | 518 video_renderer_->Copy(video_frame, &canvas, media::Context3D()); |
540 } else { | 519 } else { |
541 size_t bytes_per_row = ResourceUtil::CheckedWidthInBytes<size_t>( | 520 size_t bytes_per_row = ResourceUtil::CheckedWidthInBytes<size_t>( |
542 video_frame->coded_size().width(), ResourceFormat::RGBA_8888); | 521 video_frame->coded_size().width(), ResourceFormat::RGBA_8888); |
543 size_t needed_size = bytes_per_row * video_frame->coded_size().height(); | 522 size_t needed_size = bytes_per_row * video_frame->coded_size().height(); |
544 if (upload_pixels_.size() < needed_size) | 523 if (upload_pixels_.size() < needed_size) |
545 upload_pixels_.resize(needed_size); | 524 upload_pixels_.resize(needed_size); |
546 | 525 |
547 media::SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels( | 526 media::SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels( |
548 video_frame.get(), | 527 video_frame.get(), &upload_pixels_[0], bytes_per_row); |
549 media::SkCanvasVideoRenderer::ConvertingSize::CODED, | |
550 &upload_pixels_[0], bytes_per_row); | |
551 | 528 |
552 resource_provider_->CopyToResource(plane_resource.resource_id(), | 529 resource_provider_->CopyToResource(plane_resource.resource_id(), |
553 &upload_pixels_[0], | 530 &upload_pixels_[0], |
554 plane_resource.resource_size()); | 531 plane_resource.resource_size()); |
555 } | 532 } |
556 plane_resource.SetUniqueId(video_frame->unique_id(), 0); | 533 plane_resource.SetUniqueId(video_frame->unique_id(), 0); |
557 } | 534 } |
558 | 535 |
559 if (software_compositor) { | 536 if (software_compositor) { |
560 external_resources.software_resources.push_back( | 537 external_resources.software_resources.push_back( |
561 plane_resource.resource_id()); | 538 plane_resource.resource_id()); |
562 external_resources.software_release_callback = base::Bind( | 539 external_resources.software_release_callback = base::Bind( |
563 &RecycleResource, AsWeakPtr(), plane_resource.resource_id()); | 540 &RecycleResource, AsWeakPtr(), plane_resource.resource_id()); |
564 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; | 541 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; |
565 } else { | 542 } else { |
566 // VideoResourceUpdater shares a context with the compositor so | 543 // VideoResourceUpdater shares a context with the compositor so |
567 // a sync token is not required. | 544 // a sync token is not required. |
568 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), | 545 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), |
569 resource_provider_->GetResourceTextureTarget( | 546 resource_provider_->GetResourceTextureTarget( |
570 plane_resource.resource_id()), | 547 plane_resource.resource_id())); |
571 plane_resource.resource_size(), false, false); | |
572 mailbox.set_color_space(video_frame->ColorSpace()); | 548 mailbox.set_color_space(video_frame->ColorSpace()); |
573 external_resources.mailboxes.push_back(mailbox); | 549 external_resources.mailboxes.push_back(mailbox); |
574 external_resources.release_callbacks.push_back(base::Bind( | 550 external_resources.release_callbacks.push_back(base::Bind( |
575 &RecycleResource, AsWeakPtr(), plane_resource.resource_id())); | 551 &RecycleResource, AsWeakPtr(), plane_resource.resource_id())); |
576 external_resources.type = VideoFrameExternalResources::RGBA_RESOURCE; | 552 external_resources.type = VideoFrameExternalResources::RGBA_RESOURCE; |
577 } | 553 } |
578 return external_resources; | 554 return external_resources; |
579 } | 555 } |
580 | 556 |
581 std::unique_ptr<HalfFloatMaker> half_float_maker; | 557 std::unique_ptr<HalfFloatMaker> half_float_maker; |
582 if (YuvResourceFormat(bits_per_channel) == LUMINANCE_F16) { | 558 if (resource_provider_->YuvResourceFormat(bits_per_channel) == |
| 559 LUMINANCE_F16) { |
583 half_float_maker = NewHalfFloatMaker(bits_per_channel); | 560 half_float_maker = NewHalfFloatMaker(bits_per_channel); |
584 external_resources.offset = half_float_maker->Offset(); | 561 external_resources.offset = half_float_maker->Offset(); |
585 external_resources.multiplier = half_float_maker->Multiplier(); | 562 external_resources.multiplier = half_float_maker->Multiplier(); |
586 } | 563 } |
587 | 564 |
588 for (size_t i = 0; i < plane_resources.size(); ++i) { | 565 for (size_t i = 0; i < plane_resources.size(); ++i) { |
589 PlaneResource& plane_resource = *plane_resources[i]; | 566 PlaneResource& plane_resource = *plane_resources[i]; |
590 // Update each plane's resource id with its content. | 567 // Update each plane's resource id with its content. |
591 DCHECK_EQ(plane_resource.resource_format(), | 568 DCHECK_EQ(plane_resource.resource_format(), |
592 YuvResourceFormat(bits_per_channel)); | 569 resource_provider_->YuvResourceFormat(bits_per_channel)); |
593 | 570 |
594 if (!plane_resource.Matches(video_frame->unique_id(), i)) { | 571 if (!plane_resource.Matches(video_frame->unique_id(), i)) { |
595 // TODO(hubbe): Move all conversion (and upload?) code to media/. | 572 // TODO(hubbe): Move all conversion (and upload?) code to media/. |
596 // We need to transfer data from |video_frame| to the plane resource. | 573 // We need to transfer data from |video_frame| to the plane resource. |
597 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. | 574 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. |
598 | 575 |
599 // The |resource_size_pixels| is the size of the resource we want to | 576 // The |resource_size_pixels| is the size of the resource we want to |
600 // upload to. | 577 // upload to. |
601 gfx::Size resource_size_pixels = plane_resource.resource_size(); | 578 gfx::Size resource_size_pixels = plane_resource.resource_size(); |
602 // The |video_stride_bytes| is the width of the video frame we are | 579 // The |video_stride_bytes| is the width of the video frame we are |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 if (lost_resource) { | 801 if (lost_resource) { |
825 resource_it->clear_refs(); | 802 resource_it->clear_refs(); |
826 updater->DeleteResource(resource_it); | 803 updater->DeleteResource(resource_it); |
827 return; | 804 return; |
828 } | 805 } |
829 | 806 |
830 resource_it->remove_ref(); | 807 resource_it->remove_ref(); |
831 } | 808 } |
832 | 809 |
833 } // namespace cc | 810 } // namespace cc |
OLD | NEW |