Changeset 142823 in webkit


Ignore:
Timestamp:
Feb 13, 2013 4:59:28 PM (11 years ago)
Author:
mvujovic@adobe.com
Message:

[CSS Filters] Refactor filter outsets into a class
https://bugs.webkit.org/show_bug.cgi?id=109330

Source/WebCore:

Reviewed by Dean Jackson.

In filters related code, we're often operating on 4 ints representing the top, right,
bottom, and left filter outsets. These outsets come from a filter like blur or drop-shadow.
This patch packages those ints and their related operations into a class called
IntRectExtent.

Here are some signs that we should make a class to hold those 4 ints:
1) In RenderLayer.cpp, we have a expandRectForFilterOutsets function, which looks like

feature envy.

2) RenderStyle and other classes have methods like getFilterOutsets which set the 4 ints by

reference. The calling code has to define 4 ints, which looks bloated.

3) To fix bug 109098, we will need to check if filter outsets changed, which sounds like a

nice job for an inequality operator. (https://bugs.webkit.org/show_bug.cgi?id=109098)

No new tests. No change in behavior. Just refactoring.

  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/IntRectExtent.h: Added.

(WebCore):
(IntRectExtent):
(WebCore::IntRectExtent::IntRectExtent):
(WebCore::IntRectExtent::top):
(WebCore::IntRectExtent::setTop):
(WebCore::IntRectExtent::right):
(WebCore::IntRectExtent::setRight):
(WebCore::IntRectExtent::bottom):
(WebCore::IntRectExtent::setBottom):
(WebCore::IntRectExtent::left):
(WebCore::IntRectExtent::setLeft):
(WebCore::IntRectExtent::expandRect):
(WebCore::IntRectExtent::isZero):
(WebCore::operator==):
(WebCore::operator!=):
(WebCore::operator+=):

  • platform/graphics/filters/FilterOperations.cpp:

(WebCore::FilterOperations::outsets):

  • platform/graphics/filters/FilterOperations.h:

(FilterOperations):

  • platform/graphics/texmap/TextureMapperLayer.cpp:

(WebCore::TextureMapperLayer::intermediateSurfaceRect):

  • rendering/FilterEffectRenderer.cpp:

(WebCore::FilterEffectRenderer::FilterEffectRenderer):
(WebCore::FilterEffectRenderer::build):
(WebCore::FilterEffectRenderer::computeSourceImageRectForDirtyRect):

  • rendering/FilterEffectRenderer.h:

(FilterEffectRenderer):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::setFilterBackendNeedsRepaintingInRect):
(WebCore::transparencyClipBox):
(WebCore::RenderLayer::calculateLayerBounds):

  • rendering/style/RenderStyle.h:

Source/WebKit/chromium:

Update FilterOperations unit tests to use new interface for getting filter outsets.

Reviewed by Dean Jackson.

  • tests/FilterOperationsTest.cpp:

(WebKit::TEST):

Location:
trunk/Source
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142822 r142823  
     12013-02-13  Max Vujovic  <mvujovic@adobe.com>
     2
     3        [CSS Filters] Refactor filter outsets into a class
     4        https://bugs.webkit.org/show_bug.cgi?id=109330
     5
     6        Reviewed by Dean Jackson.
     7
     8        In filters related code, we're often operating on 4 ints representing the top, right,
     9        bottom, and left filter outsets. These outsets come from a filter like blur or drop-shadow.
     10        This patch packages those ints and their related operations into a class called
     11        IntRectExtent.
     12
     13        Here are some signs that we should make a class to hold those 4 ints:
     14        1) In RenderLayer.cpp, we have a expandRectForFilterOutsets function, which looks like
     15           feature envy.
     16        2) RenderStyle and other classes have methods like getFilterOutsets which set the 4 ints by
     17           reference. The calling code has to define 4 ints, which looks bloated.
     18        3) To fix bug 109098, we will need to check if filter outsets changed, which sounds like a
     19           nice job for an inequality operator. (https://bugs.webkit.org/show_bug.cgi?id=109098)
     20
     21        No new tests. No change in behavior. Just refactoring.
     22
     23        * GNUmakefile.list.am:
     24        * Target.pri:
     25        * WebCore.gypi:
     26        * WebCore.xcodeproj/project.pbxproj:
     27        * platform/graphics/IntRectExtent.h: Added.
     28        (WebCore):
     29        (IntRectExtent):
     30        (WebCore::IntRectExtent::IntRectExtent):
     31        (WebCore::IntRectExtent::top):
     32        (WebCore::IntRectExtent::setTop):
     33        (WebCore::IntRectExtent::right):
     34        (WebCore::IntRectExtent::setRight):
     35        (WebCore::IntRectExtent::bottom):
     36        (WebCore::IntRectExtent::setBottom):
     37        (WebCore::IntRectExtent::left):
     38        (WebCore::IntRectExtent::setLeft):
     39        (WebCore::IntRectExtent::expandRect):
     40        (WebCore::IntRectExtent::isZero):
     41        (WebCore::operator==):
     42        (WebCore::operator!=):
     43        (WebCore::operator+=):
     44        * platform/graphics/filters/FilterOperations.cpp:
     45        (WebCore::FilterOperations::outsets):
     46        * platform/graphics/filters/FilterOperations.h:
     47        (FilterOperations):
     48        * platform/graphics/texmap/TextureMapperLayer.cpp:
     49        (WebCore::TextureMapperLayer::intermediateSurfaceRect):
     50        * rendering/FilterEffectRenderer.cpp:
     51        (WebCore::FilterEffectRenderer::FilterEffectRenderer):
     52        (WebCore::FilterEffectRenderer::build):
     53        (WebCore::FilterEffectRenderer::computeSourceImageRectForDirtyRect):
     54        * rendering/FilterEffectRenderer.h:
     55        (FilterEffectRenderer):
     56        * rendering/RenderLayer.cpp:
     57        (WebCore::RenderLayer::setFilterBackendNeedsRepaintingInRect):
     58        (WebCore::transparencyClipBox):
     59        (WebCore::RenderLayer::calculateLayerBounds):
     60        * rendering/style/RenderStyle.h:
     61
    1622013-02-13  Adam Barth  <abarth@webkit.org>
    263
  • trunk/Source/WebCore/GNUmakefile.list.am

    r142809 r142823  
    56465646        Source/WebCore/platform/graphics/IntRect.cpp \
    56475647        Source/WebCore/platform/graphics/IntRect.h \
     5648        Source/WebCore/platform/graphics/IntRectExtent.h \     
    56485649        Source/WebCore/platform/graphics/IntSize.h \
    56495650        Source/WebCore/platform/graphics/IntSizeHash.h \
  • trunk/Source/WebCore/Target.pri

    r142809 r142823  
    22512251    platform/graphics/IntPointHash.h \
    22522252    platform/graphics/IntRect.h \
     2253    platform/graphics/IntRectExtent.h \
    22532254    platform/graphics/Latin1TextIterator.h \
    22542255    platform/graphics/MediaPlayer.h \
  • trunk/Source/WebCore/WebCore.gypi

    r142809 r142823  
    46864686            'platform/graphics/FloatSize.cpp',
    46874687            'platform/graphics/IntRect.cpp',
     4688            'platform/graphics/IntRectExtent.h',
    46884689            'platform/graphics/LayoutRect.cpp',
    46894690            'platform/graphics/Region.cpp',
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r142809 r142823  
    38693869                A29532D015DD5E1700469EBC /* CustomFilterValidatedProgram.h in Headers */ = {isa = PBXBuildFile; fileRef = A29532CE15DD5E1700469EBC /* CustomFilterValidatedProgram.h */; };
    38703870                A2B2AE7C16375EE500CFA50B /* CustomFilterConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = A2B2AE7B16375EE500CFA50B /* CustomFilterConstants.h */; };
     3871                A2B9217316C5CC420041DCD9 /* IntRectExtent.h in Headers */ = {isa = PBXBuildFile; fileRef = A2B9217216C5CC420041DCD9 /* IntRectExtent.h */; settings = {ATTRIBUTES = (Private, ); }; };
    38713872                A2E8AE3016A48E1C006BB3AA /* WebKitCSSFilterRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A2E8AE2E16A48E1C006BB3AA /* WebKitCSSFilterRule.cpp */; };
    38723873                A2E8AE3116A48E1C006BB3AA /* WebKitCSSFilterRule.h in Headers */ = {isa = PBXBuildFile; fileRef = A2E8AE2F16A48E1C006BB3AA /* WebKitCSSFilterRule.h */; };
     
    1134911350                A29532CE15DD5E1700469EBC /* CustomFilterValidatedProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomFilterValidatedProgram.h; path = filters/CustomFilterValidatedProgram.h; sourceTree = "<group>"; };
    1135011351                A2B2AE7B16375EE500CFA50B /* CustomFilterConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomFilterConstants.h; path = filters/CustomFilterConstants.h; sourceTree = "<group>"; };
     11352                A2B9217216C5CC420041DCD9 /* IntRectExtent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntRectExtent.h; sourceTree = "<group>"; };
    1135111353                A2E8AE2E16A48E1C006BB3AA /* WebKitCSSFilterRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSFilterRule.cpp; sourceTree = "<group>"; };
    1135211354                A2E8AE2F16A48E1C006BB3AA /* WebKitCSSFilterRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSFilterRule.h; sourceTree = "<group>"; };
     
    2063320635                                B27535450B053814002CE64F /* IntRect.cpp */,
    2063420636                                B27535460B053814002CE64F /* IntRect.h */,
     20637                                A2B9217216C5CC420041DCD9 /* IntRectExtent.h */,
    2063520638                                E134F5AA12EE343F004EC58D /* IntRectHash.h */,
    2063620639                                B27535470B053814002CE64F /* IntSize.h */,
     
    2471424717                                B27535740B053814002CE64F /* IntRect.h in Headers */,
    2471524718                                E134F5AB12EE343F004EC58D /* IntRectHash.h in Headers */,
     24719                                A2B9217316C5CC420041DCD9 /* IntRectExtent.h in Headers */,
    2471624720                                B27535750B053814002CE64F /* IntSize.h in Headers */,
    2471724721                                B27535760B053814002CE64F /* IntSizeHash.h in Headers */,
  • trunk/Source/WebCore/platform/graphics/filters/FilterOperations.cpp

    r132960 r142823  
    119119}
    120120
    121 void FilterOperations::getOutsets(int& top, int& right, int& bottom, int& left) const
     121FilterOutsets FilterOperations::outsets() const
    122122{
    123     top = 0;
    124     right = 0;
    125     bottom = 0;
    126     left = 0;
     123    FilterOutsets totalOutsets;
    127124    for (size_t i = 0; i < m_operations.size(); ++i) {
    128125        FilterOperation* filterOperation = m_operations.at(i).get();
     
    131128            BlurFilterOperation* blurOperation = static_cast<BlurFilterOperation*>(filterOperation);
    132129            float stdDeviation = floatValueForLength(blurOperation->stdDeviation(), 0);
    133             IntSize outset = outsetSizeForBlur(stdDeviation);
    134             top += outset.height();
    135             right += outset.width();
    136             bottom += outset.height();
    137             left += outset.width();
     130            IntSize outsetSize = outsetSizeForBlur(stdDeviation);
     131            FilterOutsets outsets(outsetSize.height(), outsetSize.width(), outsetSize.height(), outsetSize.width());
     132            totalOutsets += outsets;
    138133            break;
    139134        }
    140135        case FilterOperation::DROP_SHADOW: {
    141136            DropShadowFilterOperation* dropShadowOperation = static_cast<DropShadowFilterOperation*>(filterOperation);
    142             IntSize outset = outsetSizeForBlur(dropShadowOperation->stdDeviation());
    143             top += std::max(0, outset.height() - dropShadowOperation->y());
    144             right += std::max(0, outset.width() + dropShadowOperation->x());
    145             bottom += std::max(0, outset.height() + dropShadowOperation->y());
    146             left += std::max(0, outset.width() - dropShadowOperation->x());
     137            IntSize outsetSize = outsetSizeForBlur(dropShadowOperation->stdDeviation());
     138            FilterOutsets outsets(
     139                std::max(0, outsetSize.height() - dropShadowOperation->y()),
     140                std::max(0, outsetSize.width() + dropShadowOperation->x()),
     141                std::max(0, outsetSize.height() + dropShadowOperation->y()),
     142                std::max(0, outsetSize.width() - dropShadowOperation->x())
     143            );
     144            totalOutsets += outsets;
    147145            break;
    148146        }
     
    159157        }
    160158    }
     159    return totalOutsets;
    161160}
    162161
  • trunk/Source/WebCore/platform/graphics/filters/FilterOperations.h

    r133779 r142823  
    3030
    3131#include "FilterOperation.h"
     32#include "IntRectExtent.h"
    3233#include <wtf/RefPtr.h>
    3334#include <wtf/Vector.h>
    3435
    3536namespace WebCore {
     37
     38typedef IntRectExtent FilterOutsets;
    3639
    3740class FilterOperations {
     
    6467
    6568    bool hasOutsets() const;
    66     void getOutsets(int& top, int& right, int& bottom, int& left) const;
     69    FilterOutsets outsets() const;
    6770
    6871    bool hasFilterThatAffectsOpacity() const;
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp

    r142579 r142823  
    185185#if ENABLE(CSS_FILTERS)
    186186    if (m_currentFilters.hasOutsets()) {
    187         int leftOutset;
    188         int topOutset;
    189         int bottomOutset;
    190         int rightOutset;
    191         m_currentFilters.getOutsets(topOutset, rightOutset, bottomOutset, leftOutset);
     187        FilterOutsets outsets = m_currentFilters.outsets();
    192188        IntRect unfilteredTargetRect(rect);
    193         rect.move(std::max(0, -leftOutset), std::max(0, -topOutset));
    194         rect.expand(leftOutset + rightOutset, topOutset + bottomOutset);
     189        rect.move(std::max(0, -outsets.left()), std::max(0, -outsets.top()));
     190        rect.expand(outsets.left() + outsets.right(), outsets.top() + outsets.bottom());
    195191        rect.unite(unfilteredTargetRect);
    196192    }
  • trunk/Source/WebCore/rendering/FilterEffectRenderer.cpp

    r140845 r142823  
    103103
    104104FilterEffectRenderer::FilterEffectRenderer()
    105     : m_topOutset(0)
    106     , m_rightOutset(0)
    107     , m_bottomOutset(0)
    108     , m_leftOutset(0)
    109     , m_graphicsBufferAttached(false)
     105    : m_graphicsBufferAttached(false)
    110106    , m_hasFilterThatMovesPixels(false)
    111107#if ENABLE(CSS_SHADERS)
     
    197193    m_hasFilterThatMovesPixels = operations.hasFilterThatMovesPixels();
    198194    if (m_hasFilterThatMovesPixels)
    199         operations.getOutsets(m_topOutset, m_rightOutset, m_bottomOutset, m_leftOutset);
     195        m_outsets = operations.outsets();
    200196   
    201197    // Keep the old effects on the stack until we've created the new effects.
     
    440436        // Note that the outsets are reversed here because we are going backwards -> we have the dirty rect and
    441437        // need to find out what is the rectangle that might influence the result inside that dirty rect.
    442         rectForRepaint.move(-m_rightOutset, -m_bottomOutset);
    443         rectForRepaint.expand(m_leftOutset + m_rightOutset, m_topOutset + m_bottomOutset);
     438        rectForRepaint.move(-m_outsets.right(), -m_outsets.bottom());
     439        rectForRepaint.expand(m_outsets.left() + m_outsets.right(), m_outsets.top() + m_outsets.bottom());
    444440    }
    445441    rectForRepaint.intersect(filterBoxRect);
  • trunk/Source/WebCore/rendering/FilterEffectRenderer.h

    r138823 r142823  
    3535#include "GraphicsContext.h"
    3636#include "ImageBuffer.h"
     37#include "IntRectExtent.h"
    3738#include "LayoutRect.h"
    3839#include "SVGFilterBuilder.h"
     
    141142    RefPtr<SourceGraphic> m_sourceGraphic;
    142143   
    143     int m_topOutset;
    144     int m_rightOutset;
    145     int m_bottomOutset;
    146     int m_leftOutset;
    147    
     144    IntRectExtent m_outsets;
     145
    148146    bool m_graphicsBufferAttached;
    149147    bool m_hasFilterThatMovesPixels;
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r142527 r142823  
    13681368}
    13691369
    1370 static inline void expandRectForFilterOutsets(LayoutRect& rect, const RenderLayerModelObject* renderer)
    1371 {
    1372     ASSERT(renderer);
    1373     if (!renderer->style()->hasFilterOutsets())
    1374         return;
    1375 
    1376     int topOutset;
    1377     int rightOutset;
    1378     int bottomOutset;
    1379     int leftOutset;
    1380     renderer->style()->getFilterOutsets(topOutset, rightOutset, bottomOutset, leftOutset);
    1381     rect.move(-leftOutset, -topOutset);
    1382     rect.expand(leftOutset + rightOutset, topOutset + bottomOutset);
    1383 }
    1384 
    13851370void RenderLayer::setFilterBackendNeedsRepaintingInRect(const LayoutRect& rect, bool immediate)
    13861371{
     
    13891374   
    13901375    LayoutRect rectForRepaint = rect;
    1391     expandRectForFilterOutsets(rectForRepaint, renderer());
     1376    renderer()->style()->filterOutsets().expandRect(rectForRepaint);
    13921377
    13931378    RenderLayerFilterInfo* filterInfo = this->filterInfo();
     
    15581543        expandClipRectForDescendantsAndReflection(clipRect, layer, layer, paintBehavior);
    15591544#if ENABLE(CSS_FILTERS)
    1560         expandRectForFilterOutsets(clipRect, layer->renderer());
     1545        layer->renderer()->style()->filterOutsets().expandRect(clipRect);
    15611546#endif
    15621547        return transform.mapRect(clipRect);
     
    15661551    expandClipRectForDescendantsAndReflection(clipRect, layer, rootLayer, paintBehavior);
    15671552#if ENABLE(CSS_FILTERS)
    1568     expandRectForFilterOutsets(clipRect, layer->renderer());
     1553    layer->renderer()->style()->filterOutsets().expandRect(clipRect);
    15691554#endif
    15701555    return clipRect;
     
    50134998    // https://bugs.webkit.org/show_bug.cgi?id=81239
    50144999    if (flags & IncludeLayerFilterOutsets)
    5015         expandRectForFilterOutsets(unionBounds, renderer);
     5000        renderer->style()->filterOutsets().expandRect(unionBounds);
    50165001#endif
    50175002
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r142527 r142823  
    410410
    411411#if ENABLE(CSS_FILTERS)
    412     void getFilterOutsets(int& top, int& right, int& bottom, int& left) const
    413     {
    414         if (hasFilter())
    415             filter().getOutsets(top, right, bottom, left);
    416         else {
    417             top = 0;
    418             right = 0;
    419             bottom = 0;
    420             left = 0;
    421         }
    422     }
    423412    bool hasFilterOutsets() const { return hasFilter() && filter().hasOutsets(); }
    424 #else
    425     bool hasFilterOutsets() const { return false; }
     413    FilterOutsets filterOutsets() const { return hasFilter() ? filter().outsets() : FilterOutsets(); }
    426414#endif
    427415
  • trunk/Source/WebKit/chromium/ChangeLog

    r142810 r142823  
     12013-02-13  Max Vujovic  <mvujovic@adobe.com>
     2
     3        [CSS Filters] Refactor filter outsets into a class
     4        https://bugs.webkit.org/show_bug.cgi?id=109330
     5
     6        Update FilterOperations unit tests to use new interface for getting filter outsets.
     7
     8        Reviewed by Dean Jackson.
     9
     10        * tests/FilterOperationsTest.cpp:
     11        (WebKit::TEST):
     12
    1132013-02-13  Zan Dobersek  <zdobersek@igalia.com>
    214
  • trunk/Source/WebKit/chromium/tests/FilterOperationsTest.cpp

    r129373 r142823  
    4141    ops.operations().append(BlurFilterOperation::create(Length(20.0, WebCore::Fixed), FilterOperation::BLUR));
    4242    EXPECT_TRUE(ops.hasOutsets());
    43     int top, right, bottom, left;
    44     top = right = bottom = left = 0;
    45     ops.getOutsets(top, right, bottom, left);
    46     EXPECT_EQ(57, top);
    47     EXPECT_EQ(57, right);
    48     EXPECT_EQ(57, bottom);
    49     EXPECT_EQ(57, left);
     43    FilterOutsets outsets = ops.outsets();
     44    EXPECT_EQ(57, outsets.top());
     45    EXPECT_EQ(57, outsets.right());
     46    EXPECT_EQ(57, outsets.bottom());
     47    EXPECT_EQ(57, outsets.left());
    5048}
    5149
     
    5553    ops.operations().append(DropShadowFilterOperation::create(IntPoint(3, 8), 20, Color(1, 2, 3), FilterOperation::DROP_SHADOW));
    5654    EXPECT_TRUE(ops.hasOutsets());
    57     int top, right, bottom, left;
    58     top = right = bottom = left = 0;
    59     ops.getOutsets(top, right, bottom, left);
    60     EXPECT_EQ(49, top);
    61     EXPECT_EQ(60, right);
    62     EXPECT_EQ(65, bottom);
    63     EXPECT_EQ(54, left);
     55    FilterOutsets outsets = ops.outsets();
     56    EXPECT_EQ(49, outsets.top());
     57    EXPECT_EQ(60, outsets.right());
     58    EXPECT_EQ(65, outsets.bottom());
     59    EXPECT_EQ(54, outsets.left());
    6460}
    6561
Note: See TracChangeset for help on using the changeset viewer.