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

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 Ken'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"
(...skipping 22 matching lines...) Expand all
33 #include <public/Platform.h> 33 #include <public/Platform.h>
34 #include <public/WebCString.h> 34 #include <public/WebCString.h>
35 #include <public/WebCanvas.h> 35 #include <public/WebCanvas.h>
36 #include <public/WebCompositorSupport.h> 36 #include <public/WebCompositorSupport.h>
37 #include <public/WebMimeRegistry.h> 37 #include <public/WebMimeRegistry.h>
38 #include <public/WebRect.h> 38 #include <public/WebRect.h>
39 #include <public/WebSize.h> 39 #include <public/WebSize.h>
40 #include <public/WebString.h> 40 #include <public/WebString.h>
41 #include <public/WebURL.h> 41 #include <public/WebURL.h>
42 42
43 #if defined(OS_ANDROID)
44 #include "GrContext.h"
45 #include "GrTexture.h"
46 #include "GrTypes.h"
47 #include "SkCanvas.h"
48 #include "SkGrPixelRef.h"
49 #endif
50
43 #if USE(ACCELERATED_COMPOSITING) 51 #if USE(ACCELERATED_COMPOSITING)
44 #include "RenderLayerCompositor.h" 52 #include "RenderLayerCompositor.h"
45 #endif 53 #endif
46 54
47 #include <wtf/Assertions.h> 55 #include <wtf/Assertions.h>
48 #include <wtf/text/CString.h> 56 #include <wtf/text/CString.h>
49 57
50 using namespace WebCore; 58 using namespace WebCore;
51 59
52 namespace WebKit { 60 namespace WebKit {
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 paintCurrentFrameInContext(context, rect); 620 paintCurrentFrameInContext(context, rect);
613 } 621 }
614 622
615 void WebMediaPlayerClientImpl::paintCurrentFrameInContext(GraphicsContext* conte xt, const IntRect& rect) 623 void WebMediaPlayerClientImpl::paintCurrentFrameInContext(GraphicsContext* conte xt, const IntRect& rect)
616 { 624 {
617 // Normally GraphicsContext operations do nothing when painting is disabled. 625 // Normally GraphicsContext operations do nothing when painting is disabled.
618 // Since we're accessing platformContext() directly we have to manually 626 // Since we're accessing platformContext() directly we have to manually
619 // check. 627 // check.
620 if (m_webMediaPlayer && !context->paintingDisabled()) { 628 if (m_webMediaPlayer && !context->paintingDisabled()) {
621 PlatformGraphicsContext* platformContext = context->platformContext(); 629 PlatformGraphicsContext* platformContext = context->platformContext();
630
631 // On Android, video frame is emitted as GL_TEXTURE_EXTERNAL_OES texture . We use a different path to
632 // paint the video frame into the context.
633 #if defined(OS_ANDROID)
634 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get();
635 paintOnAndroid(context, context3D.get(), rect, platformContext->getNorma lizedAlpha());
636 #else
622 WebCanvas* canvas = platformContext->canvas(); 637 WebCanvas* canvas = platformContext->canvas();
623 m_webMediaPlayer->paint(canvas, rect, platformContext->getNormalizedAlph a()); 638 m_webMediaPlayer->paint(canvas, rect, platformContext->getNormalizedAlph a());
639 #endif
624 } 640 }
625 } 641 }
626 642
627 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebCore::Graphi csContext3D* context, Platform3DObject texture, GC3Dint level, GC3Denum type, GC 3Denum internalFormat, bool premultiplyAlpha, bool flipY) 643 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebCore::Graphi csContext3D* context, Platform3DObject texture, GC3Dint level, GC3Denum type, GC 3Denum internalFormat, bool premultiplyAlpha, bool flipY)
628 { 644 {
629 if (!context || !m_webMediaPlayer) 645 if (!context || !m_webMediaPlayer)
630 return false; 646 return false;
631 Extensions3D* extensions = context->getExtensions(); 647 Extensions3D* extensions = context->getExtensions();
632 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy") || !context->makeContextCurrent()) 648 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy") || !context->makeContextCurrent())
633 return false; 649 return false;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 case WebMimeRegistry::IsNotSupported: 775 case WebMimeRegistry::IsNotSupported:
760 return MediaPlayer::IsNotSupported; 776 return MediaPlayer::IsNotSupported;
761 case WebMimeRegistry::IsSupported: 777 case WebMimeRegistry::IsSupported:
762 return MediaPlayer::IsSupported; 778 return MediaPlayer::IsSupported;
763 case WebMimeRegistry::MayBeSupported: 779 case WebMimeRegistry::MayBeSupported:
764 return MediaPlayer::MayBeSupported; 780 return MediaPlayer::MayBeSupported;
765 } 781 }
766 return MediaPlayer::IsNotSupported; 782 return MediaPlayer::IsNotSupported;
767 } 783 }
768 784
785 #if defined(OS_ANDROID)
786 void WebMediaPlayerClientImpl::paintOnAndroid(WebCore::GraphicsContext* context, WebCore::GraphicsContext3D* context3D, const IntRect& rect, uint8_t alpha)
787 {
788 if (!context || !context3D || !m_webMediaPlayer || context->paintingDisabled ())
789 return;
790
791 Extensions3D* extensions = context3D->getExtensions();
792 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy")
793 || !context3D->makeContextCurrent())
794 return;
795
796 // Copy video texture into a RGBA texture based bitmap first as video textur e on Android is GL_TEXTURE_EXTERNAL_OES
797 // which is not supported by Skia yet. The bitmap's size needs to be the sam e as the video.
798 int videoWidth = naturalSize().width();
799 int videoHeight = naturalSize().height();
800
801 // Check if we could reuse existing texture based bitmap.
802 // Otherwise, release existing texture based bitmap and allocate a new one b ased on video size.
803 if (videoWidth != m_bitmap.width() || videoHeight != m_bitmap.height() || !m _texture.get()) {
804 GrTextureDesc desc;
805 desc.fConfig = kSkia8888_GrPixelConfig;
806 desc.fWidth = videoWidth;
807 desc.fHeight = videoHeight;
808 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
809 desc.fFlags = (kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlag Bit);
810 GrContext* ct = context3D->grContext();
811 if (!ct)
812 return;
813 m_texture.reset(ct->createUncachedTexture(desc, NULL, 0));
814 if (!m_texture.get())
815 return;
816 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, videoWidth, videoHeight) ;
817 m_bitmap.setPixelRef(new SkGrPixelRef(m_texture))->unref();
818 }
819
820 // Copy video texture to bitmap texture.
821 WebGraphicsContext3D* webGraphicsContext3D = GraphicsContext3DPrivate::extra ctWebGraphicsContext3D(context3D);
822 PlatformGraphicsContext* platformContext = context->platformContext();
823 WebCanvas* canvas = platformContext->canvas();
824 unsigned int textureId = static_cast<unsigned int>(m_texture->getTextureHand le());
825 if (!m_webMediaPlayer->copyVideoTextureToPlatformTexture(webGraphicsContext3 D, textureId, 0, GraphicsContext3D::RGBA, true, false)) { return; }
826
827 // 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,
828 // the texture based bitmap will be readbacked to system memory then draw on to the canvas.
829 SkRect dest;
830 dest.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height ());
831 SkPaint paint;
832 paint.setAlpha(alpha);
833 canvas->drawBitmapRect(m_bitmap, NULL, dest, &paint);
834 }
835 #endif
836
769 void WebMediaPlayerClientImpl::startDelayedLoad() 837 void WebMediaPlayerClientImpl::startDelayedLoad()
770 { 838 {
771 ASSERT(m_delayingLoad); 839 ASSERT(m_delayingLoad);
772 ASSERT(!m_webMediaPlayer); 840 ASSERT(!m_webMediaPlayer);
773 841
774 m_delayingLoad = false; 842 m_delayingLoad = false;
775 843
776 loadInternal(); 844 loadInternal();
777 } 845 }
778 846
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 { 897 {
830 if (m_client) 898 if (m_client)
831 m_client->setFormat(numberOfChannels, sampleRate); 899 m_client->setFormat(numberOfChannels, sampleRate);
832 } 900 }
833 901
834 #endif 902 #endif
835 903
836 } // namespace WebKit 904 } // namespace WebKit
837 905
838 #endif // ENABLE(VIDEO) 906 #endif // ENABLE(VIDEO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698