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"
10 #include "base/lazy_instance.h"
11 #include "cc/resources/raster_buffer.h"
12 #include "cc/resources/tile_task_runner.h"
18 class FakeTileTaskRunnerImpl
: public TileTaskRunner
, public TileTaskClient
{
20 // Overridden from TileTaskRunner:
21 void SetClient(TileTaskRunnerClient
* client
) override
{}
22 void Shutdown() override
{}
23 void ScheduleTasks(TileTaskQueue
* queue
) override
{
24 for (TileTaskQueue::Item::Vector::const_iterator it
= queue
->items
.begin();
25 it
!= queue
->items
.end(); ++it
) {
26 RasterTask
* task
= it
->task
;
29 task
->ScheduleOnOriginThread(this);
32 completed_tasks_
.push_back(task
);
35 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();
49 ResourceFormat
GetResourceFormat() override
{ return RGBA_8888
; }
51 // Overridden from TileTaskClient:
52 scoped_ptr
<RasterBuffer
> AcquireBufferForRaster(
53 const Resource
* resource
) override
{
56 void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) override
{}
59 RasterTask::Vector completed_tasks_
;
61 base::LazyInstance
<FakeTileTaskRunnerImpl
> g_fake_tile_task_runner
=
62 LAZY_INSTANCE_INITIALIZER
;
66 FakeTileManager::FakeTileManager(TileManagerClient
* client
)
68 base::MessageLoopProxy::current(),
70 g_fake_tile_task_runner
.Pointer(),
72 std::numeric_limits
<size_t>::max()) {
75 FakeTileManager::FakeTileManager(TileManagerClient
* client
,
76 ResourcePool
* resource_pool
)
78 base::MessageLoopProxy::current(),
80 g_fake_tile_task_runner
.Pointer(),
82 std::numeric_limits
<size_t>::max()) {
85 FakeTileManager::~FakeTileManager() {}
87 bool FakeTileManager::HasBeenAssignedMemory(Tile
* tile
) {
88 return std::find(tiles_for_raster
.begin(),
89 tiles_for_raster
.end(),
90 tile
) != tiles_for_raster
.end();
93 void FakeTileManager::Release(Tile
* tile
) {
94 TileManager::Release(tile
);
96 FreeResourcesForReleasedTiles();
97 CleanUpReleasedTiles();