diff options
Diffstat (limited to 'cc')
-rw-r--r-- | cc/base/BUILD.gn | 1 | ||||
-rw-r--r-- | cc/base/ref_counted_managed.h | 65 | ||||
-rw-r--r-- | cc/cc.gyp | 1 | ||||
-rw-r--r-- | cc/debug/rasterize_and_record_benchmark_impl.cc | 4 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.cc | 5 | ||||
-rw-r--r-- | cc/layers/picture_layer_impl.h | 4 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling.cc | 25 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling.h | 22 | ||||
-rw-r--r-- | cc/resources/picture_layer_tiling_unittest.cc | 4 | ||||
-rw-r--r-- | cc/resources/tile.cc | 7 | ||||
-rw-r--r-- | cc/resources/tile.h | 13 | ||||
-rw-r--r-- | cc/resources/tile_manager.cc | 21 | ||||
-rw-r--r-- | cc/resources/tile_manager.h | 22 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_tiling_client.cc | 5 | ||||
-rw-r--r-- | cc/test/fake_picture_layer_tiling_client.h | 4 |
15 files changed, 68 insertions, 135 deletions
diff --git a/cc/base/BUILD.gn b/cc/base/BUILD.gn index 261bb1c..c0d5475 100644 --- a/cc/base/BUILD.gn +++ b/cc/base/BUILD.gn @@ -15,7 +15,6 @@ source_set("base") { "invalidation_region.h", "math_util.cc", "math_util.h", - "ref_counted_managed.h", "region.cc", "region.h", "rolling_time_delta_history.cc", diff --git a/cc/base/ref_counted_managed.h b/cc/base/ref_counted_managed.h deleted file mode 100644 index 8bb836f..0000000 --- a/cc/base/ref_counted_managed.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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_BASE_REF_COUNTED_MANAGED_H_ -#define CC_BASE_REF_COUNTED_MANAGED_H_ - -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "cc/base/cc_export.h" - -namespace cc { - -template <typename T> class RefCountedManaged; - -template <typename T> -class CC_EXPORT RefCountedManager { - protected: - RefCountedManager() : live_object_count_(0) {} - ~RefCountedManager() { - CHECK_EQ(0, live_object_count_); - } - - virtual void Release(T* object) = 0; - - private: - friend class RefCountedManaged<T>; - int live_object_count_; -}; - -template <typename T> -class CC_EXPORT RefCountedManaged : public base::subtle::RefCountedBase { - public: - explicit RefCountedManaged(RefCountedManager<T>* manager) - : manager_(manager) { - manager_->live_object_count_++; - } - - void AddRef() const { - base::subtle::RefCountedBase::AddRef(); - } - - void Release() { - if (base::subtle::RefCountedBase::Release()) { - DCHECK_GT(manager_->live_object_count_, 0); - manager_->live_object_count_--; - - // This must be the last statement in case manager deletes - // the object immediately. - manager_->Release(static_cast<T*>(this)); - } - } - - protected: - ~RefCountedManaged() {} - - private: - RefCountedManager<T>* manager_; - - DISALLOW_COPY_AND_ASSIGN(RefCountedManaged<T>); -}; - -} // namespace cc - -#endif // CC_BASE_REF_COUNTED_MANAGED_H_ @@ -73,7 +73,6 @@ 'base/invalidation_region.h', 'base/math_util.cc', 'base/math_util.h', - 'base/ref_counted_managed.h', 'base/region.cc', 'base/region.h', 'base/rolling_time_delta_history.cc', diff --git a/cc/debug/rasterize_and_record_benchmark_impl.cc b/cc/debug/rasterize_and_record_benchmark_impl.cc index ef97419..c5c748b 100644 --- a/cc/debug/rasterize_and_record_benchmark_impl.cc +++ b/cc/debug/rasterize_and_record_benchmark_impl.cc @@ -72,8 +72,8 @@ class FixedInvalidationPictureLayerTilingClient const Region invalidation) : base_client_(base_client), invalidation_(invalidation) {} - scoped_refptr<Tile> CreateTile(float contents_scale, - const gfx::Rect& content_rect) override { + ScopedTilePtr CreateTile(float contents_scale, + const gfx::Rect& content_rect) override { return base_client_->CreateTile(contents_scale, content_rect); } diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index 495ed87..f11ad276 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -618,9 +618,8 @@ Region PictureLayerImpl::GetInvalidationRegion() { return IntersectRegions(invalidation_, update_rect()); } -scoped_refptr<Tile> PictureLayerImpl::CreateTile( - float contents_scale, - const gfx::Rect& content_rect) { +ScopedTilePtr PictureLayerImpl::CreateTile(float contents_scale, + const gfx::Rect& content_rect) { int flags = 0; // We don't handle solid color masks, so we shouldn't bother analyzing those. diff --git a/cc/layers/picture_layer_impl.h b/cc/layers/picture_layer_impl.h index 9155de2..f8ffc67 100644 --- a/cc/layers/picture_layer_impl.h +++ b/cc/layers/picture_layer_impl.h @@ -55,8 +55,8 @@ class CC_EXPORT PictureLayerImpl Region GetInvalidationRegion() override; // PictureLayerTilingClient overrides. - scoped_refptr<Tile> CreateTile(float contents_scale, - const gfx::Rect& content_rect) override; + ScopedTilePtr CreateTile(float contents_scale, + const gfx::Rect& content_rect) override; gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override; const Region* GetPendingInvalidation() override; const PictureLayerTiling* GetPendingOrActiveTwinTiling( diff --git a/cc/resources/picture_layer_tiling.cc b/cc/resources/picture_layer_tiling.cc index 015c492..21c1417 100644 --- a/cc/resources/picture_layer_tiling.cc +++ b/cc/resources/picture_layer_tiling.cc @@ -106,10 +106,11 @@ Tile* PictureLayerTiling::CreateTile(int i, int j) { if (!raster_source_->CoversRect(tile_rect, contents_scale_)) return nullptr; - scoped_refptr<Tile> tile = client_->CreateTile(contents_scale_, tile_rect); + ScopedTilePtr tile = client_->CreateTile(contents_scale_, tile_rect); + Tile* raw_ptr = tile.get(); tile->set_tiling_index(i, j); - tiles_[key] = tile; - return tile.get(); + tiles_.add(key, tile.Pass()); + return raw_ptr; } void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { @@ -148,16 +149,16 @@ void PictureLayerTiling::TakeTilesAndPropertiesFrom( SetLiveTilesRect(pending_twin->live_tiles_rect()); } - if (tiles_.size() < pending_twin->tiles_.size()) { + if (tiles_.empty()) { tiles_.swap(pending_twin->tiles_); - tiles_.insert(pending_twin->tiles_.begin(), pending_twin->tiles_.end()); } else { - for (TileMap::value_type& tile_pair : pending_twin->tiles_) { - tiles_[tile_pair.first].swap(tile_pair.second); - DCHECK(tiles_[tile_pair.first]->raster_source() == raster_source_.get()); + while (!pending_twin->tiles_.empty()) { + TileMapKey key = pending_twin->tiles_.begin()->first; + tiles_.set(key, pending_twin->tiles_.take_and_erase(key)); + DCHECK(tiles_.get(key)->raster_source() == raster_source_.get()); } } - pending_twin->tiles_.clear(); + DCHECK(pending_twin->tiles_.empty()); if (create_missing_tiles) CreateMissingTilesInLiveTilesRect(); @@ -678,7 +679,7 @@ void PictureLayerTiling::SetLiveTilesRect( void PictureLayerTiling::VerifyLiveTilesRect(bool is_on_recycle_tree) const { #if DCHECK_IS_ON() for (auto it = tiles_.begin(); it != tiles_.end(); ++it) { - if (!it->second.get()) + if (!it->second) continue; DCHECK(it->first.first < tiling_data_.num_tiles_x()) << this << " " << it->first.first << "," << it->first.second @@ -861,7 +862,7 @@ TilePriority PictureLayerTiling::ComputePriorityForTile( void PictureLayerTiling::GetAllTilesAndPrioritiesForTracing( std::map<const Tile*, TilePriority>* tile_map) const { for (const auto& tile_pair : tiles_) { - const Tile* tile = tile_pair.second.get(); + const Tile* tile = tile_pair.second; const TilePriority& priority = ComputePriorityForTile(tile); // Store combined priority. (*tile_map)[tile] = priority; @@ -883,7 +884,7 @@ void PictureLayerTiling::AsValueInto( size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { size_t amount = 0; for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { - const Tile* tile = it->second.get(); + const Tile* tile = it->second; amount += tile->GPUMemoryUsageInBytes(); } return amount; diff --git a/cc/resources/picture_layer_tiling.h b/cc/resources/picture_layer_tiling.h index edd1399..f63dc67 100644 --- a/cc/resources/picture_layer_tiling.h +++ b/cc/resources/picture_layer_tiling.h @@ -10,7 +10,7 @@ #include <vector> #include "base/basictypes.h" -#include "base/containers/hash_tables.h" +#include "base/containers/scoped_ptr_hash_map.h" #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" #include "cc/base/region.h" @@ -35,8 +35,8 @@ class CC_EXPORT PictureLayerTilingClient { public: // Create a tile at the given content_rect (in the contents scale of the // tiling) This might return null if the client cannot create such a tile. - virtual scoped_refptr<Tile> CreateTile(float contents_scale, - const gfx::Rect& content_rect) = 0; + virtual ScopedTilePtr CreateTile(float contents_scale, + const gfx::Rect& content_rect) = 0; virtual gfx::Size CalculateTileSize( const gfx::Size& content_bounds) const = 0; // This invalidation region defines the area (if any, it can by null) that @@ -97,7 +97,7 @@ class CC_EXPORT PictureLayerTiling { Tile* TileAt(int i, int j) const { TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); - return iter == tiles_.end() ? nullptr : iter->second.get(); + return iter == tiles_.end() ? nullptr : iter->second; } bool has_tiles() const { return !tiles_.empty(); } @@ -110,18 +110,12 @@ class CC_EXPORT PictureLayerTiling { std::vector<Tile*> AllTilesForTesting() const { std::vector<Tile*> all_tiles; for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) - all_tiles.push_back(it->second.get()); + all_tiles.push_back(it->second); return all_tiles; } void UpdateAllTilePrioritiesForTesting() { for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) - UpdateTilePriority(it->second.get()); - } - std::vector<scoped_refptr<Tile>> AllRefTilesForTesting() const { - std::vector<scoped_refptr<Tile>> all_tiles; - for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) - all_tiles.push_back(it->second); - return all_tiles; + UpdateTilePriority(it->second); } void SetAllTilesOccludedForTesting() { gfx::Rect viewport_in_layer_space = @@ -215,8 +209,8 @@ class CC_EXPORT PictureLayerTiling { friend class TilingSetRasterQueueRequired; friend class TilingSetEvictionQueue; - typedef std::pair<int, int> TileMapKey; - typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; + using TileMapKey = std::pair<int, int>; + using TileMap = base::ScopedPtrHashMap<TileMapKey, ScopedTilePtr>; struct FrameVisibleRect { gfx::Rect visible_rect_in_content_space; diff --git a/cc/resources/picture_layer_tiling_unittest.cc b/cc/resources/picture_layer_tiling_unittest.cc index 944b5e0..d8b61ab 100644 --- a/cc/resources/picture_layer_tiling_unittest.cc +++ b/cc/resources/picture_layer_tiling_unittest.cc @@ -1951,7 +1951,7 @@ TEST_F(PictureLayerTilingIteratorTest, ResizeTilesAndUpdateToCurrent) { tiling_->CreateAllTilesForTesting(); EXPECT_EQ(150, tiling_->TilingDataForTesting().max_texture_size().width()); EXPECT_EQ(100, tiling_->TilingDataForTesting().max_texture_size().height()); - EXPECT_EQ(4u, tiling_->AllRefTilesForTesting().size()); + EXPECT_EQ(4u, tiling_->AllTilesForTesting().size()); client_.SetTileSize(gfx::Size(250, 200)); @@ -1968,7 +1968,7 @@ TEST_F(PictureLayerTilingIteratorTest, ResizeTilesAndUpdateToCurrent) { // Tile size in the tiling should be resized to 250x200. EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); - EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); + EXPECT_EQ(0u, tiling_->AllTilesForTesting().size()); } } // namespace diff --git a/cc/resources/tile.cc b/cc/resources/tile.cc index 7467d93..94e42ec 100644 --- a/cc/resources/tile.cc +++ b/cc/resources/tile.cc @@ -23,7 +23,7 @@ Tile::Tile(TileManager* tile_manager, int layer_id, int source_frame_number, int flags) - : RefCountedManaged<Tile>(tile_manager), + : tile_manager_(tile_manager), desired_texture_size_(desired_texture_size), content_rect_(content_rect), contents_scale_(contents_scale), @@ -91,4 +91,9 @@ size_t Tile::GPUMemoryUsageInBytes() const { return 0; } +void Tile::Deleter::operator()(Tile* tile) const { + TileManager* tile_manager = tile->tile_manager_; + tile_manager->Release(tile); +} + } // namespace cc diff --git a/cc/resources/tile.h b/cc/resources/tile.h index 45c2b04..e9ba91c 100644 --- a/cc/resources/tile.h +++ b/cc/resources/tile.h @@ -6,7 +6,6 @@ #define CC_RESOURCES_TILE_H_ #include "base/memory/ref_counted.h" -#include "cc/base/ref_counted_managed.h" #include "cc/resources/raster_source.h" #include "cc/resources/tile_draw_info.h" #include "cc/resources/tile_priority.h" @@ -17,8 +16,13 @@ namespace cc { class TileManager; -class CC_EXPORT Tile : public RefCountedManaged<Tile> { +class CC_EXPORT Tile { public: + class Deleter { + public: + void operator()(Tile* tile) const; + }; + enum TileRasterFlags { USE_PICTURE_ANALYSIS = 1 << 0 }; typedef uint64 Id; @@ -96,9 +100,7 @@ class CC_EXPORT Tile : public RefCountedManaged<Tile> { private: friend class TileManager; - friend class PrioritizedTileSet; friend class FakeTileManager; - friend class BinComparator; friend class FakePictureLayerImpl; // Methods called by by tile manager. @@ -114,6 +116,7 @@ class CC_EXPORT Tile : public RefCountedManaged<Tile> { bool HasRasterTask() const { return !!raster_task_.get(); } + TileManager* tile_manager_; scoped_refptr<RasterSource> raster_source_; gfx::Size desired_texture_size_; gfx::Rect content_rect_; @@ -141,6 +144,8 @@ class CC_EXPORT Tile : public RefCountedManaged<Tile> { DISALLOW_COPY_AND_ASSIGN(Tile); }; +using ScopedTilePtr = scoped_ptr<Tile, Tile::Deleter>; + } // namespace cc #endif // CC_RESOURCES_TILE_H_ diff --git a/cc/resources/tile_manager.cc b/cc/resources/tile_manager.cc index 53068c6..0f3059f 100644 --- a/cc/resources/tile_manager.cc +++ b/cc/resources/tile_manager.cc @@ -763,17 +763,16 @@ void TileManager::UpdateTileDrawInfo( client_->NotifyTileStateChanged(tile); } -scoped_refptr<Tile> TileManager::CreateTile( - RasterSource* raster_source, - const gfx::Size& desired_texture_size, - const gfx::Rect& content_rect, - float contents_scale, - int layer_id, - int source_frame_number, - int flags) { - scoped_refptr<Tile> tile = make_scoped_refptr( - new Tile(this, raster_source, desired_texture_size, content_rect, - contents_scale, layer_id, source_frame_number, flags)); +ScopedTilePtr TileManager::CreateTile(RasterSource* raster_source, + const gfx::Size& desired_texture_size, + const gfx::Rect& content_rect, + float contents_scale, + int layer_id, + int source_frame_number, + int flags) { + ScopedTilePtr tile(new Tile(this, raster_source, desired_texture_size, + content_rect, contents_scale, layer_id, + source_frame_number, flags)); DCHECK(tiles_.find(tile->id()) == tiles_.end()); tiles_[tile->id()] = tile.get(); diff --git a/cc/resources/tile_manager.h b/cc/resources/tile_manager.h index 087778a..b27fa86 100644 --- a/cc/resources/tile_manager.h +++ b/cc/resources/tile_manager.h @@ -14,7 +14,6 @@ #include "base/containers/hash_tables.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" -#include "cc/base/ref_counted_managed.h" #include "cc/base/unique_notifier.h" #include "cc/resources/eviction_tile_priority_queue.h" #include "cc/resources/memory_history.h" @@ -86,8 +85,7 @@ RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); // should no longer have any memory assigned to them. Tile objects are "owned" // by layers; they automatically register with the manager when they are // created, and unregister from the manager when they are deleted. -class CC_EXPORT TileManager : public TileTaskRunnerClient, - public RefCountedManager<Tile> { +class CC_EXPORT TileManager : public TileTaskRunnerClient { public: enum NamedTaskSet { REQUIRED_FOR_ACTIVATION, @@ -118,13 +116,13 @@ class CC_EXPORT TileManager : public TileTaskRunnerClient, void UpdateVisibleTiles(const GlobalStateThatImpactsTilePriority& state); - scoped_refptr<Tile> CreateTile(RasterSource* raster_source, - const gfx::Size& desired_texture_size, - const gfx::Rect& content_rect, - float contents_scale, - int layer_id, - int source_frame_number, - int flags); + ScopedTilePtr CreateTile(RasterSource* raster_source, + const gfx::Size& desired_texture_size, + const gfx::Rect& content_rect, + float contents_scale, + int layer_id, + int source_frame_number, + int flags); bool IsReadyToActivate() const; bool IsReadyToDraw() const; @@ -192,9 +190,9 @@ class CC_EXPORT TileManager : public TileTaskRunnerClient, void FreeResourcesForReleasedTiles(); void CleanUpReleasedTiles(); - // Overriden from RefCountedManager<Tile>: friend class Tile; - void Release(Tile* tile) override; + // Virtual for testing. + virtual void Release(Tile* tile); // Overriden from TileTaskRunnerClient: void DidFinishRunningTileTasks(TaskSet task_set) override; diff --git a/cc/test/fake_picture_layer_tiling_client.cc b/cc/test/fake_picture_layer_tiling_client.cc index 0717a98..ae6d593 100644 --- a/cc/test/fake_picture_layer_tiling_client.cc +++ b/cc/test/fake_picture_layer_tiling_client.cc @@ -33,9 +33,8 @@ FakePictureLayerTilingClient::FakePictureLayerTilingClient( FakePictureLayerTilingClient::~FakePictureLayerTilingClient() { } -scoped_refptr<Tile> FakePictureLayerTilingClient::CreateTile( - float content_scale, - const gfx::Rect& rect) { +ScopedTilePtr FakePictureLayerTilingClient::CreateTile(float content_scale, + const gfx::Rect& rect) { return tile_manager_->CreateTile(pile_.get(), tile_size_, rect, 1, 0, 0, 0); } diff --git a/cc/test/fake_picture_layer_tiling_client.h b/cc/test/fake_picture_layer_tiling_client.h index 76636ba..94a600e 100644 --- a/cc/test/fake_picture_layer_tiling_client.h +++ b/cc/test/fake_picture_layer_tiling_client.h @@ -21,8 +21,8 @@ class FakePictureLayerTilingClient : public PictureLayerTilingClient { ~FakePictureLayerTilingClient() override; // PictureLayerTilingClient implementation. - scoped_refptr<Tile> CreateTile(float contents_scale, - const gfx::Rect& rect) override; + ScopedTilePtr CreateTile(float contents_scale, + const gfx::Rect& rect) override; gfx::Size CalculateTileSize(const gfx::Size& content_bounds) const override; TilePriority::PriorityBin GetMaxTilePriorityBin() const override; |