#ifndef CC_RESOURCES_TILE_MANAGER_H_
#define CC_RESOURCES_TILE_MANAGER_H_
+#include <deque>
#include <queue>
#include <set>
+#include <utility>
#include <vector>
#include "base/containers/hash_tables.h"
#include "base/values.h"
#include "cc/base/ref_counted_managed.h"
#include "cc/debug/rendering_stats_instrumentation.h"
+#include "cc/layers/picture_layer_impl.h"
#include "cc/resources/managed_tile_state.h"
#include "cc/resources/memory_history.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/prioritized_tile_set.h"
-#include "cc/resources/raster_worker_pool.h"
+#include "cc/resources/rasterizer.h"
#include "cc/resources/resource_pool.h"
#include "cc/resources/tile.h"
namespace cc {
-class PictureLayerImpl;
-class RasterWorkerPoolDelegate;
+class RasterizerDelegate;
class ResourceProvider;
class CC_EXPORT TileManagerClient {
public:
virtual void NotifyReadyToActivate() = 0;
+ virtual void NotifyTileInitialized(const Tile* tile) = 0;
protected:
virtual ~TileManagerClient() {}
// 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 RasterWorkerPoolClient,
+class CC_EXPORT TileManager : public RasterizerClient,
public RefCountedManager<Tile> {
public:
struct CC_EXPORT PairedPictureLayer {
PictureLayerImpl* pending_layer;
};
+ class CC_EXPORT RasterTileIterator {
+ public:
+ RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority);
+ ~RasterTileIterator();
+
+ RasterTileIterator& operator++();
+ operator bool() const;
+ Tile* operator*();
+
+ private:
+ struct PairedPictureLayerIterator {
+ PairedPictureLayerIterator();
+ ~PairedPictureLayerIterator();
+
+ Tile* PeekTile(TreePriority tree_priority);
+ void PopTile(TreePriority tree_priority);
+
+ std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree>
+ NextTileIterator(TreePriority tree_priority);
+
+ PictureLayerImpl::LayerRasterTileIterator active_iterator;
+ PictureLayerImpl::LayerRasterTileIterator pending_iterator;
+
+ std::vector<Tile*> returned_shared_tiles;
+ };
+
+ class RasterOrderComparator {
+ public:
+ explicit RasterOrderComparator(TreePriority tree_priority);
+
+ bool operator()(PairedPictureLayerIterator* a,
+ PairedPictureLayerIterator* b) const;
+
+ private:
+ TreePriority tree_priority_;
+ };
+
+ std::vector<PairedPictureLayerIterator> paired_iterators_;
+ std::vector<PairedPictureLayerIterator*> iterator_heap_;
+ TreePriority tree_priority_;
+ RasterOrderComparator comparator_;
+
+ DISALLOW_COPY_AND_ASSIGN(RasterTileIterator);
+ };
+
+ struct CC_EXPORT EvictionTileIterator {
+ public:
+ EvictionTileIterator();
+ EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority);
+ ~EvictionTileIterator();
+
+ EvictionTileIterator& operator++();
+ operator bool() const;
+ Tile* operator*();
+
+ private:
+ struct PairedPictureLayerIterator {
+ PairedPictureLayerIterator();
+ ~PairedPictureLayerIterator();
+
+ Tile* PeekTile(TreePriority tree_priority);
+ void PopTile(TreePriority tree_priority);
+
+ PictureLayerImpl::LayerEvictionTileIterator* NextTileIterator(
+ TreePriority tree_priority);
+
+ PictureLayerImpl::LayerEvictionTileIterator active_iterator;
+ PictureLayerImpl::LayerEvictionTileIterator pending_iterator;
+
+ std::vector<Tile*> returned_shared_tiles;
+ };
+
+ class EvictionOrderComparator {
+ public:
+ explicit EvictionOrderComparator(TreePriority tree_priority);
+
+ bool operator()(PairedPictureLayerIterator* a,
+ PairedPictureLayerIterator* b) const;
+
+ private:
+ TreePriority tree_priority_;
+ };
+
+ std::vector<PairedPictureLayerIterator> paired_iterators_;
+ std::vector<PairedPictureLayerIterator*> iterator_heap_;
+ TreePriority tree_priority_;
+ EvictionOrderComparator comparator_;
+
+ DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator);
+ };
+
static scoped_ptr<TileManager> Create(
TileManagerClient* client,
- base::SequencedTaskRunner* task_runner,
- ResourceProvider* resource_provider,
- ContextProvider* context_provider,
- RenderingStatsInstrumentation* rendering_stats_instrumentation,
- bool use_map_image,
+ ResourcePool* resource_pool,
+ Rasterizer* rasterizer,
+ Rasterizer* gpu_rasterizer,
bool use_rasterize_on_demand,
- size_t max_transfer_buffer_usage_bytes,
- size_t max_raster_usage_bytes,
- unsigned map_image_texture_target);
+ RenderingStatsInstrumentation* rendering_stats_instrumentation);
virtual ~TileManager();
void ManageTiles(const GlobalStateThatImpactsTilePriority& state);
void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const;
- ResourcePool* resource_pool() { return resource_pool_.get(); }
-
- void InitializeTilesWithResourcesForTesting(
- const std::vector<Tile*>& tiles,
- ResourceProvider* resource_provider) {
+ void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) {
for (size_t i = 0; i < tiles.size(); ++i) {
ManagedTileState& mts = tiles[i]->managed_state();
ManagedTileState::TileVersion& tile_version =
}
}
+ void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) {
+ for (size_t i = 0; i < tiles.size(); ++i) {
+ Tile* tile = tiles[i];
+ for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
+ FreeResourceForTile(tile, static_cast<RasterMode>(mode));
+ }
+ }
+ }
+
void SetGlobalStateForTesting(
const GlobalStateThatImpactsTilePriority& state) {
// Soft limit is used for resource pool such that
if (state != global_state_) {
global_state_ = state;
prioritized_tiles_dirty_ = true;
- resource_pool_->SetResourceUsageLimits(
- global_state_.soft_memory_limit_in_bytes,
- global_state_.unused_memory_limit_in_bytes,
- global_state_.num_resources_limit);
}
}
protected:
TileManager(TileManagerClient* client,
- base::SequencedTaskRunner* task_runner,
- ResourceProvider* resource_provider,
- ContextProvider* context_provider,
- scoped_ptr<RasterWorkerPool> raster_worker_pool,
- scoped_ptr<RasterWorkerPool> direct_raster_worker_pool,
- size_t max_raster_usage_bytes,
- RenderingStatsInstrumentation* rendering_stats_instrumentation,
- bool use_rasterize_on_demand);
+ ResourcePool* resource_pool,
+ Rasterizer* rasterizer,
+ Rasterizer* gpu_rasterizer,
+ bool use_rasterize_on_demand,
+ RenderingStatsInstrumentation* rendering_stats_instrumentation);
// Methods called by Tile
friend class Tile;
// Overriden from RefCountedManager<Tile>:
virtual void Release(Tile* tile) OVERRIDE;
- // Overriden from RasterWorkerPoolClient:
+ // Overriden from RasterizerClient:
virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE;
virtual void DidFinishRunningTasks() OVERRIDE;
virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE;
void GetTilesWithAssignedBins(PrioritizedTileSet* tiles);
private:
- enum RasterWorkerPoolType {
- RASTER_WORKER_POOL_TYPE_DEFAULT,
- RASTER_WORKER_POOL_TYPE_DIRECT,
- NUM_RASTER_WORKER_POOL_TYPES
+ enum RasterizerType {
+ RASTERIZER_TYPE_DEFAULT,
+ RASTERIZER_TYPE_GPU,
+ NUM_RASTERIZER_TYPES
};
void OnImageDecodeTaskCompleted(int layer_id,
inline size_t BytesConsumedIfAllocated(const Tile* tile) const {
return Resource::MemorySizeBytes(tile->size(),
- raster_worker_pool_->GetResourceFormat());
+ resource_pool_->resource_format());
}
void FreeResourceForTile(Tile* tile, RasterMode mode);
void FreeResourcesForTile(Tile* tile);
void FreeUnusedResourcesForTile(Tile* tile);
- scoped_refptr<internal::WorkerPoolTask> CreateImageDecodeTask(
- Tile* tile,
- SkPixelRef* pixel_ref);
- scoped_refptr<internal::RasterWorkerPoolTask> CreateRasterTask(Tile* tile);
+ scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile,
+ SkPixelRef* pixel_ref);
+ scoped_refptr<RasterTask> CreateRasterTask(Tile* tile);
scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const;
void UpdatePrioritizedTileSetIfNeeded();
TileManagerClient* client_;
- ContextProvider* context_provider_;
- scoped_ptr<ResourcePool> resource_pool_;
- scoped_ptr<RasterWorkerPool> raster_worker_pool_;
- scoped_ptr<RasterWorkerPool> direct_raster_worker_pool_;
- scoped_ptr<RasterWorkerPoolDelegate> raster_worker_pool_delegate_;
+ ResourcePool* resource_pool_;
+ scoped_ptr<RasterizerDelegate> rasterizer_delegate_;
GlobalStateThatImpactsTilePriority global_state_;
typedef base::hash_map<Tile::Id, Tile*> TileMap;
size_t bytes_releasable_;
size_t resources_releasable_;
- size_t max_raster_usage_bytes_;
bool ever_exceeded_memory_budget_;
MemoryHistory::Entry memory_stats_from_last_assign_;
bool did_initialize_visible_tile_;
bool did_check_for_completed_tasks_since_last_schedule_tasks_;
- typedef base::hash_map<uint32_t, scoped_refptr<internal::WorkerPoolTask> >
+ typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> >
PixelRefTaskMap;
typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap;
LayerPixelRefTaskMap image_decode_tasks_;
bool use_rasterize_on_demand_;
+ ResourceFormat resource_format_;
+
// Queues used when scheduling raster tasks.
- RasterTaskQueue raster_queue_[NUM_RASTER_WORKER_POOL_TYPES];
+ RasterTaskQueue raster_queue_[NUM_RASTERIZER_TYPES];
- std::vector<scoped_refptr<internal::Task> > orphan_raster_tasks_;
+ std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_;
std::vector<PictureLayerImpl*> layers_;