Changeset 40063 in webkit


Ignore:
Timestamp:
Jan 20, 2009 11:52:10 AM (15 years ago)
Author:
krit@webkit.org
Message:

2009-01-20 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

Make SVG pattern platform independent and remove platform code.

Make SVGPattern platform independent
https://bugs.webkit.org/show_bug.cgi?id=21205

  • GNUmakefile.am:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/GraphicsContext.h:
  • platform/graphics/cg/GraphicsContextCG.cpp: (WebCore::GraphicsContext::applyStrokePattern): (WebCore::GraphicsContext::applyFillPattern): (WebCore::GraphicsContext::drawPath): (WebCore::GraphicsContext::fillPath): (WebCore::GraphicsContext::strokePath): (WebCore::GraphicsContext::fillRect): (WebCore::GraphicsContext::strokeRect):
  • svg/graphics/SVGPaintServerPattern.cpp: (WebCore::SVGPaintServerPattern::SVGPaintServerPattern): (WebCore::SVGPaintServerPattern::~SVGPaintServerPattern): (WebCore::SVGPaintServerPattern::setup): (WebCore::SVGPaintServerPattern::renderPath): (WebCore::SVGPaintServerPattern::teardown):
  • svg/graphics/SVGPaintServerPattern.h:
  • svg/graphics/cairo/SVGPaintServerPatternCairo.cpp: Removed.
  • svg/graphics/cg/SVGPaintServerPatternCg.cpp: Removed.
  • svg/graphics/qt/SVGPaintServerPatternQt.cpp: Removed.
  • svg/graphics/skia/SVGPaintServerPatternSkia.cpp: Removed.

LayoutTests:

stroke-pattern is wrong and coords-units-01-b match the behavior of
batik and Firefox.

  • platform/mac/svg/W3C-SVG-1.1/coords-units-01-b-expected.checksum:
  • platform/mac/svg/W3C-SVG-1.1/coords-units-01-b-expected.png:
  • platform/mac/svg/custom/stroked-pattern-expected.checksum:
  • platform/mac/svg/custom/stroked-pattern-expected.png:
