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/test/impl_side_painting_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
,
35 FakePicturePile
pile(ImplSidePaintingSettings().minimum_contents_scale
,
36 ImplSidePaintingSettings().default_tile_grid_size
);
37 pile
.tiling().SetBorderTexels(0);
38 pile
.tiling().SetTilingSize(layer_bounds
);
39 pile
.tiling().SetMaxTextureSize(tile_size
);
40 pile
.SetRecordedViewport(is_filled
? gfx::Rect(layer_bounds
) : gfx::Rect());
41 pile
.SetHasAnyRecordings(is_filled
);
43 for (int x
= 0; x
< pile
.tiling().num_tiles_x(); ++x
) {
44 for (int y
= 0; y
< pile
.tiling().num_tiles_y(); ++y
)
45 pile
.AddRecordingAt(x
, y
);
48 scoped_refptr
<FakePicturePileImpl
> pile_impl(
49 new FakePicturePileImpl(&pile
, nullptr));
53 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateFilledPile(
54 const gfx::Size
& tile_size
,
55 const gfx::Size
& layer_bounds
) {
56 bool is_filled
= true;
57 return CreatePile(tile_size
, layer_bounds
, is_filled
);
60 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateEmptyPile(
61 const gfx::Size
& tile_size
,
62 const gfx::Size
& layer_bounds
) {
63 bool is_filled
= false;
64 return CreatePile(tile_size
, layer_bounds
, is_filled
);
67 scoped_refptr
<FakePicturePileImpl
>
68 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings(
69 const gfx::Size
& tile_size
,
70 const gfx::Size
& layer_bounds
,
71 bool is_solid_color
) {
72 FakePicturePile
pile(ImplSidePaintingSettings().minimum_contents_scale
,
73 ImplSidePaintingSettings().default_tile_grid_size
);
74 pile
.tiling().SetBorderTexels(0);
75 pile
.tiling().SetTilingSize(layer_bounds
);
76 pile
.tiling().SetMaxTextureSize(tile_size
);
77 // This simulates a false positive for this flag.
78 pile
.SetRecordedViewport(gfx::Rect());
79 pile
.SetHasAnyRecordings(true);
80 pile
.SetIsSolidColor(is_solid_color
);
81 return make_scoped_refptr(new FakePicturePileImpl(&pile
, nullptr));
84 scoped_refptr
<FakePicturePileImpl
>
85 FakePicturePileImpl::CreateInfiniteFilledPile() {
86 gfx::Size
size(std::numeric_limits
<int>::max(),
87 std::numeric_limits
<int>::max());
88 FakePicturePile
pile(ImplSidePaintingSettings().minimum_contents_scale
, size
);
89 pile
.tiling().SetBorderTexels(0);
90 pile
.tiling().SetTilingSize(size
);
91 pile
.tiling().SetMaxTextureSize(size
);
92 pile
.SetRecordedViewport(gfx::Rect(size
));
93 pile
.SetHasAnyRecordings(true);
94 pile
.AddRecordingAt(0, 0);
95 scoped_refptr
<FakePicturePileImpl
> pile_impl(
96 new FakePicturePileImpl(&pile
, nullptr));
100 scoped_refptr
<FakePicturePileImpl
> FakePicturePileImpl::CreateFromPile(
101 const PicturePile
* other
,
102 base::WaitableEvent
* playback_allowed_event
) {
103 return make_scoped_refptr(
104 new FakePicturePileImpl(other
, playback_allowed_event
));
107 void FakePicturePileImpl::PlaybackToCanvas(SkCanvas
* canvas
,
108 const gfx::Rect
& canvas_rect
,
109 float contents_scale
) const {
110 if (playback_allowed_event_
)
111 playback_allowed_event_
->Wait();
112 PicturePileImpl::PlaybackToCanvas(canvas
, canvas_rect
, contents_scale
);
115 bool FakePicturePileImpl::HasRecordingAt(int x
, int y
) const {
116 PictureMap::const_iterator found
= picture_map_
.find(PictureMapKey(x
, y
));
117 return found
!= picture_map_
.end();