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 "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
10 #include "gpu/command_buffer/client/gles2_interface.h" | 10 #include "gpu/command_buffer/client/gles2_interface.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } else { | 263 } else { |
264 offset = (frame_->stride(VideoFrame::kUPlane) * | 264 offset = (frame_->stride(VideoFrame::kUPlane) * |
265 (frame_->visible_rect().y() >> y_shift)) + | 265 (frame_->visible_rect().y() >> y_shift)) + |
266 (frame_->visible_rect().x() >> 1); | 266 (frame_->visible_rect().x() >> 1); |
267 } | 267 } |
268 | 268 |
269 // Copy the frame to the supplied memory. | 269 // Copy the frame to the supplied memory. |
270 // TODO: Find a way (API change?) to avoid this copy. | 270 // TODO: Find a way (API change?) to avoid this copy. |
271 char* out_line = static_cast<char*>(planes[plane]); | 271 char* out_line = static_cast<char*>(planes[plane]); |
272 int out_line_stride = row_bytes[plane]; | 272 int out_line_stride = row_bytes[plane]; |
273 uint8* in_line = frame_->data(plane) + offset; | 273 uint8_t* in_line = frame_->data(plane) + offset; |
274 int in_line_stride = frame_->stride(plane); | 274 int in_line_stride = frame_->stride(plane); |
275 int plane_height = sizes[plane].height(); | 275 int plane_height = sizes[plane].height(); |
276 if (in_line_stride == out_line_stride) { | 276 if (in_line_stride == out_line_stride) { |
277 memcpy(out_line, in_line, plane_height * in_line_stride); | 277 memcpy(out_line, in_line, plane_height * in_line_stride); |
278 } else { | 278 } else { |
279 // Different line padding so need to copy one line at a time. | 279 // Different line padding so need to copy one line at a time. |
280 int bytes_to_copy_per_line = out_line_stride < in_line_stride | 280 int bytes_to_copy_per_line = out_line_stride < in_line_stride |
281 ? out_line_stride | 281 ? out_line_stride |
282 : in_line_stride; | 282 : in_line_stride; |
283 for (int line_no = 0; line_no < plane_height; line_no++) { | 283 for (int line_no = 0; line_no < plane_height; line_no++) { |
(...skipping 20 matching lines...) Expand all Loading... |
304 this, | 304 this, |
305 &SkCanvasVideoRenderer::ResetCache) {} | 305 &SkCanvasVideoRenderer::ResetCache) {} |
306 | 306 |
307 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() { | 307 SkCanvasVideoRenderer::~SkCanvasVideoRenderer() { |
308 ResetCache(); | 308 ResetCache(); |
309 } | 309 } |
310 | 310 |
311 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame, | 311 void SkCanvasVideoRenderer::Paint(const scoped_refptr<VideoFrame>& video_frame, |
312 SkCanvas* canvas, | 312 SkCanvas* canvas, |
313 const gfx::RectF& dest_rect, | 313 const gfx::RectF& dest_rect, |
314 uint8 alpha, | 314 uint8_t alpha, |
315 SkXfermode::Mode mode, | 315 SkXfermode::Mode mode, |
316 VideoRotation video_rotation, | 316 VideoRotation video_rotation, |
317 const Context3D& context_3d) { | 317 const Context3D& context_3d) { |
318 DCHECK(thread_checker_.CalledOnValidThread()); | 318 DCHECK(thread_checker_.CalledOnValidThread()); |
319 if (alpha == 0) { | 319 if (alpha == 0) { |
320 return; | 320 return; |
321 } | 321 } |
322 | 322 |
323 SkRect dest; | 323 SkRect dest; |
324 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom()); | 324 dest.set(dest_rect.x(), dest_rect.y(), dest_rect.right(), dest_rect.bottom()); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 switch (video_frame->format()) { | 466 switch (video_frame->format()) { |
467 case PIXEL_FORMAT_YV12: | 467 case PIXEL_FORMAT_YV12: |
468 case PIXEL_FORMAT_I420: | 468 case PIXEL_FORMAT_I420: |
469 if (CheckColorSpace(video_frame, COLOR_SPACE_JPEG)) { | 469 if (CheckColorSpace(video_frame, COLOR_SPACE_JPEG)) { |
470 LIBYUV_J420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 470 LIBYUV_J420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), |
471 video_frame->stride(VideoFrame::kYPlane), | 471 video_frame->stride(VideoFrame::kYPlane), |
472 video_frame->visible_data(VideoFrame::kUPlane), | 472 video_frame->visible_data(VideoFrame::kUPlane), |
473 video_frame->stride(VideoFrame::kUPlane), | 473 video_frame->stride(VideoFrame::kUPlane), |
474 video_frame->visible_data(VideoFrame::kVPlane), | 474 video_frame->visible_data(VideoFrame::kVPlane), |
475 video_frame->stride(VideoFrame::kVPlane), | 475 video_frame->stride(VideoFrame::kVPlane), |
476 static_cast<uint8*>(rgb_pixels), row_bytes, | 476 static_cast<uint8_t*>(rgb_pixels), row_bytes, |
477 video_frame->visible_rect().width(), | 477 video_frame->visible_rect().width(), |
478 video_frame->visible_rect().height()); | 478 video_frame->visible_rect().height()); |
479 } else if (CheckColorSpace(video_frame, COLOR_SPACE_HD_REC709)) { | 479 } else if (CheckColorSpace(video_frame, COLOR_SPACE_HD_REC709)) { |
480 LIBYUV_H420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 480 LIBYUV_H420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), |
481 video_frame->stride(VideoFrame::kYPlane), | 481 video_frame->stride(VideoFrame::kYPlane), |
482 video_frame->visible_data(VideoFrame::kUPlane), | 482 video_frame->visible_data(VideoFrame::kUPlane), |
483 video_frame->stride(VideoFrame::kUPlane), | 483 video_frame->stride(VideoFrame::kUPlane), |
484 video_frame->visible_data(VideoFrame::kVPlane), | 484 video_frame->visible_data(VideoFrame::kVPlane), |
485 video_frame->stride(VideoFrame::kVPlane), | 485 video_frame->stride(VideoFrame::kVPlane), |
486 static_cast<uint8*>(rgb_pixels), row_bytes, | 486 static_cast<uint8_t*>(rgb_pixels), row_bytes, |
487 video_frame->visible_rect().width(), | 487 video_frame->visible_rect().width(), |
488 video_frame->visible_rect().height()); | 488 video_frame->visible_rect().height()); |
489 } else { | 489 } else { |
490 LIBYUV_I420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 490 LIBYUV_I420_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), |
491 video_frame->stride(VideoFrame::kYPlane), | 491 video_frame->stride(VideoFrame::kYPlane), |
492 video_frame->visible_data(VideoFrame::kUPlane), | 492 video_frame->visible_data(VideoFrame::kUPlane), |
493 video_frame->stride(VideoFrame::kUPlane), | 493 video_frame->stride(VideoFrame::kUPlane), |
494 video_frame->visible_data(VideoFrame::kVPlane), | 494 video_frame->visible_data(VideoFrame::kVPlane), |
495 video_frame->stride(VideoFrame::kVPlane), | 495 video_frame->stride(VideoFrame::kVPlane), |
496 static_cast<uint8*>(rgb_pixels), row_bytes, | 496 static_cast<uint8_t*>(rgb_pixels), row_bytes, |
497 video_frame->visible_rect().width(), | 497 video_frame->visible_rect().width(), |
498 video_frame->visible_rect().height()); | 498 video_frame->visible_rect().height()); |
499 } | 499 } |
500 break; | 500 break; |
501 case PIXEL_FORMAT_YV16: | 501 case PIXEL_FORMAT_YV16: |
502 LIBYUV_I422_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 502 LIBYUV_I422_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), |
503 video_frame->stride(VideoFrame::kYPlane), | 503 video_frame->stride(VideoFrame::kYPlane), |
504 video_frame->visible_data(VideoFrame::kUPlane), | 504 video_frame->visible_data(VideoFrame::kUPlane), |
505 video_frame->stride(VideoFrame::kUPlane), | 505 video_frame->stride(VideoFrame::kUPlane), |
506 video_frame->visible_data(VideoFrame::kVPlane), | 506 video_frame->visible_data(VideoFrame::kVPlane), |
507 video_frame->stride(VideoFrame::kVPlane), | 507 video_frame->stride(VideoFrame::kVPlane), |
508 static_cast<uint8*>(rgb_pixels), row_bytes, | 508 static_cast<uint8_t*>(rgb_pixels), row_bytes, |
509 video_frame->visible_rect().width(), | 509 video_frame->visible_rect().width(), |
510 video_frame->visible_rect().height()); | 510 video_frame->visible_rect().height()); |
511 break; | 511 break; |
512 | 512 |
513 case PIXEL_FORMAT_YV12A: | 513 case PIXEL_FORMAT_YV12A: |
514 LIBYUV_I420ALPHA_TO_ARGB( | 514 LIBYUV_I420ALPHA_TO_ARGB( |
515 video_frame->visible_data(VideoFrame::kYPlane), | 515 video_frame->visible_data(VideoFrame::kYPlane), |
516 video_frame->stride(VideoFrame::kYPlane), | 516 video_frame->stride(VideoFrame::kYPlane), |
517 video_frame->visible_data(VideoFrame::kUPlane), | 517 video_frame->visible_data(VideoFrame::kUPlane), |
518 video_frame->stride(VideoFrame::kUPlane), | 518 video_frame->stride(VideoFrame::kUPlane), |
519 video_frame->visible_data(VideoFrame::kVPlane), | 519 video_frame->visible_data(VideoFrame::kVPlane), |
520 video_frame->stride(VideoFrame::kVPlane), | 520 video_frame->stride(VideoFrame::kVPlane), |
521 video_frame->visible_data(VideoFrame::kAPlane), | 521 video_frame->visible_data(VideoFrame::kAPlane), |
522 video_frame->stride(VideoFrame::kAPlane), | 522 video_frame->stride(VideoFrame::kAPlane), |
523 static_cast<uint8*>(rgb_pixels), row_bytes, | 523 static_cast<uint8_t*>(rgb_pixels), row_bytes, |
524 video_frame->visible_rect().width(), | 524 video_frame->visible_rect().width(), |
525 video_frame->visible_rect().height(), | 525 video_frame->visible_rect().height(), |
526 1); // 1 = enable RGB premultiplication by Alpha. | 526 1); // 1 = enable RGB premultiplication by Alpha. |
527 break; | 527 break; |
528 | 528 |
529 case PIXEL_FORMAT_YV24: | 529 case PIXEL_FORMAT_YV24: |
530 LIBYUV_I444_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), | 530 LIBYUV_I444_TO_ARGB(video_frame->visible_data(VideoFrame::kYPlane), |
531 video_frame->stride(VideoFrame::kYPlane), | 531 video_frame->stride(VideoFrame::kYPlane), |
532 video_frame->visible_data(VideoFrame::kUPlane), | 532 video_frame->visible_data(VideoFrame::kUPlane), |
533 video_frame->stride(VideoFrame::kUPlane), | 533 video_frame->stride(VideoFrame::kUPlane), |
534 video_frame->visible_data(VideoFrame::kVPlane), | 534 video_frame->visible_data(VideoFrame::kVPlane), |
535 video_frame->stride(VideoFrame::kVPlane), | 535 video_frame->stride(VideoFrame::kVPlane), |
536 static_cast<uint8*>(rgb_pixels), row_bytes, | 536 static_cast<uint8_t*>(rgb_pixels), row_bytes, |
537 video_frame->visible_rect().width(), | 537 video_frame->visible_rect().width(), |
538 video_frame->visible_rect().height()); | 538 video_frame->visible_rect().height()); |
539 break; | 539 break; |
540 case PIXEL_FORMAT_NV12: | 540 case PIXEL_FORMAT_NV12: |
541 case PIXEL_FORMAT_NV21: | 541 case PIXEL_FORMAT_NV21: |
542 case PIXEL_FORMAT_UYVY: | 542 case PIXEL_FORMAT_UYVY: |
543 case PIXEL_FORMAT_YUY2: | 543 case PIXEL_FORMAT_YUY2: |
544 case PIXEL_FORMAT_ARGB: | 544 case PIXEL_FORMAT_ARGB: |
545 case PIXEL_FORMAT_XRGB: | 545 case PIXEL_FORMAT_XRGB: |
546 case PIXEL_FORMAT_RGB24: | 546 case PIXEL_FORMAT_RGB24: |
(...skipping 18 matching lines...) Expand all Loading... |
565 DCHECK(video_frame->HasTextures()); | 565 DCHECK(video_frame->HasTextures()); |
566 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); | 566 DCHECK_EQ(1u, VideoFrame::NumPlanes(video_frame->format())); |
567 | 567 |
568 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 568 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
569 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || | 569 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || |
570 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || | 570 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB || |
571 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) | 571 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) |
572 << mailbox_holder.texture_target; | 572 << mailbox_holder.texture_target; |
573 | 573 |
574 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); | 574 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); |
575 uint32 source_texture = gl->CreateAndConsumeTextureCHROMIUM( | 575 uint32_t source_texture = gl->CreateAndConsumeTextureCHROMIUM( |
576 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 576 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
577 | 577 |
578 // The video is stored in a unmultiplied format, so premultiply | 578 // The video is stored in a unmultiplied format, so premultiply |
579 // if necessary. | 579 // if necessary. |
580 // Application itself needs to take care of setting the right |flip_y| | 580 // Application itself needs to take care of setting the right |flip_y| |
581 // value down to get the expected result. | 581 // value down to get the expected result. |
582 // "flip_y == true" means to reverse the video orientation while | 582 // "flip_y == true" means to reverse the video orientation while |
583 // "flip_y == false" means to keep the intrinsic orientation. | 583 // "flip_y == false" means to keep the intrinsic orientation. |
584 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, | 584 gl->CopyTextureCHROMIUM(GL_TEXTURE_2D, source_texture, texture, |
585 internal_format, type, flip_y, premultiply_alpha, | 585 internal_format, type, flip_y, premultiply_alpha, |
586 false); | 586 false); |
587 | 587 |
588 gl->DeleteTextures(1, &source_texture); | 588 gl->DeleteTextures(1, &source_texture); |
589 gl->Flush(); | 589 gl->Flush(); |
590 | 590 |
591 SyncTokenClientImpl client(gl); | 591 SyncTokenClientImpl client(gl); |
592 video_frame->UpdateReleaseSyncToken(&client); | 592 video_frame->UpdateReleaseSyncToken(&client); |
593 } | 593 } |
594 | 594 |
595 void SkCanvasVideoRenderer::ResetCache() { | 595 void SkCanvasVideoRenderer::ResetCache() { |
596 DCHECK(thread_checker_.CalledOnValidThread()); | 596 DCHECK(thread_checker_.CalledOnValidThread()); |
597 // Clear cached values. | 597 // Clear cached values. |
598 last_image_ = nullptr; | 598 last_image_ = nullptr; |
599 last_timestamp_ = kNoTimestamp(); | 599 last_timestamp_ = kNoTimestamp(); |
600 } | 600 } |
601 | 601 |
602 } // namespace media | 602 } // namespace media |
OLD | NEW |