mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-12 02:30:30 +09:00

Before this change, we were going through the chain of base classes for each IDL interface object and having them set the prototype to their prototype. Instead of doing that, reorder things so that we set the right prototype immediately in Foo::initialize(), and then don't bother in all the base class overrides. This knocks off a ~1% profile item on Speedometer 3.
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/WebAudio/AudioNode.h>
|
|
#include <LibWeb/WebAudio/AudioParam.h>
|
|
#include <LibWeb/WebAudio/BaseAudioContext.h>
|
|
#include <LibWeb/WebAudio/GainNode.h>
|
|
|
|
namespace Web::WebAudio {
|
|
|
|
GC_DEFINE_ALLOCATOR(GainNode);
|
|
|
|
GainNode::~GainNode() = default;
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<GainNode>> GainNode::create(JS::Realm& realm, GC::Ref<BaseAudioContext> context, GainOptions const& options)
|
|
{
|
|
return construct_impl(realm, context, options);
|
|
}
|
|
|
|
// https://webaudio.github.io/web-audio-api/#dom-gainnode-gainnode
|
|
WebIDL::ExceptionOr<GC::Ref<GainNode>> GainNode::construct_impl(JS::Realm& realm, GC::Ref<BaseAudioContext> context, GainOptions const& options)
|
|
{
|
|
// Create the node and allocate memory
|
|
auto node = realm.create<GainNode>(realm, context, options);
|
|
|
|
// Default options for channel count and interpretation
|
|
// https://webaudio.github.io/web-audio-api/#GainNode
|
|
AudioNodeDefaultOptions default_options;
|
|
default_options.channel_count_mode = Bindings::ChannelCountMode::Max;
|
|
default_options.channel_interpretation = Bindings::ChannelInterpretation::Speakers;
|
|
default_options.channel_count = 2;
|
|
// FIXME: Set tail-time to no
|
|
|
|
TRY(node->initialize_audio_node_options(options, default_options));
|
|
return node;
|
|
}
|
|
|
|
GainNode::GainNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, GainOptions const& options)
|
|
: AudioNode(realm, context)
|
|
, m_gain(AudioParam::create(realm, context, options.gain, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
|
|
{
|
|
}
|
|
|
|
void GainNode::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(GainNode);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
void GainNode::visit_edges(Cell::Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
visitor.visit(m_gain);
|
|
}
|
|
|
|
}
|