diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-10-28 10:58:35 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-10-28 12:26:52 +0000 |
commit | b76be3dfc52ee7eb508e2837c9d83c8f79a5cb26 (patch) | |
tree | c4f5103ae55c7a8ae71f99ba2229cfd2fc63ae20 /src/core | |
parent | 2cb021c2978d5d8ab5ba565f10d9eddc27c6347f (diff) |
Support IOSurface frames
Support getting video as IOSurface frames on OS X.
With Chromium 45 we only get IOSurface frame when using
non-default command-line flags.
Change-Id: Ibf5226db53fa6fb51112bec9061d701918798ddd
Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/delegated_frame_node.cpp | 25 | ||||
-rw-r--r-- | src/core/stream_video_node.cpp | 35 | ||||
-rw-r--r-- | src/core/stream_video_node.h | 8 |
3 files changed, 56 insertions, 12 deletions
diff --git a/src/core/delegated_frame_node.cpp b/src/core/delegated_frame_node.cpp index aebdfd027..1b6a80f82 100644 --- a/src/core/delegated_frame_node.cpp +++ b/src/core/delegated_frame_node.cpp @@ -57,6 +57,7 @@ #include "cc/quads/checkerboard_draw_quad.h" #include "cc/quads/debug_border_draw_quad.h" #include "cc/quads/draw_quad.h" +#include "cc/quads/io_surface_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" @@ -80,6 +81,10 @@ #define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull #endif +#ifndef GL_TEXTURE_RECTANGLE +#define GL_TEXTURE_RECTANGLE 0x84F5 +#endif + namespace QtWebEngineCore { class MailboxTexture : public QSGTexture, protected QOpenGLFunctions { @@ -655,13 +660,29 @@ void DelegatedFrameNode::commit(ChromiumCompositorData *chromiumCompositorData, MailboxTexture *texture = static_cast<MailboxTexture *>(initAndHoldTexture(resource, quad->ShouldDrawWithBlending())); texture->setTarget(GL_TEXTURE_EXTERNAL_OES); // since this is not default TEXTURE_2D type - StreamVideoNode *svideoNode = new StreamVideoNode(texture); + StreamVideoNode *svideoNode = new StreamVideoNode(texture, false, ExternalTarget); svideoNode->setRect(toQt(squad->rect)); svideoNode->setTextureMatrix(toQt(squad->matrix.matrix())); currentLayerChain->appendChildNode(svideoNode); break; #endif - } default: + } + case cc::DrawQuad::IO_SURFACE_CONTENT: { + const cc::IOSurfaceDrawQuad *ioquad = cc::IOSurfaceDrawQuad::MaterialCast(quad); + ResourceHolder *resource = findAndHoldResource(ioquad->io_surface_resource_id(), resourceCandidates); + MailboxTexture *texture = static_cast<MailboxTexture *>(initAndHoldTexture(resource, quad->ShouldDrawWithBlending())); + texture->setTarget(GL_TEXTURE_RECTANGLE); + + bool flip = ioquad->orientation != cc::IOSurfaceDrawQuad::FLIPPED; + StreamVideoNode *svideoNode = new StreamVideoNode(texture, flip, RectangleTarget); + QMatrix4x4 matrix; + matrix.scale(ioquad->io_surface_size.width(), ioquad->io_surface_size.height()); + svideoNode->setRect(toQt(ioquad->rect)); + svideoNode->setTextureMatrix(matrix); + currentLayerChain->appendChildNode(svideoNode); + break; + } + default: qWarning("Unimplemented quad material: %d", quad->material); } } diff --git a/src/core/stream_video_node.cpp b/src/core/stream_video_node.cpp index 7481d49ed..fdae5fee2 100644 --- a/src/core/stream_video_node.cpp +++ b/src/core/stream_video_node.cpp @@ -43,6 +43,7 @@ namespace QtWebEngineCore { class StreamVideoMaterialShader : public QSGMaterialShader { public: + StreamVideoMaterialShader(TextureTarget target) : m_target(target) { } virtual void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial); virtual char const *const *attributeNames() const Q_DECL_OVERRIDE { @@ -57,7 +58,7 @@ public: protected: virtual const char *vertexShader() const Q_DECL_OVERRIDE { // Keep in sync with cc::VertexShaderVideoTransform - const char *shader = + static const char *shader = "attribute highp vec4 a_position;\n" "attribute mediump vec2 a_texCoord;\n" "uniform highp mat4 matrix;\n" @@ -72,7 +73,7 @@ protected: virtual const char *fragmentShader() const Q_DECL_OVERRIDE { // Keep in sync with cc::FragmentShaderRGBATexAlpha - static const char *shader = + static const char *shaderExternal = "#extension GL_OES_EGL_image_external : require\n" "varying mediump vec2 v_texCoord;\n" "uniform samplerExternalOES s_texture;\n" @@ -81,7 +82,19 @@ protected: " lowp vec4 texColor = texture2D(s_texture, v_texCoord);\n" " gl_FragColor = texColor * alpha;\n" "}"; - return shader; + static const char *shader2DRect = + "#extension GL_ARB_texture_rectangle : require\n" + "varying mediump vec2 v_texCoord;\n" + "uniform sampler2DRect s_texture;\n" + "uniform lowp float alpha;\n" + "void main() {\n" + " lowp vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" + " gl_FragColor = texColor * alpha;\n" + "}"; + if (m_target == ExternalTarget) + return shaderExternal; + else + return shader2DRect; } virtual void initialize() { @@ -95,6 +108,7 @@ protected: int m_id_texMatrix; int m_id_sTexture; int m_id_opacity; + TextureTarget m_target; }; void StreamVideoMaterialShader::updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) @@ -115,28 +129,33 @@ void StreamVideoMaterialShader::updateState(const RenderState &state, QSGMateria program()->setUniformValue(m_id_texMatrix, mat->m_texMatrix); } -StreamVideoMaterial::StreamVideoMaterial(QSGTexture *texture) +StreamVideoMaterial::StreamVideoMaterial(QSGTexture *texture, TextureTarget target) : m_texture(texture) + , m_target(target) { } QSGMaterialShader *StreamVideoMaterial::createShader() const { - return new StreamVideoMaterialShader; + return new StreamVideoMaterialShader(m_target); } -StreamVideoNode::StreamVideoNode(QSGTexture *texture) +StreamVideoNode::StreamVideoNode(QSGTexture *texture, bool flip, TextureTarget target) : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) + , m_flip(flip) { setGeometry(&m_geometry); setFlag(QSGNode::OwnsMaterial); - m_material = new StreamVideoMaterial(texture); + m_material = new StreamVideoMaterial(texture, target); setMaterial(m_material); } void StreamVideoNode::setRect(const QRectF &rect) { - QSGGeometry::updateTexturedRectGeometry(geometry(), rect, QRectF(0, 0, 1, 1)); + if (m_flip) + QSGGeometry::updateTexturedRectGeometry(geometry(), rect, QRectF(0, 1, 1, -1)); + else + QSGGeometry::updateTexturedRectGeometry(geometry(), rect, QRectF(0, 0, 1, 1)); } void StreamVideoNode::setTextureMatrix(const QMatrix4x4 &matrix) diff --git a/src/core/stream_video_node.h b/src/core/stream_video_node.h index bd2c3408a..92c640811 100644 --- a/src/core/stream_video_node.h +++ b/src/core/stream_video_node.h @@ -47,10 +47,12 @@ namespace QtWebEngineCore { // These classes duplicate, QtQuick style, the logic of GLRenderer::DrawStreamVideoQuad. // Their behavior should stay as close as possible to GLRenderer. +enum TextureTarget { ExternalTarget, RectangleTarget }; + class StreamVideoMaterial : public QSGMaterial { public: - StreamVideoMaterial(QSGTexture *texture); + StreamVideoMaterial(QSGTexture *texture, TextureTarget target); virtual QSGMaterialType *type() const Q_DECL_OVERRIDE { @@ -62,17 +64,19 @@ public: QSGTexture *m_texture; QMatrix4x4 m_texMatrix; + TextureTarget m_target; }; class StreamVideoNode : public QSGGeometryNode { public: - StreamVideoNode(QSGTexture *texture); + StreamVideoNode(QSGTexture *texture, bool flip, TextureTarget target); void setRect(const QRectF &rect); void setTextureMatrix(const QMatrix4x4 &matrix); private: QSGGeometry m_geometry; + bool m_flip; StreamVideoMaterial *m_material; }; |