Reviewed by Sam. Previous attempts reviewed by Oliver & Eric.
authorzimmermann <zimmermann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2006 14:51:13 +0000 (14:51 +0000)
committerzimmermann <zimmermann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Dec 2006 14:51:13 +0000 (14:51 +0000)
Fixes: http://bugs.webkit.org/show_bug.cgi?id=11867
Bring back masking, by adding off-screen rendering functionality in GraphicsContext.
Add new "static GraphicsContext* createImageContext(const IntSize& size, bool grayScale)"
function, and implement it with CGBitmapContext in the GraphicsContextCG (stubs for Qt.)

Mask image sizes are dynamically calculated using the passed bounding box in applyMask,
as it was orignally planned. Gradient stroke mask image sizes aren't hardcoded to 2048x2048
anymore, but are as well dynamically calculated using getAbsoluteRepaintRect().

Add new ImageBuffer class encapsulating the size of the image, a platform-specific
handle (ie. CGImageRef for CG platform) plus the GraphicsContext pointer, obtained
via GraphicsContext::createImageBuffer. Offer a generic logic for rendering subtrees
of the rendering tree into a ImageBuffer (see renderSubtreeToImage function)
ImageBufferCG is completly implemented, ImageBufferQt is stubbed.

Also add correct default values for x/y/width/height of <mask>.
Fixes masking related LayoutTests, and speeds up gradient-on-stroke a lot.

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

32 files changed:
LayoutTests/ChangeLog
LayoutTests/svg/W3C-SVG-1.1/masking-mask-01-b-expected.png
LayoutTests/svg/W3C-SVG-1.1/pservers-grad-06-b-expected.png
LayoutTests/svg/custom/grayscale-gradient-mask-expected.png
LayoutTests/svg/custom/mask-inside-defs-expected.png
WebCore/CMakeLists.txt
WebCore/ChangeLog
WebCore/WebCore.pro
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/ksvg2/svg/SVGFEImageElement.cpp
WebCore/ksvg2/svg/SVGImageElement.cpp
WebCore/ksvg2/svg/SVGMaskElement.cpp
WebCore/ksvg2/svg/SVGMaskElement.h
WebCore/ksvg2/svg/SVGPatternElement.cpp
WebCore/ksvg2/svg/SVGPatternElement.h
WebCore/platform/graphics/GraphicsContext.h
WebCore/platform/graphics/ImageBuffer.cpp [new file with mode: 0644]
WebCore/platform/graphics/ImageBuffer.h [moved from WebCore/platform/graphics/svg/SVGResourceImage.h with 71% similarity]
WebCore/platform/graphics/cg/GraphicsContextCG.cpp
WebCore/platform/graphics/cg/ImageBufferCG.cpp [new file with mode: 0644]
WebCore/platform/graphics/mac/GraphicsContextMac.mm
WebCore/platform/graphics/qt/GraphicsContextQt.cpp
WebCore/platform/graphics/qt/ImageBufferQt.cpp [moved from WebCore/platform/graphics/svg/cg/SVGResourceImageCg.cpp with 64% similarity]
WebCore/platform/graphics/svg/SVGPaintServerGradient.h
WebCore/platform/graphics/svg/SVGPaintServerPattern.cpp
WebCore/platform/graphics/svg/SVGPaintServerPattern.h
WebCore/platform/graphics/svg/SVGResourceMasker.cpp
WebCore/platform/graphics/svg/SVGResourceMasker.h
WebCore/platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp
WebCore/platform/graphics/svg/cg/SVGPaintServerPatternCg.cpp
WebCore/platform/graphics/svg/cg/SVGResourceMaskerCg.mm
WebCore/platform/graphics/svg/qt/SVGResourceImageQt.cpp [deleted file]

index bf8d497bf4cfc02029060ddb7a0add678df64ed2..47347d9b304130f633f831813026942061dee9c9 100644 (file)
@@ -1,3 +1,16 @@
+2006-12-18  Nikolas Zimmermann  <zimmermann@kde.org>
+
+        Reviewed by Sam. Previous attempts reviewed by Oliver & Eric.
+
+        Fixes: http://bugs.webkit.org/show_bug.cgi?id=11867
+
+        Bring back masks into a working shape.
+
+        * svg/W3C-SVG-1.1/masking-mask-01-b-expected.png:
+        * svg/W3C-SVG-1.1/pservers-grad-06-b-expected.png:
+        * svg/custom/grayscale-gradient-mask-expected.png:
+        * svg/custom/mask-inside-defs-expected.png:
+
 2006-12-18  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Beth Dakin.
