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
9 #include "base/lazy_instance.h"
10 #include "cc/resources/raster_buffer.h"
11 #include "cc/resources/rasterizer.h"
12
13 namespace cc {
14
15 namespace {
16
17 class FakeRasterizerImpl : public Rasterizer, public RasterizerTaskClient {
18 public:
19 // Overridden from Rasterizer:
SetClient(RasterizerClient * client)20 virtual void SetClient(RasterizerClient* client) OVERRIDE {}
Shutdown()21 virtual void Shutdown() OVERRIDE {}
ScheduleTasks(RasterTaskQueue * queue)22 virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE {
23 for (RasterTaskQueue::Item::Vector::const_iterator it =
24 queue->items.begin();
25 it != queue->items.end();
26 ++it) {
27 RasterTask* task = it->task;
28
29 task->WillSchedule();
30 task->ScheduleOnOriginThread(this);
31 task->DidSchedule();
32
33 completed_tasks_.push_back(task);
34 }
35 }
CheckForCompletedTasks()36 virtual void CheckForCompletedTasks() OVERRIDE {
37 for (RasterTask::Vector::iterator it = completed_tasks_.begin();
38 it != completed_tasks_.end();
39 ++it) {
40 RasterTask* task = it->get();
41
42 task->WillComplete();
43 task->CompleteOnOriginThread(this);
44 task->DidComplete();
45
46 task->RunReplyOnOriginThread();
47 }
48 completed_tasks_.clear();
49 }
50
51 // Overridden from RasterizerTaskClient:
AcquireBufferForRaster(const Resource * resource)52 virtual scoped_ptr<RasterBuffer> AcquireBufferForRaster(
53 const Resource* resource) OVERRIDE {
54 return scoped_ptr<RasterBuffer>();
55 }
ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer)56 virtual void ReleaseBufferForRaster(
57 scoped_ptr<RasterBuffer> buffer) OVERRIDE {}
58
59 private:
60 RasterTask::Vector completed_tasks_;
61 };
62 base::LazyInstance<FakeRasterizerImpl> g_fake_rasterizer =
63 LAZY_INSTANCE_INITIALIZER;
64
65 } // namespace
66
FakeTileManager(TileManagerClient * client)67 FakeTileManager::FakeTileManager(TileManagerClient* client)
68 : TileManager(client,
69 base::MessageLoopProxy::current(),
70 NULL,
71 g_fake_rasterizer.Pointer(),
72 NULL) {}
73
FakeTileManager(TileManagerClient * client,ResourcePool * resource_pool)74 FakeTileManager::FakeTileManager(TileManagerClient* client,
75 ResourcePool* resource_pool)
76 : TileManager(client,
77 base::MessageLoopProxy::current(),
78 resource_pool,
79 g_fake_rasterizer.Pointer(),
80 NULL) {}
81
~FakeTileManager()82 FakeTileManager::~FakeTileManager() {}
83
AssignMemoryToTiles(const GlobalStateThatImpactsTilePriority & state)84 void FakeTileManager::AssignMemoryToTiles(
85 const GlobalStateThatImpactsTilePriority& state) {
86 tiles_for_raster.clear();
87 all_tiles.Clear();
88
89 SetGlobalStateForTesting(state);
90 GetTilesWithAssignedBins(&all_tiles);
91 AssignGpuMemoryToTiles(&all_tiles, &tiles_for_raster);
92 }
93
HasBeenAssignedMemory(Tile * tile)94 bool FakeTileManager::HasBeenAssignedMemory(Tile* tile) {
95 return std::find(tiles_for_raster.begin(),
96 tiles_for_raster.end(),
97 tile) != tiles_for_raster.end();
98 }
99
Release(Tile * tile)100 void FakeTileManager::Release(Tile* tile) {
101 TileManager::Release(tile);
102
103 FreeResourcesForReleasedTiles();
104 CleanUpReleasedTiles();
105 }
106
107 } // namespace cc
108