Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / test / fake_picture_pile.cc
blob52a70ece8ac0ce6c02e1fa60fa9af21c573bd1f0
1 // Copyright 2014 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_picture_pile.h"
7 #include <utility>
9 #include "cc/test/fake_picture_pile_impl.h"
10 #include "cc/trees/layer_tree_settings.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace cc {
15 namespace {
17 scoped_ptr<FakePicturePile> CreatePile(const gfx::Size& tile_size,
18 const gfx::Size& layer_bounds,
19 bool is_filled) {
20 scoped_ptr<FakePicturePile> pile(
21 new FakePicturePile(LayerTreeSettings().minimum_contents_scale,
22 LayerTreeSettings().default_tile_grid_size));
23 pile->tiling().SetBorderTexels(0);
24 pile->tiling().SetTilingSize(layer_bounds);
25 pile->tiling().SetMaxTextureSize(tile_size);
26 pile->SetRecordedViewport(is_filled ? gfx::Rect(layer_bounds) : gfx::Rect());
27 pile->SetHasAnyRecordings(is_filled);
28 if (is_filled) {
29 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) {
30 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y)
31 pile->AddRecordingAt(x, y);
34 return pile;
37 } // namespace
39 scoped_ptr<FakePicturePile> FakePicturePile::CreateFilledPile(
40 const gfx::Size& tile_size,
41 const gfx::Size& layer_bounds) {
42 bool is_filled = true;
43 return CreatePile(tile_size, layer_bounds, is_filled);
46 scoped_ptr<FakePicturePile> FakePicturePile::CreateEmptyPile(
47 const gfx::Size& tile_size,
48 const gfx::Size& layer_bounds) {
49 bool is_filled = false;
50 return CreatePile(tile_size, layer_bounds, is_filled);
53 scoped_refptr<RasterSource> FakePicturePile::CreateRasterSource(
54 bool can_use_lcd_text) const {
55 return FakePicturePileImpl::CreateFromPile(this, playback_allowed_event_);
58 void FakePicturePile::AddRecordingAt(int x, int y) {
59 EXPECT_GE(x, 0);
60 EXPECT_GE(y, 0);
61 EXPECT_LT(x, tiling_.num_tiles_x());
62 EXPECT_LT(y, tiling_.num_tiles_y());
64 if (HasRecordingAt(x, y))
65 return;
66 gfx::Rect bounds(tiling().TileBounds(x, y));
67 bounds.Inset(-buffer_pixels(), -buffer_pixels());
69 scoped_refptr<Picture> picture(
70 Picture::Create(bounds, &client_, tile_grid_size_, gather_pixel_refs_,
71 RecordingSource::RECORD_NORMALLY));
72 picture_map_[std::pair<int, int>(x, y)] = picture;
73 EXPECT_TRUE(HasRecordingAt(x, y));
75 has_any_recordings_ = true;
78 void FakePicturePile::RemoveRecordingAt(int x, int y) {
79 EXPECT_GE(x, 0);
80 EXPECT_GE(y, 0);
81 EXPECT_LT(x, tiling_.num_tiles_x());
82 EXPECT_LT(y, tiling_.num_tiles_y());
84 if (!HasRecordingAt(x, y))
85 return;
86 picture_map_.erase(std::pair<int, int>(x, y));
87 EXPECT_FALSE(HasRecordingAt(x, y));
90 bool FakePicturePile::HasRecordingAt(int x, int y) const {
91 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y));
92 return found != picture_map_.end();
95 void FakePicturePile::Rerecord() {
96 for (int y = 0; y < num_tiles_y(); ++y) {
97 for (int x = 0; x < num_tiles_x(); ++x) {
98 RemoveRecordingAt(x, y);
99 AddRecordingAt(x, y);
104 } // namespace cc