1 /****************************************************************************
3 ** Copyright (C) 2011 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 QtGui 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 <qglobal.h> // for Q_WS_WIN define (non-PCH)
44 #include <QtGui/qpaintdevice.h>
45 #include <private/qwidget_p.h>
46 #include <private/qwindowsurface_s60_p.h>
47 #include <private/qpixmap_s60_p.h>
48 #include <private/qt_s60_p.h>
49 #include <private/qapplication_p.h>
50 #include <private/qdrawhelper_p.h>
52 #ifdef QT_GRAPHICSSYSTEM_RUNTIME
53 #include <private/qgraphicssystem_runtime_p.h>
58 struct QS60WindowSurfacePrivate
61 QList<QImage*> bufferImages;
64 TDisplayMode displayMode(bool opaque)
66 TDisplayMode mode = S60->screenDevice()->DisplayMode();
70 if (QSysInfo::symbianVersion() >= QSysInfo::SV_SF_3)
71 mode = Q_SYMBIAN_ECOLOR16MAP; // Symbian^3 WServ has support for ARGB32_PRE
73 mode = EColor16MA; // Symbian prior to Symbian^3 sw accelerates EColor16MA
78 bool blitWriteAlpha(QWidgetPrivate *widgetPrivate)
80 QWExtra *extra = widgetPrivate->extraData();
81 return extra ? extra->nativePaintMode == QWExtra::BlitWriteAlpha : false;
84 QS60WindowSurface::QS60WindowSurface(QWidget* widget)
85 : QWindowSurface(widget), d_ptr(new QS60WindowSurfacePrivate)
87 QWidgetPrivate *widgetPrivate = qt_widget_private(widget);
88 const bool opaque = widgetPrivate->isOpaque && !blitWriteAlpha(widgetPrivate);
89 TDisplayMode mode = displayMode(opaque);
90 // We create empty CFbsBitmap here -> it will be resized in setGeometry
91 CFbsBitmap *bitmap = new CFbsBitmap; // CBase derived object needs check on new
93 qt_symbian_throwIfError( bitmap->Create( TSize(0, 0), mode ) );
95 QS60PixmapData *data = new QS60PixmapData(QPixmapData::PixmapType);
97 data->fromSymbianBitmap(bitmap, true);
98 d_ptr->device = QPixmap(data);
102 QS60WindowSurface::~QS60WindowSurface()
104 #if defined(QT_GRAPHICSSYSTEM_RUNTIME) && defined(Q_SYMBIAN_SUPPORTS_SURFACES)
105 if(QApplicationPrivate::runtime_graphics_system) {
106 QRuntimeGraphicsSystem *runtimeGraphicsSystem =
107 static_cast<QRuntimeGraphicsSystem*>(QApplicationPrivate::graphics_system);
108 if(runtimeGraphicsSystem->graphicsSystemName() == QLatin1String("openvg")) {
110 // Graphics system has been switched from raster to openvg.
111 // Issue empty redraw to clear the UI surface
113 QWidget *w = window();
114 if (w->testAttribute(Qt::WA_WState_Created)) {
115 RWindow *const window = static_cast<RWindow *>(w->winId()->DrawableWindow());
116 window->BeginRedraw();
126 void QS60WindowSurface::beginPaint(const QRegion &rgn)
128 #ifdef Q_SYMBIAN_SUPPORTS_SURFACES
129 S60->wsSession().Finish();
132 QWidgetPrivate *windowPrivate = qt_widget_private(window());
133 if (!windowPrivate->isOpaque || blitWriteAlpha(windowPrivate)) {
134 QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data());
136 TDisplayMode mode = displayMode(false);
137 if (pixmapData->cfbsBitmap->DisplayMode() != mode)
138 pixmapData->convertToDisplayMode(mode);
140 pixmapData->beginDataAccess();
142 if (!windowPrivate->isOpaque) {
143 QPainter p(&pixmapData->image);
144 p.setCompositionMode(QPainter::CompositionMode_Source);
145 const QVector<QRect> rects = rgn.rects();
146 const QColor blank = Qt::transparent;
147 for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
148 p.fillRect(*it, blank);
152 pixmapData->endDataAccess();
156 void QS60WindowSurface::endPaint(const QRegion &)
158 qDeleteAll(d_ptr->bufferImages);
159 d_ptr->bufferImages.clear();
162 QImage* QS60WindowSurface::buffer(const QWidget *widget)
164 if (widget->window() != window())
167 QPaintDevice *pdev = paintDevice();
171 const QPoint off = offset(widget);
172 QImage *img = &(static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data())->image);
174 QRect rect(off, widget->size());
175 rect &= QRect(QPoint(), img->size());
180 img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8,
181 rect.width(), rect.height(),
182 img->bytesPerLine(), img->format());
183 d_ptr->bufferImages.append(img);
188 void QS60WindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &)
190 QWidget *window = widget->window();
192 QTLWExtra *topExtra = window->d_func()->maybeTopData();
194 QRect qr = region.boundingRect();
195 if (!topExtra->inExpose) {
196 topExtra->inExpose = true; // Prevent DrawNow() from calling syncBackingStore() again
197 TRect tr = qt_QRect2TRect(qr);
198 widget->winId()->DrawNow(tr);
199 topExtra->inExpose = false;
201 // This handles the case when syncBackingStore updates content outside of the
202 // original drawing rectangle. This might happen if there are pending update()
203 // events at the same time as we get a Draw() from Symbian.
204 QRect drawRect = qt_TRect2QRect(widget->winId()->DrawableWindow()->GetDrawRect());
205 if (!drawRect.contains(qr))
206 widget->winId()->DrawDeferred();
210 bool QS60WindowSurface::scroll(const QRegion &area, int dx, int dy)
212 QRect rect = area.boundingRect();
214 if (dx == 0 && dy == 0)
217 if (d_ptr->device.isNull())
220 QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
221 data->scroll(dx, dy, rect);
226 QPaintDevice* QS60WindowSurface::paintDevice()
228 return &d_ptr->device;
231 void QS60WindowSurface::setGeometry(const QRect& rect)
233 if (rect == geometry())
236 QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
237 data->resize(rect.width(), rect.height());
239 QWindowSurface::setGeometry(rect);
242 QWindowSurface::WindowSurfaceFeatures QS60WindowSurface::features() const
244 return QWindowSurface::AllFeatures;
247 CFbsBitmap* QS60WindowSurface::symbianBitmap() const
249 QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
250 return data->cfbsBitmap;