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/blink/skcanvas_video_renderer.h" | 5 #include "media/blink/skcanvas_video_renderer.h" |
| 6 | 6 |
| 7 #include "gpu/GLES2/gl2extchromium.h" | 7 #include "gpu/GLES2/gl2extchromium.h" |
| 8 #include "gpu/command_buffer/client/gles2_interface.h" | 8 #include "gpu/command_buffer/client/gles2_interface.h" |
| 9 #include "gpu/command_buffer/common/mailbox_holder.h" | 9 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| 11 #include "media/base/yuv_convert.h" | 11 #include "media/base/yuv_convert.h" |
| 12 #include "skia/ext/refptr.h" | 12 #include "skia/ext/refptr.h" |
| 13 #include "third_party/libyuv/include/libyuv.h" | 13 #include "third_party/libyuv/include/libyuv.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkImage.h" | 15 #include "third_party/skia/include/core/SkImage.h" |
| 16 #include "third_party/skia/include/core/SkImageGenerator.h" | 16 #include "third_party/skia/include/core/SkImageGenerator.h" |
| 17 #include "third_party/skia/include/gpu/GrContext.h" | 17 #include "third_party/skia/include/gpu/GrContext.h" |
| 18 #include "third_party/skia/include/gpu/GrPaint.h" | 18 #include "third_party/skia/include/gpu/GrPaint.h" |
| 19 #include "third_party/skia/include/gpu/GrTexture.h" | 19 #include "third_party/skia/include/gpu/GrTexture.h" |
| 20 #include "third_party/skia/include/gpu/GrTextureProvider.h" | 20 #include "third_party/skia/include/gpu/GrTextureProvider.h" |
| 21 #include "ui/gfx/geometry/rect_f.h" | 21 #include "ui/gfx/geometry/rect_f.h" |
| 22 | 22 |
| 23 // Skia internal format depends on a platform. On Android it is ABGR, on others | 23 // Skia internal format depends on a platform. On Android it is ABGR, on others |
| 24 // it is ARGB. | 24 // it is ARGB. |
| 25 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ | 25 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ |
| 26 SK_A32_SHIFT == 24 | 26 SK_A32_SHIFT == 24 |
| 27 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB | 27 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB |
| 28 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB | 28 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB |
| 29 #define LIBYUV_I420ALPHA_TO_ARGB libyuv::I420AlphaToARGB | 29 #define LIBYUV_I420ALPHA_TO_ARGB libyuv::I420AlphaToARGB |
| 30 #define LIBYUV_J420_TO_ARGB libyuv::J420ToARGB | |
| 30 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ | 31 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ |
| 31 SK_A32_SHIFT == 24 | 32 SK_A32_SHIFT == 24 |
| 32 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR | 33 #define LIBYUV_I420_TO_ARGB libyuv::I420ToABGR |
| 33 #define LIBYUV_I422_TO_ARGB libyuv::I422ToABGR | 34 #define LIBYUV_I422_TO_ARGB libyuv::I422ToABGR |
| 34 #define LIBYUV_I420ALPHA_TO_ARGB libyuv::I420AlphaToABGR | 35 #define LIBYUV_I420ALPHA_TO_ARGB libyuv::I420AlphaToABGR |
| 36 #define LIBYUV_J420_TO_ARGB libyuv::J420ToABGR | |
| 35 #else | 37 #else |
| 36 #error Unexpected Skia ARGB_8888 layout! | 38 #error Unexpected Skia ARGB_8888 layout! |
| 37 #endif | 39 #endif |
| 38 | 40 |
| 39 namespace media { | 41 namespace media { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 // This class keeps the last image drawn. | 45 // This class keeps the last image drawn. |
| 44 // We delete the temporary resource if it is not used for 3 seconds. | 46 // We delete the temporary resource if it is not used for 3 seconds. |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 NOTREACHED() << "Non YUV formats are not supported"; | 414 NOTREACHED() << "Non YUV formats are not supported"; |
| 413 return; | 415 return; |
| 414 } | 416 } |
| 415 DCHECK_EQ(video_frame->stride(VideoFrame::kUPlane), | 417 DCHECK_EQ(video_frame->stride(VideoFrame::kUPlane), |
| 416 video_frame->stride(VideoFrame::kVPlane)); | 418 video_frame->stride(VideoFrame::kVPlane)); |
| 417 | 419 |
| 418 switch (video_frame->format()) { | 420 switch (video_frame->format()) { |
| 419 case PIXEL_FORMAT_YV12: | 421 case PIXEL_FORMAT_YV12: |
| 420 case PIXEL_FORMAT_I420: | 422 case PIXEL_FORMAT_I420: |
| 421 if (CheckColorSpace(video_frame, COLOR_SPACE_JPEG)) { | 423 if (CheckColorSpace(video_frame, COLOR_SPACE_JPEG)) { |
| 422 libyuv::J420ToARGB( | 424 LIBYUV_J420_TO_ARGB( |
| 423 video_frame->visible_data(VideoFrame::kYPlane), | 425 video_frame->visible_data(VideoFrame::kYPlane), |
| 424 video_frame->stride(VideoFrame::kYPlane), | 426 video_frame->stride(VideoFrame::kYPlane), |
| 425 video_frame->visible_data(VideoFrame::kUPlane), | 427 video_frame->visible_data(VideoFrame::kUPlane), |
| 426 video_frame->stride(VideoFrame::kUPlane), | 428 video_frame->stride(VideoFrame::kUPlane), |
| 427 video_frame->visible_data(VideoFrame::kVPlane), | 429 video_frame->visible_data(VideoFrame::kVPlane), |
| 428 video_frame->stride(VideoFrame::kVPlane), | 430 video_frame->stride(VideoFrame::kVPlane), |
| 429 static_cast<uint8*>(rgb_pixels), | 431 static_cast<uint8*>(rgb_pixels), |
| 430 row_bytes, | 432 row_bytes, |
| 431 video_frame->visible_rect().width(), | 433 video_frame->visible_rect().width(), |
| 432 video_frame->visible_rect().height()); | 434 video_frame->visible_rect().height()); |
| 433 #if SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ | |
| 434 SK_A32_SHIFT == 24 | |
| 435 libyuv::ARGBToABGR(static_cast<uint8*>(rgb_pixels), | |
| 436 row_bytes, | |
| 437 static_cast<uint8*>(rgb_pixels), | |
| 438 row_bytes, | |
| 439 video_frame->visible_rect().width(), | |
| 440 video_frame->visible_rect().height()); | |
| 441 #endif | |
| 442 } else if (CheckColorSpace(video_frame, COLOR_SPACE_HD_REC709)) { | 435 } else if (CheckColorSpace(video_frame, COLOR_SPACE_HD_REC709)) { |
| 443 ConvertYUVToRGB32(video_frame->visible_data(VideoFrame::kYPlane), | 436 ConvertYUVToRGB32(video_frame->visible_data(VideoFrame::kYPlane), |
| 444 video_frame->visible_data(VideoFrame::kUPlane), | 437 video_frame->visible_data(VideoFrame::kUPlane), |
| 445 video_frame->visible_data(VideoFrame::kVPlane), | 438 video_frame->visible_data(VideoFrame::kVPlane), |
| 446 static_cast<uint8*>(rgb_pixels), | 439 static_cast<uint8*>(rgb_pixels), |
| 447 video_frame->visible_rect().width(), | 440 video_frame->visible_rect().width(), |
| 448 video_frame->visible_rect().height(), | 441 video_frame->visible_rect().height(), |
| 449 video_frame->stride(VideoFrame::kYPlane), | 442 video_frame->stride(VideoFrame::kYPlane), |
| 450 video_frame->stride(VideoFrame::kUPlane), row_bytes, | 443 video_frame->stride(VideoFrame::kUPlane), row_bytes, |
| 451 YV12HD); | 444 YV12HD); |
| 452 } else { | 445 } else { |
| 453 LIBYUV_I420_TO_ARGB( | 446 LIBYUV_I420_TO_ARGB( |
| 454 video_frame->visible_data(VideoFrame::kYPlane), | 447 video_frame->visible_data(VideoFrame::kYPlane), |
| 455 video_frame->stride(VideoFrame::kYPlane), | 448 video_frame->stride(VideoFrame::kYPlane), |
| 456 video_frame->visible_data(VideoFrame::kUPlane), | 449 video_frame->visible_data(VideoFrame::kUPlane), |
| 457 video_frame->stride(VideoFrame::kUPlane), | 450 video_frame->stride(VideoFrame::kUPlane), |
| 458 video_frame->visible_data(VideoFrame::kVPlane), | 451 video_frame->visible_data(VideoFrame::kVPlane), |
| 459 video_frame->stride(VideoFrame::kVPlane), | 452 video_frame->stride(VideoFrame::kVPlane), |
| 460 static_cast<uint8*>(rgb_pixels), | 453 static_cast<uint8*>(rgb_pixels), |
| 461 row_bytes, | 454 row_bytes, |
| 462 video_frame->visible_rect().width(), | 455 video_frame->visible_rect().width(), |
| 463 video_frame->visible_rect().height()); | 456 video_frame->visible_rect().height()); |
| 464 } | 457 } |
| 465 break; | 458 break; |
| 466 case PIXEL_FORMAT_YV16: | 459 case PIXEL_FORMAT_YV16: |
| 467 LIBYUV_I422_TO_ARGB( | 460 LIBYUV_I422_TO_ARGB( |
|
fbarchard
2015/09/03 19:17:36
Note J422ToARGB and J422ToABGR are also available
| |
| 468 video_frame->visible_data(VideoFrame::kYPlane), | 461 video_frame->visible_data(VideoFrame::kYPlane), |
| 469 video_frame->stride(VideoFrame::kYPlane), | 462 video_frame->stride(VideoFrame::kYPlane), |
| 470 video_frame->visible_data(VideoFrame::kUPlane), | 463 video_frame->visible_data(VideoFrame::kUPlane), |
| 471 video_frame->stride(VideoFrame::kUPlane), | 464 video_frame->stride(VideoFrame::kUPlane), |
| 472 video_frame->visible_data(VideoFrame::kVPlane), | 465 video_frame->visible_data(VideoFrame::kVPlane), |
| 473 video_frame->stride(VideoFrame::kVPlane), | 466 video_frame->stride(VideoFrame::kVPlane), |
| 474 static_cast<uint8*>(rgb_pixels), | 467 static_cast<uint8*>(rgb_pixels), |
| 475 row_bytes, | 468 row_bytes, |
| 476 video_frame->visible_rect().width(), | 469 video_frame->visible_rect().width(), |
| 477 video_frame->visible_rect().height()); | 470 video_frame->visible_rect().height()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 video_frame->UpdateReleaseSyncPoint(&client); | 562 video_frame->UpdateReleaseSyncPoint(&client); |
| 570 } | 563 } |
| 571 | 564 |
| 572 void SkCanvasVideoRenderer::ResetCache() { | 565 void SkCanvasVideoRenderer::ResetCache() { |
| 573 // Clear cached values. | 566 // Clear cached values. |
| 574 last_image_ = nullptr; | 567 last_image_ = nullptr; |
| 575 last_timestamp_ = kNoTimestamp(); | 568 last_timestamp_ = kNoTimestamp(); |
| 576 } | 569 } |
| 577 | 570 |
| 578 } // namespace media | 571 } // namespace media |
| OLD | NEW |