1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "third_party/blink/renderer/platform/transforms/interpolated_transform_operation.h"
32
33 namespace blink {
34
operator ==(const TransformOperation & o) const35 bool InterpolatedTransformOperation::operator==(
36 const TransformOperation& o) const {
37 if (!IsSameType(o))
38 return false;
39 const InterpolatedTransformOperation* t =
40 static_cast<const InterpolatedTransformOperation*>(&o);
41 return progress_ == t->progress_ && from_ == t->from_ && to_ == t->to_;
42 }
43
Apply(TransformationMatrix & transform,const FloatSize & border_box_size) const44 void InterpolatedTransformOperation::Apply(
45 TransformationMatrix& transform,
46 const FloatSize& border_box_size) const {
47 TransformationMatrix from_transform;
48 TransformationMatrix to_transform;
49 from_.ApplyRemaining(border_box_size, starting_index_, from_transform);
50 to_.ApplyRemaining(border_box_size, starting_index_, to_transform);
51
52 to_transform.Blend(from_transform, progress_);
53 transform.Multiply(to_transform);
54 }
55
Blend(const TransformOperation * from,double progress,bool blend_to_identity)56 scoped_refptr<TransformOperation> InterpolatedTransformOperation::Blend(
57 const TransformOperation* from,
58 double progress,
59 bool blend_to_identity) {
60 DCHECK(!from || CanBlendWith(*from));
61
62 TransformOperations to_operations;
63 to_operations.Operations().push_back(this);
64 TransformOperations from_operations;
65 if (blend_to_identity) {
66 return InterpolatedTransformOperation::Create(to_operations,
67 from_operations, 0, progress);
68 }
69
70 if (from) {
71 from_operations.Operations().push_back(
72 const_cast<TransformOperation*>(from));
73 }
74 return InterpolatedTransformOperation::Create(from_operations, to_operations,
75 0, progress);
76 }
77
78 } // namespace blink
79