2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2008-07-14 05:31:34 +04:00
|
|
|
#include "nsSVGFilterInstance.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "gfxPlatform.h"
|
2010-11-24 12:35:21 +03:00
|
|
|
#include "gfxUtils.h"
|
2017-02-09 21:24:31 +03:00
|
|
|
#include "nsSVGDisplayableFrame.h"
|
2016-05-25 07:50:02 +03:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2017-09-08 12:02:05 +03:00
|
|
|
#include "mozilla/dom/IDTracker.h"
|
2013-02-18 03:28:47 +04:00
|
|
|
#include "mozilla/dom/SVGFilterElement.h"
|
2017-08-30 16:14:46 +03:00
|
|
|
#include "SVGObserverUtils.h"
|
2014-02-06 02:04:42 +04:00
|
|
|
#include "nsSVGFilterFrame.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2013-11-27 15:25:29 +04:00
|
|
|
#include "FilterSupport.h"
|
|
|
|
#include "gfx2DGlue.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::gfx;
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
nsSVGFilterInstance::nsSVGFilterInstance(const nsStyleFilter& aFilter,
|
2016-07-23 11:16:59 +03:00
|
|
|
nsIFrame* aTargetFrame,
|
2014-09-15 14:12:50 +04:00
|
|
|
nsIContent* aTargetContent,
|
|
|
|
const UserSpaceMetrics& aMetrics,
|
2014-03-27 03:21:48 +04:00
|
|
|
const gfxRect& aTargetBBox,
|
2017-02-13 18:14:54 +03:00
|
|
|
const gfxSize& aUserSpaceToFilterSpaceScale) :
|
2014-02-24 19:22:58 +04:00
|
|
|
mFilter(aFilter),
|
2014-09-15 14:12:50 +04:00
|
|
|
mTargetContent(aTargetContent),
|
|
|
|
mMetrics(aMetrics),
|
2014-02-24 19:22:58 +04:00
|
|
|
mTargetBBox(aTargetBBox),
|
2014-03-27 03:21:48 +04:00
|
|
|
mUserSpaceToFilterSpaceScale(aUserSpaceToFilterSpaceScale),
|
2014-07-15 13:37:00 +04:00
|
|
|
mSourceAlphaAvailable(false),
|
2014-02-06 02:04:42 +04:00
|
|
|
mInitialized(false) {
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
// Get the filter frame.
|
2016-07-23 11:16:59 +03:00
|
|
|
mFilterFrame = GetFilterFrame(aTargetFrame);
|
2014-02-24 19:22:58 +04:00
|
|
|
if (!mFilterFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the filter element.
|
|
|
|
mFilterElement = mFilterFrame->GetFilterContent();
|
|
|
|
if (!mFilterElement) {
|
|
|
|
NS_NOTREACHED("filter frame should have a related element");
|
|
|
|
return;
|
|
|
|
}
|
2014-02-06 02:04:42 +04:00
|
|
|
|
|
|
|
mPrimitiveUnits =
|
2014-02-24 19:22:58 +04:00
|
|
|
mFilterFrame->GetEnumValue(SVGFilterElement::PRIMITIVEUNITS);
|
2014-02-06 02:04:42 +04:00
|
|
|
|
2017-02-14 05:32:10 +03:00
|
|
|
if (!ComputeBounds()) {
|
2014-03-12 16:42:19 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
2017-02-14 05:32:10 +03:00
|
|
|
bool
|
2014-03-12 16:42:19 +04:00
|
|
|
nsSVGFilterInstance::ComputeBounds()
|
|
|
|
{
|
2014-02-06 02:04:42 +04:00
|
|
|
// 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
|
2014-03-10 16:55:25 +04:00
|
|
|
// with units. This is a common mistake and can result in the filter region
|
|
|
|
// 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
|
2014-02-06 02:04:42 +04:00
|
|
|
// 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.
|
2014-08-01 04:37:35 +04:00
|
|
|
|
2014-03-12 16:42:19 +04:00
|
|
|
// Set the user space bounds (i.e. the filter region in user space).
|
2014-02-06 02:04:42 +04:00
|
|
|
nsSVGLength2 XYWH[4];
|
2015-02-10 01:34:50 +03:00
|
|
|
static_assert(sizeof(mFilterElement->mLengthAttributes) == sizeof(XYWH),
|
|
|
|
"XYWH size incorrect");
|
2014-08-01 04:37:35 +04:00
|
|
|
memcpy(XYWH, mFilterElement->mLengthAttributes,
|
2017-02-14 05:32:10 +03:00
|
|
|
sizeof(mFilterElement->mLengthAttributes));
|
2014-02-24 19:22:58 +04:00
|
|
|
XYWH[0] = *mFilterFrame->GetLengthValue(SVGFilterElement::ATTR_X);
|
|
|
|
XYWH[1] = *mFilterFrame->GetLengthValue(SVGFilterElement::ATTR_Y);
|
|
|
|
XYWH[2] = *mFilterFrame->GetLengthValue(SVGFilterElement::ATTR_WIDTH);
|
|
|
|
XYWH[3] = *mFilterFrame->GetLengthValue(SVGFilterElement::ATTR_HEIGHT);
|
2014-02-06 02:04:42 +04:00
|
|
|
uint16_t filterUnits =
|
2014-02-24 19:22:58 +04:00
|
|
|
mFilterFrame->GetEnumValue(SVGFilterElement::FILTERUNITS);
|
2017-02-14 05:32:10 +03:00
|
|
|
gfxRect userSpaceBounds =
|
|
|
|
nsSVGUtils::GetRelativeRect(filterUnits, XYWH, mTargetBBox, mMetrics);
|
2014-02-06 02:04:42 +04:00
|
|
|
|
2014-09-10 21:06:05 +04:00
|
|
|
// Transform the user space bounds to filter space, so we
|
2014-03-12 16:42:19 +04:00
|
|
|
// can align them with the pixel boundries of the offscreen surface.
|
2014-03-27 03:21:48 +04:00
|
|
|
// The offscreen surface has the same scale as filter space.
|
2014-09-10 21:06:05 +04:00
|
|
|
gfxRect filterSpaceBounds = UserSpaceToFilterSpace(userSpaceBounds);
|
|
|
|
filterSpaceBounds.RoundOut();
|
|
|
|
if (filterSpaceBounds.width <= 0 || filterSpaceBounds.height <= 0) {
|
2014-02-06 02:04:42 +04:00
|
|
|
// 0 disables rendering, < 0 is error. dispatch error console warning
|
|
|
|
// or error as appropriate.
|
2017-02-14 05:32:10 +03:00
|
|
|
return false;
|
2014-02-06 02:04:42 +04:00
|
|
|
}
|
|
|
|
|
2014-03-27 03:21:48 +04:00
|
|
|
// Set the filter space bounds.
|
2014-09-10 21:06:05 +04:00
|
|
|
if (!gfxUtils::GfxRectToIntRect(filterSpaceBounds, &mFilterSpaceBounds)) {
|
2014-03-12 16:42:19 +04:00
|
|
|
// The filter region is way too big if there is float -> int overflow.
|
2017-02-14 05:32:10 +03:00
|
|
|
return false;
|
2014-02-06 02:04:42 +04:00
|
|
|
}
|
|
|
|
|
2017-02-14 05:32:10 +03:00
|
|
|
return true;
|
2014-02-06 02:04:42 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
nsSVGFilterFrame*
|
2016-07-23 11:16:59 +03:00
|
|
|
nsSVGFilterInstance::GetFilterFrame(nsIFrame* aTargetFrame)
|
2014-02-24 19:22:58 +04:00
|
|
|
{
|
2014-02-24 19:22:58 +04:00
|
|
|
if (mFilter.GetType() != NS_STYLE_FILTER_URL) {
|
2014-02-24 19:22:58 +04:00
|
|
|
// The filter is not an SVG reference filter.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the target element to use as a point of reference for looking up the
|
|
|
|
// filter element.
|
2014-09-15 14:12:50 +04:00
|
|
|
if (!mTargetContent) {
|
2014-02-24 19:22:58 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-23 11:16:59 +03:00
|
|
|
// aTargetFrame can be null if this filter belongs to a
|
|
|
|
// CanvasRenderingContext2D.
|
|
|
|
nsCOMPtr<nsIURI> url = aTargetFrame
|
2017-08-30 17:58:31 +03:00
|
|
|
? SVGObserverUtils::GetFilterURI(aTargetFrame, mFilter)
|
2016-10-11 09:56:12 +03:00
|
|
|
: mFilter.GetURL()->ResolveLocalRef(mTargetContent);
|
2016-07-23 11:16:59 +03:00
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
NS_NOTREACHED("an nsStyleFilter of type URL should have a non-null URL");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
// Look up the filter element by URL.
|
2017-09-08 12:02:05 +03:00
|
|
|
IDTracker filterElement;
|
2014-02-24 19:22:58 +04:00
|
|
|
bool watch = false;
|
2014-09-15 14:12:50 +04:00
|
|
|
filterElement.Reset(mTargetContent, url, watch);
|
2014-02-24 19:22:58 +04:00
|
|
|
Element* element = filterElement.get();
|
|
|
|
if (!element) {
|
|
|
|
// The URL points to no element.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the frame of the filter element.
|
|
|
|
nsIFrame* frame = element->GetPrimaryFrame();
|
2017-04-30 18:30:08 +03:00
|
|
|
if (!frame || !frame->IsSVGFilterFrame()) {
|
2014-09-15 14:12:52 +04:00
|
|
|
// The URL points to an element that's not an SVG filter element, or to an
|
|
|
|
// element that hasn't had its frame constructed yet.
|
2014-02-24 19:22:58 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<nsSVGFilterFrame*>(frame);
|
|
|
|
}
|
|
|
|
|
2008-07-14 05:31:34 +04:00
|
|
|
float
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGFilterInstance::GetPrimitiveNumber(uint8_t aCtxType, float aValue) const
|
2008-07-14 05:31:34 +04:00
|
|
|
{
|
2011-07-23 12:44:52 +04:00
|
|
|
nsSVGLength2 val;
|
|
|
|
val.Init(aCtxType, 0xff, aValue,
|
|
|
|
nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
|
|
|
|
|
2008-07-14 05:31:34 +04:00
|
|
|
float value;
|
2013-11-27 15:25:29 +04:00
|
|
|
if (mPrimitiveUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2011-07-23 12:44:52 +04:00
|
|
|
value = nsSVGUtils::ObjectSpace(mTargetBBox, &val);
|
2008-09-11 04:24:16 +04:00
|
|
|
} else {
|
2014-09-15 14:12:50 +04:00
|
|
|
value = nsSVGUtils::UserSpace(mMetrics, &val);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2011-07-23 12:44:52 +04:00
|
|
|
switch (aCtxType) {
|
2012-09-22 23:26:05 +04:00
|
|
|
case SVGContentUtils::X:
|
2014-03-27 03:21:48 +04:00
|
|
|
return value * mUserSpaceToFilterSpaceScale.width;
|
2012-09-22 23:26:05 +04:00
|
|
|
case SVGContentUtils::Y:
|
2014-03-27 03:21:48 +04:00
|
|
|
return value * mUserSpaceToFilterSpaceScale.height;
|
2012-09-22 23:26:05 +04:00
|
|
|
case SVGContentUtils::XY:
|
2008-07-14 05:31:34 +04:00
|
|
|
default:
|
2012-09-22 23:26:05 +04:00
|
|
|
return value * SVGContentUtils::ComputeNormalizedHypotenuse(
|
2014-03-27 03:21:48 +04:00
|
|
|
mUserSpaceToFilterSpaceScale.width,
|
|
|
|
mUserSpaceToFilterSpaceScale.height);
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
Point3D
|
|
|
|
nsSVGFilterInstance::ConvertLocation(const Point3D& aPoint) const
|
2010-02-08 12:51:19 +03:00
|
|
|
{
|
2011-09-14 18:48:32 +04:00
|
|
|
nsSVGLength2 val[4];
|
2013-11-27 15:25:29 +04:00
|
|
|
val[0].Init(SVGContentUtils::X, 0xff, aPoint.x,
|
2011-09-14 18:48:32 +04:00
|
|
|
nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
|
2013-11-27 15:25:29 +04:00
|
|
|
val[1].Init(SVGContentUtils::Y, 0xff, aPoint.y,
|
2011-09-14 18:48:32 +04:00
|
|
|
nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
|
|
|
|
// Dummy width/height values
|
2012-09-22 23:26:05 +04:00
|
|
|
val[2].Init(SVGContentUtils::X, 0xff, 0,
|
2011-09-14 18:48:32 +04:00
|
|
|
nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
|
2012-09-22 23:26:05 +04:00
|
|
|
val[3].Init(SVGContentUtils::Y, 0xff, 0,
|
2011-09-14 18:48:32 +04:00
|
|
|
nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER);
|
|
|
|
|
|
|
|
gfxRect feArea = nsSVGUtils::GetRelativeRect(mPrimitiveUnits,
|
2014-09-15 14:12:50 +04:00
|
|
|
val, mTargetBBox, mMetrics);
|
2013-11-27 15:25:29 +04:00
|
|
|
gfxRect r = UserSpaceToFilterSpace(feArea);
|
|
|
|
return Point3D(r.x, r.y, GetPrimitiveNumber(SVGContentUtils::XY, aPoint.z));
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxRect
|
2014-03-12 16:42:19 +04:00
|
|
|
nsSVGFilterInstance::UserSpaceToFilterSpace(const gfxRect& aUserSpaceRect) const
|
|
|
|
{
|
2014-03-27 03:21:48 +04:00
|
|
|
gfxRect filterSpaceRect = aUserSpaceRect;
|
|
|
|
filterSpaceRect.Scale(mUserSpaceToFilterSpaceScale.width,
|
|
|
|
mUserSpaceToFilterSpaceScale.height);
|
|
|
|
return filterSpaceRect;
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
IntRect
|
|
|
|
nsSVGFilterInstance::ComputeFilterPrimitiveSubregion(nsSVGFE* aFilterElement,
|
2014-02-24 19:22:58 +04:00
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
2013-11-27 15:25:29 +04:00
|
|
|
const nsTArray<int32_t>& aInputIndices)
|
2008-07-14 05:31:34 +04:00
|
|
|
{
|
2013-11-27 15:25:29 +04:00
|
|
|
nsSVGFE* fE = aFilterElement;
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
IntRect defaultFilterSubregion(0,0,0,0);
|
2008-07-14 05:31:34 +04:00
|
|
|
if (fE->SubregionIsUnionOfRegions()) {
|
2013-11-27 15:25:29 +04:00
|
|
|
for (uint32_t i = 0; i < aInputIndices.Length(); ++i) {
|
|
|
|
int32_t inputIndex = aInputIndices[i];
|
2014-06-25 22:14:00 +04:00
|
|
|
bool isStandardInput = inputIndex < 0 || inputIndex == mSourceGraphicIndex;
|
|
|
|
IntRect inputSubregion = isStandardInput ?
|
2015-04-21 18:22:30 +03:00
|
|
|
mFilterSpaceBounds :
|
2014-06-25 22:14:00 +04:00
|
|
|
aPrimitiveDescrs[inputIndex].PrimitiveSubregion();
|
2013-11-27 15:25:29 +04:00
|
|
|
|
|
|
|
defaultFilterSubregion = defaultFilterSubregion.Union(inputSubregion);
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-21 18:22:30 +03:00
|
|
|
defaultFilterSubregion = mFilterSpaceBounds;
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
gfxRect feArea = nsSVGUtils::GetRelativeRect(mPrimitiveUnits,
|
2014-09-15 14:12:50 +04:00
|
|
|
&fE->mLengthAttributes[nsSVGFE::ATTR_X], mTargetBBox, mMetrics);
|
2013-11-27 15:25:29 +04:00
|
|
|
Rect region = ToRect(UserSpaceToFilterSpace(feArea));
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2013-03-07 11:17:00 +04:00
|
|
|
if (!fE->mLengthAttributes[nsSVGFE::ATTR_X].IsExplicitlySet())
|
2011-04-19 07:07:21 +04:00
|
|
|
region.x = defaultFilterSubregion.X();
|
2013-03-07 11:17:00 +04:00
|
|
|
if (!fE->mLengthAttributes[nsSVGFE::ATTR_Y].IsExplicitlySet())
|
2011-04-19 07:07:21 +04:00
|
|
|
region.y = defaultFilterSubregion.Y();
|
2013-03-07 11:17:00 +04:00
|
|
|
if (!fE->mLengthAttributes[nsSVGFE::ATTR_WIDTH].IsExplicitlySet())
|
2011-04-19 07:07:21 +04:00
|
|
|
region.width = defaultFilterSubregion.Width();
|
2013-03-07 11:17:00 +04:00
|
|
|
if (!fE->mLengthAttributes[nsSVGFE::ATTR_HEIGHT].IsExplicitlySet())
|
2011-04-19 07:07:21 +04:00
|
|
|
region.height = defaultFilterSubregion.Height();
|
2008-07-14 05:31:34 +04:00
|
|
|
|
|
|
|
// We currently require filter primitive subregions to be pixel-aligned.
|
|
|
|
// Following the spec, any pixel partially in the region is included
|
|
|
|
// in the region.
|
|
|
|
region.RoundOut();
|
2014-09-12 21:44:14 +04:00
|
|
|
return RoundedToInt(region);
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
|
2014-01-08 13:30:03 +04:00
|
|
|
void
|
2014-02-24 19:22:58 +04:00
|
|
|
nsSVGFilterInstance::GetInputsAreTainted(const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
|
|
|
const nsTArray<int32_t>& aInputIndices,
|
2016-05-25 07:50:02 +03:00
|
|
|
bool aFilterInputIsTainted,
|
2014-01-08 13:30:03 +04:00
|
|
|
nsTArray<bool>& aOutInputsAreTainted)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < aInputIndices.Length(); i++) {
|
|
|
|
int32_t inputIndex = aInputIndices[i];
|
|
|
|
if (inputIndex < 0) {
|
2016-05-25 07:50:02 +03:00
|
|
|
aOutInputsAreTainted.AppendElement(aFilterInputIsTainted);
|
2014-01-08 13:30:03 +04:00
|
|
|
} else {
|
2014-02-24 19:22:58 +04:00
|
|
|
aOutInputsAreTainted.AppendElement(aPrimitiveDescrs[inputIndex].IsTainted());
|
2014-01-08 13:30:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-01 01:40:00 +04:00
|
|
|
static int32_t
|
|
|
|
GetLastResultIndex(const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs)
|
|
|
|
{
|
|
|
|
uint32_t numPrimitiveDescrs = aPrimitiveDescrs.Length();
|
|
|
|
return !numPrimitiveDescrs ?
|
|
|
|
FilterPrimitiveDescription::kPrimitiveIndexSourceGraphic :
|
|
|
|
numPrimitiveDescrs - 1;
|
|
|
|
}
|
|
|
|
|
2014-07-15 13:37:00 +04:00
|
|
|
int32_t
|
|
|
|
nsSVGFilterInstance::GetOrCreateSourceAlphaIndex(nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs)
|
|
|
|
{
|
|
|
|
// If the SourceAlpha index has already been determined or created for this
|
|
|
|
// SVG filter, just return it.
|
|
|
|
if (mSourceAlphaAvailable)
|
|
|
|
return mSourceAlphaIndex;
|
|
|
|
|
|
|
|
// If this is the first filter in the chain, we can just use the
|
|
|
|
// kPrimitiveIndexSourceAlpha keyword to refer to the SourceAlpha of the
|
|
|
|
// original image.
|
|
|
|
if (mSourceGraphicIndex < 0) {
|
|
|
|
mSourceAlphaIndex = FilterPrimitiveDescription::kPrimitiveIndexSourceAlpha;
|
|
|
|
mSourceAlphaAvailable = true;
|
|
|
|
return mSourceAlphaIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, create a primitive description to turn the previous filter's
|
|
|
|
// output into a SourceAlpha input.
|
|
|
|
FilterPrimitiveDescription descr(PrimitiveType::ToAlpha);
|
|
|
|
descr.SetInputPrimitive(0, mSourceGraphicIndex);
|
|
|
|
|
|
|
|
const FilterPrimitiveDescription& sourcePrimitiveDescr =
|
|
|
|
aPrimitiveDescrs[mSourceGraphicIndex];
|
|
|
|
descr.SetPrimitiveSubregion(sourcePrimitiveDescr.PrimitiveSubregion());
|
|
|
|
descr.SetIsTainted(sourcePrimitiveDescr.IsTainted());
|
|
|
|
|
|
|
|
ColorSpace colorSpace = sourcePrimitiveDescr.OutputColorSpace();
|
|
|
|
descr.SetInputColorSpace(0, colorSpace);
|
|
|
|
descr.SetOutputColorSpace(colorSpace);
|
|
|
|
|
|
|
|
aPrimitiveDescrs.AppendElement(descr);
|
|
|
|
mSourceAlphaIndex = aPrimitiveDescrs.Length() - 1;
|
|
|
|
mSourceAlphaAvailable = true;
|
|
|
|
return mSourceAlphaIndex;
|
|
|
|
}
|
|
|
|
|
2014-03-01 01:40:00 +04:00
|
|
|
nsresult
|
|
|
|
nsSVGFilterInstance::GetSourceIndices(nsSVGFE* aPrimitiveElement,
|
2014-07-15 13:37:00 +04:00
|
|
|
nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
2014-03-01 01:40:00 +04:00
|
|
|
const nsDataHashtable<nsStringHashKey, int32_t>& aImageTable,
|
|
|
|
nsTArray<int32_t>& aSourceIndices)
|
2008-07-14 05:31:34 +04:00
|
|
|
{
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsSVGStringInfo,2> sources;
|
2014-03-01 01:40:00 +04:00
|
|
|
aPrimitiveElement->GetSourceImageNames(sources);
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
for (uint32_t j = 0; j < sources.Length(); j++) {
|
|
|
|
nsAutoString str;
|
|
|
|
sources[j].mString->GetAnimValue(str, sources[j].mElement);
|
|
|
|
|
|
|
|
int32_t sourceIndex = 0;
|
|
|
|
if (str.EqualsLiteral("SourceGraphic")) {
|
2014-03-01 01:40:00 +04:00
|
|
|
sourceIndex = mSourceGraphicIndex;
|
2013-11-27 15:25:29 +04:00
|
|
|
} else if (str.EqualsLiteral("SourceAlpha")) {
|
2014-07-15 13:37:00 +04:00
|
|
|
sourceIndex = GetOrCreateSourceAlphaIndex(aPrimitiveDescrs);
|
2013-11-27 15:25:29 +04:00
|
|
|
} else if (str.EqualsLiteral("FillPaint")) {
|
|
|
|
sourceIndex = FilterPrimitiveDescription::kPrimitiveIndexFillPaint;
|
|
|
|
} else if (str.EqualsLiteral("StrokePaint")) {
|
|
|
|
sourceIndex = FilterPrimitiveDescription::kPrimitiveIndexStrokePaint;
|
|
|
|
} else if (str.EqualsLiteral("BackgroundImage") ||
|
|
|
|
str.EqualsLiteral("BackgroundAlpha")) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
} else if (str.EqualsLiteral("")) {
|
2014-03-01 01:40:00 +04:00
|
|
|
sourceIndex = GetLastResultIndex(aPrimitiveDescrs);
|
2013-11-27 15:25:29 +04:00
|
|
|
} else {
|
|
|
|
bool inputExists = aImageTable.Get(str, &sourceIndex);
|
|
|
|
if (!inputExists)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
aSourceIndices.AppendElement(sourceIndex);
|
|
|
|
}
|
2008-07-14 05:31:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-24 19:22:58 +04:00
|
|
|
nsSVGFilterInstance::BuildPrimitives(nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
2016-10-19 18:32:02 +03:00
|
|
|
nsTArray<RefPtr<SourceSurface>>& aInputImages,
|
|
|
|
bool aInputIsTainted)
|
2008-07-14 05:31:34 +04:00
|
|
|
{
|
2014-03-01 01:40:00 +04:00
|
|
|
mSourceGraphicIndex = GetLastResultIndex(aPrimitiveDescrs);
|
|
|
|
|
2014-07-29 20:48:16 +04:00
|
|
|
// Clip previous filter's output to this filter's filter region.
|
|
|
|
if (mSourceGraphicIndex >= 0) {
|
|
|
|
FilterPrimitiveDescription& sourceDescr = aPrimitiveDescrs[mSourceGraphicIndex];
|
2015-04-21 18:22:30 +03:00
|
|
|
sourceDescr.SetPrimitiveSubregion(sourceDescr.PrimitiveSubregion().Intersect(mFilterSpaceBounds));
|
2014-07-29 20:48:16 +04:00
|
|
|
}
|
|
|
|
|
2014-03-01 01:40:00 +04:00
|
|
|
// Get the filter primitive elements.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<nsSVGFE> > primitives;
|
2012-03-29 12:41:37 +04:00
|
|
|
for (nsIContent* child = mFilterElement->nsINode::GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSVGFE> primitive;
|
2008-07-14 05:31:34 +04:00
|
|
|
CallQueryInterface(child, (nsSVGFE**)getter_AddRefs(primitive));
|
2013-11-27 15:25:29 +04:00
|
|
|
if (primitive) {
|
|
|
|
primitives.AppendElement(primitive);
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
2013-11-27 15:25:29 +04:00
|
|
|
}
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
// Maps source image name to source index.
|
2014-08-06 17:31:21 +04:00
|
|
|
nsDataHashtable<nsStringHashKey, int32_t> imageTable(8);
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2014-01-08 13:30:03 +04:00
|
|
|
// The principal that we check principals of any loaded images against.
|
2014-09-15 14:12:50 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = mTargetContent->NodePrincipal();
|
2014-01-08 13:30:03 +04:00
|
|
|
|
2014-03-01 01:40:00 +04:00
|
|
|
for (uint32_t primitiveElementIndex = 0;
|
|
|
|
primitiveElementIndex < primitives.Length();
|
|
|
|
++primitiveElementIndex) {
|
|
|
|
nsSVGFE* filter = primitives[primitiveElementIndex];
|
2009-01-22 03:56:51 +03:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<int32_t,2> sourceIndices;
|
2014-03-01 01:40:00 +04:00
|
|
|
nsresult rv = GetSourceIndices(filter, aPrimitiveDescrs, imageTable, sourceIndices);
|
2013-11-27 15:25:29 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
IntRect primitiveSubregion =
|
2014-02-24 19:22:58 +04:00
|
|
|
ComputeFilterPrimitiveSubregion(filter, aPrimitiveDescrs, sourceIndices);
|
2008-07-14 05:31:34 +04:00
|
|
|
|
2014-01-08 13:30:03 +04:00
|
|
|
nsTArray<bool> sourcesAreTainted;
|
2016-10-19 18:32:02 +03:00
|
|
|
GetInputsAreTainted(aPrimitiveDescrs, sourceIndices, aInputIsTainted, sourcesAreTainted);
|
2014-01-08 13:30:03 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
FilterPrimitiveDescription descr =
|
2014-02-24 19:22:58 +04:00
|
|
|
filter->GetPrimitiveDescription(this, primitiveSubregion, sourcesAreTainted, aInputImages);
|
2013-11-27 15:25:29 +04:00
|
|
|
|
2014-01-08 13:30:03 +04:00
|
|
|
descr.SetIsTainted(filter->OutputIsTainted(sourcesAreTainted, principal));
|
2015-04-21 18:22:30 +03:00
|
|
|
descr.SetFilterSpaceBounds(mFilterSpaceBounds);
|
2014-09-12 21:44:14 +04:00
|
|
|
descr.SetPrimitiveSubregion(primitiveSubregion.Intersect(descr.FilterSpaceBounds()));
|
2013-11-27 15:25:29 +04:00
|
|
|
|
2014-03-01 01:40:00 +04:00
|
|
|
for (uint32_t i = 0; i < sourceIndices.Length(); i++) {
|
|
|
|
int32_t inputIndex = sourceIndices[i];
|
|
|
|
descr.SetInputPrimitive(i, inputIndex);
|
2014-03-20 06:12:43 +04:00
|
|
|
|
|
|
|
ColorSpace inputColorSpace = inputIndex >= 0
|
|
|
|
? aPrimitiveDescrs[inputIndex].OutputColorSpace()
|
|
|
|
: ColorSpace(ColorSpace::SRGB);
|
|
|
|
|
2014-03-01 01:40:00 +04:00
|
|
|
ColorSpace desiredInputColorSpace = filter->GetInputColorSpace(i, inputColorSpace);
|
|
|
|
descr.SetInputColorSpace(i, desiredInputColorSpace);
|
|
|
|
if (i == 0) {
|
2013-11-27 15:25:29 +04:00
|
|
|
// the output color space is whatever in1 is if there is an in1
|
|
|
|
descr.SetOutputColorSpace(desiredInputColorSpace);
|
|
|
|
}
|
2008-07-14 05:31:34 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
if (sourceIndices.Length() == 0) {
|
|
|
|
descr.SetOutputColorSpace(filter->GetOutputColorSpace());
|
2008-07-23 06:15:27 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
aPrimitiveDescrs.AppendElement(descr);
|
2014-03-01 01:40:00 +04:00
|
|
|
uint32_t primitiveDescrIndex = aPrimitiveDescrs.Length() - 1;
|
2013-11-27 15:25:29 +04:00
|
|
|
|
|
|
|
nsAutoString str;
|
|
|
|
filter->GetResultImageName().GetAnimValue(str, filter);
|
2014-03-01 01:40:00 +04:00
|
|
|
imageTable.Put(str, primitiveDescrIndex);
|
2008-07-23 06:15:27 +04:00
|
|
|
}
|
2013-11-27 15:25:29 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-07-23 06:15:27 +04:00
|
|
|
}
|