1
/****************************************************************************
3
** Copyright (C) 2009 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 examples of the Qt Toolkit.
9
** $QT_BEGIN_LICENSE:LGPL$
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
40
****************************************************************************/
42
#include "svgalibpaintengine.h"
48
SvgalibPaintEngine::SvgalibPaintEngine()
52
SvgalibPaintEngine::~SvgalibPaintEngine()
57
bool SvgalibPaintEngine::begin(QPaintDevice *dev)
66
setClip(QRect(0, 0, device->width(), device->height()));
71
return QRasterPaintEngine::begin(dev);
76
bool SvgalibPaintEngine::end()
78
gl_setclippingwindow(0, 0, device->width() - 1, device->height() - 1);
79
return QRasterPaintEngine::end();
84
void SvgalibPaintEngine::updateState(const QPaintEngineState &state)
86
QPaintEngine::DirtyFlags flags = state.state();
88
if (flags & DirtyTransform) {
89
matrix = state.matrix();
90
simpleMatrix = (matrix.m12() == 0 && matrix.m21() == 0);
93
if (flags & DirtyPen) {
95
simplePen = (pen.width() == 0 || pen.widthF() <= 1)
96
&& (pen.style() == Qt::NoPen || pen.style() == Qt::SolidLine)
97
&& (pen.color().alpha() == 255);
100
if (flags & DirtyBrush) {
101
brush = state.brush();
102
simpleBrush = (brush.style() == Qt::SolidPattern
103
|| brush.style() == Qt::NoBrush)
104
&& (brush.color().alpha() == 255);
107
if (flags & DirtyClipRegion)
108
setClip(state.clipRegion());
110
if (flags & DirtyClipEnabled) {
111
clipEnabled = state.isClipEnabled();
115
if (flags & DirtyClipPath) {
120
if (flags & DirtyCompositionMode) {
121
const QPainter::CompositionMode m = state.compositionMode();
122
sourceOver = (m == QPainter::CompositionMode_SourceOver);
125
if (flags & DirtyOpacity)
126
opaque = (state.opacity() == 256);
128
if (flags & DirtyHints)
129
aliased = !(state.renderHints() & QPainter::Antialiasing);
131
QRasterPaintEngine::updateState(state);
136
void SvgalibPaintEngine::setClip(const QRegion ®ion)
138
if (region.isEmpty())
139
clip = QRect(0, 0, device->width(), device->height());
141
clip = matrix.map(region) & QRect(0, 0, device->width(), device->height());
148
void SvgalibPaintEngine::updateClip()
150
QRegion clipRegion = QRect(0, 0, device->width(), device->height());
152
if (!systemClip().isEmpty())
153
clipRegion &= systemClip();
157
simpleClip = (clipRegion.rects().size() <= 1);
159
const QRect r = clipRegion.boundingRect();
160
gl_setclippingwindow(r.left(), r.top(),
167
void SvgalibPaintEngine::drawRects(const QRect *rects, int rectCount)
169
const bool canAccelerate = simplePen && simpleBrush && simpleMatrix
170
&& simpleClip && opaque && aliased
172
if (!canAccelerate) {
173
QRasterPaintEngine::drawRects(rects, rectCount);
177
for (int i = 0; i < rectCount; ++i) {
178
const QRect r = matrix.mapRect(rects[i]);
179
if (brush != Qt::NoBrush) {
180
gl_fillbox(r.left(), r.top(), r.width(), r.height(),
181
brush.color().rgba());
183
if (pen != Qt::NoPen) {
184
const int c = pen.color().rgba();
185
gl_hline(r.left(), r.top(), r.right(), c);
186
gl_hline(r.left(), r.bottom(), r.right(), c);
187
gl_line(r.left(), r.top(), r.left(), r.bottom(), c);
188
gl_line(r.right(), r.top(), r.right(), r.bottom(), c);