summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-17 03:00:11 +0000
committerenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-17 03:00:11 +0000
commit84339434690074b89703225029ed5890a3715bbb (patch)
tree1c056eeef021d70b9bc231541a9986c86293672e /cc
parent3b265315f3c7ca648828a1a1174f064d2d071423 (diff)
downloadchromium_src-84339434690074b89703225029ed5890a3715bbb.zip
chromium_src-84339434690074b89703225029ed5890a3715bbb.tar.gz
chromium_src-84339434690074b89703225029ed5890a3715bbb.tar.bz2
cc: Add picture pile base class
PicturePile and PicturePileImpl are too similar and share nearly the same data members, so merging this code will make it easier to change the underlying PicturePile storage. R=danakj@chromium.org BUG=167213 Review URL: https://chromiumcodereview.appspot.com/11971024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177325 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/cc.gyp2
-rw-r--r--cc/managed_memory_policy.cc1
-rw-r--r--cc/picture_layer.cc11
-rw-r--r--cc/picture_layer.h2
-rw-r--r--cc/picture_pile.cc43
-rw-r--r--cc/picture_pile.h31
-rw-r--r--cc/picture_pile_base.cc57
-rw-r--r--cc/picture_pile_base.h42
-rw-r--r--cc/picture_pile_impl.cc17
-rw-r--r--cc/picture_pile_impl.h17
10 files changed, 130 insertions, 93 deletions
diff --git a/cc/cc.gyp b/cc/cc.gyp
index 46341bf..5c6388c 100644
--- a/cc/cc.gyp
+++ b/cc/cc.gyp
@@ -152,6 +152,8 @@
'picture_layer_tiling_set.h',
'picture_pile.cc',
'picture_pile.h',
+ 'picture_pile_base.cc',
+ 'picture_pile_base.h',
'picture_pile_impl.cc',
'picture_pile_impl.h',
'pinch_zoom_viewport.cc',
diff --git a/cc/managed_memory_policy.cc b/cc/managed_memory_policy.cc
index b583bd9..01e793a 100644
--- a/cc/managed_memory_policy.cc
+++ b/cc/managed_memory_policy.cc
@@ -4,6 +4,7 @@
#include "managed_memory_policy.h"
+#include "base/logging.h"
#include "priority_calculator.h"
namespace cc {
diff --git a/cc/picture_layer.cc b/cc/picture_layer.cc
index 7924739..9114d6f 100644
--- a/cc/picture_layer.cc
+++ b/cc/picture_layer.cc
@@ -16,6 +16,7 @@ scoped_refptr<PictureLayer> PictureLayer::create(ContentLayerClient* client) {
PictureLayer::PictureLayer(ContentLayerClient* client) :
client_(client),
+ pile_(make_scoped_refptr(new PicturePile())),
is_mask_(false) {
}
@@ -38,7 +39,7 @@ void PictureLayer::pushPropertiesTo(LayerImpl* base_layer) {
layer_impl->tilings_.SetLayerBounds(bounds());
layer_impl->invalidation_.Clear();
layer_impl->invalidation_.Swap(pile_invalidation_);
- pile_.PushPropertiesTo(layer_impl->pile_);
+ pile_->PushPropertiesTo(layer_impl->pile_);
layer_impl->SyncFromActiveLayer();
}
@@ -46,7 +47,7 @@ void PictureLayer::pushPropertiesTo(LayerImpl* base_layer) {
void PictureLayer::setLayerTreeHost(LayerTreeHost* host) {
Layer::setLayerTreeHost(host);
if (host)
- pile_.SetMinContentsScale(host->settings().minimumContentsScale);
+ pile_->SetMinContentsScale(host->settings().minimumContentsScale);
}
void PictureLayer::setNeedsDisplayRect(const gfx::RectF& layer_rect) {
@@ -61,17 +62,17 @@ void PictureLayer::setNeedsDisplayRect(const gfx::RectF& layer_rect) {
void PictureLayer::update(ResourceUpdateQueue&, const OcclusionTracker*,
RenderingStats& stats) {
- if (pile_.size() == bounds() && pending_invalidation_.IsEmpty())
+ if (pile_->size() == bounds() && pending_invalidation_.IsEmpty())
return;
- pile_.Resize(bounds());
+ pile_->Resize(bounds());
// Calling paint in WebKit can sometimes cause invalidations, so save
// off the invalidation prior to calling update.
pile_invalidation_.Swap(pending_invalidation_);
pending_invalidation_.Clear();
- pile_.Update(client_, pile_invalidation_, stats);
+ pile_->Update(client_, pile_invalidation_, stats);
}
void PictureLayer::setIsMask(bool is_mask) {
diff --git a/cc/picture_layer.h b/cc/picture_layer.h
index f3ec15a..731b90b 100644
--- a/cc/picture_layer.h
+++ b/cc/picture_layer.h
@@ -41,7 +41,7 @@ class CC_EXPORT PictureLayer : public ContentsScalingLayer {
private:
ContentLayerClient* client_;
- PicturePile pile_;
+ scoped_refptr<PicturePile> pile_;
// Invalidation to use the next time update is called.
Region pending_invalidation_;
// Invalidation from the last time update was called.
diff --git a/cc/picture_pile.cc b/cc/picture_pile.cc
index 565c6c2..fcf746a 100644
--- a/cc/picture_pile.cc
+++ b/cc/picture_pile.cc
@@ -6,6 +6,7 @@
#include "cc/picture_pile.h"
#include "cc/picture_pile_impl.h"
+#include "cc/region.h"
namespace {
// Maximum number of pictures that can overlap before we collapse them into
@@ -18,43 +19,7 @@ const float kResetThreshold = 0.7f;
namespace cc {
-PicturePile::PicturePile()
- : min_contents_scale_(0),
- buffer_pixels_(0) {
- SetMinContentsScale(1);
-}
-
-PicturePile::~PicturePile() {
-}
-
-void PicturePile::Resize(gfx::Size size) {
- if (size_ == size)
- return;
-
- pile_.clear();
- size_ = size;
-}
-
-void PicturePile::SetMinContentsScale(float min_contents_scale) {
- DCHECK(min_contents_scale);
- if (min_contents_scale_ == min_contents_scale)
- return;
-
- pile_.clear();
- min_contents_scale_ = min_contents_scale;
-
- // Picture contents are played back scaled. When the final contents scale is
- // less than 1 (i.e. low res), then multiple recorded pixels will be used
- // to raster one final pixel. To avoid splitting a final pixel across
- // pictures (which would result in incorrect rasterization due to blending), a
- // buffer margin is added so that any picture can be snapped to integral
- // final pixels.
- //
- // For example, if a 1/4 contents scale is used, then that would be 3 buffer
- // pixels, since that's the minimum number of pixels to add so that resulting
- // content can be snapped to a four pixel aligned grid.
- buffer_pixels_ = static_cast<int>(ceil(1 / min_contents_scale_) - 1);
- buffer_pixels_ = std::max(0, buffer_pixels_);
+PicturePile::PicturePile() {
}
void PicturePile::Update(
@@ -132,8 +97,8 @@ void PicturePile::ResetPile(ContentLayerClient* painter,
}
void PicturePile::PushPropertiesTo(PicturePileImpl* other) {
- other->pile_ = pile_;
- other->min_contents_scale_ = min_contents_scale_;
+ PicturePileBase::PushPropertiesTo(other);
+
// Remove all old clones.
other->clones_.clear();
}
diff --git a/cc/picture_pile.h b/cc/picture_pile.h
index 851f87c..79225ee 100644
--- a/cc/picture_pile.h
+++ b/cc/picture_pile.h
@@ -5,31 +5,17 @@
#ifndef CC_PICTURE_PILE_H_
#define CC_PICTURE_PILE_H_
-#include <list>
-
-#include "base/basictypes.h"
-#include "cc/cc_export.h"
-#include "cc/picture.h"
-#include "cc/region.h"
-#include "cc/scoped_ptr_vector.h"
+#include "cc/picture_pile_base.h"
#include "ui/gfx/rect.h"
-#include "ui/gfx/size.h"
namespace cc {
class PicturePileImpl;
+class Region;
struct RenderingStats;
-class CC_EXPORT PicturePile {
-public:
+class CC_EXPORT PicturePile : public PicturePileBase {
+ public:
PicturePile();
- ~PicturePile();
-
- // Resize the PicturePile, invalidating / dropping recorded pictures as
- // necessary.
- void Resize(gfx::Size);
- gfx::Size size() const { return size_; }
-
- void SetMinContentsScale(float min_contents_scale);
// Re-record parts of the picture that are invalid.
// Invalidations are in layer space.
@@ -41,18 +27,13 @@ public:
// Update other with a shallow copy of this (main => compositor thread commit)
void PushPropertiesTo(PicturePileImpl* other);
-private:
+ private:
+ ~PicturePile();
friend class PicturePileImpl;
void InvalidateRect(gfx::Rect invalidation);
void ResetPile(ContentLayerClient* painter, RenderingStats& stats);
- typedef std::list<scoped_refptr<Picture> > Pile;
- Pile pile_;
- gfx::Size size_;
- float min_contents_scale_;
- int buffer_pixels_;
-
DISALLOW_COPY_AND_ASSIGN(PicturePile);
};
diff --git a/cc/picture_pile_base.cc b/cc/picture_pile_base.cc
new file mode 100644
index 0000000..62fe686
--- /dev/null
+++ b/cc/picture_pile_base.cc
@@ -0,0 +1,57 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/picture_pile_base.h"
+
+#include "base/logging.h"
+
+namespace cc {
+
+PicturePileBase::PicturePileBase()
+ : min_contents_scale_(0),
+ buffer_pixels_(0) {
+ SetMinContentsScale(1);
+}
+
+PicturePileBase::~PicturePileBase() {
+}
+
+void PicturePileBase::Resize(gfx::Size size) {
+ if (size_ == size)
+ return;
+
+ pile_.clear();
+ size_ = size;
+}
+
+void PicturePileBase::SetMinContentsScale(float min_contents_scale) {
+ DCHECK(min_contents_scale);
+ if (min_contents_scale_ == min_contents_scale)
+ return;
+
+ pile_.clear();
+ min_contents_scale_ = min_contents_scale;
+
+ // Picture contents are played back scaled. When the final contents scale is
+ // less than 1 (i.e. low res), then multiple recorded pixels will be used
+ // to raster one final pixel. To avoid splitting a final pixel across
+ // pictures (which would result in incorrect rasterization due to blending), a
+ // buffer margin is added so that any picture can be snapped to integral
+ // final pixels.
+ //
+ // For example, if a 1/4 contents scale is used, then that would be 3 buffer
+ // pixels, since that's the minimum number of pixels to add so that resulting
+ // content can be snapped to a four pixel aligned grid.
+ buffer_pixels_ = static_cast<int>(ceil(1 / min_contents_scale_) - 1);
+ buffer_pixels_ = std::max(0, buffer_pixels_);
+}
+
+void PicturePileBase::PushPropertiesTo(PicturePileBase* other) {
+ other->pile_ = pile_;
+ other->size_ = size_;
+ other->min_contents_scale_ = min_contents_scale_;
+ other->buffer_pixels_ = buffer_pixels_;
+}
+
+} // namespace cc
diff --git a/cc/picture_pile_base.h b/cc/picture_pile_base.h
new file mode 100644
index 0000000..0cdb8ac
--- /dev/null
+++ b/cc/picture_pile_base.h
@@ -0,0 +1,42 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_PICTURE_PILE_BASE_H_
+#define CC_PICTURE_PILE_BASE_H_
+
+#include <list>
+
+#include "base/memory/ref_counted.h"
+#include "cc/cc_export.h"
+#include "cc/picture.h"
+#include "ui/gfx/size.h"
+
+namespace cc {
+
+class CC_EXPORT PicturePileBase : public base::RefCounted<PicturePileBase> {
+ public:
+ PicturePileBase();
+
+ void Resize(gfx::Size size);
+ gfx::Size size() const { return size_; }
+ void SetMinContentsScale(float min_contents_scale);
+
+ void PushPropertiesTo(PicturePileBase* other);
+
+ protected:
+ ~PicturePileBase();
+
+ typedef std::list<scoped_refptr<Picture> > Pile;
+ Pile pile_;
+ gfx::Size size_;
+ float min_contents_scale_;
+ int buffer_pixels_;
+
+ friend class base::RefCounted<PicturePileBase>;
+ DISALLOW_COPY_AND_ASSIGN(PicturePileBase);
+};
+
+} // namespace cc
+
+#endif // CC_PICTURE_PILE_H_
diff --git a/cc/picture_pile_impl.cc b/cc/picture_pile_impl.cc
index ba9d13d..4155664 100644
--- a/cc/picture_pile_impl.cc
+++ b/cc/picture_pile_impl.cc
@@ -4,10 +4,12 @@
#include "base/debug/trace_event.h"
#include "cc/picture_pile_impl.h"
+#include "cc/region.h"
#include "cc/rendering_stats.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkSize.h"
#include "ui/gfx/rect_conversions.h"
+#include "ui/gfx/skia_util.h"
namespace cc {
@@ -15,8 +17,7 @@ scoped_refptr<PicturePileImpl> PicturePileImpl::Create() {
return make_scoped_refptr(new PicturePileImpl());
}
-PicturePileImpl::PicturePileImpl()
- : min_contents_scale_(1) {
+PicturePileImpl::PicturePileImpl() {
}
PicturePileImpl::~PicturePileImpl() {
@@ -38,8 +39,7 @@ PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread(
scoped_refptr<PicturePileImpl> PicturePileImpl::CloneForDrawing() const {
TRACE_EVENT0("cc", "PicturePileImpl::CloneForDrawing");
scoped_refptr<PicturePileImpl> clone = Create();
- for (PicturePile::Pile::const_iterator i = pile_.begin();
- i != pile_.end(); ++i)
+ for (Pile::const_iterator i = pile_.begin(); i != pile_.end(); ++i)
clone->pile_.push_back((*i)->Clone());
clone->min_contents_scale_ = min_contents_scale_;
@@ -66,8 +66,7 @@ void PicturePileImpl::Raster(
// Raster through the pile top down, using clips to make sure that
// pictures on top are not overdrawn by pictures on the bottom.
Region unclipped(content_rect);
- for (PicturePile::Pile::reverse_iterator i = pile_.rbegin();
- i != pile_.rend(); ++i) {
+ for (Pile::reverse_iterator i = pile_.rbegin(); i != pile_.rend(); ++i) {
// This is intentionally *enclosed* rect, so that the clip is aligned on
// integral post-scale content pixels and does not extend past the edges of
// the picture's layer rect. The min_contents_scale enforces that enough
@@ -94,8 +93,7 @@ void PicturePileImpl::Raster(
void PicturePileImpl::GatherPixelRefs(
const gfx::Rect& rect, std::list<skia::LazyPixelRef*>& pixel_refs) {
std::list<skia::LazyPixelRef*> result;
- for (PicturePile::Pile::const_iterator i = pile_.begin();
- i != pile_.end(); ++i) {
+ for (Pile::const_iterator i = pile_.begin(); i != pile_.end(); ++i) {
(*i)->GatherPixelRefs(rect, result);
pixel_refs.splice(pixel_refs.end(), result);
}
@@ -105,8 +103,7 @@ skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() {
TRACE_EVENT0("cc", "PicturePileImpl::GetFlattenedPicture");
gfx::Rect layer_rect;
- for (PicturePile::Pile::const_iterator i = pile_.begin();
- i != pile_.end(); ++i) {
+ for (Pile::const_iterator i = pile_.begin(); i != pile_.end(); ++i) {
layer_rect.Union((*i)->LayerRect());
}
diff --git a/cc/picture_pile_impl.h b/cc/picture_pile_impl.h
index 9418e90..5ca526f 100644
--- a/cc/picture_pile_impl.h
+++ b/cc/picture_pile_impl.h
@@ -8,22 +8,17 @@
#include <list>
#include <map>
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
#include "base/threading/thread.h"
#include "cc/cc_export.h"
-#include "cc/picture.h"
-#include "cc/picture_pile.h"
-#include "cc/scoped_ptr_vector.h"
+#include "cc/picture_pile_base.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkPicture.h"
-#include "ui/gfx/rect.h"
namespace cc {
struct RenderingStats;
-class CC_EXPORT PicturePileImpl : public base::RefCounted<PicturePileImpl> {
-public:
+class CC_EXPORT PicturePileImpl : public PicturePileBase {
+ public:
static scoped_refptr<PicturePileImpl> Create();
// Get paint-safe version of this picture for a specific thread.
@@ -45,20 +40,16 @@ public:
skia::RefPtr<SkPicture> GetFlattenedPicture();
-private:
+ private:
friend class PicturePile;
PicturePileImpl();
~PicturePileImpl();
- PicturePile::Pile pile_;
- float min_contents_scale_;
-
typedef std::map<base::PlatformThreadId, scoped_refptr<PicturePileImpl> >
CloneMap;
CloneMap clones_;
- friend class base::RefCounted<PicturePileImpl>;
DISALLOW_COPY_AND_ASSIGN(PicturePileImpl);
};