Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp

Issue 13685002: Enable video painting on Canvas for Chrome on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressing Min's comments. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "config.h" 5 #include "config.h"
6 #include "WebMediaPlayerClientImpl.h" 6 #include "WebMediaPlayerClientImpl.h"
7 7
8 #if ENABLE(VIDEO) 8 #if ENABLE(VIDEO)
9 9
10 #include "AudioBus.h" 10 #include "AudioBus.h"
11 #include "AudioSourceProvider.h" 11 #include "AudioSourceProvider.h"
12 #include "AudioSourceProviderClient.h" 12 #include "AudioSourceProviderClient.h"
13 #include "Frame.h" 13 #include "Frame.h"
14 #include "GraphicsContext.h" 14 #include "GraphicsContext.h"
15 #include "GraphicsContext3DPrivate.h" 15 #include "GraphicsContext3DPrivate.h"
16 #include "GraphicsLayerChromium.h" 16 #include "GraphicsLayerChromium.h"
17 #include "GrContext.h"
18 #include "GrTexture.h"
19 #include "GrTypes.h"
17 #include "HTMLMediaElement.h" 20 #include "HTMLMediaElement.h"
18 #include "IntSize.h" 21 #include "IntSize.h"
19 #include "KURL.h" 22 #include "KURL.h"
20 #include "MediaPlayer.h" 23 #include "MediaPlayer.h"
21 #include "NotImplemented.h" 24 #include "NotImplemented.h"
22 #include "PlatformContextSkia.h" 25 #include "PlatformContextSkia.h"
23 #include "RenderView.h" 26 #include "RenderView.h"
27 #include "SkRefCnt.h"
28 #include "SkBitmap.h"
29 #include "SkCanvas.h"
30 #include "SkGrPixelRef.h"
24 #include "TimeRanges.h" 31 #include "TimeRanges.h"
25 #include "WebAudioSourceProvider.h" 32 #include "WebAudioSourceProvider.h"
26 #include "WebDocument.h" 33 #include "WebDocument.h"
27 #include "WebFrameClient.h" 34 #include "WebFrameClient.h"
28 #include "WebFrameImpl.h" 35 #include "WebFrameImpl.h"
29 #include "WebHelperPluginImpl.h" 36 #include "WebHelperPluginImpl.h"
30 #include "WebMediaPlayer.h" 37 #include "WebMediaPlayer.h"
31 #include "WebMediaSourceImpl.h" 38 #include "WebMediaSourceImpl.h"
32 #include "WebViewImpl.h" 39 #include "WebViewImpl.h"
33 #include <public/Platform.h> 40 #include <public/Platform.h>
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 } 620 }
614 621
615 void WebMediaPlayerClientImpl::paintCurrentFrameInContext(GraphicsContext* conte xt, const IntRect& rect) 622 void WebMediaPlayerClientImpl::paintCurrentFrameInContext(GraphicsContext* conte xt, const IntRect& rect)
616 { 623 {
617 // Normally GraphicsContext operations do nothing when painting is disabled. 624 // Normally GraphicsContext operations do nothing when painting is disabled.
618 // Since we're accessing platformContext() directly we have to manually 625 // Since we're accessing platformContext() directly we have to manually
619 // check. 626 // check.
620 if (m_webMediaPlayer && !context->paintingDisabled()) { 627 if (m_webMediaPlayer && !context->paintingDisabled()) {
621 PlatformGraphicsContext* platformContext = context->platformContext(); 628 PlatformGraphicsContext* platformContext = context->platformContext();
622 WebCanvas* canvas = platformContext->canvas(); 629 WebCanvas* canvas = platformContext->canvas();
630
631 // Go through the fast path trying to do a GPU-GPU texture copy without readback to system memory if possible.
632 // Otherwise, it will fallback to the normal SW path.
633 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get();
634 if (context3D && paintVideoTextureInContext(context, context3D.get()))
Ken Russell (switch to Gerrit) 2013/04/05 22:43:38 This is still wrong as it's discarding the incomin
635 return;
636
637 // Normal pure SW path
623 m_webMediaPlayer->paint(canvas, rect, platformContext->getNormalizedAlph a()); 638 m_webMediaPlayer->paint(canvas, rect, platformContext->getNormalizedAlph a());
624 } 639 }
625 } 640 }
626 641
627 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebCore::Graphi csContext3D* context, Platform3DObject texture, GC3Dint level, GC3Denum type, GC 3Denum internalFormat, bool premultiplyAlpha, bool flipY) 642 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebCore::Graphi csContext3D* context, Platform3DObject texture, GC3Dint level, GC3Denum type, GC 3Denum internalFormat, bool premultiplyAlpha, bool flipY)
628 { 643 {
629 if (!context || !m_webMediaPlayer) 644 if (!context || !m_webMediaPlayer)
630 return false; 645 return false;
631 Extensions3D* extensions = context->getExtensions(); 646 Extensions3D* extensions = context->getExtensions();
632 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy") || !context->makeContextCurrent()) 647 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy") || !context->makeContextCurrent())
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 case WebMimeRegistry::IsNotSupported: 774 case WebMimeRegistry::IsNotSupported:
760 return MediaPlayer::IsNotSupported; 775 return MediaPlayer::IsNotSupported;
761 case WebMimeRegistry::IsSupported: 776 case WebMimeRegistry::IsSupported:
762 return MediaPlayer::IsSupported; 777 return MediaPlayer::IsSupported;
763 case WebMimeRegistry::MayBeSupported: 778 case WebMimeRegistry::MayBeSupported:
764 return MediaPlayer::MayBeSupported; 779 return MediaPlayer::MayBeSupported;
765 } 780 }
766 return MediaPlayer::IsNotSupported; 781 return MediaPlayer::IsNotSupported;
767 } 782 }
768 783
784 bool WebMediaPlayerClientImpl::paintVideoTextureInContext(WebCore::GraphicsConte xt* context, WebCore::GraphicsContext3D* context3D)
Ken Russell (switch to Gerrit) 2013/04/05 22:43:38 Either this needs to be made to work correctly on
785 {
786 if (!context || !m_webMediaPlayer || context->paintingDisabled())
787 return false;
788
789 Extensions3D* extensions = context3D->getExtensions();
790 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy")
791 || !context3D->makeContextCurrent())
792 return false;
793
794 WebGraphicsContext3D* webGraphicsContext3D = GraphicsContext3DPrivate::extra ctWebGraphicsContext3D(context3D);
795 PlatformGraphicsContext* platformContext = context->platformContext();
796 WebCanvas* canvas = platformContext->canvas();
797
798 // Create a temporary RGBA texture based SkBitmap where the video will be co pied into.
799 // The bitmap's size is the same as the video.
800 unsigned int videoWidth = naturalSize().width();
801 unsigned int videoHeight = naturalSize().height();
802 GrTextureDesc desc;
803 desc.fConfig = kSkia8888_GrPixelConfig;
804 desc.fWidth = videoWidth;
805 desc.fHeight = videoHeight;
806 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
807 desc.fFlags = (kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit) ;
808 GrContext* ct = context3D->grContext();
809 if (!ct)
810 return false;
811 SkAutoTUnref<GrTexture> texture(ct->createUncachedTexture(desc, NULL, 0));
812 if (!texture.get())
813 return false;
814 unsigned int textureId = static_cast<unsigned int>(texture->getTextureHandle ());
815
816 // Copy video texture to bitmap texture.
817 if (!m_webMediaPlayer->copyVideoTextureToPlatformTexture(webGraphicsContext3 D, textureId, 0, GraphicsContext3D::RGBA, true, false)) { return false; }
818
819 SkBitmap bitmap;
820 bitmap.setConfig(SkBitmap::kARGB_8888_Config, videoWidth, videoHeight);
821 bitmap.setPixelRef(new SkGrPixelRef(texture))->unref();
822
823 // Draw the texture based bitmap onto the Canvas. If the canvas is hardware based, this will do a GPU-GPU texture copy. If the canvas is software based,
824 // the texture based bitmap will be readbacked to system memory then draw on to the canvas.
825 canvas->drawBitmap(bitmap, 0, 0);
826 return true;
827 }
828
769 void WebMediaPlayerClientImpl::startDelayedLoad() 829 void WebMediaPlayerClientImpl::startDelayedLoad()
770 { 830 {
771 ASSERT(m_delayingLoad); 831 ASSERT(m_delayingLoad);
772 ASSERT(!m_webMediaPlayer); 832 ASSERT(!m_webMediaPlayer);
773 833
774 m_delayingLoad = false; 834 m_delayingLoad = false;
775 835
776 loadInternal(); 836 loadInternal();
777 } 837 }
778 838
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 { 889 {
830 if (m_client) 890 if (m_client)
831 m_client->setFormat(numberOfChannels, sampleRate); 891 m_client->setFormat(numberOfChannels, sampleRate);
832 } 892 }
833 893
834 #endif 894 #endif
835 895
836 } // namespace WebKit 896 } // namespace WebKit
837 897
838 #endif // ENABLE(VIDEO) 898 #endif // ENABLE(VIDEO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698