Title: [108675] trunk/Source
Revision
108675
Author
[email protected]
Date
2012-02-23 14:10:02 -0800 (Thu, 23 Feb 2012)

Log Message

[Chromium] Add video stream texture support
https://bugs.webkit.org/show_bug.cgi?id=78398

This upstreams the abstraction used on Android for
hardware video decoding with the compositor.

Most of the interfaces are kept generic and the core
of this change is to allow texturing from an external
texture while receiving notifications (on the compositor
thread if we are running it) when there are new frames to
be displayed.

Patch by Daniel Sievers <[email protected]> on 2012-02-23
Reviewed by James Robinson.

Source/WebCore:

* platform/graphics/chromium/Extensions3DChromium.h:
* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::drawSingleTextureVideoQuad):
(WebCore::LayerRendererChromium::drawRGBA):
(WebCore::LayerRendererChromium::drawNativeTexture):
(WebCore):
(WebCore::LayerRendererChromium::drawStreamTexture):
(WebCore::LayerRendererChromium::drawVideoQuad):
(WebCore::LayerRendererChromium::streamTextureLayerProgram):
(WebCore::LayerRendererChromium::cleanupSharedObjects):
* platform/graphics/chromium/LayerRendererChromium.h:
(LayerRendererChromium):
* platform/graphics/chromium/ShaderChromium.cpp:
(WebCore::VertexShaderVideoTransform::VertexShaderVideoTransform):
(WebCore):
(WebCore::VertexShaderVideoTransform::init):
(WebCore::VertexShaderVideoTransform::getShaderString):
(WebCore::FragmentShaderOESImageExternal::init):
(WebCore::FragmentShaderOESImageExternal::getShaderString):
* platform/graphics/chromium/ShaderChromium.h:
(VertexShaderVideoTransform):
(WebCore::VertexShaderVideoTransform::matrixLocation):
(WebCore::VertexShaderVideoTransform::texTransformLocation):
(WebCore::VertexShaderVideoTransform::texMatrixLocation):
(WebCore):
(FragmentShaderOESImageExternal):
* platform/graphics/chromium/VideoFrameChromium.h:
* platform/graphics/chromium/VideoFrameProvider.h:
(Client):
(VideoFrameProvider):
* platform/graphics/chromium/cc/CCVideoDrawQuad.cpp:
(WebCore::CCVideoDrawQuad::CCVideoDrawQuad):
* platform/graphics/chromium/cc/CCVideoDrawQuad.h:
(WebCore::CCVideoDrawQuad::matrix):
(CCVideoDrawQuad):
(WebCore::CCVideoDrawQuad::setMatrix):
* platform/graphics/chromium/cc/CCVideoLayerImpl.cpp:
(WebCore):
(WebCore::CCVideoLayerImpl::CCVideoLayerImpl):
(WebCore::convertVFCFormatToGC3DFormat):
(WebCore::CCVideoLayerImpl::appendQuads):
(WebCore::CCVideoLayerImpl::didReceiveFrame):
(WebCore::CCVideoLayerImpl::didUpdateMatrix):
(WebCore::CCVideoLayerImpl::setNeedsRedraw):
* platform/graphics/chromium/cc/CCVideoLayerImpl.h:
(WebCore):
(CCVideoLayerImpl):

Source/WebKit/chromium:

* WebKit.gyp:
* public/WebMediaPlayer.h:
(WebKit):
(WebKit::WebMediaPlayer::setStreamTextureClient):
(WebMediaPlayer):
* public/WebStreamTextureClient.h: Copied from Source/WebKit/chromium/public/WebVideoFrame.h.
(WebKit):
(WebStreamTextureClient):
(WebKit::WebStreamTextureClient::~WebStreamTextureClient):
* public/WebVideoFrame.h:
* src/WebMediaPlayerClientImpl.cpp:
(WebKit::WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl):
(WebKit::WebMediaPlayerClientImpl::setVideoFrameProviderClient):
(WebKit::WebMediaPlayerClientImpl::didReceiveFrame):
(WebKit):
(WebKit::WebMediaPlayerClientImpl::didUpdateMatrix):
* src/WebMediaPlayerClientImpl.h:
(WebMediaPlayerClientImpl):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (108674 => 108675)


