Merge lp:~phablet-team/qtvideo-node/qtvideo-node-update-textures-in-preprocess-pass into lp:qtvideo-node

Proposed by Loïc Molinari on 2015-04-30
Status: Merged
Approved by: Ricardo Mendoza on 2015-05-11
Approved revision: 64
Merged at revision: 61
Proposed branch: lp:~phablet-team/qtvideo-node/qtvideo-node-update-textures-in-preprocess-pass
Merge into: lp:qtvideo-node
Diff against target: 172 lines (+33/-26)
5 files modified
src/shadervideomaterial.cpp (+5/-23)
src/shadervideomaterial.h (+1/-1)
src/shadervideonode.cpp (+10/-0)
src/shadervideonode.h (+2/-0)
src/shadervideoshader.cpp (+15/-2)
To merge this branch: bzr merge lp:~phablet-team/qtvideo-node/qtvideo-node-update-textures-in-preprocess-pass
Reviewer Review Type Date Requested Status
Ricardo Mendoza (community) 2015-04-30 Approve on 2015-05-11
PS Jenkins bot continuous-integration Approve on 2015-05-08
Review via email: mp+257960@code.launchpad.net

Commit Message

Moved texture updates from rendering pass to preprocess pass.

Description of the Change

Moved texture updates from rendering pass to preprocess pass.

To post a comment you must log in.
Loïc Molinari (loic.molinari) wrote :

Just fixed the build issue on desktop which prevented landing.

Ricardo Mendoza (ricmm) wrote :

Need to fix build failures.

