summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-12-03 12:37:42 +0100
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-12-03 12:37:42 +0100
commitc7350d331901cd95dc3eac69afd0efc7ca04155f (patch)
tree747a590c1e841a5917e918b3885319536f0360e0
parent1bae710f3dac38325727282b0ede964bb3de9434 (diff)
moved adaptation layers into QSGContext
-rw-r--r--TODO5
-rw-r--r--src/adaptationlayers/adaptationinterfaces.cpp100
-rw-r--r--src/adaptationlayers/adaptationinterfaces.h258
-rw-r--r--src/adaptationlayers/adaptationlayer.cpp61
-rw-r--r--src/adaptationlayers/adaptationlayer.h217
-rw-r--r--src/adaptationlayers/adaptationlayers.pri4
-rw-r--r--src/adaptationlayers/default/default_adaptationlayer.cpp82
-rw-r--r--src/adaptationlayers/default/default_adaptationlayer.h65
-rw-r--r--src/adaptationlayers/default/default_glyphnode.h2
-rw-r--r--src/adaptationlayers/default/default_rectanglenode.cpp11
-rw-r--r--src/adaptationlayers/default/default_rectanglenode.h7
-rw-r--r--src/adaptationlayers/default/default_texturemanager.h2
-rw-r--r--src/adaptationlayers/default/default_texturenode.cpp3
-rw-r--r--src/adaptationlayers/default/default_texturenode.h2
-rw-r--r--src/canvas/qxgraphicsview.cpp69
-rw-r--r--src/canvas/qxgraphicsview.h8
-rw-r--r--src/canvas/qxgraphicsview_p.h11
-rw-r--r--src/effects/shadereffectitem.cpp9
-rw-r--r--src/effects/shadereffectitem.h7
-rw-r--r--src/graphicsitems/qxborderimage.cpp2
-rw-r--r--src/graphicsitems/qximage.cpp4
-rw-r--r--src/graphicsitems/qximage_p_p.h2
-rw-r--r--src/graphicsitems/qximagebase_p_p.h2
-rw-r--r--src/graphicsitems/qxitem_p.h3
-rw-r--r--src/graphicsitems/qxrectangle.cpp2
-rw-r--r--src/graphicsitems/qxrectangle_p_p.h1
-rw-r--r--src/graphicsitems/qxtext.cpp2
-rw-r--r--src/scenegraph/convenience/textnode.cpp31
-rw-r--r--src/scenegraph/convenience/textnode.h6
-rw-r--r--src/scenegraph/convenience/utilities.cpp1
-rw-r--r--src/scenegraph/convenience/utilities.h2
-rw-r--r--src/scenegraph/coreapi/node.cpp1
-rw-r--r--src/scenegraph/coreapi/qsgcontext.cpp92
-rw-r--r--src/scenegraph/coreapi/qsgcontext.h25
34 files changed, 482 insertions, 617 deletions
diff --git a/TODO b/TODO
index 60bf747..ffad6cd 100644
--- a/TODO
+++ b/TODO
@@ -35,4 +35,9 @@
default implementations
qmlrenderer
+- Make QxImage push normalized source coords into TextureNode so we don't have to renormalize for
+ every geometry change. It also makes a lot more sense, now that TextureNode doesn't know the
+ size of the original pixmap anymore...
+- Fix any reference to "// ### gunnar: port properly". Some of these will be pointless to port
+ as the upgrade to new QML items is pretty close, so we'll have to evaluate those individually..
diff --git a/src/adaptationlayers/adaptationinterfaces.cpp b/src/adaptationlayers/adaptationinterfaces.cpp
deleted file mode 100644
index b777b69..0000000
--- a/src/adaptationlayers/adaptationinterfaces.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Qt scene graph research project.
-**
-** $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.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** 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.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "adaptationinterfaces.h"
-
-
-/*!
- Constructs a new texture reference with status set to Null
- */
-TextureReference::TextureReference()
- : m_status(Null)
- , m_texture_id(0)
- , m_sub_rect(0, 0, 1, 1)
- , m_has_alpha(false)
- , m_owns_texture(false)
- , m_mipmap(false)
-{
-}
-
-TextureReference::~TextureReference()
-{
- if (m_owns_texture) {
- glDeleteTextures(1, (GLuint *) &m_texture_id);
- }
-}
-
-void TextureReference::setStatus(Status s)
-{
- m_status = s;
-
- Q_ASSERT(s != Ready || (m_texture_id > 0 && !m_texture_size.isEmpty()));
-
- emit statusChanged(s);
-}
-
-/*!
- Performs a synchronous upload of \a image using the specified \a hints.
-
- The upload is done using the QGLContext::bindTexture().
- */
-const TextureReference *TextureManager::uploadImage(const QImage &image, UploadHints hints)
-{
- QGLContext *context = const_cast<QGLContext *>(QGLContext::currentContext());
-
- QGLContext::BindOptions options = QGLContext::PremultipliedAlphaBindOption;
- if (hints & GenerateMipmapUploadHint)
- options |= QGLContext::MipmapBindOption;
-
- int id = context->bindTexture(image,
- GL_TEXTURE_2D,
- image.hasAlphaChannel() ? GL_RGBA : GL_RGB,
- options);
-
- TextureReference *ref = new TextureReference();
- ref->setTextureId(id);
- ref->setOwnsTexture(true);
- ref->setAlphaChannel(image.hasAlphaChannel());
- ref->setTextureSize(image.size());
- ref->setStatus(TextureReference::Ready);
-
- return ref;
-}
diff --git a/src/adaptationlayers/adaptationinterfaces.h b/src/adaptationlayers/adaptationinterfaces.h
deleted file mode 100644
index fead7d9..0000000
--- a/src/adaptationlayers/adaptationinterfaces.h
+++ /dev/null
@@ -1,258 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Qt scene graph research project.
-**
-** $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.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** 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.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ADAPTATIONINTERFACES_H
-#define ADAPTATIONINTERFACES_H
-
-#include <QtCore/qobject.h>
-#include <QtCore/qrect.h>
-#include <QtGui/qcolor.h>
-#include <QtCore/qsharedpointer.h>
-#include <QtGui/qglyphs.h>
-#include <QtCore/qurl.h>
-
-#include "node.h"
-
-class Node;
-class QImage;
-class TextureReference;
-
-// TODO: Rename from XInterface to AbstractX.
-
-class RectangleNodeInterface : public GeometryNode
-{
-public:
- RectangleNodeInterface() : m_radius(0), m_opacity(1), m_pen_width(0) { }
-
- virtual void setRect(const QRectF &rect) = 0;
- QRectF rect() const { return m_rect; }
-
- virtual void setColor(const QColor &color) = 0;
- QColor color() const { return m_color; }
-
- virtual void setPenColor(const QColor &color) = 0;
- QColor penColor() const { return m_pen_color; }
-
- virtual void setPenWidth(int width) = 0;
- int penWidth() const { return m_pen_width; }
-
- virtual void setOpacity(qreal opacity) = 0;
- qreal opacity() const { return m_opacity; }
-
- virtual void setGradientStops(const QGradientStops &stops) = 0;
- QGradientStops gradientStops() const { return m_gradient_stops; }
-
- virtual void setRadius(qreal radius) = 0;
- qreal radius() const { return m_radius; }
-
-protected:
- QRectF m_rect;
- QGradientStops m_gradient_stops;
- QColor m_color;
- QColor m_pen_color;
- qreal m_radius;
- qreal m_opacity;
- int m_pen_width;
-};
-
-class TextureNodeInterface : public GeometryNode
-{
-public:
- TextureNodeInterface() : m_texture(0), m_opacity(1), m_clamp_to_edge(true), m_linear_filtering(false) { }
-
- virtual void setRect(const QRectF &rect) = 0;
- QRectF rect() const { return m_rect; }
-
- virtual void setSourceRect(const QRectF &rect) = 0;
- QRectF sourceRect() const { return m_source_rect; }
-
- virtual void setOpacity(qreal opacity) = 0;
- qreal opacity() const { return m_opacity; }
-
- virtual void setTexture(const TextureReference *ref) = 0;
- const TextureReference *texture() const;
-
- virtual void setClampToEdge(bool clampToEdge) = 0;
- bool clampToEdge() const { return m_clamp_to_edge; }
-
- virtual void setLinearFiltering(bool linearFiltering) = 0;
- bool linearFiltering() const { return m_linear_filtering; }
-
-protected:
- const TextureReference *m_texture;
- QRectF m_rect;
- QRectF m_source_rect;
- qreal m_opacity;
- bool m_clamp_to_edge;
- bool m_linear_filtering;
-
-};
-
-class TextureReference : public QObject
-{
- Q_OBJECT
-public:
- enum Status {
- Null,
- Ready,
- Loading,
- Error
- };
-
- TextureReference();
- ~TextureReference();
-
- void setTextureId(int id) { m_texture_id = id; }
- int textureId() const { return m_texture_id; }
-
- void setTextureSize(const QSize &size) { m_texture_size = size; }
- QSize textureSize() const { return m_texture_size; }
-
- void setSubRect(const QRectF &subrect) { m_sub_rect = subrect; }
- QRectF subRect() const { return m_sub_rect; }
-
- void setAlphaChannel(bool hasAlpha) { m_has_alpha = hasAlpha; }
- bool hasAlphaChannel() const { return m_has_alpha; }
-
- void setOwnsTexture(bool owns) { m_owns_texture = owns; }
- bool ownsTexture() const { return m_owns_texture; }
-
- void setMipmaps(bool mipmapped) { m_mipmap = mipmapped; }
- bool hasMipmaps() const { return m_mipmap; }
-
- void setStatus(Status s);
- Status status() const { return m_status; }
-
-signals:
- void statusChanged(Status status);
-
-protected:
-
- Status m_status;
- int m_texture_id;
-
- QSize m_texture_size;
- QRectF m_sub_rect;
-
- uint m_has_alpha : 1;
- uint m_owns_texture : 1;
- uint m_mipmap : 1;
-};
-
-class TextureManager
-{
-public:
- enum UploadHint {
- SynchronousUploadHint = 0x0001,
- CanUseAtlasUploadHint = 0x0002,
-
- GenerateMipmapUploadHint = 0x0004,
-
- DefaultUploadHints = 0
- };
- Q_DECLARE_FLAGS(UploadHints, UploadHint);
-
- virtual ~TextureManager() { };
-
- virtual const TextureReference *requestUploadedTexture(const QImage &image, UploadHints hints = DefaultUploadHints) = 0;
- const TextureReference *uploadImage(const QImage &image, UploadHints hints);
-};
-
-
-//typedef QSharedPointer<const QGLTexture2D> QGLTexture2DConstPtr;
-//typedef QSharedPointer<QGLTexture2D> QGLTexture2DPtr;
-
-//class TextureAtlasInterface
-//{
-//public:
-// enum Flag
-// {
-// DynamicFlag = 0x01 // Set if images are added to the texture atlas every few frames.
-// };
-
-// TextureAtlasInterface(uint flags) : m_flags(flags) { }
-// virtual ~TextureAtlasInterface() { }
-
-// virtual QGLTexture2DConstPtr texture() = 0;
-// virtual QRect allocate(const QImage &image, bool clampToEdge) = 0;
-// virtual void deallocate(const QRect &rect) = 0;
-
-// uint flags() const { return m_flags; }
-//protected:
-// uint m_flags;
-//};
-
-
-class GlyphNodeInterface: public GeometryNode
-{
-public:
- GlyphNodeInterface() : m_opacity(1.0) {}
-
- virtual void setGlyphs(const QPointF &position, const QGlyphs &glyphs) = 0;
- QPointF position() const { return m_position; }
- QGlyphs glyphs() const { return m_glyphs; }
-
- virtual void setOpacity(qreal opacity) = 0;
- qreal opacity() const { return m_opacity; }
-
- virtual void setColor(const QColor &color) = 0;
- QColor color() const { return m_color; }
-
- virtual QPointF baseLine() const = 0;
-
-protected:
- qreal m_opacity;
- QGlyphs m_glyphs;
- QPointF m_position;
- QColor m_color;
-};
-
-class AdaptationLayerInterface
-{
-public:
- virtual RectangleNodeInterface *createRectangleNode() = 0;
- virtual TextureNodeInterface *createTextureNode() = 0;
- virtual GlyphNodeInterface *createGlyphNode() = 0;
- virtual Renderer *createRenderer() = 0;
- virtual TextureManager *textureManager() = 0;
-};
-
-#endif
diff --git a/src/adaptationlayers/adaptationlayer.cpp b/src/adaptationlayers/adaptationlayer.cpp
index 704cb1b..152156f 100644
--- a/src/adaptationlayers/adaptationlayer.cpp
+++ b/src/adaptationlayers/adaptationlayer.cpp
@@ -41,24 +41,59 @@
#include "adaptationlayer.h"
-#include "default/default_adaptationlayer.h"
-
-#ifdef QT_OPENGL_ES_2
-
-Q_GLOBAL_STATIC(DefaultAdaptationLayer, qt_gles2_adaptation_layer)
+/*!
+ Constructs a new texture reference with status set to Null
+ */
+TextureReference::TextureReference()
+ : m_status(Null)
+ , m_texture_id(0)
+ , m_sub_rect(0, 0, 1, 1)
+ , m_has_alpha(false)
+ , m_owns_texture(false)
+ , m_mipmap(false)
+{
+}
-AdaptationLayerInterface *qt_adaptation_layer()
+TextureReference::~TextureReference()
{
- return qt_gles2_adaptation_layer();
+ if (m_owns_texture) {
+ glDeleteTextures(1, (GLuint *) &m_texture_id);
+ }
}
-#else
+void TextureReference::setStatus(Status s)
+{
+ m_status = s;
-Q_GLOBAL_STATIC(DefaultAdaptationLayer, qt_default_adaptation_layer)
+ Q_ASSERT(s != Ready || (m_texture_id > 0 && !m_texture_size.isEmpty()));
-AdaptationLayerInterface *qt_adaptation_layer()
-{
- return qt_default_adaptation_layer();
+ emit statusChanged(s);
}
-#endif
+/*!
+ Performs a synchronous upload of \a image using the specified \a hints.
+
+ The upload is done using the QGLContext::bindTexture().
+ */
+const TextureReference *TextureManager::uploadImage(const QImage &image, UploadHints hints)
+{
+ QGLContext *context = const_cast<QGLContext *>(QGLContext::currentContext());
+
+ QGLContext::BindOptions options = QGLContext::PremultipliedAlphaBindOption;
+ if (hints & GenerateMipmapUploadHint)
+ options |= QGLContext::MipmapBindOption;
+
+ int id = context->bindTexture(image,
+ GL_TEXTURE_2D,
+ image.hasAlphaChannel() ? GL_RGBA : GL_RGB,
+ options);
+
+ TextureReference *ref = new TextureReference();
+ ref->setTextureId(id);
+ ref->setOwnsTexture(true);
+ ref->setAlphaChannel(image.hasAlphaChannel());
+ ref->setTextureSize(image.size());
+ ref->setStatus(TextureReference::Ready);
+
+ return ref;
+}
diff --git a/src/adaptationlayers/adaptationlayer.h b/src/adaptationlayers/adaptationlayer.h
index 80d139d..fead7d9 100644
--- a/src/adaptationlayers/adaptationlayer.h
+++ b/src/adaptationlayers/adaptationlayer.h
@@ -39,11 +39,220 @@
**
****************************************************************************/
-#ifndef ADAPTATIONLAYER_H
-#define ADAPTATIONLAYER_H
+#ifndef ADAPTATIONINTERFACES_H
+#define ADAPTATIONINTERFACES_H
-#include "adaptationinterfaces.h"
+#include <QtCore/qobject.h>
+#include <QtCore/qrect.h>
+#include <QtGui/qcolor.h>
+#include <QtCore/qsharedpointer.h>
+#include <QtGui/qglyphs.h>
+#include <QtCore/qurl.h>
-AdaptationLayerInterface *qt_adaptation_layer();
+#include "node.h"
+
+class Node;
+class QImage;
+class TextureReference;
+
+// TODO: Rename from XInterface to AbstractX.
+
+class RectangleNodeInterface : public GeometryNode
+{
+public:
+ RectangleNodeInterface() : m_radius(0), m_opacity(1), m_pen_width(0) { }
+
+ virtual void setRect(const QRectF &rect) = 0;
+ QRectF rect() const { return m_rect; }
+
+ virtual void setColor(const QColor &color) = 0;
+ QColor color() const { return m_color; }
+
+ virtual void setPenColor(const QColor &color) = 0;
+ QColor penColor() const { return m_pen_color; }
+
+ virtual void setPenWidth(int width) = 0;
+ int penWidth() const { return m_pen_width; }
+
+ virtual void setOpacity(qreal opacity) = 0;
+ qreal opacity() const { return m_opacity; }
+
+ virtual void setGradientStops(const QGradientStops &stops) = 0;
+ QGradientStops gradientStops() const { return m_gradient_stops; }
+
+ virtual void setRadius(qreal radius) = 0;
+ qreal radius() const { return m_radius; }
+
+protected:
+ QRectF m_rect;
+ QGradientStops m_gradient_stops;
+ QColor m_color;
+ QColor m_pen_color;
+ qreal m_radius;
+ qreal m_opacity;
+ int m_pen_width;
+};
+
+class TextureNodeInterface : public GeometryNode
+{
+public:
+ TextureNodeInterface() : m_texture(0), m_opacity(1), m_clamp_to_edge(true), m_linear_filtering(false) { }
+
+ virtual void setRect(const QRectF &rect) = 0;
+ QRectF rect() const { return m_rect; }
+
+ virtual void setSourceRect(const QRectF &rect) = 0;
+ QRectF sourceRect() const { return m_source_rect; }
+
+ virtual void setOpacity(qreal opacity) = 0;
+ qreal opacity() const { return m_opacity; }
+
+ virtual void setTexture(const TextureReference *ref) = 0;
+ const TextureReference *texture() const;
+
+ virtual void setClampToEdge(bool clampToEdge) = 0;
+ bool clampToEdge() const { return m_clamp_to_edge; }
+
+ virtual void setLinearFiltering(bool linearFiltering) = 0;
+ bool linearFiltering() const { return m_linear_filtering; }
+
+protected:
+ const TextureReference *m_texture;
+ QRectF m_rect;
+ QRectF m_source_rect;
+ qreal m_opacity;
+ bool m_clamp_to_edge;
+ bool m_linear_filtering;
+
+};
+
+class TextureReference : public QObject
+{
+ Q_OBJECT
+public:
+ enum Status {
+ Null,
+ Ready,
+ Loading,
+ Error
+ };
+
+ TextureReference();
+ ~TextureReference();
+
+ void setTextureId(int id) { m_texture_id = id; }
+ int textureId() const { return m_texture_id; }
+
+ void setTextureSize(const QSize &size) { m_texture_size = size; }
+ QSize textureSize() const { return m_texture_size; }
+
+ void setSubRect(const QRectF &subrect) { m_sub_rect = subrect; }
+ QRectF subRect() const { return m_sub_rect; }
+
+ void setAlphaChannel(bool hasAlpha) { m_has_alpha = hasAlpha; }
+ bool hasAlphaChannel() const { return m_has_alpha; }
+
+ void setOwnsTexture(bool owns) { m_owns_texture = owns; }
+ bool ownsTexture() const { return m_owns_texture; }
+
+ void setMipmaps(bool mipmapped) { m_mipmap = mipmapped; }
+ bool hasMipmaps() const { return m_mipmap; }
+
+ void setStatus(Status s);
+ Status status() const { return m_status; }
+
+signals:
+ void statusChanged(Status status);
+
+protected:
+
+ Status m_status;
+ int m_texture_id;
+
+ QSize m_texture_size;
+ QRectF m_sub_rect;
+
+ uint m_has_alpha : 1;
+ uint m_owns_texture : 1;
+ uint m_mipmap : 1;
+};
+
+class TextureManager
+{
+public:
+ enum UploadHint {
+ SynchronousUploadHint = 0x0001,
+ CanUseAtlasUploadHint = 0x0002,
+
+ GenerateMipmapUploadHint = 0x0004,
+
+ DefaultUploadHints = 0
+ };
+ Q_DECLARE_FLAGS(UploadHints, UploadHint);
+
+ virtual ~TextureManager() { };
+
+ virtual const TextureReference *requestUploadedTexture(const QImage &image, UploadHints hints = DefaultUploadHints) = 0;
+ const TextureReference *uploadImage(const QImage &image, UploadHints hints);
+};
+
+
+//typedef QSharedPointer<const QGLTexture2D> QGLTexture2DConstPtr;
+//typedef QSharedPointer<QGLTexture2D> QGLTexture2DPtr;
+
+//class TextureAtlasInterface
+//{
+//public:
+// enum Flag
+// {
+// DynamicFlag = 0x01 // Set if images are added to the texture atlas every few frames.
+// };
+
+// TextureAtlasInterface(uint flags) : m_flags(flags) { }
+// virtual ~TextureAtlasInterface() { }
+
+// virtual QGLTexture2DConstPtr texture() = 0;
+// virtual QRect allocate(const QImage &image, bool clampToEdge) = 0;
+// virtual void deallocate(const QRect &rect) = 0;
+
+// uint flags() const { return m_flags; }
+//protected:
+// uint m_flags;
+//};
+
+
+class GlyphNodeInterface: public GeometryNode
+{
+public:
+ GlyphNodeInterface() : m_opacity(1.0) {}
+
+ virtual void setGlyphs(const QPointF &position, const QGlyphs &glyphs) = 0;
+ QPointF position() const { return m_position; }
+ QGlyphs glyphs() const { return m_glyphs; }
+
+ virtual void setOpacity(qreal opacity) = 0;
+ qreal opacity() const { return m_opacity; }
+
+ virtual void setColor(const QColor &color) = 0;
+ QColor color() const { return m_color; }
+
+ virtual QPointF baseLine() const = 0;
+
+protected:
+ qreal m_opacity;
+ QGlyphs m_glyphs;
+ QPointF m_position;
+ QColor m_color;
+};
+
+class AdaptationLayerInterface
+{
+public:
+ virtual RectangleNodeInterface *createRectangleNode() = 0;
+ virtual TextureNodeInterface *createTextureNode() = 0;
+ virtual GlyphNodeInterface *createGlyphNode() = 0;
+ virtual Renderer *createRenderer() = 0;
+ virtual TextureManager *textureManager() = 0;
+};
#endif
diff --git a/src/adaptationlayers/adaptationlayers.pri b/src/adaptationlayers/adaptationlayers.pri
index cc2ed71..b72c427 100644
--- a/src/adaptationlayers/adaptationlayers.pri
+++ b/src/adaptationlayers/adaptationlayers.pri
@@ -1,9 +1,7 @@
INCLUDEPATH += $$PWD
HEADERS += \
- $$PWD/adaptationinterfaces.h \
$$PWD/adaptationlayer.h \
- $$PWD/default/default_adaptationlayer.h \
$$PWD/default/default_texturenode.h \
$$PWD/default/default_rectanglenode.h \
$$PWD/default/default_glyphnode.h \
@@ -12,10 +10,8 @@ HEADERS += \
SOURCES += \
$$PWD/adaptationlayer.cpp \
- $$PWD/default/default_adaptationlayer.cpp \
$$PWD/default/default_texturenode.cpp \
$$PWD/default/default_rectanglenode.cpp \
$$PWD/default/default_glyphnode.cpp \
$$PWD/default/default_glyphnode_p.cpp \
$$PWD/default/default_texturemanager.cpp \
- adaptationlayers/adaptationinterfaces.cpp
diff --git a/src/adaptationlayers/default/default_adaptationlayer.cpp b/src/adaptationlayers/default/default_adaptationlayer.cpp
deleted file mode 100644
index b43f72d..0000000
--- a/src/adaptationlayers/default/default_adaptationlayer.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Qt scene graph research project.
-**
-** $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.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** 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.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "default_adaptationlayer.h"
-
-#include "default_texturenode.h"
-#include "default_texturemanager.h"
-#include "default_rectanglenode.h"
-#include "default_glyphnode.h"
-
-#include "qmlrenderer.h"
-#include "geometry.h"
-
-DefaultAdaptationLayer::DefaultAdaptationLayer()
- : m_texture_manager(0)
-{
-}
-
-RectangleNodeInterface *DefaultAdaptationLayer::createRectangleNode()
-{
- return new DefaultRectangleNode(DefaultRectangleNode::PreferTextureMaterial);
-}
-
-TextureNodeInterface *DefaultAdaptationLayer::createTextureNode()
-{
- return new DefaultTextureNode;
-}
-
-TextureManager *DefaultAdaptationLayer::textureManager()
-{
- if (!m_texture_manager)
- m_texture_manager = new DefaultTextureManager();
- return m_texture_manager;
-}
-
-GlyphNodeInterface *DefaultAdaptationLayer::createGlyphNode()
-{
- return new DefaultGlyphNode;
-}
-
-Renderer *DefaultAdaptationLayer::createRenderer()
-{
- return new QMLRenderer();
-}
diff --git a/src/adaptationlayers/default/default_adaptationlayer.h b/src/adaptationlayers/default/default_adaptationlayer.h
deleted file mode 100644
index f2a9e3b..0000000
--- a/src/adaptationlayers/default/default_adaptationlayer.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Qt scene graph research project.
-**
-** $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.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** 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.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef DEFAULT_ADAPTATIONLAYER_H
-#define DEFAULT_ADAPTATIONLAYER_H
-
-#include "adaptationinterfaces.h"
-
-class DefaultTextureManager;
-
-class DefaultAdaptationLayer : public AdaptationLayerInterface
-{
-public:
- DefaultAdaptationLayer();
-
- virtual RectangleNodeInterface *createRectangleNode();
- virtual TextureNodeInterface *createTextureNode();
- virtual GlyphNodeInterface *createGlyphNode();
- virtual Renderer *createRenderer();
-
- virtual TextureManager *textureManager();
-
-private:
- DefaultTextureManager *m_texture_manager;
-};
-
-#endif
diff --git a/src/adaptationlayers/default/default_glyphnode.h b/src/adaptationlayers/default/default_glyphnode.h
index 1090b31..b8e477d 100644
--- a/src/adaptationlayers/default/default_glyphnode.h
+++ b/src/adaptationlayers/default/default_glyphnode.h
@@ -42,7 +42,7 @@
#ifndef DEFAULT_GLYPHNODE_H
#define DEFAULT_GLYPHNODE_H
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
#include <node.h>
class QGlyphs;
diff --git a/src/adaptationlayers/default/default_rectanglenode.cpp b/src/adaptationlayers/default/default_rectanglenode.cpp
index ed5094b..0412f2d 100644
--- a/src/adaptationlayers/default/default_rectanglenode.cpp
+++ b/src/adaptationlayers/default/default_rectanglenode.cpp
@@ -46,14 +46,16 @@
#include "vertexcolormaterial.h"
#include "texturematerial.h"
-#include "adaptationlayer.h"
+
+#include "qsgcontext.h"
#include <QtCore/qmath.h>
-DefaultRectangleNode::DefaultRectangleNode(MaterialPreference preference)
+DefaultRectangleNode::DefaultRectangleNode(MaterialPreference preference, QSGContext *context)
: m_material_preference(preference)
, m_gradient_texture(0)
, m_gradient_is_opaque(true)
+ , m_context(context)
{
m_border_material.setColor(m_pen_color);
m_border_material.setOpacity(m_opacity);
@@ -677,9 +679,8 @@ void DefaultRectangleNode::updateGradientTexture()
line[i] = QColor::fromRgbF(c.redF() * c.alphaF(), c.greenF() * c.alphaF(), c.blueF() * c.alphaF(), c.alphaF()).rgba();
}
- m_gradient_texture =
- qt_adaptation_layer()->textureManager()->requestUploadedTexture(image,
- TextureManager::SynchronousUploadHint);
+ m_gradient_texture = m_context->textureManager()->requestUploadedTexture(image,
+ TextureManager::SynchronousUploadHint);
Q_ASSERT(TextureMaterial::is(m_fill_material) || TextureMaterialWithOpacity::is(m_fill_material));
diff --git a/src/adaptationlayers/default/default_rectanglenode.h b/src/adaptationlayers/default/default_rectanglenode.h
index d2a8894..cd69fae 100644
--- a/src/adaptationlayers/default/default_rectanglenode.h
+++ b/src/adaptationlayers/default/default_rectanglenode.h
@@ -43,12 +43,13 @@
#ifndef DEFAULT_RECTANGLENODE_H
#define DEFAULT_RECTANGLENODE_H
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
#include "flatcolormaterial.h"
#include "utilities.h"
class AbstractEffect;
+class QSGContext;
class DefaultRectangleNode : public RectangleNodeInterface
{
@@ -64,7 +65,7 @@ public:
UpdateGradientTexture = 0x02
};
- DefaultRectangleNode(MaterialPreference preference);
+ DefaultRectangleNode(MaterialPreference preference, QSGContext *context);
~DefaultRectangleNode();
virtual void setRect(const QRectF &rect);
@@ -86,6 +87,8 @@ private:
FlatColorMaterial m_border_material;
const TextureReference *m_gradient_texture;
bool m_gradient_is_opaque;
+
+ QSGContext *m_context;
};
#endif
diff --git a/src/adaptationlayers/default/default_texturemanager.h b/src/adaptationlayers/default/default_texturemanager.h
index d78a37b..aacc820 100644
--- a/src/adaptationlayers/default/default_texturemanager.h
+++ b/src/adaptationlayers/default/default_texturemanager.h
@@ -42,7 +42,7 @@
#ifndef DEFAULTTEXTUREMANAGER_H
#define DEFAULTTEXTUREMANAGER_H
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
class DefaultTextureManager : public TextureManager
{
diff --git a/src/adaptationlayers/default/default_texturenode.cpp b/src/adaptationlayers/default/default_texturenode.cpp
index ae1bb41..3deada1 100644
--- a/src/adaptationlayers/default/default_texturenode.cpp
+++ b/src/adaptationlayers/default/default_texturenode.cpp
@@ -39,10 +39,7 @@
**
****************************************************************************/
-#include "adaptationinterfaces.h"
-
#include "default_texturenode.h"
-#include "adaptationlayer.h"
#include <qmath.h>
#include <qvarlengtharray.h>
diff --git a/src/adaptationlayers/default/default_texturenode.h b/src/adaptationlayers/default/default_texturenode.h
index 44310f6..fb43ec3 100644
--- a/src/adaptationlayers/default/default_texturenode.h
+++ b/src/adaptationlayers/default/default_texturenode.h
@@ -43,7 +43,7 @@
#ifndef DEFAULT_PIXMAPNODE_H
#define DEFAULT_PIXMAPNODE_H
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
#include "texturematerial.h"
#include "utilities.h"
diff --git a/src/canvas/qxgraphicsview.cpp b/src/canvas/qxgraphicsview.cpp
index fb965c1..1d302c1 100644
--- a/src/canvas/qxgraphicsview.cpp
+++ b/src/canvas/qxgraphicsview.cpp
@@ -113,7 +113,7 @@ void QxGraphicsViewPrivate::execute()
root = go;
QxItemPrivate *op = QxItemPrivate::get(root);
op->view = q;
- sg.rootNode()->appendChildNode(&op->transformNode);
+ sg->rootNode()->appendChildNode(&op->transformNode);
q->resize(go->width(), go->height());
q->setResizeMode(QxGraphicsView::SizeRootObjectToView);
@@ -217,6 +217,12 @@ void QxGraphicsView::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e)
+ if (!d->sg) {
+ qWarning("QxGraphicsView::paintEvent: painting without a scene graph...");
+ return;
+ }
+
+
#ifdef Q_WS_QPA
QPlatformGLContext *ctx = window()->platformWindow()->glContext();
#else
@@ -229,9 +235,9 @@ void QxGraphicsView::paintEvent(QPaintEvent *e)
emit frameStarted();
- d->sg.renderer()->setDeviceRect(rect());
- d->sg.renderer()->setProjectMatrixToDeviceRect();
- d->sg.renderer()->renderScene();
+ d->sg->renderer()->setDeviceRect(rect());
+ d->sg->renderer()->setProjectMatrixToDeviceRect();
+ d->sg->renderer()->renderScene();
#ifndef Q_WS_QPA
// printf("QxGraphicsView: Swapping...\n");
@@ -540,7 +546,7 @@ QUrl QxGraphicsView::source() const
void QxGraphicsView::setSource(const QUrl &url)
{
d->source = url;
- if (d->sg.isReady())
+ if (d->sg && d->sg->isReady())
d->execute();
}
@@ -556,15 +562,60 @@ void QxGraphicsView::initializeGL()
}
#endif
+/*!
+ Returns the scene graph context used by this view.
+
+ Unless explicitely set, there won't be a context available until
+ after the view has constructed its own GL context. Depending on
+ the platform, this can happen in the constructor or just before
+ the first call to paintEvent().
+ */
+QSGContext *QxGraphicsView::sceneGraphContext() const
+{
+ return d->sg;
+}
+
+/*!
+ Sets the scene graph context to be used for this view.
+
+ The scene graph context must not be initialized.
+ */
+void QxGraphicsView::setSceneGraphContext(QSGContext *context)
+{
+ if (context->isReady()) {
+ qWarning("QxGraphicsView::setSGContext: context is already initialized");
+ return;
+ }
+
+ if (d->sg) {
+ qWarning("QxGraphicsView::setSGContext: view already has a scene graph context");
+ return;
+ }
+
+ d->sg = context;
+}
+
+/*!
+ Called when there is a GL context ready to initialize the scene graph context
+ and bind together the various things.
+
+ Right now, this function is responsible for calling execute, as we don't have the
+ proper hooks in the QxItems to respond to the "scene graph is ready, start buidling nodes"
+ signal.
+ */
void QxGraphicsView::initializeSceneGraph()
{
+ // If the user didn't override with a custom context, use the default one.
+ if (!d->sg)
+ d->sg = new QSGContext();
+
QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext());
- d->sg.initialize(ctx);
+ d->sg->initialize(ctx);
- d->sg.renderer()->setDeviceRect(rect());
- d->sg.renderer()->setProjectMatrixToDeviceRect();
+ d->sg->renderer()->setDeviceRect(rect());
+ d->sg->renderer()->setProjectMatrixToDeviceRect();
- connect(d->sg.renderer(), SIGNAL(sceneGraphChanged()), this, SLOT(maybeUpdate()));
+ connect(d->sg->renderer(), SIGNAL(sceneGraphChanged()), this, SLOT(maybeUpdate()));
// If we have a source to load, but didn't yet load it...
if (!d->source.isEmpty() && !d->component)
diff --git a/src/canvas/qxgraphicsview.h b/src/canvas/qxgraphicsview.h
index 0b5dc8d..212b4af 100644
--- a/src/canvas/qxgraphicsview.h
+++ b/src/canvas/qxgraphicsview.h
@@ -48,13 +48,12 @@
#include "qmlscene_global.h"
-#include "qsgcontext.h"
-
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecontext.h>
class QxItem;
class QxGraphicsViewPrivate;
+class QSGContext;
class QT_SCENEGRAPH_EXPORT QxGraphicsView : public
#ifdef Q_WS_QPA
@@ -73,11 +72,14 @@ public:
QDeclarativeEngine* engine() const;
QDeclarativeContext* rootContext() const;
- QSGContext *scenegraphContext() const;
+ void setSceneGraphContext(QSGContext *context);
+ QSGContext *sceneGraphContext() const;
QUrl source() const;
void setSource(const QUrl&url);
+
+
enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView };
ResizeMode resizeMode() const;
void setResizeMode(ResizeMode);
diff --git a/src/canvas/qxgraphicsview_p.h b/src/canvas/qxgraphicsview_p.h
index be109ae..ce62a35 100644
--- a/src/canvas/qxgraphicsview_p.h
+++ b/src/canvas/qxgraphicsview_p.h
@@ -58,7 +58,14 @@ class QxGraphicsViewPrivate
{
public:
QxGraphicsViewPrivate()
- : root(0), component(0), mouseGrabber(0), focusItem(0), resizeMode(QxGraphicsView::SizeViewToRootObject) { }
+ : root(0)
+ , component(0)
+ , mouseGrabber(0)
+ , focusItem(0)
+ , resizeMode(QxGraphicsView::SizeViewToRootObject)
+ , sg(0)
+ {
+ }
~QxGraphicsViewPrivate();
QxGraphicsView *q;
@@ -87,7 +94,7 @@ public:
void execute();
QSize rootObjectSize() const;
- QSGContext sg;
+ QSGContext *sg;
QUrl source;
diff --git a/src/effects/shadereffectitem.cpp b/src/effects/shadereffectitem.cpp
index 77483a0..1d23f53 100644
--- a/src/effects/shadereffectitem.cpp
+++ b/src/effects/shadereffectitem.cpp
@@ -45,7 +45,7 @@
#include "material.h"
#include "qxitem_p.h"
-#include "adaptationlayer.h"
+#include "qsgcontext.h"
#include <QtCore/qsignalmapper.h>
#include <QtOpenGL/qglframebufferobject.h>
@@ -188,6 +188,7 @@ ShaderEffectSource::ShaderEffectSource(QObject *parent)
, m_dirtyTexture(true)
, m_dirtySceneGraph(true)
{
+ m_context = QSGContext::current;
}
ShaderEffectSource::~ShaderEffectSource()
@@ -217,7 +218,7 @@ void ShaderEffectSource::setSourceItem(QxItem *item)
m_sourceItem = item;
if (m_sourceItem && !m_renderer) {
- m_renderer = qt_adaptation_layer()->createRenderer();
+ m_renderer = m_context->createRenderer();
connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markSceneGraphDirty()));
}
@@ -491,7 +492,7 @@ void ShaderEffectSource::updateSizeAndTexture()
m_size.setHeight(image.height());
emit heightChanged();
}
- TextureManager *tm = qt_adaptation_layer()->textureManager();
+ TextureManager *tm = m_context->textureManager();
TextureManager::UploadHints hints = TextureManager::SynchronousUploadHint;
if (m_mipmap != None)
hints |= TextureManager::GenerateMipmapUploadHint;
@@ -768,6 +769,7 @@ void ShaderEffectItem::setSource(QVariant var, int index)
if (source.ownedByEffect)
delete source.source;
source.source = new ShaderEffectSource;
+ source.source->setSceneGraphContext(QxItemPrivate::get(this)->view->sceneGraphContext());
source.ownedByEffect = true;
source.source->setSourceImage(url);
}
@@ -778,6 +780,7 @@ void ShaderEffectItem::setSource(QVariant var, int index)
if (source.ownedByEffect)
delete source.source;
source.source = new ShaderEffectSource;
+ source.source->setSceneGraphContext(QxItemPrivate::get(this)->view->sceneGraphContext());
source.ownedByEffect = true;
source.source->setSourceItem(static_cast<QxItem *>(obj));
break;
diff --git a/src/effects/shadereffectitem.h b/src/effects/shadereffectitem.h
index 9cf0a2d..e20769e 100644
--- a/src/effects/shadereffectitem.h
+++ b/src/effects/shadereffectitem.h
@@ -45,10 +45,11 @@
#include "qxitem.h"
#include "effectnode.h"
#include "material.h"
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
#include <QtCore/qpointer.h>
+class QSGContext;
class QSignalMapper;
class CustomShaderMaterialData;
class QGLFramebufferObject;
@@ -90,6 +91,9 @@ public:
ShaderEffectSource(QObject *parent = 0);
virtual ~ShaderEffectSource();
+ QSGContext *sceneGraphContext() const { return m_context; }
+ void setSceneGraphContext(QSGContext *context) { m_context = context; }
+
QxItem *sourceItem() const { return m_sourceItem.data(); }
void setSourceItem(QxItem *item);
@@ -165,6 +169,7 @@ private:
const TextureReference *m_texture;
QGLFramebufferObject *m_fbo;
Renderer *m_renderer;
+ QSGContext *m_context;
int m_refs;
uint m_dirtyTexture : 1; // Causes update no matter what.
uint m_dirtySceneGraph : 1; // Causes update if not static.
diff --git a/src/graphicsitems/qxborderimage.cpp b/src/graphicsitems/qxborderimage.cpp
index 76e377a..c2af4e5 100644
--- a/src/graphicsitems/qxborderimage.cpp
+++ b/src/graphicsitems/qxborderimage.cpp
@@ -340,7 +340,7 @@ void QxBorderImagePrivate::updatePixmap()
pix.height() - border->bottom() - border->top());
if (!texture) {
- texture = qt_adaptation_layer()->textureManager()->requestUploadedTexture(pix.pixmap().toImage(),
+ texture = view->sceneGraphContext()->textureManager()->requestUploadedTexture(pix.pixmap().toImage(),
TextureManager::SynchronousUploadHint);
} // ### gunnar: does not support changing images...
diff --git a/src/graphicsitems/qximage.cpp b/src/graphicsitems/qximage.cpp
index 075da68..7a2afc4 100644
--- a/src/graphicsitems/qximage.cpp
+++ b/src/graphicsitems/qximage.cpp
@@ -194,11 +194,11 @@ void QxImagePrivate::update()
}
if (!node) {
- node = qt_adaptation_layer()->createTextureNode();
+ node = QSGContext::current->createTextureNode();
}
if (!texture) {
- texture = qt_adaptation_layer()->textureManager()->requestUploadedTexture(pix.pixmap().toImage(),
+ texture = QSGContext::current->textureManager()->requestUploadedTexture(pix.pixmap().toImage(),
TextureManager::SynchronousUploadHint);
}
diff --git a/src/graphicsitems/qximage_p_p.h b/src/graphicsitems/qximage_p_p.h
index 7fcf331..b8469c4 100644
--- a/src/graphicsitems/qximage_p_p.h
+++ b/src/graphicsitems/qximage_p_p.h
@@ -55,7 +55,7 @@
#include "qxitem_p.h"
#include "qximagebase_p_p.h"
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
class QxImagePrivate : public QxImageBasePrivate
{
diff --git a/src/graphicsitems/qximagebase_p_p.h b/src/graphicsitems/qximagebase_p_p.h
index 103d847..bca583f 100644
--- a/src/graphicsitems/qximagebase_p_p.h
+++ b/src/graphicsitems/qximagebase_p_p.h
@@ -55,7 +55,7 @@
#include "qxitem_p.h"
#include "private/qdeclarativepixmapcache_p.h"
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
#include <QtCore/QPointer>
class QNetworkReply;
diff --git a/src/graphicsitems/qxitem_p.h b/src/graphicsitems/qxitem_p.h
index ead8ca0..bf623b5 100644
--- a/src/graphicsitems/qxitem_p.h
+++ b/src/graphicsitems/qxitem_p.h
@@ -75,10 +75,11 @@
#include <QtCore/qlist.h>
#include <QtCore/qdebug.h>
+#include "qxgraphicsview.h"
+#include "qsgcontext.h"
QT_BEGIN_NAMESPACE
-class QxGraphicsView;
class QNetworkReply;
class QxItemKeyFilter;
class QxClipNode;
diff --git a/src/graphicsitems/qxrectangle.cpp b/src/graphicsitems/qxrectangle.cpp
index 6d240c5..7f14153 100644
--- a/src/graphicsitems/qxrectangle.cpp
+++ b/src/graphicsitems/qxrectangle.cpp
@@ -239,7 +239,7 @@ void QxRectangle::componentComplete()
QxItem::componentComplete();
Q_ASSERT(d->node == 0);
- d->node = qt_adaptation_layer()->createRectangleNode();
+ d->node = QSGContext::current->createRectangleNode();
d->node->setColor(d->color);
d->node->setRadius(d->radius);
d->node->setRect(QRectF(0, 0, width(), height()));
diff --git a/src/graphicsitems/qxrectangle_p_p.h b/src/graphicsitems/qxrectangle_p_p.h
index 7ed4997..d8c9cef 100644
--- a/src/graphicsitems/qxrectangle_p_p.h
+++ b/src/graphicsitems/qxrectangle_p_p.h
@@ -54,7 +54,6 @@
//
#include "qxitem_p.h"
-#include "adaptationinterfaces.h"
#include "adaptationlayer.h"
class QxGradient;
diff --git a/src/graphicsitems/qxtext.cpp b/src/graphicsitems/qxtext.cpp
index 75d9fdb..cf22a24 100644
--- a/src/graphicsitems/qxtext.cpp
+++ b/src/graphicsitems/qxtext.cpp
@@ -477,7 +477,7 @@ void QxText::componentComplete()
Q_D(QxText);
QxItem::componentComplete();
- d->node = new TextNode;
+ d->node = new TextNode(QSGContext::current);
d->node->setText(d->text);
d->node->setFont(d->font);
d->node->setColor(d->color);
diff --git a/src/scenegraph/convenience/textnode.cpp b/src/scenegraph/convenience/textnode.cpp
index 9d3880c..af09f62 100644
--- a/src/scenegraph/convenience/textnode.cpp
+++ b/src/scenegraph/convenience/textnode.cpp
@@ -43,6 +43,8 @@
#include "solidrectnode.h"
#include "adaptationlayer.h"
+#include "qsgcontext.h"
+
#include <qmath.h>
#include <qtextdocument.h>
#include <qtextlayout.h>
@@ -55,13 +57,14 @@
/*!
Creates an empty TextNode
*/
-TextNode::TextNode()
+TextNode::TextNode(QSGContext *context)
: m_opacity(1.0),
m_usePixmapCache(false), m_richText(false), m_linearFiltering(false), m_layoutDirty(true),
m_textFormat(Qt::AutoText), m_wrapMode(QTextOption::NoWrap), m_elideMode(Qt::ElideNone),
m_alignment(Qt::AlignTop | Qt::AlignLeft), m_textStyle(TextNode::NormalTextStyle),
m_textDocument(0), m_textLayout(0),
m_idealContentsWidth(0.0), m_widthRestriction(-1.0), m_heightRestriction(-1.0)
+ , m_context(context)
{
#if defined(QML_RUNTIME_TESTING)
description = "text";
@@ -428,7 +431,7 @@ void TextNode::addTextDecorations(const QPointF &position, const QFont &font, co
GlyphNodeInterface *TextNode::addGlyphs(const QPointF &position, const QGlyphs &glyphs, const QColor &color)
{
- GlyphNodeInterface *node = qt_adaptation_layer()->createGlyphNode();
+ GlyphNodeInterface *node = m_context->createGlyphNode();
node->setGlyphs(position, glyphs);
node->setColor(color);
node->setOpacity(m_opacity);
@@ -817,19 +820,19 @@ void TextNode::updateNodes()
return;
if (m_usePixmapCache) {
- QPixmap pixmap = generatedPixmap();
- if (pixmap.isNull())
- return;
-
- TextureNodeInterface *pixmapNode = qt_adaptation_layer()->createTextureNode();
// ### gunnar: port properly
- pixmapNode->setRect(pixmap.rect());
- pixmapNode->setSourceRect(pixmap.rect());
- pixmapNode->setOpacity(m_opacity);
- pixmapNode->setClampToEdge(true);
- pixmapNode->setLinearFiltering(m_linearFiltering);
-
- appendChildNode(pixmapNode);
+// QPixmap pixmap = generatedPixmap();
+// if (pixmap.isNull())
+// return;
+
+// TextureNodeInterface *pixmapNode = m_context->createTextureNode();
+// pixmapNode->setRect(pixmap.rect());
+// pixmapNode->setSourceRect(pixmap.rect());
+// pixmapNode->setOpacity(m_opacity);
+// pixmapNode->setClampToEdge(true);
+// pixmapNode->setLinearFiltering(m_linearFiltering);
+
+// appendChildNode(pixmapNode);
} else {
if (m_text.isEmpty())
return;
diff --git a/src/scenegraph/convenience/textnode.h b/src/scenegraph/convenience/textnode.h
index 1fed573..4bff94a 100644
--- a/src/scenegraph/convenience/textnode.h
+++ b/src/scenegraph/convenience/textnode.h
@@ -49,10 +49,12 @@ class GlyphNodeInterface;
class QTextBlock;
class QColor;
class QTextDocument;
+class QSGContext;
+
class TextNode : public TransformNode
{
public:
- TextNode();
+ TextNode(QSGContext *);
~TextNode();
enum UpdateFlags {
@@ -179,6 +181,8 @@ private:
qreal m_idealContentsWidth;
qreal m_widthRestriction;
qreal m_heightRestriction;
+
+ QSGContext *m_context;
};
#endif // TEXTNODE_H
diff --git a/src/scenegraph/convenience/utilities.cpp b/src/scenegraph/convenience/utilities.cpp
index ea36666..82017f9 100644
--- a/src/scenegraph/convenience/utilities.cpp
+++ b/src/scenegraph/convenience/utilities.cpp
@@ -44,7 +44,6 @@
#include "flatcolormaterial.h"
#include "vertexcolormaterial.h"
#include "qgltexture2d_p.h"
-#include "adaptationlayer.h"
#include <QtGui>
#include <QGLShaderProgram>
diff --git a/src/scenegraph/convenience/utilities.h b/src/scenegraph/convenience/utilities.h
index 4e41556..ff323eb 100644
--- a/src/scenegraph/convenience/utilities.h
+++ b/src/scenegraph/convenience/utilities.h
@@ -44,7 +44,7 @@
#include "qgltexture2d.h"
#include "areaallocator.h"
-#include "adaptationinterfaces.h"
+#include "adaptationlayer.h"
#include "qmlscene_global.h"
diff --git a/src/scenegraph/coreapi/node.cpp b/src/scenegraph/coreapi/node.cpp
index d9a4cca..3c3e3dc 100644
--- a/src/scenegraph/coreapi/node.cpp
+++ b/src/scenegraph/coreapi/node.cpp
@@ -45,7 +45,6 @@
#include "nodeupdater_p.h"
#include "material.h"
#include <qglattributevalue.h>
-#include "adaptationlayer.h"
#include "limits.h"
diff --git a/src/scenegraph/coreapi/qsgcontext.cpp b/src/scenegraph/coreapi/qsgcontext.cpp
index 4927dbe..f8fde55 100644
--- a/src/scenegraph/coreapi/qsgcontext.cpp
+++ b/src/scenegraph/coreapi/qsgcontext.cpp
@@ -1,7 +1,12 @@
#include "qsgcontext.h"
#include "renderer.h"
#include "node.h"
-#include "default/default_adaptationlayer.h"
+
+#include "qmlrenderer.h"
+#include "default/default_rectanglenode.h"
+#include "default/default_texturenode.h"
+#include "default/default_texturemanager.h"
+#include "default/default_glyphnode.h"
#include <private/qobject_p.h>
@@ -11,14 +16,13 @@ public:
QSGContextPrivate()
: rootNode(0)
, renderer(0)
- , adaptationLayer(0)
, gl(0)
{
}
RootNode *rootNode;
Renderer *renderer;
- AdaptationLayerInterface *adaptationLayer;
+ TextureManager *textureManager;
QGLContext *gl;
};
@@ -64,24 +68,7 @@ QGLContext *QSGContext::glContext() const
return d->gl;
}
-
-void QSGContext::setAdaptationLayer(AdaptationLayerInterface *adapt)
-{
- Q_D(QSGContext);
- if (isReady()) {
- qWarning("QSGContext::setAdaptationLayer: adaptation layer needs to be set before initalizing");
- return;
- }
- d->adaptationLayer = adapt;
-}
-
-
-AdaptationLayerInterface *QSGContext::adaptationLayer() const
-{
- Q_D(const QSGContext);
- return d->adaptationLayer;
-}
-
+QSGContext *QSGContext::current;
/*!
Initializes the scene graph context with the GL context \a context. This also
@@ -95,10 +82,7 @@ void QSGContext::initialize(QGLContext *context)
d->gl = context;
- if (!d->adaptationLayer)
- d->adaptationLayer = new DefaultAdaptationLayer();
-
- d->renderer = d->adaptationLayer->createRenderer();
+ d->renderer = createRenderer();
d->renderer->setClearColor(Qt::white);
d->rootNode = new RootNode();
@@ -106,9 +90,24 @@ void QSGContext::initialize(QGLContext *context)
d->renderer->setRootNode(d->rootNode);
+ d->textureManager = createTextureManager();
+
+ current = this;
+
emit ready();
}
+/*!
+ Returns the texture manager for this scene graphc context. The
+ texture manager is constructed through one call to createTextureManager()
+ during the scene graph context's initialization
+ */
+TextureManager *QSGContext::textureManager() const
+{
+ Q_D(const QSGContext);
+ return d->textureManager;
+}
+
/*!
Returns if the scene graph context is ready or not, meaning that it has a valid
@@ -119,3 +118,46 @@ bool QSGContext::isReady() const
Q_D(const QSGContext);
return d->gl;
}
+
+/*!
+ Factory function for scene graph backends of the Rectangle element.
+ */
+RectangleNodeInterface *QSGContext::createRectangleNode()
+{
+ return new DefaultRectangleNode(DefaultRectangleNode::PreferTextureMaterial, this);
+}
+
+/*!
+ Factory function for scene graph backends of the Image element.
+ */
+TextureNodeInterface *QSGContext::createTextureNode()
+{
+ return new DefaultTextureNode;
+}
+
+/*!
+ Factory function for scene graph backends of the Text elements;
+ */
+GlyphNodeInterface *QSGContext::createGlyphNode()
+{
+ return new DefaultGlyphNode;
+}
+
+/*!
+ Factory function for the scene graph renderers.
+
+ The renderers are used for the toplevel renderer and once for every
+ ShaderEffectSource used in the QML scene.
+ */
+Renderer *QSGContext::createRenderer()
+{
+ return new QMLRenderer;
+}
+
+/*!
+ Factory function for the texture manager to be used for this scene graph.
+ */
+TextureManager *QSGContext::createTextureManager()
+{
+ return new DefaultTextureManager;
+}
diff --git a/src/scenegraph/coreapi/qsgcontext.h b/src/scenegraph/coreapi/qsgcontext.h
index 7430ebe..01772ee 100644
--- a/src/scenegraph/coreapi/qsgcontext.h
+++ b/src/scenegraph/coreapi/qsgcontext.h
@@ -5,12 +5,17 @@
#include <QGLContext>
-#include "adaptationlayer.h"
-#include "adaptationinterfaces.h"
+#include "node.h"
+#include "qmlscene_global.h"
class QSGContextPrivate;
+class RectangleNodeInterface;
+class TextureNodeInterface;
+class GlyphNodeInterface;
+class Renderer;
+class TextureManager;
-class QSGContext : public QObject
+class QT_SCENEGRAPH_EXPORT QSGContext : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QSGContext);
@@ -22,19 +27,23 @@ public:
Renderer *renderer() const;
+ TextureManager *textureManager() const;
+
void setRootNode(RootNode *node);
RootNode *rootNode() const;
QGLContext *glContext() const;
- // ### Make adaptation layer and SGContext the same thing...
- // move the virtual construct funtions into this and let the
- // default be the implementation of the default adaptation layer.
- void setAdaptationLayer(AdaptationLayerInterface *adapt);
- AdaptationLayerInterface *adaptationLayer() const;
+ static QSGContext *current; // Evil nasty hack!! Get rid of this!
bool isReady() const;
+ virtual RectangleNodeInterface *createRectangleNode();
+ virtual TextureNodeInterface *createTextureNode();
+ virtual GlyphNodeInterface *createGlyphNode();
+ virtual Renderer *createRenderer();
+ virtual TextureManager *createTextureManager();
+
signals:
void ready();
};