--- trunk/Source/WebCore/ChangeLog	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/ChangeLog	2012-02-23 22:10:02 UTC (rev 108675)
@@ -1,3 +1,67 @@
+2012-02-23  Daniel Sievers  <[email protected]>
+
+        [Chromium] Add video stream texture support
+        https://bugs.webkit.org/show_bug.cgi?id=78398
+
+        This upstreams the abstraction used on Android for
+        hardware video decoding with the compositor.
+
+        Most of the interfaces are kept generic and the core
+        of this change is to allow texturing from an external
+        texture while receiving notifications (on the compositor
+        thread if we are running it) when there are new frames to
+        be displayed.
+
+        Reviewed by James Robinson.
+
+        * platform/graphics/chromium/Extensions3DChromium.h:
+        * platform/graphics/chromium/LayerRendererChromium.cpp:
+        (WebCore::LayerRendererChromium::drawSingleTextureVideoQuad):
+        (WebCore::LayerRendererChromium::drawRGBA):
+        (WebCore::LayerRendererChromium::drawNativeTexture):
+        (WebCore):
+        (WebCore::LayerRendererChromium::drawStreamTexture):
+        (WebCore::LayerRendererChromium::drawVideoQuad):
+        (WebCore::LayerRendererChromium::streamTextureLayerProgram):
+        (WebCore::LayerRendererChromium::cleanupSharedObjects):
+        * platform/graphics/chromium/LayerRendererChromium.h:
+        (LayerRendererChromium):
+        * platform/graphics/chromium/ShaderChromium.cpp:
+        (WebCore::VertexShaderVideoTransform::VertexShaderVideoTransform):
+        (WebCore):
+        (WebCore::VertexShaderVideoTransform::init):
+        (WebCore::VertexShaderVideoTransform::getShaderString):
+        (WebCore::FragmentShaderOESImageExternal::init):
+        (WebCore::FragmentShaderOESImageExternal::getShaderString):
+        * platform/graphics/chromium/ShaderChromium.h:
+        (VertexShaderVideoTransform):
+        (WebCore::VertexShaderVideoTransform::matrixLocation):
+        (WebCore::VertexShaderVideoTransform::texTransformLocation):
+        (WebCore::VertexShaderVideoTransform::texMatrixLocation):
+        (WebCore):
+        (FragmentShaderOESImageExternal):
+        * platform/graphics/chromium/VideoFrameChromium.h:
+        * platform/graphics/chromium/VideoFrameProvider.h:
+        (Client):
+        (VideoFrameProvider):
+        * platform/graphics/chromium/cc/CCVideoDrawQuad.cpp:
+        (WebCore::CCVideoDrawQuad::CCVideoDrawQuad):
+        * platform/graphics/chromium/cc/CCVideoDrawQuad.h:
+        (WebCore::CCVideoDrawQuad::matrix):
+        (CCVideoDrawQuad):
+        (WebCore::CCVideoDrawQuad::setMatrix):
+        * platform/graphics/chromium/cc/CCVideoLayerImpl.cpp:
+        (WebCore):
+        (WebCore::CCVideoLayerImpl::CCVideoLayerImpl):
+        (WebCore::convertVFCFormatToGC3DFormat):
+        (WebCore::CCVideoLayerImpl::appendQuads):
+        (WebCore::CCVideoLayerImpl::didReceiveFrame):
+        (WebCore::CCVideoLayerImpl::didUpdateMatrix):
+        (WebCore::CCVideoLayerImpl::setNeedsRedraw):
+        * platform/graphics/chromium/cc/CCVideoLayerImpl.h:
+        (WebCore):
+        (CCVideoLayerImpl):
+
 2012-02-23  Stephen White  <[email protected]>
 
         [chromium] Implement drop-shadow() CSS filter on composited layers.

Modified: trunk/Source/WebCore/platform/graphics/chromium/Extensions3DChromium.h (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/Extensions3DChromium.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/Extensions3DChromium.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -63,6 +63,9 @@
     virtual String getTranslatedShaderSourceANGLE(Platform3DObject);
 
     enum {
+        // GL_OES_EGL_image_external
+        GL_TEXTURE_EXTERNAL_OES = 0x8D65,
+
         // GL_CHROMIUM_map_sub (enums inherited from GL_ARB_vertex_buffer_object)
         READ_ONLY = 0x88B8,
         WRITE_ONLY = 0x88B9,

Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp	2012-02-23 22:10:02 UTC (rev 108675)
@@ -736,12 +736,12 @@
 }
 
 template<class Program>
-void LayerRendererChromium::drawSingleTextureVideoQuad(const CCVideoDrawQuad* quad, Program* program, float widthScaleFactor, Platform3DObject textureId)
+void LayerRendererChromium::drawSingleTextureVideoQuad(const CCVideoDrawQuad* quad, Program* program, float widthScaleFactor, Platform3DObject textureId, GC3Denum target)
 {
     ASSERT(program && program->initialized());
 
     GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0));
-    GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
+    GLC(context(), context()->bindTexture(target, textureId));
 
     GLC(context(), context()->useProgram(program->program()));
     GLC(context(), context()->uniform4f(program->vertexShader().texTransformLocation(), 0, 0, widthScaleFactor, 1));
@@ -759,15 +759,27 @@
     const CCVideoLayerImpl::RGBAProgram* program = videoLayerRGBAProgram();
     const CCVideoLayerImpl::Texture& texture = quad->textures()[VideoFrameChromium::rgbPlane];
     float widthScaleFactor = static_cast<float>(texture.m_visibleSize.width()) / texture.m_texture->size().width();
-    drawSingleTextureVideoQuad(quad, program, widthScaleFactor, texture.m_texture->textureId());
+    drawSingleTextureVideoQuad(quad, program, widthScaleFactor, texture.m_texture->textureId(), GraphicsContext3D::TEXTURE_2D);
 }
 
-void LayerRendererChromium::drawNativeTexture(const CCVideoDrawQuad* quad)
+void LayerRendererChromium::drawNativeTexture2D(const CCVideoDrawQuad* quad)
 {
     const CCVideoLayerImpl::NativeTextureProgram* program = videoLayerNativeTextureProgram();
-    drawSingleTextureVideoQuad(quad, program, 1, quad->frame()->textureId());
+    drawSingleTextureVideoQuad(quad, program, 1, quad->frame()->textureId(), GraphicsContext3D::TEXTURE_2D);
 }
 
+void LayerRendererChromium::drawStreamTexture(const CCVideoDrawQuad* quad)
+{
+    ASSERT(context()->getExtensions()->supports("GL_OES_EGL_image_external") && context()->getExtensions()->isEnabled("GL_OES_EGL_image_external"));
+
+    const CCVideoLayerImpl::StreamTextureProgram* program = streamTextureLayerProgram();
+    GLC(context(), context()->useProgram(program->program()));
+    ASSERT(quad->matrix());
+    GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrixLocation(), false, const_cast<float*>(quad->matrix()), 1));
+
+    drawSingleTextureVideoQuad(quad, program, 1, quad->frame()->textureId(), Extensions3DChromium::GL_TEXTURE_EXTERNAL_OES);
+}
+
 bool LayerRendererChromium::copyFrameToTextures(const CCVideoDrawQuad* quad)
 {
     const VideoFrameChromium* frame = quad->frame();
@@ -822,8 +834,11 @@
         drawRGBA(quad);
         break;
     case GraphicsContext3D::TEXTURE_2D:
-        drawNativeTexture(quad);
+        drawNativeTexture2D(quad);
         break;
+    case Extensions3DChromium::GL_TEXTURE_EXTERNAL_OES:
+        drawStreamTexture(quad);
+        break;
     default:
         CRASH(); // Someone updated convertVFCFormatToGC3DFormat above but update this!
     }
@@ -1384,6 +1399,16 @@
     return m_videoLayerNativeTextureProgram.get();
 }
 
