OLD | NEW |
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 Loading... |
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 "GrTypes.h" |
| 46 #include "SkCanvas.h" |
| 47 #include "SkGrPixelRef.h" |
| 48 #include "SharedGraphicsContext3D.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 Loading... |
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 Loading... |
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 // It is not necessary to pass the dest into the drawBitmap call since all t
he context have been set up before calling paintCurrentFrameInContext. |
| 834 canvas->drawBitmapRect(m_bitmap, NULL, dest, &paint); |
| 835 } |
| 836 #endif |
| 837 |
769 void WebMediaPlayerClientImpl::startDelayedLoad() | 838 void WebMediaPlayerClientImpl::startDelayedLoad() |
770 { | 839 { |
771 ASSERT(m_delayingLoad); | 840 ASSERT(m_delayingLoad); |
772 ASSERT(!m_webMediaPlayer); | 841 ASSERT(!m_webMediaPlayer); |
773 | 842 |
774 m_delayingLoad = false; | 843 m_delayingLoad = false; |
775 | 844 |
776 loadInternal(); | 845 loadInternal(); |
777 } | 846 } |
778 | 847 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 { | 898 { |
830 if (m_client) | 899 if (m_client) |
831 m_client->setFormat(numberOfChannels, sampleRate); | 900 m_client->setFormat(numberOfChannels, sampleRate); |
832 } | 901 } |
833 | 902 |
834 #endif | 903 #endif |
835 | 904 |
836 } // namespace WebKit | 905 } // namespace WebKit |
837 | 906 |
838 #endif // ENABLE(VIDEO) | 907 #endif // ENABLE(VIDEO) |
OLD | NEW |