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

Side by Side Diff: cc/resources/video_resource_updater.cc

Issue 2544893006: Revert of Reland "Fix HTML5 video blurry" (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | cc/test/data/yuv_stripes.png » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(
383 int bits,
384 media::VideoPixelFormat format) const {
385 if (!context_provider_)
386 return RGBA_8888;
387
388 if (format == media::PIXEL_FORMAT_Y16) {
389 // Unable to display directly as yuv planes so convert it to RGBA for
390 // compositing.
391 return RGBA_8888;
392 }
393
394 const auto caps = context_provider_->ContextCapabilities();
395 if (caps.disable_one_component_textures)
396 return RGBA_8888;
397
398 ResourceFormat yuv_resource_format = caps.texture_rg ? RED_8 : LUMINANCE_8;
399 if (bits <= 8)
400 return yuv_resource_format;
401
402 if (caps.texture_half_float_linear)
403 return LUMINANCE_F16;
404
405 return yuv_resource_format;
406 }
407
408 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( 382 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
409 scoped_refptr<media::VideoFrame> video_frame) { 383 scoped_refptr<media::VideoFrame> video_frame) {
410 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes"); 384 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForSoftwarePlanes");
411 const media::VideoPixelFormat input_frame_format = video_frame->format(); 385 const media::VideoPixelFormat input_frame_format = video_frame->format();
412 386
413 // TODO(hubbe): Make this a video frame method. 387 // TODO(hubbe): Make this a video frame method.
414 int bits_per_channel = 0; 388 int bits_per_channel = 0;
415 switch (input_frame_format) { 389 switch (input_frame_format) {
416 case media::PIXEL_FORMAT_UNKNOWN: 390 case media::PIXEL_FORMAT_UNKNOWN:
417 NOTREACHED(); 391 NOTREACHED();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 break; 425 break;
452 case media::PIXEL_FORMAT_Y16: 426 case media::PIXEL_FORMAT_Y16:
453 bits_per_channel = 16; 427 bits_per_channel = 16;
454 break; 428 break;
455 } 429 }
456 430
457 // Only YUV and Y16 software video frames are supported. 431 // Only YUV and Y16 software video frames are supported.
458 DCHECK(media::IsYuvPlanar(input_frame_format) || 432 DCHECK(media::IsYuvPlanar(input_frame_format) ||
459 input_frame_format == media::PIXEL_FORMAT_Y16); 433 input_frame_format == media::PIXEL_FORMAT_Y16);
460 434
461 const bool software_compositor = context_provider_ == nullptr; 435 const bool software_compositor = context_provider_ == NULL;
462 bool disable_one_component_textures = true; 436
463 if (!software_compositor) { 437 ResourceFormat output_resource_format;
464 const auto caps = context_provider_->ContextCapabilities(); 438 if (input_frame_format == media::PIXEL_FORMAT_Y16) {
465 disable_one_component_textures = caps.disable_one_component_textures; 439 // Unable to display directly as yuv planes so convert it to RGBA for
440 // compositing.
441 output_resource_format = RGBA_8888;
442 } else {
443 // Can be composited directly from yuv planes.
444 output_resource_format =
445 resource_provider_->YuvResourceFormat(bits_per_channel);
466 } 446 }
467 447
468 ResourceFormat output_resource_format =
469 YuvResourceFormat(bits_per_channel, input_frame_format);
470
471 // If GPU compositing is enabled, but the output resource format 448 // If GPU compositing is enabled, but the output resource format
472 // returned by the resource provider is RGBA_8888, then a GPU driver 449 // returned by the resource provider is RGBA_8888, then a GPU driver
473 // bug workaround requires that YUV frames must be converted to RGB 450 // bug workaround requires that YUV frames must be converted to RGB
474 // before texture upload. 451 // before texture upload.
475 bool texture_needs_rgb_conversion = 452 bool texture_needs_rgb_conversion =
476 (!software_compositor && disable_one_component_textures) || 453 !software_compositor &&
477 input_frame_format == media::PIXEL_FORMAT_Y16; 454 output_resource_format == ResourceFormat::RGBA_8888;
478 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format); 455 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format);
479 456
480 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB 457 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB
481 // conversion here. That involves an extra copy of each frame to a bitmap. 458 // conversion here. That involves an extra copy of each frame to a bitmap.
482 // Obviously, this is suboptimal and should be addressed once ubercompositor 459 // Obviously, this is suboptimal and should be addressed once ubercompositor
483 // starts shaping up. 460 // starts shaping up.
484 if (software_compositor || texture_needs_rgb_conversion) { 461 if (software_compositor || texture_needs_rgb_conversion) {
485 DCHECK_EQ(output_resource_format, kRGBResourceFormat); 462 output_resource_format = kRGBResourceFormat;
486 output_plane_count = 1; 463 output_plane_count = 1;
487 bits_per_channel = 8; 464 bits_per_channel = 8;
488 } 465 }
489 466
490 // Drop recycled resources that are the wrong format. 467 // Drop recycled resources that are the wrong format.
491 for (auto it = all_resources_.begin(); it != all_resources_.end();) { 468 for (auto it = all_resources_.begin(); it != all_resources_.end();) {
492 if (!it->has_refs() && it->resource_format() != output_resource_format) 469 if (!it->has_refs() && it->resource_format() != output_resource_format)
493 DeleteResource(it++); 470 DeleteResource(it++);
494 else 471 else
495 ++it; 472 ++it;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // by software. 520 // by software.
544 video_renderer_->Copy(video_frame, &canvas, media::Context3D()); 521 video_renderer_->Copy(video_frame, &canvas, media::Context3D());
545 } else { 522 } else {
546 size_t bytes_per_row = ResourceUtil::CheckedWidthInBytes<size_t>( 523 size_t bytes_per_row = ResourceUtil::CheckedWidthInBytes<size_t>(
547 video_frame->coded_size().width(), ResourceFormat::RGBA_8888); 524 video_frame->coded_size().width(), ResourceFormat::RGBA_8888);
548 size_t needed_size = bytes_per_row * video_frame->coded_size().height(); 525 size_t needed_size = bytes_per_row * video_frame->coded_size().height();
549 if (upload_pixels_.size() < needed_size) 526 if (upload_pixels_.size() < needed_size)
550 upload_pixels_.resize(needed_size); 527 upload_pixels_.resize(needed_size);
551 528
552 media::SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels( 529 media::SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(
553 video_frame.get(), 530 video_frame.get(), &upload_pixels_[0], bytes_per_row);
554 media::SkCanvasVideoRenderer::ConvertingSize::CODED,
555 &upload_pixels_[0], bytes_per_row);
556 531
557 resource_provider_->CopyToResource(plane_resource.resource_id(), 532 resource_provider_->CopyToResource(plane_resource.resource_id(),
558 &upload_pixels_[0], 533 &upload_pixels_[0],
559 plane_resource.resource_size()); 534 plane_resource.resource_size());
560 } 535 }
561 plane_resource.SetUniqueId(video_frame->unique_id(), 0); 536 plane_resource.SetUniqueId(video_frame->unique_id(), 0);
562 } 537 }
563 538
564 if (software_compositor) { 539 if (software_compositor) {
565 external_resources.software_resources.push_back( 540 external_resources.software_resources.push_back(
566 plane_resource.resource_id()); 541 plane_resource.resource_id());
567 external_resources.software_release_callback = base::Bind( 542 external_resources.software_release_callback = base::Bind(
568 &RecycleResource, AsWeakPtr(), plane_resource.resource_id()); 543 &RecycleResource, AsWeakPtr(), plane_resource.resource_id());
569 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; 544 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE;
570 } else { 545 } else {
571 // VideoResourceUpdater shares a context with the compositor so 546 // VideoResourceUpdater shares a context with the compositor so
572 // a sync token is not required. 547 // a sync token is not required.
573 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), 548 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(),
574 resource_provider_->GetResourceTextureTarget( 549 resource_provider_->GetResourceTextureTarget(
575 plane_resource.resource_id()), 550 plane_resource.resource_id()));
576 plane_resource.resource_size(), false, false);
577 mailbox.set_color_space(video_frame->ColorSpace()); 551 mailbox.set_color_space(video_frame->ColorSpace());
578 external_resources.mailboxes.push_back(mailbox); 552 external_resources.mailboxes.push_back(mailbox);
579 external_resources.release_callbacks.push_back(base::Bind( 553 external_resources.release_callbacks.push_back(base::Bind(
580 &RecycleResource, AsWeakPtr(), plane_resource.resource_id())); 554 &RecycleResource, AsWeakPtr(), plane_resource.resource_id()));
581 external_resources.type = VideoFrameExternalResources::RGBA_RESOURCE; 555 external_resources.type = VideoFrameExternalResources::RGBA_RESOURCE;
582 } 556 }
583 return external_resources; 557 return external_resources;
584 } 558 }
585 559
586 std::unique_ptr<HalfFloatMaker> half_float_maker; 560 std::unique_ptr<HalfFloatMaker> half_float_maker;
587 if (YuvResourceFormat(bits_per_channel, input_frame_format) == 561 if (resource_provider_->YuvResourceFormat(bits_per_channel) ==
588 LUMINANCE_F16) { 562 LUMINANCE_F16) {
589 half_float_maker = NewHalfFloatMaker(bits_per_channel); 563 half_float_maker = NewHalfFloatMaker(bits_per_channel);
590 external_resources.offset = half_float_maker->Offset(); 564 external_resources.offset = half_float_maker->Offset();
591 external_resources.multiplier = half_float_maker->Multiplier(); 565 external_resources.multiplier = half_float_maker->Multiplier();
592 } 566 }
593 567
594 for (size_t i = 0; i < plane_resources.size(); ++i) { 568 for (size_t i = 0; i < plane_resources.size(); ++i) {
595 PlaneResource& plane_resource = *plane_resources[i]; 569 PlaneResource& plane_resource = *plane_resources[i];
596 // Update each plane's resource id with its content. 570 // Update each plane's resource id with its content.
597 DCHECK_EQ(plane_resource.resource_format(), 571 DCHECK_EQ(plane_resource.resource_format(),
598 YuvResourceFormat(bits_per_channel, input_frame_format)); 572 resource_provider_->YuvResourceFormat(bits_per_channel));
599 573
600 if (!plane_resource.Matches(video_frame->unique_id(), i)) { 574 if (!plane_resource.Matches(video_frame->unique_id(), i)) {
601 // TODO(hubbe): Move all conversion (and upload?) code to media/. 575 // TODO(hubbe): Move all conversion (and upload?) code to media/.
602 // We need to transfer data from |video_frame| to the plane resource. 576 // We need to transfer data from |video_frame| to the plane resource.
603 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance. 577 // TODO(reveman): Can use GpuMemoryBuffers here to improve performance.
604 578
605 // The |resource_size_pixels| is the size of the resource we want to 579 // The |resource_size_pixels| is the size of the resource we want to
606 // upload to. 580 // upload to.
607 gfx::Size resource_size_pixels = plane_resource.resource_size(); 581 gfx::Size resource_size_pixels = plane_resource.resource_size();
608 // The |video_stride_bytes| is the width of the video frame we are 582 // 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
830 if (lost_resource) { 804 if (lost_resource) {
831 resource_it->clear_refs(); 805 resource_it->clear_refs();
832 updater->DeleteResource(resource_it); 806 updater->DeleteResource(resource_it);
833 return; 807 return;
834 } 808 }
835 809
836 resource_it->remove_ref(); 810 resource_it->remove_ref();
837 } 811 }
838 812
839 } // namespace cc 813 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/video_resource_updater.h ('k') | cc/test/data/yuv_stripes.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698