2006-12-27 Eric Seidel <eric@webkit.org>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Dec 2006 00:48:37 +0000 (00:48 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Dec 2006 00:48:37 +0000 (00:48 +0000)
        Reviewed by olliej.

        Add new PDFDocumentImage and BitmapImage classes (subclasses of Image)
        (In preparation for adding SVGImage as part of bug 5971)
        http://bugs.webkit.org/show_bug.cgi?id=11990

        Test cases landed separately as part of filing bug 11992.

        * WebCore.xcodeproj/project.pbxproj: add BitmapImage.*
        * loader/CachedImage.cpp:
        (WebCore::nullImage): use BitmapImage directly
        (WebCore::CachedImage::createImage): now create either BitmapImage or PDFDocumentImage directly
        * loader/icon/IconDataCache.cpp:
        (WebCore::IconDataCache::setImageData): use BitmapImage directly
        * platform/graphics/BitmapImage.cpp: Added.
        (WebCore::BitmapImage::BitmapImage):
        (WebCore::BitmapImage::~BitmapImage):
        (WebCore::BitmapImage::invalidateData):
        (WebCore::BitmapImage::cacheFrame):
        (WebCore::BitmapImage::size):
        (WebCore::BitmapImage::setNativeData):
        (WebCore::BitmapImage::frameCount):
        (WebCore::BitmapImage::isSizeAvailable):
        (WebCore::BitmapImage::frameAtIndex):
        (WebCore::BitmapImage::frameDurationAtIndex):
        (WebCore::BitmapImage::frameHasAlphaAtIndex):
        (WebCore::BitmapImage::shouldAnimate):
        (WebCore::BitmapImage::startAnimation):
        (WebCore::BitmapImage::stopAnimation):
        (WebCore::BitmapImage::resetAnimation):
        (WebCore::BitmapImage::advanceAnimation):
        * platform/graphics/BitmapImage.h: Added.
        (WebCore::FrameData::FrameData):
        (WebCore::BitmapImage::nativeImageForCurrentFrame): added.
        (WebCore::BitmapImage::currentFrame):
        (WebCore::BitmapImage::mayFillWithSolidColor): added.
        (WebCore::BitmapImage::solidColor): added.
        * platform/graphics/Image.cpp:
        (WebCore::Image::Image):
        (WebCore::Image::~Image):
        * platform/graphics/Image.h:
        (WebCore::Image::setNativeData): now virtual
        (WebCore::Image::stopAnimation): now virtual
        (WebCore::Image::resetAnimation): now virtual
        (WebCore::Image::getNSImage): now virtual
        (WebCore::Image::getTIFFRepresentation): now virtual
        (WebCore::Image::getCGImageRef): now virtual
        * platform/graphics/cg/ImageCG.cpp:
        (WebCore::BitmapImage::checkForSolidColor):
        (WebCore::BitmapImage::getCGImageRef): use nativeImageForCurrentFrame
        (WebCore::fillWithSolidColor): added
        (WebCore::BitmapImage::draw):
        (WebCore::drawPattern): use fillWithSolidColor, mayFillWithSolidColor() and solidcolor()
        (WebCore::BitmapImage::drawTiled): use fillWithSolidColor, mayFillWithSolidColor() and solidcolor()
        * platform/graphics/cg/PDFDocumentImage.cpp:
        (WebCore::PDFDocumentImage::PDFDocumentImage):
        (WebCore::PDFDocumentImage::size): change to subclass from Image
        (WebCore::PDFDocumentImage::setNativeData):
        (WebCore::PDFDocumentImage::draw):
        * platform/graphics/cg/PDFDocumentImage.h:
        (WebCore::PDFDocumentImage::drawTiled):
        * platform/graphics/mac/ImageMac.mm:
        (WebCore::BitmapImage::initPlatformData):
        (WebCore::BitmapImage::invalidatePlatformData):
        (WebCore::Image::loadPlatformResource):
        (WebCore::BitmapImage::getTIFFRepresentation):
        (WebCore::BitmapImage::getNSImage):
        * platform/graphics/svg/filters/cg/SVGFEImageCg.mm:
        (WebCore::SVGFEImage::getCIFilter): remove soon-to-be unnecessary comment
        * rendering/RenderImage.cpp:
        (WebCore::RenderImage::nullImage): use BitmapImage

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@18446 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/ksvg2/svg/SVGPathElement.cpp
WebCore/loader/CachedImage.cpp
WebCore/loader/icon/IconDataCache.cpp
WebCore/platform/graphics/BitmapImage.cpp [new file with mode: 0644]
WebCore/platform/graphics/BitmapImage.h [new file with mode: 0644]
WebCore/platform/graphics/Image.cpp
WebCore/platform/graphics/Image.h
WebCore/platform/graphics/cg/ImageCG.cpp
WebCore/platform/graphics/cg/PDFDocumentImage.cpp
WebCore/platform/graphics/cg/PDFDocumentImage.h
WebCore/platform/graphics/mac/ImageMac.mm
WebCore/platform/graphics/svg/filters/cg/SVGFEImageCg.mm
WebCore/rendering/RenderImage.cpp

index e01851b..c1c09c9 100644 (file)
@@ -1,3 +1,77 @@
+2006-12-27  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by olliej.
+
+        Add new PDFDocumentImage and BitmapImage classes (subclasses of Image)
+        (In preparation for adding SVGImage as part of bug 5971)
+        http://bugs.webkit.org/show_bug.cgi?id=11990
+        
+        Test cases landed separately as part of filing bug 11992.
+
+        * WebCore.xcodeproj/project.pbxproj: add BitmapImage.*
+        * loader/CachedImage.cpp:
+        (WebCore::nullImage): use BitmapImage directly
+        (WebCore::CachedImage::createImage): now create either BitmapImage or PDFDocumentImage directly
+        * loader/icon/IconDataCache.cpp:
+        (WebCore::IconDataCache::setImageData): use BitmapImage directly
+        * platform/graphics/BitmapImage.cpp: Added.
+        (WebCore::BitmapImage::BitmapImage):
+        (WebCore::BitmapImage::~BitmapImage):
+        (WebCore::BitmapImage::invalidateData):
+        (WebCore::BitmapImage::cacheFrame):
+        (WebCore::BitmapImage::size):
+        (WebCore::BitmapImage::setNativeData):
+        (WebCore::BitmapImage::frameCount):
+        (WebCore::BitmapImage::isSizeAvailable):
+        (WebCore::BitmapImage::frameAtIndex):
+        (WebCore::BitmapImage::frameDurationAtIndex):
+        (WebCore::BitmapImage::frameHasAlphaAtIndex):
+        (WebCore::BitmapImage::shouldAnimate):
+        (WebCore::BitmapImage::startAnimation):
+        (WebCore::BitmapImage::stopAnimation):
+        (WebCore::BitmapImage::resetAnimation):
+        (WebCore::BitmapImage::advanceAnimation):
+        * platform/graphics/BitmapImage.h: Added.
+        (WebCore::FrameData::FrameData):
+        (WebCore::BitmapImage::nativeImageForCurrentFrame): added.
+        (WebCore::BitmapImage::currentFrame):
+        (WebCore::BitmapImage::mayFillWithSolidColor): added.
+        (WebCore::BitmapImage::solidColor): added.
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::Image):
+        (WebCore::Image::~Image):
+        * platform/graphics/Image.h:
+        (WebCore::Image::setNativeData): now virtual
+        (WebCore::Image::stopAnimation): now virtual
+        (WebCore::Image::resetAnimation): now virtual
+        (WebCore::Image::getNSImage): now virtual
+        (WebCore::Image::getTIFFRepresentation): now virtual
+        (WebCore::Image::getCGImageRef): now virtual
+        * platform/graphics/cg/ImageCG.cpp:
+        (WebCore::BitmapImage::checkForSolidColor):
+        (WebCore::BitmapImage::getCGImageRef): use nativeImageForCurrentFrame
+        (WebCore::fillWithSolidColor): added
+        (WebCore::BitmapImage::draw):
+        (WebCore::drawPattern): use fillWithSolidColor, mayFillWithSolidColor() and solidcolor()
+        (WebCore::BitmapImage::drawTiled): use fillWithSolidColor, mayFillWithSolidColor() and solidcolor()
+        * platform/graphics/cg/PDFDocumentImage.cpp:
+        (WebCore::PDFDocumentImage::PDFDocumentImage):
+        (WebCore::PDFDocumentImage::size): change to subclass from Image
+        (WebCore::PDFDocumentImage::setNativeData):
+        (WebCore::PDFDocumentImage::draw):
+        * platform/graphics/cg/PDFDocumentImage.h:
+        (WebCore::PDFDocumentImage::drawTiled):
+        * platform/graphics/mac/ImageMac.mm:
+        (WebCore::BitmapImage::initPlatformData):
+        (WebCore::BitmapImage::invalidatePlatformData):
+        (WebCore::Image::loadPlatformResource):
+        (WebCore::BitmapImage::getTIFFRepresentation):
+        (WebCore::BitmapImage::getNSImage):
+        * platform/graphics/svg/filters/cg/SVGFEImageCg.mm:
+        (WebCore::SVGFEImage::getCIFilter): remove soon-to-be unnecessary comment
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::nullImage): use BitmapImage
+
 2006-12-27  Mitz Pettel  <mitz@webkit.org>
 
         Reviewed by Hyatt.
index ba753b2..a440ce5 100644 (file)
                A88AD50C095248F0001DD196 /* SVGZoomAndPan.h in Headers */ = {isa = PBXBuildFile; fileRef = A8C0F8EC089701F400BA5114 /* SVGZoomAndPan.h */; };
                A88AD52F09524B92001DD196 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A85D7A2F0879EBA9006A9172 /* QuartzCore.framework */; };
                A88AD5AA09525131001DD196 /* SVGCSSStyleSelector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8C0F6FB089701F100BA5114 /* SVGCSSStyleSelector.cpp */; };
+               A89943280B42338800D7C802 /* BitmapImage.h in Headers */ = {isa = PBXBuildFile; fileRef = A89943260B42338700D7C802 /* BitmapImage.h */; };
+               A89943290B42338800D7C802 /* BitmapImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A89943270B42338700D7C802 /* BitmapImage.cpp */; };
                A8C4A7FD09D563270003AC8D /* StyledElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A8C4A7EB09D563270003AC8D /* StyledElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A8C4A7FE09D563270003AC8D /* StyledElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8C4A7EC09D563270003AC8D /* StyledElement.cpp */; };
                A8C4A80009D563270003AC8D /* Node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8C4A7EE09D563270003AC8D /* Node.cpp */; };
                A890DF1C0930974800513F88 /* SVGStyledTransformableElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGStyledTransformableElement.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                A890DF1D0930974800513F88 /* SVGStyledLocatableElement.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = SVGStyledLocatableElement.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                A890DF1E0930974800513F88 /* SVGStyledLocatableElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGStyledLocatableElement.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+               A89943260B42338700D7C802 /* BitmapImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitmapImage.h; sourceTree = "<group>"; };
+               A89943270B42338700D7C802 /* BitmapImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BitmapImage.cpp; sourceTree = "<group>"; };
                A8C0F6EB089701F100BA5114 /* KCanvasRenderingStyle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KCanvasRenderingStyle.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                A8C0F6EC089701F100BA5114 /* KCanvasRenderingStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = KCanvasRenderingStyle.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                A8C0F6EF089701F100BA5114 /* KSVGTimeScheduler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KSVGTimeScheduler.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                B2A015910AF6CD53006BCE0E /* graphics */ = {
                        isa = PBXGroup;
                        children = (
-                               B27535290B053814002CE64F /* cg */,
-                               B27535490B053814002CE64F /* mac */,
-                               B2A015960AF6CD53006BCE0E /* svg */,
                                B27535270B053814002CE64F /* AffineTransform.cpp */,
                                B27535280B053814002CE64F /* AffineTransform.h */,
+                               A89943270B42338700D7C802 /* BitmapImage.cpp */,
+                               A89943260B42338700D7C802 /* BitmapImage.h */,
+                               B27535290B053814002CE64F /* cg */,
                                B27535380B053814002CE64F /* Color.cpp */,
                                B27535390B053814002CE64F /* Color.h */,
                                B275353A0B053814002CE64F /* FloatPoint.cpp */,
                                B27535460B053814002CE64F /* IntRect.h */,
                                B27535470B053814002CE64F /* IntSize.h */,
                                B27535480B053814002CE64F /* IntSizeHash.h */,
+                               B27535490B053814002CE64F /* mac */,
                                B27535520B053814002CE64F /* Path.cpp */,
                                B27535530B053814002CE64F /* Path.h */,
                                B27535540B053814002CE64F /* Pen.cpp */,
                                B27535550B053814002CE64F /* Pen.h */,
+                               B2A015960AF6CD53006BCE0E /* svg */,
                        );
                        path = graphics;
                        sourceTree = "<group>";
                                E12EDB7B0B308A78002704B6 /* EventTarget.h in Headers */,
                                ABC128770B33AA6D00C693D5 /* PopupMenuClient.h in Headers */,
                                B2A10B920B3818BD00099AA4 /* ImageBuffer.h in Headers */,
+                               A89943280B42338800D7C802 /* BitmapImage.h in Headers */,
                                AACF7C4E0B42EE6000080BD8 /* SVGParserUtilities.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                                B297BC700B3C14CF0045A590 /* JSSVGPathSegListCustom.cpp in Sources */,
                                14C9A5EA0B3D105F005A0232 /* Settings.cpp in Sources */,
                                B2080A120B3CA3B600120852 /* JSSVGPointListCustom.cpp in Sources */,
+                               A89943290B42338800D7C802 /* BitmapImage.cpp in Sources */,
                                AACF7C4F0B42EE6000080BD8 /* SVGParserUtilities.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
index 8a465a5..130b59c 100644 (file)
@@ -64,17 +64,6 @@ double SVGPathElement::getTotalLength()
 
 FloatPoint SVGPathElement::getPointAtLength(double /*distance*/)
 {
-    /*
-    double totalDistance = getTotalLength();
-    T2P::BezierPath* path = ownerDoc()->view()->toBezierPath(m_item);
-    if (path) {
-        T2P::Point p;
-        path->pointTangentNormalAt(distance / totalDistance, &p);
-        ret->setX(p.x());
-        ret->setY(p.y());
-    }
-   */
-
     return FloatPoint();
 }
 
index c0a950c..eecb102 100644 (file)
 #include "config.h"
 #include "CachedImage.h"
 
+#include "BitmapImage.h"
 #include "Cache.h"
 #include "CachedResourceClient.h"
 #include "CachedResourceClientWalker.h"
 #include "DocLoader.h"
 #include "Image.h"
 #include "LoaderFunctions.h"
+#include "PDFDocumentImage.h"
 #include "Request.h"
 #include <wtf/Vector.h>
 
@@ -92,7 +94,7 @@ static Image* brokenImage()
 
 static Image* nullImage()
 {
-    static Image nullImage;
+    static BitmapImage nullImage;
     return &nullImage;
 }
 
@@ -134,8 +136,15 @@ void CachedImage::clear()
 inline void CachedImage::createImage()
 {
     // Create the image if it doesn't yet exist.
-    if (!m_image)
-        m_image = new Image(this, m_response.mimeType() == "application/pdf");
+    
+    if (!m_image) {
+#ifdef PLATFORM(CG)
+        if (m_response.mimeType() == "application/pdf")
+            m_image = new PDFDocumentImage;
+        else
+#endif
+            m_image = new BitmapImage(this);
+    }
 }
 
 Vector<char>& CachedImage::bufferData(const char* bytes, int addedSize, Request* request)
index 18b97aa..715261c 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "IconDataCache.h"
 
-#include "Image.h"
+#include "BitmapImage.h"
 #include <limits.h>
 #include "Logging.h"
 #include "SQLStatement.h"
@@ -69,7 +69,7 @@ void IconDataCache::setImageData(unsigned char* data, int size)
     // managing an image that was created with a copy of this raw image data.
     if (m_image)
         delete m_image;
-    m_image = new Image();
+    m_image = new BitmapImage();
 
     // Copy the provided data into the buffer of the new Image object
     Vector<char>& dataBuffer = m_image->dataBuffer();
diff --git a/WebCore/platform/graphics/BitmapImage.cpp b/WebCore/platform/graphics/BitmapImage.cpp
new file mode 100644 (file)
index 0000000..6582984
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
+ * Copyright (C) 2004, 2005, 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 "BitmapImage.h"
+
+#include "FloatRect.h"
+#include "ImageAnimationObserver.h"
+#include "IntRect.h"
+#include "PlatformString.h"
+#include "Timer.h"
+#include <wtf/Vector.h>
+#include "MimeTypeRegistry.h"
+
+namespace WebCore {
+
+BitmapImage::BitmapImage(ImageAnimationObserver* observer)
+    : Image(observer)
+    , m_currentFrame(0)
+    , m_frames(0)
+    , m_frameTimer(0)
+    , m_repetitionCount(0)
+    , m_repetitionsComplete(0)
+    , m_isSolidColor(false)
+    , m_animatingImageType(true)
+    , m_animationFinished(false)
+    , m_haveSize(false)
+    , m_sizeAvailable(false)
+{
+    initPlatformData();
+}
+
+BitmapImage::~BitmapImage()
+{
+    invalidateData();
+    stopAnimation();
+}
+
+void BitmapImage::invalidateData()
+{
+    // Destroy the cached images and release them.
+    if (m_frames.size()) {
+        m_frames.last().clear();
+        m_isSolidColor = false;
+        invalidatePlatformData();
+    }
+}
+
+void BitmapImage::cacheFrame(size_t index)
+{
+    size_t numFrames = frameCount();
+    if (!m_frames.size() && shouldAnimate()) {            
+        // Snag the repetition count.
+        m_repetitionCount = m_source.repetitionCount();
+        if (m_repetitionCount == cAnimationNone)
+            m_animatingImageType = false;
+    }
+    
+    if (m_frames.size() < numFrames)
+        m_frames.resize(numFrames);
+
+    m_frames[index].m_frame = m_source.createFrameAtIndex(index);
+    if (m_frames[index].m_frame)
+        checkForSolidColor();
+
+    if (shouldAnimate())
+        m_frames[index].m_duration = m_source.frameDurationAtIndex(index);
+    m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index);
+}
+
+IntSize BitmapImage::size() const
+{
+    if (m_sizeAvailable && !m_haveSize) {
+        m_size = m_source.size();
+        m_haveSize = true;
+    }
+    return m_size;
+}
+
+bool BitmapImage::setNativeData(NativeBytePtr data, bool allDataReceived)
+{
+    invalidateData();
+    
+    // Feed all the data we've seen so far to the image decoder.
+    m_source.setData(data, allDataReceived);
+    
+    // Image properties will not be available until the first frame of the file
+    // reaches kCGImageStatusIncomplete.
+    return isSizeAvailable();
+}
+
+size_t BitmapImage::frameCount()
+{
+    return m_source.frameCount();
+}
+
+bool BitmapImage::isSizeAvailable()
+{
+    if (m_sizeAvailable)
+        return true;
+
+    m_sizeAvailable = m_source.isSizeAvailable();
+
+    return m_sizeAvailable;
+}
+
+NativeImagePtr BitmapImage::frameAtIndex(size_t index)
+{
+    if (index >= frameCount())
+        return 0;
+
+    if (index >= m_frames.size() || !m_frames[index].m_frame)
+        cacheFrame(index);
+
+    return m_frames[index].m_frame;
+}
+
+float BitmapImage::frameDurationAtIndex(size_t index)
+{
+    if (index >= frameCount())
+        return 0;
+
+    if (index >= m_frames.size() || !m_frames[index].m_frame)
+        cacheFrame(index);
+
+    return m_frames[index].m_duration;
+}
+
+bool BitmapImage::frameHasAlphaAtIndex(size_t index)
+{
+    if (index >= frameCount())
+        return 0;
+
+    if (index >= m_frames.size() || !m_frames[index].m_frame)
+        cacheFrame(index);
+
+    return m_frames[index].m_hasAlpha;
+}
+
+bool BitmapImage::shouldAnimate()
+{
+    return (m_animatingImageType && !m_animationFinished && animationObserver());
+}
+
+void BitmapImage::startAnimation()
+{
+    if (m_frameTimer || !shouldAnimate() || frameCount() <= 1)
+        return;
+
+    m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
+    m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
+}
+
+void BitmapImage::stopAnimation()
+{
+    // This timer is used to animate all occurrences of this image.  Don't invalidate
+    // the timer unless all renderers have stopped drawing.
+    delete m_frameTimer;
+    m_frameTimer = 0;
+}
+
+void BitmapImage::resetAnimation()
+{
+    stopAnimation();
+    m_currentFrame = 0;
+    m_repetitionsComplete = 0;
+    m_animationFinished = false;
+}
+
+
+void BitmapImage::advanceAnimation(Timer<BitmapImage>* timer)
+{
+    // Stop the animation.
+    stopAnimation();
+    
+    // See if anyone is still paying attention to this animation.  If not, we don't
+    // advance and will simply pause the animation.
+    if (animationObserver()->shouldStopAnimation(this))
+        return;
+
+    m_currentFrame++;
+    if (m_currentFrame >= frameCount()) {
+        m_repetitionsComplete += 1;
+        if (m_repetitionCount && m_repetitionsComplete >= m_repetitionCount) {
+            m_animationFinished = false;
+            m_currentFrame--;
+            return;
+        }
+        m_currentFrame = 0;
+    }
+
+    // Notify our observer that the animation has advanced.
+    animationObserver()->animationAdvanced(this);
+        
+    // Kick off a timer to move to the next frame.
+    m_frameTimer = new Timer<BitmapImage>(this, &BitmapImage::advanceAnimation);
+    m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
+}
+
+}
diff --git a/WebCore/platform/graphics/BitmapImage.h b/WebCore/platform/graphics/BitmapImage.h
new file mode 100644 (file)
index 0000000..4a6ccdb
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
+ * Copyright (C) 2004, 2005, 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. 
+ */
+
+#ifndef BitmapImage_H
+#define BitmapImage_H
+
+#include "Image.h"
+#include "Color.h"
+#include "IntSize.h"
+
+#if PLATFORM(MAC)
+#ifdef __OBJC__
+@class NSImage;
+#else
+class NSImage;
+#endif
+#endif
+
+#if PLATFORM(WIN)
+typedef struct HBITMAP__ *HBITMAP;
+#endif
+
+namespace WebCore {
+    struct FrameData;
+}
+
+// This complicated-looking declaration tells the framedata Vector that it can copy without
+// having to invoke our copy constructor. This allows us to not have to worry about ref counting
+// the native frames.
+namespace WTF { 
+    template<> class VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {};
+}
+
+namespace WebCore {
+
+template <typename T> class Timer;
+
+// ================================================
+// FrameData Class
+// ================================================
+
+struct FrameData {
+    FrameData()
+        : m_frame(0)
+        , m_duration(0)
+        , m_hasAlpha(true) 
+    {}
+
+    ~FrameData()
+    { 
+        clear();
+    }
+
+    void clear();
+
+    NativeImagePtr m_frame;
+    float m_duration;
+    bool m_hasAlpha;
+};
+
+// =================================================
+// BitmapImage Class
+// =================================================
+
+class BitmapImage : public Image {
+    friend class GraphicsContext;
+public:
+    BitmapImage(ImageAnimationObserver* observer = 0);
+    ~BitmapImage();
+    
+    static BitmapImage* loadPlatformResource(const char* name);
+
+    virtual IntSize size() const;
+
+    virtual bool setNativeData(NativeBytePtr, bool allDataReceived);
+
+    // It may look unusual that there is no start animation call as public API.  This is because
+    // we start and stop animating lazily.  Animation begins whenever someone draws the image.  It will
+    // automatically pause once all observers no longer want to render the image anywhere.
+    virtual void stopAnimation();
+    virtual void resetAnimation();
+    
+#if PLATFORM(MAC)
+    // Accessors for native image formats.
+    virtual NSImage* getNSImage();
+    virtual CFDataRef getTIFFRepresentation();
+#endif
+    
+#if PLATFORM(CG)
+    virtual CGImageRef getCGImageRef();
+#endif
+    
+    NativeImagePtr nativeImageForCurrentFrame() { return frameAtIndex(currentFrame()); }
+
+private:
+    virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator);
+    virtual void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, CompositeOperator);
+    virtual void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator); 
+    
+    size_t currentFrame() const { return m_currentFrame; }
+    size_t frameCount();
+    NativeImagePtr frameAtIndex(size_t);
+    float frameDurationAtIndex(size_t);
+    bool frameHasAlphaAtIndex(size_t); 
+
+    // Decodes and caches a frame. Never accessed except internally.
+    void cacheFrame(size_t index);
+
+    // Called to invalidate all our cached data when more bytes are available.
+    void invalidateData();
+
+    // Whether or not size is available yet.    
+    bool isSizeAvailable();
+
+    // Animation.
+    bool shouldAnimate();
+    void startAnimation();
+    void advanceAnimation(Timer<BitmapImage>*);
+    
+    // Handle platform-specific data
+    void initPlatformData();
+    void invalidatePlatformData();
+
+    // Checks to see if the image is a 1x1 solid color.  We optimize these images and just do a fill rect instead.
+    void checkForSolidColor();
+    
+    bool mayFillWithSolidColor() const { return m_isSolidColor && m_currentFrame == 0; }
+    Color solidColor() const { return m_solidColor; }
+    
+    ImageSource m_source;
+    mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image).
+    
+    size_t m_currentFrame; // The index of the current frame of animation.
+    Vector<FrameData> m_frames; // An array of the cached frames of the animation. We have to ref frames to pin them in the cache.
+    
+    Timer<BitmapImage>* m_frameTimer;
+    int m_repetitionCount; // How many total animation loops we should do.
+    int m_repetitionsComplete;  // How many repetitions we've finished.
+
+#if PLATFORM(MAC)
+    mutable NSImage* m_nsImage; // A cached NSImage of frame 0. Only built lazily if someone actually queries for one.
+    mutable CFDataRef m_tiffRep; // Cached TIFF rep for frame 0.  Only built lazily if someone queries for one.
+#endif
+
+    Color m_solidColor;  // If we're a 1x1 solid color, this is the color to use to fill.
+    bool m_isSolidColor;  // Whether or not we are a 1x1 solid image.
+
+    bool m_animatingImageType;  // Whether or not we're an image type that is capable of animating (GIF).
+    bool m_animationFinished;  // Whether or not we've completed the entire animation.
+
+    mutable bool m_haveSize; // Whether or not our |m_size| member variable has the final overall image size yet.
+    bool m_sizeAvailable; // Whether or not we can obtain the size of the first image frame yet from ImageIO.
+};
+
+}
+
+#endif
index cbb8216..d4467ed 100644 (file)
 #include "config.h"
 #include "Image.h"
 
-#include "FloatRect.h"
-#include "Image.h"
-#include "ImageAnimationObserver.h"
 #include "IntRect.h"
-#include "PlatformString.h"
-#include "Timer.h"
-#include <wtf/Vector.h>
 #include "MimeTypeRegistry.h"
 
-#if PLATFORM(CG)
-// FIXME: Will go away when we make PDF a subclass.
-#include "PDFDocumentImage.h"
-#endif
-
 namespace WebCore {
 
-// ================================================
-// Image Class
-// ================================================
-
-Image::Image()
-: m_currentFrame(0), m_frames(0), m_animationObserver(0),
-  m_frameTimer(0), m_repetitionCount(0), m_repetitionsComplete(0),
-  m_isSolidColor(false), m_animatingImageType(true), m_animationFinished(false),
-  m_haveSize(false), m_sizeAvailable(false)
+Image::Image(ImageAnimationObserver* observer)
+    : m_animationObserver(observer)
 {
-#if PLATFORM(CG)
-    m_isPDF = false; // FIXME: Will go away when we make PDF a subclass.
-    m_PDFDoc = 0;
-#endif
-    initPlatformData();
-}
-
-Image::Image(ImageAnimationObserver* observer, bool isPDF)
- : m_currentFrame(0), m_frames(0), m_animationObserver(0),
-  m_frameTimer(0), m_repetitionCount(0), m_repetitionsComplete(0),
-  m_isSolidColor(false), m_animatingImageType(true), m_animationFinished(false),
-  m_haveSize(false), m_sizeAvailable(false)
-{
-    initPlatformData();
-#if PLATFORM(CG)
-    m_isPDF = isPDF; // FIXME: Will go away when we make PDF a subclass.
-    m_PDFDoc = 0;
-#endif
-    m_animationObserver = observer;
 }
 
 Image::~Image()
 {
-    invalidateData();
-    stopAnimation();
-#if PLATFORM(CG)
-    delete m_PDFDoc; // FIXME: Will go away when we make a PDF image subclass.
-#endif
-}
-
-void Image::invalidateData()
-{
-    // Destroy the cached images and release them.
-    if (m_frames.size()) {
-        m_frames.last().clear();
-        m_isSolidColor = false;
-        invalidatePlatformData();
-    }
-}
-
-void Image::cacheFrame(size_t index)
-{
-    size_t numFrames = frameCount();
-    if (!m_frames.size() && shouldAnimate()) {            
-        // Snag the repetition count.
-        m_repetitionCount = m_source.repetitionCount();
-        if (m_repetitionCount == cAnimationNone)
-            m_animatingImageType = false;
-    }
-    
-    if (m_frames.size() < numFrames)
-        m_frames.resize(numFrames);
-
-    m_frames[index].m_frame = m_source.createFrameAtIndex(index);
-    if (m_frames[index].m_frame)
-        checkForSolidColor();
-
-    if (shouldAnimate())
-        m_frames[index].m_duration = m_source.frameDurationAtIndex(index);
-    m_frames[index].m_hasAlpha = m_source.frameHasAlphaAtIndex(index);
 }
 
-
 bool Image::supportsType(const String& type)
 {
     return MimeTypeRegistry::isSupportedImageResourceMIMEType(type); 
@@ -126,25 +51,6 @@ bool Image::isNull() const
     return size().isEmpty();
 }
 
-IntSize Image::size() const
-{
-#if PLATFORM(CG)
-    // FIXME: Will go away when we make PDF a subclass.
-    if (m_isPDF) {
-        if (m_PDFDoc) {
-            FloatSize size = m_PDFDoc->size();
-            return IntSize((int)size.width(), (int)size.height());
-        }
-    } else
-#endif
-    
-    if (m_sizeAvailable && !m_haveSize) {
-        m_size = m_source.size();
-        m_haveSize = true;
-    }
-    return m_size;
-}
-
 bool Image::setData(bool allDataReceived)
 {
     int length = m_data.size();
@@ -173,136 +79,6 @@ bool Image::setData(bool allDataReceived)
     return result;
 }
 
-bool Image::setNativeData(NativeBytePtr data, bool allDataReceived)
-{
-#if PLATFORM(CG)
-    // FIXME: Will go away when we make PDF a subclass.
-    if (m_isPDF) {
-        if (allDataReceived && !m_PDFDoc)
-            m_PDFDoc = new PDFDocumentImage(data);
-        return m_PDFDoc;
-    }
-#endif
-
-    invalidateData();
-    
-    // Feed all the data we've seen so far to the image decoder.
-    m_source.setData(data, allDataReceived);
-    
-    // Image properties will not be available until the first frame of the file
-    // reaches kCGImageStatusIncomplete.
-    return isSizeAvailable();
-}
-
-size_t Image::frameCount()
-{
-    return m_source.frameCount();
-}
-
-bool Image::isSizeAvailable()
-{
-    if (m_sizeAvailable)
-        return true;
-
-    m_sizeAvailable = m_source.isSizeAvailable();
-
-    return m_sizeAvailable;
-
-}
-
-NativeImagePtr Image::frameAtIndex(size_t index)
-{
-    if (index >= frameCount())
-        return 0;
-
-    if (index >= m_frames.size() || !m_frames[index].m_frame)
-        cacheFrame(index);
-
-    return m_frames[index].m_frame;
-}
-
-float Image::frameDurationAtIndex(size_t index)
-{
-    if (index >= frameCount())
-        return 0;
-
-    if (index >= m_frames.size() || !m_frames[index].m_frame)
-        cacheFrame(index);
-
-    return m_frames[index].m_duration;
-}
-
-bool Image::frameHasAlphaAtIndex(size_t index)
-{
-    if (index >= frameCount())
-        return 0;
-
-    if (index >= m_frames.size() || !m_frames[index].m_frame)
-        cacheFrame(index);
-
-    return m_frames[index].m_hasAlpha;
-}
-
-bool Image::shouldAnimate()
-{
-    return (m_animatingImageType && !m_animationFinished && m_animationObserver);
-}
-
-void Image::startAnimation()
-{
-    if (m_frameTimer || !shouldAnimate() || frameCount() <= 1)
-        return;
-
-    m_frameTimer = new Timer<Image>(this, &Image::advanceAnimation);
-    m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
-}
-
-void Image::stopAnimation()
-{
-    // This timer is used to animate all occurrences of this image.  Don't invalidate
-    // the timer unless all renderers have stopped drawing.
-    delete m_frameTimer;
-    m_frameTimer = 0;
-}
-
-void Image::resetAnimation()
-{
-    stopAnimation();
-    m_currentFrame = 0;
-    m_repetitionsComplete = 0;
-    m_animationFinished = false;
-}
-
-
-void Image::advanceAnimation(Timer<Image>* timer)
-{
-    // Stop the animation.
-    stopAnimation();
-    
-    // See if anyone is still paying attention to this animation.  If not, we don't
-    // advance and will simply pause the animation.
-    if (animationObserver()->shouldStopAnimation(this))
-        return;
-
-    m_currentFrame++;
-    if (m_currentFrame >= frameCount()) {
-        m_repetitionsComplete += 1;
-        if (m_repetitionCount && m_repetitionsComplete >= m_repetitionCount) {
-            m_animationFinished = false;
-            m_currentFrame--;
-            return;
-        }
-        m_currentFrame = 0;
-    }
-
-    // Notify our observer that the animation has advanced.
-    animationObserver()->animationAdvanced(this);
-        
-    // Kick off a timer to move to the next frame.
-    m_frameTimer = new Timer<Image>(this, &Image::advanceAnimation);
-    m_frameTimer->startOneShot(frameDurationAtIndex(m_currentFrame));
-}
-
 IntRect Image::rect() const
 {
     return IntRect(IntPoint(), size());
index c0392b5..33d98a9 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef IMAGE_H_
-#define IMAGE_H_
+#ifndef Image_H
+#define Image_H
 
 #include "Color.h"
 #include "GraphicsTypes.h"
 #include "ImageSource.h"
-#include "IntSize.h"
-#include "FloatSize.h"
 
 #if PLATFORM(MAC)
 #ifdef __OBJC__
@@ -46,90 +44,45 @@ typedef struct HBITMAP__ *HBITMAP;
 #endif
 
 namespace WebCore {
-    struct FrameData;
-}
-
-// This complicated-looking declaration tells the framedata Vector that it can copy without
-// having to invoke our copy constructor. This allows us to not have to worry about ref counting
-// the native frames.
-namespace WTF { 
-    template<> class VectorTraits<WebCore::FrameData> : public SimpleClassVectorTraits {};
-}
-
-namespace WebCore {
 
 class FloatPoint;
 class FloatRect;
+class FloatSize;
 class GraphicsContext;
 class IntRect;
-class PDFDocumentImage;
+class IntSize;
 class String;
 
-template <typename T> class Timer;
-
 // This class gets notified when an image advances animation frames.
 class ImageAnimationObserver;
 
-// ================================================
-// FrameData Class
-// ================================================
-
-struct FrameData {
-    FrameData()
-      :m_frame(0), m_duration(0), m_hasAlpha(true) 
-    {}
-
-    ~FrameData()
-    { 
-        clear();
-    }
-
-    void clear();
-
-    NativeImagePtr m_frame;
-    float m_duration;
-    bool m_hasAlpha;
-};
-
-// =================================================
-// Image Class
-// =================================================
-
 class Image : Noncopyable {
     friend class GraphicsContext;
 public:
-    Image();
-    Image(ImageAnimationObserver* observer, bool isPDF = false);
-    ~Image();
+    Image(ImageAnimationObserver* observer = 0);
+    virtual ~Image();
     
     static Image* loadPlatformResource(const char *name);
-    static bool supportsType(const String& type); 
+    static bool supportsType(const String&); 
 
     bool isNull() const;
 
-    IntSize size() const;
+    virtual IntSize size() const = 0;
     IntRect rect() const;
     int width() const;
     int height() const;
 
     bool setData(bool allDataReceived);
-    bool setNativeData(NativeBytePtr, bool allDataReceived);
+    virtual bool setNativeData(NativeBytePtr, bool allDataReceived) { return false; }
     
     Vector<char>& dataBuffer() { return m_data; }
 
     // It may look unusual that there is no start animation call as public API.  This is because
     // we start and stop animating lazily.  Animation begins whenever someone draws the image.  It will
     // automatically pause once all observers no longer want to render the image anywhere.
-    void stopAnimation();
-    void resetAnimation();
+    virtual void stopAnimation() {}
+    virtual void resetAnimation() {}
     
-    // Frame accessors.
-    size_t currentFrame() const { return m_currentFrame; }
-    size_t frameCount();
-    NativeImagePtr frameAtIndex(size_t index);
-    float frameDurationAtIndex(size_t index);
-    bool frameHasAlphaAtIndex(size_t index);
-
     // Typically the CachedImage that owns us.
     ImageAnimationObserver* animationObserver() const { return m_animationObserver; }
 
@@ -137,80 +90,29 @@ public:
     
 #if PLATFORM(MAC)
     // Accessors for native image formats.
-    NSImage* getNSImage();
-    CFDataRef getTIFFRepresentation();
+    virtual NSImage* getNSImage() { return 0; }
+    virtual CFDataRef getTIFFRepresentation() { return 0; }
 #endif
 
 #if PLATFORM(CG)
-    CGImageRef getCGImageRef();
+    virtual CGImageRef getCGImageRef() { return 0; }
 #endif
 
 #if PLATFORM(WIN)
-    bool getHBITMAP(HBITMAP bmp);
+    bool getHBITMAP(HBITMAP);
 #endif
 
 private:
-    void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator);
-    void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize,
-        CompositeOperator);
-    void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule,
-        CompositeOperator);
-
-    // Decodes and caches a frame. Never accessed except internally.
-    void cacheFrame(size_t index);
-
-    // Called to invalidate all our cached data when more bytes are available.
-    void invalidateData();
-
-    // Whether or not size is available yet.    
-    bool isSizeAvailable();
-
-    // Animation.
-    bool shouldAnimate();
-    void startAnimation();
-    void advanceAnimation(Timer<Image>* timer);
+    virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator) = 0;
+    virtual void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, CompositeOperator) = 0;
+    virtual void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator) = 0;
     
-    // Constructor for OS-specific data.
+    // Handle OS-specific data
     void initPlatformData();
-
-    // Invalidation of native data.
     void invalidatePlatformData();
 
-    // Checks to see if the image is a 1x1 solid color.  We optimize these images and just do a fill rect instead.
-    void checkForSolidColor();
-
-    // Members
-    Vector<char> m_data; // The encoded raw data for the image.
-    ImageSource m_source;
-    mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image).
-    
-    size_t m_currentFrame; // The index of the current frame of animation.
-    Vector<FrameData> m_frames; // An array of the cached frames of the animation. We have to ref frames to pin them in the cache.
-    
-    // Our animation observer.
+    Vector<char> m_data; // The encoded raw data for the image. 
     ImageAnimationObserver* m_animationObserver;
-    Timer<Image>* m_frameTimer;
-    int m_repetitionCount; // How many total animation loops we should do.
-    int m_repetitionsComplete;  // How many repetitions we've finished.
-
-#if PLATFORM(MAC)
-    mutable NSImage* m_nsImage; // A cached NSImage of frame 0. Only built lazily if someone actually queries for one.
-    mutable CFDataRef m_tiffRep; // Cached TIFF rep for frame 0.  Only built lazily if someone queries for one.
-#endif
-
-#if PLATFORM(CG)
-    PDFDocumentImage* m_PDFDoc;
-    bool m_isPDF;
-#endif
-
-    Color m_solidColor;  // If we're a 1x1 solid color, this is the color to use to fill.
-    bool m_isSolidColor;  // Whether or not we are a 1x1 solid image.
-
-    bool m_animatingImageType;  // Whether or not we're an image type that is capable of animating (GIF).
-    bool m_animationFinished;  // Whether or not we've completed the entire animation.
-
-    mutable bool m_haveSize; // Whether or not our |m_size| member variable has the final overall image size yet.
-    bool m_sizeAvailable; // Whether or not we can obtain the size of the first image frame yet from ImageIO.
 };
 
 }