+const CCVideoLayerImpl::StreamTextureProgram* LayerRendererChromium::streamTextureLayerProgram()
+{
+    if (!m_streamTextureLayerProgram)
+        m_streamTextureLayerProgram = adoptPtr(new CCVideoLayerImpl::StreamTextureProgram(m_context.get()));
+    if (!m_streamTextureLayerProgram->initialized()) {
+        TRACE_EVENT("LayerRendererChromium::streamTextureLayerProgram::initialize", this, 0);
+        m_streamTextureLayerProgram->initialize(m_context.get());
+    }
+    return m_streamTextureLayerProgram.get();
+}
 
 void LayerRendererChromium::cleanupSharedObjects()
 {
@@ -1425,6 +1450,8 @@
         m_videoLayerRGBAProgram->cleanup(m_context.get());
     if (m_videoLayerYUVProgram)
         m_videoLayerYUVProgram->cleanup(m_context.get());
+    if (m_streamTextureLayerProgram)
+        m_streamTextureLayerProgram->cleanup(m_context.get());
 
     m_borderProgram.clear();
     m_headsUpDisplayProgram.clear();
@@ -1443,6 +1470,7 @@
     m_renderSurfaceProgramAA.clear();
     m_videoLayerRGBAProgram.clear();
     m_videoLayerYUVProgram.clear();
+    m_streamTextureLayerProgram.clear();
     if (m_offscreenFramebufferId)
         GLC(m_context.get(), m_context->deleteFramebuffer(m_offscreenFramebufferId));
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -130,6 +130,7 @@
     const CCVideoLayerImpl::RGBAProgram* videoLayerRGBAProgram();
     const CCVideoLayerImpl::YUVProgram* videoLayerYUVProgram();
     const CCVideoLayerImpl::NativeTextureProgram* videoLayerNativeTextureProgram();
+    const CCVideoLayerImpl::StreamTextureProgram* streamTextureLayerProgram();
 
     void getFramebufferPixels(void *pixels, const IntRect&);
 
@@ -170,8 +171,9 @@
     ManagedTexture* getOffscreenLayerTexture();
     void copyPlaneToTexture(const CCVideoDrawQuad*, const void* plane, int index);
     bool copyFrameToTextures(const CCVideoDrawQuad*);
-    template<class Program> void drawSingleTextureVideoQuad(const CCVideoDrawQuad*, Program*, float widthScaleFactor, Platform3DObject textureId);
-    void drawNativeTexture(const CCVideoDrawQuad*);
+    template<class Program> void drawSingleTextureVideoQuad(const CCVideoDrawQuad*, Program*, float widthScaleFactor, Platform3DObject textureId, GC3Denum target);
+    void drawNativeTexture2D(const CCVideoDrawQuad*);
+    void drawStreamTexture(const CCVideoDrawQuad*);
     void drawRGBA(const CCVideoDrawQuad*);
     void drawYUV(const CCVideoDrawQuad*);
 
@@ -233,6 +235,7 @@
     OwnPtr<CCVideoLayerImpl::RGBAProgram> m_videoLayerRGBAProgram;
     OwnPtr<CCVideoLayerImpl::YUVProgram> m_videoLayerYUVProgram;
     OwnPtr<CCVideoLayerImpl::NativeTextureProgram> m_videoLayerNativeTextureProgram;
+    OwnPtr<CCVideoLayerImpl::StreamTextureProgram> m_streamTextureLayerProgram;
 
     OwnPtr<TextureManager> m_renderSurfaceTextureManager;
     OwnPtr<TrackingTextureAllocator> m_contentsTextureAllocator;

Modified: trunk/Source/WebCore/platform/graphics/chromium/ShaderChromium.cpp (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/ShaderChromium.cpp	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/ShaderChromium.cpp	2012-02-23 22:10:02 UTC (rev 108675)
@@ -255,6 +255,39 @@
     );
 }
 
+VertexShaderVideoTransform::VertexShaderVideoTransform()
+    : m_matrixLocation(-1)
+    , m_texTransformLocation(-1)
+    , m_texMatrixLocation(-1)
+{
+}
+
+bool VertexShaderVideoTransform::init(GraphicsContext3D* context, unsigned program)
+{
+    m_matrixLocation = context->getUniformLocation(program, "matrix");
+    m_texTransformLocation = context->getUniformLocation(program, "texTransform");
+    m_texMatrixLocation = context->getUniformLocation(program, "texMatrix");
+    return m_matrixLocation != -1 && m_texTransformLocation != -1 && m_texMatrixLocation != -1;
+}
+
+String VertexShaderVideoTransform::getShaderString() const
+{
+    return SHADER(
+        attribute vec4 a_position;
+        attribute vec2 a_texCoord;
+        uniform mat4 matrix;
+        uniform vec4 texTransform;
+        uniform mat4 texMatrix;
+        varying vec2 v_texCoord;
+        void main()
+        {
+            gl_Position = matrix * a_position;
+            vec2 texCoord = vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0));
+            v_texCoord = texCoord * texTransform.zw + texTransform.xy;
+        }
+    );
+}
+
 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
     : m_samplerLocation(-1)
     , m_alphaLocation(-1)
@@ -296,6 +329,27 @@
     );
 }
 
