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"
10 #include "cc/test/fake_rendering_stats_instrumentation.h"
11 #include "cc/test/impl_side_painting_settings.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 FakePicturePileImpl::FakePicturePileImpl() {}
18 FakePicturePileImpl::~FakePicturePileImpl() {}
20 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateFilledPile(
22 gfx::Size layer_bounds
) {
23 scoped_refptr
<FakePicturePileImpl
> pile(new FakePicturePileImpl());
24 pile
->tiling().SetTotalSize(layer_bounds
);
25 pile
->tiling().SetMaxTextureSize(tile_size
);
26 pile
->SetTileGridSize(ImplSidePaintingSettings().default_tile_size
);
27 for (int x
= 0; x
< pile
->tiling().num_tiles_x(); ++x
) {
28 for (int y
= 0; y
< pile
->tiling().num_tiles_y(); ++y
)
29 pile
->AddRecordingAt(x
, y
);
31 pile
->UpdateRecordedRegion();
35 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateEmptyPile(
37 gfx::Size layer_bounds
) {
38 scoped_refptr
<FakePicturePileImpl
> pile(new FakePicturePileImpl());
39 pile
->tiling().SetTotalSize(layer_bounds
);
40 pile
->tiling().SetMaxTextureSize(tile_size
);
41 pile
->SetTileGridSize(ImplSidePaintingSettings().default_tile_size
);
42 pile
->UpdateRecordedRegion();
46 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreatePile() {
47 scoped_refptr
<FakePicturePileImpl
> pile(new FakePicturePileImpl());
48 gfx::Size
size(std::numeric_limits
<int>::max(),
49 std::numeric_limits
<int>::max());
51 pile
->recorded_region_
= Region(gfx::Rect(size
));
55 void FakePicturePileImpl::AddRecordingAt(int x
, int y
) {
58 EXPECT_LT(x
, tiling_
.num_tiles_x());
59 EXPECT_LT(y
, tiling_
.num_tiles_y());
61 if (HasRecordingAt(x
, y
))
63 gfx::Rect
bounds(tiling().TileBounds(x
, y
));
64 bounds
.Inset(-buffer_pixels(), -buffer_pixels());
66 FakeRenderingStatsInstrumentation stats_instrumentation
;
68 scoped_refptr
<Picture
> picture(Picture::Create(bounds
));
69 picture
->Record(&client_
, tile_grid_info_
, &stats_instrumentation
);
70 picture
->GatherPixelRefs(tile_grid_info_
, &stats_instrumentation
);
71 picture_list_map_
[std::pair
<int, int>(x
, y
)].push_back(picture
);
72 EXPECT_TRUE(HasRecordingAt(x
, y
));
74 UpdateRecordedRegion();
77 void FakePicturePileImpl::AddPictureToRecording(
80 scoped_refptr
<Picture
> picture
) {
81 picture_list_map_
[std::pair
<int, int>(x
, y
)].push_back(picture
);
84 void FakePicturePileImpl::RemoveRecordingAt(int x
, int y
) {
87 EXPECT_LT(x
, tiling_
.num_tiles_x());
88 EXPECT_LT(y
, tiling_
.num_tiles_y());
90 if (!HasRecordingAt(x
, y
))
92 picture_list_map_
.erase(std::pair
<int, int>(x
, y
));
93 EXPECT_FALSE(HasRecordingAt(x
, y
));
95 UpdateRecordedRegion();
98 void FakePicturePileImpl::RerecordPile() {
99 for (int y
= 0; y
< num_tiles_y(); ++y
) {
100 for (int x
= 0; x
< num_tiles_x(); ++x
) {
101 RemoveRecordingAt(x
, y
);
102 AddRecordingAt(x
, y
);