Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / test / fake_picture_pile_impl.cc
blob57a50742e3f0014639f388aa49ab5e5d5f5132ae
1 // Copyright 2013 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_impl.h"
7 #include <limits>
8 #include <utility>
10 #include "cc/test/impl_side_painting_settings.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace cc {
15 FakePicturePileImpl::FakePicturePileImpl() {}
17 FakePicturePileImpl::~FakePicturePileImpl() {}
19 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile(
20 const gfx::Size& tile_size,
21 const gfx::Size& layer_bounds) {
22 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
23 pile->tiling().SetTilingRect(gfx::Rect(layer_bounds));
24 pile->tiling().SetMaxTextureSize(tile_size);
25 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
26 pile->recorded_viewport_ = gfx::Rect(layer_bounds);
27 pile->has_any_recordings_ = true;
28 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) {
29 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y)
30 pile->AddRecordingAt(x, y);
32 return pile;
35 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile(
36 const gfx::Size& tile_size,
37 const gfx::Size& layer_bounds) {
38 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
39 pile->tiling().SetTilingRect(gfx::Rect(layer_bounds));
40 pile->tiling().SetMaxTextureSize(tile_size);
41 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
42 pile->recorded_viewport_ = gfx::Rect();
43 pile->has_any_recordings_ = false;
44 return pile;
47 scoped_refptr<FakePicturePileImpl>
48 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
49 const gfx::Size& tile_size,
50 const gfx::Size& layer_bounds) {
51 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
52 pile->tiling().SetTilingRect(gfx::Rect(layer_bounds));
53 pile->tiling().SetMaxTextureSize(tile_size);
54 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
55 // This simulates a false positive for this flag.
56 pile->recorded_viewport_ = gfx::Rect();
57 pile->has_any_recordings_ = true;
58 return pile;
61 scoped_refptr<FakePicturePileImpl>
62 FakePicturePileImpl::CreateInfiniteFilledPile() {
63 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
64 gfx::Size size(std::numeric_limits<int>::max(),
65 std::numeric_limits<int>::max());
66 pile->SetTilingRect(gfx::Rect(size));
67 pile->tiling().SetTilingRect(gfx::Rect(size));
68 pile->tiling().SetMaxTextureSize(size);
69 pile->SetTileGridSize(size);
70 pile->recorded_viewport_ = gfx::Rect(size);
71 pile->has_any_recordings_ = true;
72 pile->AddRecordingAt(0, 0);
73 return pile;
76 void FakePicturePileImpl::AddRecordingAt(int x, int y) {
77 EXPECT_GE(x, 0);
78 EXPECT_GE(y, 0);
79 EXPECT_LT(x, tiling_.num_tiles_x());
80 EXPECT_LT(y, tiling_.num_tiles_y());
82 if (HasRecordingAt(x, y))
83 return;
84 gfx::Rect bounds(tiling().TileBounds(x, y));
85 bounds.Inset(-buffer_pixels(), -buffer_pixels());
87 scoped_refptr<Picture> picture(Picture::Create(
88 bounds, &client_, tile_grid_info_, true, 0, Picture::RECORD_NORMALLY));
89 picture_map_[std::pair<int, int>(x, y)].SetPicture(picture);
90 EXPECT_TRUE(HasRecordingAt(x, y));
92 has_any_recordings_ = true;
95 void FakePicturePileImpl::RemoveRecordingAt(int x, int y) {
96 EXPECT_GE(x, 0);
97 EXPECT_GE(y, 0);
98 EXPECT_LT(x, tiling_.num_tiles_x());
99 EXPECT_LT(y, tiling_.num_tiles_y());
101 if (!HasRecordingAt(x, y))
102 return;
103 picture_map_.erase(std::pair<int, int>(x, y));
104 EXPECT_FALSE(HasRecordingAt(x, y));
107 void FakePicturePileImpl::RerecordPile() {
108 for (int y = 0; y < num_tiles_y(); ++y) {
109 for (int x = 0; x < num_tiles_x(); ++x) {
110 RemoveRecordingAt(x, y);
111 AddRecordingAt(x, y);
116 } // namespace cc