Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / cc / test / fake_tile_manager.cc
blobd33093f0f6e3713b4c699ddf4067bee0a721c3a7
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"
7 #include <deque>
8 #include <limits>
10 #include "base/lazy_instance.h"
11 #include "cc/resources/raster_buffer.h"
12 #include "cc/resources/tile_task_runner.h"
14 namespace cc {
16 namespace {
18 class FakeTileTaskRunnerImpl : public TileTaskRunner, public TileTaskClient {
19 public:
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;
28 task->WillSchedule();
29 task->ScheduleOnOriginThread(this);
30 task->DidSchedule();
32 completed_tasks_.push_back(task);
35 void CheckForCompletedTasks() override {
36 for (RasterTask::Vector::iterator it = completed_tasks_.begin();
37 it != completed_tasks_.end();
38 ++it) {
39 RasterTask* task = it->get();
41 task->WillComplete();
42 task->CompleteOnOriginThread(this);
43 task->DidComplete();
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 {
54 return nullptr;
56 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override {}
58 private:
59 RasterTask::Vector completed_tasks_;
61 base::LazyInstance<FakeTileTaskRunnerImpl> g_fake_tile_task_runner =
62 LAZY_INSTANCE_INITIALIZER;
64 } // namespace
66 FakeTileManager::FakeTileManager(TileManagerClient* client)
67 : TileManager(client,
68 base::MessageLoopProxy::current(),
69 nullptr,
70 g_fake_tile_task_runner.Pointer(),
71 std::numeric_limits<size_t>::max()) {
74 FakeTileManager::FakeTileManager(TileManagerClient* client,
75 ResourcePool* resource_pool)
76 : TileManager(client,
77 base::MessageLoopProxy::current(),
78 resource_pool,
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();
98 } // namespace cc