index a768984b1b2fca08529258368c97e745eb476648..4ef34baff81ff01e0744d00cbcee46edc2fb7fc8 100644 (file)
Binary files a/LayoutTests/svg/W3C-SVG-1.1/masking-mask-01-b-expected.png and b/LayoutTests/svg/W3C-SVG-1.1/masking-mask-01-b-expected.png differ
index ecfc7db6797f86f6439ba98bbe44eeb5a855c1f0..fa1a1339f2760a87e8aaf00970d64abcefa0f625 100644 (file)
Binary files a/LayoutTests/svg/W3C-SVG-1.1/pservers-grad-06-b-expected.png and b/LayoutTests/svg/W3C-SVG-1.1/pservers-grad-06-b-expected.png differ
index c51ea0f91d15315bce2ee3aa395b5392e55d099b..0789af61876d2c15a67109553ac0d925af0d8528 100644 (file)
Binary files a/LayoutTests/svg/custom/grayscale-gradient-mask-expected.png and b/LayoutTests/svg/custom/grayscale-gradient-mask-expected.png differ
index c551bfd23ed2bb684e2a325088ac775c10769a2f..dea1acd93671d9ab12b34758c0d1bc28841c58b2 100644 (file)
Binary files a/LayoutTests/svg/custom/mask-inside-defs-expected.png and b/LayoutTests/svg/custom/mask-inside-defs-expected.png differ
index 56b2331b62844eaf2a2a7910e6938ab4f441e2f4..979746fb2e1625941922572f1517bba749838f24 100644 (file)
@@ -1025,6 +1025,7 @@ set(WebCore_SRCS
     platform/graphics/GraphicsContext.cpp
     platform/graphics/GraphicsTypes.cpp
     platform/graphics/Image.cpp
+    platform/graphics/ImageBuffer.cpp
     platform/graphics/IntRect.cpp
     platform/graphics/Path.cpp
     platform/graphics/Pen.cpp
@@ -1036,6 +1037,7 @@ set(WebCore_SRCS
     platform/graphics/qt/GraphicsContextQt.cpp
     platform/graphics/qt/IconQt.cpp
     platform/graphics/qt/ImageQt.cpp
+    platform/graphics/qt/ImageBufferQt.cpp 
     platform/graphics/qt/ImageSourceQt.cpp
     platform/graphics/qt/ImageDecoderQt.cpp
     platform/graphics/qt/IntPointQt.cpp
@@ -1081,7 +1083,6 @@ set(WebCore_SRCS
     platform/graphics/svg/qt/SVGPaintServerRadialGradientQt.cpp
     platform/graphics/svg/qt/SVGPaintServerSolidQt.cpp
     platform/graphics/svg/qt/SVGResourceClipperQt.cpp
-    platform/graphics/svg/qt/SVGResourceImageQt.cpp
     platform/graphics/svg/qt/SVGResourceMaskerQt.cpp
     platform/graphics/svg/qt/SVGResourceFilterQt.cpp
 
index 553b7189f2bf79c677efecdb3b1bf08cdf4f916f..65a27fec9464f63498059ec069afb0c68a5aaa24 100644 (file)
@@ -1,3 +1,84 @@
+2006-12-19  Nikolas Zimmermann  <zimmermann@kde.org>
+
+        Reviewed by Sam. Previous attempts reviewed by Oliver & Eric.
+
+        Fixes: http://bugs.webkit.org/show_bug.cgi?id=11867
+
+        Bring back masking, by adding off-screen rendering functionality in GraphicsContext.
+        Add new "static GraphicsContext* createImageContext(const IntSize& size, bool grayScale)"
+        function, and implement it with CGBitmapContext in the GraphicsContextCG (stubs for Qt.)
+
+        Mask image sizes are dynamically calculated using the passed bounding box in applyMask,
+        as it was orignally planned. Gradient stroke mask image sizes aren't hardcoded to 2048x2048
+        anymore, but are as well dynamically calculated using getAbsoluteRepaintRect().
+
+        Add new ImageBuffer class encapsulating the size of the image, a platform-specific
+        handle (ie. CGImageRef for CG platform) plus the GraphicsContext pointer, obtained
+        via GraphicsContext::createImageBuffer. Offer a generic logic for rendering subtrees
+        of the rendering tree into a ImageBuffer (see renderSubtreeToImage function)
+        ImageBufferCG is completly implemented, ImageBufferQt is stubbed.
+
+        Also add correct default values for x/y/width/height of <mask>.
+        Fixes masking related LayoutTests, and speeds up gradient-on-stroke a lot.
+
+        * CMakeLists.txt:
+        * WebCore.pro:
+        * WebCore.xcodeproj/project.pbxproj:
+        * ksvg2/svg/SVGFEImageElement.cpp:
+        * ksvg2/svg/SVGImageElement.cpp:
+        * ksvg2/svg/SVGMaskElement.cpp:
+        (WebCore::SVGMaskElement::SVGMaskElement):
+        (WebCore::SVGMaskElement::attributeChanged):
+        (WebCore::SVGMaskElement::parseMappedAttribute):
+        (WebCore::SVGMaskElement::drawMaskerContent):
+        (WebCore::SVGMaskElement::canvasResource):
+        * ksvg2/svg/SVGMaskElement.h:
+        * ksvg2/svg/SVGPatternElement.cpp:
+        (WebCore::SVGPatternElement::drawPatternContentIntoTile):
+        (WebCore::SVGPatternElement::notifyAttributeChange):
+        * ksvg2/svg/SVGPatternElement.h:
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/ImageBuffer.cpp: Added.
+        (WebCore::ImageBuffer::renderSubtreeToImage):
+        * platform/graphics/ImageBuffer.h: Added.
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::createImageBuffer):
+        * platform/graphics/cg/ImageBufferCG.cpp: Added.
+        (WebCore::ImageBuffer::ImageBuffer):
+        (WebCore::ImageBuffer::~ImageBuffer):
+        (WebCore::ImageBuffer::size):
+        (WebCore::ImageBuffer::context):
+        (WebCore::ImageBuffer::cgImage):
+        * platform/graphics/mac/GraphicsContextMac.mm:
+        * platform/graphics/qt/GraphicsContextQt.cpp:
+        (WebCore::GraphicsContext::createImageBuffer):
+        * platform/graphics/qt/ImageBufferQt.cpp: Added.
+        (WebCore::ImageBuffer::ImageBuffer):
+        (WebCore::ImageBuffer::~ImageBuffer):
+        (WebCore::ImageBuffer::size):
+        (WebCore::ImageBuffer::context):
+        * platform/graphics/svg/SVGPaintServerGradient.h:
+        * platform/graphics/svg/SVGPaintServerPattern.cpp:
+        (WebCore::SVGPaintServerPattern::tile):
+        (WebCore::SVGPaintServerPattern::setTile):
+        * platform/graphics/svg/SVGPaintServerPattern.h:
+        * platform/graphics/svg/SVGResourceImage.h: Removed.
+        * platform/graphics/svg/SVGResourceMasker.cpp:
+        (WebCore::SVGResourceMasker::setMask):
+        (WebCore::SVGResourceMasker::mask):
+        * platform/graphics/svg/SVGResourceMasker.h:
+        * platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp:
+        (WebCore::SVGPaintServerGradient::teardown):
+        (WebCore::SVGPaintServerGradient::renderPath):
+        (WebCore::SVGPaintServerGradient::setup):
+        * platform/graphics/svg/cg/SVGPaintServerPatternCg.cpp:
+        (WebCore::patternCallback):
+        (WebCore::SVGPaintServerPattern::setup):
+        * platform/graphics/svg/cg/SVGResourceImageCg.cpp: Removed.
+        * platform/graphics/svg/cg/SVGResourceMaskerCg.mm:
+        (WebCore::SVGResourceMasker::applyMask):
+        * platform/graphics/svg/qt/SVGResourceImageQt.cpp: Removed.
+
 2006-12-19  David Hyatt  <hyatt@apple.com>
 
         Make sure to initialize the CG fill and stroke colors to our initial fill/stroke colors when first
index 927fc953bd2a89fe38379dc47268ee95f75297e4..be73645318d329f4cac6c2fba76ca6c5982f42aa 100644 (file)
@@ -32,9 +32,9 @@ INCLUDEPATH += $$PWD/../JavaScriptCore
 LIBS += -L$$OUTPUT_DIR/lib -lJavaScriptCore
 
 macx {
-       INCLUDEPATH += /opt/local/include /opt/local/include/libxml2
-       INCLUDEPATH += /usr/include/libxml2
-       LIBS += -L/opt/local/lib -lxml2 -lxslt
+    INCLUDEPATH += /opt/local/include /opt/local/include/libxml2
+    INCLUDEPATH += /usr/include/libxml2
+    LIBS += -L/opt/local/lib -lxml2 -lxslt
 }
 
 INCLUDEPATH +=  $$PWD \
@@ -539,6 +539,7 @@ SOURCES += \
     platform/TextEncodingRegistry.cpp \
     platform/Logging.cpp \
     platform/graphics/Color.cpp \
+    platform/graphics/ImageBuffer.cpp \
     platform/DeprecatedPtrListImpl.cpp \
     platform/KURL.cpp \
     platform/StringImpl.cpp \
@@ -550,6 +551,7 @@ SOURCES += \
     platform/qt/LoaderFunctionsQt.cpp \
     platform/qt/FileChooserQt.cpp \
     platform/graphics/qt/IconQt.cpp \
+    platform/graphics/qt/ImageBufferQt.cpp \
     platform/graphics/qt/AffineTransformQt.cpp \
     platform/qt/StringQt.cpp \
     platform/graphics/qt/ColorQt.cpp \
@@ -823,7 +825,7 @@ contains(DEFINES, SVG_SUPPORT=1) {
     SOURCES += \
 # TODO: this-one-is-not-auto-added! FIXME! tmp/SVGElementFactory.cpp \
         bindings/js/JSSVGElementWrapperFactory.cpp \
-       bindings/js/JSSVGMatrixCustom.cpp \
+        bindings/js/JSSVGMatrixCustom.cpp \
         ksvg2/css/SVGCSSParser.cpp \
         ksvg2/css/SVGRenderStyleDefs.cpp \
         ksvg2/css/SVGRenderStyle.cpp \
@@ -981,7 +983,6 @@ contains(DEFINES, SVG_SUPPORT=1) {
         platform/graphics/svg/qt/SVGPaintServerRadialGradientQt.cpp \
         platform/graphics/svg/qt/SVGPaintServerSolidQt.cpp \
         platform/graphics/svg/qt/SVGResourceClipperQt.cpp \
-        platform/graphics/svg/qt/SVGResourceImageQt.cpp \
         platform/graphics/svg/qt/SVGResourceMaskerQt.cpp \
         platform/graphics/svg/qt/SVGResourceFilterQt.cpp \
         rendering/RenderForeignObject.cpp \
index d9b42135f6a4a7163478739d351839f6f8a5f19a..48839ec20b27169cc8d2e06a5a4e918a18495fa4 100644 (file)
                B2310B760B1F46A200D55D87 /* CgSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2310B730B1F46A200D55D87 /* CgSupport.cpp */; };
                B2310B770B1F46A200D55D87 /* CgSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = B2310B740B1F46A200D55D87 /* CgSupport.h */; };
                B2310B780B1F46A300D55D87 /* RenderPathCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2310B750B1F46A200D55D87 /* RenderPathCg.cpp */; };
+               B23BCCE50B3829C9005B2415 /* ImageBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B23BCCE40B3829C9005B2415 /* ImageBuffer.cpp */; };
                B25DFAAF0B2E2929000E6510 /* JSSVGMatrixCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25DFAAE0B2E2929000E6510 /* JSSVGMatrixCustom.cpp */; };
                B27535560B053814002CE64F /* AffineTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B27535270B053814002CE64F /* AffineTransform.cpp */; };
                B27535570B053814002CE64F /* AffineTransform.h in Headers */ = {isa = PBXBuildFile; fileRef = B27535280B053814002CE64F /* AffineTransform.h */; };
                B2A015AA0AF6CD53006BCE0E /* GraphicsTypes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A015940AF6CD53006BCE0E /* GraphicsTypes.cpp */; };
                B2A015AB0AF6CD53006BCE0E /* GraphicsTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A015950AF6CD53006BCE0E /* GraphicsTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                B2A015AC0AF6CD53006BCE0E /* SVGResourceClipperCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A015980AF6CD53006BCE0E /* SVGResourceClipperCg.cpp */; };
