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"
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_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;
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
JSObject*
|
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
|
|
|
SVGFETurbulenceElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
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
|
|
|
return SVGFETurbulenceElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::NumberInfo SVGFETurbulenceElement::sNumberInfo[1] =
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::seed, 0, false }
|
|
|
|
};
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
nsSVGElement::NumberPairInfo SVGFETurbulenceElement::sNumberPairInfo[1] =
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::baseFrequency, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
nsSVGElement::IntegerInfo SVGFETurbulenceElement::sIntegerInfo[1] =
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::numOctaves, 1 }
|
|
|
|
};
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
nsSVGEnumMapping SVGFETurbulenceElement::sTypeMap[] = {
|
2013-03-27 03:43:33 +04:00
|
|
|
{&nsGkAtoms::fractalNoise,
|
2013-03-27 03:43:33 +04:00
|
|
|
SVG_TURBULENCE_TYPE_FRACTALNOISE},
|
2013-03-27 03:43:33 +04:00
|
|
|
{&nsGkAtoms::turbulence,
|
2013-03-27 03:43:33 +04:00
|
|
|
SVG_TURBULENCE_TYPE_TURBULENCE},
|
2013-03-27 03:43:33 +04:00
|
|
|
{nullptr, 0}
|
|
|
|
};
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
nsSVGEnumMapping SVGFETurbulenceElement::sStitchTilesMap[] = {
|
2013-03-27 03:43:33 +04:00
|
|
|
{&nsGkAtoms::stitch,
|
2013-03-27 03:43:33 +04:00
|
|
|
SVG_STITCHTYPE_STITCH},
|
2013-03-27 03:43:33 +04:00
|
|
|
{&nsGkAtoms::noStitch,
|
2013-03-27 03:43:33 +04:00
|
|
|
SVG_STITCHTYPE_NOSTITCH},
|
2013-03-27 03:43:33 +04:00
|
|
|
{nullptr, 0}
|
|
|
|
};
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
nsSVGElement::EnumInfo SVGFETurbulenceElement::sEnumInfo[2] =
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::type,
|
|
|
|
sTypeMap,
|
2013-03-27 03:43:33 +04:00
|
|
|
SVG_TURBULENCE_TYPE_TURBULENCE
|
2013-03-27 03:43:33 +04:00
|
|
|
},
|
|
|
|
{ &nsGkAtoms::stitchTiles,
|
|
|
|
sStitchTilesMap,
|
2013-03-27 03:43:33 +04:00
|
|
|
SVG_STITCHTYPE_NOSTITCH
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
nsSVGElement::StringInfo SVGFETurbulenceElement::sStringInfo[1] =
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::result, kNameSpaceID_None, true }
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
2013-03-27 03:43:33 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFETurbulenceElement)
|
2013-03-27 03:43:33 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-07-01 11:03:04 +04:00
|
|
|
already_AddRefed<SVGAnimatedNumber>
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::BaseFrequencyX()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
2013-03-27 03:43:33 +04:00
|
|
|
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:03:04 +04:00
|
|
|
already_AddRefed<SVGAnimatedNumber>
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::BaseFrequencyY()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
2013-03-27 03:43:33 +04:00
|
|
|
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:02:56 +04:00
|
|
|
already_AddRefed<SVGAnimatedInteger>
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::NumOctaves()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
2013-03-27 03:43:33 +04:00
|
|
|
return mIntegerAttributes[OCTAVES].ToDOMAnimatedInteger(this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:03:04 +04:00
|
|
|
already_AddRefed<SVGAnimatedNumber>
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::Seed()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
2013-03-27 03:43:33 +04:00
|
|
|
return mNumberAttributes[SEED].ToDOMAnimatedNumber(this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:02:46 +04:00
|
|
|
already_AddRefed<SVGAnimatedEnumeration>
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::StitchTiles()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
2013-03-27 03:43:33 +04:00
|
|
|
return mEnumAttributes[STITCHTILES].ToDOMAnimatedEnum(this);
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:02:46 +04:00
|
|
|
already_AddRefed<SVGAnimatedEnumeration>
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::Type()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
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)
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
float fX = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eFirst);
|
|
|
|
float fY = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eSecond);
|
|
|
|
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();
|
|
|
|
|
2013-11-27 15:25:29 +04: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) {
|
|
|
|
return FilterPrimitiveDescription(PrimitiveType::Empty);
|
|
|
|
}
|
|
|
|
FilterPrimitiveDescription descr(PrimitiveType::Flood);
|
|
|
|
descr.Attributes().Set(eFloodColor, Color(0.5, 0.5, 0.5, 0.5));
|
|
|
|
return descr;
|
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.
|
|
|
|
gfxRect firstPeriodInUserSpace(0, 0, 1 / fX, 1 / fY);
|
2014-03-12 16:42:19 +04:00
|
|
|
gfxRect firstPeriodInFilterSpace = aInstance->UserSpaceToFilterSpace(firstPeriodInUserSpace);
|
2013-11-27 15:25:29 +04:00
|
|
|
Size frequencyInFilterSpace(1 / firstPeriodInFilterSpace.width,
|
|
|
|
1 / firstPeriodInFilterSpace.height);
|
|
|
|
gfxPoint offset = firstPeriodInFilterSpace.TopLeft();
|
|
|
|
|
2014-03-20 06:12:43 +04:00
|
|
|
FilterPrimitiveDescription descr(PrimitiveType::Turbulence);
|
2016-07-26 17:48:30 +03:00
|
|
|
descr.Attributes().Set(eTurbulenceOffset, IntPoint::Truncate(offset.x, offset.y));
|
2013-11-27 15:25:29 +04:00
|
|
|
descr.Attributes().Set(eTurbulenceBaseFrequency, frequencyInFilterSpace);
|
|
|
|
descr.Attributes().Set(eTurbulenceSeed, seed);
|
|
|
|
descr.Attributes().Set(eTurbulenceNumOctaves, octaves);
|
|
|
|
descr.Attributes().Set(eTurbulenceStitchable, stitch == SVG_STITCHTYPE_STITCH);
|
|
|
|
descr.Attributes().Set(eTurbulenceType, type);
|
|
|
|
return descr;
|
2013-03-27 03:43:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::AttributeAffectsRendering(int32_t aNameSpaceID,
|
2013-03-27 03:43:33 +04:00
|
|
|
nsIAtom* 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
nsSVGElement::NumberAttributesInfo
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::GetNumberInfo()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
|
|
|
|
ArrayLength(sNumberInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::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));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::IntegerAttributesInfo
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::GetIntegerInfo()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
|
|
|
|
ArrayLength(sIntegerInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::EnumAttributesInfo
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::GetEnumInfo()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
|
|
|
|
ArrayLength(sEnumInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::StringAttributesInfo
|
2013-03-27 03:43:33 +04:00
|
|
|
SVGFETurbulenceElement::GetStringInfo()
|
2013-03-27 03:43:33 +04:00
|
|
|
{
|
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
|
|
|
ArrayLength(sStringInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|