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