-               B2A015AD0AF6CD53006BCE0E /* SVGResourceImageCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A015990AF6CD53006BCE0E /* SVGResourceImageCg.cpp */; };
                B2A015AE0AF6CD53006BCE0E /* SVGResourceMaskerCg.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2A0159A0AF6CD53006BCE0E /* SVGResourceMaskerCg.mm */; };
                B2A015B20AF6CD53006BCE0E /* SVGResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A0159F0AF6CD53006BCE0E /* SVGResource.cpp */; };
                B2A015B30AF6CD53006BCE0E /* SVGResource.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A015A00AF6CD53006BCE0E /* SVGResource.h */; };
                B2A015B40AF6CD53006BCE0E /* SVGResourceClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A015A10AF6CD53006BCE0E /* SVGResourceClipper.cpp */; };
                B2A015B50AF6CD53006BCE0E /* SVGResourceClipper.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A015A20AF6CD53006BCE0E /* SVGResourceClipper.h */; };
-               B2A015B60AF6CD53006BCE0E /* SVGResourceImage.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A015A30AF6CD53006BCE0E /* SVGResourceImage.h */; };
                B2A015B70AF6CD53006BCE0E /* SVGResourceMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A015A40AF6CD53006BCE0E /* SVGResourceMarker.cpp */; };
                B2A015B80AF6CD53006BCE0E /* SVGResourceMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A015A50AF6CD53006BCE0E /* SVGResourceMarker.h */; };
                B2A015B90AF6CD53006BCE0E /* SVGResourceMasker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A015A60AF6CD53006BCE0E /* SVGResourceMasker.cpp */; };
                B2A015BA0AF6CD53006BCE0E /* SVGResourceMasker.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A015A70AF6CD53006BCE0E /* SVGResourceMasker.h */; };
+               B2A10B920B3818BD00099AA4 /* ImageBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A10B910B3818BD00099AA4 /* ImageBuffer.h */; };
+               B2A10B940B3818D700099AA4 /* ImageBufferCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A10B930B3818D700099AA4 /* ImageBufferCG.cpp */; };
                B2BFB5A00B22F76200567E80 /* ImageAnimationObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = B2BFB59F0B22F76200567E80 /* ImageAnimationObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
                B2CB41930AB75904004D9C45 /* SVGRenderingIntent.h in Headers */ = {isa = PBXBuildFile; fileRef = B2CB414C0AB75904004D9C45 /* SVGRenderingIntent.h */; };
                B2CB41A60AB75904004D9C45 /* SVGUnitTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = B2CB415F0AB75904004D9C45 /* SVGUnitTypes.h */; };
                B2310B730B1F46A200D55D87 /* CgSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CgSupport.cpp; sourceTree = "<group>"; };
                B2310B740B1F46A200D55D87 /* CgSupport.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CgSupport.h; sourceTree = "<group>"; };
                B2310B750B1F46A200D55D87 /* RenderPathCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderPathCg.cpp; sourceTree = "<group>"; };
+               B23BCCE40B3829C9005B2415 /* ImageBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBuffer.cpp; sourceTree = "<group>"; };
                B25DFAAE0B2E2929000E6510 /* JSSVGMatrixCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGMatrixCustom.cpp; sourceTree = "<group>"; };
                B27535270B053814002CE64F /* AffineTransform.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = AffineTransform.cpp; sourceTree = "<group>"; };
                B27535280B053814002CE64F /* AffineTransform.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AffineTransform.h; sourceTree = "<group>"; };
                B2A015940AF6CD53006BCE0E /* GraphicsTypes.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsTypes.cpp; sourceTree = "<group>"; };
                B2A015950AF6CD53006BCE0E /* GraphicsTypes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = GraphicsTypes.h; sourceTree = "<group>"; };
                B2A015980AF6CD53006BCE0E /* SVGResourceClipperCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGResourceClipperCg.cpp; sourceTree = "<group>"; };
-               B2A015990AF6CD53006BCE0E /* SVGResourceImageCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGResourceImageCg.cpp; sourceTree = "<group>"; };
                B2A0159A0AF6CD53006BCE0E /* SVGResourceMaskerCg.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = SVGResourceMaskerCg.mm; sourceTree = "<group>"; };
                B2A0159F0AF6CD53006BCE0E /* SVGResource.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGResource.cpp; sourceTree = "<group>"; };
                B2A015A00AF6CD53006BCE0E /* SVGResource.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGResource.h; sourceTree = "<group>"; };
                B2A015A10AF6CD53006BCE0E /* SVGResourceClipper.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGResourceClipper.cpp; sourceTree = "<group>"; };
                B2A015A20AF6CD53006BCE0E /* SVGResourceClipper.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGResourceClipper.h; sourceTree = "<group>"; };
-               B2A015A30AF6CD53006BCE0E /* SVGResourceImage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGResourceImage.h; sourceTree = "<group>"; };
                B2A015A40AF6CD53006BCE0E /* SVGResourceMarker.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGResourceMarker.cpp; sourceTree = "<group>"; };
                B2A015A50AF6CD53006BCE0E /* SVGResourceMarker.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGResourceMarker.h; sourceTree = "<group>"; };
                B2A015A60AF6CD53006BCE0E /* SVGResourceMasker.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGResourceMasker.cpp; sourceTree = "<group>"; };
                B2A015A70AF6CD53006BCE0E /* SVGResourceMasker.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGResourceMasker.h; sourceTree = "<group>"; };
+               B2A10B910B3818BD00099AA4 /* ImageBuffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ImageBuffer.h; sourceTree = "<group>"; };
+               B2A10B930B3818D700099AA4 /* ImageBufferCG.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBufferCG.cpp; sourceTree = "<group>"; };
                B2BFB59F0B22F76200567E80 /* ImageAnimationObserver.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ImageAnimationObserver.h; sourceTree = "<group>"; };
                B2CB41010AB758E6004D9C45 /* SVGAElement.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SVGAElement.idl; sourceTree = "<group>"; };
                B2CB41020AB758E6004D9C45 /* SVGAnimateColorElement.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SVGAnimateColorElement.idl; sourceTree = "<group>"; };
                                B275352D0B053814002CE64F /* FloatSizeCG.cpp */,
                                B2ED97700B1F55CE00257D0F /* GraphicsContextCG.cpp */,
                                B275352F0B053814002CE64F /* GraphicsContextPlatformPrivate.h */,
+                               B2A10B930B3818D700099AA4 /* ImageBufferCG.cpp */,
                                B27535300B053814002CE64F /* ImageCG.cpp */,
                                B27535310B053814002CE64F /* ImageSourceCG.cpp */,
                                B27535320B053814002CE64F /* IntPointCG.cpp */,
                                B27535410B053814002CE64F /* Image.cpp */,
                                B27535420B053814002CE64F /* Image.h */,
                                B2BFB59F0B22F76200567E80 /* ImageAnimationObserver.h */,
+                               B23BCCE40B3829C9005B2415 /* ImageBuffer.cpp */,
+                               B2A10B910B3818BD00099AA4 /* ImageBuffer.h */,
                                B27535430B053814002CE64F /* ImageSource.h */,
                                B27535440B053814002CE64F /* IntPoint.h */,
                                B27535450B053814002CE64F /* IntRect.cpp */,
                                B2A015A20AF6CD53006BCE0E /* SVGResourceClipper.h */,
                                B2E27BD70B0F2AC800F17C7B /* SVGResourceFilter.cpp */,
                                B2E27BD80B0F2AC800F17C7B /* SVGResourceFilter.h */,
-                               B2A015A30AF6CD53006BCE0E /* SVGResourceImage.h */,
                                B2E27BD90B0F2AC800F17C7B /* SVGResourceListener.h */,
                                B2A015A40AF6CD53006BCE0E /* SVGResourceMarker.cpp */,
                                B2A015A50AF6CD53006BCE0E /* SVGResourceMarker.h */,
                                B2D87C860B124E9500B0DE1E /* SVGPaintServerSolidCg.cpp */,
                                B2E27BD30B0F2A9500F17C7B /* SVGResourceFilterCg.mm */,
                                B2A015980AF6CD53006BCE0E /* SVGResourceClipperCg.cpp */,
