1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// 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 "cc/test/fake_tile_manager.h"
#include <deque>
#include <limits>
#include "cc/resources/raster_worker_pool.h"
namespace cc {
namespace {
class FakeTaskGraphRunner : public internal::TaskGraphRunner {
public:
FakeTaskGraphRunner() : internal::TaskGraphRunner(0, "CompositorRaster") {}
};
base::LazyInstance<FakeTaskGraphRunner> g_task_graph_runner =
LAZY_INSTANCE_INITIALIZER;
class FakeRasterWorkerPool : public RasterWorkerPool {
public:
FakeRasterWorkerPool()
: RasterWorkerPool(g_task_graph_runner.Pointer(), NULL, NULL) {}
// Overridden from RasterWorkerPool:
virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE {
RasterWorkerPool::SetRasterTasks(queue);
for (RasterTaskVector::const_iterator it = raster_tasks().begin();
it != raster_tasks().end(); ++it) {
internal::WorkerPoolTask* task = it->get();
task->DidSchedule();
completed_tasks_.push_back(it->get());
}
}
virtual void CheckForCompletedTasks() OVERRIDE {
internal::Task::Vector completed_tasks;
CollectCompletedWorkerPoolTasks(&completed_tasks);
while (!completed_tasks_.empty()) {
internal::WorkerPoolTask* task = completed_tasks_.front().get();
task->WillComplete();
task->DidComplete();
task->RunReplyOnOriginThread();
completed_tasks_.pop_front();
}
}
virtual GLenum GetResourceTarget() const OVERRIDE {
return GL_TEXTURE_2D;
}
virtual ResourceFormat GetResourceFormat() const OVERRIDE {
return RGBA_8888;
}
// Overridden from internal::WorkerPoolTaskClient:
virtual void* AcquireBufferForRaster(internal::RasterWorkerPoolTask* task,
int* stride) OVERRIDE {
return NULL;
}
virtual void OnRasterCompleted(internal::RasterWorkerPoolTask* task,
const PicturePileImpl::Analysis& analysis)
OVERRIDE {}
virtual void OnImageDecodeCompleted(internal::WorkerPoolTask* task) OVERRIDE {
}
private:
// Overridden from RasterWorkerPool:
virtual void OnRasterTasksFinished() OVERRIDE {}
virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE {}
TaskDeque completed_tasks_;
};
} // namespace
FakeTileManager::FakeTileManager(TileManagerClient* client)
: TileManager(client,
NULL,
make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
std::numeric_limits<unsigned>::max(),
NULL,
true) {}
FakeTileManager::FakeTileManager(TileManagerClient* client,
ResourceProvider* resource_provider)
: TileManager(client,
resource_provider,
make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
std::numeric_limits<unsigned>::max(),
NULL,
true) {}
FakeTileManager::FakeTileManager(TileManagerClient* client,
ResourceProvider* resource_provider,
bool allow_on_demand_raster)
: TileManager(client,
resource_provider,
make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
std::numeric_limits<unsigned>::max(),
NULL,
allow_on_demand_raster) {}
FakeTileManager::FakeTileManager(TileManagerClient* client,
ResourceProvider* resource_provider,
size_t raster_task_limit_bytes)
: TileManager(client,
resource_provider,
make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
raster_task_limit_bytes,
NULL,
true) {}
FakeTileManager::~FakeTileManager() {}
void FakeTileManager::AssignMemoryToTiles(
const GlobalStateThatImpactsTilePriority& state) {
tiles_for_raster.clear();
all_tiles.Clear();
SetGlobalStateForTesting(state);
GetTilesWithAssignedBins(&all_tiles);
AssignGpuMemoryToTiles(&all_tiles, &tiles_for_raster);
}
bool FakeTileManager::HasBeenAssignedMemory(Tile* tile) {
return std::find(tiles_for_raster.begin(),
tiles_for_raster.end(),
tile) != tiles_for_raster.end();
}
void FakeTileManager::CheckForCompletedTasks() {
RasterWorkerPoolForTesting()->CheckForCompletedTasks();
}
void FakeTileManager::DidFinishRunningTasksForTesting() {
DidFinishRunningTasks();
}
void FakeTileManager::Release(Tile* tile) {
TileManager::Release(tile);
CleanUpReleasedTiles();
}
} // namespace cc
|