Bug 834929 - Part 2: Remove FloatArrayWrapper and just copy the curve array when needed; r=roc

This commit is contained in:
Ehsan Akhgari 2013-01-25 16:46:44 -05:00
Родитель f08d5611eb
Коммит 495612118f
3 изменённых файлов: 12 добавлений и 84 удалений

Просмотреть файл

@ -20,15 +20,10 @@ namespace dom {
* This class will be instantiated with different template arguments for testing and
* production code.
*
* FloatArrayWrapper is a type which satisfies the following:
* - Is copy-constructible.
* - Implements a Data() method returning a float*, representing an array.
* - Implements a Length() method returning a uint32_t, representing the array length.
* - Implements an inited() method returning true for valid objects.
* ErrorResult is a type which satisfies the following:
* - Implements a Throw() method taking an nsresult argument, representing an error code.
*/
template <class FloatArrayWrapper, class ErrorResult>
template <class ErrorResult>
class AudioEventTimeline
{
private:
@ -42,16 +37,15 @@ private:
};
Event(Type aType, double aTime, float aValue, double aTimeConstant = 0.0,
float aDuration = 0.0, FloatArrayWrapper aCurve = FloatArrayWrapper())
float aDuration = 0.0, float* aCurve = nullptr, uint32_t aCurveLength = 0)
: mType(aType)
, mValue(aValue)
, mTime(aTime)
, mTimeConstant(aTimeConstant)
, mDuration(aDuration)
, mCurve(aCurve)
, mCurveLength(aCurveLength)
{
if (aCurve.inited()) {
mCurve = aCurve;
}
}
bool IsValid() const
@ -67,7 +61,8 @@ private:
double mTime;
double mTimeConstant;
double mDuration;
FloatArrayWrapper mCurve;
float* mCurve;
uint32_t mCurveLength;
private:
static bool IsValid(float value)
@ -122,10 +117,11 @@ public:
InsertEvent(Event(Event::SetTarget, aStartTime, aTarget, aTimeConstant), aRv);
}
void SetValueCurveAtTime(const FloatArrayWrapper& aValues, double aStartTime, double aDuration, ErrorResult& aRv)
void SetValueCurveAtTime(const float* aValues, uint32_t aValuesLength, double aStartTime, double aDuration, ErrorResult& aRv)
{
// TODO: implement
// InsertEvent(Event(Event::SetValueCurve, aStartTime, 0.0f, 0.0f, aDuration, aValues), aRv);
// Note that we will need to copy the buffer here.
// InsertEvent(Event(Event::SetValueCurve, aStartTime, 0.0f, 0.0f, aDuration, aValues, aValuesLength), aRv);
}
void CancelScheduledValues(double aStartTime)

Просмотреть файл

@ -26,57 +26,7 @@ class ErrorResult;
namespace dom {
namespace detail {
// This class wraps a JS typed array so that AudioEventTimeline does not need
// to know about JSObjects directly.
class FloatArrayWrapper
{
public:
FloatArrayWrapper() // creates an uninitialized object
{
}
FloatArrayWrapper(const Float32Array& array)
{
mArray.construct(array);
}
FloatArrayWrapper(const FloatArrayWrapper& rhs)
{
MOZ_ASSERT(!rhs.mArray.empty());
mArray.construct(rhs.mArray.ref());
}
FloatArrayWrapper& operator=(const FloatArrayWrapper& rhs)
{
MOZ_ASSERT(!rhs.mArray.empty());
mArray.destroyIfConstructed();
mArray.construct(rhs.mArray.ref());
return *this;
}
// Expose the API used by AudioEventTimeline
float* Data() const
{
MOZ_ASSERT(inited());
return mArray.ref().Data();
}
uint32_t Length() const
{
MOZ_ASSERT(inited());
return mArray.ref().Length();
}
bool inited() const
{
return !mArray.empty();
}
private:
Maybe<Float32Array> mArray;
};
}
typedef AudioEventTimeline<detail::FloatArrayWrapper, ErrorResult> AudioParamTimeline;
typedef AudioEventTimeline<ErrorResult> AudioParamTimeline;
class AudioParam MOZ_FINAL : public nsWrapperCache,
public EnableWebAudioCheck,
@ -104,7 +54,7 @@ public:
// object.
void SetValueCurveAtTime(JSContext* cx, const Float32Array& aValues, double aStartTime, double aDuration, ErrorResult& aRv)
{
AudioParamTimeline::SetValueCurveAtTime(detail::FloatArrayWrapper(aValues),
AudioParamTimeline::SetValueCurveAtTime(aValues.Data(), aValues.Length(),
aStartTime, aDuration, aRv);
}

Просмотреть файл

@ -53,24 +53,6 @@ void is(const float& a, const float& b, const char* msg)
ok(fabsf(a - b) < kEpsilon, ss.str().c_str());
}
class FloatArrayMock
{
public:
// This implementation is not used for now, so let's just return dummy values.
float* Data() const
{
return nullptr;
}
uint32_t Length() const
{
return 0;
}
bool inited() const
{
return true;
}
};
class ErrorResultMock
{
public:
@ -92,7 +74,7 @@ private:
nsresult mRv;
};
typedef AudioEventTimeline<FloatArrayMock, ErrorResultMock> Timeline;
typedef AudioEventTimeline<ErrorResultMock> Timeline;
void TestSpecExample()
{