Bug 1322883 - AudioNode constructors - part 9 - ConvolverNode, r=padenot

This commit is contained in:
Andrea Marchesini 2016-12-15 19:24:42 +01:00
parent 892e3c83ca
commit 0c863ebca2
5 changed files with 54 additions and 16 deletions

View File

@ -16,6 +16,7 @@
#include "mozilla/dom/AudioBufferSourceNodeBinding.h"
#include "mozilla/dom/AudioContextBinding.h"
#include "mozilla/dom/BiquadFilterNodeBinding.h"
#include "mozilla/dom/ConvolverNodeBinding.h"
#include "mozilla/dom/DelayNodeBinding.h"
#include "mozilla/dom/GainNodeBinding.h"
#include "mozilla/dom/IIRFilterNodeBinding.h"
@ -425,12 +426,7 @@ AudioContext::CreatePanner(ErrorResult& aRv)
already_AddRefed<ConvolverNode>
AudioContext::CreateConvolver(ErrorResult& aRv)
{
if (CheckClosed(aRv)) {
return nullptr;
}
RefPtr<ConvolverNode> convolverNode = new ConvolverNode(this);
return convolverNode.forget();
return ConvolverNode::Create(nullptr, *this, ConvolverOptions(), aRv);
}
already_AddRefed<ChannelSplitterNode>

View File

@ -204,8 +204,34 @@ ConvolverNode::ConvolverNode(AudioContext* aContext)
aContext->Graph());
}
ConvolverNode::~ConvolverNode()
/* static */ already_AddRefed<ConvolverNode>
ConvolverNode::Create(JSContext* aCx, AudioContext& aAudioContext,
const ConvolverOptions& aOptions,
ErrorResult& aRv)
{
if (aAudioContext.CheckClosed(aRv)) {
return nullptr;
}
RefPtr<ConvolverNode> audioNode = new ConvolverNode(&aAudioContext);
audioNode->Initialize(aOptions, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
// This must be done before setting the buffer.
audioNode->SetNormalize(!aOptions.mDisableNormalization);
if (aOptions.mBuffer.WasPassed()) {
MOZ_ASSERT(aCx);
audioNode->SetBuffer(aCx, aOptions.mBuffer.Value(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
}
return audioNode.forget();
}
size_t
@ -292,4 +318,3 @@ ConvolverNode::SetNormalize(bool aNormalize)
} // namespace dom
} // namespace mozilla

View File

@ -13,14 +13,26 @@
namespace mozilla {
namespace dom {
class AudioContext;
struct ConvolverOptions;
class ConvolverNode final : public AudioNode
{
public:
explicit ConvolverNode(AudioContext* aContext);
static already_AddRefed<ConvolverNode>
Create(JSContext* aCx, AudioContext& aAudioContext,
const ConvolverOptions& aOptions, ErrorResult& aRv);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ConvolverNode, AudioNode);
static already_AddRefed<ConvolverNode>
Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
const ConvolverOptions& aOptions, ErrorResult& aRv)
{
return Create(aGlobal.Context(), aAudioContext, aOptions, aRv);
}
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
AudioBuffer* GetBuffer(JSContext* aCx) const
@ -28,7 +40,7 @@ public:
return mBuffer;
}
void SetBuffer(JSContext* aCx, AudioBuffer* aBufferi, ErrorResult& aRv);
void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer, ErrorResult& aRv);
bool Normalize() const
{
@ -62,10 +74,10 @@ public:
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
protected:
virtual ~ConvolverNode();
private:
explicit ConvolverNode(AudioContext* aContext);
~ConvolverNode() = default;
RefPtr<AudioBuffer> mBuffer;
bool mNormalize;
};
@ -75,4 +87,3 @@ private:
} //end namespace mozilla
#endif

View File

@ -13,7 +13,7 @@
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
var context = new AudioContext();
var conv = context.createConvolver();
var conv = new ConvolverNode(context);
is(conv.channelCount, 2, "Convolver node has 2 input channels by default");
is(conv.channelCountMode, "clamped-max", "Correct channelCountMode for the Convolver node");

View File

@ -10,7 +10,13 @@
* liability, trademark and document use rules apply.
*/
[Pref="dom.webaudio.enabled"]
dictionary ConvolverOptions : AudioNodeOptions {
AudioBuffer? buffer;
boolean disableNormalization = false;
};
[Pref="dom.webaudio.enabled",
Constructor(AudioContext context, optional ConvolverOptions options)]
interface ConvolverNode : AudioNode {
[SetterThrows]