| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bit_cast.h" | 13 #include "base/bit_cast.h" |
| 14 #include "base/feature_list.h" |
| 14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 15 #include "cc/base/math_util.h" | 16 #include "cc/base/math_util.h" |
| 16 #include "cc/output/gl_renderer.h" | 17 #include "cc/output/gl_renderer.h" |
| 17 #include "cc/paint/skia_paint_canvas.h" | 18 #include "cc/paint/skia_paint_canvas.h" |
| 18 #include "cc/resources/resource_provider.h" | 19 #include "cc/resources/resource_provider.h" |
| 19 #include "cc/resources/resource_util.h" | 20 #include "cc/resources/resource_util.h" |
| 20 #include "gpu/GLES2/gl2extchromium.h" | 21 #include "gpu/GLES2/gl2extchromium.h" |
| 21 #include "gpu/command_buffer/client/gles2_interface.h" | 22 #include "gpu/command_buffer/client/gles2_interface.h" |
| 23 #include "media/base/media_switches.h" |
| 22 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
| 23 #include "media/renderers/skcanvas_video_renderer.h" | 25 #include "media/renderers/skcanvas_video_renderer.h" |
| 24 #include "third_party/khronos/GLES2/gl2.h" | 26 #include "third_party/khronos/GLES2/gl2.h" |
| 25 #include "third_party/khronos/GLES2/gl2ext.h" | 27 #include "third_party/khronos/GLES2/gl2ext.h" |
| 26 #include "third_party/libyuv/include/libyuv.h" | 28 #include "third_party/libyuv/include/libyuv.h" |
| 27 #include "third_party/skia/include/core/SkCanvas.h" | 29 #include "third_party/skia/include/core/SkCanvas.h" |
| 28 #include "ui/gfx/geometry/size_conversions.h" | 30 #include "ui/gfx/geometry/size_conversions.h" |
| 29 | 31 |
| 30 namespace cc { | 32 namespace cc { |
| 31 | 33 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 VideoResourceUpdater::NewHalfFloatMaker(int bits_per_channel) { | 376 VideoResourceUpdater::NewHalfFloatMaker(int bits_per_channel) { |
| 375 if (bits_per_channel < 11) { | 377 if (bits_per_channel < 11) { |
| 376 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( | 378 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( |
| 377 new HalfFloatMaker_xor(bits_per_channel)); | 379 new HalfFloatMaker_xor(bits_per_channel)); |
| 378 } else { | 380 } else { |
| 379 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( | 381 return std::unique_ptr<VideoResourceUpdater::HalfFloatMaker>( |
| 380 new HalfFloatMaker_libyuv(bits_per_channel)); | 382 new HalfFloatMaker_libyuv(bits_per_channel)); |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 386 gfx::ColorSpace VideoResourceUpdater::GetColorSpace( |
| 387 media::VideoFrame* video_frame) { |
| 388 int videoframe_color_space; |
| 389 if (video_frame->metadata()->GetInteger( |
| 390 media::VideoFrameMetadata::COLOR_SPACE, &videoframe_color_space)) { |
| 391 if (videoframe_color_space == media::COLOR_SPACE_JPEG) { |
| 392 return gfx::ColorSpace::CreateJpeg(); |
| 393 } else if (videoframe_color_space == media::COLOR_SPACE_HD_REC709) { |
| 394 return gfx::ColorSpace::CreateREC709(); |
| 395 } |
| 396 } |
| 397 return gfx::ColorSpace::CreateREC601(); |
| 398 } |
| 399 |
| 384 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( | 400 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( |
| 385 scoped_refptr<media::VideoFrame> video_frame) { | 401 scoped_refptr<media::VideoFrame> video_frame) { |
| 386 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); | 402 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); |
| 387 const media::VideoPixelFormat input_frame_format = video_frame->format(); | 403 const media::VideoPixelFormat input_frame_format = video_frame->format(); |
| 388 | 404 |
| 389 int bits_per_channel = video_frame->BitsPerChannel(input_frame_format); | 405 int bits_per_channel = video_frame->BitsPerChannel(input_frame_format); |
| 390 | 406 |
| 391 // Only YUV and Y16 software video frames are supported. | 407 // Only YUV and Y16 software video frames are supported. |
| 392 DCHECK(media::IsYuvPlanar(input_frame_format) || | 408 DCHECK(media::IsYuvPlanar(input_frame_format) || |
| 393 input_frame_format == media::PIXEL_FORMAT_Y16); | 409 input_frame_format == media::PIXEL_FORMAT_Y16); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 } | 535 } |
| 520 | 536 |
| 521 std::unique_ptr<HalfFloatMaker> half_float_maker; | 537 std::unique_ptr<HalfFloatMaker> half_float_maker; |
| 522 if (resource_provider_->YuvResourceFormat(bits_per_channel) == | 538 if (resource_provider_->YuvResourceFormat(bits_per_channel) == |
| 523 LUMINANCE_F16) { | 539 LUMINANCE_F16) { |
| 524 half_float_maker = NewHalfFloatMaker(bits_per_channel); | 540 half_float_maker = NewHalfFloatMaker(bits_per_channel); |
| 525 external_resources.offset = half_float_maker->Offset(); | 541 external_resources.offset = half_float_maker->Offset(); |
| 526 external_resources.multiplier = half_float_maker->Multiplier(); | 542 external_resources.multiplier = half_float_maker->Multiplier(); |
| 527 } | 543 } |
| 528 | 544 |
| 545 if (!base::FeatureList::IsEnabled(media::kVideoColorManagement)) |
| 546 output_color_space = GetColorSpace(video_frame.get()); |
| 547 |
| 529 for (size_t i = 0; i < plane_resources.size(); ++i) { | 548 for (size_t i = 0; i < plane_resources.size(); ++i) { |
| 530 PlaneResource& plane_resource = *plane_resources[i]; | 549 PlaneResource& plane_resource = *plane_resources[i]; |
| 531 // Update each plane's resource id with its content. | 550 // Update each plane's resource id with its content. |
| 532 DCHECK_EQ(plane_resource.resource_format(), | 551 DCHECK_EQ(plane_resource.resource_format(), |
| 533 resource_provider_->YuvResourceFormat(bits_per_channel)); | 552 resource_provider_->YuvResourceFormat(bits_per_channel)); |
| 534 | 553 |
| 535 if (!plane_resource.Matches(video_frame->unique_id(), i)) { | 554 if (!plane_resource.Matches(video_frame->unique_id(), i)) { |
| 536 // TODO(hubbe): Move all conversion (and upload?) code to media/. | 555 // TODO(hubbe): Move all conversion (and upload?) code to media/. |
| 537 // We need to transfer data from |video_frame| to the plane resource. | 556 // We need to transfer data from |video_frame| to the plane resource. |
| 538 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. | 557 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 external_resources.read_lock_fences_enabled = true; | 725 external_resources.read_lock_fences_enabled = true; |
| 707 } | 726 } |
| 708 gfx::ColorSpace resource_color_space = video_frame->ColorSpace(); | 727 gfx::ColorSpace resource_color_space = video_frame->ColorSpace(); |
| 709 | 728 |
| 710 external_resources.type = ResourceTypeForVideoFrame(video_frame.get()); | 729 external_resources.type = ResourceTypeForVideoFrame(video_frame.get()); |
| 711 if (external_resources.type == VideoFrameExternalResources::NONE) { | 730 if (external_resources.type == VideoFrameExternalResources::NONE) { |
| 712 DLOG(ERROR) << "Unsupported Texture format" | 731 DLOG(ERROR) << "Unsupported Texture format" |
| 713 << media::VideoPixelFormatToString(video_frame->format()); | 732 << media::VideoPixelFormatToString(video_frame->format()); |
| 714 return external_resources; | 733 return external_resources; |
| 715 } | 734 } |
| 716 if (external_resources.type == VideoFrameExternalResources::YUV_RESOURCE) | 735 if (external_resources.type == VideoFrameExternalResources::YUV_RESOURCE) { |
| 717 resource_color_space = resource_color_space.GetAsFullRangeRGB(); | 736 resource_color_space = resource_color_space.GetAsFullRangeRGB(); |
| 737 if (!base::FeatureList::IsEnabled(media::kVideoColorManagement)) |
| 738 resource_color_space = GetColorSpace(video_frame.get()); |
| 739 } |
| 718 | 740 |
| 719 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format()); | 741 const size_t num_planes = media::VideoFrame::NumPlanes(video_frame->format()); |
| 720 for (size_t i = 0; i < num_planes; ++i) { | 742 for (size_t i = 0; i < num_planes; ++i) { |
| 721 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); | 743 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); |
| 722 if (mailbox_holder.mailbox.IsZero()) | 744 if (mailbox_holder.mailbox.IsZero()) |
| 723 break; | 745 break; |
| 724 | 746 |
| 725 if (video_frame->metadata()->IsTrue( | 747 if (video_frame->metadata()->IsTrue( |
| 726 media::VideoFrameMetadata::COPY_REQUIRED)) { | 748 media::VideoFrameMetadata::COPY_REQUIRED)) { |
| 727 CopyPlaneTexture(video_frame.get(), resource_color_space, mailbox_holder, | 749 CopyPlaneTexture(video_frame.get(), resource_color_space, mailbox_holder, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 if (lost_resource) { | 798 if (lost_resource) { |
| 777 resource_it->clear_refs(); | 799 resource_it->clear_refs(); |
| 778 updater->DeleteResource(resource_it); | 800 updater->DeleteResource(resource_it); |
| 779 return; | 801 return; |
| 780 } | 802 } |
| 781 | 803 |
| 782 resource_it->remove_ref(); | 804 resource_it->remove_ref(); |
| 783 } | 805 } |
| 784 | 806 |
| 785 } // namespace cc | 807 } // namespace cc |
| OLD | NEW |