Home | History | Annotate | Download | only in interpolation
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "config.h"
      6 #include "core/animation/interpolation/Interpolation.h"
      7 
      8 namespace WebCore {
      9 
     10 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Interpolation);
     11 
     12 namespace {
     13 
     14 bool typesMatch(const InterpolableValue* start, const InterpolableValue* end)
     15 {
     16     if (start->isNumber())
     17         return end->isNumber();
     18     if (start->isBool())
     19         return end->isBool();
     20     if (start->isAnimatableValue())
     21         return end->isAnimatableValue();
     22     if (!(start->isList() && end->isList()))
     23         return false;
     24     const InterpolableList* startList = toInterpolableList(start);
     25     const InterpolableList* endList = toInterpolableList(end);
     26     if (startList->length() != endList->length())
     27         return false;
     28     for (size_t i = 0; i < startList->length(); ++i) {
     29         if (!typesMatch(startList->get(i), endList->get(i)))
     30             return false;
     31     }
     32     return true;
     33 }
     34 
     35 }
     36 
     37 Interpolation::Interpolation(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end)
     38     : m_start(start)
     39     , m_end(end)
     40     , m_cachedFraction(0)
     41     , m_cachedIteration(0)
     42     , m_cachedValue(m_start->clone())
     43 {
     44     RELEASE_ASSERT(typesMatch(m_start.get(), m_end.get()));
     45 }
     46 
     47 void Interpolation::interpolate(int iteration, double fraction) const
     48 {
     49     if (m_cachedFraction != fraction || m_cachedIteration != iteration) {
     50         m_cachedValue = m_start->interpolate(*m_end, fraction);
     51         m_cachedIteration = iteration;
     52         m_cachedFraction = fraction;
     53     }
     54 }
     55 
     56 void Interpolation::trace(Visitor* visitor)
     57 {
     58     visitor->trace(m_start);
     59     visitor->trace(m_end);
     60     visitor->trace(m_cachedValue);
     61 }
     62 
     63 }
     64