OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/test/fake_picture_pile_impl.h" | 5 #include "cc/test/fake_picture_pile_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/synchronization/waitable_event.h" | |
11 #include "cc/resources/picture_pile.h" | 12 #include "cc/resources/picture_pile.h" |
12 #include "cc/test/fake_picture_pile.h" | 13 #include "cc/test/fake_picture_pile.h" |
13 #include "cc/test/impl_side_painting_settings.h" | 14 #include "cc/test/impl_side_painting_settings.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 | 18 |
18 FakePicturePileImpl::FakePicturePileImpl() {} | 19 FakePicturePileImpl::FakePicturePileImpl() : raster_thread_blocker_(nullptr) { |
20 } | |
19 | 21 |
20 FakePicturePileImpl::FakePicturePileImpl(const PicturePile* other) | 22 FakePicturePileImpl::FakePicturePileImpl(const PicturePile* other, |
23 base::WaitableEvent* blocker) | |
21 : PicturePileImpl(other), | 24 : PicturePileImpl(other), |
25 raster_thread_blocker_(blocker), | |
22 tile_grid_info_(other->GetTileGridInfoForTesting()) { | 26 tile_grid_info_(other->GetTileGridInfoForTesting()) { |
23 } | 27 } |
24 | 28 |
25 FakePicturePileImpl::~FakePicturePileImpl() {} | 29 FakePicturePileImpl::~FakePicturePileImpl() {} |
26 | 30 |
27 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( | 31 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( |
28 const gfx::Size& tile_size, | 32 const gfx::Size& tile_size, |
29 const gfx::Size& layer_bounds) { | 33 const gfx::Size& layer_bounds) { |
30 FakePicturePile pile; | 34 FakePicturePile pile; |
31 pile.tiling().SetTilingSize(layer_bounds); | 35 pile.tiling().SetTilingSize(layer_bounds); |
32 pile.tiling().SetMaxTextureSize(tile_size); | 36 pile.tiling().SetMaxTextureSize(tile_size); |
33 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 37 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
34 pile.SetRecordedViewport(gfx::Rect(layer_bounds)); | 38 pile.SetRecordedViewport(gfx::Rect(layer_bounds)); |
35 pile.SetHasAnyRecordings(true); | 39 pile.SetHasAnyRecordings(true); |
36 | 40 |
37 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile)); | 41 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
38 for (int x = 0; x < pile_impl->tiling().num_tiles_x(); ++x) { | 42 for (int x = 0; x < pile_impl->tiling().num_tiles_x(); ++x) { |
39 for (int y = 0; y < pile_impl->tiling().num_tiles_y(); ++y) | 43 for (int y = 0; y < pile_impl->tiling().num_tiles_y(); ++y) |
40 pile_impl->AddRecordingAt(x, y); | 44 pile_impl->AddRecordingAt(x, y); |
41 } | 45 } |
42 return pile_impl; | 46 return pile_impl; |
43 } | 47 } |
44 | 48 |
45 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( | 49 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( |
46 const gfx::Size& tile_size, | 50 const gfx::Size& tile_size, |
47 const gfx::Size& layer_bounds) { | 51 const gfx::Size& layer_bounds) { |
48 FakePicturePile pile; | 52 FakePicturePile pile; |
49 pile.tiling().SetTilingSize(layer_bounds); | 53 pile.tiling().SetTilingSize(layer_bounds); |
50 pile.tiling().SetMaxTextureSize(tile_size); | 54 pile.tiling().SetMaxTextureSize(tile_size); |
51 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 55 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
52 pile.SetRecordedViewport(gfx::Rect()); | 56 pile.SetRecordedViewport(gfx::Rect()); |
53 pile.SetHasAnyRecordings(false); | 57 pile.SetHasAnyRecordings(false); |
54 return make_scoped_refptr(new FakePicturePileImpl(&pile)); | 58 return make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
55 } | 59 } |
56 | 60 |
57 scoped_refptr<FakePicturePileImpl> | 61 scoped_refptr<FakePicturePileImpl> |
58 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( | 62 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( |
59 const gfx::Size& tile_size, | 63 const gfx::Size& tile_size, |
60 const gfx::Size& layer_bounds) { | 64 const gfx::Size& layer_bounds) { |
61 FakePicturePile pile; | 65 FakePicturePile pile; |
62 pile.tiling().SetTilingSize(layer_bounds); | 66 pile.tiling().SetTilingSize(layer_bounds); |
63 pile.tiling().SetMaxTextureSize(tile_size); | 67 pile.tiling().SetMaxTextureSize(tile_size); |
64 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 68 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
65 // This simulates a false positive for this flag. | 69 // This simulates a false positive for this flag. |
66 pile.SetRecordedViewport(gfx::Rect()); | 70 pile.SetRecordedViewport(gfx::Rect()); |
67 pile.SetHasAnyRecordings(true); | 71 pile.SetHasAnyRecordings(true); |
68 return make_scoped_refptr(new FakePicturePileImpl(&pile)); | 72 return make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
69 } | 73 } |
70 | 74 |
71 scoped_refptr<FakePicturePileImpl> | 75 scoped_refptr<FakePicturePileImpl> |
72 FakePicturePileImpl::CreateInfiniteFilledPile() { | 76 FakePicturePileImpl::CreateInfiniteFilledPile() { |
73 FakePicturePile pile; | 77 FakePicturePile pile; |
74 gfx::Size size(std::numeric_limits<int>::max(), | 78 gfx::Size size(std::numeric_limits<int>::max(), |
75 std::numeric_limits<int>::max()); | 79 std::numeric_limits<int>::max()); |
76 pile.tiling().SetTilingSize(size); | 80 pile.tiling().SetTilingSize(size); |
77 pile.tiling().SetMaxTextureSize(size); | 81 pile.tiling().SetMaxTextureSize(size); |
78 pile.SetTileGridSize(size); | 82 pile.SetTileGridSize(size); |
79 pile.SetRecordedViewport(gfx::Rect(size)); | 83 pile.SetRecordedViewport(gfx::Rect(size)); |
80 pile.SetHasAnyRecordings(true); | 84 pile.SetHasAnyRecordings(true); |
81 | 85 |
82 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile)); | 86 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
83 pile_impl->AddRecordingAt(0, 0); | 87 pile_impl->AddRecordingAt(0, 0); |
84 return pile_impl; | 88 return pile_impl; |
85 } | 89 } |
86 | 90 |
91 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFromPile( | |
92 const PicturePile* other, | |
93 base::WaitableEvent* blocker) { | |
94 return make_scoped_refptr(new FakePicturePileImpl(other, blocker)); | |
95 } | |
96 | |
97 void FakePicturePileImpl::PlaybackToCanvas(SkCanvas* canvas, | |
98 const gfx::Rect& canvas_rect, | |
99 float contents_scale) const { | |
100 PicturePileImpl::PlaybackToCanvas(canvas, canvas_rect, contents_scale); | |
reveman
2014/11/13 20:50:58
Move the Wait() call above this line if you use my
danakj
2014/11/13 21:24:40
Right it doesn't matter, it's just blocking this f
| |
101 if (raster_thread_blocker_) | |
102 raster_thread_blocker_->Wait(); | |
103 } | |
104 | |
87 void FakePicturePileImpl::AddRecordingAt(int x, int y) { | 105 void FakePicturePileImpl::AddRecordingAt(int x, int y) { |
88 EXPECT_GE(x, 0); | 106 EXPECT_GE(x, 0); |
89 EXPECT_GE(y, 0); | 107 EXPECT_GE(y, 0); |
90 EXPECT_LT(x, tiling_.num_tiles_x()); | 108 EXPECT_LT(x, tiling_.num_tiles_x()); |
91 EXPECT_LT(y, tiling_.num_tiles_y()); | 109 EXPECT_LT(y, tiling_.num_tiles_y()); |
92 | 110 |
93 if (HasRecordingAt(x, y)) | 111 if (HasRecordingAt(x, y)) |
94 return; | 112 return; |
95 gfx::Rect bounds(tiling().TileBounds(x, y)); | 113 gfx::Rect bounds(tiling().TileBounds(x, y)); |
96 bounds.Inset(-buffer_pixels(), -buffer_pixels()); | 114 bounds.Inset(-buffer_pixels(), -buffer_pixels()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 Clear(); | 176 Clear(); |
159 tiling_.SetBorderTexels(new_buffer_pixels); | 177 tiling_.SetBorderTexels(new_buffer_pixels); |
160 } | 178 } |
161 | 179 |
162 void FakePicturePileImpl::Clear() { | 180 void FakePicturePileImpl::Clear() { |
163 picture_map_.clear(); | 181 picture_map_.clear(); |
164 recorded_viewport_ = gfx::Rect(); | 182 recorded_viewport_ = gfx::Rect(); |
165 } | 183 } |
166 | 184 |
167 } // namespace cc | 185 } // namespace cc |
OLD | NEW |