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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 bool ret = did_loading_progress_; | 641 bool ret = did_loading_progress_; |
| 642 did_loading_progress_ = false; | 642 did_loading_progress_ = false; |
| 643 return ret; | 643 return ret; |
| 644 } | 644 } |
| 645 | 645 |
| 646 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, | 646 void WebMediaPlayerAndroid::paint(blink::WebCanvas* canvas, |
| 647 const blink::WebRect& rect, | 647 const blink::WebRect& rect, |
| 648 unsigned char alpha, | 648 unsigned char alpha, |
| 649 SkXfermode::Mode mode) { | 649 SkXfermode::Mode mode) { |
| 650 DCHECK(main_thread_checker_.CalledOnValidThread()); | 650 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 651 scoped_ptr<blink::WebGraphicsContext3DProvider> provider = | 651 scoped_ptr<blink::WebGraphicsContext3DProvider> provider( |
| 652 scoped_ptr<blink::WebGraphicsContext3DProvider>(blink::Platform::current( | 652 blink::Platform::current() |
| 653 )->createSharedOffscreenGraphicsContext3DProvider()); | 653 ->createSharedOffscreenGraphicsContext3DProvider()); |
| 654 if (!provider) | 654 if (!provider) |
| 655 return; | 655 return; |
| 656 blink::WebGraphicsContext3D* context3D = provider->context3d(); | 656 gpu::gles2::GLES2Interface* gl = provider->contextGL(); |
| 657 if (!context3D) | |
| 658 return; | |
| 659 | 657 |
| 660 // Copy video texture into a RGBA texture based bitmap first as video texture | 658 // Copy video texture into a RGBA texture based bitmap first as video texture |
| 661 // on Android is GL_TEXTURE_EXTERNAL_OES which is not supported by Skia yet. | 659 // on Android is GL_TEXTURE_EXTERNAL_OES which is not supported by Skia yet. |
| 662 // The bitmap's size needs to be the same as the video and use naturalSize() | 660 // The bitmap's size needs to be the same as the video and use naturalSize() |
| 663 // here. Check if we could reuse existing texture based bitmap. | 661 // here. Check if we could reuse existing texture based bitmap. |
| 664 // Otherwise, release existing texture based bitmap and allocate | 662 // Otherwise, release existing texture based bitmap and allocate |
| 665 // a new one based on video size. | 663 // a new one based on video size. |
| 666 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { | 664 if (!IsSkBitmapProperlySizedTexture(&bitmap_, naturalSize())) { |
| 667 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, | 665 if (!AllocateSkBitmapTexture(provider->grContext(), &bitmap_, |
| 668 naturalSize())) { | 666 naturalSize())) { |
| 669 return; | 667 return; |
| 670 } | 668 } |
| 671 } | 669 } |
| 672 | 670 |
| 673 unsigned textureId = skia::GrBackendObjectToGrGLTextureInfo( | 671 unsigned textureId = skia::GrBackendObjectToGrGLTextureInfo( |
| 674 (bitmap_.getTexture())->getTextureHandle()) | 672 (bitmap_.getTexture())->getTextureHandle()) |
| 675 ->fID; | 673 ->fID; |
| 676 if (!copyVideoTextureToPlatformTexture(context3D, textureId, | 674 if (!copyVideoTextureToPlatformTexture(gl, textureId, GL_RGBA, |
| 677 GL_RGBA, GL_UNSIGNED_BYTE, true, false)) { | 675 GL_UNSIGNED_BYTE, true, false)) { |
| 678 return; | 676 return; |
| 679 } | 677 } |
| 680 | 678 |
| 681 // Ensure SkBitmap to make the latest change by external source visible. | 679 // Ensure SkBitmap to make the latest change by external source visible. |
| 682 bitmap_.notifyPixelsChanged(); | 680 bitmap_.notifyPixelsChanged(); |
| 683 | 681 |
| 684 // Draw the texture based bitmap onto the Canvas. If the canvas is | 682 // Draw the texture based bitmap onto the Canvas. If the canvas is |
| 685 // hardware based, this will do a GPU-GPU texture copy. | 683 // hardware based, this will do a GPU-GPU texture copy. |
| 686 // If the canvas is software based, the texture based bitmap will be | 684 // If the canvas is software based, the texture based bitmap will be |
| 687 // readbacked to system memory then draw onto the canvas. | 685 // readbacked to system memory then draw onto the canvas. |
| 688 SkRect dest; | 686 SkRect dest; |
| 689 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); | 687 dest.set(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); |
| 690 SkPaint paint; | 688 SkPaint paint; |
| 691 paint.setAlpha(alpha); | 689 paint.setAlpha(alpha); |
| 692 paint.setXfermodeMode(mode); | 690 paint.setXfermodeMode(mode); |
| 693 // It is not necessary to pass the dest into the drawBitmap call since all | 691 // It is not necessary to pass the dest into the drawBitmap call since all |
| 694 // the context have been set up before calling paintCurrentFrameInContext. | 692 // the context have been set up before calling paintCurrentFrameInContext. |
| 695 canvas->drawBitmapRect(bitmap_, dest, &paint); | 693 canvas->drawBitmapRect(bitmap_, dest, &paint); |
| 696 canvas->flush(); | 694 canvas->flush(); |
| 697 } | 695 } |
| 698 | 696 |
| 699 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( | 697 bool WebMediaPlayerAndroid::copyVideoTextureToPlatformTexture( |
| 700 blink::WebGraphicsContext3D* web_graphics_context, | 698 gpu::gles2::GLES2Interface* gl, |
| 701 unsigned int texture, | 699 unsigned int texture, |
| 702 unsigned int internal_format, | 700 unsigned int internal_format, |
| 703 unsigned int type, | 701 unsigned int type, |
| 704 bool premultiply_alpha, | 702 bool premultiply_alpha, |
| 705 bool flip_y) { | 703 bool flip_y) { |
| 706 // TODO(danakj): Pass a GLES2Interface to this method instead. | 704 // TODO(danakj): Pass a GLES2Interface to this method instead. |
|
DaleCurtis
2016/03/25 22:32:00
Delete todo?
danakj
2016/03/25 22:36:44
:D
| |
| 707 gpu::gles2::GLES2Interface* gl = web_graphics_context->getGLES2Interface(); | |
| 708 DCHECK(main_thread_checker_.CalledOnValidThread()); | 705 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 709 // Don't allow clients to copy an encrypted video frame. | 706 // Don't allow clients to copy an encrypted video frame. |
| 710 if (needs_external_surface_) | 707 if (needs_external_surface_) |
| 711 return false; | 708 return false; |
| 712 | 709 |
| 713 scoped_refptr<VideoFrame> video_frame; | 710 scoped_refptr<VideoFrame> video_frame; |
| 714 { | 711 { |
| 715 base::AutoLock auto_lock(current_frame_lock_); | 712 base::AutoLock auto_lock(current_frame_lock_); |
| 716 video_frame = current_frame_; | 713 video_frame = current_frame_; |
| 717 } | 714 } |
| (...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1675 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; | 1672 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; |
| 1676 } else if (is_hls_url == is_hls) { | 1673 } else if (is_hls_url == is_hls) { |
| 1677 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; | 1674 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; |
| 1678 } | 1675 } |
| 1679 UMA_HISTOGRAM_ENUMERATION( | 1676 UMA_HISTOGRAM_ENUMERATION( |
| 1680 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", | 1677 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", |
| 1681 result, PREDICTION_RESULT_MAX); | 1678 result, PREDICTION_RESULT_MAX); |
| 1682 } | 1679 } |
| 1683 | 1680 |
| 1684 } // namespace content | 1681 } // namespace content |
| OLD | NEW |