Chromium Code Reviews| 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" |
| 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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); |
| 623 m_webMediaPlayer->paint(canvas, rect, platformContext->getNormalizedAlph a()); | 630 m_webMediaPlayer->paint(canvas, rect, platformContext->getNormalizedAlph a()); |
| 624 } | 631 } |
| 625 } | 632 } |
| 626 | 633 |
| 634 bool WebMediaPlayerClientImpl::copyVideoTextureToCanvas(WebCore::GraphicsContext * context, WebCore::GraphicsContext3D* context3D) | |
|
qinmin
2013/04/05 17:30:28
why this function takes a GraphicsContext param in
| |
| 635 { | |
| 636 if (!context || !context3D || !m_webMediaPlayer || context->paintingDisabled ()) | |
| 637 return false; | |
| 638 | |
| 639 Extensions3D* extensions = context3D->getExtensions(); | |
| 640 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy") | |
| 641 || !context3D->makeContextCurrent()) | |
| 642 return false; | |
| 643 | |
| 644 WebGraphicsContext3D* webGraphicsContext3D = GraphicsContext3DPrivate::extra ctWebGraphicsContext3D(context3D); | |
| 645 PlatformGraphicsContext* platformContext = context->platformContext(); | |
| 646 WebCanvas* canvas = platformContext->canvas(); | |
| 647 | |
| 648 // Create a temporary RGBA texture based SkBitmap where the video will be co pied into. | |
| 649 // The bitmap's size is the same as the video. | |
| 650 unsigned int videoWidth = naturalSize().width(), videoHeight = naturalSize() .height(); | |
|
qinmin
2013/04/05 17:30:28
split it into multiple lines.
| |
| 651 GrTextureDesc desc; | |
| 652 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 653 desc.fWidth = videoWidth; | |
| 654 desc.fHeight = videoHeight; | |
| 655 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 656 desc.fFlags = (kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit) ; | |
| 657 GrContext* ct = context3D->grContext(); | |
| 658 if (!ct) | |
| 659 return false; | |
| 660 SkAutoTUnref<GrTexture> texture(ct->createUncachedTexture(desc, NULL, 0)); | |
|
Ken Russell (switch to Gerrit)
2013/04/05 22:40:38
If this is the code structure you want, then shoul
| |
| 661 if (!texture.get()) | |
| 662 return false; | |
| 663 unsigned int textureId = static_cast<unsigned int>(texture->getTextureHandle ()); | |
| 664 | |
| 665 // Copy video texture to bitmap texture. | |
| 666 if (!m_webMediaPlayer->copyVideoTextureToPlatformTexture(webGraphicsContext3 D, textureId, 0, GraphicsContext3D::RGBA, true, false)) { | |
|
qinmin
2013/04/05 17:30:28
no { for if statement with only 1 lines
| |
| 667 return false; | |
| 668 } | |
| 669 | |
| 670 SkBitmap bitmap; | |
| 671 bitmap.setConfig(SkBitmap::kARGB_8888_Config, videoWidth, videoHeight); | |
| 672 bitmap.setPixelRef(new SkGrPixelRef(texture))->unref(); | |
| 673 | |
| 674 // 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, | |
|
scherkus (not reviewing)
2013/04/05 20:47:09
do we have GPU-based canvas implementations yet?
hkuang
2013/04/09 17:46:10
The SkCanvas will be software based when the size
| |
| 675 // the texture based bitmap will be readbacked to system memory then draw on to the canvas. | |
| 676 canvas->drawBitmap(bitmap, 0, 0); | |
|
Ken Russell (switch to Gerrit)
2013/04/05 22:40:38
This can't be correct. The destRect argument from
| |
| 677 return true; | |
| 678 } | |
| 679 | |
| 627 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebCore::Graphi csContext3D* context, Platform3DObject texture, GC3Dint level, GC3Denum type, GC 3Denum internalFormat, bool premultiplyAlpha, bool flipY) | 680 bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebCore::Graphi csContext3D* context, Platform3DObject texture, GC3Dint level, GC3Denum type, GC 3Denum internalFormat, bool premultiplyAlpha, bool flipY) |
| 628 { | 681 { |
| 629 if (!context || !m_webMediaPlayer) | 682 if (!context || !m_webMediaPlayer) |
| 630 return false; | 683 return false; |
| 631 Extensions3D* extensions = context->getExtensions(); | 684 Extensions3D* extensions = context->getExtensions(); |
| 632 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy") || !context->makeContextCurrent()) | 685 if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !ext ensions->supports("GL_CHROMIUM_flipy") || !context->makeContextCurrent()) |
| 633 return false; | 686 return false; |
| 634 WebGraphicsContext3D* webGraphicsContext3D = GraphicsContext3DPrivate::extra ctWebGraphicsContext3D(context); | 687 WebGraphicsContext3D* webGraphicsContext3D = GraphicsContext3DPrivate::extra ctWebGraphicsContext3D(context); |
| 635 return m_webMediaPlayer->copyVideoTextureToPlatformTexture(webGraphicsContex t3D, texture, level, internalFormat, premultiplyAlpha, flipY); | 688 return m_webMediaPlayer->copyVideoTextureToPlatformTexture(webGraphicsContex t3D, texture, level, internalFormat, premultiplyAlpha, flipY); |
| 636 } | 689 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 { | 882 { |
| 830 if (m_client) | 883 if (m_client) |
| 831 m_client->setFormat(numberOfChannels, sampleRate); | 884 m_client->setFormat(numberOfChannels, sampleRate); |
| 832 } | 885 } |
| 833 | 886 |
| 834 #endif | 887 #endif |
| 835 | 888 |
| 836 } // namespace WebKit | 889 } // namespace WebKit |
| 837 | 890 |
| 838 #endif // ENABLE(VIDEO) | 891 #endif // ENABLE(VIDEO) |
| OLD | NEW |