Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "SkPictureRecord.h" | 8 #include "SkPictureRecord.h" |
| 9 #include "SkTSearch.h" | 9 #include "SkTSearch.h" |
| 10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 SkDebugf("Collapse [%d out of %d] %g%spn", gCollapseCount, gCollapseCalls, | 495 SkDebugf("Collapse [%d out of %d] %g%spn", gCollapseCount, gCollapseCalls, |
| 496 (double)gCollapseCount / gCollapseCalls, "%"); | 496 (double)gCollapseCount / gCollapseCalls, "%"); |
| 497 #endif | 497 #endif |
| 498 | 498 |
| 499 writer->rewindToOffset(saveOffset); | 499 writer->rewindToOffset(saveOffset); |
| 500 return true; | 500 return true; |
| 501 } | 501 } |
| 502 | 502 |
| 503 typedef bool (*PictureRecordOptProc)(SkWriter32* writer, int32_t offset, | 503 typedef bool (*PictureRecordOptProc)(SkWriter32* writer, int32_t offset, |
| 504 SkPaintDictionary* paintDict); | 504 SkPaintDictionary* paintDict); |
| 505 enum PictureRecordOptType { | |
| 506 kRewind_OptType, // Optimization rewinds the command stream | |
| 507 kCollapseSaveLayer_OptType, // Optimization eliminates a save/restore pair | |
| 508 }; | |
| 505 | 509 |
| 510 struct PictureRecordOpt { | |
| 511 PictureRecordOptProc fProc; | |
| 512 PictureRecordOptType fType; | |
| 513 }; | |
| 506 /* | 514 /* |
| 507 * A list of the optimizations that are tried upon seeing a restore | 515 * A list of the optimizations that are tried upon seeing a restore |
| 508 * TODO: add a real API for such optimizations | 516 * TODO: add a real API for such optimizations |
| 509 * Add the ability to fire optimizations on any op (not just RESTORE) | 517 * Add the ability to fire optimizations on any op (not just RESTORE) |
| 510 */ | 518 */ |
| 511 static const PictureRecordOptProc gPictureRecordOpts[] = { | 519 static const PictureRecordOpt gPictureRecordOpts[] = { |
| 512 collapse_save_clip_restore, | 520 { collapse_save_clip_restore, kRewind_OptType }, |
| 513 #ifndef SK_IGNORE_PICTURE_RECORD_SAVE_LAYER_OPT | 521 { remove_save_layer1, kCollapseSaveLayer_OptType }, |
| 514 remove_save_layer1, | 522 { remove_save_layer2, kCollapseSaveLayer_OptType } |
| 515 remove_save_layer2, | |
| 516 #endif | |
| 517 }; | 523 }; |
| 518 | 524 |
| 525 void SkPictureRecord::handleOptimization(int opt) { | |
| 526 switch (gPictureRecordOpts[opt].fType) { | |
| 527 case kCollapseSaveLayer_OptType: | |
|
robertphillips
2013/03/14 18:10:17
NULL !=
| |
| 528 if (fStateTree) { | |
| 529 fStateTree->saveCollapsed(); | |
| 530 } | |
| 531 break; | |
| 532 case kRewind_OptType: | |
| 533 // No need do any rewinding on the state tree, we can just leave the | |
| 534 // unreferenced branches dangling. | |
|
robertphillips
2013/03/14 18:10:17
NULL !=
| |
| 535 if (fBoundingHierarchy) { | |
| 536 fBoundingHierarchy->rewindInserts(); | |
| 537 } | |
| 538 break; | |
| 539 default: | |
| 540 SkASSERT(0); | |
| 541 } | |
| 542 } | |
| 543 | |
| 519 void SkPictureRecord::restore() { | 544 void SkPictureRecord::restore() { |
| 520 // FIXME: SkDeferredCanvas needs to be refactored to respect | 545 // FIXME: SkDeferredCanvas needs to be refactored to respect |
| 521 // save/restore balancing so that the following test can be | 546 // save/restore balancing so that the following test can be |
| 522 // turned on permanently. | 547 // turned on permanently. |
| 523 #if 0 | 548 #if 0 |
| 524 SkASSERT(fRestoreOffsetStack.count() > 1); | 549 SkASSERT(fRestoreOffsetStack.count() > 1); |
| 525 #endif | 550 #endif |
| 526 | 551 |
| 527 // check for underflow | 552 // check for underflow |
| 528 if (fRestoreOffsetStack.count() == 0) { | 553 if (fRestoreOffsetStack.count() == 0) { |
| 529 return; | 554 return; |
| 530 } | 555 } |
| 531 | 556 |
| 532 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { | 557 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { |
| 533 fFirstSavedLayerIndex = kNoSavedLayerIndex; | 558 fFirstSavedLayerIndex = kNoSavedLayerIndex; |
| 534 } | 559 } |
| 535 | 560 |
| 536 uint32_t initialOffset, size; | 561 uint32_t initialOffset, size; |
| 537 size_t opt; | 562 size_t opt; |
| 538 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) { | 563 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) { |
| 539 if ((*gPictureRecordOpts[opt])(&fWriter, fRestoreOffsetStack.top(), &fPa ints)) { | 564 if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.top() , &fPaints)) { |
| 540 // Some optimization fired so don't add the RESTORE | 565 // Some optimization fired so don't add the RESTORE |
| 541 size = 0; | 566 size = 0; |
| 542 initialOffset = fWriter.size(); | 567 initialOffset = fWriter.size(); |
| 568 handleOptimization(opt); | |
| 543 break; | 569 break; |
| 544 } | 570 } |
| 545 } | 571 } |
| 546 | 572 |
| 547 if (SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { | 573 if (SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { |
| 548 // No optimization fired so add the RESTORE | 574 // No optimization fired so add the RESTORE |
| 549 fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.size ()); | 575 fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWriter.size ()); |
| 550 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code | 576 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code |
| 551 initialOffset = this->addDraw(RESTORE, &size); | 577 initialOffset = this->addDraw(RESTORE, &size); |
| 552 } | 578 } |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1415 void SkPictureRecord::validateRegions() const { | 1441 void SkPictureRecord::validateRegions() const { |
| 1416 int count = fRegions.count(); | 1442 int count = fRegions.count(); |
| 1417 SkASSERT((unsigned) count < 0x1000); | 1443 SkASSERT((unsigned) count < 0x1000); |
| 1418 for (int index = 0; index < count; index++) { | 1444 for (int index = 0; index < count; index++) { |
| 1419 const SkFlatData* region = fRegions[index]; | 1445 const SkFlatData* region = fRegions[index]; |
| 1420 SkASSERT(region); | 1446 SkASSERT(region); |
| 1421 // region->validate(); | 1447 // region->validate(); |
| 1422 } | 1448 } |
| 1423 } | 1449 } |
| 1424 #endif | 1450 #endif |
| OLD | NEW |