Skip to content
Permalink
Browse files
2011-04-10 Simon Fraser <simon.fraser@apple.com>
        Reviewed by Ariya Hidayat.

        Allow ShadowBlur to re-use the last buffer if it already contains the correct shadow
        https://bugs.webkit.org/show_bug.cgi?id=58161

        ShadowBlur already has a singleton scratch buffer that is re-used
        between shadows. Enhance use of this scratch buffer to avoid drawing
        and blurring the shadow if the results will match what is already
        in the buffer.

        Cleaned up ShadowBlur code to remove beginShadowLayer() and endShadowLayer(),
        which ended up with little reusable code after adding the re-use logic.

        * platform/graphics/FloatRect.cpp:
        (WebCore::enclosingIntRect): Replace safeFloatToInt() with the existing
        clampToInteger() from MathExtras.h

        * platform/graphics/FloatSize.h:
        (WebCore::expandedIntSize): New method to safely ceil() the size.

        * platform/graphics/RoundedIntRect.h:
        Add operator== for Radii and RoundedIntRect.

        * platform/graphics/ShadowBlur.cpp:
        (WebCore::ScratchBuffer::ScratchBuffer):
        (WebCore::ScratchBuffer::setLastShadowValues):
        (WebCore::ScratchBuffer::setLastInsetShadowValues):
        (WebCore::ScratchBuffer::matchesLastShadow):
        (WebCore::ScratchBuffer::matchesLastInsetShadow):
        (WebCore::ScratchBuffer::clearScratchBuffer):
        Have the scratch buffer remember what shadow parameters were used
        to render the buffer contents.

        (WebCore::ShadowBlur::drawShadowBuffer):
        Renamed from endShadowLayer(), and only contains the drawing
        logic now.

        (WebCore::ShadowBlur::drawRectShadow):
        Promote some code from beginShadowLayer().

        (WebCore::ShadowBlur::drawInsetShadow):
        Promote some code from beginShadowLayer().

        (WebCore::ShadowBlur::drawRectShadowWithoutTiling):
        (WebCore::ShadowBlur::drawInsetShadowWithoutTiling):
        (WebCore::ShadowBlur::drawInsetShadowWithTiling):
        (WebCore::ShadowBlur::drawRectShadowWithTiling):
        These methods now check to see if the buffer already matches
        their required parameters, and avoid work if it does.

        (WebCore::ShadowBlur::blurShadowBuffer):
        Factored some code into this new method.

        (WebCore::ShadowBlur::blurAndColorShadowBuffer):
        Minor refactoring.

        * platform/graphics/ShadowBlur.h:

Canonical link: https://commits.webkit.org/73194@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83422 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
smfr committed Apr 11, 2011
1 parent 4a6dc7f commit e9b0eb3944a942af57784d667220b1df08460bab
@@ -1,3 +1,63 @@
2011-04-10 Simon Fraser <simon.fraser@apple.com>

Reviewed by Ariya Hidayat.

Allow ShadowBlur to re-use the last buffer if it already contains the correct shadow
https://bugs.webkit.org/show_bug.cgi?id=58161

ShadowBlur already has a singleton scratch buffer that is re-used
between shadows. Enhance use of this scratch buffer to avoid drawing
and blurring the shadow if the results will match what is already
in the buffer.

Cleaned up ShadowBlur code to remove beginShadowLayer() and endShadowLayer(),
which ended up with little reusable code after adding the re-use logic.

* platform/graphics/FloatRect.cpp:
(WebCore::enclosingIntRect): Replace safeFloatToInt() with the existing
clampToInteger() from MathExtras.h

* platform/graphics/FloatSize.h:
(WebCore::expandedIntSize): New method to safely ceil() the size.

* platform/graphics/RoundedIntRect.h:
Add operator== for Radii and RoundedIntRect.

* platform/graphics/ShadowBlur.cpp:
(WebCore::ScratchBuffer::ScratchBuffer):
(WebCore::ScratchBuffer::setLastShadowValues):
(WebCore::ScratchBuffer::setLastInsetShadowValues):
(WebCore::ScratchBuffer::matchesLastShadow):
(WebCore::ScratchBuffer::matchesLastInsetShadow):
(WebCore::ScratchBuffer::clearScratchBuffer):
Have the scratch buffer remember what shadow parameters were used
to render the buffer contents.

(WebCore::ShadowBlur::drawShadowBuffer):
Renamed from endShadowLayer(), and only contains the drawing
logic now.

(WebCore::ShadowBlur::drawRectShadow):
Promote some code from beginShadowLayer().

(WebCore::ShadowBlur::drawInsetShadow):
Promote some code from beginShadowLayer().

(WebCore::ShadowBlur::drawRectShadowWithoutTiling):
(WebCore::ShadowBlur::drawInsetShadowWithoutTiling):
(WebCore::ShadowBlur::drawInsetShadowWithTiling):
(WebCore::ShadowBlur::drawRectShadowWithTiling):
These methods now check to see if the buffer already matches
their required parameters, and avoid work if it does.

(WebCore::ShadowBlur::blurShadowBuffer):
Factored some code into this new method.

(WebCore::ShadowBlur::blurAndColorShadowBuffer):
Minor refactoring.

* platform/graphics/ShadowBlur.h:

2011-04-10 Geoffrey Garen <ggaren@apple.com>

Build fix: Updated for file move.
@@ -30,8 +30,8 @@
#include "FloatConversion.h"
#include "IntRect.h"
#include <algorithm>
#include <limits>
#include <math.h>
#include <wtf/MathExtras.h>

using std::max;
using std::min;
@@ -182,26 +182,14 @@ void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1, const Fl
setLocationAndSizeFromEdges(left, top, right, bottom);
}

static inline int safeFloatToInt(float x)
{
static const int s_intMax = std::numeric_limits<int>::max();
static const int s_intMin = std::numeric_limits<int>::min();

if (x >= static_cast<float>(s_intMax))
return s_intMax;
if (x < static_cast<float>(s_intMin))
return s_intMin;
return static_cast<int>(x);
}

IntRect enclosingIntRect(const FloatRect& rect)
{
float left = floorf(rect.x());
float top = floorf(rect.y());
float width = ceilf(rect.maxX()) - left;
float height = ceilf(rect.maxY()) - top;
return IntRect(safeFloatToInt(left), safeFloatToInt(top),
safeFloatToInt(width), safeFloatToInt(height));
return IntRect(clampToInteger(left), clampToInteger(top),
clampToInteger(width), clampToInteger(height));
}

FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect)
@@ -148,6 +148,11 @@ inline IntSize roundedIntSize(const FloatSize& p)
return IntSize(static_cast<int>(roundf(p.width())), static_cast<int>(roundf(p.height())));
}

inline IntSize expandedIntSize(const FloatSize& p)
{
return IntSize(clampToInteger(ceilf(p.width())), clampToInteger(ceilf(p.height())));
}

} // namespace WebCore

#endif // FloatSize_h
@@ -98,6 +98,17 @@ class RoundedIntRect {
Radii m_radii;
};

inline bool operator==(const RoundedIntRect::Radii& a, const RoundedIntRect::Radii& b)
{
return a.topLeft() == b.topLeft() && a.topRight() == b.topRight() && a.bottomLeft() == b.bottomLeft() && a.bottomRight() == b.bottomRight();
}

inline bool operator==(const RoundedIntRect& a, const RoundedIntRect& b)
{
return a.rect() == b.rect() && a.radii() == b.radii();
}


} // namespace WebCore

#endif // RoundedIntRect_h

0 comments on commit e9b0eb3

Please sign in to comment.