diff options
author | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-09 22:37:09 +0000 |
---|---|---|
committer | enne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-09 22:37:09 +0000 |
commit | 3621e18952f50baff1781886ba9997aa6d931877 (patch) | |
tree | 9264738355870a83c9fb49c4e6a4fe306039e04d /cc/picture_pile.cc | |
parent | 78449d188a8fd1883e450fa00d07872239043c08 (diff) | |
download | chromium_src-3621e18952f50baff1781886ba9997aa6d931877.zip chromium_src-3621e18952f50baff1781886ba9997aa6d931877.tar.gz chromium_src-3621e18952f50baff1781886ba9997aa6d931877.tar.bz2 |
cc: Make Picture/PicturePile handle recording/raster
It's not efficient (or tested), but this should be enough to start being useful
once we add the raster/upload/appendQuads path.
Next steps are probably to add tilings to the PictureLayerImpl.
R=nduca@chromium.org
BUG=155209
Review URL: https://chromiumcodereview.appspot.com/11293188
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/picture_pile.cc')
-rw-r--r-- | cc/picture_pile.cc | 90 |
1 files changed, 82 insertions, 8 deletions
diff --git a/cc/picture_pile.cc b/cc/picture_pile.cc index a33147b..63858d2 100644 --- a/cc/picture_pile.cc +++ b/cc/picture_pile.cc @@ -4,7 +4,10 @@ #include "config.h" +#include <algorithm> + #include "cc/picture_pile.h" +#include "third_party/skia/include/core/SkCanvas.h" namespace cc { @@ -14,23 +17,94 @@ PicturePile::PicturePile() { PicturePile::~PicturePile() { } -void PicturePile::invalidate(gfx::Rect rect) { - // TODO(enne) +void PicturePile::Invalidate(gfx::Rect rect) { + invalidation_.Union(rect); +} + +class OutOfBoundsPredicate { +public: + OutOfBoundsPredicate(gfx::Size size) : layer_rect_(gfx::Point(), size) { } + bool operator()(const scoped_refptr<Picture>& picture) { + return !picture->LayerRect().Intersects(layer_rect_); + } + gfx::Rect layer_rect_; +}; + +void PicturePile::Resize(gfx::Size size) { + if (size.width() > size_.width()) { + gfx::Rect invalid( + size_.width(), + 0, + size.width() - size_.width(), + size.height()); + Invalidate(invalid); + } + if (size.height() > size_.height()) { + gfx::Rect invalid( + 0, + size_.height(), + size.width(), + size.height() - size_.height()); + Invalidate(invalid); + } + + // Remove pictures that aren't in bounds anymore. + if (size.width() < size_.width() || size.height() < size_.height()) { + OutOfBoundsPredicate oob(size); + pile_.erase(std::remove_if(pile_.begin(), pile_.end(), oob), pile_.end()); + } + + size_ = size; } -void PicturePile::resize(gfx::Size size) { - // TODO(enne) +void PicturePile::Update(ContentLayerClient* painter, RenderingStats& stats) { + // WebKit paints (i.e. recording) can cause invalidations, so record previous. + invalidation_.Swap(prev_invalidation_); + invalidation_.Clear(); + + // TODO(enne): Add things to the pile, consolidate if needed, etc... + if (pile_.size() == 0) + pile_.push_back(Picture::Create()); + pile_[0]->Record(painter, gfx::Rect(gfx::Point(), size_), stats); } -void PicturePile::update(ContentLayerClient* painter) { - // TODO(enne) +void PicturePile::CopyAllButPile(PicturePile& from, PicturePile& to) { + to.size_ = from.size_; + to.invalidation_ = from.invalidation_; + to.prev_invalidation_ = from.prev_invalidation_; } -void PicturePile::pushPropertiesTo(PicturePile& other) { - other.size_ = size_; +void PicturePile::PushPropertiesTo(PicturePile& other) { + CopyAllButPile(*this, other); + other.pile_.resize(pile_.size()); for (size_t i = 0; i < pile_.size(); ++i) other.pile_[i] = pile_[i]; } +scoped_ptr<PicturePile> PicturePile::CloneForDrawing() { + scoped_ptr<PicturePile> clone = make_scoped_ptr(new PicturePile); + CopyAllButPile(*this, *clone); + + clone->pile_.resize(pile_.size()); + for (size_t i = 0; i < pile_.size(); ++i) + clone->pile_[i] = pile_[i]->Clone(); + + return clone.Pass(); +} + +void PicturePile::Raster(SkCanvas* canvas, gfx::Rect rect) { + // TODO(enne): do this more efficiently, i.e. top down with Skia clips + canvas->save(); + SkRect layer_skrect = SkRect::MakeXYWH(rect.x(), rect.y(), + rect.width(), rect.height()); + canvas->clipRect(layer_skrect); + for (size_t i = 0; i < pile_.size(); ++i) { + if (!pile_[i]->LayerRect().Intersects(rect)) + continue; + pile_[i]->Raster(canvas); + } + canvas->restore(); +} + } // namespace cc |