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"
11 #include "base/synchronization/waitable_event.h"
12 #include "cc/playback/picture_pile.h"
13 #include "cc/trees/layer_tree_settings.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 FakePicturePileImpl::FakePicturePileImpl() : playback_allowed_event_(nullptr) {
21 FakePicturePileImpl::FakePicturePileImpl(
22 const PicturePile
* other
,
23 base::WaitableEvent
* playback_allowed_event
)
24 : PicturePileImpl(other
, true),
25 playback_allowed_event_(playback_allowed_event
),
26 tile_grid_size_(other
->GetTileGridSizeForTesting()) {
29 FakePicturePileImpl::~FakePicturePileImpl() {}
31 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreatePile(
32 const gfx::Size
& tile_size
,
33 const gfx::Size
& layer_bounds
,
34 const gfx::Rect
& recorded_viewport
,
36 FakePicturePile
pile(LayerTreeSettings().minimum_contents_scale
,
37 LayerTreeSettings().default_tile_grid_size
);
38 pile
.tiling().SetBorderTexels(0);
39 pile
.tiling().SetTilingSize(layer_bounds
);
40 pile
.tiling().SetMaxTextureSize(tile_size
);
41 pile
.SetRecordedViewport(recorded_viewport
);
42 pile
.SetHasAnyRecordings(is_filled
);
44 for (int x
= 0; x
< pile
.tiling().num_tiles_x(); ++x
) {
45 for (int y
= 0; y
< pile
.tiling().num_tiles_y(); ++y
)
46 pile
.AddRecordingAt(x
, y
);
49 scoped_refptr
<FakePicturePileImpl
> pile_impl(
50 new FakePicturePileImpl(&pile
, nullptr));
54 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateFilledPile(
55 const gfx::Size
& tile_size
,
56 const gfx::Size
& layer_bounds
) {
57 gfx::Rect
recorded_viewport(layer_bounds
);
58 bool is_filled
= true;
59 return CreatePile(tile_size
, layer_bounds
, recorded_viewport
, is_filled
);
62 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateEmptyPile(
63 const gfx::Size
& tile_size
,
64 const gfx::Size
& layer_bounds
) {
65 gfx::Rect recorded_viewport
;
66 bool is_filled
= false;
67 return CreatePile(tile_size
, layer_bounds
, recorded_viewport
, is_filled
);
70 scoped_refptr
<FakePicturePileImpl
>
71 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
72 const gfx::Size
& tile_size
,
73 const gfx::Size
& layer_bounds
,
74 bool is_solid_color
) {
75 FakePicturePile
pile(LayerTreeSettings().minimum_contents_scale
,
76 LayerTreeSettings().default_tile_grid_size
);
77 pile
.tiling().SetBorderTexels(0);
78 pile
.tiling().SetTilingSize(layer_bounds
);
79 pile
.tiling().SetMaxTextureSize(tile_size
);
80 // This simulates a false positive for this flag.
81 pile
.SetRecordedViewport(gfx::Rect());
82 pile
.SetHasAnyRecordings(true);
83 pile
.SetIsSolidColor(is_solid_color
);
84 return make_scoped_refptr(new FakePicturePileImpl(&pile
, nullptr));
87 scoped_refptr
<FakePicturePileImpl
>
88 FakePicturePileImpl::CreateInfiniteFilledPile() {
89 gfx::Size
size(std::numeric_limits
<int>::max(),
90 std::numeric_limits
<int>::max());
91 FakePicturePile
pile(LayerTreeSettings().minimum_contents_scale
, size
);
92 pile
.tiling().SetBorderTexels(0);
93 pile
.tiling().SetTilingSize(size
);
94 pile
.tiling().SetMaxTextureSize(size
);
95 pile
.SetRecordedViewport(gfx::Rect(size
));
96 pile
.SetHasAnyRecordings(true);
97 pile
.AddRecordingAt(0, 0);
98 scoped_refptr
<FakePicturePileImpl
> pile_impl(
99 new FakePicturePileImpl(&pile
, nullptr));
103 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateFromPile(
104 const PicturePile
* other
,
105 base::WaitableEvent
* playback_allowed_event
) {
106 return make_scoped_refptr(
107 new FakePicturePileImpl(other
, playback_allowed_event
));
110 void FakePicturePileImpl::PlaybackToCanvas(
112 const gfx::Rect
& canvas_bitmap_rect
,
113 const gfx::Rect
& canvas_playback_rect
,
114 float contents_scale
) const {
115 if (playback_allowed_event_
)
116 playback_allowed_event_
->Wait();
117 PicturePileImpl::PlaybackToCanvas(canvas
, canvas_bitmap_rect
,
118 canvas_playback_rect
, contents_scale
);
121 bool FakePicturePileImpl::HasRecordingAt(int x
, int y
) const {
122 PictureMap::const_iterator found
= picture_map_
.find(PictureMapKey(x
, y
));
123 return found
!= picture_map_
.end();