| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/paint/paint_op_buffer.h" | 5 #include "cc/paint/paint_op_buffer.h" |
| 6 | 6 |
| 7 #include "base/containers/stack_container.h" | 7 #include "base/containers/stack_container.h" |
| 8 #include "cc/paint/display_item_list.h" | 8 #include "cc/paint/display_item_list.h" |
| 9 #include "cc/paint/paint_record.h" | 9 #include "cc/paint/paint_record.h" |
| 10 #include "third_party/skia/include/core/SkAnnotation.h" | 10 #include "third_party/skia/include/core/SkAnnotation.h" |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 auto& stack = *stack_ptr; | 609 auto& stack = *stack_ptr; |
| 610 if (stack->size()) { | 610 if (stack->size()) { |
| 611 const PaintOp* op = stack->front(); | 611 const PaintOp* op = stack->front(); |
| 612 // Shift paintops forward | 612 // Shift paintops forward |
| 613 stack->erase(stack->begin()); | 613 stack->erase(stack->begin()); |
| 614 return op; | 614 return op; |
| 615 } | 615 } |
| 616 if (!*iter) | 616 if (!*iter) |
| 617 return nullptr; | 617 return nullptr; |
| 618 | 618 |
| 619 const size_t active_range = range_indices[*range_index]; |
| 620 DCHECK_GE(iter->op_idx(), range_starts[active_range]); |
| 621 |
| 619 // This grabs the PaintOp from the current iterator position, and advances it | 622 // This grabs the PaintOp from the current iterator position, and advances it |
| 620 // to the next position immediately. We'll see we reached the end of the | 623 // to the next position immediately. We'll see we reached the end of the |
| 621 // buffer on the next call to this method. | 624 // buffer on the next call to this method. |
| 622 const PaintOp* op = **iter; | 625 const PaintOp* op = **iter; |
| 623 | 626 ++*iter; |
| 624 size_t active_range = range_indices[*range_index]; | |
| 625 DCHECK_GE(iter->op_idx(), range_starts[active_range]); | |
| 626 | 627 |
| 627 if (active_range + 1 == range_starts.size()) { | 628 if (active_range + 1 == range_starts.size()) { |
| 628 // In the last possible range, so go right to the end of the buffer. | 629 // In the last possible range, so let the iter go right to the end of the |
| 629 ++*iter; | 630 // buffer. |
| 630 } else { | 631 return op; |
| 631 size_t range_end = range_starts[active_range + 1]; | |
| 632 DCHECK_LE(iter->op_idx(), range_end); | |
| 633 | |
| 634 ++*iter; | |
| 635 if (iter->op_idx() == range_end) { | |
| 636 if (*range_index + 1 == range_indices.size()) { | |
| 637 // Leaving the last range that we want to iterate. | |
| 638 *iter = iter->end(); | |
| 639 } else { | |
| 640 // Move to the next range. | |
| 641 ++(*range_index); | |
| 642 size_t next_range_start = range_starts[range_indices[*range_index]]; | |
| 643 while (iter->op_idx() < next_range_start) | |
| 644 ++(*iter); | |
| 645 } | |
| 646 } | |
| 647 } | 632 } |
| 648 | 633 |
| 634 const size_t range_end = range_starts[active_range + 1]; |
| 635 DCHECK_LE(iter->op_idx(), range_end); |
| 636 if (iter->op_idx() < range_end) { |
| 637 // Still inside the range, so let the iter be. |
| 638 return op; |
| 639 } |
| 640 |
| 641 if (*range_index + 1 == range_indices.size()) { |
| 642 // We're now past the last range that we want to iterate. |
| 643 *iter = iter->end(); |
| 644 return op; |
| 645 } |
| 646 |
| 647 // Move to the next range. |
| 648 ++(*range_index); |
| 649 size_t next_range_start = range_starts[range_indices[*range_index]]; |
| 650 while (iter->op_idx() < next_range_start) |
| 651 ++(*iter); |
| 649 return op; | 652 return op; |
| 650 } | 653 } |
| 651 | 654 |
| 652 void PaintOpBuffer::playback(SkCanvas* canvas, | 655 void PaintOpBuffer::playback(SkCanvas* canvas, |
| 653 SkPicture::AbortCallback* callback) const { | 656 SkPicture::AbortCallback* callback) const { |
| 657 static auto* zero = new std::vector<size_t>({0}); |
| 654 // Treats the entire PaintOpBuffer as a single range. | 658 // Treats the entire PaintOpBuffer as a single range. |
| 655 PlaybackRanges({0}, {0}, canvas, callback); | 659 PlaybackRanges(*zero, *zero, canvas, callback); |
| 656 } | 660 } |
| 657 | 661 |
| 658 void PaintOpBuffer::PlaybackRanges(const std::vector<size_t>& range_starts, | 662 void PaintOpBuffer::PlaybackRanges(const std::vector<size_t>& range_starts, |
| 659 const std::vector<size_t>& range_indices, | 663 const std::vector<size_t>& range_indices, |
| 660 SkCanvas* canvas, | 664 SkCanvas* canvas, |
| 661 SkPicture::AbortCallback* callback) const { | 665 SkPicture::AbortCallback* callback) const { |
| 662 if (!op_count_) | 666 if (!op_count_) |
| 663 return; | 667 return; |
| 664 if (callback && callback->abort()) | 668 if (callback && callback->abort()) |
| 665 return; | 669 return; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 return std::make_pair(op, skip); | 788 return std::make_pair(op, skip); |
| 785 } | 789 } |
| 786 | 790 |
| 787 void PaintOpBuffer::ShrinkToFit() { | 791 void PaintOpBuffer::ShrinkToFit() { |
| 788 if (!used_ || used_ == reserved_) | 792 if (!used_ || used_ == reserved_) |
| 789 return; | 793 return; |
| 790 ReallocBuffer(used_); | 794 ReallocBuffer(used_); |
| 791 } | 795 } |
| 792 | 796 |
| 793 } // namespace cc | 797 } // namespace cc |
| OLD | NEW |