1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

Issue #2364 - Re-factor AlphaBoxBlur

Only blur one quadrant of a box-shadow and mirror it to the other quadrants.
This applies only if the corners are symmetrical (square corners or equal
corner radii) otherwise we'll fall back to the old method.
This commit is contained in:
Moonchild
2023-10-30 12:23:36 +01:00
committed by roytam1
parent 8d42309580
commit 8d30faf95f
6 changed files with 552 additions and 347 deletions
+22 -11
View File
@@ -335,10 +335,26 @@ AlphaBoxBlur::AlphaBoxBlur(const Rect& aRect,
const IntSize& aBlurRadius,
const Rect* aDirtyRect,
const Rect* aSkipRect)
: mSpreadRadius(aSpreadRadius),
mBlurRadius(aBlurRadius),
mSurfaceAllocationSize(0)
: mSurfaceAllocationSize(0)
{
Init(aRect, aSpreadRadius, aBlurRadius, aDirtyRect, aSkipRect);
}
AlphaBoxBlur::AlphaBoxBlur()
: mSurfaceAllocationSize(0)
{
}
void
AlphaBoxBlur::Init(const Rect& aRect,
const IntSize& aSpreadRadius,
const IntSize& aBlurRadius,
const Rect* aDirtyRect,
const Rect* aSkipRect)
{
mSpreadRadius = aSpreadRadius;
mBlurRadius = aBlurRadius;
Rect rect(aRect);
rect.Inflate(Size(aBlurRadius + aSpreadRadius));
rect.RoundOut();
@@ -355,8 +371,7 @@ AlphaBoxBlur::AlphaBoxBlur(const Rect& aRect,
mHasDirtyRect = false;
}
mRect = IntRect(int32_t(rect.x), int32_t(rect.y),
int32_t(rect.width), int32_t(rect.height));
mRect = TruncatedToInt(rect);
if (mRect.IsEmpty()) {
return;
}
@@ -366,11 +381,8 @@ AlphaBoxBlur::AlphaBoxBlur(const Rect& aRect,
// blurring/spreading we need to do. We convert it to IntRect to avoid
// expensive int<->float conversions if we were to use Rect instead.
Rect skipRect = *aSkipRect;
skipRect.RoundIn();
skipRect.Deflate(Size(aBlurRadius + aSpreadRadius));
mSkipRect = IntRect(int32_t(skipRect.x), int32_t(skipRect.y),
int32_t(skipRect.width), int32_t(skipRect.height));
mSkipRect = RoundedIn(skipRect);
mSkipRect = mSkipRect.Intersect(mRect);
if (mSkipRect.IsEqualInterior(mRect))
return;
@@ -397,8 +409,7 @@ AlphaBoxBlur::AlphaBoxBlur(const Rect& aRect,
int32_t aStride,
float aSigmaX,
float aSigmaY)
: mRect(int32_t(aRect.x), int32_t(aRect.y),
int32_t(aRect.width), int32_t(aRect.height)),
: mRect(TruncatedToInt(aRect)),
mSpreadRadius(),
mBlurRadius(CalculateBlurRadius(Point(aSigmaX, aSigmaY))),
mStride(aStride),
+8
View File
@@ -68,6 +68,14 @@ public:
float aSigmaX,
float aSigmaY);
AlphaBoxBlur();
void Init(const Rect& aRect,
const IntSize& aSpreadRadius,
const IntSize& aBlurRadius,
const Rect* aDirtyRect,
const Rect* aSkipRect);
~AlphaBoxBlur();
/**
+9
View File
@@ -224,6 +224,15 @@ struct RectCornerRadii {
return true;
}
bool AreRadiiSame() const {
for (size_t i = 1; i < RectCorner::Count; i++) {
if (radii[i] != radii[0]) {
return false;
}
}
return true;
}
void Scale(Float aXScale, Float aYScale) {
for (int i = 0; i < RectCorner::Count; i++) {
radii[i].Scale(aXScale, aYScale);
+482 -293
View File
File diff suppressed because it is too large Load Diff
+28 -38
View File
@@ -10,14 +10,13 @@
#include "nsSize.h"
#include "gfxPoint.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/gfx/Blur.h"
class gfxContext;
struct gfxRect;
namespace mozilla {
namespace gfx {
class AlphaBoxBlur;
struct Color;
struct RectCornerRadii;
class SourceSurface;
@@ -73,21 +72,19 @@ public:
* represents an area where blurring is unnecessary and shouldn't be done
* for speed reasons. It is safe to pass nullptr here.
*/
gfxContext* Init(const gfxRect& aRect,
const mozilla::gfx::IntSize& aSpreadRadius,
const mozilla::gfx::IntSize& aBlurRadius,
const gfxRect* aDirtyRect,
const gfxRect* aSkipRect);
already_AddRefed<gfxContext>
Init(const gfxRect& aRect,
const mozilla::gfx::IntSize& aSpreadRadius,
const mozilla::gfx::IntSize& aBlurRadius,
const gfxRect* aDirtyRect,
const gfxRect* aSkipRect);
/**
* Returns the context that should be drawn to supply the alpha mask to be
* blurred. If the returned surface is null, then there was an error in
* its creation.
*/
gfxContext* GetContext()
{
return mContext;
}
already_AddRefed<DrawTarget>
InitDrawTarget(const mozilla::gfx::Rect& aRect,
const mozilla::gfx::IntSize& aSpreadRadius,
const mozilla::gfx::IntSize& aBlurRadius,
const mozilla::gfx::Rect* aDirtyRect = nullptr,
const mozilla::gfx::Rect* aSkipRect = nullptr);
already_AddRefed<mozilla::gfx::SourceSurface>
DoBlur(DrawTarget* aDT, mozilla::gfx::IntPoint* aTopLeft);
@@ -129,7 +126,7 @@ public:
*/
static void BlurRectangle(gfxContext *aDestinationCtx,
const gfxRect& aRect,
RectCornerRadii* aCornerRadii,
const RectCornerRadii* aCornerRadii,
const gfxPoint& aBlurStdDev,
const Color& aShadowColor,
const gfxRect& aDirtyRect,
@@ -154,41 +151,34 @@ public:
* @param aSKipRect An area in device pixels we don't have to paint in.
*/
void BlurInsetBox(gfxContext* aDestinationCtx,
const mozilla::gfx::Rect aDestinationRect,
const mozilla::gfx::Rect aShadowClipRect,
const mozilla::gfx::IntSize aBlurRadius,
const mozilla::gfx::IntSize aSpreadRadius,
const mozilla::gfx::Rect& aDestinationRect,
const mozilla::gfx::Rect& aShadowClipRect,
const mozilla::gfx::IntSize& aBlurRadius,
const mozilla::gfx::Color& aShadowColor,
const bool aHasBorderRadius,
const RectCornerRadii& aInnerClipRadii,
const mozilla::gfx::Rect aSkipRect,
const mozilla::gfx::Point aShadowOffset);
const RectCornerRadii* aInnerClipRadii,
const mozilla::gfx::Rect& aSkipRect,
const mozilla::gfx::Point& aShadowOffset);
protected:
already_AddRefed<mozilla::gfx::SourceSurface>
GetInsetBlur(const mozilla::gfx::Rect aOuterRect,
const mozilla::gfx::Rect aWhitespaceRect,
const bool aIsDestRect,
GetInsetBlur(const mozilla::gfx::Rect& aOuterRect,
const mozilla::gfx::Rect& aWhitespaceRect,
bool aIsDestRect,
const mozilla::gfx::Color& aShadowColor,
const mozilla::gfx::IntSize& aBlurRadius,
const bool aHasBorderRadius,
const RectCornerRadii& aInnerClipRadii,
DrawTarget* aDestDrawTarget);
/**
* The context of the temporary alpha surface.
*/
RefPtr<gfxContext> mContext;
const RectCornerRadii* aInnerClipRadii,
DrawTarget* aDestDrawTarget,
bool aMirrorCorners);
/**
* The temporary alpha surface.
*/
mozilla::UniquePtr<unsigned char[]> mData;
uint8_t* mData;
/**
* The object that actually does the blurring for us.
*/
mozilla::UniquePtr<mozilla::gfx::AlphaBoxBlur> mBlur;
mozilla::gfx::AlphaBoxBlur mBlur;
};
#endif /* GFX_BLUR_H */
+3 -5
View File
@@ -1631,7 +1631,6 @@ nsCSSRendering::PaintBoxShadowInner(nsPresContext* aPresContext,
// transparent in the shadow, so drawing them changes nothing.
gfxContext* renderContext = aRenderingContext.ThebesContext();
DrawTarget* drawTarget = renderContext->GetDrawTarget();
nsContextBoxBlur blurringArea;
// Clip the context to the area of the frame's padding rect, so no part of the
// shadow is painted outside. Also cut out anything beyond where the inset shadow
@@ -6243,9 +6242,8 @@ nsContextBoxBlur::InsetBoxBlur(gfxContext* aDestinationCtx,
mAlphaBoxBlur.BlurInsetBox(aDestinationCtx, transformedDestRect,
transformedShadowClipRect,
blurRadius, spreadRadius,
aShadowColor, aHasBorderRadius,
aInnerClipRectRadii, transformedSkipRect,
aShadowOffset);
blurRadius, aShadowColor,
aHasBorderRadius ? &aInnerClipRectRadii : nullptr,
transformedSkipRect, aShadowOffset);
return true;
}