Commit e0a21476 authored by pkasting@chromium.org's avatar pkasting@chromium.org

2009-06-13 Peter Kasting <pkasting@google.com>

        Reviewed by Eric Seidel.

        https://bugs.webkit.org/show_bug.cgi?id=25709 part nine
        Factor Cairo-specific implementation out of ImageDecoder.h into
        ImageDecoderCairo.cpp.  Add some comments to functions declared
        in ImageDecoder.h.

        * GNUmakefile.am:
        * WebCore.vcproj/WebCore.vcproj:
        * platform/image-decoders/ImageDecoder.h:
        * platform/image-decoders/cairo: Added.
        * platform/image-decoders/cairo/ImageDecoderCairo.cpp: Added.
        (WebCore::RGBA32Buffer::RGBA32Buffer):
        (WebCore::RGBA32Buffer::clear):
        (WebCore::RGBA32Buffer::zeroFill):
        (WebCore::RGBA32Buffer::copyBitmapData):
        (WebCore::RGBA32Buffer::setSize):
        (WebCore::RGBA32Buffer::asNewNativeImage):
        (WebCore::RGBA32Buffer::hasAlpha):
        (WebCore::RGBA32Buffer::setHasAlpha):
        (WebCore::RGBA32Buffer::operator=):
        (WebCore::RGBA32Buffer::width):
        (WebCore::RGBA32Buffer::height):
        (WebCore::RGBA32Buffer::getAddr):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44652 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c16c13b1
2009-06-13 Peter Kasting <pkasting@google.com>
Reviewed by Eric Seidel.
https://bugs.webkit.org/show_bug.cgi?id=25709 part nine
Factor Cairo-specific implementation out of ImageDecoder.h into
ImageDecoderCairo.cpp. Add some comments to functions declared
in ImageDecoder.h.
* GNUmakefile.am:
* WebCore.vcproj/WebCore.vcproj:
* platform/image-decoders/ImageDecoder.h:
* platform/image-decoders/cairo: Added.
* platform/image-decoders/cairo/ImageDecoderCairo.cpp: Added.
(WebCore::RGBA32Buffer::RGBA32Buffer):
(WebCore::RGBA32Buffer::clear):
(WebCore::RGBA32Buffer::zeroFill):
(WebCore::RGBA32Buffer::copyBitmapData):
(WebCore::RGBA32Buffer::setSize):
(WebCore::RGBA32Buffer::asNewNativeImage):
(WebCore::RGBA32Buffer::hasAlpha):
(WebCore::RGBA32Buffer::setHasAlpha):
(WebCore::RGBA32Buffer::operator=):
(WebCore::RGBA32Buffer::width):
(WebCore::RGBA32Buffer::height):
(WebCore::RGBA32Buffer::getAddr):
2009-06-13 David Hyatt <hyatt@apple.com>
Reviewed by Darin Adler.
......@@ -1864,6 +1864,7 @@ webcoregtk_sources += \
WebCore/platform/image-decoders/bmp/BMPImageDecoder.h \
WebCore/platform/image-decoders/bmp/BMPImageReader.cpp \
WebCore/platform/image-decoders/bmp/BMPImageReader.h \
WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp \
WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp \
WebCore/platform/image-decoders/gif/GIFImageDecoder.h \
WebCore/platform/image-decoders/gif/GIFImageReader.cpp \
......
......@@ -6251,6 +6251,38 @@
/>
</FileConfiguration>
</File>
<Filter
Name="cairo"
>
<File
RelativePath="..\platform\image-decoders\cairo\ImageDecoderCairo.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Internal|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="gif"
>
......
......@@ -34,10 +34,6 @@
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
#if PLATFORM(CAIRO)
#include <cairo.h>
#endif
namespace WebCore {
// The RGBA32Buffer object represents the decoded image data in RGBA32 format. This buffer is what all
......@@ -55,14 +51,11 @@ namespace WebCore {
};
typedef unsigned PixelData;
RGBA32Buffer()
: m_hasAlpha(false)
, m_status(FrameEmpty)
, m_duration(0)
, m_disposalMethod(DisposeNotSpecified)
{
}
RGBA32Buffer();
// For backends which refcount their data, this constructor doesn't need
// to create a new copy of the image data, only increase the ref count.
//
// This exists because ImageDecoder keeps a Vector<RGBA32Buffer>, and
// Vector requires this constructor.
RGBA32Buffer(const RGBA32Buffer& other)
......@@ -70,38 +63,20 @@ namespace WebCore {
operator=(other);
}
void clear()
{
m_bytes.clear();
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.
}
// Deletes the pixel data entirely; used by ImageDecoder to save memory
// when we no longer need to display a frame and only need its metadata.
void clear();
void zeroFill()
{
m_bytes.fill(0);
m_hasAlpha = true;
}
// This function creates a new copy of the image data in |other|, so the
// two images can be modified independently.
void copyBitmapData(const RGBA32Buffer& other)
{
if (this == &other)
return;
// Zeroes the pixel data in the buffer, setting it to fully-transparent.
void zeroFill();
m_bytes = other.m_bytes;
setHasAlpha(other.m_hasAlpha);
}
// Creates a new copy of the image data in |other|, so the two images
// can be modified independently.
void copyBitmapData(const RGBA32Buffer& other);
// This function copies [(startX, startY), (endX, startY)) to the same
// X-coordinates on each subsequent row up to but not including endY.
//
// NOTE: This function does not sanity-check its arguments! Callers
// MUST not pass invalid values or this will corrupt memory.
// Copies the pixel data at [(startX, startY), (endX, startY)) to the
// same X-coordinates on each subsequent row up to but not including
// endY.
void copyRowNTimes(int startX, int endX, int startY, int endY)
{
ASSERT(startX < width());
......@@ -114,41 +89,24 @@ namespace WebCore {
memcpy(getAddr(startX, endY), startAddr, rowBytes);
}
// Must be called before any pixels are written. Will return true on
// success, false if the memory allocation fails.
bool setSize(int width, int height)
{
// NOTE: This has no way to check for allocation failure if the
// requested size was too big...
m_bytes.resize(width * height);
m_size = IntSize(width, height);
// Zero the image.
zeroFill();
return true;
}
// Allocates space for the pixel data. Must be called before any pixels
// are written. Will return true on success, false if the memory
// allocation fails. Calling this multiple times is undefined and may
// leak memory.
bool setSize(int width, int height);
#if PLATFORM(CAIRO)
// To be used by ImageSource::createFrameAtIndex(). Returns a pointer
// to the underlying native image data. This pointer will be owned by
// the BitmapImage and freed in FrameData::clear().
NativeImagePtr asNewNativeImage() const
{
return cairo_image_surface_create_for_data(
reinterpret_cast<unsigned char*>(const_cast<PixelData*>(
m_bytes.data())), CAIRO_FORMAT_ARGB32, width(), height(),
width() * sizeof(PixelData));
}
#endif
NativeImagePtr asNewNativeImage() const;
bool hasAlpha() const { return m_hasAlpha; }
bool hasAlpha() const;
const IntRect& rect() const { return m_rect; }
FrameStatus status() const { return m_status; }
unsigned duration() const { return m_duration; }
FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
void setHasAlpha(bool alpha);
void setRect(const IntRect& r) { m_rect = r; }
void setStatus(FrameStatus s) { m_status = s; }
void setDuration(unsigned duration) { m_duration = duration; }
......@@ -160,34 +118,12 @@ namespace WebCore {
}
private:
// Initialize with another buffer. This function doesn't create a new copy
// of the image data, it only increases the refcount of the existing bitmap.
//
// Normal callers should not generally be using this function. If you want
// to create a copy on which you can modify the image data independently,
// use copyBitmapData() instead.
RGBA32Buffer& operator=(const RGBA32Buffer& other)
{
if (this == &other)
return *this;
m_bytes = other.m_bytes;
m_size = other.m_size;
setHasAlpha(other.hasAlpha());
setRect(other.rect());
setStatus(other.status());
setDuration(other.duration());
setDisposalMethod(other.disposalMethod());
return *this;
}
RGBA32Buffer& operator=(const RGBA32Buffer& other);
inline int width() const { return m_size.width(); }
inline int height() const { return m_size.height(); }
inline int width() const;
inline int height() const;
inline PixelData* getAddr(int x, int y)
{
return m_bytes.data() + (y * width()) + x;
}
inline PixelData* getAddr(int x, int y);
inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
{
......@@ -205,10 +141,12 @@ namespace WebCore {
}
}
#if PLATFORM(CAIRO)
Vector<PixelData> m_bytes;
IntSize m_size; // The size of the buffer. This should be the
// same as ImageDecoder::m_size.
bool m_hasAlpha; // Whether or not any of the pixels in the buffer have transparency.
#endif
IntRect m_rect; // The rect of the original specified frame within the overall buffer.
// This will always just be the entire buffer except for GIF frames
// whose original rect was smaller than the overall image size.
......
/*
* Copyright (C) 2006 Apple Computer, Inc. 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 "ImageDecoder.h"
#include <cairo.h>
namespace WebCore {
RGBA32Buffer::RGBA32Buffer()
: m_hasAlpha(false)
, m_status(FrameEmpty)
, m_duration(0)
, m_disposalMethod(DisposeNotSpecified)
{
}
void RGBA32Buffer::clear()
{
m_bytes.clear();
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_bytes.fill(0);
m_hasAlpha = true;
}
void RGBA32Buffer::copyBitmapData(const RGBA32Buffer& other)
{
if (this == &other)
return;
m_bytes = other.m_bytes;
setHasAlpha(other.m_hasAlpha);
}
bool RGBA32Buffer::setSize(int width, int height)
{
// NOTE: This has no way to check for allocation failure if the
// requested size was too big...
m_bytes.resize(width * height);
m_size = IntSize(width, height);
// Zero the image.
zeroFill();
return true;
}
NativeImagePtr RGBA32Buffer::asNewNativeImage() const
{
return cairo_image_surface_create_for_data(
reinterpret_cast<unsigned char*>(const_cast<PixelData*>(
m_bytes.data())), CAIRO_FORMAT_ARGB32, width(), height(),
width() * sizeof(PixelData));
}
bool RGBA32Buffer::hasAlpha() const {
return m_hasAlpha;
}
void RGBA32Buffer::setHasAlpha(bool alpha) {
m_hasAlpha = alpha;
}
RGBA32Buffer& RGBA32Buffer::operator=(const RGBA32Buffer& other)
{
if (this == &other)
return *this;
m_bytes = other.m_bytes;
m_size = other.m_size;
setHasAlpha(other.hasAlpha());
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();
}
RGBA32Buffer::PixelData* RGBA32Buffer::getAddr(int x, int y)
{
return m_bytes.data() + (y * width()) + x;
}
} // namespace WebCore
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment