Changeset 128116 in webkit


Ignore:
Timestamp:
Sep 10, 2012 3:21:49 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Implement canvas v5 line dash feature
https://bugs.webkit.org/show_bug.cgi?id=82560

Patch by Justin Novosad <junov@chromium.org> on 2012-09-10
Reviewed by Darin Adler.

Source/WebCore:

Adding new canvas 2d context API methods getLineDash and setLineDash,
and new attribute lineDashOffset. Implementation mostly based on
the existing webkitLineDash feature, with changes that reflect the
canvas v5 specification. This change is visible to all JS ports,
unlike webkitLineDash which is not exposed to V8. The new lineDash
and the legacy webkitLineDash features access the same rendering
context state. The JavasScriptCore binding layer was augmented to
support the sequence<float> IDL type.

Tests: fast/canvas/canvas-lineDash-invalid.html

fast/canvas/canvas-lineDash.html

  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:

(WebCore::JSCanvasRenderingContext2D::webkitLineDash):
(WebCore::JSCanvasRenderingContext2D::setWebkitLineDash):

  • bindings/js/JSDOMBinding.h:

Added template specialization on float to NativeValueTraits in order to
add support for the sequence<double> IDL type to JavaScriptCore.

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::getLineDash):
New 2D canvas API method, returns the current line dash array
(WebCore::lineDashSequenceIsValid):
Returns true if the line dash array contains only non-negative finite
numbers.
(WebCore::CanvasRenderingContext2D::setLineDash):
New 2D canvas API method, set the line dash array.
(WebCore::CanvasRenderingContext2D::setWebkitLineDash):
Legacy implementation, does not double the new line dash array if
it contains an odd number of elements. Just accepts it as is.
(WebCore::CanvasRenderingContext2D::lineDashOffset):
Attribute getter
(WebCore::CanvasRenderingContext2D::setLineDashOffset):
Attribute setter
(WebCore::CanvasRenderingContext2D::webkitLineDashOffset):
Alias for lineDashOffset
(WebCore::CanvasRenderingContext2D::setWebkitLineDashOffset):
Alias for setLineDashOffset
(WebCore::CanvasRenderingContext2D::applyLineDash):
Sends the line dash state to the GraphicsContext

  • html/canvas/CanvasRenderingContext2D.h:

(CanvasRenderingContext2D):
(State):

  • html/canvas/CanvasRenderingContext2D.idl:
  • platform/graphics/DashArray.h:

LayoutTests:

New layout tests for the canvas lineDash feature.
-Validate normal behavior of lineDash state change operations.
-Validate behavior when attempting invalid state changes.
-Validate rendering behavior.

  • fast/canvas/canvas-lineDash-expected.txt: Added.
  • fast/canvas/canvas-lineDash-invalid-expected.txt: Added.
  • fast/canvas/canvas-lineDash-invalid.html: Added.
  • fast/canvas/canvas-lineDash.html: Added.
  • fast/canvas/script-tests/canvas-lineDash-invalid.js: Added.

(resetLineDash):
(trySettingLineDash):
(trySettingLineDashWithNoArgs):
(trySettingLineDashOffset):

  • fast/canvas/script-tests/canvas-lineDash.js: Added.

(dataToArray):
(getPixel):
(pixelShouldBe):

