Changeset 61534 in webkit


Ignore:
Timestamp:
Jun 21, 2010 1:30:42 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-21 Benjamin Poulain <benjamin.poulain@nokia.com>

Reviewed by Kenneth Rohde Christiansen.

[Qt] Decode images directly to QPixmap
https://bugs.webkit.org/show_bug.cgi?id=40797

Decode images to QPixmap directly instead of QImage when possible.
RGBA32Buffer transforms the pixmap back to image if
necessary.

This improve the performance with certain graphic system, and
can reduce memory usage.

  • platform/graphics/qt/ImageDecoderQt.cpp: (WebCore::ImageDecoderQt::setData): (WebCore::ImageDecoderQt::internalHandleCurrentImage):
  • platform/image-decoders/ImageDecoder.h: (WebCore::RGBA32Buffer::getAddr):
  • platform/image-decoders/qt/RGBA32BufferQt.cpp: (WebCore::RGBA32Buffer::clear): (WebCore::RGBA32Buffer::zeroFill): (WebCore::RGBA32Buffer::copyBitmapData): (WebCore::RGBA32Buffer::setSize): (WebCore::RGBA32Buffer::asNewNativeImage): (WebCore::RGBA32Buffer::setPixmap):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r61531 r61534  
     12010-06-21  Benjamin Poulain  <benjamin.poulain@nokia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Decode images directly to QPixmap
     6        https://bugs.webkit.org/show_bug.cgi?id=40797
     7
     8        Decode images to QPixmap directly instead of QImage when possible.
     9        RGBA32Buffer transforms the pixmap back to image if
     10        necessary.
     11
     12        This improve the performance with certain graphic system, and
     13        can reduce memory usage.
     14
     15        * platform/graphics/qt/ImageDecoderQt.cpp:
     16        (WebCore::ImageDecoderQt::setData):
     17        (WebCore::ImageDecoderQt::internalHandleCurrentImage):
     18        * platform/image-decoders/ImageDecoder.h:
     19        (WebCore::RGBA32Buffer::getAddr):
     20        * platform/image-decoders/qt/RGBA32BufferQt.cpp:
     21        (WebCore::RGBA32Buffer::clear):
     22        (WebCore::RGBA32Buffer::zeroFill):
     23        (WebCore::RGBA32Buffer::copyBitmapData):
     24        (WebCore::RGBA32Buffer::setSize):
     25        (WebCore::RGBA32Buffer::asNewNativeImage):
     26        (WebCore::RGBA32Buffer::setPixmap):
     27
    1282010-06-20  Dumitru Daniliuc  <dumi@chromium.org>
    229
  • trunk/WebCore/platform/graphics/qt/ImageDecoderQt.cpp

    r61364 r61534  
    7979    m_reader.set(new QImageReader(m_buffer.get(), m_format));
    8080
    81     // This will force the JPEG decoder to use JDCT_IFAST
    82     m_reader->setQuality(49);
    83 
    8481    // QImageReader only allows retrieving the format before reading the image
    8582    m_format = m_reader->format();
     
    189186bool ImageDecoderQt::internalHandleCurrentImage(size_t frameIndex)
    190187{
    191     // Now get the QImage from Qt and place it in the RGBA32Buffer
    192     QImage img;
    193     if (!m_reader->read(&img)) {
     188    QPixmap pixmap;
     189    bool pixmapLoaded;
     190    const int imageCount = m_reader->imageCount();
     191    if (imageCount == 0 || imageCount == 1)
     192        pixmapLoaded = pixmap.loadFromData((const uchar*)(m_data->data()), m_data->size(), m_format);
     193    else {
     194        QImage img;
     195        const bool imageLoaded = m_reader->read(&img);
     196        if (imageLoaded) {
     197            pixmap = QPixmap::fromImage(img);
     198            pixmapLoaded = true;
     199        }
     200    }
     201
     202    if (!pixmapLoaded) {
    194203        frameCount();
    195204        repetitionCount();
     
    203212    buffer->setStatus(RGBA32Buffer::FrameComplete);
    204213    buffer->setDuration(m_reader->nextImageDelay());
    205     buffer->setDecodedImage(img);
     214    buffer->setPixmap(pixmap);
    206215    return true;
    207216}
  • trunk/WebCore/platform/image-decoders/ImageDecoder.h

    r56007 r61534  
    4141#include "NativeImageSkia.h"
    4242#elif PLATFORM(QT)
     43#include <QPixmap>
    4344#include <QImage>
    4445#endif
     
    131132
    132133#if PLATFORM(QT)
    133         void setDecodedImage(const QImage& image);
    134         QImage decodedImage() const { return m_image; }
     134        void setPixmap(const QPixmap& pixmap);
    135135#endif
    136136
     
    144144            return m_bitmap.getAddr32(x, y);
    145145#elif PLATFORM(QT)
     146            m_image = m_pixmap.toImage();
     147            m_pixmap = QPixmap();
    146148            return reinterpret_cast<QRgb*>(m_image.scanLine(y)) + x;
    147149#else
     
    169171        NativeImageSkia m_bitmap;
    170172#elif PLATFORM(QT)
     173        mutable QPixmap m_pixmap;
    171174        mutable QImage m_image;
    172175        bool m_hasAlpha;
  • trunk/WebCore/platform/image-decoders/qt/RGBA32BufferQt.cpp

    r54978 r61534  
    5858void RGBA32Buffer::clear()
    5959{
     60    m_pixmap = QPixmap();
    6061    m_image = QImage();
    6162    m_status = FrameEmpty;
     
    6869void RGBA32Buffer::zeroFill()
    6970{
    70     m_image.fill(0);
     71    if (m_pixmap.isNull() && !m_image.isNull()) {
     72        m_pixmap = QPixmap::fromImage(m_image);
     73        m_image = QImage();
     74    }
     75    m_pixmap.fill(QColor(0, 0, 0, 0));
    7176}
    7277
     
    7782
    7883    m_image = other.m_image;
     84    m_pixmap = other.m_pixmap;
    7985    m_size = other.m_size;
    8086    m_hasAlpha = other.m_hasAlpha;
     
    8894
    8995    m_size = IntSize(newWidth, newHeight);
    90     m_image = QImage(newWidth, newHeight, QImage::Format_ARGB32_Premultiplied);
    91     if (m_image.isNull())
     96    m_image = QImage();
     97    m_pixmap = QPixmap(newWidth, newHeight);
     98    if (m_pixmap.isNull())
    9299        return false;
    93100
     
    100107QPixmap* RGBA32Buffer::asNewNativeImage() const
    101108{
    102     QPixmap pix = QPixmap::fromImage(m_image);
    103     m_image = QImage();
    104 
    105     return new QPixmap(pix);
     109    if (m_pixmap.isNull() && !m_image.isNull()) {
     110        m_pixmap = QPixmap::fromImage(m_image);
     111        m_image = QImage();
     112    }
     113    return new QPixmap(m_pixmap);
    106114}
    107115
     
    122130
    123131// The image must not have format 8888 pre multiplied...
    124 void RGBA32Buffer::setDecodedImage(const QImage& image)
     132void RGBA32Buffer::setPixmap(const QPixmap& pixmap)
    125133{
    126     m_image = image;
    127     m_size = image.size();
    128     m_hasAlpha = image.hasAlphaChannel();
     134    m_pixmap = pixmap;
     135    m_image = QImage();
     136    m_size = pixmap.size();
     137    m_hasAlpha = pixmap.hasAlphaChannel();
    129138}
    130139
Note: See TracChangeset for help on using the changeset viewer.