[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75

hausmann at webkit.org hausmann at webkit.org
Thu Oct 29 20:40:16 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit 88b3eb3315f3e83af8e45d53fbaee40830d517c5
Author: hausmann at webkit.org <hausmann at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Oct 6 14:14:10 2009 +0000

    [Qt] Make use of RGBA32Buffer in ImageDecoderQt
    
    https://bugs.webkit.org/show_bug.cgi?id=27538
    
    Use the RGBA32Buffer instead of the internal ImageData
    to be able to use support of the base class, optionally
    support WebCore decoders for Qt and most importantly
    separate metadata and image data for better cache control.
    
    Remove ImageSourceQt as everything is now shared with
    the normal ImageSource.
    
    Change the ownership of the NativeImagePtr/QPixmap in
    ImageQt.cpp to delete the m_frame to be subject to cache
    control.
    
    * WebCore.pro:
    * platform/graphics/ImageSource.cpp:
    * platform/graphics/qt/ImageDecoderQt.cpp:
    (WebCore::ImageDecoderQt::ReadContext::ReadContext):
    (WebCore::ImageDecoderQt::ReadContext::read):
    (WebCore::ImageDecoderQt::ReadContext::readImageLines):
    (WebCore::ImageDecoderQt::ImageDecoderQt):
    (WebCore::ImageDecoderQt::setData):
    (WebCore::ImageDecoderQt::frameCount):
    (WebCore::ImageDecoderQt::frameBufferAtIndex):
    (WebCore::ImageDecoderQt::clearFrameBufferCache):
    * platform/graphics/qt/ImageDecoderQt.h:
    * platform/graphics/qt/ImageSourceQt.cpp: Removed.
    * platform/image-decoders/ImageDecoder.h:
    (WebCore::RGBA32Buffer::decodedImage):
    (WebCore::RGBA32Buffer::getAddr):
    * platform/image-decoders/qt/RGBA32BufferQt.cpp: Added.
    (WebCore::RGBA32Buffer::RGBA32Buffer):
    (WebCore::RGBA32Buffer::setDecodedImage):
    (WebCore::RGBA32Buffer::clear):
    (WebCore::RGBA32Buffer::zeroFill):
    (WebCore::RGBA32Buffer::copyBitmapData):
    (WebCore::RGBA32Buffer::setSize):
    (WebCore::RGBA32Buffer::asNewNativeImage):
    (WebCore::RGBA32Buffer::hasAlpha):
    (WebCore::RGBA32Buffer::setHasAlpha):
    (WebCore::RGBA32Buffer::setStatus):
    (WebCore::RGBA32Buffer::operator=):
    (WebCore::RGBA32Buffer::width):
    (WebCore::RGBA32Buffer::height):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49185 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 32c0d40..be6c21e 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -2,6 +2,56 @@
 
         Reviewed by Simon Hausmann.
 
+        [Qt] Make use of RGBA32Buffer in ImageDecoderQt
+        https://bugs.webkit.org/show_bug.cgi?id=27538
+
+        Use the RGBA32Buffer instead of the internal ImageData
+        to be able to use support of the base class, optionally
+        support WebCore decoders for Qt and most importantly
+        separate metadata and image data for better cache control.
+
+        Remove ImageSourceQt as everything is now shared with
+        the normal ImageSource.
+
+        Change the ownership of the NativeImagePtr/QPixmap in
+        ImageQt.cpp to delete the m_frame to be subject to cache
+        control.
+
+        * WebCore.pro:
+        * platform/graphics/ImageSource.cpp:
+        * platform/graphics/qt/ImageDecoderQt.cpp:
+        (WebCore::ImageDecoderQt::ReadContext::ReadContext):
+        (WebCore::ImageDecoderQt::ReadContext::read):
+        (WebCore::ImageDecoderQt::ReadContext::readImageLines):
+        (WebCore::ImageDecoderQt::ImageDecoderQt):
+        (WebCore::ImageDecoderQt::setData):
+        (WebCore::ImageDecoderQt::frameCount):
+        (WebCore::ImageDecoderQt::frameBufferAtIndex):
+        (WebCore::ImageDecoderQt::clearFrameBufferCache):
+        * platform/graphics/qt/ImageDecoderQt.h:
+        * platform/graphics/qt/ImageSourceQt.cpp: Removed.
+        * platform/image-decoders/ImageDecoder.h:
+        (WebCore::RGBA32Buffer::decodedImage):
+        (WebCore::RGBA32Buffer::getAddr):
+        * platform/image-decoders/qt/RGBA32BufferQt.cpp: Added.
+        (WebCore::RGBA32Buffer::RGBA32Buffer):
+        (WebCore::RGBA32Buffer::setDecodedImage):
+        (WebCore::RGBA32Buffer::clear):
+        (WebCore::RGBA32Buffer::zeroFill):
+        (WebCore::RGBA32Buffer::copyBitmapData):
+        (WebCore::RGBA32Buffer::setSize):
+        (WebCore::RGBA32Buffer::asNewNativeImage):
+        (WebCore::RGBA32Buffer::hasAlpha):
+        (WebCore::RGBA32Buffer::setHasAlpha):
+        (WebCore::RGBA32Buffer::setStatus):
+        (WebCore::RGBA32Buffer::operator=):
+        (WebCore::RGBA32Buffer::width):
+        (WebCore::RGBA32Buffer::height):
+
+2009-10-05  Holger Hans Peter Freyther  <zecke at selfish.org>
+
+        Reviewed by Simon Hausmann.
+
         [Qt] ImageDecoderQt avoid QString creation.
         https://bugs.webkit.org/show_bug.cgi?id=27538
 
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 9963b46..fbeace3 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -1175,6 +1175,7 @@ SOURCES += \
     platform/DragImage.cpp \
     platform/FileChooser.cpp \
     platform/GeolocationService.cpp \
+    platform/image-decoders/qt/RGBA32BufferQt.cpp \
     platform/graphics/FontDescription.cpp \
     platform/graphics/FontFamily.cpp \
     platform/graphics/BitmapImage.cpp \
@@ -1851,6 +1852,7 @@ HEADERS += \
     platform/DragImage.h \
     platform/FileChooser.h \
     platform/GeolocationService.h \
+    platform/image-decoders/ImageDecoder.h \
     platform/mock/GeolocationServiceMock.h \
     platform/graphics/BitmapImage.h \
     platform/graphics/Color.h \
@@ -2334,7 +2336,6 @@ SOURCES += \
     platform/graphics/qt/ImageBufferQt.cpp \
     platform/graphics/qt/ImageDecoderQt.cpp \
     platform/graphics/qt/ImageQt.cpp \
-    platform/graphics/qt/ImageSourceQt.cpp \
     platform/graphics/qt/IntPointQt.cpp \
     platform/graphics/qt/IntRectQt.cpp \
     platform/graphics/qt/IntSizeQt.cpp \
diff --git a/WebCore/platform/graphics/ImageSource.cpp b/WebCore/platform/graphics/ImageSource.cpp
index 799368b..bf7ae21 100644
--- a/WebCore/platform/graphics/ImageSource.cpp
+++ b/WebCore/platform/graphics/ImageSource.cpp
@@ -120,8 +120,6 @@ size_t ImageSource::frameCount() const
     return m_decoder ? m_decoder->frameCount() : 0;
 }
 
-#if !PLATFORM(QT)
-
 NativeImagePtr ImageSource::createFrameAtIndex(size_t index)
 {
     if (!m_decoder)
@@ -180,6 +178,4 @@ bool ImageSource::frameIsCompleteAtIndex(size_t index)
     return buffer && buffer->status() == RGBA32Buffer::FrameComplete;
 }
 
-#endif
-
 }
diff --git a/WebCore/platform/graphics/qt/ImageDecoderQt.cpp b/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
index ab9beb1..6831056 100644
--- a/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
@@ -55,17 +55,11 @@ ImageDecoder* ImageDecoder::create(const SharedBuffer& data)
     return new ImageDecoderQt(imageFormat);
 }
 
-ImageDecoderQt::ImageData::ImageData(const QImage& image, int duration)
-    : m_image(image)
-    , m_duration(duration)
-{
-}
-
 // Context, maintains IODevice on a data buffer.
 class ImageDecoderQt::ReadContext {
 public:
 
-    ReadContext(SharedBuffer* data, ImageList &target);
+    ReadContext(SharedBuffer* data, Vector<RGBA32Buffer>& target);
     bool read();
 
     QImageReader *reader() { return &m_reader; }
@@ -73,26 +67,20 @@ public:
 private:
     enum IncrementalReadResult { IncrementalReadFailed, IncrementalReadPartial, IncrementalReadComplete };
     // Incrementally read an image
-    IncrementalReadResult readImageLines(ImageData &);
+    IncrementalReadResult readImageLines(RGBA32Buffer&);
 
     QByteArray m_data;
     QBuffer m_buffer;
     QImageReader m_reader;
 
-    ImageList &m_target;
-
-    // Detected data format of the stream
-    enum QImage::Format m_dataFormat;
-    QSize m_size;
-
+    Vector<RGBA32Buffer> &m_target;
 };
 
-ImageDecoderQt::ReadContext::ReadContext(SharedBuffer* data, ImageList &target)
+ImageDecoderQt::ReadContext::ReadContext(SharedBuffer* data, Vector<RGBA32Buffer> &target)
     : m_data(data->data(), data->size())
     , m_buffer(&m_data)
     , m_reader(&m_buffer)
     , m_target(target)
-    , m_dataFormat(QImage::Format_Invalid)
 {
     m_buffer.open(QIODevice::ReadOnly);
 }
@@ -103,31 +91,25 @@ bool ImageDecoderQt::ReadContext::read()
     // Attempt to read out all images
     bool completed = false;
     while (true) {
-        if (m_target.empty() || completed) {
+        if (m_target.isEmpty() || completed) {
             // Start a new image.
             if (!m_reader.canRead())
                 return true;
 
-            // Attempt to construct an empty image of the matching size and format
-            // for efficient reading
-            QImage newImage = m_dataFormat != QImage::Format_Invalid  ?
-                          QImage(m_size, m_dataFormat) : QImage();
-            m_target.push_back(ImageData(newImage));
+            m_target.append(RGBA32Buffer());
             completed = false;
         }
 
         // read chunks
-        switch (readImageLines(m_target.back())) {
+        switch (readImageLines(m_target.last())) {
         case IncrementalReadFailed:
-            m_target.pop_back();
+            m_target.removeLast();
             return false;
         case IncrementalReadPartial:
             return true;
         case IncrementalReadComplete:
             completed = true;
             //store for next
-            m_dataFormat = m_target.back().m_image.format();
-            m_size = m_target.back().m_image.size();
             const bool supportsAnimation = m_reader.supportsAnimation();
 
             // No point in readinfg further
@@ -143,30 +125,29 @@ bool ImageDecoderQt::ReadContext::read()
 
 
 ImageDecoderQt::ReadContext::IncrementalReadResult
-        ImageDecoderQt::ReadContext::readImageLines(ImageData &imageData)
+        ImageDecoderQt::ReadContext::readImageLines(RGBA32Buffer& buffer)
 {
     // TODO: Implement incremental reading here,
     // set state to reflect complete header, etc.
     // For now, we read the whole image.
 
+
     const qint64 startPos = m_buffer.pos();
+    QImage img;
     // Oops, failed. Rewind.
-    if (!m_reader.read(&imageData.m_image)) {
+    if (!m_reader.read(&img)) {
         m_buffer.seek(startPos);
-        const bool gotHeader = imageData.m_image.size().width();
-
-        // [Experimental] Did we manage to read the header?
-        if (gotHeader)
-            return IncrementalReadPartial;
         return IncrementalReadFailed;
     }
-    imageData.m_duration = m_reader.nextImageDelay();
+
+    buffer.setDuration(m_reader.nextImageDelay());
+    buffer.setDecodedImage(img);
+    buffer.setStatus(RGBA32Buffer::FrameComplete);
     return IncrementalReadComplete;
 }
 
 ImageDecoderQt::ImageDecoderQt(const QByteArray& imageFormat)
-    : m_hasAlphaChannel(false)
-    , m_imageFormat(imageFormat.constData())
+    : m_imageFormat(imageFormat.constData())
 {
 }
 
@@ -174,11 +155,6 @@ ImageDecoderQt::~ImageDecoderQt()
 {
 }
 
-bool ImageDecoderQt::hasFirstImageHeader() const
-{
-    return  !m_imageList.empty();
-}
-
 void ImageDecoderQt::setData(SharedBuffer* data, bool allDataReceived)
 {
     if (m_failed)
@@ -191,17 +167,14 @@ void ImageDecoderQt::setData(SharedBuffer* data, bool allDataReceived)
     if (!allDataReceived)
         return;
 
-    ReadContext readContext(data, m_imageList);
+    ReadContext readContext(data, m_frameBufferCache);
 
     const bool result =  readContext.read();
 
-    if (hasFirstImageHeader())
-        m_hasAlphaChannel = m_imageList[0].m_image.hasAlphaChannel();
-
     if (!result)
         setFailed();
-    else if (hasFirstImageHeader()) {
-        QSize imgSize = m_imageList[0].m_image.size();
+    else if (!m_frameBufferCache.isEmpty()) {
+        QSize imgSize = m_frameBufferCache[0].decodedImage().size();
         setSize(imgSize.width(), imgSize.height());
 
         if (readContext.reader()->supportsAnimation()) {
@@ -221,7 +194,7 @@ bool ImageDecoderQt::isSizeAvailable()
 
 size_t ImageDecoderQt::frameCount()
 {
-    return m_imageList.size();
+    return m_frameBufferCache.size();
 }
 
 int ImageDecoderQt::repetitionCount() const
@@ -229,50 +202,29 @@ int ImageDecoderQt::repetitionCount() const
     return m_loopCount;
 }
 
-bool ImageDecoderQt::supportsAlpha() const
-{
-    return m_hasAlphaChannel;
-}
-
-int ImageDecoderQt::duration(size_t index) const
-{
-    if (index >= static_cast<size_t>(m_imageList.size()))
-        return 0;
-    return  m_imageList[index].m_duration;
-}
-
 String ImageDecoderQt::filenameExtension() const
 {
     return m_imageFormat;
 };
 
-RGBA32Buffer* ImageDecoderQt::frameBufferAtIndex(size_t)
+RGBA32Buffer* ImageDecoderQt::frameBufferAtIndex(size_t index)
 {
-    Q_ASSERT("use imageAtIndex instead");
-    return 0;
-}
-
-QPixmap* ImageDecoderQt::imageAtIndex(size_t index) const
-{
-    if (index >= static_cast<size_t>(m_imageList.size()))
+    if (index >= m_frameBufferCache.size())
         return 0;
 
-    if (!m_pixmapCache.contains(index)) {
-        m_pixmapCache.insert(index,
-                             QPixmap::fromImage(m_imageList[index].m_image));
-
-        // store null image since the converted pixmap is already in pixmap cache
-        Q_ASSERT(m_imageList[index].m_imageState == ImageComplete);
-        m_imageList[index].m_image = QImage();
-    }
-    return  &m_pixmapCache[index];
+    return &m_frameBufferCache[index];
 }
 
-void ImageDecoderQt::clearFrame(size_t index)
+void ImageDecoderQt::clearFrameBufferCache(size_t index)
 {
-    if (m_imageList.size() < (int)index)
-        m_imageList[index].m_image = QImage();
-    m_pixmapCache.take(index);
+    // Currently QImageReader will be asked to read everything. This
+    // might change when we read gif images on demand. For now we
+    // can have a rather simple implementation.
+    if (index > m_frameBufferCache.size())
+        return;
+
+    for (size_t i = 0; i < index; ++index)
+        m_frameBufferCache[index].setDecodedImage(QImage());
 }
 
 }
diff --git a/WebCore/platform/graphics/qt/ImageDecoderQt.h b/WebCore/platform/graphics/qt/ImageDecoderQt.h
index d73a618..6a272e9 100644
--- a/WebCore/platform/graphics/qt/ImageDecoderQt.h
+++ b/WebCore/platform/graphics/qt/ImageDecoderQt.h
@@ -48,32 +48,16 @@ public:
     virtual int repetitionCount() const;
     virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
 
-    QPixmap* imageAtIndex(size_t index) const;
-    virtual bool supportsAlpha() const;
-    int duration(size_t index) const;
     virtual String filenameExtension() const;
 
-    void clearFrame(size_t index);
+    virtual void clearFrameBufferCache(size_t clearBeforeFrame);
 
 private:
     ImageDecoderQt(const ImageDecoderQt&);
     ImageDecoderQt &operator=(const ImageDecoderQt&);
 
     class ReadContext;
-    bool hasFirstImageHeader() const;
 
-
-    // TODO: Replace usage of ImageData with RGBBuffer32
-    struct ImageData {
-        ImageData(const QImage& image, int duration=0);
-        QImage m_image;
-        int m_duration;
-    };
-
-    bool m_hasAlphaChannel;
-    typedef QList<ImageData> ImageList;
-    mutable ImageList m_imageList;
-    mutable QHash<int, QPixmap> m_pixmapCache;
     int m_loopCount;
     String m_imageFormat;
 };
diff --git a/WebCore/platform/graphics/qt/ImageQt.cpp b/WebCore/platform/graphics/qt/ImageQt.cpp
index 5d40e26..da6ddac 100644
--- a/WebCore/platform/graphics/qt/ImageQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageQt.cpp
@@ -76,6 +76,7 @@ bool FrameData::clear(bool clearMetadata)
         m_haveMetadata = false;
 
     if (m_frame) {
+        delete m_frame;
         m_frame = 0;
         return true;
     }
diff --git a/WebCore/platform/graphics/qt/ImageSourceQt.cpp b/WebCore/platform/graphics/qt/ImageSourceQt.cpp
deleted file mode 100644
index dc5c03b..0000000
--- a/WebCore/platform/graphics/qt/ImageSourceQt.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved. 
- * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "ImageSource.h"
-#include "ImageDecoderQt.h"
-
-namespace WebCore {
-
-NativeImagePtr ImageSource::createFrameAtIndex(size_t index)
-{
-    return m_decoder ? m_decoder->imageAtIndex(index) : 0;
-}
-
-float ImageSource::frameDurationAtIndex(size_t index)
-{
-    if (!m_decoder)
-        return 0;
-
-    // Many annoying ads specify a 0 duration to make an image flash as quickly
-    // as possible.  We follow WinIE's behavior and use a duration of 100 ms
-    // for any frames that specify a duration of <= 50 ms.  See
-    // <http://bugs.webkit.org/show_bug.cgi?id=14413> or Radar 4051389 for
-    // more.
-    const float duration = m_decoder->duration(index) / 1000.0f;
-    return (duration < 0.051f) ? 0.100f : duration;
-}
-
-bool ImageSource::frameHasAlphaAtIndex(size_t index)
-{
-    return frameIsCompleteAtIndex(index) && m_decoder->supportsAlpha() &&
-        m_decoder->imageAtIndex(index)->hasAlphaChannel();
-}
-
-bool ImageSource::frameIsCompleteAtIndex(size_t index)
-{
-    return m_decoder && m_decoder->imageAtIndex(index);
-}
-
-}
-
-// vim: ts=4 sw=4 et
diff --git a/WebCore/platform/image-decoders/ImageDecoder.h b/WebCore/platform/image-decoders/ImageDecoder.h
index 2df3df9..1c095d0 100644
--- a/WebCore/platform/image-decoders/ImageDecoder.h
+++ b/WebCore/platform/image-decoders/ImageDecoder.h
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
  * Copyright (C) 2008-2009 Torch Mobile, Inc.
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -37,6 +38,8 @@
 
 #if PLATFORM(SKIA)
 #include "NativeImageSkia.h"
+#elif PLATFORM(QT)
+#include <QImage>
 #endif
 
 namespace WebCore {
@@ -54,7 +57,7 @@ namespace WebCore {
             DisposeOverwriteBgcolor,   // Clear frame to transparent
             DisposeOverwritePrevious,  // Clear frame to previous framebuffer contents
         };
-#if PLATFORM(SKIA)
+#if PLATFORM(SKIA) || PLATFORM(QT)
         typedef uint32_t PixelData;
 #else
         typedef unsigned PixelData;
@@ -126,6 +129,11 @@ namespace WebCore {
             setRGBA(getAddr(x, y), r, g, b, a);
         }
 
+#if PLATFORM(QT)
+        void setDecodedImage(const QImage& image);
+        QImage decodedImage() const { return m_image; }
+#endif
+
     private:
         RGBA32Buffer& operator=(const RGBA32Buffer& other);
 
@@ -136,6 +144,8 @@ namespace WebCore {
         {
 #if PLATFORM(SKIA)
             return m_bitmap.getAddr32(x, y);
+#elif PLATFORM(QT)
+            return reinterpret_cast<QRgb*>(m_image.scanLine(y)) + x;
 #else
             return m_bytes.data() + (y * width()) + x;
 #endif
@@ -159,6 +169,10 @@ namespace WebCore {
 
 #if PLATFORM(SKIA)
         NativeImageSkia m_bitmap;
+#elif PLATFORM(QT)
+        QImage m_image;
+        bool m_hasAlpha;
+        IntSize m_size;
 #else
         Vector<PixelData> m_bytes;
         IntSize m_size;       // The size of the buffer.  This should be the
diff --git a/WebCore/platform/image-decoders/qt/RGBA32BufferQt.cpp b/WebCore/platform/image-decoders/qt/RGBA32BufferQt.cpp
new file mode 100644
index 0000000..e96389d
--- /dev/null
+++ b/WebCore/platform/image-decoders/qt/RGBA32BufferQt.cpp
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2008, 2009 Google, Inc.
+ * Copyright (C) 2009 Holger Hans Peter Freyther
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ImageDecoder.h"
+
+#include <QPixmap>
+#include <stdio.h>
+
+namespace WebCore {
+
+RGBA32Buffer::RGBA32Buffer()
+    : m_status(FrameEmpty)
+    , m_hasAlpha(false)
+    , m_size()
+    , m_duration(0)
+    , m_disposalMethod(DisposeNotSpecified)
+{
+}
+
+// The image must not have format 8888 pre multiplied...
+void RGBA32Buffer::setDecodedImage(const QImage& image)
+{
+    m_image = image;
+    m_size = image.size();
+    m_hasAlpha = image.hasAlphaChannel();
+}
+
+void RGBA32Buffer::clear()
+{
+    m_image = QImage();
+    m_status = FrameEmpty;
+    // NOTE: Do not reset other members here; clearFrameBufferCache()
+    // calls this to free the bitmap data, but other functions like
+    // initFrameBuffer() and frameComplete() may still need to read
+    // other metadata out of this frame later.
+}
+
+void RGBA32Buffer::zeroFill()
+{
+    m_image.fill(0);
+}
+
+void RGBA32Buffer::copyBitmapData(const RGBA32Buffer& other)
+{
+    if (this == &other)
+        return;
+
+    m_image = other.m_image;
+    m_size = other.m_size;
+    m_hasAlpha = other.m_hasAlpha;
+}
+
+bool RGBA32Buffer::setSize(int newWidth, int newHeight)
+{
+    // This function should only be called once, it will leak memory
+    // otherwise.
+    ASSERT(width() == 0 && height() == 0);
+
+    m_size = IntSize(newWidth, newHeight);
+    m_image = QImage(newWidth, newHeight, QImage::Format_ARGB32_Premultiplied);
+    if (m_image.isNull()) {
+        // Allocation failure, maybe the bitmap was too big.
+        setStatus(FrameComplete);
+        return false;
+    }
+
+    // Zero the image.
+    zeroFill();
+
+    return true;
+}
+
+QPixmap* RGBA32Buffer::asNewNativeImage() const
+{
+    return new QPixmap(QPixmap::fromImage(m_image));
+}
+
+bool RGBA32Buffer::hasAlpha() const
+{
+    return m_hasAlpha;
+}
+
+void RGBA32Buffer::setHasAlpha(bool alpha)
+{
+    m_hasAlpha = alpha;
+}
+
+void RGBA32Buffer::setStatus(FrameStatus status)
+{
+    m_status = status;
+}
+
+RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
+{
+    if (this == &other)
+        return *this;
+
+    copyBitmapData(other);
+    setRect(other.rect());
+    setStatus(other.status());
+    setDuration(other.duration());
+    setDisposalMethod(other.disposalMethod());
+    return *this;
+}
+
+int RGBA32Buffer::width() const
+{
+    return m_size.width();
+}
+
+int RGBA32Buffer::height() const
+{
+    return m_size.height();
+}
+
+}

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list