Changeset 140604 in webkit


Ignore:
Timestamp:
Jan 23, 2013 3:03:30 PM (11 years ago)
Author:
krit@webkit.org
Message:

Implement Canvas Path object
https://bugs.webkit.org/show_bug.cgi?id=97333

Reviewed by Dean Jackson.

Source/WebCore:

The Canvas part of the WHATWG specification defines a Path object. This Path object
shares several path segment functions (path methods) with the CanvasRenderingContext2D
interface. This patch introduces the Path object and shares the path segment functions
in the class CanvasPathMethods.
This patch does just implement the basic path functions that have a general agreement on
the WHAT WG and W3C mailing lists.
This feature is behind a flag and won't be activated by default.

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#path-objects

Test: fast/canvas/canvas-path-object.html

  • CMakeLists.txt: Add DOMPath and CanvasPathMedthods to build system.
  • DerivedSources.cpp: Ditto.
  • DerivedSources.make: Ditto.
  • DerivedSources.pri: Ditto.
  • GNUmakefile.list.am: Ditto.
  • Target.pri: Ditto.
  • WebCore.gypi: Ditto.
  • WebCore.vcproj/WebCore.vcproj: Ditto.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • html/canvas/CanvasPathMethods.cpp: Added.

(WebCore): This class shares the path segment functions (moveTo, lineTo, ...) between

DOMPath (the Path object) and CanvasRenderingContext2D.

(WebCore::CanvasPathMethods::closePath):
(WebCore::CanvasPathMethods::moveTo):
(WebCore::CanvasPathMethods::lineTo):
(WebCore::CanvasPathMethods::quadraticCurveTo):
(WebCore::CanvasPathMethods::bezierCurveTo):
(WebCore::CanvasPathMethods::arcTo):
(WebCore::CanvasPathMethods::arc):
(WebCore::CanvasPathMethods::rect):

  • html/canvas/CanvasPathMethods.h: Added.

(WebCore):
(CanvasPathMethods):
(WebCore::CanvasPathMethods::~CanvasPathMethods):
(WebCore::CanvasPathMethods::transformIsInvertible):
(WebCore::CanvasPathMethods::CanvasPathMethods):

  • html/canvas/CanvasRenderingContext2D.cpp:
  • html/canvas/CanvasRenderingContext2D.h: Remove the path segment functions here.

(CanvasRenderingContext2D):
(WebCore::CanvasRenderingContext2D::transformIsInvertible): This checks if the CTM

of the context is still invertible. Drawing should stop if it is not.

  • html/canvas/CanvasRenderingContext2D.idl:
  • html/canvas/DOMPath.h: Added.

(WebCore):
(DOMPath):
(WebCore::DOMPath::create):
(WebCore::DOMPath::~DOMPath):
(WebCore::DOMPath::DOMPath):

  • html/canvas/DOMPath.idl: Added.
  • page/DOMWindow.idl: Added CTOR for Path.

LayoutTests:

Add a test for checking existence of Path object and dependent functions.
The test is supposed to fail if canvas-path is not activated on compile time.

  • fast/canvas/canvas-path-object-expected.txt: Added.
  • fast/canvas/canvas-path-object.html: Added.
  • fast/canvas/script-tests/canvas-path-object.js: Added.
  • platform/chromium/TestExpectations: Different error handling on Chromium. Needs rebaseline.
