Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #include "SkMemberInfo.h" |
michael@0 | 11 | #include "SkAnimateMaker.h" |
michael@0 | 12 | #include "SkAnimatorScript.h" |
michael@0 | 13 | #include "SkBase64.h" |
michael@0 | 14 | #include "SkCamera.h" |
michael@0 | 15 | #include "SkDisplayable.h" |
michael@0 | 16 | #include "SkDisplayTypes.h" |
michael@0 | 17 | #include "SkDraw3D.h" |
michael@0 | 18 | #include "SkDrawColor.h" |
michael@0 | 19 | #include "SkParse.h" |
michael@0 | 20 | #include "SkScript.h" |
michael@0 | 21 | #include "SkTSearch.h" |
michael@0 | 22 | #include "SkTypedArray.h" |
michael@0 | 23 | |
michael@0 | 24 | size_t SkMemberInfo::GetSize(SkDisplayTypes type) { // size of simple types only |
michael@0 | 25 | size_t byteSize; |
michael@0 | 26 | switch (type) { |
michael@0 | 27 | case SkType_ARGB: |
michael@0 | 28 | byteSize = sizeof(SkColor); |
michael@0 | 29 | break; |
michael@0 | 30 | case SkType_AddMode: |
michael@0 | 31 | case SkType_Align: |
michael@0 | 32 | case SkType_ApplyMode: |
michael@0 | 33 | case SkType_ApplyTransition: |
michael@0 | 34 | case SkType_BitmapEncoding: |
michael@0 | 35 | case SkType_Boolean: |
michael@0 | 36 | case SkType_Cap: |
michael@0 | 37 | case SkType_EventCode: |
michael@0 | 38 | case SkType_EventKind: |
michael@0 | 39 | case SkType_EventMode: |
michael@0 | 40 | case SkType_FilterType: |
michael@0 | 41 | case SkType_FontStyle: |
michael@0 | 42 | case SkType_FromPathMode: |
michael@0 | 43 | case SkType_Join: |
michael@0 | 44 | case SkType_MaskFilterBlurStyle: |
michael@0 | 45 | case SkType_PathDirection: |
michael@0 | 46 | case SkType_Style: |
michael@0 | 47 | case SkType_TileMode: |
michael@0 | 48 | case SkType_Xfermode: |
michael@0 | 49 | byteSize = sizeof(int); |
michael@0 | 50 | break; |
michael@0 | 51 | case SkType_Base64: // assume base64 data is always const, copied by ref |
michael@0 | 52 | case SkType_Displayable: |
michael@0 | 53 | case SkType_Drawable: |
michael@0 | 54 | case SkType_Matrix: |
michael@0 | 55 | byteSize = sizeof(void*); |
michael@0 | 56 | break; |
michael@0 | 57 | case SkType_MSec: |
michael@0 | 58 | byteSize = sizeof(SkMSec); |
michael@0 | 59 | break; |
michael@0 | 60 | case SkType_Point: |
michael@0 | 61 | byteSize = sizeof(SkPoint); |
michael@0 | 62 | break; |
michael@0 | 63 | case SkType_3D_Point: |
michael@0 | 64 | byteSize = sizeof(Sk3D_Point); |
michael@0 | 65 | break; |
michael@0 | 66 | case SkType_Int: |
michael@0 | 67 | byteSize = sizeof(int32_t); |
michael@0 | 68 | break; |
michael@0 | 69 | case SkType_Float: |
michael@0 | 70 | byteSize = sizeof(SkScalar); |
michael@0 | 71 | break; |
michael@0 | 72 | case SkType_DynamicString: |
michael@0 | 73 | case SkType_String: |
michael@0 | 74 | byteSize = sizeof(SkString); // assume we'll copy by reference, not value |
michael@0 | 75 | break; |
michael@0 | 76 | default: |
michael@0 | 77 | // SkASSERT(0); |
michael@0 | 78 | byteSize = 0; |
michael@0 | 79 | } |
michael@0 | 80 | return byteSize; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | bool SkMemberInfo::getArrayValue(const SkDisplayable* displayable, int index, SkOperand* value) const { |
michael@0 | 84 | SkASSERT(fType != SkType_String && fType != SkType_MemberProperty); |
michael@0 | 85 | char* valuePtr = (char*) *(SkOperand**) memberData(displayable); |
michael@0 | 86 | SkDisplayTypes type = (SkDisplayTypes) 0; |
michael@0 | 87 | if (displayable->getType() == SkType_Array) { |
michael@0 | 88 | SkDisplayArray* dispArray = (SkDisplayArray*) displayable; |
michael@0 | 89 | if (dispArray->values.count() <= index) |
michael@0 | 90 | return false; |
michael@0 | 91 | type = dispArray->values.getType(); |
michael@0 | 92 | } else { |
michael@0 | 93 | SkASSERT(0); // incomplete |
michael@0 | 94 | } |
michael@0 | 95 | size_t byteSize = GetSize(type); |
michael@0 | 96 | memcpy(value, valuePtr + index * byteSize, byteSize); |
michael@0 | 97 | return true; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | size_t SkMemberInfo::getSize(const SkDisplayable* displayable) const { |
michael@0 | 101 | size_t byteSize; |
michael@0 | 102 | switch (fType) { |
michael@0 | 103 | case SkType_MemberProperty: |
michael@0 | 104 | byteSize = GetSize(propertyType()); |
michael@0 | 105 | break; |
michael@0 | 106 | case SkType_Array: { |
michael@0 | 107 | SkDisplayTypes type; |
michael@0 | 108 | if (displayable == NULL) |
michael@0 | 109 | return sizeof(int); |
michael@0 | 110 | if (displayable->getType() == SkType_Array) { |
michael@0 | 111 | SkDisplayArray* dispArray = (SkDisplayArray*) displayable; |
michael@0 | 112 | type = dispArray->values.getType(); |
michael@0 | 113 | } else |
michael@0 | 114 | type = propertyType(); |
michael@0 | 115 | SkTDOperandArray* array = (SkTDOperandArray*) memberData(displayable); |
michael@0 | 116 | byteSize = GetSize(type) * array->count(); |
michael@0 | 117 | } break; |
michael@0 | 118 | default: |
michael@0 | 119 | byteSize = GetSize((SkDisplayTypes) fType); |
michael@0 | 120 | } |
michael@0 | 121 | return byteSize; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | void SkMemberInfo::getString(const SkDisplayable* displayable, SkString** string) const { |
michael@0 | 125 | if (fType == SkType_MemberProperty) { |
michael@0 | 126 | SkScriptValue value; |
michael@0 | 127 | displayable->getProperty(propertyIndex(), &value); |
michael@0 | 128 | SkASSERT(value.fType == SkType_String); |
michael@0 | 129 | *string = value.fOperand.fString; |
michael@0 | 130 | return; |
michael@0 | 131 | } |
michael@0 | 132 | SkASSERT(fCount == sizeof(SkString) / sizeof(SkScalar)); |
michael@0 | 133 | SkASSERT(fType == SkType_String || fType == SkType_DynamicString); |
michael@0 | 134 | void* valuePtr = memberData(displayable); |
michael@0 | 135 | *string = (SkString*) valuePtr; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | void SkMemberInfo::getValue(const SkDisplayable* displayable, SkOperand value[], int count) const { |
michael@0 | 139 | SkASSERT(fType != SkType_String && fType != SkType_MemberProperty); |
michael@0 | 140 | SkASSERT(count == fCount); |
michael@0 | 141 | void* valuePtr = memberData(displayable); |
michael@0 | 142 | size_t byteSize = getSize(displayable); |
michael@0 | 143 | SkASSERT(sizeof(value[0].fScalar) == sizeof(value[0])); // no support for 64 bit pointers, yet |
michael@0 | 144 | memcpy(value, valuePtr, byteSize); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | void SkMemberInfo::setString(SkDisplayable* displayable, SkString* value) const { |
michael@0 | 148 | SkString* string = (SkString*) memberData(displayable); |
michael@0 | 149 | string->set(*value); |
michael@0 | 150 | displayable->dirty(); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | void SkMemberInfo::setValue(SkDisplayable* displayable, const SkOperand values[], |
michael@0 | 154 | int count) const { |
michael@0 | 155 | SkASSERT(sizeof(values[0].fScalar) == sizeof(values[0])); // no support for 64 bit pointers, yet |
michael@0 | 156 | char* dst = (char*) memberData(displayable); |
michael@0 | 157 | if (fType == SkType_Array) { |
michael@0 | 158 | SkTDScalarArray* array = (SkTDScalarArray* ) dst; |
michael@0 | 159 | array->setCount(count); |
michael@0 | 160 | dst = (char*) array->begin(); |
michael@0 | 161 | } |
michael@0 | 162 | memcpy(dst, values, count * sizeof(SkOperand)); |
michael@0 | 163 | displayable->dirty(); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | |
michael@0 | 167 | static inline bool is_between(int c, int min, int max) |
michael@0 | 168 | { |
michael@0 | 169 | return (unsigned)(c - min) <= (unsigned)(max - min); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | static inline bool is_hex(int c) |
michael@0 | 173 | { |
michael@0 | 174 | if (is_between(c, '0', '9')) |
michael@0 | 175 | return true; |
michael@0 | 176 | c |= 0x20; // make us lower-case |
michael@0 | 177 | if (is_between(c, 'a', 'f')) |
michael@0 | 178 | return true; |
michael@0 | 179 | return false; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | |
michael@0 | 183 | bool SkMemberInfo::setValue(SkAnimateMaker& maker, SkTDOperandArray* arrayStorage, |
michael@0 | 184 | int storageOffset, int maxStorage, SkDisplayable* displayable, SkDisplayTypes outType, |
michael@0 | 185 | const char rawValue[], size_t rawValueLen) const |
michael@0 | 186 | { |
michael@0 | 187 | SkString valueStr(rawValue, rawValueLen); |
michael@0 | 188 | SkScriptValue scriptValue; |
michael@0 | 189 | scriptValue.fType = SkType_Unknown; |
michael@0 | 190 | scriptValue.fOperand.fS32 = 0; |
michael@0 | 191 | SkDisplayTypes type = getType(); |
michael@0 | 192 | SkAnimatorScript engine(maker, displayable, type); |
michael@0 | 193 | if (arrayStorage) |
michael@0 | 194 | displayable = NULL; |
michael@0 | 195 | bool success = true; |
michael@0 | 196 | void* untypedStorage = NULL; |
michael@0 | 197 | if (displayable && fType != SkType_MemberProperty && fType != SkType_MemberFunction) |
michael@0 | 198 | untypedStorage = (SkTDOperandArray*) memberData(displayable); |
michael@0 | 199 | |
michael@0 | 200 | if (type == SkType_ARGB) { |
michael@0 | 201 | // for both SpiderMonkey and SkiaScript, substitute any #xyz or #xxyyzz first |
michael@0 | 202 | // it's enough to expand the colors into 0xFFxxyyzz |
michael@0 | 203 | const char* poundPos; |
michael@0 | 204 | while ((poundPos = strchr(valueStr.c_str(), '#')) != NULL) { |
michael@0 | 205 | size_t offset = poundPos - valueStr.c_str(); |
michael@0 | 206 | if (valueStr.size() - offset < 4) |
michael@0 | 207 | break; |
michael@0 | 208 | char r = poundPos[1]; |
michael@0 | 209 | char g = poundPos[2]; |
michael@0 | 210 | char b = poundPos[3]; |
michael@0 | 211 | if (is_hex(r) == false || is_hex(g) == false || is_hex(b) == false) |
michael@0 | 212 | break; |
michael@0 | 213 | char hex = poundPos[4]; |
michael@0 | 214 | if (is_hex(hex) == false) { |
michael@0 | 215 | valueStr.insertUnichar(offset + 1, r); |
michael@0 | 216 | valueStr.insertUnichar(offset + 3, g); |
michael@0 | 217 | valueStr.insertUnichar(offset + 5, b); |
michael@0 | 218 | } |
michael@0 | 219 | *(char*) poundPos = '0'; // overwrite '#' |
michael@0 | 220 | valueStr.insert(offset + 1, "xFF"); |
michael@0 | 221 | } |
michael@0 | 222 | } |
michael@0 | 223 | if (SkDisplayType::IsDisplayable(&maker, type) || SkDisplayType::IsEnum(&maker, type) || type == SkType_ARGB) |
michael@0 | 224 | goto scriptCommon; |
michael@0 | 225 | switch (type) { |
michael@0 | 226 | case SkType_String: |
michael@0 | 227 | #if 0 |
michael@0 | 228 | if (displayable && displayable->isAnimate()) { |
michael@0 | 229 | |
michael@0 | 230 | goto noScriptString; |
michael@0 | 231 | } |
michael@0 | 232 | if (strncmp(rawValue, "#string:", sizeof("#string:") - 1) == 0) { |
michael@0 | 233 | SkASSERT(sizeof("string") == sizeof("script")); |
michael@0 | 234 | char* stringHeader = valueStr.writable_str(); |
michael@0 | 235 | memcpy(&stringHeader[1], "script", sizeof("script") - 1); |
michael@0 | 236 | rawValue = valueStr.c_str(); |
michael@0 | 237 | goto noScriptString; |
michael@0 | 238 | } else |
michael@0 | 239 | #endif |
michael@0 | 240 | if (strncmp(rawValue, "#script:", sizeof("#script:") - 1) != 0) |
michael@0 | 241 | goto noScriptString; |
michael@0 | 242 | valueStr.remove(0, 8); |
michael@0 | 243 | case SkType_Unknown: |
michael@0 | 244 | case SkType_Int: |
michael@0 | 245 | case SkType_MSec: // for the purposes of script, MSec is treated as a Scalar |
michael@0 | 246 | case SkType_Point: |
michael@0 | 247 | case SkType_3D_Point: |
michael@0 | 248 | case SkType_Float: |
michael@0 | 249 | case SkType_Array: |
michael@0 | 250 | scriptCommon: { |
michael@0 | 251 | const char* script = valueStr.c_str(); |
michael@0 | 252 | success = engine.evaluateScript(&script, &scriptValue); |
michael@0 | 253 | if (success == false) { |
michael@0 | 254 | maker.setScriptError(engine); |
michael@0 | 255 | return false; |
michael@0 | 256 | } |
michael@0 | 257 | } |
michael@0 | 258 | SkASSERT(success); |
michael@0 | 259 | if (scriptValue.fType == SkType_Displayable) { |
michael@0 | 260 | if (type == SkType_String) { |
michael@0 | 261 | const char* charPtr = NULL; |
michael@0 | 262 | maker.findKey(scriptValue.fOperand.fDisplayable, &charPtr); |
michael@0 | 263 | scriptValue.fOperand.fString = new SkString(charPtr); |
michael@0 | 264 | scriptValue.fType = SkType_String; |
michael@0 | 265 | engine.SkScriptEngine::track(scriptValue.fOperand.fString); |
michael@0 | 266 | break; |
michael@0 | 267 | } |
michael@0 | 268 | SkASSERT(SkDisplayType::IsDisplayable(&maker, type)); |
michael@0 | 269 | if (displayable) |
michael@0 | 270 | displayable->setReference(this, scriptValue.fOperand.fDisplayable); |
michael@0 | 271 | else |
michael@0 | 272 | arrayStorage->begin()[0].fDisplayable = scriptValue.fOperand.fDisplayable; |
michael@0 | 273 | return true; |
michael@0 | 274 | } |
michael@0 | 275 | if (type != scriptValue.fType) { |
michael@0 | 276 | if (scriptValue.fType == SkType_Array) { |
michael@0 | 277 | engine.forget(scriptValue.getArray()); |
michael@0 | 278 | goto writeStruct; // real structs have already been written by script |
michael@0 | 279 | } |
michael@0 | 280 | switch (type) { |
michael@0 | 281 | case SkType_String: |
michael@0 | 282 | success = engine.convertTo(SkType_String, &scriptValue); |
michael@0 | 283 | break; |
michael@0 | 284 | case SkType_MSec: |
michael@0 | 285 | case SkType_Float: |
michael@0 | 286 | success = engine.convertTo(SkType_Float, &scriptValue); |
michael@0 | 287 | break; |
michael@0 | 288 | case SkType_Int: |
michael@0 | 289 | success = engine.convertTo(SkType_Int, &scriptValue); |
michael@0 | 290 | break; |
michael@0 | 291 | case SkType_Array: |
michael@0 | 292 | success = engine.convertTo(arrayType(), &scriptValue); |
michael@0 | 293 | // !!! incomplete; create array of appropriate type and add scriptValue to it |
michael@0 | 294 | SkASSERT(0); |
michael@0 | 295 | break; |
michael@0 | 296 | case SkType_Displayable: |
michael@0 | 297 | case SkType_Drawable: |
michael@0 | 298 | return false; // no way to convert other types to this |
michael@0 | 299 | default: // to avoid warnings |
michael@0 | 300 | break; |
michael@0 | 301 | } |
michael@0 | 302 | if (success == false) |
michael@0 | 303 | return false; |
michael@0 | 304 | } |
michael@0 | 305 | if (type == SkType_MSec) |
michael@0 | 306 | scriptValue.fOperand.fMSec = SkScalarRoundToInt(scriptValue.fOperand.fScalar * 1000); |
michael@0 | 307 | scriptValue.fType = type; |
michael@0 | 308 | break; |
michael@0 | 309 | noScriptString: |
michael@0 | 310 | case SkType_DynamicString: |
michael@0 | 311 | if (fType == SkType_MemberProperty && displayable) { |
michael@0 | 312 | SkString string(rawValue, rawValueLen); |
michael@0 | 313 | SkScriptValue scriptValue; |
michael@0 | 314 | scriptValue.fOperand.fString = &string; |
michael@0 | 315 | scriptValue.fType = SkType_String; |
michael@0 | 316 | displayable->setProperty(propertyIndex(), scriptValue); |
michael@0 | 317 | } else if (displayable) { |
michael@0 | 318 | SkString* string = (SkString*) memberData(displayable); |
michael@0 | 319 | string->set(rawValue, rawValueLen); |
michael@0 | 320 | } else { |
michael@0 | 321 | SkASSERT(arrayStorage->count() == 1); |
michael@0 | 322 | arrayStorage->begin()->fString->set(rawValue, rawValueLen); |
michael@0 | 323 | } |
michael@0 | 324 | goto dirty; |
michael@0 | 325 | case SkType_Base64: { |
michael@0 | 326 | SkBase64 base64; |
michael@0 | 327 | base64.decode(rawValue, rawValueLen); |
michael@0 | 328 | *(SkBase64* ) untypedStorage = base64; |
michael@0 | 329 | } goto dirty; |
michael@0 | 330 | default: |
michael@0 | 331 | SkASSERT(0); |
michael@0 | 332 | break; |
michael@0 | 333 | } |
michael@0 | 334 | // if (SkDisplayType::IsStruct(type) == false) |
michael@0 | 335 | { |
michael@0 | 336 | writeStruct: |
michael@0 | 337 | if (writeValue(displayable, arrayStorage, storageOffset, maxStorage, |
michael@0 | 338 | untypedStorage, outType, scriptValue)) { |
michael@0 | 339 | maker.setErrorCode(SkDisplayXMLParserError::kUnexpectedType); |
michael@0 | 340 | return false; |
michael@0 | 341 | } |
michael@0 | 342 | } |
michael@0 | 343 | dirty: |
michael@0 | 344 | if (displayable) |
michael@0 | 345 | displayable->dirty(); |
michael@0 | 346 | return true; |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | bool SkMemberInfo::setValue(SkAnimateMaker& maker, SkTDOperandArray* arrayStorage, |
michael@0 | 350 | int storageOffset, int maxStorage, SkDisplayable* displayable, SkDisplayTypes outType, |
michael@0 | 351 | SkString& raw) const { |
michael@0 | 352 | return setValue(maker, arrayStorage, storageOffset, maxStorage, displayable, outType, raw.c_str(), |
michael@0 | 353 | raw.size()); |
michael@0 | 354 | } |
michael@0 | 355 | |
michael@0 | 356 | bool SkMemberInfo::writeValue(SkDisplayable* displayable, SkTDOperandArray* arrayStorage, |
michael@0 | 357 | int storageOffset, int maxStorage, void* untypedStorage, SkDisplayTypes outType, |
michael@0 | 358 | SkScriptValue& scriptValue) const |
michael@0 | 359 | { |
michael@0 | 360 | SkOperand* storage = untypedStorage ? (SkOperand*) untypedStorage : arrayStorage ? |
michael@0 | 361 | arrayStorage->begin() : NULL; |
michael@0 | 362 | if (storage) |
michael@0 | 363 | storage += storageOffset; |
michael@0 | 364 | SkDisplayTypes type = getType(); |
michael@0 | 365 | if (fType == SkType_MemberProperty) { |
michael@0 | 366 | if(displayable) |
michael@0 | 367 | displayable->setProperty(propertyIndex(), scriptValue); |
michael@0 | 368 | else { |
michael@0 | 369 | SkASSERT(storageOffset < arrayStorage->count()); |
michael@0 | 370 | switch (scriptValue.fType) { |
michael@0 | 371 | case SkType_Boolean: |
michael@0 | 372 | case SkType_Float: |
michael@0 | 373 | case SkType_Int: |
michael@0 | 374 | memcpy(&storage->fScalar, &scriptValue.fOperand.fScalar, sizeof(SkScalar)); |
michael@0 | 375 | break; |
michael@0 | 376 | case SkType_Array: |
michael@0 | 377 | memcpy(&storage->fScalar, scriptValue.fOperand.fArray->begin(), scriptValue.fOperand.fArray->count() * sizeof(SkScalar)); |
michael@0 | 378 | break; |
michael@0 | 379 | case SkType_String: |
michael@0 | 380 | storage->fString->set(*scriptValue.fOperand.fString); |
michael@0 | 381 | break; |
michael@0 | 382 | default: |
michael@0 | 383 | SkASSERT(0); // type isn't handled yet |
michael@0 | 384 | } |
michael@0 | 385 | } |
michael@0 | 386 | } else if (fType == SkType_MemberFunction) { |
michael@0 | 387 | SkASSERT(scriptValue.fType == SkType_Array); |
michael@0 | 388 | if (displayable) |
michael@0 | 389 | displayable->executeFunction(displayable, this, scriptValue.fOperand.fArray, NULL); |
michael@0 | 390 | else { |
michael@0 | 391 | int count = scriptValue.fOperand.fArray->count(); |
michael@0 | 392 | // SkASSERT(maxStorage == 0 || count == maxStorage); |
michael@0 | 393 | if (arrayStorage->count() == 2) |
michael@0 | 394 | arrayStorage->setCount(2 * count); |
michael@0 | 395 | else { |
michael@0 | 396 | storageOffset *= count; |
michael@0 | 397 | SkASSERT(count + storageOffset <= arrayStorage->count()); |
michael@0 | 398 | } |
michael@0 | 399 | memcpy(&(*arrayStorage)[storageOffset], scriptValue.fOperand.fArray->begin(), count * sizeof(SkOperand)); |
michael@0 | 400 | } |
michael@0 | 401 | |
michael@0 | 402 | } else if (fType == SkType_Array) { |
michael@0 | 403 | SkTypedArray* destArray = (SkTypedArray*) (untypedStorage ? untypedStorage : arrayStorage); |
michael@0 | 404 | SkASSERT(destArray); |
michael@0 | 405 | // destArray->setCount(0); |
michael@0 | 406 | if (scriptValue.fType != SkType_Array) { |
michael@0 | 407 | SkASSERT(type == scriptValue.fType); |
michael@0 | 408 | // SkASSERT(storageOffset + 1 <= maxStorage); |
michael@0 | 409 | destArray->setCount(storageOffset + 1); |
michael@0 | 410 | (*destArray)[storageOffset] = scriptValue.fOperand; |
michael@0 | 411 | } else { |
michael@0 | 412 | if (type == SkType_Unknown) { |
michael@0 | 413 | type = scriptValue.fOperand.fArray->getType(); |
michael@0 | 414 | destArray->setType(type); |
michael@0 | 415 | } |
michael@0 | 416 | SkASSERT(type == scriptValue.fOperand.fArray->getType()); |
michael@0 | 417 | int count = scriptValue.fOperand.fArray->count(); |
michael@0 | 418 | // SkASSERT(storageOffset + count <= maxStorage); |
michael@0 | 419 | destArray->setCount(storageOffset + count); |
michael@0 | 420 | memcpy(destArray->begin() + storageOffset, scriptValue.fOperand.fArray->begin(), sizeof(SkOperand) * count); |
michael@0 | 421 | } |
michael@0 | 422 | } else if (type == SkType_String) { |
michael@0 | 423 | SkString* string = untypedStorage ? (SkString*) untypedStorage : (*arrayStorage)[storageOffset].fString; |
michael@0 | 424 | string->set(*scriptValue.fOperand.fString); |
michael@0 | 425 | } else if (type == SkType_ARGB && outType == SkType_Float) { |
michael@0 | 426 | SkTypedArray* array = scriptValue.fOperand.fArray; |
michael@0 | 427 | SkASSERT(scriptValue.fType == SkType_Int || scriptValue.fType == SkType_ARGB || |
michael@0 | 428 | scriptValue.fType == SkType_Array); |
michael@0 | 429 | SkASSERT(scriptValue.fType != SkType_Array || (array != NULL && |
michael@0 | 430 | array->getType() == SkType_Int)); |
michael@0 | 431 | int numberOfColors = scriptValue.fType == SkType_Array ? array->count() : 1; |
michael@0 | 432 | int numberOfComponents = numberOfColors * 4; |
michael@0 | 433 | // SkASSERT(maxStorage == 0 || maxStorage == numberOfComponents); |
michael@0 | 434 | if (maxStorage == 0) |
michael@0 | 435 | arrayStorage->setCount(numberOfComponents); |
michael@0 | 436 | for (int index = 0; index < numberOfColors; index++) { |
michael@0 | 437 | SkColor color = scriptValue.fType == SkType_Array ? |
michael@0 | 438 | (SkColor) array->begin()[index].fS32 : (SkColor) scriptValue.fOperand.fS32; |
michael@0 | 439 | storage[0].fScalar = SkIntToScalar(SkColorGetA(color)); |
michael@0 | 440 | storage[1].fScalar = SkIntToScalar(SkColorGetR(color)); |
michael@0 | 441 | storage[2].fScalar = SkIntToScalar(SkColorGetG(color)); |
michael@0 | 442 | storage[3].fScalar = SkIntToScalar(SkColorGetB(color)); |
michael@0 | 443 | storage += 4; |
michael@0 | 444 | } |
michael@0 | 445 | } else if (SkDisplayType::IsStruct(NULL /* !!! maker*/, type)) { |
michael@0 | 446 | if (scriptValue.fType != SkType_Array) |
michael@0 | 447 | return true; // error |
michael@0 | 448 | SkASSERT(sizeof(SkScalar) == sizeof(SkOperand)); // !!! no 64 bit pointer support yet |
michael@0 | 449 | int count = scriptValue.fOperand.fArray->count(); |
michael@0 | 450 | if (count > 0) { |
michael@0 | 451 | SkASSERT(fCount == count); |
michael@0 | 452 | memcpy(storage, scriptValue.fOperand.fArray->begin(), count * sizeof(SkOperand)); |
michael@0 | 453 | } |
michael@0 | 454 | } else if (scriptValue.fType == SkType_Array) { |
michael@0 | 455 | SkASSERT(scriptValue.fOperand.fArray->getType() == type); |
michael@0 | 456 | SkASSERT(scriptValue.fOperand.fArray->count() == getCount()); |
michael@0 | 457 | memcpy(storage, scriptValue.fOperand.fArray->begin(), getCount() * sizeof(SkOperand)); |
michael@0 | 458 | } else { |
michael@0 | 459 | memcpy(storage, &scriptValue.fOperand, sizeof(SkOperand)); |
michael@0 | 460 | } |
michael@0 | 461 | return false; |
michael@0 | 462 | } |
michael@0 | 463 | |
michael@0 | 464 | |
michael@0 | 465 | //void SkMemberInfo::setValue(SkDisplayable* displayable, const char value[], const char name[]) const { |
michael@0 | 466 | // void* valuePtr = (void*) ((char*) displayable + fOffset); |
michael@0 | 467 | // switch (fType) { |
michael@0 | 468 | // case SkType_Point3D: { |
michael@0 | 469 | // static const char xyz[] = "x|y|z"; |
michael@0 | 470 | // int index = find_one(xyz, name); |
michael@0 | 471 | // SkASSERT(index >= 0); |
michael@0 | 472 | // valuePtr = (void*) ((char*) valuePtr + index * sizeof(SkScalar)); |
michael@0 | 473 | // } break; |
michael@0 | 474 | // default: |
michael@0 | 475 | // SkASSERT(0); |
michael@0 | 476 | // } |
michael@0 | 477 | // SkParse::FindScalar(value, (SkScalar*) valuePtr); |
michael@0 | 478 | // displayable->dirty(); |
michael@0 | 479 | //} |
michael@0 | 480 | |
michael@0 | 481 | #if SK_USE_CONDENSED_INFO == 0 |
michael@0 | 482 | |
michael@0 | 483 | // Find Nth memberInfo |
michael@0 | 484 | const SkMemberInfo* SkMemberInfo::Find(const SkMemberInfo info[], int count, int* index) { |
michael@0 | 485 | SkASSERT(*index >= 0); |
michael@0 | 486 | if (info->fType == SkType_BaseClassInfo) { |
michael@0 | 487 | const SkMemberInfo* inherited = (SkMemberInfo*) info->fName; |
michael@0 | 488 | const SkMemberInfo* result = SkMemberInfo::Find(inherited, info->fCount, index); |
michael@0 | 489 | if (result != NULL) |
michael@0 | 490 | return result; |
michael@0 | 491 | if (--count == 0) |
michael@0 | 492 | return NULL; |
michael@0 | 493 | info++; |
michael@0 | 494 | } |
michael@0 | 495 | SkASSERT(info->fName); |
michael@0 | 496 | SkASSERT(info->fType != SkType_BaseClassInfo); |
michael@0 | 497 | if (*index >= count) { |
michael@0 | 498 | *index -= count; |
michael@0 | 499 | return NULL; |
michael@0 | 500 | } |
michael@0 | 501 | return &info[*index]; |
michael@0 | 502 | } |
michael@0 | 503 | |
michael@0 | 504 | // Find named memberinfo |
michael@0 | 505 | const SkMemberInfo* SkMemberInfo::Find(const SkMemberInfo info[], int count, const char** matchPtr) { |
michael@0 | 506 | const char* match = *matchPtr; |
michael@0 | 507 | if (info->fType == SkType_BaseClassInfo) { |
michael@0 | 508 | const SkMemberInfo* inherited = (SkMemberInfo*) info->fName; |
michael@0 | 509 | const SkMemberInfo* result = SkMemberInfo::Find(inherited, info->fCount, matchPtr); |
michael@0 | 510 | if (result != NULL) |
michael@0 | 511 | return result; |
michael@0 | 512 | if (--count == 0) |
michael@0 | 513 | return NULL; |
michael@0 | 514 | info++; |
michael@0 | 515 | } |
michael@0 | 516 | SkASSERT(info->fName); |
michael@0 | 517 | SkASSERT(info->fType != SkType_BaseClassInfo); |
michael@0 | 518 | int index = SkStrSearch(&info->fName, count, match, sizeof(*info)); |
michael@0 | 519 | if (index < 0 || index >= count) |
michael@0 | 520 | return NULL; |
michael@0 | 521 | return &info[index]; |
michael@0 | 522 | } |
michael@0 | 523 | |
michael@0 | 524 | const SkMemberInfo* SkMemberInfo::getInherited() const { |
michael@0 | 525 | return (SkMemberInfo*) fName; |
michael@0 | 526 | } |
michael@0 | 527 | |
michael@0 | 528 | #endif // SK_USE_CONDENSED_INFO == 0 |
michael@0 | 529 | |
michael@0 | 530 | #if 0 |
michael@0 | 531 | bool SkMemberInfo::SetValue(void* valuePtr, const char value[], SkDisplayTypes type, |
michael@0 | 532 | int count) { |
michael@0 | 533 | switch (type) { |
michael@0 | 534 | case SkType_Animate: |
michael@0 | 535 | case SkType_BaseBitmap: |
michael@0 | 536 | case SkType_Bitmap: |
michael@0 | 537 | case SkType_Dash: |
michael@0 | 538 | case SkType_Displayable: |
michael@0 | 539 | case SkType_Drawable: |
michael@0 | 540 | case SkType_Matrix: |
michael@0 | 541 | case SkType_Path: |
michael@0 | 542 | case SkType_Text: |
michael@0 | 543 | case SkType_3D_Patch: |
michael@0 | 544 | return false; // ref to object; caller must resolve |
michael@0 | 545 | case SkType_MSec: { |
michael@0 | 546 | SkParse::FindMSec(value, (SkMSec*) valuePtr); |
michael@0 | 547 | } break; |
michael@0 | 548 | case SkType_3D_Point: |
michael@0 | 549 | case SkType_Point: |
michael@0 | 550 | // case SkType_PointArray: |
michael@0 | 551 | case SkType_ScalarArray: |
michael@0 | 552 | SkParse::FindScalars(value, (SkScalar*) valuePtr, count); |
michael@0 | 553 | break; |
michael@0 | 554 | default: |
michael@0 | 555 | SkASSERT(0); |
michael@0 | 556 | } |
michael@0 | 557 | return true; |
michael@0 | 558 | } |
michael@0 | 559 | #endif |