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 SkCanvas
* AcquireCanvasForRaster(RasterTask
* task
) OVERRIDE
{
54 virtual void ReleaseCanvasForRaster(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();
85 SetGlobalStateForTesting(state
);
86 AssignGpuMemoryToTiles(&tiles_for_raster
);
89 bool FakeTileManager::HasBeenAssignedMemory(Tile
* tile
) {
90 return std::find(tiles_for_raster
.begin(),
91 tiles_for_raster
.end(),
92 tile
) != tiles_for_raster
.end();
95 void FakeTileManager::DidFinishRunningTasksForTesting() {
96 DidFinishRunningTasks();
99 void FakeTileManager::Release(Tile
* tile
) {
100 TileManager::Release(tile
);
101 CleanUpReleasedTiles();