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

Side by Side Diff: src/animator/SkDrawGroup.cpp

Issue 764463002: rename SkDrawable to SkADrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkDrawGroup.h" 10 #include "SkDrawGroup.h"
(...skipping 18 matching lines...) Expand all
29 DEFINE_GET_MEMBER(SkGroup); 29 DEFINE_GET_MEMBER(SkGroup);
30 30
31 SkGroup::SkGroup() : fParentList(NULL), fOriginal(NULL) { 31 SkGroup::SkGroup() : fParentList(NULL), fOriginal(NULL) {
32 } 32 }
33 33
34 SkGroup::~SkGroup() { 34 SkGroup::~SkGroup() {
35 if (fOriginal) // has been copied 35 if (fOriginal) // has been copied
36 return; 36 return;
37 int index = 0; 37 int index = 0;
38 int max = fCopies.count() << 5; 38 int max = fCopies.count() << 5;
39 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 39 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
40 if (index >= max || markedForDelete(index)) 40 if (index >= max || markedForDelete(index))
41 delete *ptr; 41 delete *ptr;
42 // else { 42 // else {
43 // SkApply* apply = (SkApply*) *ptr; 43 // SkApply* apply = (SkApply*) *ptr;
44 // SkASSERT(apply->isApply()); 44 // SkASSERT(apply->isApply());
45 // SkASSERT(apply->getScope()); 45 // SkASSERT(apply->getScope());
46 // delete apply->getScope(); 46 // delete apply->getScope();
47 // } 47 // }
48 index++; 48 index++;
49 } 49 }
50 } 50 }
51 51
52 bool SkGroup::addChild(SkAnimateMaker& , SkDisplayable* child) { 52 bool SkGroup::addChild(SkAnimateMaker& , SkDisplayable* child) {
53 SkASSERT(child); 53 SkASSERT(child);
54 // SkASSERT(child->isDrawable()); 54 // SkASSERT(child->isDrawable());
55 *fChildren.append() = (SkDrawable*) child; 55 *fChildren.append() = (SkADrawable*) child;
56 if (child->isGroup()) { 56 if (child->isGroup()) {
57 SkGroup* groupie = (SkGroup*) child; 57 SkGroup* groupie = (SkGroup*) child;
58 SkASSERT(groupie->fParentList == NULL); 58 SkASSERT(groupie->fParentList == NULL);
59 groupie->fParentList = &fChildren; 59 groupie->fParentList = &fChildren;
60 } 60 }
61 return true; 61 return true;
62 } 62 }
63 63
64 bool SkGroup::contains(SkDisplayable* match) { 64 bool SkGroup::contains(SkDisplayable* match) {
65 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 65 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
66 SkDrawable* drawable = *ptr; 66 SkADrawable* drawable = *ptr;
67 if (drawable == match || drawable->contains(match)) 67 if (drawable == match || drawable->contains(match))
68 return true; 68 return true;
69 } 69 }
70 return false; 70 return false;
71 } 71 }
72 72
73 SkGroup* SkGroup::copy() { 73 SkGroup* SkGroup::copy() {
74 SkGroup* result = new SkGroup(); 74 SkGroup* result = new SkGroup();
75 result->fOriginal = this; 75 result->fOriginal = this;
76 result->fChildren = fChildren; 76 result->fChildren = fChildren;
77 return result; 77 return result;
78 } 78 }
79 79
80 SkBool SkGroup::copySet(int index) { 80 SkBool SkGroup::copySet(int index) {
81 return (fCopies[index >> 5] & 1 << (index & 0x1f)) != 0; 81 return (fCopies[index >> 5] & 1 << (index & 0x1f)) != 0;
82 } 82 }
83 83
84 SkDisplayable* SkGroup::deepCopy(SkAnimateMaker* maker) { 84 SkDisplayable* SkGroup::deepCopy(SkAnimateMaker* maker) {
85 SkDisplayable* copy = INHERITED::deepCopy(maker); 85 SkDisplayable* copy = INHERITED::deepCopy(maker);
86 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 86 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
87 SkDisplayable* displayable = (SkDisplayable*)*ptr; 87 SkDisplayable* displayable = (SkDisplayable*)*ptr;
88 SkDisplayable* deeperCopy = displayable->deepCopy(maker); 88 SkDisplayable* deeperCopy = displayable->deepCopy(maker);
89 ((SkGroup*)copy)->addChild(*maker, deeperCopy); 89 ((SkGroup*)copy)->addChild(*maker, deeperCopy);
90 } 90 }
91 return copy; 91 return copy;
92 } 92 }
93 93
94 bool SkGroup::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) { 94 bool SkGroup::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) {
95 bool handled = false; 95 bool handled = false;
96 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 96 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
97 SkDrawable* drawable = *ptr; 97 SkADrawable* drawable = *ptr;
98 if (drawable->isDrawable() == false) 98 if (drawable->isDrawable() == false)
99 continue; 99 continue;
100 handled |= drawable->doEvent(kind, state); 100 handled |= drawable->doEvent(kind, state);
101 } 101 }
102 return handled; 102 return handled;
103 } 103 }
104 104
105 bool SkGroup::draw(SkAnimateMaker& maker) { 105 bool SkGroup::draw(SkAnimateMaker& maker) {
106 bool conditionTrue = ifCondition(maker, this, condition); 106 bool conditionTrue = ifCondition(maker, this, condition);
107 bool result = false; 107 bool result = false;
108 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 108 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
109 SkDrawable* drawable = *ptr; 109 SkADrawable* drawable = *ptr;
110 if (drawable->isDrawable() == false) 110 if (drawable->isDrawable() == false)
111 continue; 111 continue;
112 if (conditionTrue == false) { 112 if (conditionTrue == false) {
113 if (drawable->isApply()) 113 if (drawable->isApply())
114 ((SkApply*) drawable)->disable(); 114 ((SkApply*) drawable)->disable();
115 continue; 115 continue;
116 } 116 }
117 maker.validate(); 117 maker.validate();
118 result |= drawable->draw(maker); 118 result |= drawable->draw(maker);
119 maker.validate(); 119 maker.validate();
120 } 120 }
121 return result; 121 return result;
122 } 122 }
123 123
124 #ifdef SK_DUMP_ENABLED 124 #ifdef SK_DUMP_ENABLED
125 void SkGroup::dump(SkAnimateMaker* maker) { 125 void SkGroup::dump(SkAnimateMaker* maker) {
126 dumpBase(maker); 126 dumpBase(maker);
127 if (condition.size() > 0) 127 if (condition.size() > 0)
128 SkDebugf("condition=\"%s\" ", condition.c_str()); 128 SkDebugf("condition=\"%s\" ", condition.c_str());
129 if (enableCondition.size() > 0) 129 if (enableCondition.size() > 0)
130 SkDebugf("enableCondition=\"%s\" ", enableCondition.c_str()); 130 SkDebugf("enableCondition=\"%s\" ", enableCondition.c_str());
131 dumpDrawables(maker); 131 dumpDrawables(maker);
132 } 132 }
133 133
134 void SkGroup::dumpDrawables(SkAnimateMaker* maker) { 134 void SkGroup::dumpDrawables(SkAnimateMaker* maker) {
135 SkDisplayList::fIndent += 4; 135 SkDisplayList::fIndent += 4;
136 int save = SkDisplayList::fDumpIndex; 136 int save = SkDisplayList::fDumpIndex;
137 SkDisplayList::fDumpIndex = 0; 137 SkDisplayList::fDumpIndex = 0;
138 bool closedYet = false; 138 bool closedYet = false;
139 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 139 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
140 if (closedYet == false) { 140 if (closedYet == false) {
141 closedYet = true; 141 closedYet = true;
142 SkDebugf(">\n"); 142 SkDebugf(">\n");
143 } 143 }
144 SkDrawable* drawable = *ptr; 144 SkADrawable* drawable = *ptr;
145 drawable->dump(maker); 145 drawable->dump(maker);
146 SkDisplayList::fDumpIndex++; 146 SkDisplayList::fDumpIndex++;
147 } 147 }
148 SkDisplayList::fIndent -= 4; 148 SkDisplayList::fIndent -= 4;
149 SkDisplayList::fDumpIndex = save; 149 SkDisplayList::fDumpIndex = save;
150 if (closedYet) //we had children, now it's time to close the group 150 if (closedYet) //we had children, now it's time to close the group
151 dumpEnd(maker); 151 dumpEnd(maker);
152 else //no children 152 else //no children
153 SkDebugf("/>\n"); 153 SkDebugf("/>\n");
154 } 154 }
155 155
156 void SkGroup::dumpEvents() { 156 void SkGroup::dumpEvents() {
157 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 157 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
158 SkDrawable* drawable = *ptr; 158 SkADrawable* drawable = *ptr;
159 drawable->dumpEvents(); 159 drawable->dumpEvents();
160 } 160 }
161 } 161 }
162 #endif 162 #endif
163 163
164 bool SkGroup::enable(SkAnimateMaker& maker ) { 164 bool SkGroup::enable(SkAnimateMaker& maker ) {
165 reset(); 165 reset();
166 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 166 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
167 SkDrawable* drawable = *ptr; 167 SkADrawable* drawable = *ptr;
168 if (ifCondition(maker, drawable, enableCondition) == false) 168 if (ifCondition(maker, drawable, enableCondition) == false)
169 continue; 169 continue;
170 drawable->enable(maker); 170 drawable->enable(maker);
171 } 171 }
172 return true; // skip add; already added so that scope is findable by chil dren 172 return true; // skip add; already added so that scope is findable by chil dren
173 } 173 }
174 174
175 int SkGroup::findGroup(SkDrawable* match, SkTDDrawableArray** list, 175 int SkGroup::findGroup(SkADrawable* match, SkTDDrawableArray** list,
176 SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandLis t) { 176 SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandLis t) {
177 *list = &fChildren; 177 *list = &fChildren;
178 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 178 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
179 SkDrawable* drawable = *ptr; 179 SkADrawable* drawable = *ptr;
180 if (drawable->isGroup()) { 180 if (drawable->isGroup()) {
181 SkGroup* childGroup = (SkGroup*) drawable; 181 SkGroup* childGroup = (SkGroup*) drawable;
182 if (childGroup->fOriginal == match) 182 if (childGroup->fOriginal == match)
183 goto foundMatch; 183 goto foundMatch;
184 } 184 }
185 if (drawable == match) { 185 if (drawable == match) {
186 foundMatch: 186 foundMatch:
187 *parent = this; 187 *parent = this;
188 return (int) (ptr - fChildren.begin()); 188 return (int) (ptr - fChildren.begin());
189 } 189 }
190 } 190 }
191 *grandList = &fChildren; 191 *grandList = &fChildren;
192 return SkDisplayList::SearchForMatch(match, list, parent, found, grandList); 192 return SkDisplayList::SearchForMatch(match, list, parent, found, grandList);
193 } 193 }
194 194
195 bool SkGroup::hasEnable() const { 195 bool SkGroup::hasEnable() const {
196 return true; 196 return true;
197 } 197 }
198 198
199 bool SkGroup::ifCondition(SkAnimateMaker& maker, SkDrawable*, 199 bool SkGroup::ifCondition(SkAnimateMaker& maker, SkADrawable*,
200 SkString& conditionString) { 200 SkString& conditionString) {
201 if (conditionString.size() == 0) 201 if (conditionString.size() == 0)
202 return true; 202 return true;
203 int32_t result; 203 int32_t result;
204 bool success = SkAnimatorScript::EvaluateInt(maker, this, conditionString.c_ str(), &result); 204 bool success = SkAnimatorScript::EvaluateInt(maker, this, conditionString.c_ str(), &result);
205 #ifdef SK_DUMP_ENABLED 205 #ifdef SK_DUMP_ENABLED
206 if (maker.fDumpGConditions) { 206 if (maker.fDumpGConditions) {
207 SkDebugf("group: "); 207 SkDebugf("group: ");
208 dumpBase(&maker); 208 dumpBase(&maker);
209 SkDebugf("condition=%s ", conditionString.c_str()); 209 SkDebugf("condition=%s ", conditionString.c_str());
210 if (success == false) 210 if (success == false)
211 SkDebugf("(script failed)\n"); 211 SkDebugf("(script failed)\n");
212 else 212 else
213 SkDebugf("success=%s\n", result != 0 ? "true" : "false"); 213 SkDebugf("success=%s\n", result != 0 ? "true" : "false");
214 } 214 }
215 #endif 215 #endif
216 return success && result != 0; 216 return success && result != 0;
217 } 217 }
218 218
219 void SkGroup::initialize() { 219 void SkGroup::initialize() {
220 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 220 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
221 SkDrawable* drawable = *ptr; 221 SkADrawable* drawable = *ptr;
222 if (drawable->isDrawable() == false) 222 if (drawable->isDrawable() == false)
223 continue; 223 continue;
224 drawable->initialize(); 224 drawable->initialize();
225 } 225 }
226 } 226 }
227 227
228 void SkGroup::markCopyClear(int index) { 228 void SkGroup::markCopyClear(int index) {
229 if (index < 0) 229 if (index < 0)
230 index = fChildren.count(); 230 index = fChildren.count();
231 fCopies[index >> 5] &= ~(1 << (index & 0x1f)); 231 fCopies[index >> 5] &= ~(1 << (index & 0x1f));
(...skipping 14 matching lines...) Expand all
246 fCopies.setCount(newLongs); 246 fCopies.setCount(newLongs);
247 memset(&fCopies[oldLongs], 0, (newLongs - oldLongs) << 2); 247 memset(&fCopies[oldLongs], 0, (newLongs - oldLongs) << 2);
248 } 248 }
249 } 249 }
250 250
251 void SkGroup::reset() { 251 void SkGroup::reset() {
252 if (fOriginal) // has been copied 252 if (fOriginal) // has been copied
253 return; 253 return;
254 int index = 0; 254 int index = 0;
255 int max = fCopies.count() << 5; 255 int max = fCopies.count() << 5;
256 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 256 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
257 if (index >= max || copySet(index) == false) 257 if (index >= max || copySet(index) == false)
258 continue; 258 continue;
259 SkApply* apply = (SkApply*) *ptr; 259 SkApply* apply = (SkApply*) *ptr;
260 SkASSERT(apply->isApply()); 260 SkASSERT(apply->isApply());
261 SkASSERT(apply->getScope()); 261 SkASSERT(apply->getScope());
262 *ptr = apply->getScope(); 262 *ptr = apply->getScope();
263 markCopyClear(index); 263 markCopyClear(index);
264 index++; 264 index++;
265 } 265 }
266 } 266 }
267 267
268 bool SkGroup::resolveIDs(SkAnimateMaker& maker, SkDisplayable* orig, SkApply* ap ply) { 268 bool SkGroup::resolveIDs(SkAnimateMaker& maker, SkDisplayable* orig, SkApply* ap ply) {
269 SkGroup* original = (SkGroup*) orig; 269 SkGroup* original = (SkGroup*) orig;
270 SkTDDrawableArray& originalChildren = original->fChildren; 270 SkTDDrawableArray& originalChildren = original->fChildren;
271 SkDrawable** originalPtr = originalChildren.begin(); 271 SkADrawable** originalPtr = originalChildren.begin();
272 SkDrawable** ptr = fChildren.begin(); 272 SkADrawable** ptr = fChildren.begin();
273 SkDrawable** end = fChildren.end(); 273 SkADrawable** end = fChildren.end();
274 SkDrawable** origChild = ((SkGroup*) orig)->fChildren.begin(); 274 SkADrawable** origChild = ((SkGroup*) orig)->fChildren.begin();
275 while (ptr < end) { 275 while (ptr < end) {
276 SkDrawable* drawable = *ptr++; 276 SkADrawable* drawable = *ptr++;
277 maker.resolveID(drawable, *origChild++); 277 maker.resolveID(drawable, *origChild++);
278 if (drawable->resolveIDs(maker, *originalPtr++, apply) == true) 278 if (drawable->resolveIDs(maker, *originalPtr++, apply) == true)
279 return true; // failed 279 return true; // failed
280 } 280 }
281 return false; 281 return false;
282 } 282 }
283 283
284 void SkGroup::setSteps(int steps) { 284 void SkGroup::setSteps(int steps) {
285 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 285 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
286 SkDrawable* drawable = *ptr; 286 SkADrawable* drawable = *ptr;
287 if (drawable->isDrawable() == false) 287 if (drawable->isDrawable() == false)
288 continue; 288 continue;
289 drawable->setSteps(steps); 289 drawable->setSteps(steps);
290 } 290 }
291 } 291 }
292 292
293 #ifdef SK_DEBUG 293 #ifdef SK_DEBUG
294 void SkGroup::validate() { 294 void SkGroup::validate() {
295 for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) { 295 for (SkADrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
296 SkDrawable* drawable = *ptr; 296 SkADrawable* drawable = *ptr;
297 drawable->validate(); 297 drawable->validate();
298 } 298 }
299 } 299 }
300 #endif 300 #endif
301 301
302 #if SK_USE_CONDENSED_INFO == 0 302 #if SK_USE_CONDENSED_INFO == 0
303 303
304 const SkMemberInfo SkSave::fInfo[] = { 304 const SkMemberInfo SkSave::fInfo[] = {
305 SK_MEMBER_INHERITED 305 SK_MEMBER_INHERITED
306 }; 306 };
307 307
308 #endif 308 #endif
309 309
310 DEFINE_GET_MEMBER(SkSave); 310 DEFINE_GET_MEMBER(SkSave);
311 311
312 bool SkSave::draw(SkAnimateMaker& maker) { 312 bool SkSave::draw(SkAnimateMaker& maker) {
313 maker.fCanvas->save(); 313 maker.fCanvas->save();
314 SkPaint* save = maker.fPaint; 314 SkPaint* save = maker.fPaint;
315 SkPaint local = SkPaint(*maker.fPaint); 315 SkPaint local = SkPaint(*maker.fPaint);
316 maker.fPaint = &local; 316 maker.fPaint = &local;
317 bool result = INHERITED::draw(maker); 317 bool result = INHERITED::draw(maker);
318 maker.fPaint = save; 318 maker.fPaint = save;
319 maker.fCanvas->restore(); 319 maker.fCanvas->restore();
320 return result; 320 return result;
321 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698