OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/test/fake_picture_pile_impl.h" | |
6 | |
7 #include <algorithm> | |
8 #include <limits> | |
9 #include <utility> | |
10 | |
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" | |
15 | |
16 namespace cc { | |
17 | |
18 FakePicturePileImpl::FakePicturePileImpl() : playback_allowed_event_(nullptr) { | |
19 } | |
20 | |
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 | |
27 FakePicturePileImpl::~FakePicturePileImpl() {} | |
28 | |
29 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreatePile( | |
30 const gfx::Size& tile_size, | |
31 const gfx::Size& layer_bounds, | |
32 const gfx::Rect& recorded_viewport, | |
33 bool is_filled) { | |
34 FakePicturePile pile(LayerTreeSettings().minimum_contents_scale, | |
35 LayerTreeSettings().default_tile_grid_size); | |
36 pile.tiling().SetBorderTexels(0); | |
37 pile.tiling().SetTilingSize(layer_bounds); | |
38 pile.tiling().SetMaxTextureSize(tile_size); | |
39 pile.SetRecordedViewport(recorded_viewport); | |
40 pile.SetHasAnyRecordings(is_filled); | |
41 if (is_filled) { | |
42 for (int x = 0; x < pile.tiling().num_tiles_x(); ++x) { | |
43 for (int y = 0; y < pile.tiling().num_tiles_y(); ++y) | |
44 pile.AddRecordingAt(x, y); | |
45 } | |
46 } | |
47 scoped_refptr<FakePicturePileImpl> pile_impl( | |
48 new FakePicturePileImpl(&pile, nullptr)); | |
49 return pile_impl; | |
50 } | |
51 | |
52 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( | |
53 const gfx::Size& tile_size, | |
54 const gfx::Size& layer_bounds) { | |
55 gfx::Rect recorded_viewport(layer_bounds); | |
56 bool is_filled = true; | |
57 return CreatePile(tile_size, layer_bounds, recorded_viewport, is_filled); | |
58 } | |
59 | |
60 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( | |
61 const gfx::Size& tile_size, | |
62 const gfx::Size& layer_bounds) { | |
63 gfx::Rect recorded_viewport; | |
64 bool is_filled = false; | |
65 return CreatePile(tile_size, layer_bounds, recorded_viewport, is_filled); | |
66 } | |
67 | |
68 scoped_refptr<FakePicturePileImpl> | |
69 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( | |
70 const gfx::Size& tile_size, | |
71 const gfx::Size& layer_bounds, | |
72 bool is_solid_color) { | |
73 FakePicturePile pile(LayerTreeSettings().minimum_contents_scale, | |
74 LayerTreeSettings().default_tile_grid_size); | |
75 pile.tiling().SetBorderTexels(0); | |
76 pile.tiling().SetTilingSize(layer_bounds); | |
77 pile.tiling().SetMaxTextureSize(tile_size); | |
78 // This simulates a false positive for this flag. | |
79 pile.SetRecordedViewport(gfx::Rect()); | |
80 pile.SetHasAnyRecordings(true); | |
81 pile.SetIsSolidColor(is_solid_color); | |
82 return make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); | |
83 } | |
84 | |
85 scoped_refptr<FakePicturePileImpl> | |
86 FakePicturePileImpl::CreateInfiniteFilledPile() { | |
87 gfx::Size size(std::numeric_limits<int>::max(), | |
88 std::numeric_limits<int>::max()); | |
89 FakePicturePile pile(LayerTreeSettings().minimum_contents_scale, size); | |
90 pile.tiling().SetBorderTexels(0); | |
91 pile.tiling().SetTilingSize(size); | |
92 pile.tiling().SetMaxTextureSize(size); | |
93 pile.SetRecordedViewport(gfx::Rect(size)); | |
94 pile.SetHasAnyRecordings(true); | |
95 pile.AddRecordingAt(0, 0); | |
96 scoped_refptr<FakePicturePileImpl> pile_impl( | |
97 new FakePicturePileImpl(&pile, nullptr)); | |
98 return pile_impl; | |
99 } | |
100 | |
101 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFromPile( | |
102 const PicturePile* other, | |
103 base::WaitableEvent* playback_allowed_event) { | |
104 return make_scoped_refptr( | |
105 new FakePicturePileImpl(other, playback_allowed_event)); | |
106 } | |
107 | |
108 void FakePicturePileImpl::PlaybackToCanvas( | |
109 SkCanvas* canvas, | |
110 const gfx::Rect& canvas_bitmap_rect, | |
111 const gfx::Rect& canvas_playback_rect, | |
112 float contents_scale) const { | |
113 if (playback_allowed_event_) | |
114 playback_allowed_event_->Wait(); | |
115 PicturePileImpl::PlaybackToCanvas(canvas, canvas_bitmap_rect, | |
116 canvas_playback_rect, contents_scale); | |
117 } | |
118 | |
119 bool FakePicturePileImpl::HasRecordingAt(int x, int y) const { | |
120 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); | |
121 return found != picture_map_.end(); | |
122 } | |
123 | |
124 } // namespace cc | |
OLD | NEW |