1 /****************************************************************************
3 ** Copyright (C) 2010 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 #include "qsgcontext2dtile_p.h"
44 #include <QtOpenGL/QGLFramebufferObject>
45 #include <QtOpenGL/QGLFramebufferObjectFormat>
47 QSGContext2DTile::QSGContext2DTile()
49 , m_rect(QRect(0, 0, 1, 1))
54 QSGContext2DTile::~QSGContext2DTile()
56 if (m_painter.isActive())
60 QPainter* QSGContext2DTile::createPainter(bool smooth)
62 if (m_painter.isActive())
66 m_painter.begin(m_device);
67 m_painter.resetTransform();
68 m_painter.setCompositionMode(QPainter::CompositionMode_Source);
70 #ifdef QSGCONTEXT2D_DEBUG
72 int gray = (m_rect.x() / m_rect.width() + m_rect.y() / m_rect.height()) % 2;
75 m_painter.fillRect(QRect(0, 0, m_rect.width(), m_rect.height()), QColor(v, v, v, 255));
78 m_painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing
79 | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
81 m_painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing
82 | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, false);
84 m_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
85 m_painter.translate(-m_rect.left(), -m_rect.top());
86 m_painter.setClipRect(m_rect);
87 m_painter.setClipping(false);
94 QSGContext2DFBOTile::QSGContext2DFBOTile()
100 QSGContext2DFBOTile::~QSGContext2DFBOTile()
105 void QSGContext2DFBOTile::setRect(const QRect& r)
111 if (!m_fbo || m_fbo->size() != r.size()) {
112 QGLFramebufferObjectFormat format;
113 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
114 format.setInternalTextureFormat(GL_RGBA);
115 format.setMipmap(false);
117 if (m_painter.isActive())
121 m_fbo = new QGLFramebufferObject(r.size(), format);
127 QSGContext2DImageTile::QSGContext2DImageTile()
132 QSGContext2DImageTile::~QSGContext2DImageTile()
136 void QSGContext2DImageTile::setRect(const QRect& r)
142 if (m_image.size() != r.size()) {
143 m_image = QImage(r.size(), QImage::Format_ARGB32_Premultiplied);