Changeset 74328 in webkit


Ignore:
Timestamp:
Dec 19, 2010 5:02:20 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-12-19 Helder Correia <helder@sencha.com>

Reviewed by Ariya Hidayat.

[Qt] Blur distance should not be affected by transformations
https://bugs.webkit.org/show_bug.cgi?id=51161

From the spec at http://dev.w3.org/html5/2dcontext/#dom-context-2d-shadowblur:
"The shadowBlur attribute specifies the level of the blurring effect.
(The units do not map to coordinate space units, and are not affected
by the current transformation matrix.)"

Add test to ensure that the blur radius is not affected by the CTM.

  • fast/canvas/canvas-scale-shadowBlur-expected.txt: Added.
  • fast/canvas/canvas-scale-shadowBlur.html: Added.
  • fast/canvas/canvas-scale-strokePath-shadow-expected.txt: Increase shadowBlur and test tolerance to ease testing and support the different blurring algorithms.
  • fast/canvas/script-tests/canvas-scale-shadowBlur.js: Added.
  • fast/canvas/script-tests/canvas-scale-strokePath-shadow.js:

2010-12-19 Helder Correia <helder@sencha.com>

Reviewed by Ariya Hidayat.

[Qt] Blur distance should not be affected by transformations
https://bugs.webkit.org/show_bug.cgi?id=51161

From the spec at http://dev.w3.org/html5/2dcontext/#dom-context-2d-shadowblur:
"The shadowBlur attribute specifies the level of the blurring effect.
(The units do not map to coordinate space units, and are not affected
by the current transformation matrix.)"

Test: fast/canvas/canvas-scale-shadowBlur.html

  • platform/graphics/ContextShadow.cpp: (WebCore::ContextShadow::adjustBlurDistance):
  • platform/graphics/ContextShadow.h:
  • platform/graphics/cairo/ContextShadowCairo.cpp: (WebCore::ContextShadow::beginShadowLayer):
  • platform/graphics/qt/ContextShadowQt.cpp: (WebCore::ContextShadow::beginShadowLayer):
