Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "media/renderers/skcanvas_video_renderer.h" | 5 #include "media/renderers/skcanvas_video_renderer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 } | 218 } |
| 219 ~VideoImageGenerator() override {} | 219 ~VideoImageGenerator() override {} |
| 220 | 220 |
| 221 protected: | 221 protected: |
| 222 bool onGetPixels(const SkImageInfo& info, | 222 bool onGetPixels(const SkImageInfo& info, |
| 223 void* pixels, | 223 void* pixels, |
| 224 size_t row_bytes, | 224 size_t row_bytes, |
| 225 SkPMColor ctable[], | 225 SkPMColor ctable[], |
| 226 int* ctable_count) override { | 226 int* ctable_count) override { |
| 227 // If skia couldn't do the YUV conversion on GPU, we will on CPU. | 227 // If skia couldn't do the YUV conversion on GPU, we will on CPU. |
| 228 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels(frame_.get(), pixels, | 228 SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels( |
| 229 row_bytes); | 229 frame_.get(), SkCanvasVideoRenderer::ConvertingSize::VISUAL, pixels, |
| 230 row_bytes); | |
| 230 return true; | 231 return true; |
| 231 } | 232 } |
| 232 | 233 |
| 233 bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, | 234 bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, |
| 234 SkYUVColorSpace* color_space) const override { | 235 SkYUVColorSpace* color_space) const override { |
| 235 if (!media::IsYuvPlanar(frame_->format()) || | 236 if (!media::IsYuvPlanar(frame_->format()) || |
| 236 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove | 237 // TODO(rileya): Skia currently doesn't support YUVA conversion. Remove |
| 237 // this case once it does. As-is we will fall back on the pure-software | 238 // this case once it does. As-is we will fall back on the pure-software |
| 238 // path in this case. | 239 // path in this case. |
| 239 frame_->format() == PIXEL_FORMAT_YV12A) { | 240 frame_->format() == PIXEL_FORMAT_YV12A) { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 for (int row = 0; row < video_frame->rows(plane); row++) { | 514 for (int row = 0; row < video_frame->rows(plane); row++) { |
| 514 for (int x = 0; x < width; x++) { | 515 for (int x = 0; x < width; x++) { |
| 515 dst[x] = src[x] >> shift; | 516 dst[x] = src[x] >> shift; |
| 516 } | 517 } |
| 517 src += video_frame->stride(plane) / 2; | 518 src += video_frame->stride(plane) / 2; |
| 518 dst += ret->stride(plane); | 519 dst += ret->stride(plane); |
| 519 } | 520 } |
| 520 } | 521 } |
| 521 return ret; | 522 return ret; |
| 522 } | 523 } |
| 524 | |
| 525 const uint8_t* FrameData(const VideoFrame* video_frame, | |
| 526 SkCanvasVideoRenderer::ConvertingSize size_type, | |
| 527 size_t plane) { | |
| 528 if (size_type == SkCanvasVideoRenderer::ConvertingSize::VISUAL) { | |
|
DaleCurtis
2016/10/25 23:53:37
Drop {} from single life if.
dshwang
2016/10/26 15:26:28
Done.
| |
| 529 return video_frame->visible_data(plane); | |
| 530 } | |
| 531 DCHECK(size_type == SkCanvasVideoRenderer::ConvertingSize::CODED); | |
|
DaleCurtis
2016/10/25 23:53:37
DCHECK_EQ?
dshwang
2016/10/26 15:26:28
DCHECK_EQ doesn't support enum class, unfortunatel
| |
| 532 return video_frame->data(plane); | |
| 523 } | 533 } |
| 524 | 534 |
| 535 } // namespace | |
| 536 | |
| 525 // static | 537 // static |
| 526 void SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels( | 538 void SkCanvasVideoRenderer::ConvertVideoFrameToRGBPixels( |
| 527 const VideoFrame* video_frame, | 539 const VideoFrame* video_frame, |
| 540 ConvertingSize size_type, | |
| 528 void* rgb_pixels, | 541 void* rgb_pixels, |
| 529 size_t row_bytes) { | 542 size_t row_bytes) { |
| 530 if (!video_frame->IsMappable()) { | 543 if (!video_frame->IsMappable()) { |
| 531 NOTREACHED() << "Cannot extract pixels from non-CPU frame formats."; | 544 NOTREACHED() << "Cannot extract pixels from non-CPU frame formats."; |
| 532 return; | 545 return; |
| 533 } | 546 } |
| 534 if (!media::IsYuvPlanar(video_frame->format())) { | 547 if (!media::IsYuvPlanar(video_frame->format())) { |
| 535 NOTREACHED() << "Non YUV formats are not supported"; | 548 NOTREACHED() << "Non YUV formats are not supported"; |
| 536 return; | 549 return; |
| 537 } | 550 } |
| 538 | 551 |
| 552 gfx::Size frame_size = video_frame->coded_size(); | |
| 553 if (size_type == SkCanvasVideoRenderer::ConvertingSize::VISUAL) | |
| 554 frame_size = video_frame->visible_rect().size(); | |
| 555 | |
| 539 switch (video_frame->format()) { | 556 switch (video_frame->format()) { |
| 540 case PIXEL_FORMAT_YV12: | 557 case PIXEL_FORMAT_YV12: |
| 541 case PIXEL_FORMAT_I420: | 558 case PIXEL_FORMAT_I420: |
| 542 if (CheckColorSpace(video_frame, COLOR_SPACE_JPEG)) { | 559 if (CheckColorSpace(video_frame, COLOR_SPACE_JPEG)) { |
| 543 LIBYUV_J420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 560 LIBYUV_J420_TO_ARGB( |
| 544 video_frame->stride(VideoFrame::kYPlane), | 561 FrameData(video_frame, size_type, VideoFrame::kYPlane), |
| 545 video_frame->visible_data(VideoFrame::kUPlane), | 562 video_frame->stride(VideoFrame::kYPlane), |
| 546 video_frame->stride(VideoFrame::kUPlane), | 563 FrameData(video_frame, size_type, VideoFrame::kUPlane), |
| 547 video_frame->visible_data(VideoFrame::kVPlane), | 564 video_frame->stride(VideoFrame::kUPlane), |
| 548 video_frame->stride(VideoFrame::kVPlane), | 565 FrameData(video_frame, size_type, VideoFrame::kVPlane), |
| 549 static_cast<uint8_t*>(rgb_pixels), row_bytes, | 566 video_frame->stride(VideoFrame::kVPlane), |
| 550 video_frame->visible_rect().width(), | 567 static_cast<uint8_t*>(rgb_pixels), row_bytes, frame_size.width(), |
| 551 video_frame->visible_rect().height()); | 568 frame_size.height()); |
| 552 } else if (CheckColorSpace(video_frame, COLOR_SPACE_HD_REC709)) { | 569 } else if (CheckColorSpace(video_frame, COLOR_SPACE_HD_REC709)) { |
| 553 LIBYUV_H420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 570 LIBYUV_H420_TO_ARGB( |
| 554 video_frame->stride(VideoFrame::kYPlane), | 571 FrameData(video_frame, size_type, VideoFrame::kYPlane), |
| 555 video_frame->visible_data(VideoFrame::kUPlane), | 572 video_frame->stride(VideoFrame::kYPlane), |
| 556 video_frame->stride(VideoFrame::kUPlane), | 573 FrameData(video_frame, size_type, VideoFrame::kUPlane), |
| 557 video_frame->visible_data(VideoFrame::kVPlane), | 574 video_frame->stride(VideoFrame::kUPlane), |
| 558 video_frame->stride(VideoFrame::kVPlane), | 575 FrameData(video_frame, size_type, VideoFrame::kVPlane), |
| 559 static_cast<uint8_t*>(rgb_pixels), row_bytes, | 576 video_frame->stride(VideoFrame::kVPlane), |
| 560 video_frame->visible_rect().width(), | 577 static_cast<uint8_t*>(rgb_pixels), row_bytes, frame_size.width(), |
| 561 video_frame->visible_rect().height()); | 578 frame_size.height()); |
| 562 } else { | 579 } else { |
| 563 LIBYUV_I420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 580 LIBYUV_I420_TO_ARGB( |
| 564 video_frame->stride(VideoFrame::kYPlane), | 581 FrameData(video_frame, size_type, VideoFrame::kYPlane), |
| 565 video_frame->visible_data(VideoFrame::kUPlane), | 582 video_frame->stride(VideoFrame::kYPlane), |
| 566 video_frame->stride(VideoFrame::kUPlane), | 583 FrameData(video_frame, size_type, VideoFrame::kUPlane), |
| 567 video_frame->visible_data(VideoFrame::kVPlane), | 584 video_frame->stride(VideoFrame::kUPlane), |
| 568 video_frame->stride(VideoFrame::kVPlane), | 585 FrameData(video_frame, size_type, VideoFrame::kVPlane), |
| 569 static_cast<uint8_t*>(rgb_pixels), row_bytes, | 586 video_frame->stride(VideoFrame::kVPlane), |
| 570 video_frame->visible_rect().width(), | 587 static_cast<uint8_t*>(rgb_pixels), row_bytes, frame_size.width(), |
| 571 video_frame->visible_rect().height()); | 588 frame_size.height()); |
| 572 } | 589 } |
| 573 break; | 590 break; |
| 574 case PIXEL_FORMAT_YV16: | 591 case PIXEL_FORMAT_YV16: |
| 575 LIBYUV_I422_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 592 LIBYUV_I422_TO_ARGB( |
| 576 video_frame->stride(VideoFrame::kYPlane), | 593 FrameData(video_frame, size_type, VideoFrame::kYPlane), |
| 577 video_frame->visible_data(VideoFrame::kUPlane), | 594 video_frame->stride(VideoFrame::kYPlane), |
| 578 video_frame->stride(VideoFrame::kUPlane), | 595 FrameData(video_frame, size_type, VideoFrame::kUPlane), |
| 579 video_frame->visible_data(VideoFrame::kVPlane), | 596 video_frame->stride(VideoFrame::kUPlane), |
| 580 video_frame->stride(VideoFrame::kVPlane), | 597 FrameData(video_frame, size_type, VideoFrame::kVPlane), |
| 581 static_cast<uint8_t*>(rgb_pixels), row_bytes, | 598 video_frame->stride(VideoFrame::kVPlane), |
| 582 video_frame->visible_rect().width(), | 599 static_cast<uint8_t*>(rgb_pixels), row_bytes, frame_size.width(), |
| 583 video_frame->visible_rect().height()); | 600 frame_size.height()); |
| 584 break; | 601 break; |
| 585 | 602 |
| 586 case PIXEL_FORMAT_YV12A: | 603 case PIXEL_FORMAT_YV12A: |
| 587 LIBYUV_I420ALPHA_TO_ARGB( | 604 LIBYUV_I420ALPHA_TO_ARGB( |
| 588 video_frame->visible_data(VideoFrame::kYPlane), | 605 FrameData(video_frame, size_type, VideoFrame::kYPlane), |
| 589 video_frame->stride(VideoFrame::kYPlane), | 606 video_frame->stride(VideoFrame::kYPlane), |
| 590 video_frame->visible_data(VideoFrame::kUPlane), | 607 FrameData(video_frame, size_type, VideoFrame::kUPlane), |
| 591 video_frame->stride(VideoFrame::kUPlane), | 608 video_frame->stride(VideoFrame::kUPlane), |
| 592 video_frame->visible_data(VideoFrame::kVPlane), | 609 FrameData(video_frame, size_type, VideoFrame::kVPlane), |
| 593 video_frame->stride(VideoFrame::kVPlane), | 610 video_frame->stride(VideoFrame::kVPlane), |
| 594 video_frame->visible_data(VideoFrame::kAPlane), | 611 FrameData(video_frame, size_type, VideoFrame::kAPlane), |
| 595 video_frame->stride(VideoFrame::kAPlane), | 612 video_frame->stride(VideoFrame::kAPlane), |
| 596 static_cast<uint8_t*>(rgb_pixels), row_bytes, | 613 static_cast<uint8_t*>(rgb_pixels), row_bytes, frame_size.width(), |
| 597 video_frame->visible_rect().width(), | 614 frame_size.height(), |
| 598 video_frame->visible_rect().height(), | |
| 599 1); // 1 = enable RGB premultiplication by Alpha. | 615 1); // 1 = enable RGB premultiplication by Alpha. |
| 600 break; | 616 break; |
| 601 | 617 |
| 602 case PIXEL_FORMAT_YV24: | 618 case PIXEL_FORMAT_YV24: |
| 603 LIBYUV_I444_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 619 LIBYUV_I444_TO_ARGB( |
| 604 video_frame->stride(VideoFrame::kYPlane), | 620 FrameData(video_frame, size_type, VideoFrame::kYPlane), |
| 605 video_frame->visible_data(VideoFrame::kUPlane), | 621 video_frame->stride(VideoFrame::kYPlane), |
| 606 video_frame->stride(VideoFrame::kUPlane), | 622 FrameData(video_frame, size_type, VideoFrame::kUPlane), |
| 607 video_frame->visible_data(VideoFrame::kVPlane), | 623 video_frame->stride(VideoFrame::kUPlane), |
| 608 video_frame->stride(VideoFrame::kVPlane), | 624 FrameData(video_frame, size_type, VideoFrame::kVPlane), |
| 609 static_cast<uint8_t*>(rgb_pixels), row_bytes, | 625 video_frame->stride(VideoFrame::kVPlane), |
| 610 video_frame->visible_rect().width(), | 626 static_cast<uint8_t*>(rgb_pixels), row_bytes, frame_size.width(), |
| 611 video_frame->visible_rect().height()); | 627 frame_size.height()); |
| 612 break; | 628 break; |
| 613 | 629 |
| 614 case PIXEL_FORMAT_YUV420P9: | 630 case PIXEL_FORMAT_YUV420P9: |
| 615 case PIXEL_FORMAT_YUV422P9: | 631 case PIXEL_FORMAT_YUV422P9: |
| 616 case PIXEL_FORMAT_YUV444P9: | 632 case PIXEL_FORMAT_YUV444P9: |
| 617 case PIXEL_FORMAT_YUV420P10: | 633 case PIXEL_FORMAT_YUV420P10: |
| 618 case PIXEL_FORMAT_YUV422P10: | 634 case PIXEL_FORMAT_YUV422P10: |
| 619 case PIXEL_FORMAT_YUV444P10: | 635 case PIXEL_FORMAT_YUV444P10: |
| 620 case PIXEL_FORMAT_YUV420P12: | 636 case PIXEL_FORMAT_YUV420P12: |
| 621 case PIXEL_FORMAT_YUV422P12: | 637 case PIXEL_FORMAT_YUV422P12: |
| 622 case PIXEL_FORMAT_YUV444P12: { | 638 case PIXEL_FORMAT_YUV444P12: { |
| 623 scoped_refptr<VideoFrame> temporary_frame = | 639 scoped_refptr<VideoFrame> temporary_frame = |
| 624 DownShiftHighbitVideoFrame(video_frame); | 640 DownShiftHighbitVideoFrame(video_frame); |
| 625 ConvertVideoFrameToRGBPixels(temporary_frame.get(), rgb_pixels, | 641 ConvertVideoFrameToRGBPixels(temporary_frame.get(), size_type, rgb_pixels, |
| 626 row_bytes); | 642 row_bytes); |
| 627 break; | 643 break; |
| 628 } | 644 } |
| 629 | 645 |
| 630 case PIXEL_FORMAT_NV12: | 646 case PIXEL_FORMAT_NV12: |
| 631 case PIXEL_FORMAT_NV21: | 647 case PIXEL_FORMAT_NV21: |
| 632 case PIXEL_FORMAT_UYVY: | 648 case PIXEL_FORMAT_UYVY: |
| 633 case PIXEL_FORMAT_YUY2: | 649 case PIXEL_FORMAT_YUY2: |
| 634 case PIXEL_FORMAT_ARGB: | 650 case PIXEL_FORMAT_ARGB: |
| 635 case PIXEL_FORMAT_XRGB: | 651 case PIXEL_FORMAT_XRGB: |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 last_image_->bounds().contains(visible_rect)) { | 819 last_image_->bounds().contains(visible_rect)) { |
| 804 last_image_ = last_image_->makeSubset(visible_rect); | 820 last_image_ = last_image_->makeSubset(visible_rect); |
| 805 } | 821 } |
| 806 } | 822 } |
| 807 | 823 |
| 808 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { | 824 SkISize SkCanvasVideoRenderer::LastImageDimensionsForTesting() { |
| 809 return last_image_dimensions_for_testing_; | 825 return last_image_dimensions_for_testing_; |
| 810 } | 826 } |
| 811 | 827 |
| 812 } // namespace media | 828 } // namespace media |
| OLD | NEW |