2015-05-03 22:32:37 +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: */
|
2013-03-27 03:43:33 +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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/SVGFETurbulenceElement.h"
|
2013-03-27 03:43:33 +04:00
|
|
|
#include "mozilla/dom/SVGFETurbulenceElementBinding.h"
|
|
|
|
#include "nsSVGFilterInstance.h"
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
|
2018-12-21 14:43:29 +03:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(FETurbulence)
|
2013-03-27 03:43:33 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
// Stitch Options
|
|
|
|
static const unsigned short SVG_STITCHTYPE_STITCH = 1;
|
|
|
|
static const unsigned short SVG_STITCHTYPE_NOSTITCH = 2;
|
|
|
|
|
2013-06-24 13:42:22 +04:00
|
|
|
static const int32_t MAX_OCTAVES = 10;
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* SVGFETurbulenceElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGFETurbulenceElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberInfo SVGFETurbulenceElement::sNumberInfo[1] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::seed, 0, false}};
|
2013-03-27 03:43:33 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberPairInfo SVGFETurbulenceElement::sNumberPairInfo[1] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::baseFrequency, 0, 0}};
|
2013-03-27 03:43:33 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::IntegerInfo SVGFETurbulenceElement::sIntegerInfo[1] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::numOctaves, 1}};
|
2013-03-27 03:43:33 +04:00
|
|
|
|
2019-01-02 21:24:11 +03:00
|
|
|
SVGEnumMapping SVGFETurbulenceElement::sTypeMap[] = {
|
2013-03-27 03:43:33 +04:00
|
|
|
{nsGkAtoms::fractalNoise, SVG_TURBULENCE_TYPE_FRACTALNOISE},
|
|
|
|
{nsGkAtoms::turbulence, SVG_TURBULENCE_TYPE_TURBULENCE},
|
2013-03-27 03:43:33 +04:00
|
|
|
{nullptr, 0}};
|
|
|
|
|
2019-01-02 21:24:11 +03:00
|
|
|
SVGEnumMapping SVGFETurbulenceElement::sStitchTilesMap[] = {
|
2013-03-27 03:43:33 +04:00
|
|
|
{nsGkAtoms::stitch, SVG_STITCHTYPE_STITCH},
|
|
|
|
{nsGkAtoms::noStitch, SVG_STITCHTYPE_NOSTITCH},
|
2013-03-27 03:43:33 +04:00
|
|
|
{nullptr, 0}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::EnumInfo SVGFETurbulenceElement::sEnumInfo[2] = {
|
2013-03-27 03:43:33 +04:00
|
|
|
{nsGkAtoms::type, sTypeMap, SVG_TURBULENCE_TYPE_TURBULENCE},
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::stitchTiles, sStitchTilesMap, SVG_STITCHTYPE_NOSTITCH}};
|
2013-03-27 03:43:33 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::StringInfo SVGFETurbulenceElement::sStringInfo[1] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::result, kNameSpaceID_None, true}};
|
2013-03-27 03:43:33 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 05:58:49 +03:00
|
|
|
// nsINode methods
|
2013-03-27 03:43:33 +04:00
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFETurbulenceElement)
|
2013-03-27 03:43:33 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber>
|
|
|
|
SVGFETurbulenceElement::BaseFrequencyX() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedNumberPair::eFirst, this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber>
|
|
|
|
SVGFETurbulenceElement::BaseFrequencyY() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedNumberPair::eSecond, this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedInteger> SVGFETurbulenceElement::NumOctaves() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return mIntegerAttributes[OCTAVES].ToDOMAnimatedInteger(this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber> SVGFETurbulenceElement::Seed() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return mNumberAttributes[SEED].ToDOMAnimatedNumber(this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedEnumeration>
|
|
|
|
SVGFETurbulenceElement::StitchTiles() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return mEnumAttributes[STITCHTILES].ToDOMAnimatedEnum(this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedEnumeration> SVGFETurbulenceElement::Type() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return mEnumAttributes[TYPE].ToDOMAnimatedEnum(this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
FilterPrimitiveDescription SVGFETurbulenceElement::GetPrimitiveDescription(
|
|
|
|
nsSVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
|
2014-01-08 13:30:03 +04:00
|
|
|
const nsTArray<bool>& aInputsAreTainted,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<SourceSurface>>& aInputImages) {
|
2019-04-04 20:40:56 +03:00
|
|
|
float fX = mNumberPairAttributes[BASE_FREQ].GetAnimValue(
|
|
|
|
SVGAnimatedNumberPair::eFirst);
|
|
|
|
float fY = mNumberPairAttributes[BASE_FREQ].GetAnimValue(
|
|
|
|
SVGAnimatedNumberPair::eSecond);
|
2013-03-27 03:43:33 +04:00
|
|
|
float seed = mNumberAttributes[OCTAVES].GetAnimValue();
|
2013-11-27 15:25:29 +04:00
|
|
|
uint32_t octaves =
|
|
|
|
clamped(mIntegerAttributes[OCTAVES].GetAnimValue(), 0, MAX_OCTAVES);
|
|
|
|
uint32_t type = mEnumAttributes[TYPE].GetAnimValue();
|
2013-03-27 03:43:33 +04:00
|
|
|
uint16_t stitch = mEnumAttributes[STITCHTILES].GetAnimValue();
|
|
|
|
|
2017-09-16 19:04:29 +03:00
|
|
|
if (fX == 0 && fY == 0) {
|
2017-03-01 18:03:15 +03:00
|
|
|
// A base frequency of zero results in transparent black for
|
|
|
|
// type="turbulence" and in 50% alpha 50% gray for type="fractalNoise".
|
|
|
|
if (type == SVG_TURBULENCE_TYPE_TURBULENCE) {
|
2018-09-19 20:18:44 +03:00
|
|
|
return FilterPrimitiveDescription();
|
2017-03-01 18:03:15 +03:00
|
|
|
}
|
2018-09-19 20:18:16 +03:00
|
|
|
FloodAttributes atts;
|
2020-03-09 17:16:17 +03:00
|
|
|
atts.mColor = sRGBColor(0.5, 0.5, 0.5, 0.5);
|
2018-09-19 20:18:44 +03:00
|
|
|
return FilterPrimitiveDescription(AsVariant(std::move(atts)));
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
// We interpret the base frequency as relative to user space units. In other
|
|
|
|
// words, we consider one turbulence base period to be 1 / fX user space
|
|
|
|
// units wide and 1 / fY user space units high. We do not scale the frequency
|
|
|
|
// depending on the filter primitive region.
|
2017-10-16 22:14:22 +03:00
|
|
|
// We now convert the frequency from user space to filter space.
|
|
|
|
// If a frequency in user space units is zero, then it will also be zero in
|
|
|
|
// filter space. During the conversion we use a dummy period length of 1
|
|
|
|
// for those frequencies but then ignore the converted length and use 0
|
|
|
|
// for the converted frequency. This avoids division by zero.
|
|
|
|
gfxRect firstPeriodInUserSpace(0, 0, fX == 0 ? 1 : (1 / fX),
|
|
|
|
fY == 0 ? 1 : (1 / fY));
|
2014-03-12 16:42:19 +04:00
|
|
|
gfxRect firstPeriodInFilterSpace =
|
|
|
|
aInstance->UserSpaceToFilterSpace(firstPeriodInUserSpace);
|
2018-02-19 23:15:23 +03:00
|
|
|
Size frequencyInFilterSpace(
|
|
|
|
fX == 0 ? 0 : (1 / firstPeriodInFilterSpace.width),
|
|
|
|
fY == 0 ? 0 : (1 / firstPeriodInFilterSpace.height));
|
2013-11-27 15:25:29 +04:00
|
|
|
gfxPoint offset = firstPeriodInFilterSpace.TopLeft();
|
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
TurbulenceAttributes atts;
|
|
|
|
atts.mOffset = IntPoint::Truncate(offset.x, offset.y);
|
|
|
|
atts.mBaseFrequency = frequencyInFilterSpace;
|
|
|
|
atts.mSeed = seed;
|
|
|
|
atts.mOctaves = octaves;
|
|
|
|
atts.mStitchable = stitch == SVG_STITCHTYPE_STITCH;
|
|
|
|
atts.mType = type;
|
2018-09-19 20:18:44 +03:00
|
|
|
return FilterPrimitiveDescription(AsVariant(std::move(atts)));
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
bool SVGFETurbulenceElement::AttributeAffectsRendering(
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t aNameSpaceID, nsAtom* aAttribute) const {
|
2013-03-27 03:43:33 +04:00
|
|
|
return SVGFETurbulenceElementBase::AttributeAffectsRendering(aNameSpaceID,
|
|
|
|
aAttribute) ||
|
2013-03-27 03:43:33 +04:00
|
|
|
(aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::seed ||
|
|
|
|
aAttribute == nsGkAtoms::baseFrequency ||
|
|
|
|
aAttribute == nsGkAtoms::numOctaves ||
|
|
|
|
aAttribute == nsGkAtoms::type ||
|
|
|
|
aAttribute == nsGkAtoms::stitchTiles));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement methods
|
2013-03-27 03:43:33 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberAttributesInfo SVGFETurbulenceElement::GetNumberInfo() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
|
|
|
|
ArrayLength(sNumberInfo));
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberPairAttributesInfo
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::GetNumberPairInfo() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
|
|
|
|
ArrayLength(sNumberPairInfo));
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::IntegerAttributesInfo SVGFETurbulenceElement::GetIntegerInfo() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
|
|
|
|
ArrayLength(sIntegerInfo));
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::EnumAttributesInfo SVGFETurbulenceElement::GetEnumInfo() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::StringAttributesInfo SVGFETurbulenceElement::GetStringInfo() {
|
2013-03-27 03:43:33 +04:00
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
|
|
|
ArrayLength(sStringInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|