fake_tile_manager.cc revision 31fc3ed1513c41bdd4a09cdd402f3c4f53b0cecd
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.
4
5#include "cc/test/fake_tile_manager.h"
6
7#include <deque>
8#include <limits>
9
10#include "cc/resources/raster_worker_pool.h"
11
12namespace cc {
13
14namespace {
15
16class FakeRasterWorkerPool : public RasterWorkerPool {
17 public:
18  FakeRasterWorkerPool() : RasterWorkerPool(NULL, 1) {}
19
20  virtual void ScheduleTasks(RasterTask::Queue* queue) OVERRIDE {
21    RasterWorkerPool::SetRasterTasks(queue);
22    for (RasterTaskVector::const_iterator it = raster_tasks().begin();
23         it != raster_tasks().end(); ++it) {
24      completed_tasks_.push_back(it->get());
25    }
26  }
27  virtual void CheckForCompletedTasks() OVERRIDE {
28    while (!completed_tasks_.empty()) {
29      internal::RasterWorkerPoolTask* task = completed_tasks_.front().get();
30      task->WillComplete();
31      task->CompleteOnOriginThread();
32      task->DidComplete();
33      completed_tasks_.pop_front();
34    }
35  }
36  virtual GLenum GetResourceTarget() const OVERRIDE {
37    return GL_TEXTURE_2D;
38  }
39  virtual ResourceFormat GetResourceFormat() const OVERRIDE {
40    return RGBA_8888;
41  }
42  virtual void OnRasterTasksFinished() OVERRIDE {}
43  virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE {}
44
45 private:
46  typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > TaskDeque;
47  TaskDeque completed_tasks_;
48};
49
50}  // namespace
51
52FakeTileManager::FakeTileManager(TileManagerClient* client)
53    : TileManager(client,
54                  NULL,
55                  make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
56                  1,
57                  std::numeric_limits<unsigned>::max(),
58                  NULL) {}
59
60FakeTileManager::FakeTileManager(TileManagerClient* client,
61                                 ResourceProvider* resource_provider)
62    : TileManager(client,
63                  resource_provider,
64                  make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
65                  1,
66                  std::numeric_limits<unsigned>::max(),
67                  NULL) {}
68
69FakeTileManager::FakeTileManager(TileManagerClient* client,
70                                 ResourceProvider* resource_provider,
71                                 size_t raster_task_limit_bytes)
72    : TileManager(client,
73                  resource_provider,
74                  make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool),
75                  1,
76                  raster_task_limit_bytes,
77                  NULL) {}
78
79FakeTileManager::~FakeTileManager() {}
80
81void FakeTileManager::AssignMemoryToTiles(
82    const GlobalStateThatImpactsTilePriority& state) {
83  tiles_for_raster.clear();
84  all_tiles.Clear();
85
86  SetGlobalStateForTesting(state);
87  GetTilesWithAssignedBins(&all_tiles);
88  AssignGpuMemoryToTiles(&all_tiles, &tiles_for_raster);
89}
90
91bool FakeTileManager::HasBeenAssignedMemory(Tile* tile) {
92  return std::find(tiles_for_raster.begin(),
93                   tiles_for_raster.end(),
94                   tile) != tiles_for_raster.end();
95}
96
97void FakeTileManager::CheckForCompletedTasks() {
98  RasterWorkerPoolForTesting()->CheckForCompletedTasks();
99}
100
101void FakeTileManager::Release(Tile* tile) {
102  TileManager::Release(tile);
103  CleanUpReleasedTiles();
104}
105
106}  // namespace cc
107