Bug 1216842 - Part 2: Add LayerAnimationUtils. r=cam

This is also for compositor side.
we need a new class to share the function which converts TimingFunction
to ComputedTimingFunction for either keyframe's timing function or keyframe
effect's timing function.
This commit is contained in:
Hiroyuki Ikezoe 2016-01-29 14:44:00 +01:00
parent 52d846dacd
commit f67bc01a17
7 changed files with 89 additions and 22 deletions

View File

@ -41,6 +41,12 @@ public:
int32_t Compare(const ComputedTimingFunction& aRhs) const;
void AppendToString(nsAString& aResult) const;
static double GetPortion(const Maybe<ComputedTimingFunction>& aFunction,
double aPortion)
{
return aFunction.isSome() ? aFunction->GetValue(aPortion) : aPortion;
}
private:
nsTimingFunction::Type mType;
nsSMILKeySpline mTimingFunction;

View File

@ -30,6 +30,7 @@
#include "mozilla/layers/CompositableClient.h" // for CompositableClient
#include "mozilla/layers/Compositor.h" // for Compositor
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayerAnimationUtils.h" // for TimingFunctionToComputedTimingFunction
#include "mozilla/layers/LayerManagerComposite.h" // for LayerComposite
#include "mozilla/layers/LayerMetricsWrapper.h" // for LayerMetricsWrapper
#include "mozilla/layers/LayersMessages.h" // for TransformFunction, etc
@ -470,31 +471,15 @@ Layer::SetAnimations(const AnimationArray& aAnimations)
mAnimationData.Clear();
for (uint32_t i = 0; i < mAnimations.Length(); i++) {
AnimData* data = mAnimationData.AppendElement();
InfallibleTArray<nsAutoPtr<ComputedTimingFunction> >& functions =
InfallibleTArray<Maybe<ComputedTimingFunction>>& functions =
data->mFunctions;
const InfallibleTArray<AnimationSegment>& segments =
mAnimations.ElementAt(i).segments();
for (uint32_t j = 0; j < segments.Length(); j++) {
TimingFunction tf = segments.ElementAt(j).sampleFn();
ComputedTimingFunction* ctf = new ComputedTimingFunction();
switch (tf.type()) {
case TimingFunction::TCubicBezierFunction: {
CubicBezierFunction cbf = tf.get_CubicBezierFunction();
ctf->Init(nsTimingFunction(cbf.x1(), cbf.y1(), cbf.x2(), cbf.y2()));
break;
}
default: {
NS_ASSERTION(tf.type() == TimingFunction::TStepFunction,
"Function must be bezier or step");
StepFunction sf = tf.get_StepFunction();
nsTimingFunction::Type type = sf.type() == 1 ?
nsTimingFunction::Type::StepStart :
nsTimingFunction::Type::StepEnd;
ctf->Init(nsTimingFunction(type, sf.steps(),
nsTimingFunction::Keyword::Explicit));
break;
}
}
Maybe<ComputedTimingFunction> ctf =
AnimationUtils::TimingFunctionToComputedTimingFunction(tf);
functions.AppendElement(ctf);
}

View File

@ -715,7 +715,7 @@ typedef InfallibleTArray<Animation> AnimationArray;
struct AnimData {
InfallibleTArray<mozilla::StyleAnimationValue> mStartValues;
InfallibleTArray<mozilla::StyleAnimationValue> mEndValues;
InfallibleTArray<nsAutoPtr<mozilla::ComputedTimingFunction> > mFunctions;
InfallibleTArray<Maybe<mozilla::ComputedTimingFunction>> mFunctions;
};
/**

View File

@ -617,7 +617,8 @@ SampleAnimations(Layer* aLayer, TimeStamp aPoint)
(segment->endPortion() - segment->startPortion());
double portion =
animData.mFunctions[segmentIndex]->GetValue(positionInSegment);
ComputedTimingFunction::GetPortion(animData.mFunctions[segmentIndex],
positionInSegment);
// interpolate the property
Animatable interpolatedValue;

View File

@ -0,0 +1,47 @@
/* -*- 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 "LayerAnimationUtils.h"
#include "mozilla/ComputedTimingFunction.h" // For ComputedTimingFunction
#include "mozilla/layers/LayersMessages.h" // For TimingFunction etc.
#include "mozilla/Maybe.h" // For Maybe<>
namespace mozilla {
namespace layers {
/* static */ Maybe<ComputedTimingFunction>
AnimationUtils::TimingFunctionToComputedTimingFunction(
const TimingFunction& aTimingFunction)
{
switch (aTimingFunction.type()) {
case TimingFunction::Tnull_t:
return Nothing();
case TimingFunction::TCubicBezierFunction: {
ComputedTimingFunction result;
CubicBezierFunction cbf = aTimingFunction.get_CubicBezierFunction();
result.Init(nsTimingFunction(cbf.x1(), cbf.y1(), cbf.x2(), cbf.y2()));
return Some(result);
}
case TimingFunction::TStepFunction: {
StepFunction sf = aTimingFunction.get_StepFunction();
nsTimingFunction::Type type = sf.type() == 1 ?
nsTimingFunction::Type::StepStart :
nsTimingFunction::Type::StepEnd;
ComputedTimingFunction result;
result.Init(nsTimingFunction(type, sf.steps(),
nsTimingFunction::Keyword::Explicit));
return Some(result);
}
default:
MOZ_ASSERT_UNREACHABLE(
"Function must be null, bezier or step");
break;
}
return Nothing();
}
} // namespace layers
} // namespace mozilla

View File

@ -0,0 +1,26 @@
/* -*- 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/. */
#ifndef mozilla_layers_LayerAnimationUtils_h
#define mozilla_layers_LayerAnimationUtils_h
namespace mozilla {
class ComputedTimingFunction;
namespace layers {
class AnimationUtils
{
public:
static Maybe<ComputedTimingFunction> TimingFunctionToComputedTimingFunction(
const TimingFunction& aTimingFunction);
};
} // namespace layers
} // namespace mozilla
#endif // mozilla_layers_LayerAnimationUtils_h

View File

@ -163,6 +163,7 @@ EXPORTS.mozilla.layers += [
'ipc/ImageBridgeParent.h',
'ipc/ImageContainerParent.h',
'ipc/ISurfaceAllocator.h',
'ipc/LayerAnimationUtils.h',
'ipc/LayerTransactionChild.h',
'ipc/LayerTransactionParent.h',
'ipc/ShadowLayerChild.h',
@ -337,6 +338,7 @@ UNIFIED_SOURCES += [
'ipc/ImageBridgeParent.cpp',
'ipc/ImageContainerParent.cpp',
'ipc/ISurfaceAllocator.cpp',
'ipc/LayerAnimationUtils.cpp',
'ipc/LayerTransactionChild.cpp',
'ipc/LayerTransactionParent.cpp',
'ipc/ShadowLayerChild.cpp',