Location:
trunk
Files:
7 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r140602 r140604  
     12013-01-23  Dirk Schulze  <dschulze@adobe.com>
     2
     3        Implement Canvas Path object
     4        https://bugs.webkit.org/show_bug.cgi?id=97333
     5
     6        Reviewed by Dean Jackson.
     7
     8        Add a test for checking existence of Path object and dependent functions.
     9        The test is supposed to fail if canvas-path is not activated on compile time.
     10
     11        * fast/canvas/canvas-path-object-expected.txt: Added.
     12        * fast/canvas/canvas-path-object.html: Added.
     13        * fast/canvas/script-tests/canvas-path-object.js: Added.
     14        * platform/chromium/TestExpectations: Different error handling on Chromium. Needs rebaseline.
     15
    1162013-01-23  Joshua Bell  <jsbell@chromium.org>
    217
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r140585 r140604  
    43244324webkit.org/b/105574 platform/chromium/fast/forms/suggestion-picker/week-suggestion-picker-appearance-with-scroll-bar.html [ ImageOnlyFailure ]
    43254325
     4326webkit.org/b/97333 fast/canvas/canvas-path-object.html [ Failure ]
     4327webkit.org/b/97333 platform/chromium/virtual/gpu/fast/canvas/canvas-path-object.html [ Failure ]
     4328
    43264329# This is won't fix, as the debug and release versions differ.
    43274330webkit.org/b/99138 [ Debug SnowLeopard ] svg/custom/foreign-object-skew.svg [ ImageOnlyFailure ]
  • trunk/Source/WebCore/CMakeLists.txt

    r140602 r140604  
    517517    html/canvas/CanvasRenderingContext.idl
    518518    html/canvas/DataView.idl
     519    html/canvas/DOMPath.idl
    519520    html/canvas/EXTTextureFilterAnisotropic.idl
    520521    html/canvas/Float32Array.idl
     
    14961497    html/canvas/CanvasContextAttributes.cpp
    14971498    html/canvas/CanvasGradient.cpp
     1499    html/canvas/CanvasPathMethods.cpp
    14981500    html/canvas/CanvasPattern.cpp
    14991501    html/canvas/CanvasProxy.cpp
  • trunk/Source/WebCore/ChangeLog

    r140602 r140604  
     12013-01-23  Dirk Schulze  <dschulze@adobe.com>
     2
     3        Implement Canvas Path object
     4        https://bugs.webkit.org/show_bug.cgi?id=97333
     5
     6        Reviewed by Dean Jackson.
     7
     8        The Canvas part of the WHATWG specification defines a Path object. This Path object
     9        shares several path segment functions (path methods) with the CanvasRenderingContext2D
     10        interface. This patch introduces the Path object and shares the path segment functions
     11        in the class CanvasPathMethods.
     12        This patch does just implement the basic path functions that have a general agreement on
     13        the WHAT WG and W3C mailing lists.
     14        This feature is behind a flag and won't be activated by default.
     15
     16        http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#path-objects
     17
     18        Test: fast/canvas/canvas-path-object.html
     19
     20        * CMakeLists.txt: Add DOMPath and CanvasPathMedthods to build system.
     21        * DerivedSources.cpp: Ditto.
     22        * DerivedSources.make: Ditto.
     23        * DerivedSources.pri: Ditto.
     24        * GNUmakefile.list.am: Ditto.
     25        * Target.pri: Ditto.
     26        * WebCore.gypi: Ditto.
     27        * WebCore.vcproj/WebCore.vcproj: Ditto.
     28        * WebCore.xcodeproj/project.pbxproj: Ditto.
     29        * html/canvas/CanvasPathMethods.cpp: Added.
     30        (WebCore): This class shares the path segment functions (moveTo, lineTo, ...) between
     31            DOMPath (the Path object) and CanvasRenderingContext2D.
     32        (WebCore::CanvasPathMethods::closePath):
     33        (WebCore::CanvasPathMethods::moveTo):
     34        (WebCore::CanvasPathMethods::lineTo):
     35        (WebCore::CanvasPathMethods::quadraticCurveTo):
     36        (WebCore::CanvasPathMethods::bezierCurveTo):
     37        (WebCore::CanvasPathMethods::arcTo):
     38        (WebCore::CanvasPathMethods::arc):
     39        (WebCore::CanvasPathMethods::rect):
     40        * html/canvas/CanvasPathMethods.h: Added.
     41        (WebCore):
     42        (CanvasPathMethods):
     43        (WebCore::CanvasPathMethods::~CanvasPathMethods):
     44        (WebCore::CanvasPathMethods::transformIsInvertible):
     45        (WebCore::CanvasPathMethods::CanvasPathMethods):
     46        * html/canvas/CanvasRenderingContext2D.cpp:
     47        * html/canvas/CanvasRenderingContext2D.h: Remove the path segment functions here.
     48        (CanvasRenderingContext2D):
     49        (WebCore::CanvasRenderingContext2D::transformIsInvertible): This checks if the CTM
     50            of the context is still invertible. Drawing should stop if it is not.
     51        * html/canvas/CanvasRenderingContext2D.idl:
     52        * html/canvas/DOMPath.h: Added.
     53        (WebCore):
     54        (DOMPath):
     55        (WebCore::DOMPath::create):
     56        (WebCore::DOMPath::~DOMPath):
     57        (WebCore::DOMPath::DOMPath):
     58        * html/canvas/DOMPath.idl: Added.
     59        * page/DOMWindow.idl: Added CTOR for Path.
     60
    1612013-01-23  Joshua Bell  <jsbell@chromium.org>
    262
  • trunk/Source/WebCore/DerivedSources.cpp

    r140488 r140604  
    9696#include "JSDOMNamedFlowCollection.cpp"
    9797#include "JSDOMParser.cpp"
     98#include "JSDOMPath.cpp"
    9899#include "JSDOMPlugin.cpp"
    99100#include "JSDOMPluginArray.cpp"
  • trunk/Source/WebCore/DerivedSources.make

    r140602 r140604  
    382382    $(WebCore)/html/canvas/CanvasRenderingContext2D.idl \
    383383    $(WebCore)/html/canvas/DataView.idl \
     384    $(WebCore)/html/canvas/DOMPath.idl \
    384385    $(WebCore)/html/canvas/EXTTextureFilterAnisotropic.idl \
    385386    $(WebCore)/html/canvas/Float32Array.idl \
  • trunk/Source/WebCore/DerivedSources.pri

    r140488 r140604  
    306306    $$PWD/html/canvas/CanvasRenderingContext.idl \
    307307    $$PWD/html/canvas/CanvasRenderingContext2D.idl \
     308    $$PWD/html/canvas/DOMPath.idl \
    308309    $$PWD/html/canvas/EXTTextureFilterAnisotropic.idl \
    309310    $$PWD/html/canvas/OESStandardDerivatives.idl \
  • trunk/Source/WebCore/GNUmakefile.list.am

    r140602 r140604  
    198198        DerivedSources/WebCore/JSDOMNamedFlowCollection.cpp \
    199199        DerivedSources/WebCore/JSDOMNamedFlowCollection.h \
     200        DerivedSources/WebCore/JSDOMPath.cpp \
     201        DerivedSources/WebCore/JSDOMPath.h \
    200202        DerivedSources/WebCore/JSDOMParser.cpp \
    201203        DerivedSources/WebCore/JSDOMParser.h \
     
    15251527        $(WebCore)/html/canvas/CanvasRenderingContext2D.idl \
    15261528        $(WebCore)/html/canvas/DataView.idl \
     1529        $(WebCore)/html/canvas/DOMPath.idl \
    15271530        $(WebCore)/html/canvas/EXTTextureFilterAnisotropic.idl \
    15281531        $(WebCore)/html/canvas/Float32Array.idl \
     
    32163219        Source/WebCore/html/canvas/CanvasGradient.cpp \
    32173220        Source/WebCore/html/canvas/CanvasGradient.h \
     3221        Source/WebCore/html/canvas/CanvasPathMethods.cpp \
     3222        Source/WebCore/html/canvas/CanvasPathMethods.h \
    32183223        Source/WebCore/html/canvas/CanvasPattern.cpp \
    32193224        Source/WebCore/html/canvas/CanvasPattern.h \
     
    32293234        Source/WebCore/html/canvas/DataView.cpp \
    32303235        Source/WebCore/html/canvas/DataView.h \
     3236        Source/WebCore/html/canvas/DOMPath.h \
    32313237        Source/WebCore/html/canvas/EXTTextureFilterAnisotropic.cpp \
    32323238        Source/WebCore/html/canvas/EXTTextureFilterAnisotropic.h \
  • trunk/Source/WebCore/Target.pri

    r140518 r140604  
    704704    html/WeekInputType.cpp \
    705705    html/canvas/CanvasGradient.cpp \
     706    html/canvas/CanvasPathMethods.cpp \
    706707    html/canvas/CanvasPattern.cpp \
    707708    html/canvas/CanvasProxy.cpp \
     
    17621763    history/PageCache.h \
    17631764    html/canvas/CanvasGradient.h \
     1765    html/canvas/CanvasPathMethods.h \
    17641766    html/canvas/CanvasPattern.h \
    17651767    html/canvas/CanvasProxy.h \
     
    17681770    html/canvas/CanvasStyle.h \
    17691771    html/canvas/DataView.h \
     1772    html/canvas/DOMPath.h \
    17701773    html/ClassList.h \
    17711774    html/DOMFormData.h \
  • trunk/Source/WebCore/WebCore.gypi

    r140602 r140604  
    371371            'html/canvas/CanvasRenderingContext2D.idl',
    372372            'html/canvas/DataView.idl',
     373            'html/canvas/DOMPath.idl',
    373374            'html/canvas/EXTTextureFilterAnisotropic.idl',
    374375            'html/canvas/Float32Array.idl',
     
    32713272            'html/canvas/CanvasGradient.cpp',
    32723273            'html/canvas/CanvasGradient.h',
     3274            'html/canvas/CanvasPathMethods.cpp',
     3275            'html/canvas/CanvasPathMethods.h',
    32733276            'html/canvas/CanvasPattern.cpp',
    32743277            'html/canvas/CanvasPattern.h',
     
    32843287            'html/canvas/DataView.cpp',
    32853288            'html/canvas/DataView.h',
     3289            'html/canvas/DOMPath.h',
    32863290            'html/canvas/EXTTextureFilterAnisotropic.cpp',
    32873291            'html/canvas/EXTTextureFilterAnisotropic.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r140498 r140604  
    38433843                        </File>
    38443844                        <File
     3845                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\JSDOMPath.cpp"
     3846                                >
     3847                                <FileConfiguration
     3848                                        Name="Debug|Win32"
     3849                                        ExcludedFromBuild="true"
     3850                                        >
     3851                                        <Tool
     3852                                                Name="VCCLCompilerTool"
     3853                                        />
     3854                                </FileConfiguration>
     3855                                <FileConfiguration
     3856                                        Name="Release|Win32"
     3857                                        ExcludedFromBuild="true"
     3858                                        >
     3859                                        <Tool
     3860                                                Name="VCCLCompilerTool"
     3861                                        />
     3862                                </FileConfiguration>
     3863                                <FileConfiguration
     3864                                        Name="Debug_Cairo_CFLite|Win32"
     3865                                        ExcludedFromBuild="true"
     3866                                        >
     3867                                        <Tool
     3868                                                Name="VCCLCompilerTool"
     3869                                        />
     3870                                </FileConfiguration>
     3871                                <FileConfiguration
     3872                                        Name="Release_Cairo_CFLite|Win32"
     3873                                        ExcludedFromBuild="true"
     3874                                        >
     3875                                        <Tool
     3876                                                Name="VCCLCompilerTool"
     3877                                        />
     3878                                </FileConfiguration>
     3879                                <FileConfiguration
     3880                                        Name="Debug_All|Win32"
     3881                                        ExcludedFromBuild="true"
     3882                                        >
     3883                                        <Tool
     3884                                                Name="VCCLCompilerTool"
     3885                                        />
     3886                                </FileConfiguration>
     3887                                <FileConfiguration
     3888                                        Name="Production|Win32"
     3889                                        ExcludedFromBuild="true"
     3890                                        >
     3891                                        <Tool
     3892                                                Name="VCCLCompilerTool"
     3893                                        />
     3894                                </FileConfiguration>
     3895                        </File>
     3896                        <File
     3897                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\JSDOMPath.h"
     3898                                >
     3899                        </File>
     3900                        <File
    38453901                                RelativePath="$(ConfigurationBuildDir)\obj\$(ProjectName)\DerivedSources\JSDOMParser.cpp"
    38463902                                >
     
    5985559911                        </File>
    5985659912                        <File
     59913                                RelativePath="..\html\canvas\CanvasPathMethods.cpp"
     59914                                >
     59915                        </File>
     59916                        <File
     59917                                RelativePath="..\html\canvas\CanvasPathMethods.h"
     59918                                >
     59919                        </File>
     59920                        <File
    5985759921                                RelativePath="..\html\canvas\CanvasPattern.cpp"
    5985859922                                >
     
    5992059984                        <File
    5992159985                                RelativePath="..\html\canvas\DataView.h"
     59986                                >
     59987                        </File>
     59988                        <File
     59989                                RelativePath="..\html\canvas\DOMPath.h"
    5992259990                                >
    5992359991                        </File>
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r140602 r140604  
    64636463                FB49C39D16784947007FFB5D /* CSSHostRule.h in Headers */ = {isa = PBXBuildFile; fileRef = FB49C39C16784947007FFB5D /* CSSHostRule.h */; };
    64646464                FB78AD2E151BF5E600FE54D3 /* CSSParserMode.h in Headers */ = {isa = PBXBuildFile; fileRef = FB78AD2C151BF5D200FE54D3 /* CSSParserMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
     6465                FB91392416AE4C17001FE682 /* DOMPath.h in Headers */ = {isa = PBXBuildFile; fileRef = FB91392016AE4B0B001FE682 /* DOMPath.h */; };
     6466                FB91392616AE4C2F001FE682 /* CanvasPathMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = FB91391F16AE4B0B001FE682 /* CanvasPathMethods.h */; };
     6467                FB91392716AE4C34001FE682 /* CanvasPathMethods.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FB91391E16AE4B0B001FE682 /* CanvasPathMethods.cpp */; };
     6468                FB91392A16AE4FC0001FE682 /* JSDOMPath.h in Headers */ = {isa = PBXBuildFile; fileRef = FB91392816AE4FC0001FE682 /* JSDOMPath.h */; };
     6469                FB91392B16AE4FC0001FE682 /* JSDOMPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FB91392916AE4FC0001FE682 /* JSDOMPath.cpp */; };
    64656470                FB92DF4B15FED08700994433 /* ClipPathOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = FB92DF4915FED08700994433 /* ClipPathOperation.h */; settings = {ATTRIBUTES = (Private, ); }; };
    64666471                FBC220DF1237FBEB00BCF788 /* GraphicsContext3DOpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBC220DE1237FBEB00BCF788 /* GraphicsContext3DOpenGL.cpp */; };
     
    1408214087                FB49C39E16784954007FFB5D /* CSSHostRule.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CSSHostRule.idl; sourceTree = "<group>"; };
    1408314088                FB78AD2C151BF5D200FE54D3 /* CSSParserMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSParserMode.h; sourceTree = "<group>"; };
     14089                FB91391E16AE4B0B001FE682 /* CanvasPathMethods.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CanvasPathMethods.cpp; path = canvas/CanvasPathMethods.cpp; sourceTree = "<group>"; };
     14090                FB91391F16AE4B0B001FE682 /* CanvasPathMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CanvasPathMethods.h; path = canvas/CanvasPathMethods.h; sourceTree = "<group>"; };
     14091                FB91392016AE4B0B001FE682 /* DOMPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DOMPath.h; path = canvas/DOMPath.h; sourceTree = "<group>"; };
     14092                FB91392116AE4B0B001FE682 /* DOMPath.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = DOMPath.idl; path = canvas/DOMPath.idl; sourceTree = "<group>"; };
     14093                FB91392816AE4FC0001FE682 /* JSDOMPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMPath.h; sourceTree = "<group>"; };
     14094                FB91392916AE4FC0001FE682 /* JSDOMPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMPath.cpp; sourceTree = "<group>"; };
    1408414095                FB92DF4915FED08700994433 /* ClipPathOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipPathOperation.h; sourceTree = "<group>"; };
    1408514096                FBC220DE1237FBEB00BCF788 /* GraphicsContext3DOpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContext3DOpenGL.cpp; sourceTree = "<group>"; };
     
    1550015511                        isa = PBXGroup;
    1550115512                        children = (
     15513                                FB91391E16AE4B0B001FE682 /* CanvasPathMethods.cpp */,
     15514                                FB91391F16AE4B0B001FE682 /* CanvasPathMethods.h */,
     15515                                FB91392016AE4B0B001FE682 /* DOMPath.h */,
     15516                                FB91392116AE4B0B001FE682 /* DOMPath.idl */,
    1550215517                                49EECDCC10503C2300099FAB /* ArrayBuffer.idl */,
    1550315518                                49EECDC910503C2300099FAB /* ArrayBufferView.idl */,
     
    1872218737                                2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */,
    1872318738                                2E0888D31148848A00AF4265 /* JSDOMFormData.h */,
     18739                                FB91392916AE4FC0001FE682 /* JSDOMPath.cpp */,
     18740                                FB91392816AE4FC0001FE682 /* JSDOMPath.h */,
    1872418741                                4ACBC0C812713D0A0094F9B2 /* JSDOMSettableTokenList.cpp */,
    1872518742                                4ACBC0C912713D0A0094F9B2 /* JSDOMSettableTokenList.h */,
     
    2625226269                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
    2625326270                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
     26271                                FB91392416AE4C17001FE682 /* DOMPath.h in Headers */,
     26272                                FB91392616AE4C2F001FE682 /* CanvasPathMethods.h in Headers */,
     26273                                FB91392A16AE4FC0001FE682 /* JSDOMPath.h in Headers */,
    2625426274                        );
    2625526275                        runOnlyForDeploymentPostprocessing = 0;
     
    2940029420                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
    2940129421                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
     29422                                FB91392716AE4C34001FE682 /* CanvasPathMethods.cpp in Sources */,
     29423                                FB91392B16AE4FC0001FE682 /* JSDOMPath.cpp in Sources */,
    2940229424                        );
    2940329425                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r140352 r140604  
    853853}
    854854
    855 void CanvasRenderingContext2D::closePath()
    856 {
    857     if (m_path.isEmpty())
    858         return;
    859 
    860     FloatRect boundRect = m_path.fastBoundingRect();
    861     if (boundRect.width() || boundRect.height())
    862         m_path.closeSubpath();
    863 }
    864 
    865 void CanvasRenderingContext2D::moveTo(float x, float y)
    866 {
    867     if (!isfinite(x) | !isfinite(y))
    868         return;
    869     if (!state().m_invertibleCTM)
    870         return;
    871     m_path.moveTo(FloatPoint(x, y));
    872 }
    873 
    874 void CanvasRenderingContext2D::lineTo(float x, float y)
    875 {
    876     if (!isfinite(x) | !isfinite(y))
    877         return;
    878     if (!state().m_invertibleCTM)
    879         return;
    880 
    881     FloatPoint p1 = FloatPoint(x, y);
    882     if (!m_path.hasCurrentPoint())
    883         m_path.moveTo(p1);
    884     else if (p1 != m_path.currentPoint())
    885         m_path.addLineTo(FloatPoint(x, y));
    886 }
    887 
    888 void CanvasRenderingContext2D::quadraticCurveTo(float cpx, float cpy, float x, float y)
    889 {
    890     if (!isfinite(cpx) | !isfinite(cpy) | !isfinite(x) | !isfinite(y))
    891         return;
    892     if (!state().m_invertibleCTM)
    893         return;
    894     if (!m_path.hasCurrentPoint())
    895         m_path.moveTo(FloatPoint(cpx, cpy));
    896 
    897     FloatPoint p1 = FloatPoint(x, y);
    898     if (p1 != m_path.currentPoint())
    899         m_path.addQuadCurveTo(FloatPoint(cpx, cpy), p1);
    900 }
    901 
    902 void CanvasRenderingContext2D::bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y)
    903 {
    904     if (!isfinite(cp1x) | !isfinite(cp1y) | !isfinite(cp2x) | !isfinite(cp2y) | !isfinite(x) | !isfinite(y))
    905         return;
    906     if (!state().m_invertibleCTM)
    907         return;
    908     if (!m_path.hasCurrentPoint())
    909         m_path.moveTo(FloatPoint(cp1x, cp1y));
    910 
    911     FloatPoint p1 = FloatPoint(x, y);
    912     if (p1 != m_path.currentPoint())
    913         m_path.addBezierCurveTo(FloatPoint(cp1x, cp1y), FloatPoint(cp2x, cp2y), p1);
    914 }
    915 
    916 void CanvasRenderingContext2D::arcTo(float x1, float y1, float x2, float y2, float r, ExceptionCode& ec)
    917 {
    918     ec = 0;
    919     if (!isfinite(x1) | !isfinite(y1) | !isfinite(x2) | !isfinite(y2) | !isfinite(r))
    920         return;
    921 
    922     if (r < 0) {
    923         ec = INDEX_SIZE_ERR;
    924         return;
    925     }
    926 
    927     if (!state().m_invertibleCTM)
    928         return;
    929 
    930     FloatPoint p1 = FloatPoint(x1, y1);
    931     FloatPoint p2 = FloatPoint(x2, y2);
    932 
    933     if (!m_path.hasCurrentPoint())
    934         m_path.moveTo(p1);
    935     else if (p1 == m_path.currentPoint() || p1 == p2 || !r)
    936         lineTo(x1, y1);
    937     else
    938         m_path.addArcTo(p1, p2, r);
    939 }
    940 
    941 void CanvasRenderingContext2D::arc(float x, float y, float r, float sa, float ea, bool anticlockwise, ExceptionCode& ec)
    942 {
    943     ec = 0;
    944     if (!isfinite(x) | !isfinite(y) | !isfinite(r) | !isfinite(sa) | !isfinite(ea))
    945         return;
    946 
    947     if (r < 0) {
    948         ec = INDEX_SIZE_ERR;
    949         return;
    950     }
    951 
    952     if (!r || sa == ea) {
    953         // The arc is empty but we still need to draw the connecting line
    954         lineTo(x + r * cosf(sa), y + r * sinf(sa));
    955         return;
    956     }
    957 
    958     if (!state().m_invertibleCTM)
    959         return;
    960 
    961     // If 'sa' and 'ea' differ by more than 2Pi, just add a circle starting/ending at 'sa'
    962     if (anticlockwise && sa - ea >= 2 * piFloat) {
    963         m_path.addArc(FloatPoint(x, y), r, sa, sa - 2 * piFloat, anticlockwise);
    964         return;
    965     }
    966     if (!anticlockwise && ea - sa >= 2 * piFloat) {
    967         m_path.addArc(FloatPoint(x, y), r, sa, sa + 2 * piFloat, anticlockwise);
    968         return;
    969     }
    970 
    971     m_path.addArc(FloatPoint(x, y), r, sa, ea, anticlockwise);
    972 }
    973 
    974855static bool validateRectForCanvas(float& x, float& y, float& width, float& height)
    975856{
     
    991872
    992873    return true;
    993 }
    994 
    995 void CanvasRenderingContext2D::rect(float x, float y, float width, float height)
    996 {
    997     if (!state().m_invertibleCTM)
    998         return;
    999 
    1000     if (!isfinite(x) || !isfinite(y) || !isfinite(width) || !isfinite(height))
    1001         return;
    1002 
    1003     if (!width && !height) {
    1004         m_path.moveTo(FloatPoint(x, y));
    1005         return;
    1006     }
    1007 
    1008     m_path.addRect(FloatRect(x, y, width, height));
    1009874}
    1010875
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r140352 r140604  
    2828
    2929#include "AffineTransform.h"
     30#include "CanvasPathMethods.h"
    3031#include "CanvasRenderingContext.h"
    3132#include "Color.h"
     
    5960typedef int ExceptionCode;
    6061
    61 class CanvasRenderingContext2D : public CanvasRenderingContext {
     62class CanvasRenderingContext2D : public CanvasRenderingContext, public CanvasPathMethods {
    6263public:
    6364    static PassOwnPtr<CanvasRenderingContext2D> create(HTMLCanvasElement* canvas, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode)
     
    136137
    137138    void beginPath();
    138     void closePath();
    139 
    140     void moveTo(float x, float y);
    141     void lineTo(float x, float y);
    142     void quadraticCurveTo(float cpx, float cpy, float x, float y);
    143     void bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y);
    144     void arcTo(float x0, float y0, float x1, float y1, float radius, ExceptionCode&);
    145     void arc(float x, float y, float r, float sa, float ea, bool clockwise, ExceptionCode&);
    146     void rect(float x, float y, float width, float height);
    147139
    148140    void fill(const String& winding = "nonzero");
     
    332324    virtual bool isAccelerated() const OVERRIDE;
    333325
     326    virtual bool transformIsInvertible() { return state().m_invertibleCTM; }
     327
    334328#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
    335329    virtual PlatformLayer* platformLayer() const OVERRIDE;
    336330#endif
    337331
    338     Path m_path;
    339332    Vector<State, 1> m_stateStack;
    340333    unsigned m_unrealizedSaveCount;
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r140352 r140604  
    9696
    9797    void beginPath();
     98
     99    // FIXME: These methods should be shared with CanvasRenderingContext2D in the CanvasPathMethods interface.
    98100    void closePath();
    99101    void moveTo(in [Optional=DefaultIsUndefined] float x,
     
    128130             in [Optional=DefaultIsUndefined] boolean anticlockwise)
    129131        raises (DOMException);
     132
    130133    void fill(in [Optional] DOMString winding);
    131134    void stroke();
  • trunk/Source/WebCore/page/DOMWindow.idl

    r140448 r140604  
    399399    attribute EntityConstructor Entity;
    400400    attribute EntityReferenceConstructor EntityReference;
     401    [Conditional=CANVAS_PATH] attribute DOMPathConstructor Path;
    401402    attribute ProcessingInstructionConstructor ProcessingInstruction;
    402403    [Conditional=SHADOW_DOM, V8EnabledAtRuntime=shadowDOM] attribute ShadowRootConstructor WebKitShadowRoot;
Note: See TracChangeset for help on using the changeset viewer.