Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 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 "SkPictureFlat.h" | 10 #include "SkPictureFlat.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 ) { | 291 ) { |
| 292 return false; | 292 return false; |
| 293 } | 293 } |
| 294 | 294 |
| 295 if (pInfo != NULL) { | 295 if (pInfo != NULL) { |
| 296 *pInfo = info; | 296 *pInfo = info; |
| 297 } | 297 } |
| 298 return true; | 298 return true; |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool SkPicture::BufferIsSKP(SkFlattenableReadBuffer& buffer, SkPictInfo* pInfo) { | |
| 302 // Check magic bytes. | |
| 303 char magic[sizeof(kMagic)]; | |
| 304 | |
| 305 if (!buffer.readByteArray(magic, sizeof(kMagic)) || | |
| 306 (0 != memcmp(magic, kMagic, sizeof(kMagic)))) { | |
| 307 return false; | |
| 308 } | |
| 309 | |
| 310 SkPictInfo info; | |
| 311 if (!buffer.readByteArray(&info, sizeof(SkPictInfo))) { | |
| 312 return false; | |
| 313 } | |
| 314 | |
| 315 if (PICTURE_VERSION != info.fVersion | |
| 316 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V16_AND_ALL_OTHER_INSTANCES_TO O | |
|
Stephen White
2014/01/15 14:59:02
Considering that this will be the first time that
sugoi
2014/01/15 16:49:22
Done.
| |
| 317 // V16 is backwards compatible with V15 | |
| 318 && PRIOR_PICTURE_VERSION != info.fVersion // TODO: remove when .skps re generated | |
| 319 #endif | |
| 320 ) { | |
| 321 return false; | |
| 322 } | |
| 323 | |
| 324 if (pInfo != NULL) { | |
| 325 *pInfo = info; | |
| 326 } | |
| 327 return true; | |
| 328 } | |
| 329 | |
| 301 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) | 330 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) |
| 302 : fPlayback(playback) | 331 : fPlayback(playback) |
| 303 , fRecord(NULL) | 332 , fRecord(NULL) |
| 304 , fWidth(width) | 333 , fWidth(width) |
| 305 , fHeight(height) {} | 334 , fHeight(height) {} |
| 306 | 335 |
| 307 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { | 336 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { |
| 308 SkPictInfo info; | 337 SkPictInfo info; |
| 309 | 338 |
| 310 if (!StreamIsSKP(stream, &info)) { | 339 if (!StreamIsSKP(stream, &info)) { |
| 311 return NULL; | 340 return NULL; |
| 312 } | 341 } |
| 313 | 342 |
| 314 SkPicturePlayback* playback; | 343 SkPicturePlayback* playback; |
| 315 // Check to see if there is a playback to recreate. | 344 // Check to see if there is a playback to recreate. |
| 316 if (stream->readBool()) { | 345 if (stream->readBool()) { |
| 317 playback = SkPicturePlayback::CreateFromStream(stream, info, proc); | 346 playback = SkPicturePlayback::CreateFromStream(stream, info, proc); |
| 318 if (NULL == playback) { | 347 if (NULL == playback) { |
| 319 return NULL; | 348 return NULL; |
| 320 } | 349 } |
| 321 } else { | 350 } else { |
| 322 playback = NULL; | 351 playback = NULL; |
| 323 } | 352 } |
| 324 | 353 |
| 325 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | 354 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); |
| 326 } | 355 } |
| 327 | 356 |
| 357 SkPicture* SkPicture::CreateFromBuffer(SkFlattenableReadBuffer& buffer) { | |
| 358 SkPictInfo info; | |
| 359 | |
| 360 if (!BufferIsSKP(buffer, &info)) { | |
| 361 return NULL; | |
| 362 } | |
| 363 | |
| 364 SkPicturePlayback* playback; | |
| 365 // Check to see if there is a playback to recreate. | |
| 366 if (buffer.readBool()) { | |
| 367 playback = SkPicturePlayback::CreateFromBuffer(buffer); | |
| 368 if (NULL == playback) { | |
| 369 return NULL; | |
| 370 } | |
| 371 } else { | |
| 372 playback = NULL; | |
| 373 } | |
| 374 | |
| 375 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | |
| 376 } | |
| 377 | |
| 328 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 378 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
| 329 SkPicturePlayback* playback = fPlayback; | 379 SkPicturePlayback* playback = fPlayback; |
| 330 | 380 |
| 331 if (NULL == playback && fRecord) { | 381 if (NULL == playback && fRecord) { |
| 332 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); | 382 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); |
| 333 } | 383 } |
| 334 | 384 |
| 335 SkPictInfo info; | 385 SkPictInfo info; |
| 336 | 386 |
| 337 info.fVersion = PICTURE_VERSION; | 387 info.fVersion = PICTURE_VERSION; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 355 playback->serialize(stream, encoder); | 405 playback->serialize(stream, encoder); |
| 356 // delete playback if it is a local version (i.e. cons'd up just now) | 406 // delete playback if it is a local version (i.e. cons'd up just now) |
| 357 if (playback != fPlayback) { | 407 if (playback != fPlayback) { |
| 358 SkDELETE(playback); | 408 SkDELETE(playback); |
| 359 } | 409 } |
| 360 } else { | 410 } else { |
| 361 stream->writeBool(false); | 411 stream->writeBool(false); |
| 362 } | 412 } |
| 363 } | 413 } |
| 364 | 414 |
| 415 void SkPicture::flatten(SkFlattenableWriteBuffer& buffer) const { | |
| 416 SkPicturePlayback* playback = fPlayback; | |
| 417 | |
| 418 if (NULL == playback && fRecord) { | |
| 419 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); | |
| 420 } | |
| 421 | |
| 422 SkPictInfo info; | |
| 423 | |
| 424 info.fVersion = PICTURE_VERSION; | |
| 425 info.fWidth = fWidth; | |
| 426 info.fHeight = fHeight; | |
| 427 info.fFlags = SkPictInfo::kCrossProcess_Flag; | |
| 428 // TODO: remove this flag, since we're always float (now) | |
| 429 info.fFlags |= SkPictInfo::kScalarIsFloat_Flag; | |
| 430 | |
| 431 if (8 == sizeof(void*)) { | |
| 432 info.fFlags |= SkPictInfo::kPtrIs64Bit_Flag; | |
| 433 } | |
| 434 | |
| 435 // Write 8 magic bytes to ID this file format. | |
| 436 SkASSERT(sizeof(kMagic) == 8); | |
| 437 buffer.writeByteArray(kMagic, sizeof(kMagic)); | |
| 438 | |
| 439 buffer.writeByteArray(&info, sizeof(info)); | |
| 440 if (playback) { | |
| 441 buffer.writeBool(true); | |
| 442 playback->flatten(buffer); | |
| 443 // delete playback if it is a local version (i.e. cons'd up just now) | |
| 444 if (playback != fPlayback) { | |
| 445 SkDELETE(playback); | |
| 446 } | |
| 447 } else { | |
| 448 buffer.writeBool(false); | |
| 449 } | |
| 450 } | |
| 451 | |
| 365 bool SkPicture::willPlayBackBitmaps() const { | 452 bool SkPicture::willPlayBackBitmaps() const { |
| 366 if (!fPlayback) return false; | 453 if (!fPlayback) return false; |
| 367 return fPlayback->containsBitmaps(); | 454 return fPlayback->containsBitmaps(); |
| 368 } | 455 } |
| 369 | 456 |
| 370 #ifdef SK_BUILD_FOR_ANDROID | 457 #ifdef SK_BUILD_FOR_ANDROID |
| 371 void SkPicture::abortPlayback() { | 458 void SkPicture::abortPlayback() { |
| 372 if (NULL == fPlayback) { | 459 if (NULL == fPlayback) { |
| 373 return; | 460 return; |
| 374 } | 461 } |
| 375 fPlayback->abort(); | 462 fPlayback->abort(); |
| 376 } | 463 } |
| 377 #endif | 464 #endif |
| OLD | NEW |