OLD | NEW |
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 "SkEvent.h" | 10 #include "SkEvent.h" |
11 | 11 |
12 void SkEvent::initialize(const char* type, size_t typeLen, | 12 void SkEvent::initialize(const char* type, size_t typeLen, |
13 SkEventSinkID targetID) { | 13 SkEventSinkID targetID) { |
14 fType = NULL; | 14 fType = nullptr; |
15 setType(type, typeLen); | 15 setType(type, typeLen); |
16 f32 = 0; | 16 f32 = 0; |
17 fTargetID = targetID; | 17 fTargetID = targetID; |
18 fTargetProc = NULL; | 18 fTargetProc = nullptr; |
19 #ifdef SK_DEBUG | 19 #ifdef SK_DEBUG |
20 fTime = 0; | 20 fTime = 0; |
21 fNextEvent = NULL; | 21 fNextEvent = nullptr; |
22 #endif | 22 #endif |
23 } | 23 } |
24 | 24 |
25 SkEvent::SkEvent() | 25 SkEvent::SkEvent() |
26 { | 26 { |
27 initialize("", 0, 0); | 27 initialize("", 0, 0); |
28 } | 28 } |
29 | 29 |
30 SkEvent::SkEvent(const SkEvent& src) | 30 SkEvent::SkEvent(const SkEvent& src) |
31 { | 31 { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 #include "SkParse.h" | 122 #include "SkParse.h" |
123 | 123 |
124 void SkEvent::inflate(const SkDOM& dom, const SkDOM::Node* node) | 124 void SkEvent::inflate(const SkDOM& dom, const SkDOM::Node* node) |
125 { | 125 { |
126 const char* name = dom.findAttr(node, "type"); | 126 const char* name = dom.findAttr(node, "type"); |
127 if (name) | 127 if (name) |
128 this->setType(name); | 128 this->setType(name); |
129 | 129 |
130 const char* value; | 130 const char* value; |
131 if ((value = dom.findAttr(node, "fast32")) != NULL) | 131 if ((value = dom.findAttr(node, "fast32")) != nullptr) |
132 { | 132 { |
133 int32_t n; | 133 int32_t n; |
134 if (SkParse::FindS32(value, &n)) | 134 if (SkParse::FindS32(value, &n)) |
135 this->setFast32(n); | 135 this->setFast32(n); |
136 } | 136 } |
137 | 137 |
138 for (node = dom.getFirstChild(node); node; node = dom.getNextSibling(node)) | 138 for (node = dom.getFirstChild(node); node; node = dom.getNextSibling(node)) |
139 { | 139 { |
140 if (strcmp(dom.getName(node), "data")) | 140 if (strcmp(dom.getName(node), "data")) |
141 { | 141 { |
142 SkDEBUGCODE(SkDebugf("SkEvent::inflate unrecognized subelement <%s>\
n", dom.getName(node));) | 142 SkDEBUGCODE(SkDebugf("SkEvent::inflate unrecognized subelement <%s>\
n", dom.getName(node));) |
143 continue; | 143 continue; |
144 } | 144 } |
145 | 145 |
146 name = dom.findAttr(node, "name"); | 146 name = dom.findAttr(node, "name"); |
147 if (name == NULL) | 147 if (name == nullptr) |
148 { | 148 { |
149 SkDEBUGCODE(SkDebugf("SkEvent::inflate missing required \"name\" att
ribute in <data> subelement\n");) | 149 SkDEBUGCODE(SkDebugf("SkEvent::inflate missing required \"name\" att
ribute in <data> subelement\n");) |
150 continue; | 150 continue; |
151 } | 151 } |
152 | 152 |
153 if ((value = dom.findAttr(node, "s32")) != NULL) | 153 if ((value = dom.findAttr(node, "s32")) != nullptr) |
154 { | 154 { |
155 int32_t n; | 155 int32_t n; |
156 if (SkParse::FindS32(value, &n)) | 156 if (SkParse::FindS32(value, &n)) |
157 this->setS32(name, n); | 157 this->setS32(name, n); |
158 } | 158 } |
159 else if ((value = dom.findAttr(node, "scalar")) != NULL) | 159 else if ((value = dom.findAttr(node, "scalar")) != nullptr) |
160 { | 160 { |
161 SkScalar x; | 161 SkScalar x; |
162 if (SkParse::FindScalar(value, &x)) | 162 if (SkParse::FindScalar(value, &x)) |
163 this->setScalar(name, x); | 163 this->setScalar(name, x); |
164 } | 164 } |
165 else if ((value = dom.findAttr(node, "string")) != NULL) | 165 else if ((value = dom.findAttr(node, "string")) != nullptr) |
166 this->setString(name, value); | 166 this->setString(name, value); |
167 #ifdef SK_DEBUG | 167 #ifdef SK_DEBUG |
168 else | 168 else |
169 { | 169 { |
170 SkDebugf("SkEvent::inflate <data name=\"%s\"> subelement missing req
uired type attribute [S32 | scalar | string]\n", name); | 170 SkDebugf("SkEvent::inflate <data name=\"%s\"> subelement missing req
uired type attribute [S32 | scalar | string]\n", name); |
171 } | 171 } |
172 #endif | 172 #endif |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
(...skipping 11 matching lines...) Expand all Loading... |
187 SkString etype; | 187 SkString etype; |
188 this->getType(&etype); | 188 this->getType(&etype); |
189 SkDebugf("event<%s> fast32=%d", etype.c_str(), this->getFast32()); | 189 SkDebugf("event<%s> fast32=%d", etype.c_str(), this->getFast32()); |
190 | 190 |
191 const SkMetaData& md = this->getMetaData(); | 191 const SkMetaData& md = this->getMetaData(); |
192 SkMetaData::Iter iter(md); | 192 SkMetaData::Iter iter(md); |
193 SkMetaData::Type mtype; | 193 SkMetaData::Type mtype; |
194 int count; | 194 int count; |
195 const char* name; | 195 const char* name; |
196 | 196 |
197 while ((name = iter.next(&mtype, &count)) != NULL) | 197 while ((name = iter.next(&mtype, &count)) != nullptr) |
198 { | 198 { |
199 SkASSERT(count > 0); | 199 SkASSERT(count > 0); |
200 | 200 |
201 SkDebugf(" <%s>=", name); | 201 SkDebugf(" <%s>=", name); |
202 switch (mtype) { | 202 switch (mtype) { |
203 case SkMetaData::kS32_Type: // vector version??? | 203 case SkMetaData::kS32_Type: // vector version??? |
204 { | 204 { |
205 int32_t value; | 205 int32_t value; |
206 md.findS32(name, &value); | 206 md.findS32(name, &value); |
207 SkDebugf("%d ", value); | 207 SkDebugf("%d ", value); |
208 } | 208 } |
209 break; | 209 break; |
210 case SkMetaData::kScalar_Type: | 210 case SkMetaData::kScalar_Type: |
211 { | 211 { |
212 const SkScalar* values = md.findScalars(name, &count, NULL); | 212 const SkScalar* values = md.findScalars(name, &count, nullpt
r); |
213 SkDebugf("%f", SkScalarToFloat(values[0])); | 213 SkDebugf("%f", SkScalarToFloat(values[0])); |
214 for (int i = 1; i < count; i++) | 214 for (int i = 1; i < count; i++) |
215 SkDebugf(", %f", SkScalarToFloat(values[i])); | 215 SkDebugf(", %f", SkScalarToFloat(values[i])); |
216 SkDebugf(" "); | 216 SkDebugf(" "); |
217 } | 217 } |
218 break; | 218 break; |
219 case SkMetaData::kString_Type: | 219 case SkMetaData::kString_Type: |
220 { | 220 { |
221 const char* value = md.findString(name); | 221 const char* value = md.findString(name); |
222 SkASSERT(value); | 222 SkASSERT(value); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 #define EVENT_LOG(s) | 264 #define EVENT_LOG(s) |
265 #define EVENT_LOGN(s, n) | 265 #define EVENT_LOGN(s, n) |
266 #endif | 266 #endif |
267 | 267 |
268 #include "SkMutex.h" | 268 #include "SkMutex.h" |
269 #include "SkTime.h" | 269 #include "SkTime.h" |
270 | 270 |
271 class SkEvent_Globals { | 271 class SkEvent_Globals { |
272 public: | 272 public: |
273 SkEvent_Globals() { | 273 SkEvent_Globals() { |
274 fEventQHead = NULL; | 274 fEventQHead = nullptr; |
275 fEventQTail = NULL; | 275 fEventQTail = nullptr; |
276 fDelayQHead = NULL; | 276 fDelayQHead = nullptr; |
277 SkDEBUGCODE(fEventCounter = 0;) | 277 SkDEBUGCODE(fEventCounter = 0;) |
278 } | 278 } |
279 | 279 |
280 SkMutex fEventMutex; | 280 SkMutex fEventMutex; |
281 SkEvent* fEventQHead, *fEventQTail; | 281 SkEvent* fEventQHead, *fEventQTail; |
282 SkEvent* fDelayQHead; | 282 SkEvent* fDelayQHead; |
283 SkDEBUGCODE(int fEventCounter;) | 283 SkDEBUGCODE(int fEventCounter;) |
284 }; | 284 }; |
285 | 285 |
286 static SkEvent_Globals& getGlobals() { | 286 static SkEvent_Globals& getGlobals() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 SkEvent::SignalQueueTimer(queueDelay); | 331 SkEvent::SignalQueueTimer(queueDelay); |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 bool SkEvent::Enqueue(SkEvent* evt) { | 335 bool SkEvent::Enqueue(SkEvent* evt) { |
336 SkEvent_Globals& globals = getGlobals(); | 336 SkEvent_Globals& globals = getGlobals(); |
337 // gEventMutex acquired by caller | 337 // gEventMutex acquired by caller |
338 | 338 |
339 SkASSERT(evt); | 339 SkASSERT(evt); |
340 | 340 |
341 bool wasEmpty = globals.fEventQHead == NULL; | 341 bool wasEmpty = globals.fEventQHead == nullptr; |
342 | 342 |
343 if (globals.fEventQTail) | 343 if (globals.fEventQTail) |
344 globals.fEventQTail->fNextEvent = evt; | 344 globals.fEventQTail->fNextEvent = evt; |
345 globals.fEventQTail = evt; | 345 globals.fEventQTail = evt; |
346 if (globals.fEventQHead == NULL) | 346 if (globals.fEventQHead == nullptr) |
347 globals.fEventQHead = evt; | 347 globals.fEventQHead = evt; |
348 evt->fNextEvent = NULL; | 348 evt->fNextEvent = nullptr; |
349 | 349 |
350 SkDEBUGCODE(++globals.fEventCounter); | 350 SkDEBUGCODE(++globals.fEventCounter); |
351 | 351 |
352 return wasEmpty; | 352 return wasEmpty; |
353 } | 353 } |
354 | 354 |
355 SkEvent* SkEvent::Dequeue() { | 355 SkEvent* SkEvent::Dequeue() { |
356 SkEvent_Globals& globals = getGlobals(); | 356 SkEvent_Globals& globals = getGlobals(); |
357 globals.fEventMutex.acquire(); | 357 globals.fEventMutex.acquire(); |
358 | 358 |
359 SkEvent* evt = globals.fEventQHead; | 359 SkEvent* evt = globals.fEventQHead; |
360 if (evt) { | 360 if (evt) { |
361 SkDEBUGCODE(--globals.fEventCounter); | 361 SkDEBUGCODE(--globals.fEventCounter); |
362 | 362 |
363 globals.fEventQHead = evt->fNextEvent; | 363 globals.fEventQHead = evt->fNextEvent; |
364 if (globals.fEventQHead == NULL) { | 364 if (globals.fEventQHead == nullptr) { |
365 globals.fEventQTail = NULL; | 365 globals.fEventQTail = nullptr; |
366 } | 366 } |
367 } | 367 } |
368 globals.fEventMutex.release(); | 368 globals.fEventMutex.release(); |
369 | 369 |
370 return evt; | 370 return evt; |
371 } | 371 } |
372 | 372 |
373 bool SkEvent::QHasEvents() { | 373 bool SkEvent::QHasEvents() { |
374 SkEvent_Globals& globals = getGlobals(); | 374 SkEvent_Globals& globals = getGlobals(); |
375 | 375 |
376 // this is not thread accurate, need a semaphore for that | 376 // this is not thread accurate, need a semaphore for that |
377 return globals.fEventQHead != NULL; | 377 return globals.fEventQHead != nullptr; |
378 } | 378 } |
379 | 379 |
380 #ifdef SK_TRACE_EVENTS | 380 #ifdef SK_TRACE_EVENTS |
381 static int gDelayDepth; | 381 static int gDelayDepth; |
382 #endif | 382 #endif |
383 | 383 |
384 SkMSec SkEvent::EnqueueTime(SkEvent* evt, SkMSec time) { | 384 SkMSec SkEvent::EnqueueTime(SkEvent* evt, SkMSec time) { |
385 SkEvent_Globals& globals = getGlobals(); | 385 SkEvent_Globals& globals = getGlobals(); |
386 // gEventMutex acquired by caller | 386 // gEventMutex acquired by caller |
387 | 387 |
388 SkEvent* curr = globals.fDelayQHead; | 388 SkEvent* curr = globals.fDelayQHead; |
389 SkEvent* prev = NULL; | 389 SkEvent* prev = nullptr; |
390 | 390 |
391 while (curr) { | 391 while (curr) { |
392 if (SkMSec_LT(time, curr->fTime)) { | 392 if (SkMSec_LT(time, curr->fTime)) { |
393 break; | 393 break; |
394 } | 394 } |
395 prev = curr; | 395 prev = curr; |
396 curr = curr->fNextEvent; | 396 curr = curr->fNextEvent; |
397 } | 397 } |
398 | 398 |
399 evt->fTime = time; | 399 evt->fTime = time; |
400 evt->fNextEvent = curr; | 400 evt->fNextEvent = curr; |
401 if (prev == NULL) { | 401 if (prev == nullptr) { |
402 globals.fDelayQHead = evt; | 402 globals.fDelayQHead = evt; |
403 } else { | 403 } else { |
404 prev->fNextEvent = evt; | 404 prev->fNextEvent = evt; |
405 } | 405 } |
406 | 406 |
407 SkMSec delay = globals.fDelayQHead->fTime - SkTime::GetMSecs(); | 407 SkMSec delay = globals.fDelayQHead->fTime - SkTime::GetMSecs(); |
408 if ((int32_t)delay <= 0) { | 408 if ((int32_t)delay <= 0) { |
409 delay = 1; | 409 delay = 1; |
410 } | 410 } |
411 return delay; | 411 return delay; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 evt = next; | 499 evt = next; |
500 } | 500 } |
501 | 501 |
502 evt = globals.fDelayQHead; | 502 evt = globals.fDelayQHead; |
503 while (evt) { | 503 while (evt) { |
504 SkEvent* next = evt->fNextEvent; | 504 SkEvent* next = evt->fNextEvent; |
505 delete evt; | 505 delete evt; |
506 evt = next; | 506 evt = next; |
507 } | 507 } |
508 } | 508 } |
OLD | NEW |