Changeset 561 for trunk/src/gui/image/qpixmap_x11.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/image/qpixmap_x11.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 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 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 68 68 #include "qx11info_x11.h" 69 69 #include <private/qdrawhelper_p.h> 70 #include <private/qimage_p.h> 70 71 71 72 #include <stdlib.h> … … 313 314 314 315 QX11PixmapData::QX11PixmapData(PixelType type) 315 : QPixmapData(type, X11Class), hd(0), w(0), h(0), d(0),316 uninit(true), read_only(false), x11_mask(0), picture(0), mask_picture(0), hd2(0),316 : QPixmapData(type, X11Class), hd(0), 317 flags(Uninitialized), x11_mask(0), picture(0), mask_picture(0), hd2(0), gl_surface(0), 317 318 share_mode(QPixmap::ImplicitlyShared), pengine(0) 318 319 { 320 } 321 322 QPixmapData *QX11PixmapData::createCompatiblePixmapData() const 323 { 324 return new QX11PixmapData(pixelType()); 319 325 } 320 326 … … 325 331 w = width; 326 332 h = height; 333 is_null = (w <= 0 || h <= 0); 327 334 328 335 if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { … … 348 355 w = 0; 349 356 h = 0; 357 is_null = true; 350 358 hd = 0; 351 359 picture = 0; … … 368 376 } 369 377 378 struct QX11AlphaDetector 379 { 380 bool hasAlpha() const { 381 if (checked) 382 return has; 383 // Will implicitly also check format and return quickly for opaque types... 384 checked = true; 385 has = const_cast<QImage *>(image)->data_ptr()->checkForAlphaPixels(); 386 return has; 387 } 388 389 bool hasXRenderAndAlpha() const { 390 if (!X11->use_xrender) 391 return false; 392 return hasAlpha(); 393 } 394 395 QX11AlphaDetector(const QImage *i, Qt::ImageConversionFlags flags) 396 : image(i), checked(false), has(false) 397 { 398 if (flags & Qt::NoOpaqueDetection) { 399 checked = true; 400 has = image->hasAlphaChannel(); 401 } 402 } 403 404 const QImage *image; 405 mutable bool checked; 406 mutable bool has; 407 }; 408 370 409 void QX11PixmapData::fromImage(const QImage &img, 371 410 Qt::ImageConversionFlags flags) … … 376 415 h = img.height(); 377 416 d = img.depth(); 417 is_null = (w <= 0 || h <= 0); 418 419 if (is_null) { 420 w = h = 0; 421 return; 422 } 378 423 379 424 if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { … … 396 441 if (uint(w) >= 32768 || uint(h) >= 32768) { 397 442 w = h = 0; 443 is_null = true; 398 444 return; 399 445 } 400 446 401 int dd = X11->use_xrender && img.hasAlphaChannel() ? 32 : xinfo.depth(); 447 QX11AlphaDetector alphaCheck(&img, flags); 448 int dd = alphaCheck.hasXRenderAndAlpha() ? 32 : xinfo.depth(); 449 402 450 if (qt_x11_preferred_pixmap_depth) 403 451 dd = qt_x11_preferred_pixmap_depth; … … 422 470 conv8 = (d == 1); // native depth wanted 423 471 } else if (d == 1) { 424 if (image. numColors() == 2) {472 if (image.colorCount() == 2) { 425 473 QRgb c0 = image.color(0); // Auto: convert to best 426 474 QRgb c1 = image.color(1); … … 447 495 XImage *xi = 0; 448 496 bool trucol = (visual->c_class >= TrueColor); 449 int nbytes = image. numBytes();497 int nbytes = image.byteCount(); 450 498 uchar *newbits= 0; 451 499 452 500 #ifndef QT_NO_XRENDER 453 if ( X11->use_xrender && image.hasAlphaChannel()) {501 if (alphaCheck.hasXRenderAndAlpha()) { 454 502 const QImage &cimage = image; 455 503 … … 589 637 if (d8) { // setup pixel translation 590 638 QVector<QRgb> ctable = cimage.colorTable(); 591 for (int i=0; i < cimage. numColors(); i++) {639 for (int i=0; i < cimage.colorCount(); i++) { 592 640 int r = qRed (ctable[i]); 593 641 int g = qGreen(ctable[i]); … … 915 963 int pop[256]; // pixel popularity 916 964 917 if (image. numColors() == 0)918 image.set NumColors(1);965 if (image.colorCount() == 0) 966 image.setColorCount(1); 919 967 920 968 const QImage &cimage = image; … … 946 994 }; 947 995 int ncols = 0; 948 for (int i=0; i< cimage. numColors(); i++) { // compute number of colors996 for (int i=0; i< cimage.colorCount(); i++) { // compute number of colors 949 997 if (pop[i] > 0) 950 998 ncols++; 951 999 } 952 for (int i = cimage. numColors(); i < 256; i++) // ignore out-of-range pixels1000 for (int i = cimage.colorCount(); i < 256; i++) // ignore out-of-range pixels 953 1001 pop[i] = 0; 954 1002 … … 1088 1136 #endif 1089 1137 1090 if ( image.hasAlphaChannel()) {1138 if (alphaCheck.hasAlpha()) { 1091 1139 QBitmap m = QBitmap::fromImage(image.createAlphaMask(flags)); 1092 1140 setMask(m); … … 1110 1158 h = img.height(); 1111 1159 d = 1; 1160 is_null = (w <= 0 || h <= 0); 1112 1161 int bpl = (w + 7) / 8; 1113 1162 int ibpl = img.bytesPerLine(); … … 1213 1262 hd2 = 0; 1214 1263 } 1215 if (! read_only)1264 if (!(flags & Readonly)) 1216 1265 XFreePixmap(xinfo.display(), hd); 1217 1266 hd = 0; … … 1221 1270 QPixmap QX11PixmapData::alphaChannel() const 1222 1271 { 1223 if (!hasAlphaChannel()) 1224 return QPixmap(); 1272 if (!hasAlphaChannel()) { 1273 QPixmap pm(w, h); 1274 pm.fill(Qt::white); 1275 return pm; 1276 } 1225 1277 QImage im(toImage()); 1226 1278 return QPixmap::fromImage(im.alphaChannel(), Qt::OrderedDither); … … 1438 1490 // we may have to swap the byte order 1439 1491 if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst) 1440 || (QSysInfo::ByteOrder == QSysInfo::BigEndian ))1492 || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst)) 1441 1493 { 1442 1494 for (int i=0; i < image.height(); i++) { … … 1605 1657 1606 1658 if (d == 1) { // bitmap 1607 image.set NumColors(2);1659 image.setColorCount(2); 1608 1660 image.setColor(0, qRgb(255,255,255)); 1609 1661 image.setColor(1, qRgb(0,0,0)); … … 1661 1713 if (ncols < 256) { 1662 1714 trans = ncols++; 1663 image.set NumColors(ncols); // create color table1715 image.setColorCount(ncols); // create color table 1664 1716 image.setColor(trans, 0x00000000); 1665 1717 } else { 1666 image.set NumColors(ncols); // create color table1718 image.setColorCount(ncols); // create color table 1667 1719 // oh dear... no spare "transparent" pixel. 1668 1720 // use first pixel in image (as good as any). … … 1687 1739 } 1688 1740 } else { 1689 image.set NumColors(ncols); // create color table1741 image.setColorCount(ncols); // create color table 1690 1742 } 1691 1743 QVector<QColor> colors = QColormap::instance(xinfo.screen()).colormap(); … … 1870 1922 return bm; 1871 1923 } else { // color pixmap 1872 Q Pixmap pm;1873 Q X11PixmapData *x11Data = static_cast<QX11PixmapData*>(pm.data);1874 x11Data-> uninit = false;1924 QX11PixmapData *x11Data = new QX11PixmapData(QPixmapData::PixmapType); 1925 QPixmap pm(x11Data); 1926 x11Data->flags &= ~QX11PixmapData::Uninitialized; 1875 1927 x11Data->xinfo = xinfo; 1876 1928 x11Data->d = d; 1877 1929 x11Data->w = w; 1878 1930 x11Data->h = h; 1931 x11Data->is_null = (w <= 0 || h <= 0); 1879 1932 x11Data->hd = (Qt::HANDLE)XCreatePixmap(X11->display, 1880 1933 RootWindow(X11->display, xinfo.screen()), 1881 1934 w, h, d); 1935 x11Data->setSerialNumber(++qt_pixmap_serial); 1936 1882 1937 #ifndef QT_NO_XRENDER 1883 1938 if (X11->use_xrender) { … … 1915 1970 } 1916 1971 1917 /*!1918 \internal1919 */1920 1972 int QPixmap::x11SetDefaultScreen(int screen) 1921 1973 { … … 1925 1977 } 1926 1978 1927 /*!1928 \internal1929 */1930 1979 void QPixmap::x11SetScreen(int screen) 1931 1980 { … … 1935 1984 } 1936 1985 1986 if (isNull()) 1987 return; 1988 1937 1989 if (data->classId() != QPixmapData::X11Class) 1938 1990 return; … … 1941 1993 screen = QX11Info::appScreen(); 1942 1994 1943 QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data );1995 QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(data.data()); 1944 1996 if (screen == x11Data->xinfo.screen()) 1945 1997 return; // nothing to do … … 2019 2071 QPixmap pm(data); 2020 2072 2021 data-> uninit = false;2073 data->flags &= ~QX11PixmapData::Uninitialized; 2022 2074 pm.x11SetScreen(scr); 2023 2075 … … 2035 2087 } 2036 2088 2037 /*!2038 Returns information about the configuration of the X display used to display2039 the widget.2040 2041 \warning This function is only available on X11.2042 2043 \sa {QPixmap#Pixmap Information}{Pixmap Information}2044 */2045 2089 const QX11Info &QPixmap::x11Info() const 2046 2090 { 2047 if (data ->classId() == QPixmapData::X11Class)2048 return static_cast<QX11PixmapData*>(data )->xinfo;2091 if (data && data->classId() == QPixmapData::X11Class) 2092 return static_cast<QX11PixmapData*>(data.data())->xinfo; 2049 2093 else { 2050 2094 static QX11Info nullX11Info; … … 2069 2113 QX11PixmapData *that = const_cast<QX11PixmapData*>(this); 2070 2114 2071 if ( read_only&& share_mode == QPixmap::ImplicitlyShared) {2115 if ((flags & Readonly) && share_mode == QPixmap::ImplicitlyShared) { 2072 2116 // if someone wants to draw onto us, copy the shared contents 2073 2117 // and turn it into a fully fledged QPixmap … … 2091 2135 } 2092 2136 that->hd = hd_copy; 2093 that-> read_only = false;2137 that->flags &= ~QX11PixmapData::Readonly; 2094 2138 } 2095 2139 … … 2099 2143 } 2100 2144 2101 /*!2102 Returns the X11 Picture handle of the pixmap for XRender2103 support.2104 2105 This function will return 0 if XRender support is not compiled2106 into Qt, if the XRender extension is not supported on the X112107 display, or if the handle could not be created. Use of this2108 function is not portable.2109 2110 \warning This function is only available on X11.2111 2112 \sa {QPixmap#Pixmap Information}{Pixmap Information}2113 */2114 2115 2145 Qt::HANDLE QPixmap::x11PictureHandle() const 2116 2146 { 2117 2147 #ifndef QT_NO_XRENDER 2118 if (data ->classId() == QPixmapData::X11Class)2119 return static_cast< QX11PixmapData*>(data)->picture;2148 if (data && data->classId() == QPixmapData::X11Class) 2149 return static_cast<const QX11PixmapData*>(data.data())->picture; 2120 2150 else 2121 2151 return 0; … … 2156 2186 setSerialNumber(++qt_pixmap_serial); 2157 2187 2158 uninit = false;2188 flags &= ~Uninitialized; 2159 2189 xinfo = x11Data->xinfo; 2160 2190 d = x11Data->d; 2161 2191 w = rect.width(); 2162 2192 h = rect.height(); 2193 is_null = (w <= 0 || h <= 0); 2163 2194 hd = (Qt::HANDLE)XCreatePixmap(X11->display, 2164 2195 RootWindow(X11->display, x11Data->xinfo.screen()), … … 2206 2237 } 2207 2238 2239 bool QX11PixmapData::scroll(int dx, int dy, const QRect &rect) 2240 { 2241 GC gc = XCreateGC(X11->display, hd, 0, 0); 2242 XCopyArea(X11->display, hd, hd, gc, 2243 rect.left(), rect.top(), rect.width(), rect.height(), 2244 rect.left() + dx, rect.top() + dy); 2245 XFreeGC(X11->display, gc); 2246 return true; 2247 } 2248 2208 2249 #if !defined(QT_NO_XRENDER) 2209 2250 void QX11PixmapData::convertToARGB32(bool preserveContents) … … 2213 2254 2214 2255 // Q_ASSERT(count == 1); 2215 if ( read_only&& share_mode == QPixmap::ExplicitlyShared)2256 if ((flags & Readonly) && share_mode == QPixmap::ExplicitlyShared) 2216 2257 return; 2217 2258 … … 2223 2264 if (preserveContents) 2224 2265 XRenderComposite(X11->display, PictOpSrc, picture, 0, p, 0, 0, 0, 0, 0, 0, w, h); 2225 if (! read_only)2266 if (!(flags & Readonly)) 2226 2267 XRenderFreePicture(X11->display, picture); 2227 2268 } 2228 if (hd && ! read_only)2269 if (hd && !(flags & Readonly)) 2229 2270 XFreePixmap(X11->display, hd); 2230 2271 if (x11_mask) { … … 2264 2305 QX11PixmapData *data = new QX11PixmapData(depth == 1 ? QPixmapData::BitmapType : QPixmapData::PixmapType); 2265 2306 data->setSerialNumber(++qt_pixmap_serial); 2266 data-> read_only = true;2307 data->flags = QX11PixmapData::Readonly; 2267 2308 data->share_mode = mode; 2268 data->uninit = false;2269 2309 data->w = width; 2270 2310 data->h = height; 2311 data->is_null = (width <= 0 || height <= 0); 2271 2312 data->d = depth; 2272 2313 data->hd = pixmap;
Note:
See TracChangeset
for help on using the changeset viewer.