| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkFlattenableBuffers.h" | 9 #include "SkFlattenableBuffers.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 cstr = ""; | 151 cstr = ""; |
| 152 size = 1; | 152 size = 1; |
| 153 } else { | 153 } else { |
| 154 size = strlen(cstr) + 1; | 154 size = strlen(cstr) + 1; |
| 155 } | 155 } |
| 156 return NewWithCopy(cstr, size); | 156 return NewWithCopy(cstr, size); |
| 157 } | 157 } |
| 158 | 158 |
| 159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
| 160 | 160 |
| 161 void SkData::flatten(SkFlattenableWriteBuffer& buffer) const { | |
| 162 buffer.writeByteArray(fPtr, fSize); | |
| 163 } | |
| 164 | |
| 165 SkData::SkData(SkFlattenableReadBuffer& buffer) { | |
| 166 fSize = buffer.getArrayCount(); | |
| 167 fReleaseProcContext = NULL; | |
| 168 | |
| 169 if (fSize > 0) { | |
| 170 fPtr = sk_malloc_throw(fSize); | |
| 171 fReleaseProc = sk_free_releaseproc; | |
| 172 } else { | |
| 173 fPtr = NULL; | |
| 174 fReleaseProc = NULL; | |
| 175 } | |
| 176 | |
| 177 buffer.readByteArray(const_cast<void*>(fPtr)); | |
| 178 } | |
| 179 | |
| 180 /////////////////////////////////////////////////////////////////////////////// | |
| 181 /////////////////////////////////////////////////////////////////////////////// | |
| 182 | |
| 183 #include "SkDataSet.h" | 161 #include "SkDataSet.h" |
| 184 #include "SkFlattenable.h" | 162 #include "SkFlattenable.h" |
| 185 #include "SkStream.h" | 163 #include "SkStream.h" |
| 186 | 164 |
| 187 static SkData* dupdata(SkData* data) { | 165 static SkData* dupdata(SkData* data) { |
| 188 if (data) { | 166 if (data) { |
| 189 data->ref(); | 167 data->ref(); |
| 190 } else { | 168 } else { |
| 191 data = SkData::NewEmpty(); | 169 data = SkData::NewEmpty(); |
| 192 } | 170 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 stream->writeData(fPairs[i].fValue); | 254 stream->writeData(fPairs[i].fValue); |
| 277 } | 255 } |
| 278 } | 256 } |
| 279 } | 257 } |
| 280 | 258 |
| 281 void SkDataSet::flatten(SkFlattenableWriteBuffer& buffer) const { | 259 void SkDataSet::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 282 buffer.writeInt(fCount); | 260 buffer.writeInt(fCount); |
| 283 if (fCount > 0) { | 261 if (fCount > 0) { |
| 284 buffer.writeByteArray(fPairs[0].fKey, fKeySize); | 262 buffer.writeByteArray(fPairs[0].fKey, fKeySize); |
| 285 for (int i = 0; i < fCount; ++i) { | 263 for (int i = 0; i < fCount; ++i) { |
| 286 buffer.writeFlattenable(fPairs[i].fValue); | 264 buffer.writeDataAsByteArray(fPairs[i].fValue); |
| 287 } | 265 } |
| 288 } | 266 } |
| 289 } | 267 } |
| 290 | 268 |
| 291 SkDataSet::SkDataSet(SkStream* stream) { | 269 SkDataSet::SkDataSet(SkStream* stream) { |
| 292 fCount = stream->readU32(); | 270 fCount = stream->readU32(); |
| 293 if (fCount > 0) { | 271 if (fCount > 0) { |
| 294 fKeySize = stream->readU32(); | 272 fKeySize = stream->readU32(); |
| 295 fPairs = allocatePairStorage(fCount, fKeySize); | 273 fPairs = allocatePairStorage(fCount, fKeySize); |
| 296 char* keyStorage = (char*)(fPairs + fCount); | 274 char* keyStorage = (char*)(fPairs + fCount); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 313 if (fCount > 0) { | 291 if (fCount > 0) { |
| 314 fKeySize = buffer.getArrayCount(); | 292 fKeySize = buffer.getArrayCount(); |
| 315 fPairs = allocatePairStorage(fCount, fKeySize); | 293 fPairs = allocatePairStorage(fCount, fKeySize); |
| 316 char* keyStorage = (char*)(fPairs + fCount); | 294 char* keyStorage = (char*)(fPairs + fCount); |
| 317 | 295 |
| 318 buffer.readByteArray(keyStorage); | 296 buffer.readByteArray(keyStorage); |
| 319 | 297 |
| 320 for (int i = 0; i < fCount; ++i) { | 298 for (int i = 0; i < fCount; ++i) { |
| 321 fPairs[i].fKey = keyStorage; | 299 fPairs[i].fKey = keyStorage; |
| 322 keyStorage += strlen(keyStorage) + 1; | 300 keyStorage += strlen(keyStorage) + 1; |
| 323 fPairs[i].fValue = buffer.readFlattenableT<SkData>(); | 301 fPairs[i].fValue = buffer.readByteArrayAsData(); |
| 324 } | 302 } |
| 325 } else { | 303 } else { |
| 326 fKeySize = 0; | 304 fKeySize = 0; |
| 327 fPairs = NULL; | 305 fPairs = NULL; |
| 328 } | 306 } |
| 329 } | 307 } |
| 330 | 308 |
| 331 SkDataSet* SkDataSet::NewEmpty() { | 309 SkDataSet* SkDataSet::NewEmpty() { |
| 332 static SkDataSet* gEmptySet; | 310 static SkDataSet* gEmptySet; |
| 333 if (NULL == gEmptySet) { | 311 if (NULL == gEmptySet) { |
| 334 gEmptySet = SkNEW_ARGS(SkDataSet, (NULL, 0)); | 312 gEmptySet = SkNEW_ARGS(SkDataSet, (NULL, 0)); |
| 335 } | 313 } |
| 336 gEmptySet->ref(); | 314 gEmptySet->ref(); |
| 337 return gEmptySet; | 315 return gEmptySet; |
| 338 } | 316 } |
| OLD | NEW |