+bool FragmentShaderOESImageExternal::init(GraphicsContext3D* context, unsigned program)
+{
+    m_samplerLocation = context->getUniformLocation(program, "s_texture");
+
+    return m_samplerLocation != -1;
+}
+
+String FragmentShaderOESImageExternal::getShaderString() const
+{
+    // Cannot use the SHADER() macro because of the '#' char
+    return "#extension GL_OES_EGL_image_external : require \n"
+           "precision mediump float;\n"
+           "varying vec2 v_texCoord;\n"
+           "uniform samplerExternalOES s_texture;\n"
+           "void main()\n"
+           "{\n"
+           "    vec4 texColor = texture2D(s_texture, v_texCoord);\n"
+           "    gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w);\n"
+           "}\n";
+}
+
 String FragmentShaderRGBATexAlpha::getShaderString() const
 {
     return SHADER(

Modified: trunk/Source/WebCore/platform/graphics/chromium/ShaderChromium.h (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/ShaderChromium.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/ShaderChromium.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -145,6 +145,23 @@
     int m_vertexTexTransformLocation;
 };
 
+class VertexShaderVideoTransform {
+public:
+    VertexShaderVideoTransform();
+
+    bool init(GraphicsContext3D*, unsigned program);
+    String getShaderString() const;
+
+    int matrixLocation() const { return m_matrixLocation; }
+    int texTransformLocation() const { return m_texTransformLocation; }
+    int texMatrixLocation() const { return m_texMatrixLocation; }
+
+private:
+    int m_matrixLocation;
+    int m_texTransformLocation;
+    int m_texMatrixLocation;
+};
+
 class FragmentTexAlphaBinding {
 public:
     FragmentTexAlphaBinding();
@@ -211,6 +228,15 @@
     String getShaderString() const;
 };
 
+// Fragment shader for external textures.
+class FragmentShaderOESImageExternal : public FragmentTexAlphaBinding {
+public:
+    String getShaderString() const;
+    bool init(GraphicsContext3D*, unsigned program);
+private:
+    int m_samplerLocation;
+};
+
 class FragmentShaderRGBATexAlphaAA {
 public:
     FragmentShaderRGBATexAlphaAA();

Modified: trunk/Source/WebCore/platform/graphics/chromium/VideoFrameChromium.h (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/VideoFrameChromium.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/VideoFrameChromium.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -75,6 +75,7 @@
     virtual const IntSize requiredTextureSize(unsigned plane) const = 0;
     virtual bool hasPaddingBytes(unsigned plane) const = 0;
     virtual unsigned textureId() const = 0;
+    virtual unsigned textureTarget() const = 0;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/chromium/VideoFrameProvider.h (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/VideoFrameProvider.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/VideoFrameProvider.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -43,6 +43,8 @@
     public:
         // Provider will call this method to tell the client to stop using it.
         virtual void stopUsingProvider() = 0;
+        virtual void didReceiveFrame() = 0;
+        virtual void didUpdateMatrix(const float*) = 0;
     };
 
     virtual void setVideoFrameProviderClient(Client*) = 0;

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoDrawQuad.cpp (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoDrawQuad.cpp	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoDrawQuad.cpp	2012-02-23 22:10:02 UTC (rev 108675)
@@ -39,6 +39,7 @@
     , m_textures(textures)
     , m_frame(frame)
     , m_format(format)
+    , m_matrix(0)
 {
 }
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoDrawQuad.h (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoDrawQuad.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoDrawQuad.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -41,13 +41,17 @@
     CCVideoLayerImpl::Texture* textures() const { return m_textures; }
     VideoFrameChromium* frame() const { return m_frame; }
     GC3Denum format() const { return m_format; }
+    const float* matrix() const { return m_matrix; }
 
+    void setMatrix(const float* matrix) { m_matrix = matrix; }
+
 private:
     CCVideoDrawQuad(const CCSharedQuadState*, const IntRect&, CCVideoLayerImpl::Texture* textures, VideoFrameChromium*, GC3Denum format);
 
     CCVideoLayerImpl::Texture* m_textures;
     VideoFrameChromium* m_frame;
     GC3Denum m_format;
+    const float* m_matrix;
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp	2012-02-23 22:10:02 UTC (rev 108675)
@@ -62,10 +62,21 @@
     -0.5f,
 };
 
+// This matrix is the default transformation for stream textures.
+const float CCVideoLayerImpl::flipTransform[16] = {
+    1, 0, 0, 0,
+    0, -1, 0, 0,
+    0, 0, 1, 0,
+    0, 1, 0, 1,
+};
+
 CCVideoLayerImpl::CCVideoLayerImpl(int id, VideoFrameProvider* provider)
     : CCLayerImpl(id)
     , m_provider(provider)
+    , m_layerTreeHostImpl(0)
+    , m_frame(0)
 {
+    memcpy(m_streamTextureMatrix, flipTransform, sizeof(m_streamTextureMatrix));
     provider->setVideoFrameProviderClient(this);
 }
 
@@ -88,16 +99,16 @@
 }
 
 // Convert VideoFrameChromium::Format to GraphicsContext3D's format enum values.
-static GC3Denum convertVFCFormatToGC3DFormat(VideoFrameChromium::Format format)
+static GC3Denum convertVFCFormatToGC3DFormat(const VideoFrameChromium* frame)
 {
-    switch (format) {
+    switch (frame->format()) {
     case VideoFrameChromium::YV12:
     case VideoFrameChromium::YV16:
         return GraphicsContext3D::LUMINANCE;
     case VideoFrameChromium::RGBA:
         return GraphicsContext3D::RGBA;
     case VideoFrameChromium::NativeTexture:
-        return GraphicsContext3D::TEXTURE_2D;
+        return frame->textureTarget();
     case VideoFrameChromium::Invalid:
     case VideoFrameChromium::RGB555:
     case VideoFrameChromium::RGB565:
@@ -118,15 +129,17 @@
 
     MutexLocker locker(m_providerMutex);
 
-    if (!m_provider)
+    if (!m_provider) {
+        m_frame = 0;
         return;
+    }
 
     m_frame = m_provider->getCurrentFrame();
 
     if (!m_frame)
         return;
 
-    m_format = convertVFCFormatToGC3DFormat(m_frame->format());
+    m_format = convertVFCFormatToGC3DFormat(m_frame);
 
     if (m_format == GraphicsContext3D::INVALID_VALUE) {
         m_provider->putCurrentFrame(m_frame);
@@ -143,7 +156,12 @@
 void CCVideoLayerImpl::appendQuads(CCQuadList& quadList, const CCSharedQuadState* sharedQuadState)
 {
     IntRect quadRect(IntPoint(), bounds());
-    quadList.append(CCVideoDrawQuad::create(sharedQuadState, quadRect, m_textures, m_frame, m_format));
+    OwnPtr<CCVideoDrawQuad> videoQuad = CCVideoDrawQuad::create(sharedQuadState, quadRect, m_textures, m_frame, m_format);
+
+    if (m_format == Extensions3DChromium::GL_TEXTURE_EXTERNAL_OES)
+        videoQuad->setMatrix(m_streamTextureMatrix);
+
+    quadList.append(videoQuad.release());
 }
 
 void CCVideoLayerImpl::didDraw()
@@ -214,6 +232,23 @@
     return true;
 }
 
+void CCVideoLayerImpl::didReceiveFrame()
+{
+    setNeedsRedraw();
+}
+
+void CCVideoLayerImpl::didUpdateMatrix(const float matrix[16])
+{
+    memcpy(m_streamTextureMatrix, matrix, sizeof(m_streamTextureMatrix));
+    setNeedsRedraw();
+}
+
+void CCVideoLayerImpl::setNeedsRedraw()
+{
+    if (m_layerTreeHostImpl)
+        m_layerTreeHostImpl->setNeedsRedraw();
+}
+
 void CCVideoLayerImpl::dumpLayerProperties(TextStream& ts, int indent) const
 {
     writeIndent(ts, indent);

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h (108674 => 108675)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -35,6 +35,9 @@
 
 namespace WebCore {
 
+class CCLayerTreeHostImpl;
+class CCVideoLayerImpl;
+
 template<class VertexShader, class FragmentShader> class ProgramBinding;
 
 class CCVideoLayerImpl : public CCLayerImpl
@@ -53,17 +56,23 @@
     typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexFlipAlpha> RGBAProgram;
     typedef ProgramBinding<VertexShaderPosTexYUVStretch, FragmentShaderYUVVideo> YUVProgram;
     typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexFlipAlpha> NativeTextureProgram;
+    typedef ProgramBinding<VertexShaderVideoTransform, FragmentShaderOESImageExternal> StreamTextureProgram;
 
     virtual void dumpLayerProperties(TextStream&, int indent) const;
 
     Mutex& providerMutex() { return m_providerMutex; }
     VideoFrameProvider* provider() const { return m_provider; }
 
-    // VideoFrameProvider::Client implementation (callable on any thread).
-    virtual void stopUsingProvider();
+    // VideoFrameProvider::Client implementation.
+    virtual void stopUsingProvider(); // Callable on any thread.
+    virtual void didReceiveFrame(); // Callable on impl thread.
+    virtual void didUpdateMatrix(const float*); // Callable on impl thread.
 
+    void setNeedsRedraw();
+
     static const float yuv2RGB[9];
     static const float yuvAdjust[3];
+    static const float flipTransform[16];
 
     struct Texture {
         OwnPtr<ManagedTexture> m_texture;
@@ -84,6 +93,9 @@
 
     Texture m_textures[MaxPlanes];
 
+    float m_streamTextureMatrix[16];
+    CCLayerTreeHostImpl* m_layerTreeHostImpl;
+
     VideoFrameChromium* m_frame;
     GC3Denum m_format;
 };

Modified: trunk/Source/WebKit/chromium/ChangeLog (108674 => 108675)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-02-23 22:10:02 UTC (rev 108675)
@@ -1,3 +1,38 @@
+2012-02-23  Daniel Sievers  <[email protected]>
+
+        [Chromium] Add video stream texture support
+        https://bugs.webkit.org/show_bug.cgi?id=78398
+
+        This upstreams the abstraction used on Android for
+        hardware video decoding with the compositor.
+
+        Most of the interfaces are kept generic and the core
+        of this change is to allow texturing from an external
+        texture while receiving notifications (on the compositor
+        thread if we are running it) when there are new frames to
+        be displayed.
+
+        Reviewed by James Robinson.
+
+        * WebKit.gyp:
+        * public/WebMediaPlayer.h:
+        (WebKit):
+        (WebKit::WebMediaPlayer::setStreamTextureClient):
+        (WebMediaPlayer):
+        * public/WebStreamTextureClient.h: Copied from Source/WebKit/chromium/public/WebVideoFrame.h.
+        (WebKit):
+        (WebStreamTextureClient):
+        (WebKit::WebStreamTextureClient::~WebStreamTextureClient):
+        * public/WebVideoFrame.h:
+        * src/WebMediaPlayerClientImpl.cpp:
+        (WebKit::WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl):
+        (WebKit::WebMediaPlayerClientImpl::setVideoFrameProviderClient):
+        (WebKit::WebMediaPlayerClientImpl::didReceiveFrame):
+        (WebKit):
+        (WebKit::WebMediaPlayerClientImpl::didUpdateMatrix):
+        * src/WebMediaPlayerClientImpl.h:
+        (WebMediaPlayerClientImpl):
+
 2012-02-22  James Robinson  <[email protected]>
 
         [chromium] Clean up GraphicsContext3D initialization paths

Modified: trunk/Source/WebKit/chromium/WebKit.gyp (108674 => 108675)


--- trunk/Source/WebKit/chromium/WebKit.gyp	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/WebKit.gyp	2012-02-23 22:10:02 UTC (rev 108675)
@@ -257,6 +257,7 @@
                 'public/WebStorageNamespace.h',
                 'public/WebStorageQuotaCallbacks.h',
                 'public/WebStorageQuotaType.h',
+                'public/WebStreamTextureClient.h',
                 'public/WebTextAffinity.h',
                 'public/WebTextCaseSensitivity.h',
                 'public/WebTextCheckingCompletion.h',

Modified: trunk/Source/WebKit/chromium/public/WebMediaPlayer.h (108674 => 108675)


--- trunk/Source/WebKit/chromium/public/WebMediaPlayer.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/public/WebMediaPlayer.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -40,6 +40,7 @@
 class WebAudioSourceProvider;
 class WebAudioSourceProviderClient;
 class WebMediaPlayerClient;
+class WebStreamTextureClient;
 class WebURL;
 struct WebRect;
 struct WebSize;
@@ -162,6 +163,8 @@
     // method should no longer be referenced after the call is made.
     virtual void putCurrentFrame(WebVideoFrame*) { }
 
+    virtual void setStreamTextureClient(WebStreamTextureClient*) { }
+
     virtual WebAudioSourceProvider* audioSourceProvider() { return 0; }
 
     virtual bool sourceAppend(const unsigned char* data, unsigned length) { return false; }

Copied: trunk/Source/WebKit/chromium/public/WebStreamTextureClient.h (from rev 108674, trunk/Source/WebKit/chromium/public/WebVideoFrame.h) (0 => 108675)


--- trunk/Source/WebKit/chromium/public/WebStreamTextureClient.h	                        (rev 0)
+++ trunk/Source/WebKit/chromium/public/WebStreamTextureClient.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebStreamTextureClient_h
+#define WebStreamTextureClient_h
+
+namespace WebKit {
+
+class WebStreamTextureClient {
+public:
+    virtual void didReceiveFrame() = 0;
+    virtual void didUpdateMatrix(const float*) = 0;
+
+protected:
+    virtual ~WebStreamTextureClient() { }
+};
+
+} // namespace WebKit
+
+#endif

Modified: trunk/Source/WebKit/chromium/public/WebVideoFrame.h (108674 => 108675)


--- trunk/Source/WebKit/chromium/public/WebVideoFrame.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/public/WebVideoFrame.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -61,6 +61,7 @@
     virtual int stride(unsigned plane) const { return 0; }
     virtual const void* data(unsigned plane) const { return 0; }
     virtual unsigned textureId() const { return 0; }
+    virtual unsigned textureTarget() const { return 0; }
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/chromium/src/VideoFrameChromiumImpl.cpp (108674 => 108675)


--- trunk/Source/WebKit/chromium/src/VideoFrameChromiumImpl.cpp	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/src/VideoFrameChromiumImpl.cpp	2012-02-23 22:10:02 UTC (rev 108675)
@@ -128,4 +128,11 @@
     return 0;
 }
 
+unsigned VideoFrameChromiumImpl::textureTarget() const
+{
+    if (m_webVideoFrame)
+        return m_webVideoFrame->textureTarget();
+    return 0;
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/chromium/src/VideoFrameChromiumImpl.h (108674 => 108675)


--- trunk/Source/WebKit/chromium/src/VideoFrameChromiumImpl.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/src/VideoFrameChromiumImpl.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -58,6 +58,7 @@
     virtual const WebCore::IntSize requiredTextureSize(unsigned plane) const;
     virtual bool hasPaddingBytes(unsigned plane) const;
     virtual unsigned textureId() const;
+    virtual unsigned textureTarget() const;
 
 private:
     WebVideoFrame* m_webVideoFrame;

Modified: trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp (108674 => 108675)


--- trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp	2012-02-23 22:10:02 UTC (rev 108675)
@@ -28,6 +28,7 @@
 #include "WebMediaElement.h"
 #include "WebMediaPlayer.h"
 #include "WebViewImpl.h"
+#include "cc/CCProxy.h"
 #include "platform/WebCString.h"
 #include "platform/WebCanvas.h"
 #include "platform/WebKitPlatformSupport.h"
@@ -105,6 +106,8 @@
     MutexLocker locker(m_compositingMutex);
     if (m_videoFrameProviderClient)
         m_videoFrameProviderClient->stopUsingProvider();
+    if (m_webMediaPlayer)
+        m_webMediaPlayer->setStreamTextureClient(0);
 #endif
 }
 
@@ -237,6 +240,7 @@
     m_url = url;
 
     if (m_preload == MediaPlayer::None) {
+        MutexLocker locker(m_compositingMutex);
 #if ENABLE(WEB_AUDIO)
         m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's WebAudioSourceProvider.
 #endif
@@ -248,6 +252,7 @@
 
 void WebMediaPlayerClientImpl::loadInternal()
 {
+    MutexLocker locker(m_compositingMutex);
 #if ENABLE(WEB_AUDIO)
     m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's WebAudioSourceProvider.
 #endif
@@ -597,6 +602,8 @@
 {
     MutexLocker locker(m_compositingMutex);
     m_videoFrameProviderClient = client;
+    if (m_webMediaPlayer)
+        m_webMediaPlayer->setStreamTextureClient(client ? this : 0);
 }
 
 VideoFrameChromium* WebMediaPlayerClientImpl::getCurrentFrame()
@@ -679,6 +686,20 @@
     loadInternal();
 }
 
+void WebMediaPlayerClientImpl::didReceiveFrame()
+{
+    // No lock since this gets called on the client's thread.
+    ASSERT(CCProxy::isImplThread());
+    m_videoFrameProviderClient->didReceiveFrame();
+}
+
+void WebMediaPlayerClientImpl::didUpdateMatrix(const float* matrix)
+{
+    // No lock since this gets called on the client's thread.
+    ASSERT(CCProxy::isImplThread());
+    m_videoFrameProviderClient->didUpdateMatrix(matrix);
+}
+
 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl()
     : m_mediaPlayer(0)
     , m_delayingLoad(false)

Modified: trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h (108674 => 108675)


--- trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h	2012-02-23 22:05:15 UTC (rev 108674)
+++ trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h	2012-02-23 22:10:02 UTC (rev 108675)
@@ -40,7 +40,9 @@
 #include "VideoLayerChromium.h"
 #include "WebAudioSourceProviderClient.h"
 #include "WebMediaPlayerClient.h"
+#include "WebStreamTextureClient.h"
 #include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore { class AudioSourceProviderClient; }
 
@@ -56,7 +58,8 @@
 #if USE(ACCELERATED_COMPOSITING)
                                , public WebCore::VideoFrameProvider
 #endif
-                               , public WebMediaPlayerClient {
+                               , public WebMediaPlayerClient
+                               , public WebStreamTextureClient {
 
 public:
     static bool isEnabled();
@@ -150,6 +153,10 @@
     virtual void sourceEndOfStream(WebCore::MediaPlayer::EndOfStreamStatus);
 #endif
 
+    // WebStreamTextureClient methods:
+    virtual void didReceiveFrame();
+    virtual void didUpdateMatrix(const float*);
+
 private:
     WebMediaPlayerClientImpl();
     void startDelayedLoad();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to