Changeset 769 for trunk/src/gui/image


Ignore:
Timestamp:
Aug 2, 2010, 9:27:30 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qicon.cpp

    r763 r769  
    105105static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);
    106106
     107static void qt_cleanup_icon_cache();
     108typedef QCache<QString, QIcon> IconCache;
     109Q_GLOBAL_STATIC_WITH_INITIALIZER(IconCache, qtIconCache, qAddPostRoutine(qt_cleanup_icon_cache))
     110
     111static void qt_cleanup_icon_cache()
     112{
     113    qtIconCache()->clear();
     114}
     115
    107116QIconPrivate::QIconPrivate()
    108117    : engine(0), ref(1),
     
    964973QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
    965974{
    966     static QCache <QString, QIcon> iconCache;
    967 
    968975    QIcon icon;
    969976
    970     if (iconCache.contains(name)) {
    971         icon = *iconCache.object(name);
     977    if (qtIconCache()->contains(name)) {
     978        icon = *qtIconCache()->object(name);
    972979    } else {
    973980        QIcon *cachedIcon  = new QIcon(new QIconLoaderEngine(name));
    974         iconCache.insert(name, cachedIcon);
     981        qtIconCache()->insert(name, cachedIcon);
    975982        icon = *cachedIcon;
    976983    }
    977984
    978     if (icon.availableSizes().isEmpty())
     985    // Note the qapp check is to allow lazy loading of static icons
     986    // Supporting fallbacks will not work for this case.
     987    if (qApp && icon.availableSizes().isEmpty())
    979988        return fallback;
    980989
  • trunk/src/gui/image/qiconloader.cpp

    r651 r769  
    8686
    8787QIconLoader::QIconLoader() :
    88         m_themeKey(1), m_supportsSvg(false)
    89 {
    90     m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
    91     if (m_systemTheme.isEmpty())
    92         m_systemTheme = fallbackTheme();
    93 
     88        m_themeKey(1), m_supportsSvg(false), m_initialized(false)
     89{
     90}
     91
     92// We lazily initialize the loader to make static icons
     93// work. Though we do not officially support this.
     94void QIconLoader::ensureInitialized()
     95{
     96    if (!m_initialized) {
     97        m_initialized = true;
     98
     99        Q_ASSERT(qApp);
     100
     101        m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
     102        if (m_systemTheme.isEmpty())
     103            m_systemTheme = fallbackTheme();
    94104#ifndef QT_NO_LIBRARY
    95     QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
    96                                      QLatin1String("/iconengines"),
    97                                      Qt::CaseInsensitive);
    98     if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
    99         m_supportsSvg = true;
     105        QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
     106                                         QLatin1String("/iconengines"),
     107                                         Qt::CaseInsensitive);
     108        if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
     109            m_supportsSvg = true;
    100110#endif //QT_NO_LIBRARY
     111    }
    101112}
    102113
     
    340351void QIconLoaderEngine::ensureLoaded()
    341352{
     353
     354    iconLoaderInstance()->ensureInitialized();
     355
    342356    if (!(iconLoaderInstance()->themeKey() == m_key)) {
    343357
  • trunk/src/gui/image/qiconloader_p.h

    r651 r769  
    170170    void updateSystemTheme();
    171171    void invalidateKey() { m_themeKey++; }
     172    void ensureInitialized();
    172173
    173174private:
     
    177178    uint m_themeKey;
    178179    bool m_supportsSvg;
     180    bool m_initialized;
    179181
    180182    mutable QString m_userTheme;
  • trunk/src/gui/image/qimage.cpp

    r651 r769  
    119119}
    120120
    121 extern int qt_defaultDpiX();
    122 extern int qt_defaultDpiY();
     121Q_GUI_EXPORT extern int qt_defaultDpiX();
     122Q_GUI_EXPORT extern int qt_defaultDpiY();
    123123
    124124QBasicAtomicInt qimage_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1);
     
    56685668    detach();
    56695669
    5670     *this = convertToFormat(QImage::Format_ARGB32_Premultiplied);
     5670    QImage converted = convertToFormat(QImage::Format_ARGB32_Premultiplied);
     5671    if (!converted.isNull())
     5672        *this = converted;
     5673    else
     5674        return;
    56715675
    56725676    // Slight optimization since alphachannels are returned as 8-bit grays.
  • trunk/src/gui/image/qimagepixmapcleanuphooks.cpp

    r651 r769  
    9797{
    9898    QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
     99    // the global destructor for the pixmap and image hooks might have
     100    // been called already if the app is "leaking" global
     101    // pixmaps/images
     102    if (!h)
     103        return;
    99104    for (int i = 0; i < h->pixmapModificationHooks.count(); ++i)
    100105        h->pixmapModificationHooks[i](pmd);
     
    107112{
    108113    QImagePixmapCleanupHooks *h = qt_image_and_pixmap_cleanup_hooks();
     114    // the global destructor for the pixmap and image hooks might have
     115    // been called already if the app is "leaking" global
     116    // pixmaps/images
     117    if (!h)
     118        return;
    109119    for (int i = 0; i < h->pixmapDestructionHooks.count(); ++i)
    110120        h->pixmapDestructionHooks[i](pmd);
     
    123133}
    124134
    125 void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
    126 {
    127     enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
    128 }
    129135
    130136void QImagePixmapCleanupHooks::enableCleanupHooks(QPixmapData *pixmapData)
    131137{
    132138    pixmapData->is_cached = true;
     139}
     140
     141void QImagePixmapCleanupHooks::enableCleanupHooks(const QPixmap &pixmap)
     142{
     143    enableCleanupHooks(const_cast<QPixmap &>(pixmap).data_ptr().data());
    133144}
    134145
     
    138149}
    139150
     151bool QImagePixmapCleanupHooks::isImageCached(const QImage &image)
     152{
     153    return const_cast<QImage &>(image).data_ptr()->is_cached;
     154}
     155
     156bool QImagePixmapCleanupHooks::isPixmapCached(const QPixmap &pixmap)
     157{
     158    return const_cast<QPixmap&>(pixmap).data_ptr().data()->is_cached;
     159}
     160
     161
     162
    140163QT_END_NAMESPACE
  • trunk/src/gui/image/qimagepixmapcleanuphooks_p.h

    r651 r769  
    7373    static void enableCleanupHooks(QPixmapData *pixmapData);
    7474
     75    static bool isImageCached(const QImage &image);
     76    static bool isPixmapCached(const QPixmap &pixmap);
     77
    7578    // Gets called when a pixmap data is about to be modified:
    7679    void addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd);
  • trunk/src/gui/image/qimagereader.cpp

    r651 r769  
    264264    }
    265265
    266     if (!handler && !testFormat.isEmpty() && autoDetectImageFormat && !ignoresFormatAndExtension) {
     266    if (!handler && !testFormat.isEmpty() && !ignoresFormatAndExtension) {
    267267        // check if any plugin supports the format (they are not allowed to
    268268        // read from the device yet).
    269269        const qint64 pos = device ? device->pos() : 0;
    270         for (int i = 0; i < keys.size(); ++i) {
    271             if (i != suffixPluginIndex) {
    272                 QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i)));
    273                 if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
     270
     271        if (autoDetectImageFormat) {
     272            for (int i = 0; i < keys.size(); ++i) {
     273                if (i != suffixPluginIndex) {
     274                    QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i)));
     275                    if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
    274276#ifdef QIMAGEREADER_DEBUG
    275                     qDebug() << "QImageReader::createReadHandler: the" << keys.at(i) << "plugin can read this format";
    276 #endif
    277                     handler = plugin->create(device, testFormat);
    278                     break;
     277                        qDebug() << "QImageReader::createReadHandler: the" << keys.at(i) << "plugin can read this format";
     278#endif
     279                        handler = plugin->create(device, testFormat);
     280                        break;
     281                    }
    279282                }
     283            }
     284        } else {
     285            QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QLatin1String(testFormat)));
     286            if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) {
     287#ifdef QIMAGEREADER_DEBUG
     288                qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format";
     289#endif
     290                handler = plugin->create(device, testFormat);
    280291            }
    281292        }
     
    283294            device->seek(pos);
    284295    }
     296
    285297#endif // QT_NO_LIBRARY
    286298
  • trunk/src/gui/image/qimagewriter.cpp

    r651 r769  
    198198            QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i)));
    199199            if (plugin && (plugin->capabilities(device, testFormat) & QImageIOPlugin::CanWrite)) {
     200                delete handler;
    200201                handler = plugin->create(device, testFormat);
    201202                break;
  • trunk/src/gui/image/qnativeimage.cpp

    r651 r769  
    202202        ok = (xshminfo.shmaddr != (char*)-1);
    203203        if (ok)
    204             image = QImage((uchar *)xshmimg->data, width, height, systemFormat());
     204            image = QImage((uchar *)xshmimg->data, width, height, format);
    205205    }
    206206    xshminfo.readOnly = false;
  • trunk/src/gui/image/qpaintengine_pic.cpp

    r651 r769  
    478478}
    479479
    480 extern int qt_defaultDpi();
     480Q_GUI_EXPORT extern int qt_defaultDpi();
    481481
    482482void QPicturePaintEngine::drawTextItem(const QPointF &p , const QTextItem &ti)
  • trunk/src/gui/image/qpicture.cpp

    r651 r769  
    109109static const quint16 mfhdr_maj = 11; // major version #
    110110static const quint16 mfhdr_min = 0; // minor version #
    111 extern int qt_defaultDpiX();
    112 extern int qt_defaultDpiY();
     111Q_GUI_EXPORT extern int qt_defaultDpiX();
     112Q_GUI_EXPORT extern int qt_defaultDpiY();
    113113
    114114/*!
  • trunk/src/gui/image/qpixmap.cpp

    r651 r769  
    832832        return true;
    833833
    834     bool ok;
    835 
    836     if (data) {
    837         ok = data->fromFile(fileName, format, flags);
    838     } else {
    839         QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, QPixmapData::PixmapType));
    840         ok = tmp->fromFile(fileName, format, flags);
    841         if (ok)
    842             data = tmp.take();
    843     }
    844 
    845     if (ok)
     834    QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, data ? data->type : QPixmapData::PixmapType));
     835    if (tmp->fromFile(fileName, format, flags)) {
     836        data = tmp.take();
    846837        QPixmapCache::insert(key, *this);
    847 
    848     return ok;
     838        return true;
     839    }
     840
     841    return false;
    849842}
    850843
     
    16711664
    16721665    The hasAlphaChannel() returns true if the pixmap has a format that
    1673     respects the alpha channel, otherwise returns false, while the
    1674     hasAlpha() function returns true if the pixmap has an alpha
    1675     channel \e or a mask (otherwise false). The mask() function returns
    1676     the mask as a QBitmap object, which can be set using setMask().
     1666    respects the alpha channel, otherwise returns false. The hasAlpha(),
     1667    setMask() and mask() functions are legacy and should not be used.
     1668    They are potentially very slow.
    16771669
    16781670    The createHeuristicMask() function creates and returns a 1-bpp
     
    17601752    Returns true if this pixmap has an alpha channel, \e or has a
    17611753    mask, otherwise returns false.
     1754
     1755    \warning This is potentially an expensive operation.
    17621756
    17631757    \sa hasAlphaChannel(), mask()
     
    20282022    too. The mouse cursor is generally not grabbed.
    20292023
    2030     Note on X11that if the given \a window doesn't have the same depth
     2024    Note on X11 that if the given \a window doesn't have the same depth
    20312025    as the root window, and another window partially or entirely
    20322026    obscures the one you grab, you will \e not get pixels from the
     
    20342028    pixmap will be undefined and uninitialized.
    20352029
     2030    On Windows Vista and above grabbing a layered window, which is
     2031    created by setting the Qt::WA_TranslucentBackground attribute, will
     2032    not work. Instead grabbing the desktop widget should work.
     2033
    20362034    \warning In general, grabbing an area outside the screen is not
    20372035    safe. This depends on the underlying window system.
  • trunk/src/gui/image/qpixmap_raster.cpp

    r651 r769  
    358358}
    359359
    360 extern int qt_defaultDpiX();
    361 extern int qt_defaultDpiY();
     360Q_GUI_EXPORT extern int qt_defaultDpiX();
     361Q_GUI_EXPORT extern int qt_defaultDpiY();
    362362
    363363int QRasterPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
  • trunk/src/gui/image/qpixmap_s60.cpp

    r651 r769  
    338338        return QPixmap();
    339339
    340     QScopedPointer<QS60PixmapData> data(new QS60PixmapData(QPixmapData::PixmapType));
     340    QScopedPointer<QPixmapData> data(QPixmapData::create(0,0, QPixmapData::PixmapType));
    341341    data->fromNativeType(reinterpret_cast<void*>(bitmap), QPixmapData::FbsBitmap);
    342342    QPixmap pixmap(data.take());
     
    736736        return QPixmap();
    737737
    738     QScopedPointer<QS60PixmapData> data(new QS60PixmapData(QPixmapData::PixmapType));
     738    QScopedPointer<QPixmapData> data(QPixmapData::create(0,0, QPixmapData::PixmapType));
    739739    data->fromNativeType(reinterpret_cast<void*>(sgImage), QPixmapData::SgImage);
    740740    QPixmap pixmap(data.take());
  • trunk/src/gui/image/qpixmap_x11.cpp

    r651 r769  
    384384        // Will implicitly also check format and return quickly for opaque types...
    385385        checked = true;
    386         has = const_cast<QImage *>(image)->data_ptr()->checkForAlphaPixels();
     386        has = image->isNull() ? false : const_cast<QImage *>(image)->data_ptr()->checkForAlphaPixels();
    387387        return has;
    388388    }
  • trunk/src/gui/image/qpixmapfilter.cpp

    r651 r769  
    423423        return;
    424424
     425    if (src.isNull())
     426        return;
     427
    425428    QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ?
    426429        static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0;
     
    775778Q_GUI_EXPORT QImage qt_halfScaled(const QImage &source)
    776779{
     780    if (source.width() < 2 || source.height() < 2)
     781        return QImage();
     782
    777783    QImage srcImage = source;
    778784
     
    867873
    868874    qreal scale = 1;
    869     if (radius >= 4) {
     875    if (radius >= 4 && blurImage.width() >= 2 && blurImage.height() >= 2) {
    870876        blurImage = qt_halfScaled(blurImage);
    871877        scale = 2;
     
    893899}
    894900
    895 bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
     901Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
    896902
    897903/*!
     
    902908    Q_D(const QPixmapBlurFilter);
    903909    if (!painter->isActive())
     910        return;
     911
     912    if (src.isNull())
    904913        return;
    905914
     
    10841093{
    10851094    Q_D(const QPixmapColorizeFilter);
     1095
     1096    if (src.isNull())
     1097        return;
     1098
    10861099    QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ?
    10871100        static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0;
     
    13141327{
    13151328    Q_D(const QPixmapDropShadowFilter);
     1329
     1330    if (px.isNull())
     1331        return;
     1332
    13161333    QPixmapFilter *filter = p->paintEngine() && p->paintEngine()->isExtended() ?
    13171334        static_cast<QPaintEngineEx *>(p->paintEngine())->pixmapFilter(type(), this) : 0;
Note: See TracChangeset for help on using the changeset viewer.