Chromium Code Reviews| 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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 // a new one based on video size. | 630 // a new one based on video size. |
| 631 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { | 631 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { |
| 632 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, | 632 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, |
| 633 naturalSize())) { | 633 naturalSize())) { |
| 634 return; | 634 return; |
| 635 } | 635 } |
| 636 } | 636 } |
| 637 | 637 |
| 638 unsigned textureId = static_cast<unsigned>( | 638 unsigned textureId = static_cast<unsigned>( |
| 639 (bitmap_.getTexture())->getTextureHandle()); | 639 (bitmap_.getTexture())->getTextureHandle()); |
| 640 if (!copyVideoTextureToPlatformTexture(context3D, textureId, | 640 if (!copyVideoTextureToPlatformTexture(context3D, GL_TEXTURE_2D, textureId, |
| 641 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) { | 641 GL_RGBA, GL_UNSIGNED_BYTE, 0, true, |
| 642 false)) { | |
| 642 return; | 643 return; |
| 643 } | 644 } |
| 644 | 645 |
| 645 // Draw the texture based bitmap onto the Canvas. If the canvas is | 646 // Draw the texture based bitmap onto the Canvas. If the canvas is |
| 646 // hardware based, this will do a GPU-GPU texture copy. | 647 // hardware based, this will do a GPU-GPU texture copy. |
| 647 // If the canvas is software based, the texture based bitmap will be | 648 // If the canvas is software based, the texture based bitmap will be |
| 648 // readbacked to system memory then draw onto the canvas. | 649 // readbacked to system memory then draw onto the canvas. |
| 649 SkRect dest; | 650 SkRect dest; |
| 650 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); | 651 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); |
| 651 SkPaint paint; | 652 SkPaint paint; |
| 652 paint.setAlpha(alpha); | 653 paint.setAlpha(alpha); |
| 653 paint.setXfermodeMode(mode); | 654 paint.setXfermodeMode(mode); |
| 654 // It is not necessary to pass the dest into the drawBitmap call since all | 655 // It is not necessary to pass the dest into the drawBitmap call since all |
| 655 // the context have been set up before calling paintCurrentFrameInContext. | 656 // the context have been set up before calling paintCurrentFrameInContext. |
| 656 canvas->drawBitmapRect(bitmap_, dest, &paint); | 657 canvas->drawBitmapRect(bitmap_, dest, &paint); |
| 657 } | 658 } |
| 658 | 659 |
| 659 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 660 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
| 660 blink::WebGraphicsContext3D* web_graphics_context, | 661 blink::WebGraphicsContext3D* web_graphics_context, |
| 661 unsigned int texture, | 662 unsigned int texture, |
| 662 unsigned int internal_format, | 663 unsigned int internal_format, |
| 663 unsigned int type, | 664 unsigned int type, |
| 664 bool premultiply_alpha, | 665 bool premultiply_alpha, |
| 665 bool flip_y) { | 666 bool flip_y) { |
| 667 return copyVideoTextureToPlatformTexture(web_graphics_context, GL_TEXTURE_2D, | |
| 668 texture, internal_format, type, 0, | |
| 669 premultiply_alpha, flip_y); | |
| 670 } | |
| 671 | |
| 672 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | |
| 673 blink::WebGraphicsContext3D* web_graphics_context, | |
| 674 unsigned int target, | |
| 675 unsigned int texture, | |
| 676 unsigned int internal_format, | |
| 677 unsigned int type, | |
| 678 int level, | |
| 679 bool premultiply_alpha, | |
| 680 bool flip_y) { | |
| 681 return CopyVideoTextureToPlatformTextureInternal( | |
| 682 web_graphics_context, true, target, texture, internal_format, type, level, | |
| 683 0, 0, premultiply_alpha, flip_y); | |
| 684 } | |
| 685 | |
| 686 bool WebMediaPlayerAndroid::copyVideoSubTextureToPlatformTexture( | |
| 687 blink::WebGraphicsContext3D* web_graphics_context, | |
| 688 unsigned int target, | |
| 689 unsigned int texture, | |
| 690 int level, | |
| 691 int xoffset, | |
| 692 int yoffset, | |
| 693 bool premultiply_alpha, | |
| 694 bool flip_y) { | |
| 695 return CopyVideoTextureToPlatformTextureInternal( | |
| 696 web_graphics_context, false, target, texture, GL_FALSE, GL_FALSE, level, | |
| 697 xoffset, yoffset, premultiply_alpha, flip_y); | |
| 698 } | |
| 699 | |
| 700 bool WebMediaPlayerAndroid::CopyVideoTextureToPlatformTextureInternal( | |
| 701 blink::WebGraphicsContext3D* web_graphics_context, | |
| 702 bool is_full_copy, | |
| 703 unsigned int target, | |
| 704 unsigned int texture, | |
| 705 unsigned int internal_format, | |
| 706 unsigned int type, | |
| 707 int level, | |
| 708 int xoffset, | |
| 709 int yoffset, | |
| 710 bool premultiply_alpha, | |
| 711 bool flip_y) { | |
| 666 DCHECK(main_thread_checker_.CalledOnValidThread()); | 712 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 667 // Don't allow clients to copy an encrypted video frame. | 713 // Don't allow clients to copy an encrypted video frame. |
| 668 if (needs_external_surface_) | 714 if (needs_external_surface_) |
| 669 return false; | 715 return false; |
| 670 | 716 |
| 671 scoped_refptr<VideoFrame> video_frame; | 717 scoped_refptr<VideoFrame> video_frame; |
| 672 { | 718 { |
| 673 base::AutoLock auto_lock(current_frame_lock_); | 719 base::AutoLock auto_lock(current_frame_lock_); |
| 674 video_frame = current_frame_; | 720 video_frame = current_frame_; |
| 675 } | 721 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 687 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 733 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
| 688 // an invalid texture target may be used for copy texture. | 734 // an invalid texture target may be used for copy texture. |
| 689 uint32 src_texture = | 735 uint32 src_texture = |
| 690 web_graphics_context->createAndConsumeTextureCHROMIUM( | 736 web_graphics_context->createAndConsumeTextureCHROMIUM( |
| 691 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 737 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
| 692 | 738 |
| 693 // Application itself needs to take care of setting the right flip_y | 739 // Application itself needs to take care of setting the right flip_y |
| 694 // value down to get the expected result. | 740 // value down to get the expected result. |
| 695 // flip_y==true means to reverse the video orientation while | 741 // flip_y==true means to reverse the video orientation while |
| 696 // flip_y==false means to keep the intrinsic orientation. | 742 // flip_y==false means to keep the intrinsic orientation. |
| 697 web_graphics_context->copyTextureCHROMIUM( | 743 if (is_full_copy) { |
|
piman
2015/09/04 17:34:29
nit: maybe DCHECK that xoffset/yoffset are 0 here?
| |
| 698 GL_TEXTURE_2D, src_texture, texture, internal_format, type, | 744 web_graphics_context->copyTextureCHROMIUM(target, src_texture, texture, |
| 699 flip_y, premultiply_alpha, false); | 745 internal_format, type, flip_y, |
| 746 premultiply_alpha, false); | |
| 747 } else { | |
| 748 web_graphics_context->copySubTextureCHROMIUM( | |
| 749 target, src_texture, texture, xoffset, yoffset, 0, 0, | |
| 750 video_frame->natural_size().width(), | |
| 751 video_frame->natural_size().height(), flip_y, premultiply_alpha, false); | |
| 752 } | |
| 700 | 753 |
| 701 web_graphics_context->deleteTexture(src_texture); | 754 web_graphics_context->deleteTexture(src_texture); |
| 702 web_graphics_context->flush(); | 755 web_graphics_context->flush(); |
| 703 | 756 |
| 704 SyncPointClientImpl client(web_graphics_context); | 757 SyncPointClientImpl client(web_graphics_context); |
| 705 video_frame->UpdateReleaseSyncPoint(&client); | 758 video_frame->UpdateReleaseSyncPoint(&client); |
| 706 return true; | 759 return true; |
| 707 } | 760 } |
| 708 | 761 |
| 709 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 762 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
| (...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1907 | 1960 |
| 1908 bool is_hls = IsHLSStream(); | 1961 bool is_hls = IsHLSStream(); |
| 1909 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); | 1962 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); |
| 1910 if (is_hls) { | 1963 if (is_hls) { |
| 1911 media::RecordOriginOfHLSPlayback( | 1964 media::RecordOriginOfHLSPlayback( |
| 1912 GURL(frame_->document().securityOrigin().toString())); | 1965 GURL(frame_->document().securityOrigin().toString())); |
| 1913 } | 1966 } |
| 1914 } | 1967 } |
| 1915 | 1968 |
| 1916 } // namespace content | 1969 } // namespace content |
| OLD | NEW |