2015-05-03 12:32:37 -07: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-26 16:43:33 -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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/SVGFETurbulenceElement.h"
|
2013-03-26 16:43:33 -07:00
|
|
|
#include "mozilla/dom/SVGFETurbulenceElementBinding.h"
|
|
|
|
#include "nsSVGFilterInstance.h"
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FETurbulence)
|
2013-03-26 16:43:33 -07:00
|
|
|
|
2013-11-27 03:25:29 -08:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
// Stitch Options
|
|
|
|
static const unsigned short SVG_STITCHTYPE_STITCH = 1;
|
|
|
|
static const unsigned short SVG_STITCHTYPE_NOSTITCH = 2;
|
|
|
|
|
2013-06-24 02:42:22 -07:00
|
|
|
static const int32_t MAX_OCTAVES = 10;
|
|
|
|
|
2013-03-26 16:43:33 -07: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 07:13:33 -07:00
|
|
|
SVGFETurbulenceElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-26 16:43:33 -07: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 07:13:33 -07:00
|
|
|
return SVGFETurbulenceElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::NumberInfo SVGFETurbulenceElement::sNumberInfo[1] =
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::seed, 0, false }
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
nsSVGElement::NumberPairInfo SVGFETurbulenceElement::sNumberPairInfo[1] =
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::baseFrequency, 0, 0 }
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
nsSVGElement::IntegerInfo SVGFETurbulenceElement::sIntegerInfo[1] =
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::numOctaves, 1 }
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
nsSVGEnumMapping SVGFETurbulenceElement::sTypeMap[] = {
|
2013-03-26 16:43:33 -07:00
|
|
|
{&nsGkAtoms::fractalNoise,
|
2013-03-26 16:43:33 -07:00
|
|
|
SVG_TURBULENCE_TYPE_FRACTALNOISE},
|
2013-03-26 16:43:33 -07:00
|
|
|
{&nsGkAtoms::turbulence,
|
2013-03-26 16:43:33 -07:00
|
|
|
SVG_TURBULENCE_TYPE_TURBULENCE},
|
2013-03-26 16:43:33 -07:00
|
|
|
{nullptr, 0}
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
nsSVGEnumMapping SVGFETurbulenceElement::sStitchTilesMap[] = {
|
2013-03-26 16:43:33 -07:00
|
|
|
{&nsGkAtoms::stitch,
|
2013-03-26 16:43:33 -07:00
|
|
|
SVG_STITCHTYPE_STITCH},
|
2013-03-26 16:43:33 -07:00
|
|
|
{&nsGkAtoms::noStitch,
|
2013-03-26 16:43:33 -07:00
|
|
|
SVG_STITCHTYPE_NOSTITCH},
|
2013-03-26 16:43:33 -07:00
|
|
|
{nullptr, 0}
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
nsSVGElement::EnumInfo SVGFETurbulenceElement::sEnumInfo[2] =
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::type,
|
|
|
|
sTypeMap,
|
2013-03-26 16:43:33 -07:00
|
|
|
SVG_TURBULENCE_TYPE_TURBULENCE
|
2013-03-26 16:43:33 -07:00
|
|
|
},
|
|
|
|
{ &nsGkAtoms::stitchTiles,
|
|
|
|
sStitchTilesMap,
|
2013-03-26 16:43:33 -07:00
|
|
|
SVG_STITCHTYPE_NOSTITCH
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
nsSVGElement::StringInfo SVGFETurbulenceElement::sStringInfo[1] =
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
{ &nsGkAtoms::result, kNameSpaceID_None, true }
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
2013-03-26 16:43:33 -07:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFETurbulenceElement)
|
2013-03-26 16:43:33 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-07-01 00:03:04 -07:00
|
|
|
already_AddRefed<SVGAnimatedNumber>
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::BaseFrequencyX()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
2013-03-26 16:43:33 -07:00
|
|
|
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
2013-07-01 00:03:04 -07:00
|
|
|
already_AddRefed<SVGAnimatedNumber>
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::BaseFrequencyY()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
2013-03-26 16:43:33 -07:00
|
|
|
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
2013-07-01 00:02:56 -07:00
|
|
|
already_AddRefed<SVGAnimatedInteger>
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::NumOctaves()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
2013-03-26 16:43:33 -07:00
|
|
|
return mIntegerAttributes[OCTAVES].ToDOMAnimatedInteger(this);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
2013-07-01 00:03:04 -07:00
|
|
|
already_AddRefed<SVGAnimatedNumber>
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::Seed()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
2013-03-26 16:43:33 -07:00
|
|
|
return mNumberAttributes[SEED].ToDOMAnimatedNumber(this);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
2013-07-01 00:02:46 -07:00
|
|
|
already_AddRefed<SVGAnimatedEnumeration>
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::StitchTiles()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
2013-03-26 16:43:33 -07:00
|
|
|
return mEnumAttributes[STITCHTILES].ToDOMAnimatedEnum(this);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
2013-07-01 00:02:46 -07:00
|
|
|
already_AddRefed<SVGAnimatedEnumeration>
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::Type()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
2013-03-26 16:43:33 -07:00
|
|
|
return mEnumAttributes[TYPE].ToDOMAnimatedEnum(this);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
2013-11-27 03:25:29 -08:00
|
|
|
FilterPrimitiveDescription
|
|
|
|
SVGFETurbulenceElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
|
|
|
|
const IntRect& aFilterSubregion,
|
2014-01-08 01:30:03 -08:00
|
|
|
const nsTArray<bool>& aInputsAreTainted,
|
2013-11-28 06:38:43 -08:00
|
|
|
nsTArray<RefPtr<SourceSurface>>& aInputImages)
|
2013-03-26 16:43:33 -07: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 03:25:29 -08:00
|
|
|
uint32_t octaves = clamped(mIntegerAttributes[OCTAVES].GetAnimValue(), 0, MAX_OCTAVES);
|
|
|
|
uint32_t type = mEnumAttributes[TYPE].GetAnimValue();
|
2013-03-26 16:43:33 -07:00
|
|
|
uint16_t stitch = mEnumAttributes[STITCHTILES].GetAnimValue();
|
|
|
|
|
2013-11-27 03:25:29 -08:00
|
|
|
if (fX == 0 || fY == 0) {
|
2014-03-19 19:12:43 -07:00
|
|
|
return FilterPrimitiveDescription(PrimitiveType::Empty);
|
2013-03-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
2013-11-27 03:25:29 -08: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 05:42:19 -07:00
|
|
|
gfxRect firstPeriodInFilterSpace = aInstance->UserSpaceToFilterSpace(firstPeriodInUserSpace);
|
2013-11-27 03:25:29 -08:00
|
|
|
Size frequencyInFilterSpace(1 / firstPeriodInFilterSpace.width,
|
|
|
|
1 / firstPeriodInFilterSpace.height);
|
|
|
|
gfxPoint offset = firstPeriodInFilterSpace.TopLeft();
|
|
|
|
|
2014-03-19 19:12:43 -07:00
|
|
|
FilterPrimitiveDescription descr(PrimitiveType::Turbulence);
|
2013-11-27 03:25:29 -08:00
|
|
|
descr.Attributes().Set(eTurbulenceOffset, IntPoint(offset.x, offset.y));
|
|
|
|
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-26 16:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::AttributeAffectsRendering(int32_t aNameSpaceID,
|
2013-03-26 16:43:33 -07:00
|
|
|
nsIAtom* aAttribute) const
|
|
|
|
{
|
2013-03-26 16:43:33 -07:00
|
|
|
return SVGFETurbulenceElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
|
2013-03-26 16:43:33 -07: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-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::GetNumberInfo()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
|
|
|
|
ArrayLength(sNumberInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::NumberPairAttributesInfo
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::GetNumberPairInfo()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
|
|
|
|
ArrayLength(sNumberPairInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::IntegerAttributesInfo
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::GetIntegerInfo()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
|
|
|
|
ArrayLength(sIntegerInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::EnumAttributesInfo
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::GetEnumInfo()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
|
|
|
|
ArrayLength(sEnumInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::StringAttributesInfo
|
2013-03-26 16:43:33 -07:00
|
|
|
SVGFETurbulenceElement::GetStringInfo()
|
2013-03-26 16:43:33 -07:00
|
|
|
{
|
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
|
|
|
ArrayLength(sStringInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|