Index: Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp |
diff --git a/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp b/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp |
index bc77af2f52cea64dd2e96a9b7a44d614c3c19777..9c757f3a1515916e118d3fb01af77071e2f91f86 100644 |
--- a/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp |
+++ b/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp |
@@ -14,6 +14,9 @@ |
#include "GraphicsContext.h" |
#include "GraphicsContext3DPrivate.h" |
#include "GraphicsLayerChromium.h" |
+#include "GrContext.h" |
+#include "GrTexture.h" |
+#include "GrTypes.h" |
#include "HTMLMediaElement.h" |
#include "IntSize.h" |
#include "KURL.h" |
@@ -21,6 +24,10 @@ |
#include "NotImplemented.h" |
#include "PlatformContextSkia.h" |
#include "RenderView.h" |
+#include "SkRefCnt.h" |
+#include "SkBitmap.h" |
+#include "SkCanvas.h" |
+#include "SkGrPixelRef.h" |
#include "TimeRanges.h" |
#include "WebAudioSourceProvider.h" |
#include "WebDocument.h" |
@@ -620,6 +627,14 @@ void WebMediaPlayerClientImpl::paintCurrentFrameInContext(GraphicsContext* conte |
if (m_webMediaPlayer && !context->paintingDisabled()) { |
PlatformGraphicsContext* platformContext = context->platformContext(); |
WebCanvas* canvas = platformContext->canvas(); |
+ |
+ // Go through the fast path trying to do a GPU-GPU texture copy without readback to system memory if possible. |
+ // Otherwise, it will fallback to the normal SW path. |
+ RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); |
+ 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
|
+ return; |
+ |
+ // Normal pure SW path |
m_webMediaPlayer->paint(canvas, rect, platformContext->getNormalizedAlpha()); |
} |
} |
@@ -766,6 +781,51 @@ MediaPlayer::SupportsType WebMediaPlayerClientImpl::supportsType(const String& t |
return MediaPlayer::IsNotSupported; |
} |
+bool WebMediaPlayerClientImpl::paintVideoTextureInContext(WebCore::GraphicsContext* 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
|
+{ |
+ if (!context || !m_webMediaPlayer || context->paintingDisabled()) |
+ return false; |
+ |
+ Extensions3D* extensions = context3D->getExtensions(); |
+ if (!extensions || !extensions->supports("GL_CHROMIUM_copy_texture") || !extensions->supports("GL_CHROMIUM_flipy") |
+ || !context3D->makeContextCurrent()) |
+ return false; |
+ |
+ WebGraphicsContext3D* webGraphicsContext3D = GraphicsContext3DPrivate::extractWebGraphicsContext3D(context3D); |
+ PlatformGraphicsContext* platformContext = context->platformContext(); |
+ WebCanvas* canvas = platformContext->canvas(); |
+ |
+ // Create a temporary RGBA texture based SkBitmap where the video will be copied into. |
+ // The bitmap's size is the same as the video. |
+ unsigned int videoWidth = naturalSize().width(); |
+ unsigned int videoHeight = naturalSize().height(); |
+ GrTextureDesc desc; |
+ desc.fConfig = kSkia8888_GrPixelConfig; |
+ desc.fWidth = videoWidth; |
+ desc.fHeight = videoHeight; |
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
+ desc.fFlags = (kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit); |
+ GrContext* ct = context3D->grContext(); |
+ if (!ct) |
+ return false; |
+ SkAutoTUnref<GrTexture> texture(ct->createUncachedTexture(desc, NULL, 0)); |
+ if (!texture.get()) |
+ return false; |
+ unsigned int textureId = static_cast<unsigned int>(texture->getTextureHandle()); |
+ |
+ // Copy video texture to bitmap texture. |
+ if (!m_webMediaPlayer->copyVideoTextureToPlatformTexture(webGraphicsContext3D, textureId, 0, GraphicsContext3D::RGBA, true, false)) { return false; } |
+ |
+ SkBitmap bitmap; |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, videoWidth, videoHeight); |
+ bitmap.setPixelRef(new SkGrPixelRef(texture))->unref(); |
+ |
+ // 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, |
+ // the texture based bitmap will be readbacked to system memory then draw onto the canvas. |
+ canvas->drawBitmap(bitmap, 0, 0); |
+ return true; |
+} |
+ |
void WebMediaPlayerClientImpl::startDelayedLoad() |
{ |
ASSERT(m_delayingLoad); |