Remove Q_WS_*, symbian and maemo code in QtDeclarative
[profile/ivi/qtdeclarative.git] / src / declarative / scenegraph / qsgcontext.cpp
index 635b0ad..f995f9e 100644 (file)
@@ -7,29 +7,29 @@
 ** This file is part of the QtDeclarative module of the Qt Toolkit.
 **
 ** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
 ** 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.
+** 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, Nokia gives you certain additional
-** rights.  These rights are described in the Nokia Qt LGPL Exception
+** rights. These rights are described in the Nokia Qt LGPL Exception
 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 **
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
+** 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.
 **
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
 **
 **
 **
 #include <private/qsgtexture_p.h>
 #include <qsgengine.h>
 
-#include <QApplication>
-#include <QGLContext>
+#include <QGuiApplication>
+#include <QOpenGLContext>
 
 #include <private/qobject_p.h>
 #include <qmutex.h>
 
 DEFINE_BOOL_CONFIG_OPTION(qmlFlashMode, QML_FLASH_MODE)
 DEFINE_BOOL_CONFIG_OPTION(qmlTranslucentMode, QML_TRANSLUCENT_MODE)
+DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD)
 
-/*!
+/*
     Comments about this class from Gunnar:
 
     The QSGContext class is right now two things.. The first is the
@@ -78,8 +79,7 @@ DEFINE_BOOL_CONFIG_OPTION(qmlTranslucentMode, QML_TRANSLUCENT_MODE)
     If we ever move the scene graph core API into its own thing, this class
     needs to be split in two. Right now its one because we're lazy when it comes
     to defining plugin interfaces..
-
- */
+*/
 
 
 QT_BEGIN_NAMESPACE
@@ -91,29 +91,34 @@ public:
         : rootNode(0)
         , renderer(0)
         , gl(0)
+        , distanceFieldCacheManager(0)
         , flashMode(qmlFlashMode())
+        , distanceFieldDisabled(qmlDisableDistanceField())
     {
         renderAlpha = qmlTranslucentMode() ? 0.5 : 1;
     }
 
-    ~QSGContextPrivate() 
+    ~QSGContextPrivate()
     {
     }
 
     QSGRootNode *rootNode;
     QSGRenderer *renderer;
 
-    QGLContext *gl;
+    QOpenGLContext *gl;
 
     QSGEngine engine;
 
     QHash<QSGMaterialType *, QSGMaterialShader *> materials;
 
+    QSGDistanceFieldGlyphCacheManager *distanceFieldCacheManager;
+
     QMutex textureMutex;
     QList<QSGTexture *> texturesToClean;
 
     bool flashMode;
     float renderAlpha;
+    bool distanceFieldDisabled;
 };
 
 
@@ -122,7 +127,7 @@ public:
 
     \brief The QSGContext holds the scene graph entry points for one QML engine.
 
-    The context is not ready for use until it has a QGLContext. Once that happens,
+    The context is not ready for use until it has a QOpenGLContext. Once that happens,
     the scene graph population can start.
 
     \internal
@@ -143,6 +148,7 @@ QSGContext::~QSGContext()
     delete d->rootNode;
     cleanupTextures();
     qDeleteAll(d->materials.values());
+    delete d->distanceFieldCacheManager;
 }
 
 /*!
@@ -208,7 +214,7 @@ QSGRootNode *QSGContext::rootNode() const
 }
 
 
-QGLContext *QSGContext::glContext() const
+QOpenGLContext *QSGContext::glContext() const
 {
     Q_D(const QSGContext);
     return d->gl;
@@ -218,7 +224,7 @@ QGLContext *QSGContext::glContext() const
     Initializes the scene graph context with the GL context \a context. This also
     emits the ready() signal so that the QML graph can start building scene graph nodes.
  */
-void QSGContext::initialize(QGLContext *context)
+void QSGContext::initialize(QOpenGLContext *context)
 {
     Q_D(QSGContext);
 
@@ -247,14 +253,20 @@ bool QSGContext::isReady() const
 }
 
 
-void QSGContext::renderNextFrame()
+void QSGContext::renderNextFrame(QOpenGLFramebufferObject *fbo)
 {
     Q_D(QSGContext);
 
     emit d->engine.beforeRendering();
 
     cleanupTextures();
-    d->renderer->renderScene();
+
+    if (fbo) {
+        QSGBindableFbo bindable(fbo);
+        d->renderer->renderScene(bindable);
+    } else {
+        d->renderer->renderScene();
+    }
 
     emit d->engine.afterRendering();
 
@@ -281,20 +293,28 @@ QSGImageNode *QSGContext::createImageNode()
  */
 QSGGlyphNode *QSGContext::createGlyphNode()
 {
+    Q_D(QSGContext);
+
     // ### Do something with these before final release...
     static bool doSubpixel = qApp->arguments().contains(QLatin1String("--text-subpixel-antialiasing"));
+    static bool doLowQualSubpixel = qApp->arguments().contains(QLatin1String("--text-subpixel-antialiasing-lowq"));
     static bool doGray = qApp->arguments().contains(QLatin1String("--text-gray-antialiasing"));
 
-    if (QSGDistanceFieldGlyphCache::distanceFieldEnabled()) {
-        QSGGlyphNode *node = new QSGDistanceFieldGlyphNode;
-
-        if (doSubpixel)
-            node->setPreferredAntialiasingMode(QSGGlyphNode::SubPixelAntialiasing);
-        else if (doGray)
-            node->setPreferredAntialiasingMode(QSGGlyphNode::GrayAntialiasing);
-        return node;
-    } else {
+    if (d->distanceFieldDisabled) {
         return new QSGDefaultGlyphNode;
+    } else {
+        if (!d->distanceFieldCacheManager) {
+            d->distanceFieldCacheManager = new QSGDistanceFieldGlyphCacheManager(d->gl);
+            if (doSubpixel)
+                d->distanceFieldCacheManager->setDefaultAntialiasingMode(QSGGlyphNode::HighQualitySubPixelAntialiasing);
+            else if (doLowQualSubpixel)
+                d->distanceFieldCacheManager->setDefaultAntialiasingMode(QSGGlyphNode::LowQualitySubPixelAntialiasing);
+            else if (doGray)
+               d->distanceFieldCacheManager->setDefaultAntialiasingMode(QSGGlyphNode::GrayAntialiasing);
+        }
+
+        QSGGlyphNode *node = new QSGDistanceFieldGlyphNode(d->distanceFieldCacheManager);
+        return node;
     }
 }
 
@@ -302,7 +322,7 @@ QSGGlyphNode *QSGContext::createGlyphNode()
     Factory function for the scene graph renderers.
 
     The renderers are used for the toplevel renderer and once for every
-    QSGShaderEffectSource used in the QML scene.
+    QQuickShaderEffectSource used in the QML scene.
  */
 QSGRenderer *QSGContext::createRenderer()
 {
@@ -360,6 +380,16 @@ QSGTexture *QSGContext::decodeImageToTexture(QIODevice *dev,
 
 
 
+QSurfaceFormat QSGContext::defaultSurfaceFormat() const
+{
+    QSurfaceFormat format;
+    format.setDepthBufferSize(24);
+    format.setStencilBufferSize(8);
+    format.setSamples(16);
+    return format;
+}
+
+
 /*!
     Factory function for texture objects.
 
@@ -378,6 +408,21 @@ QSGTexture *QSGContext::createTexture(const QImage &image) const
 
 
 /*!
+    Returns the minimum supported framebuffer object size.
+ */
+
+QSize QSGContext::minimumFBOSize() const
+{
+#ifdef Q_OS_MAC
+    return QSize(33, 33);
+#else
+    return QSize(1, 1);
+#endif
+}
+
+
+
+/*!
     Returns a material shader for the given material.
  */
 
@@ -400,7 +445,7 @@ QSGMaterialShader *QSGContext::prepareMaterial(QSGMaterial *material)
 
 
 /*!
-    Sets weither the scene graph should render with flashing update rectangles or not
+    Sets whether the scene graph should render with flashing update rectangles or not
   */
 
 void QSGContext::setFlashModeEnabled(bool enabled)
@@ -444,6 +489,24 @@ qreal QSGContext::renderAlpha() const
 }
 
 
+/*!
+    Sets whether or not the scene graph should use the distance field technique to render text
+  */
+void QSGContext::setDistanceFieldEnabled(bool enabled)
+{
+    d_func()->distanceFieldDisabled = !enabled;
+}
+
+
+/*!
+    Returns true if the scene graph uses the distance field technique to render text
+ */
+bool QSGContext::isDistanceFieldEnabled() const
+{
+    return !d_func()->distanceFieldDisabled;
+}
+
+
 
 /*!
     Creates a new animation driver.