1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qglobal.h> // for Q_WS_WIN define (non-PCH)
43 
44 #include <QtGui/qpaintdevice.h>
45 #include <private/qwidget_p.h>
46 #include <private/qwindowsurface_s60_p.h>
47 #include <private/qpixmap_raster_symbian_p.h>
48 #include <private/qt_s60_p.h>
49 #include <private/qapplication_p.h>
50 #include <private/qdrawhelper_p.h>
51 
52 #ifdef QT_GRAPHICSSYSTEM_RUNTIME
53 #include <private/qgraphicssystem_runtime_p.h>
54 #endif
55 
56 QT_BEGIN_NAMESPACE
57 
58 struct QS60WindowSurfacePrivate
59 {
60     QPixmap device;
61     QList<QImage*> bufferImages;
62 };
63 
displayMode(bool opaque)64 TDisplayMode displayMode(bool opaque)
65 {
66     TDisplayMode mode = S60->screenDevice()->DisplayMode();
67     if (opaque) {
68         mode = EColor16MU;
69     } else  {
70         if (QSysInfo::symbianVersion() >= QSysInfo::SV_SF_3)
71             mode = Q_SYMBIAN_ECOLOR16MAP; // Symbian^3 WServ has support for ARGB32_PRE
72         else
73             mode = EColor16MA; // Symbian prior to Symbian^3 sw accelerates EColor16MA
74     }
75     return mode;
76 }
77 
blitWriteAlpha(QWidgetPrivate * widgetPrivate)78 bool blitWriteAlpha(QWidgetPrivate *widgetPrivate)
79 {
80     QWExtra *extra = widgetPrivate->extraData();
81     return extra ? extra->nativePaintMode == QWExtra::BlitWriteAlpha : false;
82 }
83 
QS60WindowSurface(QWidget * widget)84 QS60WindowSurface::QS60WindowSurface(QWidget* widget)
85     : QWindowSurface(widget), d_ptr(new QS60WindowSurfacePrivate)
86 {
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
92     Q_CHECK_PTR(bitmap);
93     qt_symbian_throwIfError( bitmap->Create( TSize(0, 0), mode ) );
94 
95     QSymbianRasterPixmapData *data = new QSymbianRasterPixmapData(QPixmapData::PixmapType);
96     if (data) {
97         data->fromSymbianBitmap(bitmap, true);
98         d_ptr->device = QPixmap(data);
99     }
100 }
101 
~QS60WindowSurface()102 QS60WindowSurface::~QS60WindowSurface()
103 {
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")) {
109 
110             // Graphics system has been switched from raster to openvg.
111             // Issue empty redraw to clear the UI surface
112 
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();
117                 window->EndRedraw();
118             }
119         }
120     }
121 #endif
122 
123     delete d_ptr;
124 }
125 
beginPaint(const QRegion & rgn)126 void QS60WindowSurface::beginPaint(const QRegion &rgn)
127 {
128 #ifdef Q_SYMBIAN_SUPPORTS_SURFACES
129     S60->wsSession().Finish();
130 #endif
131 
132     QWidgetPrivate *windowPrivate = qt_widget_private(window());
133     if (!windowPrivate->isOpaque || blitWriteAlpha(windowPrivate)) {
134         QSymbianRasterPixmapData *pixmapData = static_cast<QSymbianRasterPixmapData *>(d_ptr->device.data_ptr().data());
135 
136         TDisplayMode mode = displayMode(false);
137         if (pixmapData->cfbsBitmap->DisplayMode() != mode)
138             pixmapData->convertToDisplayMode(mode);
139 
140         pixmapData->beginDataAccess();
141 
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);
149             }
150         }
151 
152         pixmapData->endDataAccess();
153     }
154 }
155 
endPaint(const QRegion &)156 void QS60WindowSurface::endPaint(const QRegion &)
157 {
158     qDeleteAll(d_ptr->bufferImages);
159     d_ptr->bufferImages.clear();
160 }
161 
buffer(const QWidget * widget)162 QImage* QS60WindowSurface::buffer(const QWidget *widget)
163 {
164     if (widget->window() != window())
165         return 0;
166 
167     QPaintDevice *pdev = paintDevice();
168     if (!pdev)
169         return 0;
170 
171     const QPoint off = offset(widget);
172     QImage *img = &(static_cast<QSymbianRasterPixmapData *>(d_ptr->device.data_ptr().data())->image);
173 
174     QRect rect(off, widget->size());
175     rect &= QRect(QPoint(), img->size());
176 
177     if (rect.isEmpty())
178         return 0;
179 
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);
184 
185     return img;
186 }
187 
flush(QWidget * widget,const QRegion & region,const QPoint &)188 void QS60WindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &)
189 {
190     QWidget *window = widget->window();
191     Q_ASSERT(window);
192     QTLWExtra *topExtra = window->d_func()->maybeTopData();
193     Q_ASSERT(topExtra);
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;
200     } else {
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();
207     }
208 }
209 
scroll(const QRegion & area,int dx,int dy)210 bool QS60WindowSurface::scroll(const QRegion &area, int dx, int dy)
211 {
212     QRect rect = area.boundingRect();
213 
214     if (dx == 0 && dy == 0)
215         return false;
216 
217     if (d_ptr->device.isNull())
218         return false;
219 
220     QSymbianRasterPixmapData *data = static_cast<QSymbianRasterPixmapData*>(d_ptr->device.data_ptr().data());
221     data->scroll(dx, dy, rect);
222 
223     return true;
224 }
225 
paintDevice()226 QPaintDevice* QS60WindowSurface::paintDevice()
227 {
228     return &d_ptr->device;
229 }
230 
setGeometry(const QRect & rect)231 void QS60WindowSurface::setGeometry(const QRect& rect)
232 {
233     if (rect == geometry())
234         return;
235 
236     QSymbianRasterPixmapData *data = static_cast<QSymbianRasterPixmapData*>(d_ptr->device.data_ptr().data());
237     data->resize(rect.width(), rect.height());
238 
239     QWindowSurface::setGeometry(rect);
240 }
241 
features() const242 QWindowSurface::WindowSurfaceFeatures QS60WindowSurface::features() const
243 {
244     return QWindowSurface::AllFeatures;
245 }
246 
symbianBitmap() const247 CFbsBitmap* QS60WindowSurface::symbianBitmap() const
248 {
249     QSymbianRasterPixmapData *data = static_cast<QSymbianRasterPixmapData*>(d_ptr->device.data_ptr().data());
250     return data->cfbsBitmap;
251 }
252 
253 QT_END_NAMESPACE
254 
255