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

Side by Side Diff: Source/core/page/animation/KeyframeAnimation.cpp

Issue 14189015: KeyframeAnimation::fetchIntervalEndpointsForProperty could use binary search to lookup keyframes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 const double fractionalTime = this->fractionalTime(1, elapsedTime, 0); 91 const double fractionalTime = this->fractionalTime(1, elapsedTime, 0);
92 92
93 size_t numKeyframes = m_keyframes.size(); 93 size_t numKeyframes = m_keyframes.size();
94 if (!numKeyframes) 94 if (!numKeyframes)
95 return; 95 return;
96 96
97 ASSERT(!m_keyframes[0].key()); 97 ASSERT(!m_keyframes[0].key());
98 ASSERT(m_keyframes[m_keyframes.size() - 1].key() == 1); 98 ASSERT(m_keyframes[m_keyframes.size() - 1].key() == 1);
99 99
100 size_t currentIndex = 0;
101 size_t firstIndex = 0;
102 size_t lastIndex = numKeyframes - 1;
103 size_t distance = numKeyframes;
104
105 // Find keyframe that is closest to elapsed time.
106 while (distance > 1) {
107 currentIndex = (lastIndex + firstIndex) >> 1;
108 float key = m_keyframes[currentIndex].key();
109 distance = lastIndex - currentIndex;
110
111 if (key == fractionalTime)
apavlov 2013/04/22 14:23:02 I think this will _rarely_ be true, as you are com
112 break;
113
114 if (key < fractionalTime) {
115 if (distance < 2)
116 currentIndex++;
117 firstIndex = currentIndex;
118 } else
119 lastIndex = currentIndex;
120 }
121
100 int prevIndex = -1; 122 int prevIndex = -1;
101 int nextIndex = -1; 123 int nextIndex = -1;
102
103 // FIXME: with a lot of keys, this linear search will be slow. We could bina ry search.
104 for (size_t i = 0; i < numKeyframes; ++i) {
105 const KeyframeValue& currKeyFrame = m_keyframes[i];
106 124
107 if (!currKeyFrame.containsProperty(property)) 125 // Interate forward to find next keyframe that is used to animate CSS proper ty.
108 continue; 126 for (size_t i = currentIndex; i < numKeyframes; ++i) {
109 127 const KeyframeValue& keyFrame = m_keyframes[i];
110 if (fractionalTime < currKeyFrame.key()) { 128 if (keyFrame.containsProperty(property) && keyFrame.key() > fractionalTi me) {
111 nextIndex = i; 129 nextIndex = i;
112 break; 130 break;
113 } 131 }
114 132 }
115 prevIndex = i; 133
134 // Interate backward to find previous keyframe.
135 for (size_t i = currentIndex; i < numKeyframes; --i) {
apavlov 2013/04/22 14:23:02 The condition should definitely be "i >= 0"
136 const KeyframeValue& keyFrame = m_keyframes[i];
137 if (keyFrame.containsProperty(property) && keyFrame.key() <= fractionalT ime) {
138 prevIndex = i;
139 break;
140 }
116 } 141 }
117 142
118 double scale = 1; 143 double scale = 1;
119 double offset = 0; 144 double offset = 0;
120 145
121 if (prevIndex == -1) 146 if (prevIndex == -1)
122 prevIndex = 0; 147 prevIndex = 0;
123 148
124 if (nextIndex == -1) 149 if (nextIndex == -1)
125 nextIndex = m_keyframes.size() - 1; 150 nextIndex = m_keyframes.size() - 1;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 469
445 if (acceleratedPropertiesOnly) { 470 if (acceleratedPropertiesOnly) {
446 bool isLooping; 471 bool isLooping;
447 getTimeToNextEvent(t, isLooping); 472 getTimeToNextEvent(t, isLooping);
448 } 473 }
449 474
450 return t; 475 return t;
451 } 476 }
452 477
453 } // namespace WebCore 478 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698