Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: Source/core/platform/graphics/transforms/TransformOperations.cpp

Issue 45553002: Move remaining classes in graphics/transforms to platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix merge problem Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22 #include "config.h"
23 #include "core/platform/graphics/transforms/TransformOperations.h"
24
25 #include <algorithm>
26 #include "core/platform/graphics/transforms/IdentityTransformOperation.h"
27 #include "core/platform/graphics/transforms/InterpolatedTransformOperation.h"
28
29 using namespace std;
30
31 namespace WebCore {
32
33 TransformOperations::TransformOperations(bool makeIdentity)
34 {
35 if (makeIdentity)
36 m_operations.append(IdentityTransformOperation::create());
37 }
38
39 bool TransformOperations::operator==(const TransformOperations& o) const
40 {
41 if (m_operations.size() != o.m_operations.size())
42 return false;
43
44 unsigned s = m_operations.size();
45 for (unsigned i = 0; i < s; i++) {
46 if (*m_operations[i] != *o.m_operations[i])
47 return false;
48 }
49
50 return true;
51 }
52
53 bool TransformOperations::operationsMatch(const TransformOperations& other) cons t
54 {
55 size_t numOperations = operations().size();
56 // If the sizes of the function lists don't match, the lists don't match
57 if (numOperations != other.operations().size())
58 return false;
59
60 // If the types of each function are not the same, the lists don't match
61 for (size_t i = 0; i < numOperations; ++i) {
62 if (!operations()[i]->isSameType(*other.operations()[i]))
63 return false;
64 }
65 return true;
66 }
67
68 TransformOperations TransformOperations::blendByMatchingOperations(const Transfo rmOperations& from, const double& progress) const
69 {
70 TransformOperations result;
71
72 unsigned fromSize = from.operations().size();
73 unsigned toSize = operations().size();
74 unsigned size = max(fromSize, toSize);
75 for (unsigned i = 0; i < size; i++) {
76 RefPtr<TransformOperation> fromOperation = (i < fromSize) ? from.operati ons()[i].get() : 0;
77 RefPtr<TransformOperation> toOperation = (i < toSize) ? operations()[i]. get() : 0;
78 RefPtr<TransformOperation> blendedOperation = toOperation ? toOperation- >blend(fromOperation.get(), progress) : (fromOperation ? fromOperation->blend(0, progress, true) : 0);
79 if (blendedOperation)
80 result.operations().append(blendedOperation);
81 else {
82 RefPtr<TransformOperation> identityOperation = IdentityTransformOper ation::create();
83 if (progress > 0.5)
84 result.operations().append(toOperation ? toOperation : identityO peration);
85 else
86 result.operations().append(fromOperation ? fromOperation : ident ityOperation);
87 }
88 }
89
90 return result;
91 }
92
93 TransformOperations TransformOperations::blendByUsingMatrixInterpolation(const T ransformOperations& from, double progress) const
94 {
95 TransformOperations result;
96 result.operations().append(InterpolatedTransformOperation::create(from, *thi s, progress));
97 return result;
98 }
99
100 TransformOperations TransformOperations::blend(const TransformOperations& from, double progress) const
101 {
102 if (from == *this)
103 return *this;
104
105 if (from.size() && from.operationsMatch(*this))
106 return blendByMatchingOperations(from, progress);
107
108 return blendByUsingMatrixInterpolation(from, progress);
109 }
110
111 TransformOperations TransformOperations::add(const TransformOperations& addend) const
112 {
113 TransformOperations result;
114 result.m_operations = operations();
115 result.m_operations.append(addend.operations());
116 return result;
117 }
118
119 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698