| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 SkGrPixelRef* pixel_ref = new SkGrPixelRef(info, texture.get()); | 138 SkGrPixelRef* pixel_ref = new SkGrPixelRef(info, texture.get()); |
| 139 if (!pixel_ref) | 139 if (!pixel_ref) |
| 140 return false; | 140 return false; |
| 141 bitmap->setInfo(info); | 141 bitmap->setInfo(info); |
| 142 bitmap->setPixelRef(pixel_ref)->unref(); | 142 bitmap->setPixelRef(pixel_ref)->unref(); |
| 143 return true; | 143 return true; |
| 144 } | 144 } |
| 145 | 145 |
| 146 class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { | 146 class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { |
| 147 public: | 147 public: |
| 148 explicit SyncTokenClientImpl( | 148 explicit SyncTokenClientImpl(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} |
| 149 blink::WebGraphicsContext3D* web_graphics_context) | |
| 150 : web_graphics_context_(web_graphics_context) {} | |
| 151 ~SyncTokenClientImpl() override {} | 149 ~SyncTokenClientImpl() override {} |
| 152 void GenerateSyncToken(gpu::SyncToken* sync_token) override { | 150 void GenerateSyncToken(gpu::SyncToken* sync_token) override { |
| 153 const blink::WGC3Duint64 fence_sync = | 151 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); |
| 154 web_graphics_context_->insertFenceSyncCHROMIUM(); | 152 gl_->ShallowFlushCHROMIUM(); |
| 155 web_graphics_context_->shallowFlushCHROMIUM(); | 153 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token->GetData()); |
| 156 if (!web_graphics_context_->genSyncTokenCHROMIUM(fence_sync, | |
| 157 sync_token->GetData())) { | |
| 158 sync_token->Clear(); | |
| 159 } | |
| 160 } | 154 } |
| 161 void WaitSyncToken(const gpu::SyncToken& sync_token) override { | 155 void WaitSyncToken(const gpu::SyncToken& sync_token) override { |
| 162 web_graphics_context_->waitSyncTokenCHROMIUM(sync_token.GetConstData()); | 156 gl_->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 163 } | 157 } |
| 164 | 158 |
| 165 private: | 159 private: |
| 166 blink::WebGraphicsContext3D* web_graphics_context_; | 160 gpu::gles2::GLES2Interface* gl_; |
| 167 }; | 161 }; |
| 168 | 162 |
| 169 } // namespace | 163 } // namespace |
| 170 | 164 |
| 171 namespace content { | 165 namespace content { |
| 172 | 166 |
| 173 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 167 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| 174 blink::WebFrame* frame, | 168 blink::WebFrame* frame, |
| 175 blink::WebMediaPlayerClient* client, | 169 blink::WebMediaPlayerClient* client, |
| 176 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 170 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 canvas->flush(); | 696 canvas->flush(); |
| 703 } | 697 } |
| 704 | 698 |
| 705 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 699 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
| 706 blink::WebGraphicsContext3D* web_graphics_context, | 700 blink::WebGraphicsContext3D* web_graphics_context, |
| 707 unsigned int texture, | 701 unsigned int texture, |
| 708 unsigned int internal_format, | 702 unsigned int internal_format, |
| 709 unsigned int type, | 703 unsigned int type, |
| 710 bool premultiply_alpha, | 704 bool premultiply_alpha, |
| 711 bool flip_y) { | 705 bool flip_y) { |
| 706 // TODO(danakj): Pass a GLES2Interface to this method instead. |
| 707 gpu::gles2::GLES2Interface* gl = web_graphics_context->getGLES2Interface(); |
| 712 DCHECK(main_thread_checker_.CalledOnValidThread()); | 708 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 713 // Don't allow clients to copy an encrypted video frame. | 709 // Don't allow clients to copy an encrypted video frame. |
| 714 if (needs_external_surface_) | 710 if (needs_external_surface_) |
| 715 return false; | 711 return false; |
| 716 | 712 |
| 717 scoped_refptr<VideoFrame> video_frame; | 713 scoped_refptr<VideoFrame> video_frame; |
| 718 { | 714 { |
| 719 base::AutoLock auto_lock(current_frame_lock_); | 715 base::AutoLock auto_lock(current_frame_lock_); |
| 720 video_frame = current_frame_; | 716 video_frame = current_frame_; |
| 721 } | 717 } |
| 722 | 718 |
| 723 if (!video_frame.get() || !video_frame->HasTextures()) | 719 if (!video_frame.get() || !video_frame->HasTextures()) |
| 724 return false; | 720 return false; |
| 725 DCHECK_EQ(1u, media::VideoFrame::NumPlanes(video_frame->format())); | 721 DCHECK_EQ(1u, media::VideoFrame::NumPlanes(video_frame->format())); |
| 726 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 722 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
| 727 DCHECK((!is_remote_ && | 723 DCHECK((!is_remote_ && |
| 728 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || | 724 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || |
| 729 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); | 725 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); |
| 730 | 726 |
| 731 web_graphics_context->waitSyncTokenCHROMIUM( | 727 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); |
| 732 mailbox_holder.sync_token.GetConstData()); | |
| 733 | 728 |
| 734 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 729 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
| 735 // an invalid texture target may be used for copy texture. | 730 // an invalid texture target may be used for copy texture. |
| 736 uint32_t src_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( | 731 uint32_t src_texture = gl->CreateAndConsumeTextureCHROMIUM( |
| 737 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | 732 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
| 738 | 733 |
| 739 // Application itself needs to take care of setting the right flip_y | 734 // Application itself needs to take care of setting the right flip_y |
| 740 // value down to get the expected result. | 735 // value down to get the expected result. |
| 741 // flip_y==true means to reverse the video orientation while | 736 // flip_y==true means to reverse the video orientation while |
| 742 // flip_y==false means to keep the intrinsic orientation. | 737 // flip_y==false means to keep the intrinsic orientation. |
| 743 web_graphics_context->copyTextureCHROMIUM(src_texture, texture, | 738 gl->CopyTextureCHROMIUM(src_texture, texture, internal_format, type, flip_y, |
| 744 internal_format, type, flip_y, | 739 premultiply_alpha, false); |
| 745 premultiply_alpha, false); | |
| 746 | 740 |
| 747 web_graphics_context->deleteTexture(src_texture); | 741 gl->DeleteTextures(1, &src_texture); |
| 748 web_graphics_context->flush(); | 742 web_graphics_context->flush(); |
| 749 | 743 |
| 750 SyncTokenClientImpl client(web_graphics_context); | 744 SyncTokenClientImpl client(gl); |
| 751 video_frame->UpdateReleaseSyncToken(&client); | 745 video_frame->UpdateReleaseSyncToken(&client); |
| 752 return true; | 746 return true; |
| 753 } | 747 } |
| 754 | 748 |
| 755 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 749 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
| 756 DCHECK(main_thread_checker_.CalledOnValidThread()); | 750 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 757 if (player_type_ != MEDIA_PLAYER_TYPE_URL) | 751 if (player_type_ != MEDIA_PLAYER_TYPE_URL) |
| 758 return true; | 752 return true; |
| 759 | 753 |
| 760 if (!info_loader_ || !info_loader_->HasSingleOrigin()) | 754 if (!info_loader_ || !info_loader_->HasSingleOrigin()) |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; | 1675 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; |
| 1682 } else if (is_hls_url == is_hls) { | 1676 } else if (is_hls_url == is_hls) { |
| 1683 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; | 1677 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; |
| 1684 } | 1678 } |
| 1685 UMA_HISTOGRAM_ENUMERATION( | 1679 UMA_HISTOGRAM_ENUMERATION( |
| 1686 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", | 1680 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", |
| 1687 result, PREDICTION_RESULT_MAX); | 1681 result, PREDICTION_RESULT_MAX); |
| 1688 } | 1682 } |
| 1689 | 1683 |
| 1690 } // namespace content | 1684 } // namespace content |
| OLD | NEW |