-                               B2A015990AF6CD53006BCE0E /* SVGResourceImageCg.cpp */,
                                B2A0159A0AF6CD53006BCE0E /* SVGResourceMaskerCg.mm */,
                        );
                        path = cg;
                                B2A015AB0AF6CD53006BCE0E /* GraphicsTypes.h in Headers */,
                                B2A015B30AF6CD53006BCE0E /* SVGResource.h in Headers */,
                                B2A015B50AF6CD53006BCE0E /* SVGResourceClipper.h in Headers */,
-                               B2A015B60AF6CD53006BCE0E /* SVGResourceImage.h in Headers */,
                                B2A015B80AF6CD53006BCE0E /* SVGResourceMarker.h in Headers */,
                                B2A015BA0AF6CD53006BCE0E /* SVGResourceMasker.h in Headers */,
                                B2EBDC9D0AF77E3400AE4A68 /* SVGRenderTreeAsText.h in Headers */,
                                AB7170890B3118080017123E /* SearchPopupMenu.h in Headers */,
                                E12EDB7B0B308A78002704B6 /* EventTarget.h in Headers */,
                                ABC128770B33AA6D00C693D5 /* PopupMenuClient.h in Headers */,
+                               B2A10B920B3818BD00099AA4 /* ImageBuffer.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                B2A015A80AF6CD53006BCE0E /* GraphicsContext.cpp in Sources */,
                                B2A015AA0AF6CD53006BCE0E /* GraphicsTypes.cpp in Sources */,
                                B2A015AC0AF6CD53006BCE0E /* SVGResourceClipperCg.cpp in Sources */,
-                               B2A015AD0AF6CD53006BCE0E /* SVGResourceImageCg.cpp in Sources */,
                                B2A015AE0AF6CD53006BCE0E /* SVGResourceMaskerCg.mm in Sources */,
                                B2A015B20AF6CD53006BCE0E /* SVGResource.cpp in Sources */,
                                B2A015B40AF6CD53006BCE0E /* SVGResourceClipper.cpp in Sources */,
                                14993BE50B2F2B1C0050497F /* FocusController.cpp in Sources */,
                                AB7170A00B31193B0017123E /* SearchPopupMenuMac.mm in Sources */,
                                E12EDBEA0B308E0B002704B6 /* EventTarget.cpp in Sources */,
