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"
9 #include "base/lazy_instance.h"
10 #include "cc/resources/rasterizer.h"
16 class FakeRasterizerImpl
: public Rasterizer
, public RasterizerTaskClient
{
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
=
24 it
!= queue
->items
.end();
26 RasterTask
* task
= it
->task
;
29 task
->ScheduleOnOriginThread(this);
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();
39 RasterTask
* task
= it
->get();
42 task
->CompleteOnOriginThread(this);
45 task
->RunReplyOnOriginThread();
47 completed_tasks_
.clear();
50 // Overridden from RasterizerTaskClient:
51 virtual RasterBuffer
* AcquireBufferForRaster(RasterTask
* task
) OVERRIDE
{
54 virtual void ReleaseBufferForRaster(RasterTask
* task
) OVERRIDE
{}
57 RasterTask::Vector completed_tasks_
;
59 base::LazyInstance
<FakeRasterizerImpl
> g_fake_rasterizer
=
60 LAZY_INSTANCE_INITIALIZER
;
64 FakeTileManager::FakeTileManager(TileManagerClient
* client
)
66 base::MessageLoopProxy::current(),
68 g_fake_rasterizer
.Pointer(),
71 FakeTileManager::FakeTileManager(TileManagerClient
* client
,
72 ResourcePool
* resource_pool
)
74 base::MessageLoopProxy::current(),
76 g_fake_rasterizer
.Pointer(),
79 FakeTileManager::~FakeTileManager() {}
81 void FakeTileManager::AssignMemoryToTiles(
82 const GlobalStateThatImpactsTilePriority
& state
) {
83 tiles_for_raster
.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();