Location:
trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r128113 r128116  
     12012-09-10  Justin Novosad  <junov@chromium.org>
     2
     3        Implement canvas v5 line dash feature
     4        https://bugs.webkit.org/show_bug.cgi?id=82560
     5
     6        Reviewed by Darin Adler.
     7
     8        New layout tests for the canvas lineDash feature.
     9        -Validate normal behavior of lineDash state change operations.
     10        -Validate behavior when attempting invalid state changes.
     11        -Validate rendering behavior.
     12
     13        * fast/canvas/canvas-lineDash-expected.txt: Added.
     14        * fast/canvas/canvas-lineDash-invalid-expected.txt: Added.
     15        * fast/canvas/canvas-lineDash-invalid.html: Added.
     16        * fast/canvas/canvas-lineDash.html: Added.
     17        * fast/canvas/script-tests/canvas-lineDash-invalid.js: Added.
     18        (resetLineDash):
     19        (trySettingLineDash):
     20        (trySettingLineDashWithNoArgs):
     21        (trySettingLineDashOffset):
     22        * fast/canvas/script-tests/canvas-lineDash.js: Added.
     23        (dataToArray):
     24        (getPixel):
     25        (pixelShouldBe):
     26
    1272012-08-31  Jon Lee  <jonlee@apple.com>
    228
  • trunk/Source/WebCore/ChangeLog

    r128115 r128116  
     12012-09-10  Justin Novosad  <junov@chromium.org>
     2
     3        Implement canvas v5 line dash feature
     4        https://bugs.webkit.org/show_bug.cgi?id=82560
     5
     6        Reviewed by Darin Adler.
     7
     8        Adding new canvas 2d context API methods getLineDash and setLineDash,
     9        and new attribute lineDashOffset. Implementation mostly based on
     10        the existing webkitLineDash feature, with changes that reflect the
     11        canvas v5 specification. This change is visible to all JS ports,
     12        unlike webkitLineDash which is not exposed to V8. The new lineDash
     13        and the legacy webkitLineDash features access the same rendering
     14        context state. The JavasScriptCore binding layer was augmented to
     15        support the sequence<float> IDL type.
     16
     17        Tests: fast/canvas/canvas-lineDash-invalid.html
     18               fast/canvas/canvas-lineDash.html
     19
     20        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
     21        (WebCore::JSCanvasRenderingContext2D::webkitLineDash):
     22        (WebCore::JSCanvasRenderingContext2D::setWebkitLineDash):
     23        * bindings/js/JSDOMBinding.h:
     24        Added template specialization on float to NativeValueTraits in order to
     25        add support for the sequence<double> IDL type to JavaScriptCore.
     26        * html/canvas/CanvasRenderingContext2D.cpp:
     27        (WebCore::CanvasRenderingContext2D::getLineDash):
     28        New 2D canvas API method, returns the current line dash array
     29        (WebCore::lineDashSequenceIsValid):
     30        Returns true if the line dash array contains only non-negative finite
     31        numbers.
     32        (WebCore::CanvasRenderingContext2D::setLineDash):
     33        New 2D canvas API method, set the line dash array.
     34        (WebCore::CanvasRenderingContext2D::setWebkitLineDash):
     35        Legacy implementation, does not double the new line dash array if
     36        it contains an odd number of elements.  Just accepts it as is.
     37        (WebCore::CanvasRenderingContext2D::lineDashOffset):
     38        Attribute getter
     39        (WebCore::CanvasRenderingContext2D::setLineDashOffset):
     40        Attribute setter
     41        (WebCore::CanvasRenderingContext2D::webkitLineDashOffset):
     42        Alias for lineDashOffset
     43        (WebCore::CanvasRenderingContext2D::setWebkitLineDashOffset):
     44        Alias for setLineDashOffset
     45        (WebCore::CanvasRenderingContext2D::applyLineDash):
     46        Sends the line dash state to the GraphicsContext
     47        * html/canvas/CanvasRenderingContext2D.h:
     48        (CanvasRenderingContext2D):
     49        (State):
     50        * html/canvas/CanvasRenderingContext2D.idl:
     51        * platform/graphics/DashArray.h:
     52
    1532012-09-10  Sheriff Bot  <webkit.review.bot@gmail.com>
    254
  • trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp

    r127191 r128116  
    9595{
    9696    CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
    97     const DashArray* dash = context->webkitLineDash();
     97    const Vector<float>& dash = context->getLineDash();
    9898
    9999    MarkedArgumentBuffer list;
    100     DashArray::const_iterator end = dash->end();
    101     for (DashArray::const_iterator it = dash->begin(); it != end; ++it)
     100    Vector<float>::const_iterator end = dash.end();
     101    for (Vector<float>::const_iterator it = dash.begin(); it != end; ++it)
    102102        list.append(JSValue(*it));
    103103    return constructArray(exec, globalObject(), list);
     
    109109        return;
    110110
    111     DashArray dash;
     111    Vector<float> dash;
    112112    JSArray* valueArray = asArray(value);
    113113    for (unsigned i = 0; i < valueArray->length(); ++i) {
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.h

    r127191 r128116  
    376376    };
    377377
     378    template<>
     379    struct NativeValueTraits<float> {
     380        static inline bool arrayNativeValue(JSC::ExecState* exec, JSC::JSValue jsValue, float& indexedValue)
     381        {
     382            indexedValue = jsValue.toFloat(exec);
     383            return !exec->hadException();
     384        }
     385    };
     386
    378387    template <class T>
    379388    Vector<T> toNativeArray(JSC::ExecState* exec, JSC::JSValue value)
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r128076 r128116  
    509509}
    510510
    511 const DashArray* CanvasRenderingContext2D::webkitLineDash() const
    512 {
    513     return &state().m_lineDash;
    514 }
    515 
    516 void CanvasRenderingContext2D::setWebkitLineDash(const DashArray& dash)
    517 {
    518     if (state().m_lineDash == dash)
    519         return;
     511const Vector<float>& CanvasRenderingContext2D::getLineDash() const
     512{
     513    return state().m_lineDash;
     514}
     515
     516static bool lineDashSequenceIsValid(const Vector<float>& dash)
     517{
     518    for (size_t i = 0; i < dash.size(); i++) {
     519        if (!isfinite(dash[i]) || dash[i] < 0)
     520            return false;
     521    }
     522    return true;
     523}
     524
     525void CanvasRenderingContext2D::setLineDash(const Vector<float>& dash)
     526{
     527    if (!lineDashSequenceIsValid(dash))
     528        return;
     529
    520530    realizeSaves();
    521531    modifiableState().m_lineDash = dash;
    522     GraphicsContext* c = drawingContext();
    523     if (!c)
    524         return;
    525     c->setLineDash(state().m_lineDash, state().m_lineDashOffset);
     532    // Spec requires the concatenation of two copies the dash list when the
     533    // number of elements is odd
     534    if (dash.size() % 2)
     535        modifiableState().m_lineDash.append(dash);
     536
     537    applyLineDash();
     538}
     539
     540void CanvasRenderingContext2D::setWebkitLineDash(const Vector<float>& dash)
     541{
     542    if (!lineDashSequenceIsValid(dash))
     543        return;
     544
     545    realizeSaves();
     546    modifiableState().m_lineDash = dash;
     547
     548    applyLineDash();
     549}
     550
     551float CanvasRenderingContext2D::lineDashOffset() const
     552{
     553    return state().m_lineDashOffset;
     554}
     555
     556void CanvasRenderingContext2D::setLineDashOffset(float offset)
     557{
     558    if (!isfinite(offset) || state().m_lineDashOffset == offset)
     559        return;
     560
     561    realizeSaves();
     562    modifiableState().m_lineDashOffset = offset;
     563    applyLineDash();
    526564}
    527565
    528566float CanvasRenderingContext2D::webkitLineDashOffset() const
    529567{
    530     return state().m_lineDashOffset;
     568    return lineDashOffset();
    531569}
    532570
    533571void CanvasRenderingContext2D::setWebkitLineDashOffset(float offset)
    534572{
    535     if (!isfinite(offset))
    536         return;
    537     if (state().m_lineDashOffset == offset)
    538         return;
    539     realizeSaves();
    540     modifiableState().m_lineDashOffset = offset;
    541     GraphicsContext* c = drawingContext();
    542     if (!c)
    543         return;
    544     c->setLineDash(state().m_lineDash, state().m_lineDashOffset);
     573    setLineDashOffset(offset);
     574}
     575
     576void CanvasRenderingContext2D::applyLineDash() const
     577{
     578    GraphicsContext* c = drawingContext();
     579    if (!c)
     580        return;
     581    DashArray convertedLineDash(state().m_lineDash.size());
     582    for (size_t i = 0; i < state().m_lineDash.size(); ++i)
     583        convertedLineDash[i] = static_cast<DashArrayElement>(state().m_lineDash[i]);
     584    c->setLineDash(convertedLineDash, state().m_lineDashOffset);
    545585}
    546586
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r127757 r128116  
    8585    void setMiterLimit(float);
    8686
    87     const DashArray* webkitLineDash() const;
    88     void setWebkitLineDash(const DashArray&);
    89 
     87    const Vector<float>& getLineDash() const;
     88    void setLineDash(const Vector<float>&);
     89    void setWebkitLineDash(const Vector<float>&);
     90
     91    float lineDashOffset() const;
     92    void setLineDashOffset(float);
    9093    float webkitLineDashOffset() const;
    9194    void setWebkitLineDashOffset(float);
     
    251254        AffineTransform m_transform;
    252255        bool m_invertibleCTM;
    253         DashArray m_lineDash;
     256        Vector<float> m_lineDash;
    254257        float m_lineDashOffset;
    255258        bool m_imageSmoothingEnabled;
     
    277280    const State& state() const { return m_stateStack.last(); }
    278281
     282    void applyLineDash() const;
    279283    void setShadow(const FloatSize& offset, float blur, RGBA32 color);
    280284    void applyShadow();
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r121714 r128116  
    7575        attribute [TreatNullAs=NullString] DOMString shadowColor;
    7676
     77        void setLineDash(in sequence<float> dash);
     78        sequence<float> getLineDash();
     79        attribute float lineDashOffset;
     80
    7781        // FIXME: These attributes should also be implemented for V8.
    7882#if !(defined(V8_BINDING) && V8_BINDING)
  • trunk/Source/WebCore/platform/graphics/DashArray.h

    r84101 r128116  
    3030
    3131#if USE(CG)
    32 typedef Vector<CGFloat> DashArray;
     32typedef CGFloat DashArrayElement;
    3333#elif USE(CAIRO)
    34 typedef Vector<double> DashArray;
     34typedef double DashArrayElement;
    3535#else
    36 typedef Vector<float> DashArray;
     36typedef float DashArrayElement;
    3737#endif
    3838
     39typedef Vector<DashArrayElement> DashArray;
     40
    3941#endif // DashArray_h
Note: See TracChangeset for help on using the changeset viewer.