diff options
author | Mansoor Chishtie <mchishtie@blackberry.com> | 2014-02-13 15:59:46 -0600 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-25 09:18:48 +0100 |
commit | e7793c99669f635ea4dab6d025a4db7a45bf718e (patch) | |
tree | 8e6fb1d4e5f42f89316b8ad6a07df952d8c05655 /src | |
parent | c10ddd8930b06c5872499ca49213af9d9e3eb092 (diff) |
Video texture streaming support via external EGLImage textures
Created new StreamVideoNode & StreamVideoMaterial classes
for QSG renderer. These classes duplicate the logic of
chromium's direct renderer GLRenderer::DrawStreamVideoQuad.
Added support for new DrawQuad material in DelegatedFrameNode.
Added support for external textures in MailboxTexture.
Change-Id: If569b07dfef985f9833de7e64eeb3f952026bca4
Reviewed-by: Arvid Nilsson <anilsson@blackberry.com>
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/core_gyp_generator.pro | 2 | ||||
-rw-r--r-- | src/core/delegated_frame_node.cpp | 26 | ||||
-rw-r--r-- | src/core/stream_video_node.cpp | 138 | ||||
-rw-r--r-- | src/core/stream_video_node.h | 82 |
4 files changed, 246 insertions, 2 deletions
diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index 44375cfed..bf7cce9fe 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -52,6 +52,7 @@ SOURCES = \ renderer/qt_render_view_observer.cpp \ resource_bundle_qt.cpp \ resource_context_qt.cpp \ + stream_video_node.cpp \ url_request_context_getter_qt.cpp \ web_contents_adapter.cpp \ web_contents_delegate_qt.cpp \ @@ -86,6 +87,7 @@ HEADERS = \ renderer/content_renderer_client_qt.h \ renderer/qt_render_view_observer.h \ resource_context_qt.h \ + stream_video_node.h \ url_request_context_getter_qt.h \ web_contents_adapter.h \ web_contents_adapter_client.h \ diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index 195b26add..97a7066bc 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -51,6 +51,7 @@ #include "delegated_frame_node.h" #include "chromium_gpu_helper.h" +#include "stream_video_node.h" #include "type_conversion.h" #include "yuv_video_node.h" @@ -60,6 +61,7 @@ #include "cc/quads/draw_quad.h" #include "cc/quads/render_pass_draw_quad.h" #include "cc/quads/solid_color_draw_quad.h" +#include "cc/quads/stream_video_draw_quad.h" #include "cc/quads/texture_draw_quad.h" #include "cc/quads/tile_draw_quad.h" #include "cc/quads/yuv_video_draw_quad.h" @@ -120,12 +122,14 @@ public: bool needsToFetch() const { return !m_textureId; } cc::TransferableResource &resource() { return m_resource; } void fetchTexture(gpu::gles2::MailboxManager *mailboxManager); + void setTarget(GLenum target); private: cc::TransferableResource m_resource; int m_textureId; QSize m_textureSize; bool m_hasAlpha; + GLenum m_target; }; static inline QSharedPointer<RenderPassTexture> findRenderPassTexture(const cc::RenderPass::Id &id, const QList<QSharedPointer<RenderPassTexture> > &list) @@ -258,17 +262,23 @@ MailboxTexture::MailboxTexture(const cc::TransferableResource &resource) , m_textureId(0) , m_textureSize(toQt(resource.size)) , m_hasAlpha(false) + , m_target(GL_TEXTURE_2D) { } void MailboxTexture::bind() { - glBindTexture(GL_TEXTURE_2D, m_textureId); + glBindTexture(m_target, m_textureId); +} + +void MailboxTexture::setTarget(GLenum target) +{ + m_target = target; } void MailboxTexture::fetchTexture(gpu::gles2::MailboxManager *mailboxManager) { - gpu::gles2::Texture *tex = ConsumeTexture(mailboxManager, GL_TEXTURE_2D, *reinterpret_cast<const gpu::gles2::MailboxName*>(m_resource.mailbox.name)); + gpu::gles2::Texture *tex = ConsumeTexture(mailboxManager, m_target, *reinterpret_cast<const gpu::gles2::MailboxName*>(m_resource.mailbox.name)); // The texture might already have been deleted (e.g. when navigating away from a page). if (tex) @@ -470,6 +480,18 @@ void DelegatedFrameNode::commit(DelegatedFrameNodeData* data, cc::ReturnedResour videoNode->setRect(toQt(quad->rect)); currentLayerChain->appendChildNode(videoNode); break; +#ifdef GL_OES_EGL_image_external + } case cc::DrawQuad::STREAM_VIDEO_CONTENT: { + const cc::StreamVideoDrawQuad *squad = cc::StreamVideoDrawQuad::MaterialCast(quad); + QSharedPointer<MailboxTexture> &texture = m_data->mailboxTextures[squad->resource_id] = mailboxTextureCandidates.take(squad->resource_id); + texture->setTarget(GL_TEXTURE_EXTERNAL_OES); // since this is not default TEXTURE_2D type + Q_ASSERT(texture); + + StreamVideoNode *svideoNode = new StreamVideoNode(texture.data()); + svideoNode->setRect(toQt(squad->rect)); + currentLayerChain->appendChildNode(svideoNode); + break; +#endif } default: qWarning("Unimplemented quad material: %d", quad->material); } diff --git a/src/core/stream_video_node.cpp b/src/core/stream_video_node.cpp new file mode 100644 index 000000000..8f8723bd3 --- /dev/null +++ b/src/core/stream_video_node.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "stream_video_node.h" + +#include <QtQuick/qsgtexture.h> + +class StreamVideoMaterialShader : public QSGMaterialShader +{ +public: + virtual void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial); + + virtual char const *const *attributeNames() const { + static const char *names[] = { + "a_position", + "a_texCoord", + 0 + }; + return names; + } + +protected: + virtual const char *vertexShader() const { + // Keep in sync with cc::VertexShaderVideoTransform + const char *shader = + "attribute highp vec4 a_position;\n" + "attribute mediump vec2 a_texCoord;\n" + "uniform highp mat4 matrix;\n" + "varying mediump vec2 v_texCoord;\n" + "void main() {\n" + " gl_Position = matrix * a_position;\n" + " v_texCoord = a_texCoord;\n" + "}"; + return shader; + } + + virtual const char *fragmentShader() const { + // Keep in sync with cc::FragmentShaderOESImageExternal + static const char *shader = + "#extension GL_OES_EGL_image_external : require\n" + "varying mediump vec2 v_texCoord;\n" + "uniform samplerExternalOES s_texture;\n" + "void main() {\n" + " vec4 texColor = texture2D(s_texture, v_texCoord);\n" + " gl_FragColor = texColor;\n" + "}"; + return shader; + } + + virtual void initialize() { + m_id_matrix = program()->uniformLocation("matrix"); + m_id_sTexture = program()->uniformLocation("s_texture"); + } + + int m_id_matrix; + int m_id_sTexture; +}; + +void StreamVideoMaterialShader::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) +{ + Q_UNUSED(oldMaterial); + + StreamVideoMaterial *mat = static_cast<StreamVideoMaterial *>(newMaterial); + program()->setUniformValue(m_id_sTexture, 0); + + mat->m_texture->bind(); + + // TODO(mchishtie): handle state.opacity() when shader implements it + if (state.isMatrixDirty()) + program()->setUniformValue(m_id_matrix, state.combinedMatrix()); +} + +StreamVideoMaterial::StreamVideoMaterial(QSGTexture *texture) + : m_texture(texture) +{ +} + +QSGMaterialShader *StreamVideoMaterial::createShader() const +{ + return new StreamVideoMaterialShader; +} + +int StreamVideoMaterial::compare(const QSGMaterial *other) const +{ + const StreamVideoMaterial *m = static_cast<const StreamVideoMaterial *>(other); + return (m_texture->textureId() - m->m_texture->textureId()); +} + +StreamVideoNode::StreamVideoNode(QSGTexture *texture) + : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) +{ + setGeometry(&m_geometry); + setFlag(QSGNode::OwnsMaterial); + m_material = new StreamVideoMaterial(texture); + setMaterial(m_material); +} + +void StreamVideoNode::setRect(const QRectF &rect) +{ + QSGGeometry::updateTexturedRectGeometry(geometry(), rect, QRectF(0, 0, 1, 1)); +} diff --git a/src/core/stream_video_node.h b/src/core/stream_video_node.h new file mode 100644 index 000000000..cf16f10d4 --- /dev/null +++ b/src/core/stream_video_node.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STREAM_VIDEO_NODE_H +#define STREAM_VIDEO_NODE_H + +#include <QtQuick/qsgmaterial.h> +#include <QtQuick/qsgnode.h> + +QT_BEGIN_NAMESPACE +class QSGTexture; +QT_END_NAMESPACE + +// These classes duplicate, QtQuick style, the logic of GLRenderer::DrawStreamVideoQuad. +// Their behavior should stay as close as possible to GLRenderer. + +class StreamVideoMaterial : public QSGMaterial +{ +public: + StreamVideoMaterial(QSGTexture *texture); + + virtual QSGMaterialType *type() const Q_DECL_OVERRIDE{ + static QSGMaterialType theType; + return &theType; + } + + virtual QSGMaterialShader *createShader() const; + virtual int compare(const QSGMaterial *other) const; + + QSGTexture *m_texture; +}; + +class StreamVideoNode : public QSGGeometryNode +{ +public: + StreamVideoNode(QSGTexture *texture); + void setRect(const QRectF &rect); + +private: + QSGGeometry m_geometry; + StreamVideoMaterial *m_material; +}; + +#endif // STREAM_VIDEO_NODE_H |