aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/util
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-06-24 11:26:22 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-06-24 11:48:46 +0200
commit1a9759855639b9e2b3cdc0687d3381dcbf6c9815 (patch)
treeb2da51f6eddddb83c2d97cdcfac24d38d2e67a4e /src/quick/scenegraph/util
parent8217ec1b888f3ff93f004801b018c5f85362c484 (diff)
parente1fc2793aef53b84a3f1e19b6d6bdf1141340074 (diff)
Merge branch 'dev' of ssh://codereview.qt-project.org/qt/qtdeclarative into wip/v4
Conflicts: src/imports/qtquick2/plugins.qmltypes src/qml/debugger/qv8debugservice.cpp src/qml/qml/qml.pri src/qml/qml/qqmlcompiler.cpp src/qml/qml/qqmlcomponent.cpp src/qml/qml/qqmlcontext.cpp src/qml/qml/qqmldata_p.h src/qml/qml/qqmlengine_p.h src/qml/qml/qqmljavascriptexpression.cpp src/qml/qml/qqmlxmlhttprequest.cpp src/qml/qml/v4/qv4bindings.cpp src/qml/qml/v4/qv4irbuilder.cpp src/qml/qml/v4/qv4jsonobject_p.h src/qml/qml/v8/qqmlbuiltinfunctions.cpp src/qml/qml/v8/qv8bindings.cpp src/qml/qml/v8/qv8contextwrapper.cpp src/qml/qml/v8/qv8listwrapper.cpp src/qml/qml/v8/qv8qobjectwrapper.cpp src/qml/qml/v8/qv8qobjectwrapper_p.h src/qml/qml/v8/qv8sequencewrapper_p_p.h src/qml/qml/v8/qv8typewrapper.cpp src/qml/qml/v8/qv8valuetypewrapper.cpp src/qml/types/qqmldelegatemodel.cpp src/quick/items/context2d/qquickcanvasitem.cpp src/quick/items/context2d/qquickcontext2d.cpp sync.profile tests/auto/qml/qjsengine/tst_qjsengine.cpp tests/benchmarks/qml/animation/animation.pro tools/qmlprofiler/qmlprofiler.pro Change-Id: I18a76b8a81d87523247fa03a44ca334b1a2360c9
Diffstat (limited to 'src/quick/scenegraph/util')
-rw-r--r--src/quick/scenegraph/util/qsgflatcolormaterial.cpp10
-rw-r--r--src/quick/scenegraph/util/qsgpainternode.cpp31
-rw-r--r--src/quick/scenegraph/util/qsgsimpletexturenode.cpp81
-rw-r--r--src/quick/scenegraph/util/qsgsimpletexturenode.h16
-rw-r--r--src/quick/scenegraph/util/qsgtexture.cpp60
-rw-r--r--src/quick/scenegraph/util/qsgtexture_p.h2
-rw-r--r--src/quick/scenegraph/util/qsgtexturematerial.cpp6
7 files changed, 143 insertions, 63 deletions
diff --git a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp
index 307201277c..09e2a7da27 100644
--- a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp
+++ b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp
@@ -74,11 +74,11 @@ void FlatColorMaterialShader::updateState(const RenderState &state, QSGMaterial
const QColor &c = newMaterial->color();
if (oldMaterial == 0 || c != oldMaterial->color() || state.isOpacityDirty()) {
- float opacity = state.opacity();
- QVector4D v(c.redF() * c.alphaF() * opacity,
- c.greenF() * c.alphaF() * opacity,
- c.blueF() * c.alphaF() * opacity,
- c.alphaF() * opacity);
+ float opacity = state.opacity() * c.alphaF();
+ QVector4D v(c.redF() * opacity,
+ c.greenF() * opacity,
+ c.blueF() * opacity,
+ opacity);
program()->setUniformValue(m_color_id, v);
}
diff --git a/src/quick/scenegraph/util/qsgpainternode.cpp b/src/quick/scenegraph/util/qsgpainternode.cpp
index e5cf6b8295..97b3500ad0 100644
--- a/src/quick/scenegraph/util/qsgpainternode.cpp
+++ b/src/quick/scenegraph/util/qsgpainternode.cpp
@@ -73,10 +73,6 @@ QSGPainterTexture::QSGPainterTexture()
m_retain_image = true;
}
-#ifdef QT_OPENGL_ES
-extern void qsg_swizzleBGRAToRGBA(QImage *image);
-#endif
-
void QSGPainterTexture::bind()
{
if (m_dirty_rect.isNull()) {
@@ -84,33 +80,8 @@ void QSGPainterTexture::bind()
return;
}
- bool oldMipmapsGenerated = m_mipmaps_generated;
- m_mipmaps_generated = true;
+ setImage(m_image);
QSGPlainTexture::bind();
- m_mipmaps_generated = oldMipmapsGenerated;
-
- QImage subImage = m_image.copy(m_dirty_rect);
-
- int w = m_dirty_rect.width();
- int h = m_dirty_rect.height();
-
-#ifdef QT_OPENGL_ES
- qsg_swizzleBGRAToRGBA(&subImage);
- glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_rect.x(), m_dirty_rect.y(), w, h,
- GL_RGBA, GL_UNSIGNED_BYTE, subImage.constBits());
-#else
- glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_rect.x(), m_dirty_rect.y(), w, h,
- GL_BGRA, GL_UNSIGNED_BYTE, subImage.constBits());
-#endif
-
- if (m_has_mipmaps && !m_mipmaps_generated) {
- QOpenGLContext *ctx = QOpenGLContext::currentContext();
- ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D);
- m_mipmaps_generated = true;
- }
-
- m_dirty_texture = false;
- m_dirty_bind_options = false;
m_dirty_rect = QRect();
}
diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
index 318120e4bf..86e0d36f6c 100644
--- a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
+++ b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
@@ -41,18 +41,44 @@
#include "qsgsimpletexturenode.h"
+#include <private/qsgnode_p.h>
QT_BEGIN_NAMESPACE
+class QSGSimpleTextureNodePrivate : public QSGGeometryNodePrivate
+{
+public:
+ QSGSimpleTextureNodePrivate()
+ : QSGGeometryNodePrivate()
+ , m_texCoordMode(QSGSimpleTextureNode::NoTransform)
+ {}
+
+ QSGSimpleTextureNode::TextureCoordinatesTransformMode m_texCoordMode;
+};
+
static void qsgsimpletexturenode_update(QSGGeometry *g,
QSGTexture *texture,
- const QRectF &rect)
+ const QRectF &rect,
+ QSGSimpleTextureNode::TextureCoordinatesTransformMode texCoordMode)
{
if (!texture)
return;
QSize ts = texture->textureSize();
QRectF sourceRect(0, 0, ts.width(), ts.height());
+
+ // Maybe transform the texture coordinates
+ if (texCoordMode.testFlag(QSGSimpleTextureNode::MirrorHorizontally)) {
+ float tmp = sourceRect.left();
+ sourceRect.setLeft(sourceRect.right());
+ sourceRect.setRight(tmp);
+ }
+ if (texCoordMode.testFlag(QSGSimpleTextureNode::MirrorVertically)) {
+ float tmp = sourceRect.top();
+ sourceRect.setTop(sourceRect.bottom());
+ sourceRect.setBottom(tmp);
+ }
+
QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect));
}
@@ -71,7 +97,8 @@ static void qsgsimpletexturenode_update(QSGGeometry *g,
Constructs a new simple texture node
*/
QSGSimpleTextureNode::QSGSimpleTextureNode()
- : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
+ : QSGGeometryNode(*new QSGSimpleTextureNodePrivate)
+ , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
{
setGeometry(&m_geometry);
setMaterial(&m_material);
@@ -112,7 +139,8 @@ void QSGSimpleTextureNode::setRect(const QRectF &r)
if (m_rect == r)
return;
m_rect = r;
- qsgsimpletexturenode_update(&m_geometry, texture(), m_rect);
+ Q_D(QSGSimpleTextureNode);
+ qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->m_texCoordMode);
markDirty(DirtyGeometry);
}
@@ -144,7 +172,8 @@ void QSGSimpleTextureNode::setTexture(QSGTexture *texture)
return;
m_material.setTexture(texture);
m_opaque_material.setTexture(texture);
- qsgsimpletexturenode_update(&m_geometry, texture, m_rect);
+ Q_D(QSGSimpleTextureNode);
+ qsgsimpletexturenode_update(&m_geometry, texture, m_rect, d->m_texCoordMode);
markDirty(DirtyMaterial);
}
@@ -158,4 +187,48 @@ QSGTexture *QSGSimpleTextureNode::texture() const
return m_material.texture();
}
+/*!
+ \enum QSGSimpleTextureNode::TextureCoordinatesTransformFlag
+
+ The TextureCoordinatesTransformFlag enum is used to specify the
+ mode used to generate texture coordinates for a textured quad.
+
+ \value NoTransform Texture coordinates are oriented with window coordinates
+ i.e. with origin at top-left.
+
+ \value MirrorHorizontally Texture coordinates are inverted in the horizontal axis with
+ respect to window coordinates
+
+ \value MirrorVertically Texture coordinates are inverted in the vertical axis with
+ respect to window coordinates
+ */
+
+/*!
+ Sets the method used to generate texture coordinates to \a mode. This can be used to obtain
+ correct orientation of the texture. This is commonly needed when using a third party OpenGL
+ library to render to texture as OpenGL has an inverted y-axis relative to Qt Quick.
+
+ \sa textureCoordinatesTransform()
+ */
+void QSGSimpleTextureNode::setTextureCoordinatesTransform(QSGSimpleTextureNode::TextureCoordinatesTransformMode mode)
+{
+ Q_D(QSGSimpleTextureNode);
+ if (d->m_texCoordMode == mode)
+ return;
+ d->m_texCoordMode = mode;
+ qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->m_texCoordMode);
+ markDirty(DirtyMaterial);
+}
+
+/*!
+ Returns the mode used to generate texture coordinates for this node.
+
+ \sa setTextureCoordinatesTransform()
+ */
+QSGSimpleTextureNode::TextureCoordinatesTransformMode QSGSimpleTextureNode::textureCoordinatesTransform() const
+{
+ Q_D(const QSGSimpleTextureNode);
+ return d->m_texCoordMode;
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.h b/src/quick/scenegraph/util/qsgsimpletexturenode.h
index ffd10210ae..f5ab7fb3bb 100644
--- a/src/quick/scenegraph/util/qsgsimpletexturenode.h
+++ b/src/quick/scenegraph/util/qsgsimpletexturenode.h
@@ -48,6 +48,8 @@
QT_BEGIN_NAMESPACE
+class QSGSimpleTextureNodePrivate;
+
class Q_QUICK_EXPORT QSGSimpleTextureNode : public QSGGeometryNode
{
public:
@@ -63,14 +65,28 @@ public:
void setFiltering(QSGTexture::Filtering filtering);
QSGTexture::Filtering filtering() const;
+ enum TextureCoordinatesTransformFlag {
+ NoTransform = 0x00,
+ MirrorHorizontally = 0x01,
+ MirrorVertically = 0x02
+ };
+ Q_DECLARE_FLAGS(TextureCoordinatesTransformMode, TextureCoordinatesTransformFlag)
+
+ void setTextureCoordinatesTransform(TextureCoordinatesTransformMode mode);
+ TextureCoordinatesTransformMode textureCoordinatesTransform() const;
+
private:
QSGGeometry m_geometry;
QSGOpaqueTextureMaterial m_opaque_material;
QSGTextureMaterial m_material;
QRectF m_rect;
+
+ Q_DECLARE_PRIVATE(QSGSimpleTextureNode)
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QSGSimpleTextureNode::TextureCoordinatesTransformMode)
+
QT_END_NAMESPACE
#endif // QSGSIMPLETEXTURENODE_H
diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp
index ad98fe9d47..a69f43f8d6 100644
--- a/src/quick/scenegraph/util/qsgtexture.cpp
+++ b/src/quick/scenegraph/util/qsgtexture.cpp
@@ -614,7 +614,8 @@ void QSGPlainTexture::bind()
m_dirty_texture = false;
#ifndef QSG_NO_RENDER_TIMING
- if (qsg_render_timing)
+ bool profileFrames = qsg_render_timing || QQmlProfilerService::enabled;
+ if (profileFrames)
qsg_renderer_timer.start();
#endif
@@ -628,6 +629,11 @@ void QSGPlainTexture::bind()
m_texture_size.width(),
m_texture_size.height());
}
+ if (QQmlProfilerService::enabled) {
+ QQmlProfilerService::sceneGraphFrame(
+ QQmlProfilerService::SceneGraphTextureDeletion,
+ qsg_renderer_timer.nsecsElapsed());
+ }
#endif
}
m_texture_id = 0;
@@ -645,9 +651,9 @@ void QSGPlainTexture::bind()
glBindTexture(GL_TEXTURE_2D, m_texture_id);
#ifndef QSG_NO_RENDER_TIMING
- int bindTime = 0;
- if (qsg_render_timing)
- bindTime = qsg_renderer_timer.elapsed();
+ qint64 bindTime = 0;
+ if (profileFrames)
+ bindTime = qsg_renderer_timer.nsecsElapsed();
#endif
// ### TODO: check for out-of-memory situations...
@@ -657,11 +663,13 @@ void QSGPlainTexture::bind()
QImage tmp = (m_image.format() == QImage::Format_RGB32 || m_image.format() == QImage::Format_ARGB32_Premultiplied)
? m_image
: m_image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
+ if (tmp.width() * 4 != tmp.bytesPerLine())
+ tmp = tmp.copy();
#ifndef QSG_NO_RENDER_TIMING
- int convertTime = 0;
- if (qsg_render_timing)
- convertTime = qsg_renderer_timer.elapsed();
+ qint64 convertTime = 0;
+ if (profileFrames)
+ convertTime = qsg_renderer_timer.nsecsElapsed();
#endif
updateBindOptions(m_dirty_bind_options);
@@ -684,16 +692,16 @@ void QSGPlainTexture::bind()
}
#ifndef QSG_NO_RENDER_TIMING
- int swizzleTime = 0;
- if (qsg_render_timing)
- swizzleTime = qsg_renderer_timer.elapsed();
+ qint64 swizzleTime = 0;
+ if (profileFrames)
+ swizzleTime = qsg_renderer_timer.nsecsElapsed();
#endif
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, externalFormat, GL_UNSIGNED_BYTE, tmp.constBits());
#ifndef QSG_NO_RENDER_TIMING
- int uploadTime = 0;
- if (qsg_render_timing)
- uploadTime = qsg_renderer_timer.elapsed();
+ qint64 uploadTime = 0;
+ if (profileFrames)
+ uploadTime = qsg_renderer_timer.nsecsElapsed();
#endif
@@ -704,23 +712,35 @@ void QSGPlainTexture::bind()
}
#ifndef QSG_NO_RENDER_TIMING
- int mipmapTime = 0;
+ qint64 mipmapTime = 0;
if (qsg_render_timing) {
- mipmapTime = qsg_renderer_timer.elapsed();
+ mipmapTime = qsg_renderer_timer.nsecsElapsed();
printf(" - plaintexture(%dx%d) bind=%d, convert=%d, swizzle=%d (%s->%s), upload=%d, mipmap=%d, total=%d\n",
m_texture_size.width(), m_texture_size.height(),
- bindTime,
- convertTime - bindTime,
- swizzleTime - convertTime,
+ int(bindTime/1000000),
+ int((convertTime - bindTime)/1000000),
+ int((swizzleTime - convertTime)/1000000),
externalFormat == GL_BGRA ? "BGRA" : "RGBA",
internalFormat == GL_BGRA ? "BGRA" : "RGBA",
- uploadTime - swizzleTime,
- mipmapTime - uploadTime,
+ int((uploadTime - swizzleTime)/1000000),
+ int((mipmapTime - uploadTime)/1000000),
(int) qsg_renderer_timer.elapsed());
}
+ if (QQmlProfilerService::enabled) {
+ mipmapTime = qsg_renderer_timer.nsecsElapsed();
+
+ QQmlProfilerService::sceneGraphFrame(
+ QQmlProfilerService::SceneGraphTexturePrepare,
+ bindTime,
+ convertTime - bindTime,
+ swizzleTime - convertTime,
+ uploadTime - swizzleTime,
+ mipmapTime - uploadTime);
+ }
+
#endif
diff --git a/src/quick/scenegraph/util/qsgtexture_p.h b/src/quick/scenegraph/util/qsgtexture_p.h
index 6430a93ed8..7282d4051f 100644
--- a/src/quick/scenegraph/util/qsgtexture_p.h
+++ b/src/quick/scenegraph/util/qsgtexture_p.h
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
class QSGTexturePrivate : public QObjectPrivate
{
- Q_DECLARE_PUBLIC(QSGTexture);
+ Q_DECLARE_PUBLIC(QSGTexture)
public:
QSGTexturePrivate();
diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp
index ff91109a2a..87414766e3 100644
--- a/src/quick/scenegraph/util/qsgtexturematerial.cpp
+++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp
@@ -145,7 +145,7 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa
tuple. The QSGGeometry::defaultAttributes_TexturedPoint2D returns an
attribute set compatible with this material.
- The texture to be rendered is can be set using setTexture(). How the
+ The texture to be rendered can be set using setTexture(). How the
texture should be rendered can be specified using setMipmapFiltering(),
setFiltering(), setHorizontalWrapMode() and setVerticalWrapMode().
The rendering state is set on the texture instance just before it
@@ -208,7 +208,7 @@ QSGMaterialShader *QSGOpaqueTextureMaterial::createShader() const
/*!
Sets the texture of this material to \a texture.
- The material does not take ownership over the texture.
+ The material does not take ownership of the texture.
*/
void QSGOpaqueTextureMaterial::setTexture(QSGTexture *texture)
@@ -337,7 +337,7 @@ int QSGOpaqueTextureMaterial::compare(const QSGMaterial *o) const
tuple. The QSGGeometry::defaultAttributes_TexturedPoint2D returns an
attribute set compatible with this material.
- The texture to be rendered is set using setTexture(). How the
+ The texture to be rendered can be set using setTexture(). How the
texture should be rendered can be specified using setMipmapFiltering(),
setFiltering(), setHorizontalWrapMode() and setVerticalWrapMode().
The rendering state is set on the texture instance just before it