index 00ec958..d07a12f 100644 (file)
@@ -24,7 +24,7 @@
  */
 
 #include "config.h"
-#include "Image.h"
+#include "BitmapImage.h"
 
 #if PLATFORM(CG)
 
@@ -53,7 +53,7 @@ void FrameData::clear()
 
 // Drawing Routines
 
-void Image::checkForSolidColor()
+void BitmapImage::checkForSolidColor()
 {
     if (frameCount() > 1)
         m_isSolidColor = false;
@@ -82,19 +82,24 @@ void Image::checkForSolidColor()
     }
 }
 
-CGImageRef Image::getCGImageRef()
+CGImageRef BitmapImage::getCGImageRef()
 {
     return frameAtIndex(0);
 }
 
-void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp)
+void fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, CompositeOperator op)
 {
-    if (m_isPDF) {
-        if (m_PDFDoc)
-            m_PDFDoc->draw(ctxt, srcRect, dstRect, compositeOp);
+    if (color.alpha() <= 0)
         return;
-    } 
     
+    ctxt->save();
+    ctxt->setCompositeOperation(!color.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
+    ctxt->fillRect(dstRect, color);
+    ctxt->restore();
+}
+
+void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp)
+{
     if (!m_source.initialized())
         return;
     
@@ -104,14 +109,9 @@ void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRec
     CGImageRef image = frameAtIndex(m_currentFrame);
     if (!image) // If it's too early we won't have an image yet.
         return;
-
-    if (m_isSolidColor && m_currentFrame == 0) {
-        if (m_solidColor.alpha() > 0) {
-            ctxt->save();
-            ctxt->setCompositeOperation(!m_solidColor.hasAlpha() && compositeOp == CompositeSourceOver ? CompositeCopy : compositeOp);
-            ctxt->fillRect(ir, m_solidColor);
-            ctxt->restore();
-        }
+    
+    if (mayFillWithSolidColor()) {
+        fillWithSolidColor(ctxt, ir, solidColor(), compositeOp);
         return;
     }
 
@@ -175,8 +175,8 @@ void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRec
 
 static void drawPattern(void* info, CGContextRef context)
 {
-    Image* data = (Image*)info;
-    CGImageRef image = data->frameAtIndex(data->currentFrame());
+    BitmapImage* data = (BitmapImage*)info;
+    CGImageRef image = data->nativeImageForCurrentFrame();
     float w = CGImageGetWidth(image);
     float h = CGImageGetHeight(image);
     CGContextDrawImage(context, GraphicsContext(context).roundToDevicePixels(FloatRect
@@ -185,20 +185,15 @@ static void drawPattern(void* info, CGContextRef context)
 
 static const CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
 
-void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint,
+void BitmapImage::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint,
                       const FloatSize& tileSize, CompositeOperator op)
 {    
     CGImageRef image = frameAtIndex(m_currentFrame);
     if (!image)
         return;
-
-    if (m_isSolidColor && m_currentFrame == 0) {
-        if (m_solidColor.alpha() > 0) {
-            ctxt->save();
-            ctxt->setCompositeOperation(!m_solidColor.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
-            ctxt->fillRect(destRect, m_solidColor);
-            ctxt->restore();
-        }
+    
+    if (mayFillWithSolidColor()) {
+        fillWithSolidColor(ctxt, destRect, solidColor(), op);
         return;
     }
 
@@ -272,20 +267,15 @@ void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
 }
 
 // FIXME: Merge with the other drawTiled eventually, since we need a combination of both for some things.
-void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule,
+void BitmapImage::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule,
                       TileRule vRule, CompositeOperator op)
 {    
     CGImageRef image = frameAtIndex(m_currentFrame);
     if (!image)
         return;
 
-    if (m_isSolidColor && m_currentFrame == 0) {
-        if (m_solidColor.alpha() > 0) {
-            ctxt->save();
-            ctxt->setCompositeOperation(!m_solidColor.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
-            ctxt->fillRect(dstRect, m_solidColor);
-            ctxt->restore();
-        }
+    if (mayFillWithSolidColor()) {
+        fillWithSolidColor(ctxt, dstRect, solidColor(), op);
         return;
     }
 
index 44e19e8..c04a9fc 100644 (file)
@@ -35,15 +35,12 @@ using namespace std;
 
 namespace WebCore {
 
-PDFDocumentImage::PDFDocumentImage(CFDataRef data)
+PDFDocumentImage::PDFDocumentImage()
+    : Image(0) // PDFs don't animate
+    , m_document(0)
+    , m_rotation(0f)
+    , m_currentPage(-1)
 {
-    if (data) {
-        CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
-        m_document = CGPDFDocumentCreateWithProvider(dataProvider);
-        CGDataProviderRelease(dataProvider);
-    }
-    m_currentPage = -1;
-    setCurrentPage(0);
 }
 
 PDFDocumentImage::~PDFDocumentImage()
@@ -51,6 +48,22 @@ PDFDocumentImage::~PDFDocumentImage()
     CGPDFDocumentRelease(m_document);
 }
 
+IntSize PDFDocumentImage::size() const
+{
+    return IntSize((int)m_mediaBox.size().width(), (int)m_mediaBox.size().height());
+}
+
+bool PDFDocumentImage::setNativeData(NativeBytePtr data, bool allDataReceived)
+{
+    if (allDataReceived && !m_document && data) {
+        CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
+        m_document = CGPDFDocumentCreateWithProvider(dataProvider);
+        CGDataProviderRelease(dataProvider);
+        setCurrentPage(0);
+    }
+    return m_document; // return true if size is available
+}
+
 void PDFDocumentImage::adjustCTM(GraphicsContext* context) const
 {
     // rotate the crop box and calculate bounding box
@@ -109,7 +122,7 @@ int PDFDocumentImage::pageCount() const
     return m_document ? CGPDFDocumentGetNumberOfPages(m_document) : 0;
 }
 
-void PDFDocumentImage::draw(GraphicsContext* context, const FloatRect& srcRect, const FloatRect& dstRect, CompositeOperator op) const
+void PDFDocumentImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator op)
 {
     if (!m_document || m_currentPage == -1)
         return;
index 20c0ebf..db95883 100644 (file)
@@ -23,6 +23,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+#include "Image.h"
+
 #include "FloatRect.h"
 #include "GraphicsTypes.h"
 
@@ -34,16 +36,21 @@ namespace WebCore {
 
     class GraphicsContext;
 
-    class PDFDocumentImage {
+    class PDFDocumentImage : public Image {
     public:
-        PDFDocumentImage(CFDataRef);
+        PDFDocumentImage();
         ~PDFDocumentImage();
+        
+        virtual bool setNativeData(NativeBytePtr, bool allDataReceived);
 
-        FloatSize size() const { return m_mediaBox.size(); }
-        void draw(GraphicsContext*, const FloatRect& fromRect, const FloatRect& toRect, CompositeOperator) const;
+        virtual IntSize size() const;
 
     private:
-        void setCurrentPage(int page);
+        virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator);
+        virtual void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, CompositeOperator) { }
+        virtual void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator)  { }
+        
+        void setCurrentPage(int);
         int pageCount() const;
         void adjustCTM(GraphicsContext*) const;
 
index 357b4c2..378c3c1 100644 (file)
  */
 
 #import "config.h"
-#import "Image.h"
+#import "BitmapImage.h"
 
 #import "FloatRect.h"
 #import "FoundationExtras.h"
 #import "GraphicsContext.h"
-#import "PDFDocumentImage.h"
 #import "PlatformString.h"
 #import "WebCoreFrameBridge.h"
 #import "WebCoreSystemInterface.h"
 
 namespace WebCore {
 
-// ================================================
-// Image Class
-// ================================================
-
-void Image::initPlatformData()
+void BitmapImage::initPlatformData()
 {
     m_nsImage = 0;
     m_tiffRep = 0;
 }
 
-void Image::invalidatePlatformData()
+void BitmapImage::invalidatePlatformData()
 {
     if (m_frames.size() != 1)
         return;
@@ -68,14 +63,14 @@ Image* Image::loadPlatformResource(const char *name)
     NSString *imagePath = [bundle pathForResource:[NSString stringWithUTF8String:name] ofType:@"tiff"];
     NSData *namedImageData = [NSData dataWithContentsOfFile:imagePath];
     if (namedImageData) {
-        Image* image = new Image;
+        Image* image = new BitmapImage;
         image->setNativeData((CFDataRef)namedImageData, true);
         return image;
     }
     return 0;
 }
 
-CFDataRef Image::getTIFFRepresentation()
+CFDataRef BitmapImage::getTIFFRepresentation()
 {
     if (m_tiffRep)
         return m_tiffRep;
@@ -108,7 +103,7 @@ CFDataRef Image::getTIFFRepresentation()
     return m_tiffRep;
 }
 
-NSImage* Image::getNSImage()
+NSImage* BitmapImage::getNSImage()
 {
     if (m_nsImage)
         return m_nsImage;
index 0ccd1eb..3ac8265 100644 (file)
@@ -37,7 +37,6 @@ CIFilter* SVGFEImage::getCIFilter(SVGResourceFilter* svgFilter) const
 
     CIFilter* filter;
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    // FIXME: This is only partially implemented (only supports images)
     CIImage* ciImage = [CIImage imageWithCGImage:cachedImage()->image()->getCGImageRef()];
 
     // FIXME: There is probably a nicer way to perform both of these transforms.
index 2ee35d3..9075018 100644 (file)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "RenderImage.h"
 
+#include "BitmapImage.h"
 #include "Document.h"
 #include "GraphicsContext.h"
 #include "HTMLImageElement.h"
@@ -433,7 +434,7 @@ void RenderImage::calcMinMaxWidth()
 
 Image* RenderImage::nullImage()
 {
-    static Image sharedNullImage;
+    static BitmapImage sharedNullImage;
     return &sharedNullImage;
 }