1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef ADAPTATIONINTERFACES_H
43 #define ADAPTATIONINTERFACES_H
45 #include <QtQuick/qsgnode.h>
46 #include <QtQuick/qsgtexture.h>
47 #include <QtCore/qobject.h>
48 #include <QtCore/qrect.h>
49 #include <QtGui/qbrush.h>
50 #include <QtGui/qcolor.h>
51 #include <QtCore/qsharedpointer.h>
52 #include <QtGui/qglyphrun.h>
53 #include <QtCore/qurl.h>
54 #include <private/qfontengine_p.h>
55 #include <QtGui/private/qdatabuffer_p.h>
56 #include <private/qopenglcontext_p.h>
59 #include <QtQuick/private/qquicktext_p.h>
67 class TextureReference;
68 class QSGDistanceFieldGlyphCacheManager;
69 class QSGDistanceFieldGlyphNode;
71 // TODO: Rename from XInterface to AbstractX.
72 class Q_QUICK_EXPORT QSGRectangleNode : public QSGGeometryNode
75 virtual void setRect(const QRectF &rect) = 0;
76 virtual void setColor(const QColor &color) = 0;
77 virtual void setPenColor(const QColor &color) = 0;
78 virtual void setPenWidth(qreal width) = 0;
79 virtual void setGradientStops(const QGradientStops &stops) = 0;
80 virtual void setRadius(qreal radius) = 0;
81 virtual void setAligned(bool aligned) = 0;
83 virtual void update() = 0;
87 class Q_QUICK_EXPORT QSGImageNode : public QSGGeometryNode
90 virtual void setTargetRect(const QRectF &rect) = 0;
91 virtual void setSourceRect(const QRectF &rect) = 0;
92 virtual void setTexture(QSGTexture *texture) = 0;
94 virtual void setMipmapFiltering(QSGTexture::Filtering filtering) = 0;
95 virtual void setFiltering(QSGTexture::Filtering filtering) = 0;
96 virtual void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) = 0;
97 virtual void setVerticalWrapMode(QSGTexture::WrapMode wrapMode) = 0;
99 virtual void update() = 0;
103 class Q_QUICK_EXPORT QSGGlyphNode : public QSGGeometryNode
106 enum AntialiasingMode
109 LowQualitySubPixelAntialiasing,
110 HighQualitySubPixelAntialiasing
113 virtual void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) = 0;
114 virtual void setColor(const QColor &color) = 0;
115 virtual void setStyle(QQuickText::TextStyle style) = 0;
116 virtual void setStyleColor(const QColor &color) = 0;
117 virtual QPointF baseLine() const = 0;
119 virtual QRectF boundingRect() const { return m_bounding_rect; }
120 virtual void setBoundingRect(const QRectF &bounds) { m_bounding_rect = bounds; }
122 virtual void setPreferredAntialiasingMode(AntialiasingMode) = 0;
124 virtual void update() = 0;
127 QRectF m_bounding_rect;
130 class Q_QUICK_EXPORT QSGDistanceFieldGlyphCache
133 QSGDistanceFieldGlyphCache(QSGDistanceFieldGlyphCacheManager *man, QOpenGLContext *c, const QRawFont &font);
134 virtual ~QSGDistanceFieldGlyphCache();
142 bool isNull() const { return width == 0 || height == 0; }
153 TexCoord() : x(0), y(0), width(-1), height(-1), xMargin(0), yMargin(0) { }
155 bool isNull() const { return width <= 0 || height <= 0; }
156 bool isValid() const { return width >= 0 && height >= 0; }
163 Texture() : textureId(0), size(QSize()) { }
164 bool operator == (const Texture &other) const { return textureId == other.textureId; }
167 const QSGDistanceFieldGlyphCacheManager *manager() const { return m_manager; }
169 const QRawFont &font() const { return m_font; }
171 qreal fontScale() const;
172 int distanceFieldRadius() const;
173 int glyphCount() const { return m_glyphCount; }
174 bool doubleGlyphResolution() const { return m_cacheData->doubleGlyphResolution; }
176 Metrics glyphMetrics(glyph_t glyph);
177 TexCoord glyphTexCoord(glyph_t glyph) const;
178 const Texture *glyphTexture(glyph_t glyph) const;
180 void populate(const QVector<glyph_t> &glyphs);
181 void release(const QVector<glyph_t> &glyphs);
185 void registerGlyphNode(QSGDistanceFieldGlyphNode *node);
186 void unregisterGlyphNode(QSGDistanceFieldGlyphNode *node);
189 struct GlyphPosition {
194 virtual void requestGlyphs(const QSet<glyph_t> &glyphs) = 0;
195 virtual void storeGlyphs(const QHash<glyph_t, QImage> &glyphs) = 0;
196 virtual void referenceGlyphs(const QSet<glyph_t> &glyphs) = 0;
197 virtual void releaseGlyphs(const QSet<glyph_t> &glyphs) = 0;
199 void setGlyphsPosition(const QList<GlyphPosition> &glyphs);
200 void setGlyphsTexture(const QVector<glyph_t> &glyphs, const Texture &tex);
201 void markGlyphsToRender(const QVector<glyph_t> &glyphs);
202 void removeGlyph(glyph_t glyph);
204 void updateTexture(GLuint oldTex, GLuint newTex, const QSize &newTexSize);
206 bool containsGlyph(glyph_t glyph) const;
211 struct GlyphCacheData : public QOpenGLSharedResource {
212 QList<Texture> textures;
213 QHash<glyph_t, Texture*> glyphTextures;
214 QHash<glyph_t, TexCoord> texCoords;
215 QDataBuffer<glyph_t> pendingGlyphs;
216 QHash<glyph_t, QPainterPath> glyphPaths;
217 bool doubleGlyphResolution;
218 QLinkedList<QSGDistanceFieldGlyphNode*> m_registeredNodes;
219 QHash<glyph_t, quint32> glyphRefCount;
221 GlyphCacheData(QOpenGLContext *ctx)
222 : QOpenGLSharedResource(ctx->shareGroup())
224 , doubleGlyphResolution(false)
227 void invalidateResource()
230 glyphTextures.clear();
234 void freeResource(QOpenGLContext *)
239 QSGDistanceFieldGlyphCacheManager *m_manager;
242 QRawFont m_referenceFont;
245 QHash<glyph_t, Metrics> m_metrics;
247 GlyphCacheData *cacheData();
248 GlyphCacheData *m_cacheData;
249 static QHash<QString, QOpenGLMultiGroupSharedResource> m_caches_data;