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