| 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() : playback_allowed_event_(nullptr) { |
| 20 } |
| 19 | 21 |
| 20 FakePicturePileImpl::FakePicturePileImpl(const PicturePile* other) | 22 FakePicturePileImpl::FakePicturePileImpl( |
| 23 const PicturePile* other, |
| 24 base::WaitableEvent* playback_allowed_event) |
| 21 : PicturePileImpl(other), | 25 : PicturePileImpl(other), |
| 26 playback_allowed_event_(playback_allowed_event), |
| 22 tile_grid_info_(other->GetTileGridInfoForTesting()) { | 27 tile_grid_info_(other->GetTileGridInfoForTesting()) { |
| 23 } | 28 } |
| 24 | 29 |
| 25 FakePicturePileImpl::~FakePicturePileImpl() {} | 30 FakePicturePileImpl::~FakePicturePileImpl() {} |
| 26 | 31 |
| 27 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( | 32 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( |
| 28 const gfx::Size& tile_size, | 33 const gfx::Size& tile_size, |
| 29 const gfx::Size& layer_bounds) { | 34 const gfx::Size& layer_bounds) { |
| 30 FakePicturePile pile; | 35 FakePicturePile pile; |
| 31 pile.tiling().SetTilingSize(layer_bounds); | 36 pile.tiling().SetTilingSize(layer_bounds); |
| 32 pile.tiling().SetMaxTextureSize(tile_size); | 37 pile.tiling().SetMaxTextureSize(tile_size); |
| 33 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 38 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
| 34 pile.SetRecordedViewport(gfx::Rect(layer_bounds)); | 39 pile.SetRecordedViewport(gfx::Rect(layer_bounds)); |
| 35 pile.SetHasAnyRecordings(true); | 40 pile.SetHasAnyRecordings(true); |
| 36 | 41 |
| 37 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile)); | 42 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
| 38 for (int x = 0; x < pile_impl->tiling().num_tiles_x(); ++x) { | 43 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) | 44 for (int y = 0; y < pile_impl->tiling().num_tiles_y(); ++y) |
| 40 pile_impl->AddRecordingAt(x, y); | 45 pile_impl->AddRecordingAt(x, y); |
| 41 } | 46 } |
| 42 return pile_impl; | 47 return pile_impl; |
| 43 } | 48 } |
| 44 | 49 |
| 45 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( | 50 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( |
| 46 const gfx::Size& tile_size, | 51 const gfx::Size& tile_size, |
| 47 const gfx::Size& layer_bounds) { | 52 const gfx::Size& layer_bounds) { |
| 48 FakePicturePile pile; | 53 FakePicturePile pile; |
| 49 pile.tiling().SetTilingSize(layer_bounds); | 54 pile.tiling().SetTilingSize(layer_bounds); |
| 50 pile.tiling().SetMaxTextureSize(tile_size); | 55 pile.tiling().SetMaxTextureSize(tile_size); |
| 51 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 56 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
| 52 pile.SetRecordedViewport(gfx::Rect()); | 57 pile.SetRecordedViewport(gfx::Rect()); |
| 53 pile.SetHasAnyRecordings(false); | 58 pile.SetHasAnyRecordings(false); |
| 54 return make_scoped_refptr(new FakePicturePileImpl(&pile)); | 59 return make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
| 55 } | 60 } |
| 56 | 61 |
| 57 scoped_refptr<FakePicturePileImpl> | 62 scoped_refptr<FakePicturePileImpl> |
| 58 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( | 63 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( |
| 59 const gfx::Size& tile_size, | 64 const gfx::Size& tile_size, |
| 60 const gfx::Size& layer_bounds) { | 65 const gfx::Size& layer_bounds) { |
| 61 FakePicturePile pile; | 66 FakePicturePile pile; |
| 62 pile.tiling().SetTilingSize(layer_bounds); | 67 pile.tiling().SetTilingSize(layer_bounds); |
| 63 pile.tiling().SetMaxTextureSize(tile_size); | 68 pile.tiling().SetMaxTextureSize(tile_size); |
| 64 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 69 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
| 65 // This simulates a false positive for this flag. | 70 // This simulates a false positive for this flag. |
| 66 pile.SetRecordedViewport(gfx::Rect()); | 71 pile.SetRecordedViewport(gfx::Rect()); |
| 67 pile.SetHasAnyRecordings(true); | 72 pile.SetHasAnyRecordings(true); |
| 68 return make_scoped_refptr(new FakePicturePileImpl(&pile)); | 73 return make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
| 69 } | 74 } |
| 70 | 75 |
| 71 scoped_refptr<FakePicturePileImpl> | 76 scoped_refptr<FakePicturePileImpl> |
| 72 FakePicturePileImpl::CreateInfiniteFilledPile() { | 77 FakePicturePileImpl::CreateInfiniteFilledPile() { |
| 73 FakePicturePile pile; | 78 FakePicturePile pile; |
| 74 gfx::Size size(std::numeric_limits<int>::max(), | 79 gfx::Size size(std::numeric_limits<int>::max(), |
| 75 std::numeric_limits<int>::max()); | 80 std::numeric_limits<int>::max()); |
| 76 pile.tiling().SetTilingSize(size); | 81 pile.tiling().SetTilingSize(size); |
| 77 pile.tiling().SetMaxTextureSize(size); | 82 pile.tiling().SetMaxTextureSize(size); |
| 78 pile.SetTileGridSize(size); | 83 pile.SetTileGridSize(size); |
| 79 pile.SetRecordedViewport(gfx::Rect(size)); | 84 pile.SetRecordedViewport(gfx::Rect(size)); |
| 80 pile.SetHasAnyRecordings(true); | 85 pile.SetHasAnyRecordings(true); |
| 81 | 86 |
| 82 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile)); | 87 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile, nullptr)); |
| 83 pile_impl->AddRecordingAt(0, 0); | 88 pile_impl->AddRecordingAt(0, 0); |
| 84 return pile_impl; | 89 return pile_impl; |
| 85 } | 90 } |
| 86 | 91 |
| 92 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFromPile( |
| 93 const PicturePile* other, |
| 94 base::WaitableEvent* playback_allowed_event) { |
| 95 return make_scoped_refptr( |
| 96 new FakePicturePileImpl(other, playback_allowed_event)); |
| 97 } |
| 98 |
| 99 void FakePicturePileImpl::PlaybackToCanvas(SkCanvas* canvas, |
| 100 const gfx::Rect& canvas_rect, |
| 101 float contents_scale) const { |
| 102 if (playback_allowed_event_) |
| 103 playback_allowed_event_->Wait(); |
| 104 PicturePileImpl::PlaybackToCanvas(canvas, canvas_rect, contents_scale); |
| 105 } |
| 106 |
| 87 void FakePicturePileImpl::AddRecordingAt(int x, int y) { | 107 void FakePicturePileImpl::AddRecordingAt(int x, int y) { |
| 88 EXPECT_GE(x, 0); | 108 EXPECT_GE(x, 0); |
| 89 EXPECT_GE(y, 0); | 109 EXPECT_GE(y, 0); |
| 90 EXPECT_LT(x, tiling_.num_tiles_x()); | 110 EXPECT_LT(x, tiling_.num_tiles_x()); |
| 91 EXPECT_LT(y, tiling_.num_tiles_y()); | 111 EXPECT_LT(y, tiling_.num_tiles_y()); |
| 92 | 112 |
| 93 if (HasRecordingAt(x, y)) | 113 if (HasRecordingAt(x, y)) |
| 94 return; | 114 return; |
| 95 gfx::Rect bounds(tiling().TileBounds(x, y)); | 115 gfx::Rect bounds(tiling().TileBounds(x, y)); |
| 96 bounds.Inset(-buffer_pixels(), -buffer_pixels()); | 116 bounds.Inset(-buffer_pixels(), -buffer_pixels()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 Clear(); | 178 Clear(); |
| 159 tiling_.SetBorderTexels(new_buffer_pixels); | 179 tiling_.SetBorderTexels(new_buffer_pixels); |
| 160 } | 180 } |
| 161 | 181 |
| 162 void FakePicturePileImpl::Clear() { | 182 void FakePicturePileImpl::Clear() { |
| 163 picture_map_.clear(); | 183 picture_map_.clear(); |
| 164 recorded_viewport_ = gfx::Rect(); | 184 recorded_viewport_ = gfx::Rect(); |
| 165 } | 185 } |
| 166 | 186 |
| 167 } // namespace cc | 187 } // namespace cc |
| OLD | NEW |