+                               B2A10B940B3818D700099AA4 /* ImageBufferCG.cpp in Sources */,
+                               B23BCCE50B3829C9005B2415 /* ImageBuffer.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 1e8478b2252204b3448a0e6e7cb7c7e63d34e1c6..b90525e9ba809b5ee3bbc09470154ced91cd9dc7 100644 (file)
@@ -29,7 +29,6 @@
 #include "CachedImage.h"
 #include "DocLoader.h"
 #include "Document.h"
-#include "SVGResourceImage.h"
 #include "SVGLength.h"
 #include "SVGNames.h"
 #include "SVGPreserveAspectRatio.h"
index 4ff43ed7fafc18dedb629b9eca33e51c64d345da..59ae4b33581bdba034ab075ef66df1700e69b85e 100644 (file)
@@ -27,7 +27,6 @@
 #include "SVGImageElement.h"
 
 #include "CSSPropertyNames.h"
-#include "SVGResourceImage.h"
 #include "RenderSVGContainer.h"
 #include "RenderSVGImage.h"
 #include "SVGDocument.h"
index f688e29fb734fff4b6ef7bd5531a8f72840d9935..ce6585daf5c21c6114746a3d86c4d73aa1b6d486 100644 (file)
@@ -27,7 +27,6 @@
 #include "SVGMaskElement.h"
 
 #include "GraphicsContext.h"
-#include "SVGResourceImage.h"
 #include "RenderSVGContainer.h"
 #include "SVGLength.h"
 #include "SVGNames.h"
@@ -50,6 +49,13 @@ SVGMaskElement::SVGMaskElement(const QualifiedName& tagName, Document* doc)
     , m_height(this, LengthModeHeight)
     , m_dirty(true)
 {
+    // Spec: If the attribute is not specified, the effect is as if a value of "-10%" were specified.
+    setXBaseValue(SVGLength(this, LengthModeWidth, "-10%"));
+    setYBaseValue(SVGLength(this, LengthModeHeight, "-10%"));
+  
+    // Spec: If the attribute is not specified, the effect is as if a value of "120%" were specified.
+    setWidthBaseValue(SVGLength(this, LengthModeWidth, "120%"));
+    setHeightBaseValue(SVGLength(this, LengthModeHeight, "120%"));
 }
 
 SVGMaskElement::~SVGMaskElement()
@@ -66,6 +72,7 @@ void SVGMaskElement::attributeChanged(Attribute* attr, bool preserveDecls)
     IntSize newSize = IntSize(lroundf(width().value()), lroundf(height().value()));
     if (!m_masker || !m_masker->mask() || (m_masker->mask()->size() != newSize))
         m_dirty = true;
+
     SVGStyledLocatableElement::attributeChanged(attr, preserveDecls);
 }
 
@@ -98,28 +105,27 @@ void SVGMaskElement::parseMappedAttribute(MappedAttribute* attr)
         SVGStyledElement::parseMappedAttribute(attr);
     }
 }
-SVGResourceImage* SVGMaskElement::drawMaskerContent()
-{
-    // FIXME: Masks are broken! This way it can NOT work!
-    // We need a image->createContext() function - as Eric suggested -
-    // to finally fix the problem in one function, and share it with patterns...
-    return 0;
-    SVGResourceImage* maskImage = new SVGResourceImage();
 
+ImageBuffer* SVGMaskElement::drawMaskerContent()
+{
     IntSize size = IntSize(lroundf(width().value()), lroundf(height().value()));
-    maskImage->init(size);
 
-    OwnPtr<GraphicsContext> context(contextForImage(maskImage));
+    ImageBuffer* maskImage(GraphicsContext::createImageBuffer(size, false));
+    if (!maskImage)
+        return 0;
 
-    RenderSVGContainer* maskContainer = static_cast<RenderSVGContainer*>(renderer());
-    RenderObject::PaintInfo info(context.get(), IntRect(), PaintPhaseForeground, 0, 0, 0);
-    maskContainer->setDrawsContents(true);
-    maskContainer->paint(info, 0, 0);
-    maskContainer->setDrawsContents(false);
+    GraphicsContext* maskImageContext = maskImage->context();
+    ASSERT(maskImageContext);
 
+    maskImageContext->save();
+    maskImageContext->translate(-x().value(), -y().value());
+
+    ImageBuffer::renderSubtreeToImage(maskImage, renderer());
+
+    maskImageContext->restore();
     return maskImage;
 }
-
 RenderObject* SVGMaskElement::createRenderer(RenderArena* arena, RenderStyle*)
 {
     RenderSVGContainer* maskContainer = new (arena) RenderSVGContainer(this);
@@ -134,9 +140,8 @@ SVGResource* SVGMaskElement::canvasResource()
         m_dirty = true;
     }
     if (m_dirty) {
-        RefPtr<SVGResourceImage> mask(drawMaskerContent());
-        m_masker->setMask(mask);
-        m_dirty = (mask == 0);
+        m_masker->setMask(drawMaskerContent());
+        m_dirty = !m_masker->mask();
     }
     return m_masker.get();
 }
index b09e7e7d31cfd029098fdf8183908db0ca25960e..47d1cf97e81d9d86ba0f105e48f4b658eba24901 100644 (file)
@@ -56,7 +56,7 @@ namespace WebCore
         virtual SVGResource* canvasResource();
 
     protected:
-        SVGResourceImage* drawMaskerContent();
+        ImageBuffer* drawMaskerContent();
 
         ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGURIReference, String, Href, href)
         ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGExternalResourcesRequired, bool, ExternalResourcesRequired, externalResourcesRequired)
index fc65e56e8aec64135bb786e93fe851c892d06390..cb6044a472985f3d0fd36fbc42c02b18956883e3 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "Document.h"
 #include "GraphicsContext.h"
-#include "SVGResourceImage.h"
 #include "SVGPaintServerPattern.h"
 #include "RenderSVGContainer.h"
 #include "SVGLength.h"
@@ -181,66 +180,28 @@ void SVGPatternElement::drawPatternContentIntoTile(const SVGPatternElement* targ
         h = height().value();
     }
 
-    m_tile = new SVGResourceImage();
-    m_tile->init(newSize);
-
-    OwnPtr<GraphicsContext> patternContext(contextForImage(m_tile.get()));
-
-    FloatRect rect(_x, _y, w, h);
-    m_paintServer->setBbox(rect);
-    m_paintServer->setPatternTransform(patternTransformMatrix);
-    m_paintServer->setTile(m_tile.get());
+    ImageBuffer* patternImage(GraphicsContext::createImageBuffer(IntSize(w, h), false));
+    if (!patternImage)
+        return;
 
+    // Render subtree into ImageBuffer
     for (Node* n = target->firstChild(); n; n = n->nextSibling()) {
         SVGElement* elem = svg_dynamic_cast(n);
         if (!elem || !elem->isStyled())
             continue;
+
         SVGStyledElement* e = static_cast<SVGStyledElement*>(elem);
         RenderObject* item = e->renderer();
         if (!item)
             continue;
-#if 0
-        // FIXME: None of this code seems to be necessary
-        // to pass the w3c tests (and infact breaks them)
-        // However, I'm leaving it #if 0'd for now until
-        // I can quiz WildFox on the subject -- ecs 11/24/05
-        // It's possible that W3C-SVG-1.1/coords-units-01-b
-        // is failing due to lack of this code.
-        KCanvasMatrix savedMatrix = item->localTransform();
-
-        const SVGStyledElement* savedContext = 0;
-        if (patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
-        {
-            if (activeElement)
-                savedContext = e->pushAttributeContext(activeElement);
-        }
-
-        // Take into account viewportElement's viewBox, if existant...
-        if (viewportElement() && viewportElement()->hasTagName(SVGNames::svgTag))
-        {
-            SVGSVGElement* svgElement = static_cast<SVGSVGElement*>(viewportElement());
-
-            RefPtr<SVGMatrix> svgCTM = svgElement->getCTM();
-            RefPtr<SVGMatrix> ctm = getCTM();
 
-            KCanvasMatrix newMatrix(svgCTM->matrix());
-            newMatrix.multiply(savedMatrix);
-            newMatrix.scale(1.0 / ctm->a(), 1.0 / ctm->d());
-
-            item->setLocalTransform(newMatrix.matrix());
-        }
-#endif
-        RenderObject::PaintInfo info(patternContext.get(), IntRect(), PaintPhaseForeground, 0, 0, 0);
-        item->paint(info, 0, 0);
-
-#if 0
-        if (savedContext)
-            e->pushAttributeContext(savedContext);
-
-        item->setLocalTransform(savedMatrix.matrix());
-#endif
+        ImageBuffer::renderSubtreeToImage(patternImage, item);
     }
+
+    FloatRect rect(_x, _y, w, h);
+    m_paintServer->setBbox(rect);
+    m_paintServer->setPatternTransform(patternTransformMatrix);
+    m_paintServer->setTile(patternImage);
 }
 
 void SVGPatternElement::notifyClientsToRepaint() const
@@ -267,7 +228,7 @@ void SVGPatternElement::notifyAttributeChange() const
         return;
 
     IntSize newSize = IntSize(lroundf(width().value()), lroundf(height().value()));
-    if (m_tile && (m_tile->size() == newSize) || newSize.width() < 1 || newSize.height() < 1)
+    if (m_paintServer->tile() && (m_paintServer->tile()->size() == newSize) || newSize.width() < 1 || newSize.height() < 1)
         return;
 
     m_ignoreAttributeChanges = true;
@@ -294,7 +255,6 @@ void SVGPatternElement::notifyAttributeChange() const
     if (patternTransform()->numberOfItems() > 0)
         patternTransformMatrix = patternTransform()->consolidate()->matrix();
 
-
     SVGPatternElement* nonConstThis = const_cast<SVGPatternElement*>(this);
 
     nonConstThis->fillAttributesFromReferencePattern(target, patternTransformMatrix);   
index e8d117346224481c317f3d1b250a25fa46157ef9..9ee0d379ecd1eaa2153d4287d5346b246135056d 100644 (file)
@@ -33,7 +33,6 @@
 #include "SVGTests.h"
 #include "SVGURIReference.h"
 
-class SVGResourceImage;
 
 namespace WebCore
 {
@@ -83,10 +82,9 @@ namespace WebCore
         ANIMATED_PROPERTY_DECLARATIONS(SVGPatternElement, int, int, PatternContentUnits, patternContentUnits)
         ANIMATED_PROPERTY_DECLARATIONS(SVGPatternElement, SVGTransformList*, RefPtr<SVGTransformList>, PatternTransform, patternTransform)
 
-        mutable RefPtr<SVGResourceImage> m_tile;
         mutable bool m_ignoreAttributeChanges;
         mutable RefPtr<SVGPaintServerPattern> m_paintServer;
-        
+
         virtual const SVGElement* contextElement() const { return this; }
 
     private:
index bbc8ed7307e619d8d7c70553b76313f94c15f79f..32ffe14ed5163f4777a38f37de9122a2244b6086 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "FloatRect.h"
 #include "Image.h"
+#include "ImageBuffer.h"
 #include "IntRect.h"
 #include "Path.h"
 #include "TextDirection.h"
@@ -198,6 +199,8 @@ namespace WebCore {
         PlatformPath* currentPath();
 #endif
 
+        static ImageBuffer* createImageBuffer(const IntSize&, bool grayScale);
+
     private:
         void savePlatformState();
         void restorePlatformState();
@@ -219,11 +222,6 @@ namespace WebCore {
         GraphicsContextPlatformPrivate* m_data;
     };
 
-#ifdef SVG_SUPPORT
-    class SVGResourceImage;
-    GraphicsContext* contextForImage(SVGResourceImage*);
-#endif
-
 } // namespace WebCore
 
 #endif // GraphicsContext_h
diff --git a/WebCore/platform/graphics/ImageBuffer.cpp b/WebCore/platform/graphics/ImageBuffer.cpp
new file mode 100644 (file)
index 0000000..bdf6e51
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * 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 "ImageBuffer.h"
+
+#include "GraphicsContext.h"
+
+#ifdef SVG_SUPPORT
+#include "RenderSVGContainer.h"
+#endif
+
+namespace WebCore {
+
+void ImageBuffer::renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
+{
+    ASSERT(item && image && image->context());
+    RenderObject::PaintInfo info(image->context(), IntRect(), PaintPhaseForeground, 0, 0, 0);
+
+#ifdef SVG_SUPPORT
+    RenderSVGContainer* svgContainer = 0;
+    if(item && item->isKCanvasContainer())
+         svgContainer = static_cast<RenderSVGContainer*>(item);
+
+    bool drawsContents = svgContainer ? svgContainer->drawsContents() : false;
+    if (svgContainer && !drawsContents)
+        svgContainer->setDrawsContents(true);
+#endif
+
+    item->paint(info, 0, 0);
+
+#ifdef SVG_SUPPORT
+    if (svgContainer && !drawsContents)
+        svgContainer->setDrawsContents(false);
+#endif
+}
+
+}
similarity index 71%
rename from WebCore/platform/graphics/svg/SVGResourceImage.h
rename to WebCore/platform/graphics/ImageBuffer.h
index 1a4f7f6630dd1f2aac91453e2ceb679145343e8d..81a38eb98786887372b35f952b1c86e6306d91a1 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef SVGResourceImage_H
-#define SVGResourceImage_H
-
-#ifdef SVG_SUPPORT
+#ifndef ImageBuffer_H
+#define ImageBuffer_H
 
 #include "IntSize.h"
-#include "SVGResource.h"
+#include <wtf/OwnPtr.h>
 
 #if PLATFORM(CG)
-typedef struct CGContext *CGContextRef;
-typedef struct CGLayer *CGLayerRef;
+typedef struct CGImage* CGImageRef;
 #endif
 
 namespace WebCore {
 
-    class Image;
-    class IntSize;
+    class GraphicsContext;
+    class RenderObject;
 
-    class SVGResourceImage : public SVGResource {
+    class ImageBuffer {
     public:
-        SVGResourceImage();
-
-#if PLATFORM(CG)
-        virtual ~SVGResourceImage();
-#endif
-
-        // To be implemented by the specific rendering devices 
-        void init(const Image&);
-        void init(IntSize);
+        ImageBuffer(const IntSize&, GraphicsContext*);
+        ~ImageBuffer();
 
         IntSize size() const;
+        GraphicsContext* context() const;
+
+        // This offers a way to render parts of a WebKit rendering tree into this ImageBuffer class.
+        static void renderSubtreeToImage(ImageBuffer*, RenderObject* item);
 
 #if PLATFORM(CG)
-        CGLayerRef cgLayer();
-        void setCGLayer(CGLayerRef layer);
-    
+        CGImageRef cgImage() const;
+#endif
+
     private:
+        OwnPtr<GraphicsContext> m_context;
+
+#if PLATFORM(CG) 
         IntSize m_size;
-        CGLayerRef m_cgLayer;
+        mutable CGImageRef m_cgImage;
 #endif
     };
-
-} // namespace WebCore
+}
 
 #endif
-
-#endif // SVGResourceImage_H
index b16ddab301f6c98d6ca4605025ea867f4674b16b..5f0f5128799399ca08d8e928eff763b83bc2f8b6 100644 (file)
@@ -789,6 +789,23 @@ void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
     }
 }
 
+ImageBuffer* GraphicsContext::createImageBuffer(const IntSize& size, bool grayScale)
+{
+    unsigned int bytesPerRow = size.width();
+    if (!grayScale)
+        bytesPerRow *= 4;
+
+    void* imageBuffer = fastMalloc(bytesPerRow * size.height());
+    memset(imageBuffer, 0, bytesPerRow * size.height());
+
+    CGColorSpaceRef colorSpace = grayScale ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
+    CGContextRef context = CGBitmapContextCreate(imageBuffer, size.width(), size.height(), 8, bytesPerRow,
+                                                 colorSpace, grayScale ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);
+
+    CGColorSpaceRelease(colorSpace);
+    return new ImageBuffer(size, new GraphicsContext(context));
+}
+
 void GraphicsContext::setPlatformTextDrawingMode(int mode)
 {
     if (paintingDisabled())
diff --git a/WebCore/platform/graphics/cg/ImageBufferCG.cpp b/WebCore/platform/graphics/cg/ImageBufferCG.cpp
new file mode 100644 (file)
index 0000000..babe021
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * 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 "ImageBuffer.h"
+
+#include "GraphicsContext.h"
+
+#include <ApplicationServices/ApplicationServices.h>
+#include <wtf/Assertions.h>
+
+namespace WebCore {
+
+ImageBuffer::ImageBuffer(const IntSize& size, GraphicsContext* context)
+    : m_context(context)
+    , m_size(size)
+    , m_cgImage(0)
+{
+}
+
+ImageBuffer::~ImageBuffer()
+{
+    if (m_cgImage)
+        CGImageRelease(m_cgImage);
+}
+
+IntSize ImageBuffer::size() const
+{
+    return m_size;
+}
+
+GraphicsContext* ImageBuffer::context() const
+{
+    return m_context.get();
+}
+
+CGImageRef ImageBuffer::cgImage() const
+{
+    // It's assumed that if cgImage() is called, the actual rendering to the
+    // contained GraphicsContext must be done, as we create the CGImageRef here.
+    if (!m_cgImage) {
+        ASSERT(context());
+        m_cgImage = CGBitmapContextCreateImage(context()->platformContext());
+    }
+
+    return m_cgImage;
+}
+
+}
index b6562f066811f565287dab4ca8d4aece03c4cfcf..36cef24702e571eda02ae99b8552e2deda7a320a 100644 (file)
@@ -25,7 +25,6 @@
 
 #import "config.h"
 #import "GraphicsContext.h"
-#import "SVGResourceImage.h"
 
 #import "../cg/GraphicsContextPlatformPrivate.h"
 
@@ -179,26 +178,4 @@ void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint& point,
     CGContextRestoreGState(context);
 }
 
-#ifdef SVG_SUPPORT
-GraphicsContext* contextForImage(SVGResourceImage* image)
-{
-    CGLayerRef cgLayer = image->cgLayer();
-
-    // FIXME: Using currentContext / graphicsPort here is a TOTAL hack. See SVGMaskElement comment for a possible solution!
-    CGContextRef currentContext = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
-
-    if (!cgLayer) {
-        ASSERT(currentContext);
-
-        // FIXME: we might not get back a layer if this is a loaded image
-        // maybe this logic should go into SVGResourceImage?
-        cgLayer = CGLayerCreateWithContext(currentContext, CGSize(image->size() + IntSize(1,1)), NULL);  // FIXME + 1 is a hack
-        // FIXME: we should composite the original image onto the layer...
-        image->setCGLayer(cgLayer);
-        CGLayerRelease(cgLayer);
-    }
-    return new GraphicsContext(CGLayerGetContext(cgLayer));
-}
-#endif
-
 }
index 6573955af2161a1a5bc819b95c2090278925adad..817ce6d17947420839258e56ecf0a75417e315a4 100644 (file)
@@ -38,7 +38,6 @@
 #include "GraphicsContext.h"
 #include "Font.h"
 #include "Pen.h"
-#include "SVGResourceImage.h"
 
 #include <QStack>
 #include <QPainter>
@@ -867,13 +866,12 @@ void GraphicsContext::setPlatformFillColor(const Color& color)
     m_data->p().setBrush(QBrush(color));
 }
 
-#ifdef SVG_SUPPORT
-GraphicsContext* contextForImage(SVGResourceImage*)
+ImageBuffer* GraphicsContext::createImageBuffer(const IntSize&, bool)
 {
     // FIXME!
     return 0;
 }
-#endif
 
 }
+
 // vim: ts=4 sw=4 et
similarity index 64%
rename from WebCore/platform/graphics/svg/cg/SVGResourceImageCg.cpp
rename to WebCore/platform/graphics/qt/ImageBufferQt.cpp
index e5e01d65c61d5495e03c10895ebb12b56262f658..a9ab4c85c473ee8cc554799406ebe9617f32d258 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  */
 
 #include "config.h"
