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
commit 8d30faf95f
6 changed files with 556 additions and 351 deletions

File diff suppressed because it is too large Load diff

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 */