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(),
71 std::numeric_limits
<size_t>::max()) {
74 FakeTileManager::FakeTileManager(TileManagerClient
* client
,
75 ResourcePool
* resource_pool
)
77 base::MessageLoopProxy::current(),
79 g_fake_tile_task_runner
.Pointer(),
80 std::numeric_limits
<size_t>::max()) {
83 FakeTileManager::~FakeTileManager() {}
85 bool FakeTileManager::HasBeenAssignedMemory(Tile
* tile
) {
86 return std::find(tiles_for_raster
.begin(),
87 tiles_for_raster
.end(),
88 tile
) != tiles_for_raster
.end();
91 void FakeTileManager::Release(Tile
* tile
) {
92 TileManager::Release(tile
);
94 FreeResourcesForReleasedTiles();
95 CleanUpReleasedTiles();