-
-#ifdef SVG_SUPPORT
-#include <ApplicationServices/ApplicationServices.h>
-#include "SVGResourceImage.h"
+#include "ImageBuffer.h"
 
 namespace WebCore {
 
-SVGResourceImage::SVGResourceImage()
-    : m_cgLayer(0)
-{
-}
-
-SVGResourceImage::~SVGResourceImage()
-{
-    CGLayerRelease(m_cgLayer);
-}
-
-void SVGResourceImage::init(const Image&)
+ImageBuffer::ImageBuffer(const IntSize&, GraphicsContext*)
 {
-    // no-op
 }
 
-void SVGResourceImage::init(IntSize size)
+ImageBuffer::~ImageBuffer()
 {
-    m_size = size;    
 }
 
-IntSize SVGResourceImage::size() const
+IntSize ImageBuffer::size() const
 {
-    return m_size;
+    return IntSize();
 }
 
-CGLayerRef SVGResourceImage::cgLayer()
+GraphicsContext* ImageBuffer::context() const
 {
-    return m_cgLayer;
+    return 0;
 }
 
-void SVGResourceImage::setCGLayer(CGLayerRef layer)
-{
-    if (m_cgLayer != layer) {
-        CGLayerRelease(m_cgLayer);
-        m_cgLayer = CGLayerRetain(layer);
-    }
 }
-
-} // namespace WebCore
-
-#endif // SVG_SUPPORT
index 9cb36cda4b5c2254c2af1dc5542c7e5805d71f29..74d1ab0232a176b5cf0a1a4cd229fb25dd601c86 100644 (file)
 #include "Color.h"
 #include "SVGPaintServer.h"
 
-#if PLATFORM(CG)
-#include "SVGResourceImage.h"
-#endif
-
 #if PLATFORM(QT)
 class QGradient;
 #endif
 
