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 "base/thread_task_runner_handle.h"
12 #include "cc/raster/raster_buffer.h"
13 #include "cc/raster/tile_task_runner.h"
19 class FakeTileTaskRunnerImpl
: public TileTaskRunner
, public TileTaskClient
{
21 // Overridden from TileTaskRunner:
22 void SetClient(TileTaskRunnerClient
* client
) override
{}
23 void Shutdown() override
{}
24 void ScheduleTasks(TileTaskQueue
* queue
) override
{
25 for (TileTaskQueue::Item::Vector::const_iterator it
= queue
->items
.begin();
26 it
!= queue
->items
.end(); ++it
) {
27 RasterTask
* task
= it
->task
;
30 task
->ScheduleOnOriginThread(this);
33 completed_tasks_
.push_back(task
);
36 void CheckForCompletedTasks() override
{
37 for (RasterTask::Vector::iterator it
= completed_tasks_
.begin();
38 it
!= completed_tasks_
.end();
40 RasterTask
* task
= it
->get();
43 task
->CompleteOnOriginThread(this);
46 completed_tasks_
.clear();
48 ResourceFormat
GetResourceFormat() const override
{ return RGBA_8888
; }
49 bool GetResourceRequiresSwizzle() const override
{
50 return !PlatformColor::SameComponentOrder(GetResourceFormat());
53 // Overridden from TileTaskClient:
54 scoped_ptr
<RasterBuffer
> AcquireBufferForRaster(
55 const Resource
* resource
,
56 uint64_t resource_content_id
,
57 uint64_t previous_content_id
) override
{
60 void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) override
{}
63 RasterTask::Vector completed_tasks_
;
65 base::LazyInstance
<FakeTileTaskRunnerImpl
> g_fake_tile_task_runner
=
66 LAZY_INSTANCE_INITIALIZER
;
70 FakeTileManager::FakeTileManager(TileManagerClient
* client
)
72 base::ThreadTaskRunnerHandle::Get(),
73 std::numeric_limits
<size_t>::max()) {
74 SetResources(nullptr, g_fake_tile_task_runner
.Pointer(),
75 std::numeric_limits
<size_t>::max());
78 FakeTileManager::FakeTileManager(TileManagerClient
* client
,
79 ResourcePool
* resource_pool
)
81 base::ThreadTaskRunnerHandle::Get(),
82 std::numeric_limits
<size_t>::max()) {
83 SetResources(resource_pool
, g_fake_tile_task_runner
.Pointer(),
84 std::numeric_limits
<size_t>::max());
87 FakeTileManager::~FakeTileManager() {}
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::Release(Tile
* tile
) {
96 TileManager::Release(tile
);
98 FreeResourcesForReleasedTiles();
99 CleanUpReleasedTiles();