OLD | NEW |
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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 // a new one based on video size. | 628 // a new one based on video size. |
629 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { | 629 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { |
630 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, | 630 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, |
631 naturalSize())) { | 631 naturalSize())) { |
632 return; | 632 return; |
633 } | 633 } |
634 } | 634 } |
635 | 635 |
636 unsigned textureId = static_cast<unsigned>( | 636 unsigned textureId = static_cast<unsigned>( |
637 (bitmap_.getTexture())->getTextureHandle()); | 637 (bitmap_.getTexture())->getTextureHandle()); |
638 if (!copyVideoTextureToPlatformTexture(context3D, textureId, | 638 if (!copyVideoTextureToPlatformTexture( |
639 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) { | 639 context3D, |
| 640 CopyVideoTextureParams(CopyVideoTextureParams::FullCopy, |
| 641 GL_TEXTURE_2D, textureId, GL_RGBA, |
| 642 GL_UNSIGNED_BYTE, 0, 0, 0, true, false))) { |
640 return; | 643 return; |
641 } | 644 } |
642 | 645 |
643 // Ensure SkBitmap to make the latest change by external source visible. | 646 // Ensure SkBitmap to make the latest change by external source visible. |
644 bitmap_.notifyPixelsChanged(); | 647 bitmap_.notifyPixelsChanged(); |
645 | 648 |
646 // Draw the texture based bitmap onto the Canvas. If the canvas is | 649 // Draw the texture based bitmap onto the Canvas. If the canvas is |
647 // hardware based, this will do a GPU-GPU texture copy. | 650 // hardware based, this will do a GPU-GPU texture copy. |
648 // If the canvas is software based, the texture based bitmap will be | 651 // If the canvas is software based, the texture based bitmap will be |
649 // readbacked to system memory then draw onto the canvas. | 652 // readbacked to system memory then draw onto the canvas. |
650 SkRect dest; | 653 SkRect dest; |
651 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); | 654 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); |
652 SkPaint paint; | 655 SkPaint paint; |
653 paint.setAlpha(alpha); | 656 paint.setAlpha(alpha); |
654 paint.setXfermodeMode(mode); | 657 paint.setXfermodeMode(mode); |
655 // It is not necessary to pass the dest into the drawBitmap call since all | 658 // It is not necessary to pass the dest into the drawBitmap call since all |
656 // the context have been set up before calling paintCurrentFrameInContext. | 659 // the context have been set up before calling paintCurrentFrameInContext. |
657 canvas->drawBitmapRect(bitmap_, dest, &paint); | 660 canvas->drawBitmapRect(bitmap_, dest, &paint); |
658 canvas->flush(); | 661 canvas->flush(); |
659 } | 662 } |
660 | 663 |
661 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 664 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
662 blink::WebGraphicsContext3D* web_graphics_context, | 665 blink::WebGraphicsContext3D* web_graphics_context, |
663 unsigned int texture, | 666 const CopyVideoTextureParams& params) { |
664 unsigned int internal_format, | |
665 unsigned int type, | |
666 bool premultiply_alpha, | |
667 bool flip_y) { | |
668 DCHECK(main_thread_checker_.CalledOnValidThread()); | 667 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 668 DCHECK((params.copyType == CopyVideoTextureParams::FullCopy && |
| 669 !params.xoffset && !params.yoffset) || |
| 670 (params.copyType == CopyVideoTextureParams::SubCopy && |
| 671 !params.internalFormat && !params.type)); |
669 // Don't allow clients to copy an encrypted video frame. | 672 // Don't allow clients to copy an encrypted video frame. |
670 if (needs_external_surface_) | 673 if (needs_external_surface_) |
671 return false; | 674 return false; |
672 | 675 |
673 scoped_refptr<VideoFrame> video_frame; | 676 scoped_refptr<VideoFrame> video_frame; |
674 { | 677 { |
675 base::AutoLock auto_lock(current_frame_lock_); | 678 base::AutoLock auto_lock(current_frame_lock_); |
676 video_frame = current_frame_; | 679 video_frame = current_frame_; |
677 } | 680 } |
678 | 681 |
(...skipping 10 matching lines...) Expand all Loading... |
689 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 692 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
690 // an invalid texture target may be used for copy texture. | 693 // an invalid texture target may be used for copy texture. |
691 uint32 src_texture = | 694 uint32 src_texture = |
692 web_graphics_context->createAndConsumeTextureCHROMIUM( | 695 web_graphics_context->createAndConsumeTextureCHROMIUM( |
693 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 696 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
694 | 697 |
695 // Application itself needs to take care of setting the right flip_y | 698 // Application itself needs to take care of setting the right flip_y |
696 // value down to get the expected result. | 699 // value down to get the expected result. |
697 // flip_y==true means to reverse the video orientation while | 700 // flip_y==true means to reverse the video orientation while |
698 // flip_y==false means to keep the intrinsic orientation. | 701 // flip_y==false means to keep the intrinsic orientation. |
699 web_graphics_context->copyTextureCHROMIUM( | 702 if (params.copyType == CopyVideoTextureParams::FullCopy) { |
700 GL_TEXTURE_2D, src_texture, texture, internal_format, type, | 703 web_graphics_context->copyTextureCHROMIUM( |
701 flip_y, premultiply_alpha, false); | 704 params.target, src_texture, params.texture, params.internalFormat, |
| 705 params.type, params.flipY, params.premultiplyAlpha, false); |
| 706 } else { |
| 707 web_graphics_context->copySubTextureCHROMIUM( |
| 708 params.target, src_texture, params.texture, params.xoffset, |
| 709 params.yoffset, 0, 0, video_frame->natural_size().width(), |
| 710 video_frame->natural_size().height(), params.flipY, |
| 711 params.premultiplyAlpha, false); |
| 712 } |
702 | 713 |
703 web_graphics_context->deleteTexture(src_texture); | 714 web_graphics_context->deleteTexture(src_texture); |
704 web_graphics_context->flush(); | 715 web_graphics_context->flush(); |
705 | 716 |
706 SyncPointClientImpl client(web_graphics_context); | 717 SyncPointClientImpl client(web_graphics_context); |
707 video_frame->UpdateReleaseSyncPoint(&client); | 718 video_frame->UpdateReleaseSyncPoint(&client); |
708 return true; | 719 return true; |
709 } | 720 } |
710 | 721 |
711 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 722 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1919 | 1930 |
1920 bool is_hls = IsHLSStream(); | 1931 bool is_hls = IsHLSStream(); |
1921 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); | 1932 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); |
1922 if (is_hls) { | 1933 if (is_hls) { |
1923 media::RecordOriginOfHLSPlayback( | 1934 media::RecordOriginOfHLSPlayback( |
1924 GURL(frame_->document().securityOrigin().toString())); | 1935 GURL(frame_->document().securityOrigin().toString())); |
1925 } | 1936 } |
1926 } | 1937 } |
1927 | 1938 |
1928 } // namespace content | 1939 } // namespace content |
OLD | NEW |