Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "cc/picture_pile.h" | 7 #include "cc/picture_pile.h" |
| 8 #include "cc/picture_pile_impl.h" | 8 #include "cc/picture_pile_impl.h" |
| 9 | 9 |
| 10 namespace { | |
| 11 const float kResetThreshold = 0.7f; | |
|
enne (OOO)
2012/12/04 04:11:09
Can you add a comment for what this constant is fo
| |
| 12 } | |
| 13 | |
| 10 namespace cc { | 14 namespace cc { |
| 11 | 15 |
| 12 PicturePile::PicturePile() { | 16 PicturePile::PicturePile() { |
| 13 } | 17 } |
| 14 | 18 |
| 15 PicturePile::~PicturePile() { | 19 PicturePile::~PicturePile() { |
| 16 } | 20 } |
| 17 | 21 |
| 18 class OutOfBoundsPredicate { | 22 void PicturePile::Resize(gfx::Size size) { |
| 19 public: | 23 if (size_ == size) |
| 20 OutOfBoundsPredicate(gfx::Size size) : layer_rect_(gfx::Point(), size) { } | 24 return; |
| 21 bool operator()(const scoped_refptr<Picture>& picture) { | |
| 22 return !picture->LayerRect().Intersects(layer_rect_); | |
| 23 } | |
| 24 gfx::Rect layer_rect_; | |
| 25 }; | |
| 26 | 25 |
| 27 void PicturePile::Resize(gfx::Size size) { | 26 pile_.clear(); |
|
enne (OOO)
2012/12/04 04:11:09
Ah, quite right. I guess if you're resizing and ha
| |
| 28 // Remove pictures that aren't in bounds anymore. | |
| 29 if (size.width() < size_.width() || size.height() < size_.height()) { | |
| 30 OutOfBoundsPredicate oob(size); | |
| 31 pile_.erase(std::remove_if(pile_.begin(), pile_.end(), oob), pile_.end()); | |
| 32 } | |
| 33 | |
| 34 size_ = size; | 27 size_ = size; |
| 35 } | 28 } |
| 36 | 29 |
| 37 void PicturePile::Update( | 30 void PicturePile::Update( |
| 38 ContentLayerClient* painter, | 31 ContentLayerClient* painter, |
| 39 const Region&, | 32 const Region& invalidation, |
| 40 RenderingStats& stats) { | 33 RenderingStats& stats) { |
| 41 // TODO(enne): Add things to the pile, consolidate if needed, etc... | 34 if (pile_.empty()) { |
| 42 // TODO(enne): Only re-record invalidated areas. | 35 ResetPile(painter, stats); |
| 43 // TODO(enne): Also re-record areas that have been newly exposed by resize. | 36 return; |
| 37 } | |
| 44 | 38 |
| 45 // Always re-record the entire layer into a single picture, just to get | 39 for (Region::Iterator i(invalidation); i.has_rect(); i.next()) |
| 46 // this class up and running. | 40 InvalidateRect(i.rect()); |
| 41 | |
| 42 for (Pile::iterator i = pile_.begin(); i != pile_.end(); ++i) { | |
| 43 if (!(*i)->HasRecording()) | |
| 44 (*i)->Record(painter, stats); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 class FullyContainedPredicate { | |
| 49 public: | |
| 50 FullyContainedPredicate(gfx::Rect rect) : layer_rect_(rect) { } | |
| 51 bool operator()(const scoped_refptr<Picture>& picture) { | |
| 52 return layer_rect_.Contains(picture->LayerRect()); | |
| 53 } | |
| 54 gfx::Rect layer_rect_; | |
| 55 }; | |
| 56 | |
| 57 void PicturePile::InvalidateRect(gfx::Rect invalidation) { | |
| 58 if (invalidation.IsEmpty()) | |
| 59 return; | |
| 60 | |
| 61 std::vector<Pile::iterator> overlaps; | |
| 62 for (Pile::iterator i = pile_.begin(); i != pile_.end(); ++i) { | |
| 63 if ((*i)->LayerRect().Contains(invalidation) && !(*i)->HasRecording()) | |
| 64 return; | |
| 65 if ((*i)->LayerRect().Intersects(invalidation) && i != pile_.begin()) | |
| 66 overlaps.push_back(i); | |
| 67 } | |
| 68 | |
| 69 gfx::Rect picture_rect = invalidation; | |
| 70 for (int j = 0; j < overlaps.size(); j++) | |
| 71 picture_rect = gfx::UnionRects(picture_rect, (*overlaps[j])->LayerRect()); | |
| 72 if (picture_rect.size().GetArea() / static_cast<float>(size_.GetArea()) | |
| 73 > kResetThreshold) | |
|
enne (OOO)
2012/12/04 04:11:09
style nit: I'm pretty sure operators go on the pre
| |
| 74 picture_rect = gfx::Rect(size_); | |
| 75 | |
| 76 FullyContainedPredicate pred(picture_rect); | |
| 77 pile_.erase(std::remove_if(pile_.begin(), pile_.end(), pred), pile_.end()); | |
| 78 | |
| 79 pile_.push_back(Picture::Create(picture_rect)); | |
| 80 } | |
| 81 | |
| 82 | |
| 83 void PicturePile::ResetPile(ContentLayerClient* painter, | |
| 84 RenderingStats& stats) { | |
| 47 pile_.clear(); | 85 pile_.clear(); |
| 48 pile_.push_back(Picture::Create()); | 86 |
| 49 pile_[0]->Record(painter, gfx::Rect(gfx::Point(), size_), stats); | 87 scoped_refptr<Picture> base_picture = Picture::Create(gfx::Rect(size_)); |
| 88 base_picture->Record(painter, stats); | |
| 89 pile_.push_back(base_picture); | |
| 50 } | 90 } |
| 51 | 91 |
| 52 void PicturePile::PushPropertiesTo(PicturePileImpl* other) { | 92 void PicturePile::PushPropertiesTo(PicturePileImpl* other) { |
| 53 other->pile_.resize(pile_.size()); | 93 other->pile_ = pile_; |
| 54 for (size_t i = 0; i < pile_.size(); ++i) | |
| 55 other->pile_[i] = pile_[i]; | |
| 56 } | 94 } |
| 57 | 95 |
| 58 } // namespace cc | 96 } // namespace cc |
| OLD | NEW |