Location:
trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r74326 r74328  
     12010-12-19  Helder Correia  <helder@sencha.com>
     2
     3        Reviewed by Ariya Hidayat.
     4
     5        [Qt] Blur distance should not be affected by transformations
     6        https://bugs.webkit.org/show_bug.cgi?id=51161
     7
     8        From the spec at http://dev.w3.org/html5/2dcontext/#dom-context-2d-shadowblur:
     9        "The shadowBlur attribute specifies the level of the blurring effect.
     10        (The units do not map to coordinate space units, and are not affected
     11        by the current transformation matrix.)"
     12
     13        Add test to ensure that the blur radius is not affected by the CTM.
     14
     15        * fast/canvas/canvas-scale-shadowBlur-expected.txt: Added.
     16        * fast/canvas/canvas-scale-shadowBlur.html: Added.
     17        * fast/canvas/canvas-scale-strokePath-shadow-expected.txt: Increase
     18          shadowBlur and test tolerance to ease testing and support the
     19          different blurring algorithms.
     20        * fast/canvas/script-tests/canvas-scale-shadowBlur.js: Added.
     21        * fast/canvas/script-tests/canvas-scale-strokePath-shadow.js:
     22
    1232010-12-19  Dan Bernstein  <mitz@apple.com>
    224
  • trunk/LayoutTests/fast/canvas/canvas-scale-strokePath-shadow-expected.txt

    r74317 r74328  
    3131PASS d[1] is 0
    3232PASS d[2] is 0
    33 PASS d[3] is around 149
     33PASS d[3] is around 200
    3434PASS d[0] is 255
    3535PASS d[1] is 0
    3636PASS d[2] is 0
    37 PASS d[3] is around 116
     37PASS d[3] is around 49
    3838PASS d[0] is 255
    3939PASS d[1] is 0
    4040PASS d[2] is 0
    41 PASS d[3] is around 115
     41PASS d[3] is around 199
    4242PASS d[0] is 255
    4343PASS d[1] is 0
  • trunk/LayoutTests/fast/canvas/script-tests/canvas-scale-strokePath-shadow.js

    r74317 r74328  
    2828var canvas = document.createElement('canvas');
    2929document.body.appendChild(canvas);
    30 canvas.setAttribute('width', '1000');
    31 canvas.setAttribute('height', '1000');
     30canvas.setAttribute('width', '600');
     31canvas.setAttribute('height', '600');
    3232var ctx = canvas.getContext('2d');
    3333
     
    116116
    117117// Verify blurry shadow.
    118 d = ctx.getImageData(404, 210, 1, 1).data;
     118d = ctx.getImageData(398, 210, 1, 1).data;
    119119shouldBe('d[0]', '255');
    120120shouldBe('d[1]', '0');
    121121shouldBe('d[2]', '0');
    122 shouldBeAround('d[3]', '149');
     122shouldBeAround('d[3]', '200');
    123123
    124 d = ctx.getImageData(505, 250, 1, 1).data;
     124d = ctx.getImageData(508, 250, 1, 1).data;
    125125shouldBe('d[0]', '255');
    126126shouldBe('d[1]', '0');
    127127shouldBe('d[2]', '0');
    128 shouldBeAround('d[3]', '116');
     128shouldBeAround('d[3]', '49');
    129129
    130 d = ctx.getImageData(450, 205, 1, 1).data;
     130d = ctx.getImageData(450, 198, 1, 1).data;
    131131shouldBe('d[0]', '255');
    132132shouldBe('d[1]', '0');
    133133shouldBe('d[2]', '0');
    134 shouldBeAround('d[3]', '115');
     134shouldBeAround('d[3]', '199');
    135135
    136136// Verify blurry alpha shadow.
  • trunk/WebCore/ChangeLog

    r74326 r74328  
     12010-12-19  Helder Correia  <helder@sencha.com>
     2
     3        Reviewed by Ariya Hidayat.
     4
     5        [Qt] Blur distance should not be affected by transformations
     6        https://bugs.webkit.org/show_bug.cgi?id=51161
     7
     8        From the spec at http://dev.w3.org/html5/2dcontext/#dom-context-2d-shadowblur:
     9        "The shadowBlur attribute specifies the level of the blurring effect.
     10        (The units do not map to coordinate space units, and are not affected
     11        by the current transformation matrix.)"
     12
     13        Test: fast/canvas/canvas-scale-shadowBlur.html
     14
     15        * platform/graphics/ContextShadow.cpp:
     16        (WebCore::ContextShadow::adjustBlurDistance):
     17        * platform/graphics/ContextShadow.h:
     18        * platform/graphics/cairo/ContextShadowCairo.cpp:
     19        (WebCore::ContextShadow::beginShadowLayer):
     20        * platform/graphics/qt/ContextShadowQt.cpp:
     21        (WebCore::ContextShadow::beginShadowLayer):
     22
    1232010-12-19  Dan Bernstein  <mitz@apple.com>
    224
  • trunk/WebCore/platform/graphics/ContextShadow.cpp

    r74317 r74328  
    3131
    3232#include "FloatQuad.h"
     33#include <cmath>
    3334#include <wtf/MathExtras.h>
    3435#include <wtf/Noncopyable.h>
     
    170171}
    171172
     173void ContextShadow::adjustBlurDistance(const PlatformContext context)
     174{
     175    // Adjust blur if we're scaling, since the radius must not be affected by transformations.
     176    const TransformationMatrix transform(getTransformationMatrixFromContext(context));
     177
     178    if (transform.isIdentity())
     179        return;
     180
     181    // Calculale transformed unit vectors.
     182    const FloatQuad unitQuad(FloatPoint(0, 0), FloatPoint(1, 0),
     183                             FloatPoint(0, 1), FloatPoint(1, 1));
     184    const FloatQuad transformedUnitQuad = transform.mapQuad(unitQuad);
     185
     186    // Calculate X axis scale factor.
     187    const FloatSize xUnitChange = transformedUnitQuad.p2() - transformedUnitQuad.p1();
     188    const float xAxisScale = sqrtf(xUnitChange.width() * xUnitChange.width()
     189                                   + xUnitChange.height() * xUnitChange.height());
     190
     191    // Calculate Y axis scale factor.
     192    const FloatSize yUnitChange = transformedUnitQuad.p3() - transformedUnitQuad.p1();
     193    const float yAxisScale = sqrtf(yUnitChange.width() * yUnitChange.width()
     194                                   + yUnitChange.height() * yUnitChange.height());
     195
     196    // blurLayerImage() does not support per-axis blurring, so calculate a balanced scaling.
     197    const float scale = sqrtf(xAxisScale * yAxisScale);
     198    m_blurDistance = roundf(static_cast<float>(m_blurDistance) / scale);
     199}
     200
    172201IntRect ContextShadow::calculateLayerBoundingRect(const PlatformContext context, const FloatRect& layerArea, const IntRect& clipRect)
    173202{
  • trunk/WebCore/platform/graphics/ContextShadow.h

    r74317 r74328  
    127127    bool m_shadowsIgnoreTransforms;
    128128
     129    void adjustBlurDistance(const PlatformContext);
    129130    void blurLayerImage(unsigned char*, const IntSize& imageSize, int stride);
    130131    IntRect calculateLayerBoundingRect(const PlatformContext, const FloatRect& layerArea, const IntRect& clipRect);
  • trunk/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp

    r74317 r74328  
    9393PlatformContext ContextShadow::beginShadowLayer(PlatformContext context, const FloatRect& layerArea)
    9494{
     95    adjustBlurDistance(context);
     96
    9597    double x1, x2, y1, y2;
    9698    cairo_clip_extents(context, &x1, &y1, &x2, &y2);
  • trunk/WebCore/platform/graphics/qt/ContextShadowQt.cpp

    r74317 r74328  
    112112PlatformContext ContextShadow::beginShadowLayer(PlatformContext p, const FloatRect& layerArea)
    113113{
     114    // Set m_blurDistance.
     115    adjustBlurDistance(p);
     116
    114117    QRect clipRect;
    115118    if (p->hasClipping())
Note: See TracChangeset for help on using the changeset viewer.