Fix girth of native text with grayscale AA or style

When using a grayscale glyph cache, the source data should be
interpreted differently, like in the OpenGL paint engine. We
should not do srgb gamma correction and we should use the default
blend mode. This also fixes styled text, since that will always
default to a grayscale glyph cache.

This patch ensures:
1. That we detect when the font requires grayscale AA (e.g. when
font smoothing is turned off in the OS)
2. That we interpret the source data correctly.

Task-number: QTBUG-31720
Change-Id: I600f4a28cd443caa0a8d5544d219b47436cde693
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
Fix colorization of native rendered text...

Task-number: QTBUG-33633

Change-Id: Ic7fabe36887fc19e28286ae6f4eb2f22b4211b4f
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Don't delete scene-graph atlas manager if it hasn't been created yet

QSGContext::invalidate() is called from the QSGContext destructor,
but the atlas manager is only created if QSGContext::initialize()
is called, which may not always happen.

The result was a bunch of "QCoreApplication::postEvent: Unexpected
null receiver" messages during testing.

Change-Id: I11a294d48c06d687a9f82cf1ce825063cda8ecf6
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Remove QSGContext's precompilation step.

Materials are managed solely inside the renderer now, so these
are just wasting time.

Task-number: QTBUG-33456
Change-Id: Ie320df20b7971633c257b1bd3a218e7d70e52c3d
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
Avoid infinite loop with distance fields disabled

createGlyphNode() and createNativeGlyphNode() kept calling each other
on GLES whenever QML_DISABLE_DISTANCEFIELD was set.

Change-Id: Ic1c2cfe0c4c7301f82cbbcce1cb512bd515b52ef
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Separate and fix 8/24-bit text mask materials.

The logic was a bit cluttered, trying to handle two rather
different pieces of logic in one material shader. The 8-bit
shader does not try to be fancy in any way, it just takes the
alpha * color which gives similar intensities as the distance
fields. The logic for 24-bit contains a tiny fix for opacity.

The patch also includes a change from QColor -> QVector4D and
QPointF -> QVector2D to simplify the conversion needed and
be consistent with what kind of types we use.

Task-number: QTBUG-33805
Task-number: QTBUG-33633
Task-number: QTCREATORBUG-10176
Change-Id: Ia8c464f98a1fc2c190a1d323fc21466a4d7b0dfd
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Invalidate the bounding rects when the roots change.

When roots change, matrices are updated in the nodes, so
we need to also invalidate the bounding rects for geometry
nodes.

Change-Id: I61f60ad069c3b1d018ce31c57310a1e5c4807684
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Respect DirtyForceUpdate in QSGBatchRenderer.

There is a way this could have been done slightly more efficitently.
If we moved all "combined" logic out of the scene graph and into the
Node shadow tree, we could ignore the forceupdate all
together. However, this is a quite large change for what is currently
a non-common case. It would also increase overall memory consumption a
bit as we would have superfluous combined matrix and opacity in the
QSGNodes.

Task-number: QTBUG-33838
Change-Id: I06c486ace2be15bef1f1dc72a8b41cb649d7c813
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
All matrices in a batch need to be 2D safe when merging.

If we merge geometry nodes that make actual use of the
z-coordinate, this information becomes lost when merging
and the result is that we end up with an arbitrary
wrongfully applied transformation to the merged element.

Task-number: QTBUG-33897
Change-Id: I6129243e9bb890949023c35dc6b7bce30d31709a
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Be explicit about precision specifiers.

Task-number: QTBUG-33912
Change-Id: I4b6988e7385bcf9167e5f44d0bde7c80fbc1e117
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Make tiled images not use atlas.

The imagenode has two code paths, one fast path relying on
GL_REPEAT and one slower based on one quad per internal tile.
The quad path is very costly and should be avoided at all cost
so extract the texture from the atlas when we have tiling.

Task-number: QTBUG-33310
Task-number: QTBUG-29786

Change-Id: I952749e86dc407db43b168db3ab880eb93329a7a
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Prevent badly formed texture nodes in the scene graph.

A texture based node without a valid texture is not allowed,
as the material and the renderer will only tolerate
well-formed nodes. If a node is missing any part of its material
state it should not be in the scene graph in the first place.

Because of an "optimization" in QSGDefaultImageNode::setTexture
and QSGSimpleTextureNode::setTexture, we must temporarily set
the texture to 0 to ensure that it gets updated properly. This
temporarily puts the node into an invalid state which can lead
to crashes when QSGNode::markDirty() reaches the renderer.

Task-number: QTBUG-34062
Change-Id: Ic1735c9b974b90b3684262de9589133c961bac6e
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Don't use reserved keyword "texture" as uniform variable name

The "texture" keyword is a function name in OpenGL core profile. This
commit is in preparation for making the Qt Quick 2 renderer and
materials work with a core profile context.

Change-Id: Iad243e64ab8db739fc46b85bb626bdb8b9ceb208
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Fix tst_rendernode for fullscreen platforms

Change-Id: Ib82aef04b7748ecdf148c3d9ec60ad15b3dfd7cb
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Stabilize tst_rendernode.

Center windows on screen, add QSKIP for screen depth, add error message
to color comparison.

Change-Id: I03d600a4810f27654e0b971b19631ba51c9f6874
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Fix rendernode bug and enable rendernode test.

The bug in the renderer was that the viewport was set before
we called the render node, leaving us with the viewport
set by the render node as opposed to the viewport of the
renderer.

The render node API is a crude and intrusive hack which was added for
webkit back in the day. With the introduction of webengine it becomes
less relevant, but it should still work.

Change-Id: I66a1e3047e018ad6c0bb28044851e9fc65da59cc
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Prevent bogus warning message flood on nVidia driver related to mipmaps

When using QtQuick2 Text elements on nVidia with the KHR_debug extension
active we get flooded by messages of the form:

"Texture state usage warning: Waste of memory: Texture 0 has mipmaps,
while its min filter is inconsistent with mipmaps."

This is totally bogus as there really aren't any mipmaps created here.
However, it is very annoying and hides genuine errors. Setting the
mipmap max level to 0 works around the issue. nVidia seem unwilling
to fix it in the driver.

Change-Id: I56632ba1ee777fb54fc8d17e1828669baa183a55
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Be consistent when checking for blocked subtrees.

This code was a leftover from before we started sending notifications
for changes in QSGNode::isSubtreeBlocked. It would accumulate opacity
and return blocked for nested blocks, even when
QSGNode::isSubtreeBlocked would return non-blocked. The result is that
the renderer would not respond correctly to DirtySubtreeBlocked and
would not add/remove shadow nodes for that subtree.

Change-Id: Iea83e89c6da4d0a3cb3ee7ea74cd96b7cda9fd6d
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Fix rendering bug with batched translucent elements.

When one item in a batch of other translucent items would
change opacity, we need to rebuild batches under the current
root as all items in a batch are expected to have the same
opacity.

Task-number: QTBUG-34311
Change-Id: I2b9db19f05bd3a82be65cfa8a91e9398e8d58d0f
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Tolerate NaN in the geometry without asserting

If we come across NaN geometry, we treat it as spanning
the entire viewport, similar to other geometries with
undefined geometry.

Task-number: QTBUG-34520
Change-Id: Ia4171f9f13d876c6c587043ad7decaa19bb85f01
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>