+#if PLATFORM(CG)
+#include "ImageBuffer.h"
+#endif
+
 namespace WebCore {
 
     enum SVGGradientSpreadMethod {
@@ -114,9 +114,8 @@ namespace WebCore {
         int m_stopsCount;
 
         CGShadingRef m_shadingCache;
-        mutable RefPtr<SVGResourceImage> m_maskImage;
-
         mutable GraphicsContext* m_savedContext;
+        mutable ImageBuffer* m_imageBuffer;
 #endif
     };
 
index b1a00a38e0f5da4d6e5be592bc02827d0671b117..aa8b752850de15136dbcf10f4bb390660d75618f 100644 (file)
@@ -28,7 +28,6 @@
 #ifdef SVG_SUPPORT
 #include "SVGPaintServerPattern.h"
 #include "SVGRenderTreeAsText.h"
-#include "SVGResourceImage.h"
 
 namespace WebCore {
 
@@ -62,14 +61,14 @@ void SVGPaintServerPattern::setBoundingBoxMode(bool mode)
     m_boundingBoxMode = mode;
 }
 
-SVGResourceImage* SVGPaintServerPattern::tile() const
+ImageBuffer* SVGPaintServerPattern::tile() const
 {
     return m_tile.get();
 }
 
-void SVGPaintServerPattern::setTile(const PassRefPtr<SVGResourceImage>& tile)
+void SVGPaintServerPattern::setTile(ImageBuffer* tile)
 {
-    m_tile = tile;
+    m_tile.set(tile);
 }
 
 AffineTransform SVGPaintServerPattern::patternTransform() const
index 3a7b631e8edd8594572731ea63c785ccec5ccac9..3a22b378c41b39881c18c066ad7248449608baf5 100644 (file)
 
 #include "AffineTransform.h"
 #include "FloatRect.h"
+#include "GraphicsContext.h"
 #include "SVGPaintServer.h"
 
-namespace WebCore {
+#include <wtf/OwnPtr.h>
 
-    class SVGResourceImage;
+namespace WebCore {
 
     class SVGPaintServerPattern : public SVGPaintServer {
     public:
@@ -52,8 +53,8 @@ namespace WebCore {
         bool boundingBoxMode() const;
         void setBoundingBoxMode(bool mode = true);
 
-        SVGResourceImage* tile() const;
-        void setTile(const PassRefPtr<SVGResourceImage>&);
+        ImageBuffer* tile() const;
+        void setTile(ImageBuffer*);
 
         AffineTransform patternTransform() const;
         void setPatternTransform(const AffineTransform&);
@@ -73,7 +74,7 @@ namespace WebCore {
 #endif
 
     private:
-        RefPtr<SVGResourceImage> m_tile;
+        OwnPtr<ImageBuffer> m_tile;
         AffineTransform m_patternTransform;
         FloatRect m_bbox;
         bool m_boundingBoxMode;
index bff44aed7e747591f860337411ea8dca54b9f7a7..5e724fb46bfdf9298d5115e774d90f082b54c5f3 100644 (file)
@@ -29,7 +29,6 @@
 #include "SVGResourceMasker.h"
 
 #include "TextStream.h"
-#include "SVGResourceImage.h"
 
 namespace WebCore {
 
@@ -42,12 +41,12 @@ SVGResourceMasker::~SVGResourceMasker()
 {
 }
 
-void SVGResourceMasker::setMask(const PassRefPtr<SVGResourceImage>& mask)
+void SVGResourceMasker::setMask(ImageBuffer* mask)
 {
-    m_mask = mask;
+    m_mask.set(mask);
 }
 
-SVGResourceImage* SVGResourceMasker::mask() const
+ImageBuffer* SVGResourceMasker::mask() const
 {
     return m_mask.get();
 }
index 0e58d30091cbe06f9b328e58badf9873deb2ce10..37e7d1d886be98b7db18e431834fa02b0323558c 100644 (file)
 
 #ifdef SVG_SUPPORT
 
+#include "GraphicsContext.h"
 #include "SVGResource.h"
 
+#include <wtf/OwnPtr.h>
+
 namespace WebCore {
 
     class FloatRect;
-    class GraphicsContext;
-    class SVGResourceImage;
 
     class SVGResourceMasker : public SVGResource {
     public:
         SVGResourceMasker();
         virtual ~SVGResourceMasker();
 
-        void setMask(const PassRefPtr<SVGResourceImage>&);
-        SVGResourceImage* mask() const;
+        void setMask(ImageBuffer* mask);
+        ImageBuffer* mask() const;
 
         virtual bool isMasker() const { return true; }
         virtual TextStream& externalRepresentation(TextStream&) const;
@@ -51,7 +52,7 @@ namespace WebCore {
         void applyMask(GraphicsContext*, const FloatRect& boundingBox) const;
 
     private:
-        RefPtr<SVGResourceImage> m_mask;
+        OwnPtr<ImageBuffer> m_mask;
     };
 
     SVGResourceMasker* getMaskerById(Document*, const AtomicString&);
index 8a14026428daaea9272ff71c72279b127b6065f9..f50cf5bb84270edb28857096786def96bbd0e36c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
+    Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
 
     This file is part of the KDE project
 
@@ -172,7 +172,7 @@ void SVGPaintServerGradient::teardown(GraphicsContext*& context, const RenderObj
     CGShadingRef shading = m_shadingCache;
     CGContextRef contextRef = context->platformContext();
     RenderStyle* style = object->style();
-    ASSERT(contextRef != NULL);
+    ASSERT(contextRef);
 
     if ((type & ApplyToFillTargetType) && style->svgStyle()->hasFill()) {
         // workaround for filling the entire screen with the shading in the case that no text was intersected with the clip
@@ -183,24 +183,23 @@ void SVGPaintServerGradient::teardown(GraphicsContext*& context, const RenderObj
 
     if ((type & ApplyToStrokeTargetType) && style->svgStyle()->hasStroke()) {
         if (isPaintingText()) {
-            int width  = 2048;
-            int height = 2048; // FIXME??? SEE ABOVE
+            IntRect maskRect = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect();
+            maskRect = object->absoluteTransform().inverse().mapRect(maskRect);
 
-            delete context;
+            // Translate from 0x0 image origin to actual rendering position
+            m_savedContext->translate(maskRect.x(), maskRect.y());
+
+            // Clip current context to mask image (gradient)
+            CGContextClipToMask(m_savedContext->platformContext(), CGRectMake(0, 0, maskRect.width(), maskRect.height()), m_imageBuffer->cgImage());
+            m_savedContext->translate(-maskRect.x(), -maskRect.y());
+
+            // Restore on-screen drawing context, after we got the image of the gradient
+            delete m_imageBuffer;
             context = m_savedContext;
             contextRef = context->platformContext();
             m_savedContext = 0;
-
-            void* imageBuffer = fastMalloc(width * height);
-            CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();
-            CGContextRef grayscaleContext = CGBitmapContextCreate(imageBuffer, width, height, 8, width, grayColorSpace, kCGImageAlphaNone);
-            CGColorSpaceRelease(grayColorSpace);
-            CGContextDrawLayerAtPoint(grayscaleContext, CGPointMake(0, 0), m_maskImage->cgLayer());
-            CGImageRef grayscaleImage = CGBitmapContextCreateImage(grayscaleContext);
-            CGContextClipToMask(contextRef, CGRectMake(0, 0, width, height), grayscaleImage);
-            CGContextRelease(grayscaleContext);
-            CGImageRelease(grayscaleImage);
         }
+
         CGContextDrawShading(contextRef, shading);
         context->restore();
     }
@@ -212,7 +211,7 @@ void SVGPaintServerGradient::renderPath(GraphicsContext*& context, const RenderP
 {
     CGContextRef contextRef = context->platformContext();
     RenderStyle* style = path->style();
-    ASSERT(contextRef != NULL);
+    ASSERT(contextRef);
 
     CGRect objectBBox;
     if (boundingBoxMode())
@@ -240,8 +239,6 @@ bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject
     if (listener()) // this seems like bad design to me, should be in a common baseclass. -- ecs 8/6/05
         listener()->resourceNotification();
 
-    m_maskImage = 0;
-
     // FIXME: total const HACK!
     // We need a hook to call this when the gradient gets updated, before drawn.
     if (!m_shadingCache)
@@ -249,7 +246,7 @@ bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject
 
     CGContextRef contextRef = context->platformContext();
     RenderStyle* style = object->style();
-    ASSERT(contextRef != NULL);
+    ASSERT(contextRef);
 
     context->save();
     CGContextSetAlpha(contextRef, style->opacity());
@@ -264,16 +261,19 @@ bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject
         context->save();
         applyStrokeStyleToContext(contextRef, style, object); // FIXME: this seems like the wrong place for this.
         if (isPaintingText()) {
-            m_maskImage = new SVGResourceImage();
-            int width  = 2048;
-            int height = 2048; // FIXME???
-            IntSize size = IntSize(width, height);
-            m_maskImage->init(size);
+            IntRect maskRect = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect();
+            maskRect = object->absoluteTransform().inverse().mapRect(maskRect);
+
+            ImageBuffer* maskImage(GraphicsContext::createImageBuffer(IntSize(maskRect.width(), maskRect.height()), false));
+            GraphicsContext* maskImageContext = maskImage->context();
+
+            maskImageContext->save();
+            maskImageContext->translate(-maskRect.x(), -maskRect.y());
 
-            GraphicsContext* maskImageContext = contextForImage(m_maskImage.get());
             const_cast<RenderObject*>(object)->style()->setColor(Color(255, 255, 255));
             maskImageContext->setTextDrawingMode(cTextStroke);
 
+            m_imageBuffer = maskImage;
             m_savedContext = context;
             context = maskImageContext;
         }
index 45af1a851bd9a025d8a5d334aa7e91ad95ac0924..bb246a54997da9fc861479e8c146906e19f45c98 100644 (file)
 
 #include "GraphicsContext.h"
 #include "RenderObject.h"
-#include "SVGResourceImage.h"
 #include "CgSupport.h"
 
 namespace WebCore {
 
 static void patternCallback(void* info, CGContextRef context)
 {
-    CGLayerRef layer = reinterpret_cast<SVGResourceImage*>(info)->cgLayer();
-    CGContextDrawLayerAtPoint(context, CGPointZero, layer);
+    ImageBuffer* patternImage = reinterpret_cast<ImageBuffer*>(info);
+
+    IntSize patternContentSize = patternImage->size();
+    CGContextDrawImage(context, CGRectMake(0, 0, patternContentSize.width(), patternContentSize.height()), patternImage->cgImage());
 }
 
 bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type) const
@@ -46,14 +47,12 @@ bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject*
 
     CGContextRef contextRef = context->platformContext();
 
-    RefPtr<SVGResourceImage> cell = tile();
-    if (!cell)
+    if (!tile())
         return false;
 
     context->save();
 
-    CGSize cellSize = CGSize(cell->size());
-
+    CGSize cellSize = CGSize(tile()->size());
     CGFloat alpha = 1; // canvasStyle->opacity(); //which?
 
     // Patterns don't seem to resepect the CTM unless we make them...
@@ -65,19 +64,18 @@ bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject*
     CGContextSetPatternPhase(contextRef, phase);
 
     CGPatternCallbacks callbacks = {0, patternCallback, NULL};
-    m_pattern = CGPatternCreate(
-            tile(),
-            CGRectMake(0, 0, cellSize.width, cellSize.height),
-            transform,
-            bbox().width(), //cellSize.width,
-            bbox().height(), //cellSize.height,
-            kCGPatternTilingConstantSpacing,  // FIXME: should ask CG guys.
-            true, // has color
-            &callbacks);
+    m_pattern = CGPatternCreate(tile(),
+                                CGRectMake(0, 0, cellSize.width, cellSize.height),
+                                transform,
+                                bbox().width(),
+                                bbox().height(),
+                                kCGPatternTilingConstantSpacing, // FIXME: should ask CG guys.
+                                true, // has color
+                                &callbacks);
 
     CGContextSetAlpha(contextRef, style->opacity()); // or do I set the alpha above?
 
-    m_patternSpace = CGColorSpaceCreatePattern(NULL);
+    m_patternSpace = CGColorSpaceCreatePattern(0);
 
     if ((type & ApplyToFillTargetType) && style->svgStyle()->hasFill()) {
         CGContextSetFillColorSpace(contextRef, m_patternSpace);
index 4d8327509ca8244a4bb47473e07b4707228e506d..34b8fe32e42c0eb81387d50df4420938d1830b2a 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2005, 2006 Alexander Kellett <lypanov@kde.org>
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,7 +29,6 @@
 #ifdef SVG_SUPPORT
 #import "SVGResourceFilter.h"
 #import "SVGResourceMasker.h"
-#import "SVGResourceImage.h"
 #import "SVGRenderStyle.h"
 
 #import "GraphicsContext.h"
@@ -36,7 +36,7 @@
 
 #import <QuartzCore/CoreImage.h>
 #import <QuartzCore/CIFilter.h>
-#
+
 namespace WebCore {
 
 static CIImage* applyLuminanceToAlphaFilter(CIImage* inputImage)
@@ -91,26 +91,27 @@ void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& bou
 {
     if (!m_mask)
         return;
-    // Create grayscale bitmap context
-    int width = m_mask->size().width();
-    int height = m_mask->size().height();
-    void* imageBuffer = fastMalloc(width * height);
-    CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();
-    CGContextRef grayscaleContext = CGBitmapContextCreate(imageBuffer, width, height, 8, width, grayColorSpace, kCGImageAlphaNone);
-    CGColorSpaceRelease(grayColorSpace);
-    CIContext* ciGrayscaleContext = [CIContext contextWithCGContext:grayscaleContext options:nil];
-
-    SVGResourceImage* maskImage = static_cast<SVGResourceImage*>(m_mask.get());
-    CIImage* grayscaleMask = transformImageIntoGrayscaleMask([CIImage imageWithCGLayer:maskImage->cgLayer()]);
-    [ciGrayscaleContext drawImage:grayscaleMask atPoint:CGPointZero fromRect:CGRectMake(0, 0, width, height)];
-
-    CGImageRef grayscaleImage = CGBitmapContextCreateImage(grayscaleContext);
-    CGContextRef cgContext = context->platformContext();
-    CGContextClipToMask(cgContext, CGRectMake(0, 0, width, height), grayscaleImage);
-
-    CGImageRelease(grayscaleImage);
-    CGContextRelease(grayscaleContext);
-    fastFree(imageBuffer);
+
+    IntSize maskSize = m_mask->size();
+
+    // The mask we operate on is has it's top left corner at (0, 0) on the CGImage.
+    // We have to translate to the current relative bbox, to get the clipping right.
+    CGRect maskDestinationRect = CGRectMake(lroundf(boundingBox.x()), lroundf(boundingBox.y()),
+                                            maskSize.width(), maskSize.height());
+
+    // Create new graphics context in gray scale mode for image rendering
+    OwnPtr<ImageBuffer> grayScaleImage(GraphicsContext::createImageBuffer(maskSize, true));
+    CGContextRef grayScaleContext = grayScaleImage->context()->platformContext();
+
+    // Wrap CG context in CI context
+    CIContext* ciGrayscaleContext = [CIContext contextWithCGContext:grayScaleContext options:nil];
+
+    // Transform colorized mask to gray scale
+    CIImage* grayScaleMask = transformImageIntoGrayscaleMask([CIImage imageWithCGImage:m_mask->cgImage()]);
+    [ciGrayscaleContext drawImage:grayScaleMask atPoint:CGPointZero fromRect:CGRectMake(0, 0, maskSize.width(), maskSize.height())];
+
+    // Do the actual masking!
+    CGContextClipToMask(context->platformContext(), maskDestinationRect, grayScaleImage->cgImage());
 }
 
 } // namespace WebCore
diff --git a/WebCore/platform/graphics/svg/qt/SVGResourceImageQt.cpp b/WebCore/platform/graphics/svg/qt/SVGResourceImageQt.cpp
deleted file mode 100644 (file)
index 1d919e2..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-    Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
-
-    This file is part of the KDE project
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Library General Public
-    License as published by the Free Software Foundation; either
-    version 2 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Library General Public License for more details.
-
-    You should have received a copy of the GNU Library General Public License
-    aint with this library; see the file COPYING.LIB.  If not, write to
-    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-    Boston, MA 02111-1307, USA.
-*/
-
-#include "config.h"
-#include "SVGResourceImage.h"
-
-#ifdef SVG_SUPPORT
-
-#include "IntSize.h"
-
-namespace WebCore {
-
-// FIXME: For now we only stub this methods!
-SVGResourceImage::SVGResourceImage()
-{
-}
-
-void SVGResourceImage::init(const Image&)
-{
-}
-
-void SVGResourceImage::init(IntSize size)
-{
-}
-
-IntSize SVGResourceImage::size() const
-{
-    return IntSize();
-}
-
-} // namespace WebCore
-
-#endif
-
-// vim:ts=4:noet