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..48f49d2250727666ff378121da254e09e2a64ba5 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" |
@@ -624,6 +631,52 @@ void WebMediaPlayerClientImpl::paintCurrentFrameInContext(GraphicsContext* conte |
} |
} |
+bool WebMediaPlayerClientImpl::copyVideoTextureToCanvas(WebCore::GraphicsContext* context, WebCore::GraphicsContext3D* context3D) |
qinmin
2013/04/05 17:30:28
why this function takes a GraphicsContext param in
|
+{ |
+ if (!context || !context3D || !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(), videoHeight = naturalSize().height(); |
qinmin
2013/04/05 17:30:28
split it into multiple lines.
|
+ 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)); |
Ken Russell (switch to Gerrit)
2013/04/05 22:40:38
If this is the code structure you want, then shoul
|
+ 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)) { |
qinmin
2013/04/05 17:30:28
no { for if statement with only 1 lines
|
+ 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, |
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
|
+ // the texture based bitmap will be readbacked to system memory then draw onto the canvas. |
+ 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
|
+ return true; |
+} |
+ |
bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebCore::GraphicsContext3D* context, Platform3DObject texture, GC3Dint level, GC3Denum type, GC3Denum internalFormat, bool premultiplyAlpha, bool flipY) |
{ |
if (!context || !m_webMediaPlayer) |