| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 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.
|
|---|
| 23 | **
|
|---|
| 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.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 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 "qwindowsurface_s60_p.h"
|
|---|
| 47 | #include "qpixmap_s60_p.h"
|
|---|
| 48 | #include "qt_s60_p.h"
|
|---|
| 49 | #include "private/qdrawhelper_p.h"
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_NAMESPACE
|
|---|
| 52 |
|
|---|
| 53 | struct QS60WindowSurfacePrivate
|
|---|
| 54 | {
|
|---|
| 55 | QPixmap device;
|
|---|
| 56 | QList<QImage*> bufferImages;
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | QS60WindowSurface::QS60WindowSurface(QWidget* widget)
|
|---|
| 60 | : QWindowSurface(widget), d_ptr(new QS60WindowSurfacePrivate)
|
|---|
| 61 | {
|
|---|
| 62 |
|
|---|
| 63 | TDisplayMode mode = S60->screenDevice()->DisplayMode();
|
|---|
| 64 | bool isOpaque = qt_widget_private(widget)->isOpaque;
|
|---|
| 65 | if (mode == EColor16MA && isOpaque)
|
|---|
| 66 | mode = EColor16MU; // Faster since 16MU -> 16MA is typically accelerated
|
|---|
| 67 | else if (mode == EColor16MU && !isOpaque)
|
|---|
| 68 | mode = EColor16MA; // Try for transparency anyway
|
|---|
| 69 |
|
|---|
| 70 | // We create empty CFbsBitmap here -> it will be resized in setGeometry
|
|---|
| 71 | CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); // CBase derived object needs check on new
|
|---|
| 72 | qt_symbian_throwIfError( bitmap->Create( TSize(0, 0), mode ) );
|
|---|
| 73 |
|
|---|
| 74 | QS60PixmapData *data = new QS60PixmapData(QPixmapData::PixmapType);
|
|---|
| 75 | if (data) {
|
|---|
| 76 | data->fromSymbianBitmap(bitmap, true);
|
|---|
| 77 | d_ptr->device = QPixmap(data);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | setStaticContentsSupport(true);
|
|---|
| 81 | }
|
|---|
| 82 | QS60WindowSurface::~QS60WindowSurface()
|
|---|
| 83 | {
|
|---|
| 84 | delete d_ptr;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void QS60WindowSurface::beginPaint(const QRegion &rgn)
|
|---|
| 88 | {
|
|---|
| 89 | if (!qt_widget_private(window())->isOpaque) {
|
|---|
| 90 | QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data());
|
|---|
| 91 | pixmapData->beginDataAccess();
|
|---|
| 92 | QImage &image = pixmapData->image;
|
|---|
| 93 | QRgb *data = reinterpret_cast<QRgb *>(image.bits());
|
|---|
| 94 | const int row_stride = image.bytesPerLine() / 4;
|
|---|
| 95 |
|
|---|
| 96 | const QVector<QRect> rects = rgn.rects();
|
|---|
| 97 | for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
|
|---|
| 98 | const int x_start = it->x();
|
|---|
| 99 | const int width = it->width();
|
|---|
| 100 |
|
|---|
| 101 | const int y_start = it->y();
|
|---|
| 102 | const int height = it->height();
|
|---|
| 103 |
|
|---|
| 104 | QRgb *row = data + row_stride * y_start;
|
|---|
| 105 | for (int y = 0; y < height; ++y) {
|
|---|
| 106 | qt_memfill(row + x_start, 0U, width);
|
|---|
| 107 | row += row_stride;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | pixmapData->endDataAccess();
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | void QS60WindowSurface::endPaint(const QRegion &)
|
|---|
| 115 | {
|
|---|
| 116 | qDeleteAll(d_ptr->bufferImages);
|
|---|
| 117 | d_ptr->bufferImages.clear();
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | QImage* QS60WindowSurface::buffer(const QWidget *widget)
|
|---|
| 121 | {
|
|---|
| 122 | if (widget->window() != window())
|
|---|
| 123 | return 0;
|
|---|
| 124 |
|
|---|
| 125 | QPaintDevice *pdev = paintDevice();
|
|---|
| 126 | if (!pdev)
|
|---|
| 127 | return 0;
|
|---|
| 128 |
|
|---|
| 129 | const QPoint off = offset(widget);
|
|---|
| 130 | QImage *img = &(static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data())->image);
|
|---|
| 131 |
|
|---|
| 132 | QRect rect(off, widget->size());
|
|---|
| 133 | rect &= QRect(QPoint(), img->size());
|
|---|
| 134 |
|
|---|
| 135 | if (rect.isEmpty())
|
|---|
| 136 | return 0;
|
|---|
| 137 |
|
|---|
| 138 | img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8,
|
|---|
| 139 | rect.width(), rect.height(),
|
|---|
| 140 | img->bytesPerLine(), img->format());
|
|---|
| 141 | d_ptr->bufferImages.append(img);
|
|---|
| 142 |
|
|---|
| 143 | return img;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | void QS60WindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &)
|
|---|
| 147 | {
|
|---|
| 148 | QWidget *window = widget->window();
|
|---|
| 149 | Q_ASSERT(window);
|
|---|
| 150 | QTLWExtra *topExtra = window->d_func()->maybeTopData();
|
|---|
| 151 | Q_ASSERT(topExtra);
|
|---|
| 152 | if (!topExtra->inExpose) {
|
|---|
| 153 | topExtra->inExpose = true; // Prevent DrawNow() from calling syncBackingStore() again
|
|---|
| 154 | TRect tr = qt_QRect2TRect(region.boundingRect());
|
|---|
| 155 | widget->winId()->DrawNow(tr);
|
|---|
| 156 | topExtra->inExpose = false;
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | bool QS60WindowSurface::scroll(const QRegion &area, int dx, int dy)
|
|---|
| 161 | {
|
|---|
| 162 | QRect rect = area.boundingRect();
|
|---|
| 163 |
|
|---|
| 164 | if (dx == 0 && dy == 0)
|
|---|
| 165 | return false;
|
|---|
| 166 |
|
|---|
| 167 | if (d_ptr->device.isNull())
|
|---|
| 168 | return false;
|
|---|
| 169 |
|
|---|
| 170 | QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
|
|---|
| 171 | data->scroll(dx, dy, rect);
|
|---|
| 172 |
|
|---|
| 173 | return true;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | QPaintDevice* QS60WindowSurface::paintDevice()
|
|---|
| 177 | {
|
|---|
| 178 | return &d_ptr->device;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | void QS60WindowSurface::setGeometry(const QRect& rect)
|
|---|
| 182 | {
|
|---|
| 183 | if (rect == geometry())
|
|---|
| 184 | return;
|
|---|
| 185 |
|
|---|
| 186 | QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
|
|---|
| 187 | data->resize(rect.width(), rect.height());
|
|---|
| 188 |
|
|---|
| 189 | QWindowSurface::setGeometry(rect);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | CFbsBitmap* QS60WindowSurface::symbianBitmap() const
|
|---|
| 193 | {
|
|---|
| 194 | QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
|
|---|
| 195 | return data->cfbsBitmap;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | QT_END_NAMESPACE
|
|---|
| 199 |
|
|---|