[Android] Expose more GoogleUtils to Java.
[chromium-blink-merge.git] / cc / test / fake_tile_manager.cc
blob60f75323e116f2a922ab53ce0229ad98f8e98e42
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>
9 #include "base/lazy_instance.h"
10 #include "cc/resources/rasterizer.h"
12 namespace cc {
14 namespace {
16 class FakeRasterizerImpl : public Rasterizer, public RasterizerTaskClient {
17 public:
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 =
23 queue->items.begin();
24 it != queue->items.end();
25 ++it) {
26 RasterTask* task = it->task;
28 task->WillSchedule();
29 task->ScheduleOnOriginThread(this);
30 task->DidSchedule();
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();
38 ++it) {
39 RasterTask* task = it->get();
41 task->WillComplete();
42 task->CompleteOnOriginThread(this);
43 task->DidComplete();
45 task->RunReplyOnOriginThread();
47 completed_tasks_.clear();
50 // Overridden from RasterizerTaskClient:
51 virtual SkCanvas* AcquireCanvasForRaster(RasterTask* task) OVERRIDE {
52 return NULL;
54 virtual void ReleaseCanvasForRaster(RasterTask* task) OVERRIDE {}
56 private:
57 RasterTask::Vector completed_tasks_;
59 base::LazyInstance<FakeRasterizerImpl> g_fake_rasterizer =
60 LAZY_INSTANCE_INITIALIZER;
62 } // namespace
64 FakeTileManager::FakeTileManager(TileManagerClient* client)
65 : TileManager(client,
66 base::MessageLoopProxy::current(),
67 NULL,
68 g_fake_rasterizer.Pointer(),
69 NULL) {}
71 FakeTileManager::FakeTileManager(TileManagerClient* client,
72 ResourcePool* resource_pool)
73 : TileManager(client,
74 base::MessageLoopProxy::current(),
75 resource_pool,
76 g_fake_rasterizer.Pointer(),
77 NULL) {}
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();
104 } // namespace cc