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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 return true; | 515 return true; |
516 } | 516 } |
517 | 517 |
518 typedef bool (*PictureRecordOptProc)(SkWriter32* writer, int32_t offset, | 518 typedef bool (*PictureRecordOptProc)(SkWriter32* writer, int32_t offset, |
519 SkPaintDictionary* paintDict); | 519 SkPaintDictionary* paintDict); |
520 enum PictureRecordOptType { | 520 enum PictureRecordOptType { |
521 kRewind_OptType, // Optimization rewinds the command stream | 521 kRewind_OptType, // Optimization rewinds the command stream |
522 kCollapseSaveLayer_OptType, // Optimization eliminates a save/restore pair | 522 kCollapseSaveLayer_OptType, // Optimization eliminates a save/restore pair |
523 }; | 523 }; |
524 | 524 |
| 525 enum PictureRecordOptFlags { |
| 526 kSkipIfBBoxHierarchy_Flag = 0x1, // Optimization should be skipped if the |
| 527 // SkPicture has a bounding box hierarchy. |
| 528 }; |
| 529 |
525 struct PictureRecordOpt { | 530 struct PictureRecordOpt { |
526 PictureRecordOptProc fProc; | 531 PictureRecordOptProc fProc; |
527 PictureRecordOptType fType; | 532 PictureRecordOptType fType; |
| 533 unsigned fFlags; |
528 }; | 534 }; |
529 /* | 535 /* |
530 * A list of the optimizations that are tried upon seeing a restore | 536 * A list of the optimizations that are tried upon seeing a restore |
531 * TODO: add a real API for such optimizations | 537 * TODO: add a real API for such optimizations |
532 * Add the ability to fire optimizations on any op (not just RESTORE) | 538 * Add the ability to fire optimizations on any op (not just RESTORE) |
533 */ | 539 */ |
534 static const PictureRecordOpt gPictureRecordOpts[] = { | 540 static const PictureRecordOpt gPictureRecordOpts[] = { |
535 { collapse_save_clip_restore, kRewind_OptType }, | 541 // 'collapse_save_clip_restore' is skipped if there is a BBoxHierarchy |
536 { remove_save_layer1, kCollapseSaveLayer_OptType }, | 542 // because it is redundant with the state traversal optimization in |
537 { remove_save_layer2, kCollapseSaveLayer_OptType } | 543 // SkPictureStateTree, and applying the optimization introduces significant |
| 544 // record time overhead because it requires rewinding contents that were |
| 545 // recorded into the BBoxHierarchy. |
| 546 { collapse_save_clip_restore, kRewind_OptType, kSkipIfBBoxHierarchy_Flag }, |
| 547 { remove_save_layer1, kCollapseSaveLayer_OptType, 0 }, |
| 548 { remove_save_layer2, kCollapseSaveLayer_OptType, 0 } |
538 }; | 549 }; |
539 | 550 |
540 // This is called after an optimization has been applied to the command stream | 551 // This is called after an optimization has been applied to the command stream |
541 // in order to adjust the contents and state of the bounding box hierarchy and | 552 // in order to adjust the contents and state of the bounding box hierarchy and |
542 // state tree to reflect the optimization. | 553 // state tree to reflect the optimization. |
543 static void apply_optimization_to_bbh(PictureRecordOptType opt, SkPictureStateTr
ee* stateTree, | 554 static void apply_optimization_to_bbh(PictureRecordOptType opt, SkPictureStateTr
ee* stateTree, |
544 SkBBoxHierarchy* boundingHierarchy) { | 555 SkBBoxHierarchy* boundingHierarchy) { |
545 switch (opt) { | 556 switch (opt) { |
546 case kCollapseSaveLayer_OptType: | 557 case kCollapseSaveLayer_OptType: |
547 if (NULL != stateTree) { | 558 if (NULL != stateTree) { |
(...skipping 27 matching lines...) Expand all Loading... |
575 } | 586 } |
576 | 587 |
577 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { | 588 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { |
578 fFirstSavedLayerIndex = kNoSavedLayerIndex; | 589 fFirstSavedLayerIndex = kNoSavedLayerIndex; |
579 } | 590 } |
580 | 591 |
581 uint32_t initialOffset, size; | 592 uint32_t initialOffset, size; |
582 size_t opt = 0; | 593 size_t opt = 0; |
583 if (!(fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag))
{ | 594 if (!(fRecordFlags & SkPicture::kDisableRecordOptimizations_RecordingFlag))
{ |
584 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) { | 595 for (opt = 0; opt < SK_ARRAY_COUNT(gPictureRecordOpts); ++opt) { |
| 596 if (0 != (gPictureRecordOpts[opt].fFlags & kSkipIfBBoxHierarchy_Flag
) |
| 597 && NULL != fBoundingHierarchy) { |
| 598 continue; |
| 599 } |
585 if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.t
op(), &fPaints)) { | 600 if ((*gPictureRecordOpts[opt].fProc)(&fWriter, fRestoreOffsetStack.t
op(), &fPaints)) { |
586 // Some optimization fired so don't add the RESTORE | 601 // Some optimization fired so don't add the RESTORE |
587 size = 0; | 602 size = 0; |
588 initialOffset = fWriter.bytesWritten(); | 603 initialOffset = fWriter.bytesWritten(); |
589 apply_optimization_to_bbh(gPictureRecordOpts[opt].fType, | 604 apply_optimization_to_bbh(gPictureRecordOpts[opt].fType, |
590 fStateTree, fBoundingHierarchy); | 605 fStateTree, fBoundingHierarchy); |
591 break; | 606 break; |
592 } | 607 } |
593 } | 608 } |
594 } | 609 } |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 void SkPictureRecord::validateRegions() const { | 1516 void SkPictureRecord::validateRegions() const { |
1502 int count = fRegions.count(); | 1517 int count = fRegions.count(); |
1503 SkASSERT((unsigned) count < 0x1000); | 1518 SkASSERT((unsigned) count < 0x1000); |
1504 for (int index = 0; index < count; index++) { | 1519 for (int index = 0; index < count; index++) { |
1505 const SkFlatData* region = fRegions[index]; | 1520 const SkFlatData* region = fRegions[index]; |
1506 SkASSERT(region); | 1521 SkASSERT(region); |
1507 // region->validate(); | 1522 // region->validate(); |
1508 } | 1523 } |
1509 } | 1524 } |
1510 #endif | 1525 #endif |
OLD | NEW |