Windows QPA: Prefer const-versions of API where applicable.

Ensure no detaching occurs by using Container::constFirst()
and QImage::constScanLine().

Change-Id: Ie197d795d9329de8be76ed388ba2c71ccf201f5c
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2016-02-08 15:51:46 +01:00
parent 62984d8918
commit 966e893151
6 changed files with 12 additions and 12 deletions

View File

@ -142,8 +142,8 @@ static HCURSOR createBitmapCursor(const QImage &bbits, const QImage &mbits,
QScopedArrayPointer<uchar> xMask(new uchar[height * n]);
int x = 0;
for (int i = 0; i < height; ++i) {
const uchar *bits = bbits.scanLine(i);
const uchar *mask = mbits.scanLine(i);
const uchar *bits = bbits.constScanLine(i);
const uchar *mask = mbits.constScanLine(i);
for (int j = 0; j < n; ++j) {
uchar b = bits[j];
uchar m = mask[j];
@ -173,8 +173,8 @@ static HCURSOR createBitmapCursor(const QImage &bbits, const QImage &mbits,
x += sysN;
} else {
int fillWidth = n > sysN ? sysN : n;
const uchar *bits = bbits.scanLine(i);
const uchar *mask = mbits.scanLine(i);
const uchar *bits = bbits.constScanLine(i);
const uchar *mask = mbits.constScanLine(i);
for (int j = 0; j < fillWidth; ++j) {
uchar b = bits[j];
uchar m = mask[j];

View File

@ -990,7 +990,7 @@ EGLConfig QWindowsEGLContext::chooseConfig(const QSurfaceFormat &format)
QVector<EGLConfig> configs(matching);
QWindowsEGLStaticContext::libEGL.eglChooseConfig(display, configureAttributes.constData(), configs.data(), configs.size(), &matching);
if (!cfg && matching > 0)
cfg = configs.first();
cfg = configs.constFirst();
EGLint red = 0;
EGLint green = 0;

View File

@ -1174,11 +1174,11 @@ QImage QWindowsFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &xfo
for (int y=0; y<mask->height(); ++y) {
uchar *dest = alphaMap.scanLine(y);
if (mask->image().format() == QImage::Format_RGB16) {
const qint16 *src = (qint16 *) ((const QImage &) mask->image()).scanLine(y);
const qint16 *src = reinterpret_cast<const qint16 *>(mask->image().constScanLine(y));
for (int x=0; x<mask->width(); ++x)
dest[x] = 255 - qGray(src[x]);
} else {
const uint *src = (uint *) ((const QImage &) mask->image()).scanLine(y);
const uint *src = reinterpret_cast<const uint *>(mask->image().constScanLine(y));
for (int x=0; x<mask->width(); ++x) {
if (QWindowsNativeImage::systemFormat() == QImage::Format_RGB16)
dest[x] = 255 - qGray(src[x]);
@ -1223,7 +1223,7 @@ QImage QWindowsFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed, const QTra
QImage rgbMask(mask->width(), mask->height(), QImage::Format_RGB32);
for (int y=0; y<mask->height(); ++y) {
uint *dest = (uint *) rgbMask.scanLine(y);
const uint *src = (uint *) source.scanLine(y);
const uint *src = reinterpret_cast<const uint *>(source.constScanLine(y));
for (int x=0; x<mask->width(); ++x) {
dest[x] = 0xffffffff - (0x00ffffff & src[x]);
}

View File

@ -493,7 +493,7 @@ QImage QWindowsFontEngineDirectWrite::alphaMapForGlyph(glyph_t glyph, QFixed sub
QImage alphaMap(im.width(), im.height(), QImage::Format_Alpha8);
for (int y=0; y<im.height(); ++y) {
uint *src = (uint*) im.scanLine(y);
const uint *src = reinterpret_cast<const uint *>(im.constScanLine(y));
uchar *dst = alphaMap.scanLine(y);
for (int x=0; x<im.width(); ++x) {
*dst = 255 - (m_fontEngineData->pow_gamma[qGray(0xffffffff - *src)] * 255. / 2047.);

View File

@ -175,8 +175,8 @@ static bool qt_write_dibv5(QDataStream &s, QImage image)
memset(buf, 0, bpl_bmp);
for (int y=image.height()-1; y>=0; y--) {
// write the image bits
QRgb *p = (QRgb *)image.scanLine(y);
QRgb *end = p + image.width();
const QRgb *p = reinterpret_cast<const QRgb *>(image.constScanLine(y));
const QRgb *end = p + image.width();
b = buf;
while (p < end) {
int alpha = qAlpha(*p);

View File

@ -183,7 +183,7 @@ static QPoint windowPlacementOffset(HWND hwnd, const QPoint &point)
return QPoint(0, 0);
const QWindowsScreenManager &screenManager = QWindowsContext::instance()->screenManager();
const QWindowsScreen *screen = screenManager.screens().size() == 1
? screenManager.screens().first() : screenManager.screenAtDp(point);
? screenManager.screens().constFirst() : screenManager.screenAtDp(point);
if (screen)
return screen->availableGeometry().topLeft() - screen->geometry().topLeft();
#else