src/gui/painting/qwindowsurface_s60.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui of the Qt Toolkit.
       
     8 **
       
     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
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    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 "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     data->fromSymbianBitmap(bitmap);
       
    76     d_ptr->device = QPixmap(data);
       
    77         
       
    78     setStaticContentsSupport(true);
       
    79 }
       
    80 QS60WindowSurface::~QS60WindowSurface()
       
    81 {
       
    82     delete d_ptr;
       
    83 }
       
    84 
       
    85 void QS60WindowSurface::beginPaint(const QRegion &rgn)
       
    86 {
       
    87     if (!qt_widget_private(window())->isOpaque) {
       
    88         QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data());
       
    89         pixmapData->beginDataAccess();
       
    90         QImage &image = pixmapData->image;
       
    91         QRgb *data = reinterpret_cast<QRgb *>(image.bits());
       
    92         const int row_stride = image.bytesPerLine() / 4;
       
    93 
       
    94         const QVector<QRect> rects = rgn.rects();
       
    95         for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
       
    96             const int x_start = it->x();
       
    97             const int width = it->width();
       
    98 
       
    99             const int y_start = it->y();
       
   100             const int height = it->height();
       
   101 
       
   102             QRgb *row = data + row_stride * y_start;
       
   103             for (int y = 0; y < height; ++y) {
       
   104                 qt_memfill(row + x_start, 0U, width);
       
   105                 row += row_stride;
       
   106             }
       
   107         }
       
   108         pixmapData->endDataAccess();
       
   109     }
       
   110 }
       
   111 
       
   112 void QS60WindowSurface::endPaint(const QRegion &)
       
   113 {
       
   114     qDeleteAll(d_ptr->bufferImages);
       
   115     d_ptr->bufferImages.clear();
       
   116 }
       
   117 
       
   118 QImage* QS60WindowSurface::buffer(const QWidget *widget)
       
   119 {
       
   120     if (widget->window() != window())
       
   121         return 0;
       
   122 
       
   123     QPaintDevice *pdev = paintDevice();
       
   124     if (!pdev)
       
   125         return 0;
       
   126 
       
   127     const QPoint off = offset(widget);
       
   128     QImage *img = &(static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data())->image);
       
   129     
       
   130     QRect rect(off, widget->size());
       
   131     rect &= QRect(QPoint(), img->size());
       
   132 
       
   133     if (rect.isEmpty())
       
   134         return 0;
       
   135 
       
   136     img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8,
       
   137                      rect.width(), rect.height(),
       
   138                      img->bytesPerLine(), img->format());
       
   139     d_ptr->bufferImages.append(img);
       
   140 
       
   141     return img;
       
   142 }
       
   143 
       
   144 void QS60WindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &)
       
   145 {
       
   146     const QVector<QRect> subRects = region.rects();
       
   147     for (int i = 0; i < subRects.count(); ++i) {
       
   148         TRect tr = qt_QRect2TRect(subRects[i]);
       
   149         widget->winId()->DrawNow(tr);
       
   150     }
       
   151 }
       
   152 
       
   153 bool QS60WindowSurface::scroll(const QRegion &area, int dx, int dy)
       
   154 {
       
   155     QRect rect = area.boundingRect();
       
   156 
       
   157     if (dx == 0 && dy == 0)
       
   158         return false;
       
   159 
       
   160     if (d_ptr->device.isNull())
       
   161         return false;
       
   162 
       
   163     QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
       
   164     data->scroll(dx, dy, rect);
       
   165 
       
   166     return true;
       
   167 }
       
   168 
       
   169 QPaintDevice* QS60WindowSurface::paintDevice()
       
   170 {
       
   171     return &d_ptr->device;
       
   172 }
       
   173 
       
   174 void QS60WindowSurface::setGeometry(const QRect& rect)
       
   175 {
       
   176     if (rect == geometry())
       
   177         return;
       
   178 
       
   179     QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
       
   180     data->resize(rect.width(), rect.height());
       
   181 
       
   182     QWindowSurface::setGeometry(rect);
       
   183 }
       
   184 
       
   185 CFbsBitmap* QS60WindowSurface::symbianBitmap() const
       
   186 {
       
   187     QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data());
       
   188     return data->cfbsBitmap;
       
   189 }
       
   190 
       
   191 QT_END_NAMESPACE
       
   192