1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/test/fake_tile_manager.h"
6
7 #include <deque>
8 #include <limits>
9
10 #include "cc/resources/raster_worker_pool.h"
11
12 namespace cc {
13
14 namespace {
15
16 class FakeRasterWorkerPool : public RasterWorkerPool {
17 public:
FakeRasterWorkerPool()18 FakeRasterWorkerPool() : RasterWorkerPool(NULL, 1) {}
19
ScheduleTasks(RasterTask::Queue * queue)20 virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE {
21 RasterWorkerPool::SetRasterTasks(queue);
22 for (RasterTaskVector::const_iterator it = raster_tasks().begin();
23 it != raster_tasks().end(); ++it) {
24 completed_tasks_.push_back(it->get());
25 }
26 }
CheckForCompletedTasks()27 virtual void CheckForCompletedTasks() OVERRIDE {
28 while (!completed_tasks_.empty()) {
29 internal::RasterWorkerPoolTask* task = completed_tasks_.front().get();
30 task->WillComplete();
31 task->CompleteOnOriginThread();
32 task->DidComplete();
33 completed_tasks_.pop_front();
34 }
35 }
GetResourceTarget() const36 virtual GLenum GetResourceTarget() const OVERRIDE {
37 return GL_TEXTURE_2D;
38 }
GetResourceFormat() const39 virtual ResourceFormat GetResourceFormat() const OVERRIDE {
40 return RGBA_8888;
41 }
OnRasterTasksFinished()42 virtual void OnRasterTasksFinished() OVERRIDE {}
OnRasterTasksRequiredForActivationFinished()43 virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE {}
44
45 private:
46 typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > TaskDeque;
47 TaskDeque completed_tasks_;
48 };
49
50 } // namespace
51
FakeTileManager(TileManagerClient * client)52 FakeTileManager::FakeTileManager(TileManagerClient* client)
53 : TileManager(client,
54 NULL,
55 make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
56 1,
57 std::numeric_limits<unsigned>::max(),
58 NULL) {}
59
FakeTileManager(TileManagerClient * client,ResourceProvider * resource_provider)60 FakeTileManager::FakeTileManager(TileManagerClient* client,
61 ResourceProvider* resource_provider)
62 : TileManager(client,
63 resource_provider,
64 make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
65 1,
66 std::numeric_limits<unsigned>::max(),
67 NULL) {}
68
FakeTileManager(TileManagerClient * client,ResourceProvider * resource_provider,size_t raster_task_limit_bytes)69 FakeTileManager::FakeTileManager(TileManagerClient* client,
70 ResourceProvider* resource_provider,
71 size_t raster_task_limit_bytes)
72 : TileManager(client,
73 resource_provider,
74 make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
75 1,
76 raster_task_limit_bytes,
77 NULL) {}
78
~FakeTileManager()79 FakeTileManager::~FakeTileManager() {}
80
AssignMemoryToTiles(const GlobalStateThatImpactsTilePriority & state)81 void FakeTileManager::AssignMemoryToTiles(
82 const GlobalStateThatImpactsTilePriority& state) {
83 tiles_for_raster.clear();
84 all_tiles.Clear();
85
86 SetGlobalStateForTesting(state);
87 GetTilesWithAssignedBins(&all_tiles);
88 AssignGpuMemoryToTiles(&all_tiles, &tiles_for_raster);
89 }
90
HasBeenAssignedMemory(Tile * tile)91 bool FakeTileManager::HasBeenAssignedMemory(Tile* tile) {
92 return std::find(tiles_for_raster.begin(),
93 tiles_for_raster.end(),
94 tile) != tiles_for_raster.end();
95 }
96
CheckForCompletedTasks()97 void FakeTileManager::CheckForCompletedTasks() {
98 RasterWorkerPoolForTesting()->CheckForCompletedTasks();
99 }
100
Release(Tile * tile)101 void FakeTileManager::Release(Tile* tile) {
102 TileManager::Release(tile);
103 CleanUpReleasedTiles();
104 }
105
106 } // namespace cc
107