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

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

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 | « src/animator/SkAnimatorScript.cpp ('k') | src/animator/SkBoundable.cpp » ('j') | 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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
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 #include "SkAnimatorScript2.h" 8 #include "SkAnimatorScript2.h"
9 #include "SkAnimateBase.h" 9 #include "SkAnimateBase.h"
10 #include "SkAnimateMaker.h" 10 #include "SkAnimateMaker.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 bool getMemberReference(const char* member, size_t len, void* object, SkScri ptValue2* ref) { 198 bool getMemberReference(const char* member, size_t len, void* object, SkScri ptValue2* ref) {
199 SkDisplayable* displayable = (SkDisplayable*) object; 199 SkDisplayable* displayable = (SkDisplayable*) object;
200 SkString name(member, len); 200 SkString name(member, len);
201 SkDisplayable* named = displayable->contains(name); 201 SkDisplayable* named = displayable->contains(name);
202 if (named) { 202 if (named) {
203 ref->fType = SkOperand2::kObject; 203 ref->fType = SkOperand2::kObject;
204 ref->fOperand.fObject = named; 204 ref->fOperand.fObject = named;
205 return true; 205 return true;
206 } 206 }
207 const SkMemberInfo* info = displayable->getMember(name.c_str()); 207 const SkMemberInfo* info = displayable->getMember(name.c_str());
208 if (info == NULL) 208 if (info == nullptr)
209 return false; // !!! add additional error info? 209 return false; // !!! add additional error info?
210 ref->fType = SkAnimatorScript2::ToOpType(info->getType()); 210 ref->fType = SkAnimatorScript2::ToOpType(info->getType());
211 ref->fOperand.fObject = (void*) info; 211 ref->fOperand.fObject = (void*) info;
212 return true; 212 return true;
213 } 213 }
214 214
215 bool invoke(size_t ref, void* object, SkOperand2* value) { 215 bool invoke(size_t ref, void* object, SkOperand2* value) {
216 const SkMemberInfo* info = (const SkMemberInfo* ) ref; 216 const SkMemberInfo* info = (const SkMemberInfo* ) ref;
217 SkDisplayable* displayable = (SkDisplayable*) object; 217 SkDisplayable* displayable = (SkDisplayable*) object;
218 if (info->fType == SkType_MemberProperty) { 218 if (info->fType == SkType_MemberProperty) {
219 if (displayable->getProperty2(info->propertyIndex(), value) == false ) { 219 if (displayable->getProperty2(info->propertyIndex(), value) == false ) {
220 return false; 220 return false;
221 } 221 }
222 } 222 }
223 return fEngine->evalMemberCommon(info, displayable, value); 223 return fEngine->evalMemberCommon(info, displayable, value);
224 } 224 }
225 225
226 SkAnimatorScript2* fEngine; 226 SkAnimatorScript2* fEngine;
227 }; 227 };
228 228
229 229
230 class SkAnimatorScript_MemberFunction : public SkScriptCallBackMemberFunction { 230 class SkAnimatorScript_MemberFunction : public SkScriptCallBackMemberFunction {
231 public: 231 public:
232 SkAnimatorScript_MemberFunction(SkAnimatorScript2* engine) : fEngine(engine) {} 232 SkAnimatorScript_MemberFunction(SkAnimatorScript2* engine) : fEngine(engine) {}
233 233
234 bool getMemberReference(const char* member, size_t len, void* object, SkScri ptValue2* ref) { 234 bool getMemberReference(const char* member, size_t len, void* object, SkScri ptValue2* ref) {
235 SkDisplayable* displayable = (SkDisplayable*) object; 235 SkDisplayable* displayable = (SkDisplayable*) object;
236 SkString name(member, len); 236 SkString name(member, len);
237 const SkMemberInfo* info = displayable->getMember(name.c_str()); 237 const SkMemberInfo* info = displayable->getMember(name.c_str());
238 if (info == NULL || info->fType != SkType_MemberFunction) 238 if (info == nullptr || info->fType != SkType_MemberFunction)
239 return false; // !!! add additional error info? 239 return false; // !!! add additional error info?
240 ref->fType = SkAnimatorScript2::ToOpType(info->getType()); 240 ref->fType = SkAnimatorScript2::ToOpType(info->getType());
241 ref->fOperand.fObject = (void*) info; 241 ref->fOperand.fObject = (void*) info;
242 return true; 242 return true;
243 } 243 }
244 244
245 virtual void getParamTypes(SkIntArray(SkOperand2::OpType)* types) { 245 virtual void getParamTypes(SkIntArray(SkOperand2::OpType)* types) {
246 types->setCount(3); 246 types->setCount(3);
247 SkOperand2::OpType* type = types->begin(); 247 SkOperand2::OpType* type = types->begin();
248 type[0] = type[1] = type[2] = SkOperand2::kS32; 248 type[0] = type[1] = type[2] = SkOperand2::kS32;
249 } 249 }
250 250
251 bool invoke(size_t ref, void* object, SkOpArray* params, SkOperand2* value) 251 bool invoke(size_t ref, void* object, SkOpArray* params, SkOperand2* value)
252 { 252 {
253 const SkMemberInfo* info = (const SkMemberInfo* ) ref; 253 const SkMemberInfo* info = (const SkMemberInfo* ) ref;
254 SkDisplayable* displayable = (SkDisplayable*) object; 254 SkDisplayable* displayable = (SkDisplayable*) object;
255 displayable->executeFunction2(displayable, info->functionIndex(), params , info->getType(), 255 displayable->executeFunction2(displayable, info->functionIndex(), params , info->getType(),
256 value); 256 value);
257 return fEngine->evalMemberCommon(info, displayable, value); 257 return fEngine->evalMemberCommon(info, displayable, value);
258 } 258 }
259 259
260 SkAnimatorScript2* fEngine; 260 SkAnimatorScript2* fEngine;
261 }; 261 };
262 262
263 263
264 class SkAnimatorScript_NamedColor : public SkScriptCallBackProperty { 264 class SkAnimatorScript_NamedColor : public SkScriptCallBackProperty {
265 public: 265 public:
266 virtual bool getConstValue(const char* name, int len, SkOperand2* value) { 266 virtual bool getConstValue(const char* name, int len, SkOperand2* value) {
267 return SkParse::FindNamedColor(name, len, (SkColor*) &value->fS32) != NU LL; 267 return SkParse::FindNamedColor(name, len, (SkColor*) &value->fS32) != nu llptr;
268 } 268 }
269 }; 269 };
270 270
271 271
272 class SkAnimatorScript_RGB : public SkScriptCallBackFunction { 272 class SkAnimatorScript_RGB : public SkScriptCallBackFunction {
273 public: 273 public:
274 virtual bool getIndex(const char* name, int len, size_t* result) { 274 virtual bool getIndex(const char* name, int len, size_t* result) {
275 if (SK_LITERAL_STR_EQUAL("rgb", name, len) != 0) 275 if (SK_LITERAL_STR_EQUAL("rgb", name, len) != 0)
276 return false; 276 return false;
277 *result = 0; 277 *result = 0;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 return SkType_Array; 467 return SkType_Array;
468 case SkOperand2::kObject: 468 case SkOperand2::kObject:
469 return SkType_Displayable; 469 return SkType_Displayable;
470 default: 470 default:
471 SkASSERT(0); 471 SkASSERT(0);
472 return SkType_Unknown; 472 return SkType_Unknown;
473 } 473 }
474 } 474 }
475 475
476 SkOperand2::OpType SkAnimatorScript2::ToOpType(SkDisplayTypes type) { 476 SkOperand2::OpType SkAnimatorScript2::ToOpType(SkDisplayTypes type) {
477 if (SkDisplayType::IsDisplayable(NULL /* fMaker */, type)) 477 if (SkDisplayType::IsDisplayable(nullptr /* fMaker */, type))
478 return SkOperand2::kObject; 478 return SkOperand2::kObject;
479 if (SkDisplayType::IsEnum(NULL /* fMaker */, type)) 479 if (SkDisplayType::IsEnum(nullptr /* fMaker */, type))
480 return SkOperand2::kS32; 480 return SkOperand2::kS32;
481 switch (type) { 481 switch (type) {
482 case SkType_ARGB: 482 case SkType_ARGB:
483 case SkType_MSec: 483 case SkType_MSec:
484 case SkType_Int: 484 case SkType_Int:
485 return SkOperand2::kS32; 485 return SkOperand2::kS32;
486 case SkType_Float: 486 case SkType_Float:
487 case SkType_Point: 487 case SkType_Point:
488 case SkType_3D_Point: 488 case SkType_3D_Point:
489 return SkOperand2::kScalar; 489 return SkOperand2::kScalar;
490 case SkType_Base64: 490 case SkType_Base64:
491 case SkType_DynamicString: 491 case SkType_DynamicString:
492 case SkType_String: 492 case SkType_String:
493 return SkOperand2::kString; 493 return SkOperand2::kString;
494 case SkType_Array: 494 case SkType_Array:
495 return SkOperand2::kArray; 495 return SkOperand2::kArray;
496 case SkType_Unknown: 496 case SkType_Unknown:
497 return SkOperand2::kNoType; 497 return SkOperand2::kNoType;
498 default: 498 default:
499 SkASSERT(0); 499 SkASSERT(0);
500 return SkOperand2::kNoType; 500 return SkOperand2::kNoType;
501 } 501 }
502 } 502 }
503 503
504 bool SkAnimatorScript2::MapEnums(const char* ptr, const char* match, size_t len, int* value) { 504 bool SkAnimatorScript2::MapEnums(const char* ptr, const char* match, size_t len, int* value) {
505 int index = 0; 505 int index = 0;
506 bool more = true; 506 bool more = true;
507 do { 507 do {
508 const char* last = strchr(ptr, '|'); 508 const char* last = strchr(ptr, '|');
509 if (last == NULL) { 509 if (last == nullptr) {
510 last = &ptr[strlen(ptr)]; 510 last = &ptr[strlen(ptr)];
511 more = false; 511 more = false;
512 } 512 }
513 size_t length = last - ptr; 513 size_t length = last - ptr;
514 if (len == length && strncmp(ptr, match, length) == 0) { 514 if (len == length && strncmp(ptr, match, length) == 0) {
515 *value = index; 515 *value = index;
516 return true; 516 return true;
517 } 517 }
518 index++; 518 index++;
519 ptr = last + 1; 519 ptr = last + 1;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 void SkAnimatorScript2::UnitTest() { 584 void SkAnimatorScript2::UnitTest() {
585 #if defined(SK_SUPPORT_UNITTEST) 585 #if defined(SK_SUPPORT_UNITTEST)
586 SkAnimator animator; 586 SkAnimator animator;
587 SkASSERT(animator.decodeMemory(scriptTestSetup, sizeof(scriptTestSetup)-1)); 587 SkASSERT(animator.decodeMemory(scriptTestSetup, sizeof(scriptTestSetup)-1));
588 SkEvent evt; 588 SkEvent evt;
589 evt.setString("id", "evt"); 589 evt.setString("id", "evt");
590 evt.setS32("x", 3); 590 evt.setS32("x", 3);
591 animator.doUserEvent(evt); 591 animator.doUserEvent(evt);
592 // set up animator with memory script above, then run value tests 592 // set up animator with memory script above, then run value tests
593 for (int index = 0; index < SkScriptNAnswer_testCount; index++) { 593 for (int index = 0; index < SkScriptNAnswer_testCount; index++) {
594 SkAnimatorScript2 engine(*animator.fMaker, NULL, scriptTests[index].fTyp e); 594 SkAnimatorScript2 engine(*animator.fMaker, nullptr, scriptTests[index].f Type);
595 SkScriptValue2 value; 595 SkScriptValue2 value;
596 const char* script = scriptTests[index].fScript; 596 const char* script = scriptTests[index].fScript;
597 bool success = engine.evaluateScript(&script, &value); 597 bool success = engine.evaluateScript(&script, &value);
598 if (success == false) { 598 if (success == false) {
599 SkASSERT(scriptTests[index].fType == SkType_Unknown); 599 SkASSERT(scriptTests[index].fType == SkType_Unknown);
600 continue; 600 continue;
601 } 601 }
602 SkASSERT(value.fType == ToOpType(scriptTests[index].fType)); 602 SkASSERT(value.fType == ToOpType(scriptTests[index].fType));
603 SkScalar error; 603 SkScalar error;
604 switch (value.fType) { 604 switch (value.fType) {
605 case SkOperand2::kS32: 605 case SkOperand2::kS32:
606 SkASSERT(value.fOperand.fS32 == scriptTests[index].fIntAnswer); 606 SkASSERT(value.fOperand.fS32 == scriptTests[index].fIntAnswer);
607 break; 607 break;
608 case SkOperand2::kScalar: 608 case SkOperand2::kScalar:
609 error = SkScalarAbs(value.fOperand.fScalar - scriptTests[index]. fScalarAnswer); 609 error = SkScalarAbs(value.fOperand.fScalar - scriptTests[index]. fScalarAnswer);
610 SkASSERT(error < SK_Scalar1 / 10000); 610 SkASSERT(error < SK_Scalar1 / 10000);
611 break; 611 break;
612 case SkOperand2::kString: 612 case SkOperand2::kString:
613 SkASSERT(value.fOperand.fString->equals(scriptTests[index].fStri ngAnswer)); 613 SkASSERT(value.fOperand.fString->equals(scriptTests[index].fStri ngAnswer));
614 break; 614 break;
615 default: 615 default:
616 SkASSERT(0); 616 SkASSERT(0);
617 } 617 }
618 } 618 }
619 #endif 619 #endif
620 } 620 }
621 621
622 #endif 622 #endif
OLDNEW
« no previous file with comments | « src/animator/SkAnimatorScript.cpp ('k') | src/animator/SkBoundable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698