review: Needs Fixing
Ricardo Mendoza (ricmm) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/shadervideomaterial.cpp'
2--- src/shadervideomaterial.cpp 2015-03-20 13:17:28 +0000
3+++ src/shadervideomaterial.cpp 2015-05-03 21:42:49 +0000
4@@ -14,13 +14,6 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8-#ifdef QT_OPENGL_ES_2
9-# define TEXTURE_TARGET GL_TEXTURE_EXTERNAL_OES
10-#else
11-# define TEXTURE_TARGET GL_TEXTURE_2D
12-# define GL_GLEXT_PROTOTYPES
13-#endif
14-
15 #include <QGLShaderProgram>
16 #include <QtOpenGL>
17 #include <QTransform>
18@@ -118,24 +111,21 @@
19 return m_videoSink;
20 }
21
22-bool ShaderVideoMaterial::updateTexture()
23+void ShaderVideoMaterial::updateTexture()
24 {
25- bool textureDirty = false;
26-
27 if (!m_camControl && !m_textureId && !m_videoSink) {
28- return false;
29+ return;
30 }
31
32 if (m_camControl != NULL) {
33 android_camera_update_preview_texture(m_camControl);
34 android_camera_get_preview_texture_transformation(m_camControl, m_textureMatrix);
35- textureDirty = true;
36 } else if (m_videoSink && !m_readyToRender) {
37 m_readyToRender = true;
38+ return;
39 } else if (m_videoSink && m_readyToRender) {
40 if (m_videoSink->swap_buffers()) {
41 m_videoSink->transformation_matrix(static_cast<float*>(m_textureMatrix));
42- textureDirty = true;
43 }
44 }
45
46@@ -144,21 +134,13 @@
47 m_orientation == SharedSignal::Orientation::rotate180 ||
48 m_orientation == SharedSignal::Orientation::rotate270)
49 {
50- QMatrix4x4 qRotated = rotateAndFlip(m_textureMatrix, m_orientation);
51- glUniformMatrix4fv(m_videoShader->m_tex_matrix, 1, GL_FALSE, qRotated.data());
52+ memcpy(m_textureMatrix, rotateAndFlip(m_textureMatrix, m_orientation).data(),
53+ sizeof(m_textureMatrix));
54 }
55 else
56 {
57 undoAndroidYFlip(m_textureMatrix);
58- glUniformMatrix4fv(m_videoShader->m_tex_matrix, 1, GL_FALSE, m_textureMatrix);
59 }
60-
61- glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
62- glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
63- glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
64- glTexParameteri(TEXTURE_TARGET, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
65-
66- return textureDirty;
67 }
68
69 void ShaderVideoMaterial::onSetOrientation(const SharedSignal::Orientation& orientation,
70
71=== modified file 'src/shadervideomaterial.h'
72--- src/shadervideomaterial.h 2015-01-12 16:21:50 +0000
73+++ src/shadervideomaterial.h 2015-05-03 21:42:49 +0000
74@@ -62,7 +62,7 @@
75 void setGLVideoSink(const std::shared_ptr<core::ubuntu::media::video::Sink>& sink);
76 const std::shared_ptr<core::ubuntu::media::video::Sink>& glVideoSink() const;
77
78- bool updateTexture();
79+ void updateTexture();
80
81 GLfloat m_textureMatrix[16] {};
82
83
84=== modified file 'src/shadervideonode.cpp'
85--- src/shadervideonode.cpp 2015-01-12 16:52:18 +0000
86+++ src/shadervideonode.cpp 2015-05-03 21:42:49 +0000
87@@ -30,6 +30,8 @@
88 m_format(format),
89 m_textureId(0)
90 {
91+ QSGNode::setFlag(UsePreprocess, true);
92+
93 m_material = new ShaderVideoMaterial(format);
94 setMaterial(m_material);
95
96@@ -47,6 +49,11 @@
97 delete m_snapshotGenerator;
98 }
99
100+void ShaderVideoNode::preprocess()
101+{
102+ m_material->updateTexture();
103+}
104+
105 /*!
106 * \brief ShaderVideoNode::pixelFormat \reimp
107 * \return
108@@ -143,6 +150,7 @@
109 return;
110 }
111
112+ m_material->setTextureId(m_textureId);
113 Q_EMIT SharedSignal::instance()->textureCreated(static_cast<unsigned int>(m_textureId));
114 }
115
116@@ -156,4 +164,6 @@
117 glDeleteTextures(1, &m_textureId);
118 #endif
119 m_textureId = 0;
120+
121+ m_material->setTextureId(0);
122 }
123
124=== modified file 'src/shadervideonode.h'
125--- src/shadervideonode.h 2015-01-12 16:21:50 +0000
126+++ src/shadervideonode.h 2015-05-03 21:42:49 +0000
127@@ -40,6 +40,8 @@
128 ShaderVideoNode(const QVideoSurfaceFormat &format);
129 ~ShaderVideoNode();
130
131+ void preprocess();
132+
133 QVideoFrame::PixelFormat pixelFormat() const;
134 void setCurrentFrame(const QVideoFrame &frame);
135
136
137=== modified file 'src/shadervideoshader.cpp'
138--- src/shadervideoshader.cpp 2014-10-06 14:44:29 +0000
139+++ src/shadervideoshader.cpp 2015-05-03 21:42:49 +0000
140@@ -16,6 +16,7 @@
141
142 #include "shadervideoshader.h"
143 #include "shadervideomaterial.h"
144+#include <QtGui/QOpenGLFunctions>
145
146 ShaderVideoShader::ShaderVideoShader(QVideoFrame::PixelFormat pixelFormat)
147 : QSGMaterialShader(),
148@@ -29,10 +30,22 @@
149 {
150 Q_UNUSED(oldMaterial);
151 ShaderVideoMaterial *mat = dynamic_cast<ShaderVideoMaterial *>(newMaterial);
152+ QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
153+
154+#if !defined(QT_OPENGL_ES_2)
155+ const GLenum textureTarget = GL_TEXTURE_2D;
156+#else
157+ const GLenum textureTarget = GL_TEXTURE_EXTERNAL_OES;
158+#endif
159+ functions->glBindTexture(textureTarget, mat->textureId());
160+ functions->glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
161+ functions->glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
162+ functions->glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
163+ functions->glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
164+
165 program()->setUniformValue(m_id_texture, 0);
166
167- if (mat->updateTexture())
168- program()->setUniformValueArray(m_id_matrix, mat->m_textureMatrix, 16, 1);
169+ functions->glUniformMatrix4fv(m_tex_matrix, 1, GL_FALSE, mat->m_textureMatrix);
170
171 if (state.isOpacityDirty())
172 program()->setUniformValue(m_id_opacity, state.opacity());

Subscribers

People subscribed via source and target branches

to all changes: