| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 : fCullWidth(width) | 264 : fCullWidth(width) |
| 265 , fCullHeight(height) | 265 , fCullHeight(height) |
| 266 , fAnalysis() { | 266 , fAnalysis() { |
| 267 this->needsNewGenID(); | 267 this->needsNewGenID(); |
| 268 | 268 |
| 269 SkPictInfo info; | 269 SkPictInfo info; |
| 270 this->createHeader(&info); | 270 this->createHeader(&info); |
| 271 fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); | 271 fData.reset(SkNEW_ARGS(SkPictureData, (record, info, deepCopyOps))); |
| 272 } | 272 } |
| 273 | 273 |
| 274 int SkPicture::drawableCount() const { |
| 275 if (fDrawablePicts.get()) { |
| 276 return SkToInt(fDrawablePicts->size() / sizeof(SkPicture*)); |
| 277 } else { |
| 278 return 0; |
| 279 } |
| 280 } |
| 281 |
| 282 SkPicture* const* SkPicture::drawablePicts() const { |
| 283 if (fDrawablePicts) { |
| 284 return reinterpret_cast<SkPicture* const*>(fDrawablePicts->data()); |
| 285 } |
| 286 return NULL; |
| 287 } |
| 288 |
| 274 // Create an SkPictureData-backed SkPicture from an SkRecord. | 289 // Create an SkPictureData-backed SkPicture from an SkRecord. |
| 275 // This for compatibility with serialization code only. This is not cheap. | 290 // This for compatibility with serialization code only. This is not cheap. |
| 276 SkPicture* SkPicture::Backport(const SkRecord& src, const SkRect& cullRect) { | 291 SkPicture* SkPicture::Backport(const SkRecord& src, |
| 292 SkPicture* const drawablePicts[], int drawableCou
nt, |
| 293 const SkRect& cullRect) { |
| 277 SkPictureRecord rec(SkISize::Make(cullRect.width(), cullRect.height()), 0/*f
lags*/); | 294 SkPictureRecord rec(SkISize::Make(cullRect.width(), cullRect.height()), 0/*f
lags*/); |
| 278 rec.beginRecording(); | 295 rec.beginRecording(); |
| 279 SkRecordDraw(src, &rec, NULL/*bbh*/, NULL/*callback*/); | 296 SkRecordDraw(src, &rec, drawablePicts, drawableCount, NULL/*bbh*/, NULL/
*callback*/); |
| 280 rec.endRecording(); | 297 rec.endRecording(); |
| 281 return SkNEW_ARGS(SkPicture, (cullRect.width(), cullRect.height(), rec, fals
e/*deepCopyOps*/)); | 298 return SkNEW_ARGS(SkPicture, (cullRect.width(), cullRect.height(), rec, fals
e/*deepCopyOps*/)); |
| 282 } | 299 } |
| 283 | 300 |
| 284 // fRecord OK | 301 // fRecord OK |
| 285 SkPicture::~SkPicture() { | 302 SkPicture::~SkPicture() { |
| 286 this->callDeletionListeners(); | 303 this->callDeletionListeners(); |
| 304 |
| 305 const int count = this->drawableCount(); |
| 306 SkPicture* const* pics = this->drawablePicts(); |
| 307 for (int i = 0; i < count; ++i) { |
| 308 pics[i]->unref(); |
| 309 } |
| 287 } | 310 } |
| 288 | 311 |
| 289 // fRecord OK | 312 // fRecord OK |
| 290 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { | 313 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { |
| 291 fAccelData.reset(SkRef(data)); | 314 fAccelData.reset(SkRef(data)); |
| 292 } | 315 } |
| 293 | 316 |
| 294 // fRecord OK | 317 // fRecord OK |
| 295 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( | 318 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( |
| 296 SkPicture::AccelData::Key key) const { | 319 SkPicture::AccelData::Key key) const { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 322 if (fData.get()) { | 345 if (fData.get()) { |
| 323 SkPicturePlayback playback(this); | 346 SkPicturePlayback playback(this); |
| 324 playback.draw(canvas, callback); | 347 playback.draw(canvas, callback); |
| 325 } | 348 } |
| 326 if (fRecord.get()) { | 349 if (fRecord.get()) { |
| 327 // If the query contains the whole picture, don't bother with the BBH. | 350 // If the query contains the whole picture, don't bother with the BBH. |
| 328 SkRect clipBounds = { 0, 0, 0, 0 }; | 351 SkRect clipBounds = { 0, 0, 0, 0 }; |
| 329 (void)canvas->getClipBounds(&clipBounds); | 352 (void)canvas->getClipBounds(&clipBounds); |
| 330 const bool useBBH = !clipBounds.contains(this->cullRect()); | 353 const bool useBBH = !clipBounds.contains(this->cullRect()); |
| 331 | 354 |
| 332 SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback); | 355 SkRecordDraw(*fRecord, canvas, this->drawablePicts(), this->drawableCoun
t(), |
| 356 useBBH ? fBBH.get() : NULL, callback); |
| 333 } | 357 } |
| 334 } | 358 } |
| 335 | 359 |
| 336 /////////////////////////////////////////////////////////////////////////////// | 360 /////////////////////////////////////////////////////////////////////////////// |
| 337 | 361 |
| 338 #include "SkStream.h" | 362 #include "SkStream.h" |
| 339 | 363 |
| 340 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; | 364 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; |
| 341 | 365 |
| 342 // fRecord OK | 366 // fRecord OK |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 , fCullWidth(width) | 464 , fCullWidth(width) |
| 441 , fCullHeight(height) | 465 , fCullHeight(height) |
| 442 , fAnalysis() { | 466 , fAnalysis() { |
| 443 this->needsNewGenID(); | 467 this->needsNewGenID(); |
| 444 } | 468 } |
| 445 | 469 |
| 446 SkPicture* SkPicture::Forwardport(const SkPicture& src) { | 470 SkPicture* SkPicture::Forwardport(const SkPicture& src) { |
| 447 SkAutoTDelete<SkRecord> record(SkNEW(SkRecord)); | 471 SkAutoTDelete<SkRecord> record(SkNEW(SkRecord)); |
| 448 SkRecorder canvas(record.get(), src.cullRect().width(), src.cullRect().heigh
t()); | 472 SkRecorder canvas(record.get(), src.cullRect().width(), src.cullRect().heigh
t()); |
| 449 src.playback(&canvas); | 473 src.playback(&canvas); |
| 474 SkData* drawablePicts = NULL; // old pictures never have these |
| 450 return SkNEW_ARGS(SkPicture, (src.cullRect().width(), src.cullRect().height(
), | 475 return SkNEW_ARGS(SkPicture, (src.cullRect().width(), src.cullRect().height(
), |
| 451 record.detach(), NULL/*bbh*/)); | 476 record.detach(), drawablePicts, NULL/*bbh*/)); |
| 452 } | 477 } |
| 453 | 478 |
| 454 // fRecord OK | 479 // fRecord OK |
| 455 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { | 480 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { |
| 456 SkPictInfo info; | 481 SkPictInfo info; |
| 457 | 482 |
| 458 if (!InternalOnly_StreamIsSKP(stream, &info)) { | 483 if (!InternalOnly_StreamIsSKP(stream, &info)) { |
| 459 return NULL; | 484 return NULL; |
| 460 } | 485 } |
| 461 | 486 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 537 } |
| 513 } | 538 } |
| 514 | 539 |
| 515 // fRecord OK | 540 // fRecord OK |
| 516 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 541 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
| 517 const SkPictureData* data = fData.get(); | 542 const SkPictureData* data = fData.get(); |
| 518 | 543 |
| 519 // If we're a new-format picture, backport to old format for serialization. | 544 // If we're a new-format picture, backport to old format for serialization. |
| 520 SkAutoTDelete<SkPicture> oldFormat; | 545 SkAutoTDelete<SkPicture> oldFormat; |
| 521 if (NULL == data && fRecord.get()) { | 546 if (NULL == data && fRecord.get()) { |
| 522 oldFormat.reset(Backport(*fRecord, this->cullRect())); | 547 oldFormat.reset(Backport(*fRecord, this->drawablePicts(), this->drawable
Count(), |
| 548 this->cullRect())); |
| 523 data = oldFormat->fData.get(); | 549 data = oldFormat->fData.get(); |
| 524 SkASSERT(data); | 550 SkASSERT(data); |
| 525 } | 551 } |
| 526 | 552 |
| 527 SkPictInfo info; | 553 SkPictInfo info; |
| 528 this->createHeader(&info); | 554 this->createHeader(&info); |
| 529 SkASSERT(sizeof(SkPictInfo) == 32); | 555 SkASSERT(sizeof(SkPictInfo) == 32); |
| 530 stream->write(&info, sizeof(info)); | 556 stream->write(&info, sizeof(info)); |
| 531 | 557 |
| 532 if (data) { | 558 if (data) { |
| 533 stream->writeBool(true); | 559 stream->writeBool(true); |
| 534 data->serialize(stream, encoder); | 560 data->serialize(stream, encoder); |
| 535 } else { | 561 } else { |
| 536 stream->writeBool(false); | 562 stream->writeBool(false); |
| 537 } | 563 } |
| 538 } | 564 } |
| 539 | 565 |
| 540 // fRecord OK | 566 // fRecord OK |
| 541 void SkPicture::flatten(SkWriteBuffer& buffer) const { | 567 void SkPicture::flatten(SkWriteBuffer& buffer) const { |
| 542 const SkPictureData* data = fData.get(); | 568 const SkPictureData* data = fData.get(); |
| 543 | 569 |
| 544 // If we're a new-format picture, backport to old format for serialization. | 570 // If we're a new-format picture, backport to old format for serialization. |
| 545 SkAutoTDelete<SkPicture> oldFormat; | 571 SkAutoTDelete<SkPicture> oldFormat; |
| 546 if (NULL == data && fRecord.get()) { | 572 if (NULL == data && fRecord.get()) { |
| 547 oldFormat.reset(Backport(*fRecord, this->cullRect())); | 573 oldFormat.reset(Backport(*fRecord, this->drawablePicts(), this->drawable
Count(), |
| 574 this->cullRect())); |
| 548 data = oldFormat->fData.get(); | 575 data = oldFormat->fData.get(); |
| 549 SkASSERT(data); | 576 SkASSERT(data); |
| 550 } | 577 } |
| 551 | 578 |
| 552 SkPictInfo info; | 579 SkPictInfo info; |
| 553 this->createHeader(&info); | 580 this->createHeader(&info); |
| 554 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); | 581 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); |
| 555 buffer.writeUInt(info.fVersion); | 582 buffer.writeUInt(info.fVersion); |
| 556 buffer.writeRect(info.fCullRect); | 583 buffer.writeRect(info.fCullRect); |
| 557 buffer.writeUInt(info.fFlags); | 584 buffer.writeUInt(info.fFlags); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 646 |
| 620 // fRecord OK | 647 // fRecord OK |
| 621 uint32_t SkPicture::uniqueID() const { | 648 uint32_t SkPicture::uniqueID() const { |
| 622 if (SK_InvalidGenID == fUniqueID) { | 649 if (SK_InvalidGenID == fUniqueID) { |
| 623 fUniqueID = next_picture_generation_id(); | 650 fUniqueID = next_picture_generation_id(); |
| 624 } | 651 } |
| 625 return fUniqueID; | 652 return fUniqueID; |
| 626 } | 653 } |
| 627 | 654 |
| 628 // fRecord OK | 655 // fRecord OK |
| 629 SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkBBoxHi
erarchy* bbh) | 656 SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkData*
drawablePicts, |
| 657 SkBBoxHierarchy* bbh) |
| 630 : fCullWidth(width) | 658 : fCullWidth(width) |
| 631 , fCullHeight(height) | 659 , fCullHeight(height) |
| 632 , fRecord(record) | 660 , fRecord(record) |
| 633 , fBBH(SkSafeRef(bbh)) | 661 , fBBH(SkSafeRef(bbh)) |
| 662 , fDrawablePicts(SkSafeRef(drawablePicts)) |
| 634 , fAnalysis(*fRecord) { | 663 , fAnalysis(*fRecord) { |
| 635 this->needsNewGenID(); | 664 this->needsNewGenID(); |
| 636 } | 665 } |
| 637 | 666 |
| 638 // Note that we are assuming that this entry point will only be called from | 667 // Note that we are assuming that this entry point will only be called from |
| 639 // one thread. Currently the only client of this method is | 668 // one thread. Currently the only client of this method is |
| 640 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single | 669 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single |
| 641 // thread. | 670 // thread. |
| 642 void SkPicture::addDeletionListener(DeletionListener* listener) const { | 671 void SkPicture::addDeletionListener(DeletionListener* listener) const { |
| 643 SkASSERT(listener); | 672 SkASSERT(listener); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 657 int SkPicture::approximateOpCount() const { | 686 int SkPicture::approximateOpCount() const { |
| 658 SkASSERT(fRecord.get() || fData.get()); | 687 SkASSERT(fRecord.get() || fData.get()); |
| 659 if (fRecord.get()) { | 688 if (fRecord.get()) { |
| 660 return fRecord->count(); | 689 return fRecord->count(); |
| 661 } | 690 } |
| 662 if (fData.get()) { | 691 if (fData.get()) { |
| 663 return fData->opCount(); | 692 return fData->opCount(); |
| 664 } | 693 } |
| 665 return 0; | 694 return 0; |
| 666 } | 695 } |
| OLD | NEW |