Revert of Create a new AccountTrackerService (patchset #8 of https://codereview.chrom...
[chromium-blink-merge.git] / cc / test / fake_tile_manager.cc
blobd15819d737712612e8e29a874eb363f31800c9b1
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.
5 #include "cc/test/fake_tile_manager.h"
7 #include <deque>
9 #include "base/lazy_instance.h"
10 #include "cc/resources/rasterizer.h"
12 namespace cc {
14 namespace {
16 class FakeRasterizerImpl : public Rasterizer, public RasterizerTaskClient {
17 public:
18 // Overridden from Rasterizer:
19 virtual void SetClient(RasterizerClient* client) OVERRIDE {}
20 virtual void Shutdown() OVERRIDE {}
21 virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE {
22 for (RasterTaskQueue::Item::Vector::const_iterator it =
23 queue->items.begin();
24 it != queue->items.end();
25 ++it) {
26 RasterTask* task = it->task;
28 task->WillSchedule();
29 task->ScheduleOnOriginThread(this);
30 task->DidSchedule();
32 completed_tasks_.push_back(task);
35 virtual void CheckForCompletedTasks() OVERRIDE {
36 for (RasterTask::Vector::iterator it = completed_tasks_.begin();
37 it != completed_tasks_.end();
38 ++it) {
39 RasterTask* task = it->get();
41 task->WillComplete();
42 task->CompleteOnOriginThread(this);
43 task->DidComplete();
45 task->RunReplyOnOriginThread();
47 completed_tasks_.clear();
50 // Overridden from RasterizerTaskClient:
51 virtual SkCanvas* AcquireCanvasForRaster(RasterTask* task) OVERRIDE {
52 return NULL;
54 virtual void ReleaseCanvasForRaster(RasterTask* task) OVERRIDE {}
56 private:
57 RasterTask::Vector completed_tasks_;
59 base::LazyInstance<FakeRasterizerImpl> g_fake_rasterizer =
60 LAZY_INSTANCE_INITIALIZER;
62 } // namespace
64 FakeTileManager::FakeTileManager(TileManagerClient* client)
65 : TileManager(client,
66 base::MessageLoopProxy::current(),
67 NULL,
68 g_fake_rasterizer.Pointer(),
69 NULL) {}
71 FakeTileManager::FakeTileManager(TileManagerClient* client,
72 ResourcePool* resource_pool)
73 : TileManager(client,
74 base::MessageLoopProxy::current(),
75 resource_pool,
76 g_fake_rasterizer.Pointer(),
77 NULL) {}
79 FakeTileManager::~FakeTileManager() {}
81 void FakeTileManager::AssignMemoryToTiles(
82 const GlobalStateThatImpactsTilePriority& state) {
83 tiles_for_raster.clear();
84 all_tiles.Clear();
86 SetGlobalStateForTesting(state);
87 GetTilesWithAssignedBins(&all_tiles);
88 AssignGpuMemoryToTiles(&all_tiles, &tiles_for_raster);
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();
97 void FakeTileManager::DidFinishRunningTasksForTesting() {
98 DidFinishRunningTasks();
101 void FakeTileManager::Release(Tile* tile) {
102 TileManager::Release(tile);
104 FreeResourcesForReleasedTiles();
105 CleanUpReleasedTiles();
108 } // namespace cc