diff options
author | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 12:58:18 +0000 |
---|---|---|
committer | reveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-29 12:58:18 +0000 |
commit | 91e89bc85631eb357ead53afc8a5642fe7067b60 (patch) | |
tree | 97d0dc2f0c49043c22002f0a36fa08e9cfba65e2 | |
parent | a09159a8a3658a616ebc7e32703c25366ac65a0f (diff) | |
download | chromium_src-91e89bc85631eb357ead53afc8a5642fe7067b60.zip chromium_src-91e89bc85631eb357ead53afc8a5642fe7067b60.tar.gz chromium_src-91e89bc85631eb357ead53afc8a5642fe7067b60.tar.bz2 |
cc: Add ref counted PicturePileImpl class and give each Tile instance a ref.
This is required as tiles are reference counted and there's no
guarantee that they have been destroyed by the time the layer owning
the picture pile is destroyed.
BUG=skia:988
TEST=manual
Review URL: https://chromiumcodereview.appspot.com/11434016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170170 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | cc/cc.gyp | 2 | ||||
-rw-r--r-- | cc/picture_layer_impl.cc | 5 | ||||
-rw-r--r-- | cc/picture_layer_impl.h | 4 | ||||
-rw-r--r-- | cc/picture_pile.cc | 34 | ||||
-rw-r--r-- | cc/picture_pile.h | 12 | ||||
-rw-r--r-- | cc/picture_pile_impl.cc | 46 | ||||
-rw-r--r-- | cc/picture_pile_impl.h | 44 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_tiling_client.cc | 5 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_tiling_client.h | 4 | ||||
-rw-r--r-- | cc/tile.cc | 2 | ||||
-rw-r--r-- | cc/tile.h | 10 | ||||
-rw-r--r-- | cc/tile_manager.cc | 16 | ||||
-rw-r--r-- | cc/tile_manager.h | 2 |
13 files changed, 120 insertions, 66 deletions
@@ -124,6 +124,8 @@ 'picture_layer_tiling_set.h', 'picture_pile.cc', 'picture_pile.h', + 'picture_pile_impl.cc', + 'picture_pile_impl.h', 'platform_color.h', 'prioritized_resource.cc', 'prioritized_resource.h', diff --git a/cc/picture_layer_impl.cc b/cc/picture_layer_impl.cc index 1809596..48cd82d 100644 --- a/cc/picture_layer_impl.cc +++ b/cc/picture_layer_impl.cc @@ -13,7 +13,8 @@ namespace cc { PictureLayerImpl::PictureLayerImpl(int id) : LayerImpl(id), - tilings_(this) { + tilings_(this), + pile_(PicturePileImpl::Create()) { } PictureLayerImpl::~PictureLayerImpl() { @@ -96,7 +97,7 @@ scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling*, return make_scoped_refptr(new Tile( tile_manager, - &pile_, + pile_.get(), rect.size(), GL_RGBA, rect)); diff --git a/cc/picture_layer_impl.h b/cc/picture_layer_impl.h index 4288042..30b88d1 100644 --- a/cc/picture_layer_impl.h +++ b/cc/picture_layer_impl.h @@ -8,7 +8,7 @@ #include "cc/layer_impl.h" #include "cc/picture_layer_tiling.h" #include "cc/picture_layer_tiling_set.h" -#include "cc/picture_pile.h" +#include "cc/picture_pile_impl.h" #include "cc/scoped_ptr_vector.h" namespace cc { @@ -42,7 +42,7 @@ protected: PictureLayerImpl(int id); PictureLayerTilingSet tilings_; - PicturePile pile_; + scoped_refptr<PicturePileImpl> pile_; friend class PictureLayer; DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl); diff --git a/cc/picture_pile.cc b/cc/picture_pile.cc index 7da05be..9a6ac59 100644 --- a/cc/picture_pile.cc +++ b/cc/picture_pile.cc @@ -4,9 +4,8 @@ #include <algorithm> -#include "base/debug/trace_event.h" #include "cc/picture_pile.h" -#include "third_party/skia/include/core/SkCanvas.h" +#include "cc/picture_pile_impl.h" namespace cc { @@ -50,35 +49,10 @@ void PicturePile::Update( pile_[0]->Record(painter, gfx::Rect(gfx::Point(), size_), stats); } -void PicturePile::PushPropertiesTo(PicturePile& other) { - other.pile_.resize(pile_.size()); +void PicturePile::PushPropertiesTo(PicturePileImpl* 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() const { - TRACE_EVENT0("cc", "PicturePile::CloneForDrawing"); - scoped_ptr<PicturePile> clone = make_scoped_ptr(new PicturePile); - 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(); - canvas->translate(-rect.x(), -rect.y()); - 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(); + other->pile_[i] = pile_[i]; } } // namespace cc diff --git a/cc/picture_pile.h b/cc/picture_pile.h index 8ec7093..892fc39 100644 --- a/cc/picture_pile.h +++ b/cc/picture_pile.h @@ -14,7 +14,7 @@ #include "ui/gfx/size.h" namespace cc { - +class PicturePileImpl; struct RenderingStats; class CC_EXPORT PicturePile { @@ -35,15 +35,7 @@ public: RenderingStats& stats); // Update other with a shallow copy of this (main => compositor thread commit) - void PushPropertiesTo(PicturePile& other); - - // Clone a paint-safe version of this picture (with cloned PicturePileRecords) - scoped_ptr<PicturePile> CloneForDrawing() const; - - // Raster a subrect of this PicturePile into the given canvas. - // It's only safe to call paint on a cloned version. - // It is assumed that contentsScale has already been applied to this canvas. - void Raster(SkCanvas* canvas, gfx::Rect rect); + void PushPropertiesTo(PicturePileImpl* other); private: std::vector<scoped_refptr<Picture> > pile_; diff --git a/cc/picture_pile_impl.cc b/cc/picture_pile_impl.cc new file mode 100644 index 0000000..217a5eb --- /dev/null +++ b/cc/picture_pile_impl.cc @@ -0,0 +1,46 @@ +// Copyright 2012 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 "base/debug/trace_event.h" +#include "cc/picture_pile_impl.h" +#include "third_party/skia/include/core/SkCanvas.h" + +namespace cc { + +scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { + return make_scoped_refptr(new PicturePileImpl()); +} + +PicturePileImpl::PicturePileImpl() { +} + +PicturePileImpl::~PicturePileImpl() { +} + +scoped_refptr<PicturePileImpl> PicturePileImpl::CloneForDrawing() const { + TRACE_EVENT0("cc", "PicturePileImpl::CloneForDrawing"); + scoped_refptr<PicturePileImpl> clone = Create(); + clone->pile_.resize(pile_.size()); + for (size_t i = 0; i < pile_.size(); ++i) + clone->pile_[i] = pile_[i]->Clone(); + + return clone; +} + +void PicturePileImpl::Raster(SkCanvas* canvas, gfx::Rect rect) { + // TODO(enne): do this more efficiently, i.e. top down with Skia clips + canvas->save(); + canvas->translate(-rect.x(), -rect.y()); + 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 diff --git a/cc/picture_pile_impl.h b/cc/picture_pile_impl.h new file mode 100644 index 0000000..d188623 --- /dev/null +++ b/cc/picture_pile_impl.h @@ -0,0 +1,44 @@ +// Copyright 2012 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_IMPL_H_ +#define CC_PICTURE_PILE_IMPL_H_ + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "cc/cc_export.h" +#include "cc/picture.h" +#include "cc/scoped_ptr_vector.h" +#include "ui/gfx/rect.h" + +namespace cc { +class PicturePile; + +class CC_EXPORT PicturePileImpl : public base::RefCounted<PicturePileImpl> { +public: + static scoped_refptr<PicturePileImpl> Create(); + + // Clone a paint-safe version of this picture. + scoped_refptr<PicturePileImpl> CloneForDrawing() const; + + // Raster a subrect of this PicturePileImpl into the given canvas. + // It's only safe to call paint on a cloned version. + // It is assumed that contentsScale has already been applied to this canvas. + void Raster(SkCanvas* canvas, gfx::Rect rect); + +private: + friend class PicturePile; + + PicturePileImpl(); + ~PicturePileImpl(); + + std::vector<scoped_refptr<Picture> > pile_; + + friend class base::RefCounted<PicturePileImpl>; + DISALLOW_COPY_AND_ASSIGN(PicturePileImpl); +}; + +} // namespace cc + +#endif // CC_PICTURE_PILE_IMPL_H_ diff --git a/cc/test/fake_picture_layer_tiling_client.cc b/cc/test/fake_picture_layer_tiling_client.cc index f608837..9d13330 100644 --- a/cc/test/fake_picture_layer_tiling_client.cc +++ b/cc/test/fake_picture_layer_tiling_client.cc @@ -7,7 +7,8 @@ namespace cc { FakePictureLayerTilingClient::FakePictureLayerTilingClient() - : tile_manager_(&tile_manager_client_, NULL) { + : tile_manager_(&tile_manager_client_, NULL), + pile_(PicturePileImpl::Create()) { } FakePictureLayerTilingClient::~FakePictureLayerTilingClient() { @@ -17,7 +18,7 @@ scoped_refptr<Tile> FakePictureLayerTilingClient::CreateTile( PictureLayerTiling*, gfx::Rect rect) { return make_scoped_refptr(new Tile(&tile_manager_, - &pile_, + pile_.get(), tile_size_, GL_RGBA, rect)); diff --git a/cc/test/fake_picture_layer_tiling_client.h b/cc/test/fake_picture_layer_tiling_client.h index ecadac0..b61b83e 100644 --- a/cc/test/fake_picture_layer_tiling_client.h +++ b/cc/test/fake_picture_layer_tiling_client.h @@ -6,7 +6,7 @@ #define CC_TEST_FAKE_PICTURE_LAYER_TILING_CLIENT_H_ #include "cc/picture_layer_tiling.h" -#include "cc/picture_pile.h" +#include "cc/picture_pile_impl.h" #include "cc/test/fake_tile_manager_client.h" #include "cc/tile.h" #include "cc/tile_manager.h" @@ -29,7 +29,7 @@ class FakePictureLayerTilingClient : public PictureLayerTilingClient { protected: FakeTileManagerClient tile_manager_client_; TileManager tile_manager_; - PicturePile pile_; + scoped_refptr<PicturePileImpl> pile_; gfx::Size tile_size_; }; @@ -10,7 +10,7 @@ namespace cc { Tile::Tile(TileManager* tile_manager, - PicturePile* picture_pile, + PicturePileImpl* picture_pile, gfx::Size tile_size, GLenum format, gfx::Rect rect_inside_picture) @@ -9,7 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "cc/layer_tree_host_impl.h" -#include "cc/picture_pile.h" +#include "cc/picture_pile_impl.h" #include "cc/resource_provider.h" #include "cc/tile_manager.h" #include "cc/tile_priority.h" @@ -23,13 +23,13 @@ class Tile; class CC_EXPORT Tile : public base::RefCounted<Tile> { public: Tile(TileManager* tile_manager, - PicturePile* picture_pile, + PicturePileImpl* picture_pile, gfx::Size tile_size, GLenum format, gfx::Rect rect_inside_picture); - const PicturePile* picture_pile() const { - return picture_pile_; + const PicturePileImpl* picture_pile() const { + return picture_pile_.get(); } const TilePriority& priority(WhichTree tree) const { @@ -64,7 +64,7 @@ class CC_EXPORT Tile : public base::RefCounted<Tile> { ~Tile(); TileManager* tile_manager_; - PicturePile* picture_pile_; + scoped_refptr<PicturePileImpl> picture_pile_; gfx::Rect tile_size_; GLenum format_; gfx::Rect rect_inside_picture_; diff --git a/cc/tile_manager.cc b/cc/tile_manager.cc index 504aa2e..93f05e3 100644 --- a/cc/tile_manager.cc +++ b/cc/tile_manager.cc @@ -16,7 +16,7 @@ namespace { -void RasterizeTile(cc::PicturePile* picture_pile, +void RasterizeTile(cc::PicturePileImpl* picture_pile, uint8_t* mapped_buffer, const gfx::Rect& rect) { TRACE_EVENT0("cc", "RasterizeTile"); @@ -287,7 +287,7 @@ void TileManager::DispatchMoreRasterTasks() { void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { TRACE_EVENT0("cc", "TileManager::DispatchOneRasterTask"); - scoped_ptr<PicturePile> cloned_picture_pile = + scoped_refptr<PicturePileImpl> cloned_picture_pile = tile->picture_pile()->CloneForDrawing(); ManagedTileState& managed_tile_state = tile->managed_state(); @@ -299,17 +299,12 @@ void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { managed_tile_state.resource_id_is_being_initialized = true; managed_tile_state.can_be_freed = false; - // Get a pointer to the picture pile before the cloned_picture_pile - // reference is passed to base::Bind. - PicturePile* picture_pile = cloned_picture_pile.get(); - DCHECK(picture_pile); - ++pending_raster_tasks_; worker_pool_->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)->PostTaskAndReply( FROM_HERE, base::Bind(&RasterizeTile, - picture_pile, + base::Unretained(cloned_picture_pile.get()), resource_pool_->resource_provider()->mapPixelBuffer( resource_id), tile->rect_inside_picture_), @@ -317,19 +312,18 @@ void TileManager::DispatchOneRasterTask(scoped_refptr<Tile> tile) { base::Unretained(this), tile, resource_id, - base::Passed(&cloned_picture_pile))); + cloned_picture_pile)); } void TileManager::OnRasterTaskCompleted( scoped_refptr<Tile> tile, ResourceProvider::ResourceId resource_id, - scoped_ptr<PicturePile> cloned_picture_pile) { + scoped_refptr<PicturePileImpl> cloned_picture_pile) { TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); --pending_raster_tasks_; // Release raster resources. resource_pool_->resource_provider()->unmapPixelBuffer(resource_id); - cloned_picture_pile.reset(); ManagedTileState& managed_tile_state = tile->managed_state(); managed_tile_state.can_be_freed = true; diff --git a/cc/tile_manager.h b/cc/tile_manager.h index 83e8b75..ee74c2c 100644 --- a/cc/tile_manager.h +++ b/cc/tile_manager.h @@ -90,7 +90,7 @@ class CC_EXPORT TileManager { void OnRasterTaskCompleted( scoped_refptr<Tile>, ResourceProvider::ResourceId, - scoped_ptr<PicturePile>); + scoped_refptr<PicturePileImpl>); void DidFinishTileInitialization(Tile*, ResourceProvider::ResourceId); TileManagerClient* client_; |