Location:
trunk
Files:
4 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r40051 r40063  
     12009-01-20  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        stroke-pattern is wrong and coords-units-01-b match the behavior of
     6        batik and Firefox.
     7
     8        * platform/mac/svg/W3C-SVG-1.1/coords-units-01-b-expected.checksum:
     9        * platform/mac/svg/W3C-SVG-1.1/coords-units-01-b-expected.png:
     10        * platform/mac/svg/custom/stroked-pattern-expected.checksum:
     11        * platform/mac/svg/custom/stroked-pattern-expected.png:
     12
    1132009-01-19  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/LayoutTests/platform/mac/svg/W3C-SVG-1.1/coords-units-01-b-expected.checksum

    r38121 r40063  
    1 eefe528f058ea5d9c1410f90d497656f
     15bf54d0647c985b448ad2aca7aa9e389
  • trunk/LayoutTests/platform/mac/svg/custom/stroked-pattern-expected.checksum

    r38008 r40063  
    1 05e5e91f267142becd5b7004c591cd0e
     193364011085c58d8a5988263423f38e2
  • trunk/WebCore/ChangeLog

    r40062 r40063  
     12009-01-20  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Make SVG pattern platform independent and remove platform code.
     6
     7        Make SVGPattern platform independent
     8        https://bugs.webkit.org/show_bug.cgi?id=21205
     9
     10        * GNUmakefile.am:
     11        * WebCore.pro:
     12        * WebCore.vcproj/WebCore.vcproj:
     13        * WebCore.xcodeproj/project.pbxproj:
     14        * platform/graphics/GraphicsContext.h:
     15        * platform/graphics/cg/GraphicsContextCG.cpp:
     16        (WebCore::GraphicsContext::applyStrokePattern):
     17        (WebCore::GraphicsContext::applyFillPattern):
     18        (WebCore::GraphicsContext::drawPath):
     19        (WebCore::GraphicsContext::fillPath):
     20        (WebCore::GraphicsContext::strokePath):
     21        (WebCore::GraphicsContext::fillRect):
     22        (WebCore::GraphicsContext::strokeRect):
     23        * svg/graphics/SVGPaintServerPattern.cpp:
     24        (WebCore::SVGPaintServerPattern::SVGPaintServerPattern):
     25        (WebCore::SVGPaintServerPattern::~SVGPaintServerPattern):
     26        (WebCore::SVGPaintServerPattern::setup):
     27        (WebCore::SVGPaintServerPattern::renderPath):
     28        (WebCore::SVGPaintServerPattern::teardown):
     29        * svg/graphics/SVGPaintServerPattern.h:
     30        * svg/graphics/cairo/SVGPaintServerPatternCairo.cpp: Removed.
     31        * svg/graphics/cg/SVGPaintServerPatternCg.cpp: Removed.
     32        * svg/graphics/qt/SVGPaintServerPatternQt.cpp: Removed.
     33        * svg/graphics/skia/SVGPaintServerPatternSkia.cpp: Removed.
     34
    1352009-01-20  Darin Fisher  <darin@chromium.org>
    236
  • trunk/WebCore/GNUmakefile.am

    r40044 r40063  
    28372837webcoregtk_sources += \
    28382838        WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp \
    2839         WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp \
    28402839        WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp \
    28412840        WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp
  • trunk/WebCore/WebCore.pro

    r40039 r40063  
    17971797
    17981798SOURCES += \
    1799         svg/graphics/qt/SVGPaintServerPatternQt.cpp \
    18001799        svg/graphics/qt/SVGPaintServerQt.cpp \
    18011800        svg/graphics/qt/SVGResourceFilterQt.cpp \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r40052 r40063  
    1544915449                                        </File>
    1545015450                                        <File
    15451                                                 RelativePath="..\svg\graphics\cg\SVGPaintServerPatternCg.cpp"
    15452                                                 >
    15453                                                 <FileConfiguration
    15454                                                         Name="Debug_Cairo|Win32"
    15455                                                         ExcludedFromBuild="true"
    15456                                                         >
    15457                                                         <Tool
    15458                                                                 Name="VCCLCompilerTool"
    15459                                                         />
    15460                                                 </FileConfiguration>
    15461                                                 <FileConfiguration
    15462                                                         Name="Release_Cairo|Win32"
    15463                                                         ExcludedFromBuild="true"
    15464                                                         >
    15465                                                         <Tool
    15466                                                                 Name="VCCLCompilerTool"
    15467                                                         />
    15468                                                 </FileConfiguration>
    15469                                         </File>
    15470                                         <File
    1547115451                                                RelativePath="..\svg\graphics\cg\SVGResourceFilterCg.cpp"
    1547215452                                                >
     
    1567015650                                        <File
    1567115651                                                RelativePath="..\svg\graphics\cairo\SVGPaintServerCairo.cpp"
    15672                                                 >
    15673                                                 <FileConfiguration
    15674                                                         Name="Debug|Win32"
    15675                                                         ExcludedFromBuild="true"
    15676                                                         >
    15677                                                         <Tool
    15678                                                                 Name="VCCLCompilerTool"
    15679                                                         />
    15680                                                 </FileConfiguration>
    15681                                                 <FileConfiguration
    15682                                                         Name="Release|Win32"
    15683                                                         ExcludedFromBuild="true"
    15684                                                         >
    15685                                                         <Tool
    15686                                                                 Name="VCCLCompilerTool"
    15687                                                         />
    15688                                                 </FileConfiguration>
    15689                                                 <FileConfiguration
    15690                                                         Name="Debug_Internal|Win32"
    15691                                                         ExcludedFromBuild="true"
    15692                                                         >
    15693                                                         <Tool
    15694                                                                 Name="VCCLCompilerTool"
    15695                                                         />
    15696                                                 </FileConfiguration>
    15697                                                 <FileConfiguration
    15698                                                         Name="Release_PGO|Win32"
    15699                                                         ExcludedFromBuild="true"
    15700                                                         >
    15701                                                         <Tool
    15702                                                                 Name="VCCLCompilerTool"
    15703                                                         />
    15704                                                 </FileConfiguration>
    15705                                         </File>
    15706                                         <File
    15707                                                 RelativePath="..\svg\graphics\cairo\SVGPaintServerPatternCairo.cpp"
    1570815652                                                >
    1570915653                                                <FileConfiguration
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r40046 r40063  
    32053205                B24055660B5BE640002A28C0 /* DOMSVGElementInstanceListInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = B24055640B5BE640002A28C0 /* DOMSVGElementInstanceListInternal.h */; };
    32063206                B255992F0D00D8BA00BB825C /* SVGPaintServerCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598930D00D8B800BB825C /* SVGPaintServerCg.cpp */; };
    3207                 B25599310D00D8BA00BB825C /* SVGPaintServerPatternCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598950D00D8B800BB825C /* SVGPaintServerPatternCg.cpp */; };
    32083207                B25599350D00D8BA00BB825C /* SVGResourceFilterCg.mm in Sources */ = {isa = PBXBuildFile; fileRef = B25598990D00D8B800BB825C /* SVGResourceFilterCg.mm */; };
    32093208                B25599370D00D8BA00BB825C /* SVGResourceMaskerCg.mm in Sources */ = {isa = PBXBuildFile; fileRef = B255989B0D00D8B800BB825C /* SVGResourceMaskerCg.mm */; };
     
    79227921                B24055640B5BE640002A28C0 /* DOMSVGElementInstanceListInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMSVGElementInstanceListInternal.h; sourceTree = "<group>"; };
    79237922                B25598930D00D8B800BB825C /* SVGPaintServerCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPaintServerCg.cpp; sourceTree = "<group>"; };
    7924                 B25598950D00D8B800BB825C /* SVGPaintServerPatternCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPaintServerPatternCg.cpp; sourceTree = "<group>"; };
    79257923                B25598990D00D8B800BB825C /* SVGResourceFilterCg.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = SVGResourceFilterCg.mm; sourceTree = "<group>"; };
    79267924                B255989B0D00D8B800BB825C /* SVGResourceMaskerCg.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = SVGResourceMaskerCg.mm; sourceTree = "<group>"; };
     
    1275512753                        children = (
    1275612754                                B25598930D00D8B800BB825C /* SVGPaintServerCg.cpp */,
    12757                                 B25598950D00D8B800BB825C /* SVGPaintServerPatternCg.cpp */,
    1275812755                                B25598990D00D8B800BB825C /* SVGResourceFilterCg.mm */,
    1275912756                                B255989B0D00D8B800BB825C /* SVGResourceMaskerCg.mm */,
     
    1819618193                                B25599AA0D00D8BA00BB825C /* SVGPaintServerLinearGradient.cpp in Sources */,
    1819718194                                B25599AC0D00D8BA00BB825C /* SVGPaintServerPattern.cpp in Sources */,
    18198                                 B25599310D00D8BA00BB825C /* SVGPaintServerPatternCg.cpp in Sources */,
    1819918195                                B25599AE0D00D8BA00BB825C /* SVGPaintServerRadialGradient.cpp in Sources */,
    1820018196                                B25599B00D00D8BA00BB825C /* SVGPaintServerSolid.cpp in Sources */,
  • trunk/WebCore/platform/graphics/GraphicsContext.h

    r40007 r40063  
    163163        bool shouldAntialias() const;
    164164
     165#if PLATFORM(CG)
     166        void applyStrokePattern();
     167        void applyFillPattern();
     168#endif
     169
    165170        void save();
    166171        void restore();
  • trunk/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r39981 r40063  
    390390}
    391391
    392 static void applyStrokePattern(GraphicsContext* context, Pattern* pattern)
    393 {
    394     CGContextRef cgContext = context->platformContext();
    395    
    396     CGPatternRef platformPattern = pattern->createPlatformPattern(context->getCTM());
     392void GraphicsContext::applyStrokePattern()
     393{
     394    CGContextRef cgContext = platformContext();
     395   
     396    CGPatternRef platformPattern = m_common->state.strokePattern.get()->createPlatformPattern(getCTM());
    397397    if (!platformPattern)
    398398        return;
     
    407407}
    408408
    409 static void applyFillPattern(GraphicsContext* context, Pattern* pattern)
    410 {
    411     CGContextRef cgContext = context->platformContext();
    412 
    413     CGPatternRef platformPattern = pattern->createPlatformPattern(context->getCTM());
     409void GraphicsContext::applyFillPattern()
     410{
     411    CGContextRef cgContext = platformContext();
     412
     413    CGPatternRef platformPattern = m_common->state.fillPattern.get()->createPlatformPattern(getCTM());
    414414    if (!platformPattern)
    415415        return;
     
    467467   
    468468    if (state.fillColorSpace == PatternColorSpace)
    469         applyFillPattern(this, m_common->state.fillPattern.get());
     469        applyFillPattern();
    470470    if (state.strokeColorSpace == PatternColorSpace)
    471         applyStrokePattern(this, m_common->state.strokePattern.get());
     471        applyStrokePattern();
    472472
    473473    CGPathDrawingMode drawingMode;
     
    496496        break;
    497497    case PatternColorSpace:
    498         applyFillPattern(this, m_common->state.fillPattern.get());
     498        applyFillPattern();
    499499        fillPathWithFillRule(context, fillRule());
    500500        break;
     
    523523        break;
    524524    case PatternColorSpace:
    525         applyStrokePattern(this, m_common->state.strokePattern.get());
     525        applyStrokePattern();
    526526        CGContextStrokePath(context);
    527527        break;
     
    547547        break;
    548548    case PatternColorSpace:
    549         applyFillPattern(this, m_common->state.fillPattern.get());
     549        applyFillPattern();
    550550        CGContextFillRect(context, rect);
    551551        break;
     
    784784        break;
    785785    case PatternColorSpace:
    786         applyStrokePattern(this, m_common->state.strokePattern.get());
     786        applyStrokePattern();
    787787        CGContextStrokeRectWithWidth(context, r, lineWidth);
    788788        break;
  • trunk/WebCore/svg/graphics/SVGPaintServerPattern.cpp

    r39635 r40063  
    11/*
    22 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
     3 *               2008 Dirk Schulze <krit@webkit.org>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2930#include "SVGPaintServerPattern.h"
    3031
     32#include "GraphicsContext.h"
     33#include "Image.h"
    3134#include "ImageBuffer.h"
     35#include "Pattern.h"
     36#include "RenderObject.h"
    3237#include "SVGPatternElement.h"
    3338#include "SVGRenderTreeAsText.h"
     39#include "TransformationMatrix.h"
    3440
    3541using namespace std;
     
    3945SVGPaintServerPattern::SVGPaintServerPattern(const SVGPatternElement* owner)
    4046    : m_ownerElement(owner)
    41 #if PLATFORM(CG)
    42     , m_patternSpace(0)
    4347    , m_pattern(0)
    44 #endif
    4548{
    4649    ASSERT(owner);
     
    4952SVGPaintServerPattern::~SVGPaintServerPattern()
    5053{
    51 #if PLATFORM(CG)
    52     CGPatternRelease(m_pattern);
    53     CGColorSpaceRelease(m_patternSpace);
    54 #endif
    5554}
    5655
     
    9796}
    9897
     98bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
     99{
     100    FloatRect targetRect;
     101    if (isPaintingText) {
     102        IntRect textBoundary = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect();
     103        targetRect = object->absoluteTransform().inverse().mapRect(textBoundary);
     104    } else
     105        targetRect = object->relativeBBox(false);
     106
     107    const SVGRenderStyle* style = object->style()->svgStyle();
     108    bool isFilled = (type & ApplyToFillTargetType) && style->hasFill();
     109    bool isStroked = (type & ApplyToStrokeTargetType) && style->hasStroke();
     110
     111    ASSERT(isFilled && !isStroked || !isFilled && isStroked);
     112
     113    m_ownerElement->buildPattern(targetRect);
     114    if (!tile())
     115        return false;
     116
     117    context->save();
     118    context->translate(patternBoundaries().x(), patternBoundaries().y());
     119    context->concatCTM(patternTransform());
     120
     121    ASSERT(!m_pattern);
     122
     123    IntRect tileRect = tile()->image()->rect();
     124    if (tileRect.width() > patternBoundaries().width() || tileRect.height() > patternBoundaries().height()) {
     125        // Draw the first cell of the pattern manually to support overflow="visible" on all platforms.
     126        int tileWidth = static_cast<int>(patternBoundaries().width() + 0.5f);
     127        int tileHeight = static_cast<int>(patternBoundaries().height() + 0.5f);
     128        std::auto_ptr<ImageBuffer> tileImage = ImageBuffer::create(IntSize(tileWidth, tileHeight), false);
     129 
     130        GraphicsContext* tileImageContext = tileImage->context();
     131
     132        int numY = static_cast<int>(ceilf(tileRect.height() / tileHeight)) + 1;
     133        int numX = static_cast<int>(ceilf(tileRect.width() / tileWidth)) + 1;
     134
     135        tileImageContext->save();
     136        tileImageContext->translate(-patternBoundaries().width() * numX, -patternBoundaries().height() * numY);
     137        for (int i = numY; i > 0; i--) {
     138            tileImageContext->translate(0, patternBoundaries().height());
     139            for (int j = numX; j > 0; j--) {
     140                tileImageContext->translate(patternBoundaries().width(), 0);
     141                tileImageContext->drawImage(tile()->image(), tileRect, tileRect);
     142            }
     143            tileImageContext->translate(-patternBoundaries().width() * numX, 0);
     144        }
     145        tileImageContext->restore();
     146
     147        m_pattern = Pattern::create(tileImage->image(), true, true);
     148    }
     149    else
     150        m_pattern = Pattern::create(tile()->image(), true, true);
     151
     152    if (isFilled) {
     153        context->setAlpha(style->fillOpacity());
     154        context->setFillPattern(m_pattern);
     155        context->setFillRule(style->fillRule());
     156    }
     157    if (isStroked) {
     158        context->setAlpha(style->strokeOpacity());
     159        context->setStrokePattern(m_pattern);
     160        applyStrokeStyleToContext(context, object->style(), object);
     161    }
     162
     163    if (isPaintingText) {
     164        context->setTextDrawingMode(isFilled ? cTextFill : cTextStroke);
     165#if PLATFORM(CG)
     166        if (isFilled)
     167            context->applyFillPattern();
     168        else
     169            context->applyStrokePattern();
     170#endif
     171    }
     172
     173    return true;
     174}
     175
     176void SVGPaintServerPattern::renderPath(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const
     177{
     178    const SVGRenderStyle* style = path->style()->svgStyle();
     179
     180    if ((type & ApplyToFillTargetType) && style->hasFill())
     181        context->fillPath();
     182
     183    if ((type & ApplyToStrokeTargetType) && style->hasStroke())
     184        context->strokePath();
     185}
     186
     187void SVGPaintServerPattern::teardown(GraphicsContext*& context, const RenderObject*, SVGPaintTargetType, bool) const
     188{
     189    m_pattern = 0;
     190
     191    context->restore();
     192}
     193
    99194} // namespace WebCore
    100195
  • trunk/WebCore/svg/graphics/SVGPaintServerPattern.h

    r39635 r40063  
    3131#include "TransformationMatrix.h"
    3232#include "FloatRect.h"
     33#include "Pattern.h"
    3334#include "SVGPaintServer.h"
    3435
     
    6465
    6566        virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
    66 #if PLATFORM(CG) || PLATFORM(QT)
     67        virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const;
    6768        virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
    68 #endif
    6969
    7070    private:
     
    7676        FloatRect m_patternBoundaries;
    7777
    78 #if PLATFORM(CG)
    79         mutable CGColorSpaceRef m_patternSpace;
    80         mutable CGPatternRef m_pattern;
    81 #endif               
     78        mutable RefPtr<Pattern> m_pattern;
    8279    };
    8380
Note: See TracChangeset for help on using the changeset viewer.