src/gui/painting/qwindowsurface_s60.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
    68         mode = EColor16MA; // Try for transparency anyway
    68         mode = EColor16MA; // Try for transparency anyway
    69 
    69 
    70     // We create empty CFbsBitmap here -> it will be resized in setGeometry
    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
    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 ) );
    72     qt_symbian_throwIfError( bitmap->Create( TSize(0, 0), mode ) );
    73 	
    73 
    74     QS60PixmapData *data = new QS60PixmapData(QPixmapData::PixmapType);
    74     QS60PixmapData *data = new QS60PixmapData(QPixmapData::PixmapType);
    75     if (data) {
    75     if (data) {
    76         data->fromSymbianBitmap(bitmap, true);
    76         data->fromSymbianBitmap(bitmap, true);
    77         d_ptr->device = QPixmap(data);
    77         d_ptr->device = QPixmap(data);
    78     }
    78     }
    79         
    79 
    80     setStaticContentsSupport(true);
    80     setStaticContentsSupport(true);
    81 }
    81 }
    82 QS60WindowSurface::~QS60WindowSurface()
    82 QS60WindowSurface::~QS60WindowSurface()
    83 {
    83 {
    84     delete d_ptr;
    84     delete d_ptr;
    87 void QS60WindowSurface::beginPaint(const QRegion &rgn)
    87 void QS60WindowSurface::beginPaint(const QRegion &rgn)
    88 {
    88 {
    89     if (!qt_widget_private(window())->isOpaque) {
    89     if (!qt_widget_private(window())->isOpaque) {
    90         QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data());
    90         QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data());
    91         pixmapData->beginDataAccess();
    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 
    92 
       
    93         QPainter p(&pixmapData->image);
       
    94         p.setCompositionMode(QPainter::CompositionMode_Source);
    96         const QVector<QRect> rects = rgn.rects();
    95         const QVector<QRect> rects = rgn.rects();
       
    96         const QColor blank = Qt::transparent;
    97         for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
    97         for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
    98             const int x_start = it->x();
    98             p.fillRect(*it, blank);
    99             const int width = it->width();
    99         }
   100 
   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();
   101         pixmapData->endDataAccess();
   111     }
   102     }
   112 }
   103 }
   113 
   104 
   114 void QS60WindowSurface::endPaint(const QRegion &)
   105 void QS60WindowSurface::endPaint(const QRegion &)
   126     if (!pdev)
   117     if (!pdev)
   127         return 0;
   118         return 0;
   128 
   119 
   129     const QPoint off = offset(widget);
   120     const QPoint off = offset(widget);
   130     QImage *img = &(static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data())->image);
   121     QImage *img = &(static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data())->image);
   131     
   122 
   132     QRect rect(off, widget->size());
   123     QRect rect(off, widget->size());
   133     rect &= QRect(QPoint(), img->size());
   124     rect &= QRect(QPoint(), img->size());
   134 
   125 
   135     if (rect.isEmpty())
   126     if (rect.isEmpty())
   136         return 0;
   127         return 0;
   143     return img;
   134     return img;
   144 }
   135 }
   145 
   136 
   146 void QS60WindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &)
   137 void QS60WindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &)
   147 {
   138 {
   148     const QVector<QRect> subRects = region.rects();
   139     QWidget *window = widget->window();
   149     for (int i = 0; i < subRects.count(); ++i) {
   140     Q_ASSERT(window);
   150         TRect tr = qt_QRect2TRect(subRects[i]);
   141     QTLWExtra *topExtra = window->d_func()->maybeTopData();
       
   142     Q_ASSERT(topExtra);
       
   143     QRect qr = region.boundingRect();
       
   144     if (!topExtra->inExpose) {
       
   145         topExtra->inExpose = true; // Prevent DrawNow() from calling syncBackingStore() again
       
   146         TRect tr = qt_QRect2TRect(qr);
   151         widget->winId()->DrawNow(tr);
   147         widget->winId()->DrawNow(tr);
       
   148         topExtra->inExpose = false;
       
   149     } else {
       
   150         // This handles the case when syncBackingStore updates content outside of the
       
   151         // original drawing rectangle. This might happen if there are pending update()
       
   152         // events at the same time as we get a Draw() from Symbian.
       
   153         QRect drawRect = qt_TRect2QRect(widget->winId()->DrawableWindow()->GetDrawRect());
       
   154         if (!drawRect.contains(qr))
       
   155             widget->winId()->DrawDeferred();
   152     }
   156     }
   153 }
   157 }
   154 
   158 
   155 bool QS60WindowSurface::scroll(const QRegion &area, int dx, int dy)
   159 bool QS60WindowSurface::scroll(const QRegion &area, int dx, int dy)
   156 {
   160 {