2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGFilterFrame.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxASurface.h"
|
|
|
|
#include "gfxUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2011-10-09 10:17:29 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2012-06-26 03:49:23 -07:00
|
|
|
#include "nsSVGElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGFilterElement.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsSVGFilterInstance.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGFilterPaintCallback.h"
|
2012-06-24 05:59:26 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGFilterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGFilterFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGFilterFrame)
|
|
|
|
|
2012-06-24 05:59:26 -07:00
|
|
|
/**
|
2012-06-26 03:49:23 -07:00
|
|
|
* Converts an nsRect that is relative to a filtered frame's origin (i.e. the
|
|
|
|
* top-left corner of its border box) into filter space.
|
|
|
|
* Returns the entire filter region (a rect the width/height of aFilterRes) if
|
|
|
|
* aFrameRect is null, or if the result is too large to be stored in an
|
|
|
|
* nsIntRect.
|
2012-06-24 05:59:26 -07:00
|
|
|
*/
|
2008-07-22 19:15:27 -07:00
|
|
|
static nsIntRect
|
2012-06-26 03:49:23 -07:00
|
|
|
MapFrameRectToFilterSpace(const nsRect* aRect,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aAppUnitsPerCSSPx,
|
2012-06-26 03:49:23 -07:00
|
|
|
const gfxMatrix& aFrameSpaceInCSSPxToFilterSpace,
|
|
|
|
const gfxIntSize& aFilterRes)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-26 03:49:23 -07:00
|
|
|
nsIntRect rect(0, 0, aFilterRes.width, aFilterRes.height);
|
|
|
|
if (aRect) {
|
|
|
|
gfxRect rectInCSSPx =
|
|
|
|
nsLayoutUtils::RectToGfxRect(*aRect, aAppUnitsPerCSSPx);
|
|
|
|
gfxRect rectInFilterSpace =
|
|
|
|
aFrameSpaceInCSSPxToFilterSpace.TransformBounds(rectInCSSPx);
|
|
|
|
rectInFilterSpace.RoundOut();
|
2008-07-22 19:15:27 -07:00
|
|
|
nsIntRect intRect;
|
2012-06-26 03:49:23 -07:00
|
|
|
if (gfxUtils::GfxRectToIntRect(rectInFilterSpace, &intRect)) {
|
2008-07-22 19:15:27 -07:00
|
|
|
rect = intRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rect;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
/**
|
|
|
|
* Returns the transform from frame space to the coordinate space that
|
|
|
|
* GetCanvasTM transforms to. "Frame space" is the origin of a frame, aka the
|
|
|
|
* top-left corner of its border box, aka the top left corner of its mRect.
|
|
|
|
*/
|
|
|
|
static gfxMatrix
|
|
|
|
GetUserToFrameSpaceInCSSPxTransform(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
gfxMatrix userToFrameSpaceInCSSPx;
|
|
|
|
|
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerCSSPx = aFrame->PresContext()->AppUnitsPerCSSPixel();
|
2012-06-26 03:49:23 -07:00
|
|
|
// As currently implemented by Mozilla for the purposes of filters, user
|
|
|
|
// space is the coordinate system established by GetCanvasTM(), since
|
|
|
|
// that's what we use to set filterToDeviceSpace above. In other words,
|
|
|
|
// for SVG, user space is actually the coordinate system aTarget
|
|
|
|
// establishes for _its_ children (i.e. after taking account of any x/y
|
|
|
|
// and viewBox attributes), not the coordinate system that is established
|
|
|
|
// for it by its 'transform' attribute (or by its _parent_) as it's
|
|
|
|
// normally defined. (XXX We should think about fixing this.) The only
|
|
|
|
// frame type for which these extra transforms are not simply an x/y
|
|
|
|
// translation is nsSVGInnerSVGFrame, hence we treat it specially here.
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgInnerSVGFrame) {
|
|
|
|
userToFrameSpaceInCSSPx =
|
|
|
|
static_cast<nsSVGElement*>(aFrame->GetContent())->
|
|
|
|
PrependLocalTransformsTo(gfxMatrix());
|
|
|
|
} else {
|
|
|
|
gfxPoint targetsUserSpaceOffset =
|
|
|
|
nsLayoutUtils::RectToGfxRect(aFrame->GetRect(), appUnitsPerCSSPx).
|
|
|
|
TopLeft();
|
|
|
|
userToFrameSpaceInCSSPx.Translate(-targetsUserSpaceOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else, for all other frames, leave as the identity matrix
|
|
|
|
return userToFrameSpaceInCSSPx;
|
|
|
|
}
|
|
|
|
|
2012-03-28 04:31:47 -07:00
|
|
|
class nsSVGFilterFrame::AutoFilterReferencer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoFilterReferencer(nsSVGFilterFrame *aFrame)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
|
|
|
// Reference loops should normally be detected in advance and handled, so
|
|
|
|
// we're not expecting to encounter them here
|
|
|
|
NS_ABORT_IF_FALSE(!mFrame->mLoopFlag, "Undetected reference loop!");
|
|
|
|
mFrame->mLoopFlag = true;
|
|
|
|
}
|
|
|
|
~AutoFilterReferencer() {
|
|
|
|
mFrame->mLoopFlag = false;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsSVGFilterFrame *mFrame;
|
|
|
|
};
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
class NS_STACK_CLASS nsAutoFilterInstance {
|
|
|
|
public:
|
|
|
|
nsAutoFilterInstance(nsIFrame *aTarget,
|
|
|
|
nsSVGFilterFrame *aFilterFrame,
|
|
|
|
nsSVGFilterPaintCallback *aPaint,
|
2012-06-26 03:49:23 -07:00
|
|
|
const nsRect *aPostFilterDirtyRect,
|
|
|
|
const nsRect *aPreFilterDirtyRect,
|
|
|
|
const nsRect *aOverridePreFilterVisualOverflowRect,
|
2012-07-30 07:20:58 -07:00
|
|
|
const gfxRect *aOverrideBBox = nullptr);
|
2012-04-13 06:22:06 -07:00
|
|
|
~nsAutoFilterInstance() {}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
|
|
|
// If this returns null, then draw nothing. Either the filter draws
|
|
|
|
// nothing or it is "in error".
|
|
|
|
nsSVGFilterInstance* get() { return mInstance; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsAutoPtr<nsSVGFilterInstance> mInstance;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsAutoFilterInstance::nsAutoFilterInstance(nsIFrame *aTarget,
|
|
|
|
nsSVGFilterFrame *aFilterFrame,
|
|
|
|
nsSVGFilterPaintCallback *aPaint,
|
2012-06-26 03:49:23 -07:00
|
|
|
const nsRect *aPostFilterDirtyRect,
|
|
|
|
const nsRect *aPreFilterDirtyRect,
|
|
|
|
const nsRect *aPreFilterVisualOverflowRectOverride,
|
|
|
|
const gfxRect *aOverrideBBox)
|
2008-02-17 23:29:00 -08:00
|
|
|
{
|
2012-03-28 04:31:47 -07:00
|
|
|
const nsSVGFilterElement *filter = aFilterFrame->GetFilterContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t filterUnits =
|
2012-03-28 04:31:47 -07:00
|
|
|
aFilterFrame->GetEnumValue(nsSVGFilterElement::FILTERUNITS);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t primitiveUnits =
|
2012-03-28 04:31:47 -07:00
|
|
|
aFilterFrame->GetEnumValue(nsSVGFilterElement::PRIMITIVEUNITS);
|
2009-02-09 16:54:28 -08:00
|
|
|
|
2012-06-22 20:01:36 -07:00
|
|
|
gfxRect bbox = aOverrideBBox ? *aOverrideBBox : nsSVGUtils::GetBBox(aTarget);
|
2009-02-09 16:54:28 -08:00
|
|
|
|
|
|
|
// Get the filter region (in the filtered element's user space):
|
|
|
|
|
|
|
|
// XXX if filterUnits is set (or has defaulted) to objectBoundingBox, we
|
|
|
|
// should send a warning to the error console if the author has used lengths
|
|
|
|
// with units. This is a common mistake and can result in filterRes being
|
|
|
|
// *massive* below (because we ignore the units and interpret the number as
|
|
|
|
// a factor of the bbox width/height). We should also send a warning if the
|
|
|
|
// user uses a number without units (a future SVG spec should really
|
|
|
|
// deprecate that, since it's too confusing for a bare number to be sometimes
|
|
|
|
// interpreted as a fraction of the bounding box and sometimes as user-space
|
|
|
|
// units). So really only percentage values should be used in this case.
|
|
|
|
|
2012-03-28 04:31:47 -07:00
|
|
|
nsSVGLength2 XYWH[4];
|
|
|
|
NS_ABORT_IF_FALSE(sizeof(filter->mLengthAttributes) == sizeof(XYWH),
|
|
|
|
"XYWH size incorrect");
|
|
|
|
memcpy(XYWH, filter->mLengthAttributes, sizeof(filter->mLengthAttributes));
|
|
|
|
XYWH[0] = *aFilterFrame->GetLengthValue(nsSVGFilterElement::X);
|
|
|
|
XYWH[1] = *aFilterFrame->GetLengthValue(nsSVGFilterElement::Y);
|
|
|
|
XYWH[2] = *aFilterFrame->GetLengthValue(nsSVGFilterElement::WIDTH);
|
|
|
|
XYWH[3] = *aFilterFrame->GetLengthValue(nsSVGFilterElement::HEIGHT);
|
2012-06-26 03:49:23 -07:00
|
|
|
// The filter region in user space, in user units:
|
2009-02-09 16:54:28 -08:00
|
|
|
gfxRect filterRegion = nsSVGUtils::GetRelativeRect(filterUnits,
|
2012-03-28 04:31:47 -07:00
|
|
|
XYWH, bbox, aTarget);
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2009-02-09 16:54:28 -08:00
|
|
|
if (filterRegion.Width() <= 0 || filterRegion.Height() <= 0) {
|
|
|
|
// 0 disables rendering, < 0 is error. dispatch error console warning
|
|
|
|
// or error as appropriate.
|
2009-01-29 23:22:29 -08:00
|
|
|
return;
|
2009-02-09 16:54:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate filterRes (the width and height of the pixel buffer of the
|
2012-06-26 03:49:23 -07:00
|
|
|
// temporary offscreen surface that we would/will create to paint into when
|
|
|
|
// painting the entire filtered element) and, if necessary, adjust
|
|
|
|
// filterRegion out slightly so that it aligns with pixel boundaries of this
|
|
|
|
// buffer:
|
2009-01-29 23:22:29 -08:00
|
|
|
|
2007-06-13 02:02:48 -07:00
|
|
|
gfxIntSize filterRes;
|
2012-03-28 04:31:47 -07:00
|
|
|
const nsSVGIntegerPair* filterResAttrs =
|
|
|
|
aFilterFrame->GetIntegerPairValue(nsSVGFilterElement::FILTERRES);
|
|
|
|
if (filterResAttrs->IsExplicitlySet()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t filterResX = filterResAttrs->GetAnimValue(nsSVGIntegerPair::eFirst);
|
|
|
|
int32_t filterResY = filterResAttrs->GetAnimValue(nsSVGIntegerPair::eSecond);
|
2011-08-15 11:41:57 -07:00
|
|
|
if (filterResX <= 0 || filterResY <= 0) {
|
|
|
|
// 0 disables rendering, < 0 is error. dispatch error console warning?
|
|
|
|
return;
|
|
|
|
}
|
2007-06-13 02:02:48 -07:00
|
|
|
|
2011-08-15 11:41:57 -07:00
|
|
|
filterRegion.Scale(filterResX, filterResY);
|
|
|
|
filterRegion.RoundOut();
|
|
|
|
filterRegion.Scale(1.0 / filterResX, 1.0 / filterResY);
|
2009-10-26 18:43:55 -07:00
|
|
|
// We don't care if this overflows, because we can handle upscaling/
|
|
|
|
// downscaling to filterRes
|
2011-09-28 23:19:26 -07:00
|
|
|
bool overflow;
|
2007-06-13 02:02:48 -07:00
|
|
|
filterRes =
|
|
|
|
nsSVGUtils::ConvertToSurfaceSize(gfxSize(filterResX, filterResY),
|
2009-10-26 18:43:55 -07:00
|
|
|
&overflow);
|
2009-02-09 16:54:28 -08:00
|
|
|
// XXX we could send a warning to the error console if the author specified
|
|
|
|
// filterRes doesn't align well with our outer 'svg' device space.
|
2007-06-13 02:02:48 -07:00
|
|
|
} else {
|
2009-02-09 16:54:28 -08:00
|
|
|
// Match filterRes as closely as possible to the pixel density of the nearest
|
|
|
|
// outer 'svg' device space:
|
2012-06-30 04:20:46 -07:00
|
|
|
gfxMatrix canvasTM =
|
|
|
|
nsSVGUtils::GetCanvasTM(aTarget, nsISVGChildFrame::FOR_OUTERSVG_TM);
|
2012-05-16 21:05:09 -07:00
|
|
|
if (canvasTM.IsSingular()) {
|
|
|
|
// nothing to draw
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float scale = nsSVGUtils::MaxExpansion(canvasTM);
|
2011-08-15 11:41:57 -07:00
|
|
|
|
|
|
|
filterRegion.Scale(scale);
|
|
|
|
filterRegion.RoundOut();
|
2009-10-26 18:43:55 -07:00
|
|
|
// We don't care if this overflows, because we can handle upscaling/
|
|
|
|
// downscaling to filterRes
|
2011-09-28 23:19:26 -07:00
|
|
|
bool overflow;
|
2011-08-15 11:41:57 -07:00
|
|
|
filterRes = nsSVGUtils::ConvertToSurfaceSize(filterRegion.Size(),
|
2009-10-26 18:43:55 -07:00
|
|
|
&overflow);
|
2011-08-15 11:41:57 -07:00
|
|
|
filterRegion.Scale(1.0 / scale);
|
2009-02-09 16:54:28 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
// Get various transforms:
|
2009-02-09 16:54:28 -08:00
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix filterToUserSpace(filterRegion.Width() / filterRes.width, 0.0f,
|
|
|
|
0.0f, filterRegion.Height() / filterRes.height,
|
|
|
|
filterRegion.X(), filterRegion.Y());
|
2012-06-26 03:49:23 -07:00
|
|
|
|
|
|
|
// Only used (so only set) when we paint:
|
|
|
|
gfxMatrix filterToDeviceSpace;
|
|
|
|
if (aPaint) {
|
2012-06-30 04:20:46 -07:00
|
|
|
filterToDeviceSpace = filterToUserSpace *
|
|
|
|
nsSVGUtils::GetCanvasTM(aTarget, nsISVGChildFrame::FOR_PAINTING);
|
2012-06-26 03:49:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the passed in rects from frame to filter space:
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerCSSPx = aTarget->PresContext()->AppUnitsPerCSSPixel();
|
2012-06-26 03:49:23 -07:00
|
|
|
|
|
|
|
gfxMatrix filterToFrameSpaceInCSSPx =
|
|
|
|
filterToUserSpace * GetUserToFrameSpaceInCSSPxTransform(aTarget);
|
|
|
|
// filterToFrameSpaceInCSSPx is always invertible
|
|
|
|
gfxMatrix frameSpaceInCSSPxTofilterSpace = filterToFrameSpaceInCSSPx;
|
|
|
|
frameSpaceInCSSPxTofilterSpace.Invert();
|
2008-07-22 19:15:27 -07:00
|
|
|
|
2012-06-16 13:23:48 -07:00
|
|
|
nsIntRect postFilterDirtyRect =
|
2012-06-26 03:49:23 -07:00
|
|
|
MapFrameRectToFilterSpace(aPostFilterDirtyRect, appUnitsPerCSSPx,
|
|
|
|
frameSpaceInCSSPxTofilterSpace, filterRes);
|
2012-06-16 13:23:48 -07:00
|
|
|
nsIntRect preFilterDirtyRect =
|
2012-06-26 03:49:23 -07:00
|
|
|
MapFrameRectToFilterSpace(aPreFilterDirtyRect, appUnitsPerCSSPx,
|
|
|
|
frameSpaceInCSSPxTofilterSpace, filterRes);
|
|
|
|
nsIntRect preFilterVisualOverflowRect;
|
|
|
|
if (aPreFilterVisualOverflowRectOverride) {
|
|
|
|
preFilterVisualOverflowRect =
|
|
|
|
MapFrameRectToFilterSpace(aPreFilterVisualOverflowRectOverride,
|
|
|
|
appUnitsPerCSSPx,
|
|
|
|
frameSpaceInCSSPxTofilterSpace, filterRes);
|
|
|
|
} else {
|
|
|
|
nsRect preFilterVOR = aTarget->GetPreEffectsVisualOverflowRect();
|
|
|
|
preFilterVisualOverflowRect =
|
|
|
|
MapFrameRectToFilterSpace(&preFilterVOR, appUnitsPerCSSPx,
|
|
|
|
frameSpaceInCSSPxTofilterSpace, filterRes);
|
2011-09-17 01:29:51 -07:00
|
|
|
}
|
2008-07-14 20:08:47 -07:00
|
|
|
|
2008-07-13 18:21:25 -07:00
|
|
|
// Setup instance data
|
2012-06-26 03:49:23 -07:00
|
|
|
mInstance =
|
|
|
|
new nsSVGFilterInstance(aTarget, aPaint, filter, bbox, filterRegion,
|
|
|
|
nsIntSize(filterRes.width, filterRes.height),
|
|
|
|
filterToDeviceSpace, filterToFrameSpaceInCSSPx,
|
|
|
|
preFilterVisualOverflowRect, postFilterDirtyRect,
|
|
|
|
preFilterDirtyRect, primitiveUnits);
|
2008-07-22 19:15:27 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t
|
|
|
|
nsSVGFilterFrame::GetEnumValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-28 04:31:47 -07:00
|
|
|
{
|
|
|
|
nsSVGEnum& thisEnum =
|
|
|
|
static_cast<nsSVGFilterElement *>(mContent)->mEnumAttributes[aIndex];
|
|
|
|
|
|
|
|
if (thisEnum.IsExplicitlySet())
|
|
|
|
return thisEnum.GetAnimValue();
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetEnumValue(aIndex, aDefault) :
|
|
|
|
static_cast<nsSVGFilterElement *>(aDefault)->
|
|
|
|
mEnumAttributes[aIndex].GetAnimValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsSVGIntegerPair *
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGFilterFrame::GetIntegerPairValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-28 04:31:47 -07:00
|
|
|
{
|
|
|
|
const nsSVGIntegerPair *thisIntegerPair =
|
|
|
|
&static_cast<nsSVGFilterElement *>(mContent)->mIntegerPairAttributes[aIndex];
|
|
|
|
|
|
|
|
if (thisIntegerPair->IsExplicitlySet())
|
|
|
|
return thisIntegerPair;
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetIntegerPairValue(aIndex, aDefault) :
|
|
|
|
&static_cast<nsSVGFilterElement *>(aDefault)->mIntegerPairAttributes[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsSVGLength2 *
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGFilterFrame::GetLengthValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-28 04:31:47 -07:00
|
|
|
{
|
|
|
|
const nsSVGLength2 *thisLength =
|
|
|
|
&static_cast<nsSVGFilterElement *>(mContent)->mLengthAttributes[aIndex];
|
|
|
|
|
|
|
|
if (thisLength->IsExplicitlySet())
|
|
|
|
return thisLength;
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetLengthValue(aIndex, aDefault) :
|
|
|
|
&static_cast<nsSVGFilterElement *>(aDefault)->mLengthAttributes[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsSVGFilterElement *
|
|
|
|
nsSVGFilterFrame::GetFilterContent(nsIContent *aDefault)
|
|
|
|
{
|
2012-03-29 01:41:37 -07:00
|
|
|
for (nsIContent* child = mContent->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2012-03-28 04:31:47 -07:00
|
|
|
nsRefPtr<nsSVGFE> primitive;
|
|
|
|
CallQueryInterface(child, (nsSVGFE**)getter_AddRefs(primitive));
|
|
|
|
if (primitive) {
|
|
|
|
return static_cast<nsSVGFilterElement *>(mContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetFilterContent(aDefault) :
|
|
|
|
static_cast<nsSVGFilterElement *>(aDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame *
|
|
|
|
nsSVGFilterFrame::GetReferencedFilter()
|
|
|
|
{
|
|
|
|
if (mNoHRefURI)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
nsSVGPaintingProperty *property = static_cast<nsSVGPaintingProperty*>
|
|
|
|
(Properties().Get(nsSVGEffects::HrefProperty()));
|
|
|
|
|
|
|
|
if (!property) {
|
|
|
|
// Fetch our Filter element's xlink:href attribute
|
|
|
|
nsSVGFilterElement *filter = static_cast<nsSVGFilterElement *>(mContent);
|
|
|
|
nsAutoString href;
|
|
|
|
filter->mStringAttributes[nsSVGFilterElement::HREF].GetAnimValue(href, filter);
|
|
|
|
if (href.IsEmpty()) {
|
|
|
|
mNoHRefURI = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; // no URL
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert href to an nsIURI
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
|
|
|
|
mContent->GetCurrentDoc(), base);
|
|
|
|
|
|
|
|
property =
|
|
|
|
nsSVGEffects::GetPaintingProperty(targetURI, this, nsSVGEffects::HrefProperty());
|
|
|
|
if (!property)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *result = property->GetReferencedFrame();
|
|
|
|
if (!result)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
nsIAtom* frameType = result->GetType();
|
|
|
|
if (frameType != nsGkAtoms::svgFilterFrame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
return static_cast<nsSVGFilterFrame*>(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame *
|
|
|
|
nsSVGFilterFrame::GetReferencedFilterIfNotInUse()
|
|
|
|
{
|
|
|
|
nsSVGFilterFrame *referenced = GetReferencedFilter();
|
|
|
|
if (!referenced)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
if (referenced->mLoopFlag) {
|
|
|
|
// XXXjwatt: we should really send an error to the JavaScript Console here:
|
|
|
|
NS_WARNING("Filter reference loop detected while inheriting attribute!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return referenced;
|
|
|
|
}
|
|
|
|
|
2011-10-09 10:17:29 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGFilterFrame::AttributeChanged(int32_t aNameSpaceID,
|
2011-10-09 10:17:29 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2011-10-09 10:17:29 -07:00
|
|
|
{
|
2012-03-28 04:31:47 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height ||
|
|
|
|
aAttribute == nsGkAtoms::filterRes ||
|
|
|
|
aAttribute == nsGkAtoms::filterUnits ||
|
|
|
|
aAttribute == nsGkAtoms::primitiveUnits)) {
|
2012-06-23 07:19:00 -07:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2012-03-28 04:31:47 -07:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
|
|
|
// Blow away our reference, if any
|
|
|
|
Properties().Delete(nsSVGEffects::HrefProperty());
|
|
|
|
mNoHRefURI = false;
|
|
|
|
// And update whoever references us
|
2012-06-23 07:19:00 -07:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2011-10-09 10:17:29 -07:00
|
|
|
}
|
|
|
|
return nsSVGFilterFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2008-07-22 19:15:27 -07:00
|
|
|
nsresult
|
2012-06-16 13:23:48 -07:00
|
|
|
nsSVGFilterFrame::PaintFilteredFrame(nsRenderingContext *aContext,
|
|
|
|
nsIFrame *aFilteredFrame,
|
|
|
|
nsSVGFilterPaintCallback *aPaintCallback,
|
2012-06-26 03:49:23 -07:00
|
|
|
const nsRect *aDirtyArea)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-16 13:23:48 -07:00
|
|
|
nsAutoFilterInstance instance(aFilteredFrame, this, aPaintCallback,
|
2012-07-30 07:20:58 -07:00
|
|
|
aDirtyArea, nullptr, nullptr);
|
2012-06-26 03:49:23 -07:00
|
|
|
if (!instance.get()) {
|
2008-09-10 17:24:16 -07:00
|
|
|
return NS_OK;
|
2012-06-26 03:49:23 -07:00
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
nsRefPtr<gfxASurface> result;
|
|
|
|
nsresult rv = instance.get()->Render(getter_AddRefs(result));
|
|
|
|
if (NS_SUCCEEDED(rv) && result) {
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGUtils::CompositeSurfaceMatrix(aContext->ThebesContext(),
|
2008-09-10 17:24:16 -07:00
|
|
|
result, instance.get()->GetFilterSpaceToDeviceSpaceTransform(), 1.0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-07-22 19:15:27 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
static nsRect
|
|
|
|
TransformFilterSpaceToFrameSpace(nsSVGFilterInstance *aInstance,
|
|
|
|
nsIntRect *aRect)
|
2008-07-22 19:15:27 -07:00
|
|
|
{
|
2012-06-26 03:49:23 -07:00
|
|
|
gfxMatrix m = aInstance->GetFilterSpaceToFrameSpaceInCSSPxTransform();
|
2008-09-10 17:24:16 -07:00
|
|
|
gfxRect r(aRect->x, aRect->y, aRect->width, aRect->height);
|
|
|
|
r = m.TransformBounds(r);
|
2012-06-26 03:49:23 -07:00
|
|
|
return nsLayoutUtils::RoundGfxRectToAppRect(r, aInstance->AppUnitsPerCSSPixel());
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
2008-07-22 19:15:27 -07:00
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
nsRect
|
2012-06-16 13:23:48 -07:00
|
|
|
nsSVGFilterFrame::GetPostFilterDirtyArea(nsIFrame *aFilteredFrame,
|
2012-06-26 03:49:23 -07:00
|
|
|
const nsRect& aPreFilterDirtyRect)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsAutoFilterInstance instance(aFilteredFrame, this, nullptr, nullptr,
|
|
|
|
&aPreFilterDirtyRect, nullptr);
|
2012-06-26 03:49:23 -07:00
|
|
|
if (!instance.get()) {
|
|
|
|
return nsRect();
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
// We've passed in the source's dirty area so the instance knows about it.
|
|
|
|
// Now we can ask the instance to compute the area of the filter output
|
|
|
|
// that's dirty.
|
|
|
|
nsIntRect dirtyRect;
|
2012-06-16 13:23:48 -07:00
|
|
|
nsresult rv = instance.get()->ComputePostFilterDirtyRect(&dirtyRect);
|
2008-07-22 19:15:27 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-06-26 03:49:23 -07:00
|
|
|
return TransformFilterSpaceToFrameSpace(instance.get(), &dirtyRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-26 03:49:23 -07:00
|
|
|
return nsRect();
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
nsRect
|
2012-06-16 13:23:48 -07:00
|
|
|
nsSVGFilterFrame::GetPreFilterNeededArea(nsIFrame *aFilteredFrame,
|
2012-06-26 03:49:23 -07:00
|
|
|
const nsRect& aPostFilterDirtyRect)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsAutoFilterInstance instance(aFilteredFrame, this, nullptr,
|
|
|
|
&aPostFilterDirtyRect, nullptr, nullptr);
|
2012-06-26 03:49:23 -07:00
|
|
|
if (!instance.get()) {
|
|
|
|
return nsRect();
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
// Now we can ask the instance to compute the area of the source
|
|
|
|
// that's needed.
|
|
|
|
nsIntRect neededRect;
|
|
|
|
nsresult rv = instance.get()->ComputeSourceNeededRect(&neededRect);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-06-26 03:49:23 -07:00
|
|
|
return TransformFilterSpaceToFrameSpace(instance.get(), &neededRect);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
2012-06-26 03:49:23 -07:00
|
|
|
return nsRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
nsRect
|
2012-06-16 13:23:48 -07:00
|
|
|
nsSVGFilterFrame::GetPostFilterBounds(nsIFrame *aFilteredFrame,
|
2012-06-22 20:01:36 -07:00
|
|
|
const gfxRect *aOverrideBBox,
|
2012-06-26 03:49:23 -07:00
|
|
|
const nsRect *aPreFilterBounds)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-08-14 02:04:24 -07:00
|
|
|
MOZ_ASSERT(!(aFilteredFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) ||
|
|
|
|
!(aFilteredFrame->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD),
|
|
|
|
"Non-display SVG do not maintain visual overflow rects");
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsAutoFilterInstance instance(aFilteredFrame, this, nullptr, nullptr,
|
2012-06-26 03:49:23 -07:00
|
|
|
aPreFilterBounds, aPreFilterBounds,
|
|
|
|
aOverrideBBox);
|
|
|
|
if (!instance.get()) {
|
|
|
|
return nsRect();
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
// We've passed in the source's bounding box so the instance knows about
|
|
|
|
// it. Now we can ask the instance to compute the bounding box of
|
|
|
|
// the filter output.
|
|
|
|
nsIntRect bbox;
|
|
|
|
nsresult rv = instance.get()->ComputeOutputBBox(&bbox);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-06-26 03:49:23 -07:00
|
|
|
return TransformFilterSpaceToFrameSpace(instance.get(), &bbox);
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
2012-06-26 03:49:23 -07:00
|
|
|
return nsRect();
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGFilterFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGFilterElement> filter = do_QueryInterface(aContent);
|
|
|
|
NS_ASSERTION(filter, "Content is not an SVG filter");
|
|
|
|
|
|
|
|
return nsSVGFilterFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGFilterFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgFilterFrame;
|
|
|
|
}
|