gecko-dev/dom/svg/SVGFETurbulenceElement.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

226 строки
7.3 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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"
#include "mozilla/dom/SVGFETurbulenceElementBinding.h"
#include "nsSVGFilterInstance.h"
#include "nsSVGUtils.h"
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FETurbulence)
using namespace mozilla::gfx;
namespace mozilla {
namespace dom {
// Stitch Options
static const unsigned short SVG_STITCHTYPE_STITCH = 1;
static const unsigned short SVG_STITCHTYPE_NOSTITCH = 2;
static const int32_t MAX_OCTAVES = 10;
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)
{
return SVGFETurbulenceElement_Binding::Wrap(aCx, this, aGivenProto);
}
nsSVGElement::NumberInfo SVGFETurbulenceElement::sNumberInfo[1] =
{
{ nsGkAtoms::seed, 0, false }
};
nsSVGElement::NumberPairInfo SVGFETurbulenceElement::sNumberPairInfo[1] =
{
{ nsGkAtoms::baseFrequency, 0, 0 }
};
nsSVGElement::IntegerInfo SVGFETurbulenceElement::sIntegerInfo[1] =
{
{ nsGkAtoms::numOctaves, 1 }
};
nsSVGEnumMapping SVGFETurbulenceElement::sTypeMap[] = {
{nsGkAtoms::fractalNoise,
SVG_TURBULENCE_TYPE_FRACTALNOISE},
{nsGkAtoms::turbulence,
SVG_TURBULENCE_TYPE_TURBULENCE},
{nullptr, 0}
};
nsSVGEnumMapping SVGFETurbulenceElement::sStitchTilesMap[] = {
{nsGkAtoms::stitch,
SVG_STITCHTYPE_STITCH},
{nsGkAtoms::noStitch,
SVG_STITCHTYPE_NOSTITCH},
{nullptr, 0}
};
nsSVGElement::EnumInfo SVGFETurbulenceElement::sEnumInfo[2] =
{
{ nsGkAtoms::type,
sTypeMap,
SVG_TURBULENCE_TYPE_TURBULENCE
},
{ nsGkAtoms::stitchTiles,
sStitchTilesMap,
SVG_STITCHTYPE_NOSTITCH
}
};
nsSVGElement::StringInfo SVGFETurbulenceElement::sStringInfo[1] =
{
{ nsGkAtoms::result, kNameSpaceID_None, true }
};
//----------------------------------------------------------------------
// nsINode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFETurbulenceElement)
//----------------------------------------------------------------------
already_AddRefed<SVGAnimatedNumber>
SVGFETurbulenceElement::BaseFrequencyX()
{
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
}
already_AddRefed<SVGAnimatedNumber>
SVGFETurbulenceElement::BaseFrequencyY()
{
return mNumberPairAttributes[BASE_FREQ].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
}
already_AddRefed<SVGAnimatedInteger>
SVGFETurbulenceElement::NumOctaves()
{
return mIntegerAttributes[OCTAVES].ToDOMAnimatedInteger(this);
}
already_AddRefed<SVGAnimatedNumber>
SVGFETurbulenceElement::Seed()
{
return mNumberAttributes[SEED].ToDOMAnimatedNumber(this);
}
already_AddRefed<SVGAnimatedEnumeration>
SVGFETurbulenceElement::StitchTiles()
{
return mEnumAttributes[STITCHTILES].ToDOMAnimatedEnum(this);
}
already_AddRefed<SVGAnimatedEnumeration>
SVGFETurbulenceElement::Type()
{
return mEnumAttributes[TYPE].ToDOMAnimatedEnum(this);
}
FilterPrimitiveDescription
SVGFETurbulenceElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
const IntRect& aFilterSubregion,
2014-01-08 13:30:03 +04:00
const nsTArray<bool>& aInputsAreTainted,
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
nsTArray<RefPtr<SourceSurface>>& aInputImages)
{
float fX = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eFirst);
float fY = mNumberPairAttributes[BASE_FREQ].GetAnimValue(nsSVGNumberPair::eSecond);
float seed = mNumberAttributes[OCTAVES].GetAnimValue();
uint32_t octaves = clamped(mIntegerAttributes[OCTAVES].GetAnimValue(), 0, MAX_OCTAVES);
uint32_t type = mEnumAttributes[TYPE].GetAnimValue();
uint16_t stitch = mEnumAttributes[STITCHTILES].GetAnimValue();
if (fX == 0 && fY == 0) {
// 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();
}
FloodAttributes atts;
atts.mColor = Color(0.5, 0.5, 0.5, 0.5);
return FilterPrimitiveDescription(AsVariant(std::move(atts)));
}
// 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.
// 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));
gfxRect firstPeriodInFilterSpace = aInstance->UserSpaceToFilterSpace(firstPeriodInUserSpace);
Size frequencyInFilterSpace(fX == 0 ? 0 : (1 / firstPeriodInFilterSpace.width),
fY == 0 ? 0 : (1 / firstPeriodInFilterSpace.height));
gfxPoint offset = firstPeriodInFilterSpace.TopLeft();
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;
return FilterPrimitiveDescription(AsVariant(std::move(atts)));
}
bool
SVGFETurbulenceElement::AttributeAffectsRendering(int32_t aNameSpaceID,
nsAtom* aAttribute) const
{
return SVGFETurbulenceElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
(aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::seed ||
aAttribute == nsGkAtoms::baseFrequency ||
aAttribute == nsGkAtoms::numOctaves ||
aAttribute == nsGkAtoms::type ||
aAttribute == nsGkAtoms::stitchTiles));
}
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::NumberAttributesInfo
SVGFETurbulenceElement::GetNumberInfo()
{
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
ArrayLength(sNumberInfo));
}
nsSVGElement::NumberPairAttributesInfo
SVGFETurbulenceElement::GetNumberPairInfo()
{
return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
ArrayLength(sNumberPairInfo));
}
nsSVGElement::IntegerAttributesInfo
SVGFETurbulenceElement::GetIntegerInfo()
{
return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
ArrayLength(sIntegerInfo));
}
nsSVGElement::EnumAttributesInfo
SVGFETurbulenceElement::GetEnumInfo()
{
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
ArrayLength(sEnumInfo));
}
nsSVGElement::StringAttributesInfo
SVGFETurbulenceElement::GetStringInfo()
{
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));
}
} // namespace dom
} // namespace mozilla