Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: cc/picture_layer_impl_unittest.cc

Issue 12221077: Fixing tile grid size used by cc:Picture to make it respect current tile configuration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: response to comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/picture_layer_impl.h" 5 #include "cc/picture_layer_impl.h"
6 6
7 #include "cc/layer_tree_impl.h" 7 #include "cc/layer_tree_impl.h"
8 #include "cc/picture_layer.h"
8 #include "cc/test/fake_content_layer_client.h" 9 #include "cc/test/fake_content_layer_client.h"
9 #include "cc/test/fake_impl_proxy.h" 10 #include "cc/test/fake_impl_proxy.h"
10 #include "cc/test/fake_layer_tree_host_impl.h" 11 #include "cc/test/fake_layer_tree_host_impl.h"
11 #include "cc/test/fake_output_surface.h" 12 #include "cc/test/fake_output_surface.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/rect_conversions.h" 14 #include "ui/gfx/rect_conversions.h"
14 15
15 namespace cc { 16 namespace cc {
16 namespace { 17 namespace {
17 18
(...skipping 26 matching lines...) Expand all
44 LayerTreeImpl* treeImpl, 45 LayerTreeImpl* treeImpl,
45 int id, 46 int id,
46 scoped_refptr<PicturePileImpl> pile) 47 scoped_refptr<PicturePileImpl> pile)
47 : PictureLayerImpl(treeImpl, id) { 48 : PictureLayerImpl(treeImpl, id) {
48 pile_ = pile; 49 pile_ = pile;
49 setBounds(pile_->size()); 50 setBounds(pile_->size());
50 CreateTilingSet(); 51 CreateTilingSet();
51 } 52 }
52 }; 53 };
53 54
55 class ImplSidePaintingSettings : public LayerTreeSettings {
56 public:
57 ImplSidePaintingSettings() {
58 implSidePainting = true;
59 }
60 };
61
54 class TestablePicturePileImpl : public PicturePileImpl { 62 class TestablePicturePileImpl : public PicturePileImpl {
55 public: 63 public:
56 static scoped_refptr<TestablePicturePileImpl> CreateFilledPile( 64 static scoped_refptr<TestablePicturePileImpl> CreateFilledPile(
57 gfx::Size tile_size, 65 gfx::Size tile_size,
58 gfx::Size layer_bounds) { 66 gfx::Size layer_bounds) {
59 scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl()); 67 scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl());
60 pile->tiling().SetTotalSize(layer_bounds); 68 pile->tiling().SetTotalSize(layer_bounds);
61 pile->tiling().SetMaxTextureSize(tile_size); 69 pile->tiling().SetMaxTextureSize(tile_size);
70 pile->ApplyLayerTreeSettings(ImplSidePaintingSettings());
62 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) { 71 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) {
63 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y) 72 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y)
64 pile->AddRecordingAt(x, y); 73 pile->AddRecordingAt(x, y);
65 } 74 }
66 pile->UpdateRecordedRegion(); 75 pile->UpdateRecordedRegion();
67 return pile; 76 return pile;
68 } 77 }
69 78
70 static scoped_refptr<TestablePicturePileImpl> CreateEmptyPile( 79 static scoped_refptr<TestablePicturePileImpl> CreateEmptyPile(
71 gfx::Size tile_size, 80 gfx::Size tile_size,
72 gfx::Size layer_bounds) { 81 gfx::Size layer_bounds) {
73 scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl()); 82 scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl());
74 pile->tiling().SetTotalSize(layer_bounds); 83 pile->tiling().SetTotalSize(layer_bounds);
75 pile->tiling().SetMaxTextureSize(tile_size); 84 pile->tiling().SetMaxTextureSize(tile_size);
85 pile->ApplyLayerTreeSettings(ImplSidePaintingSettings());
76 pile->UpdateRecordedRegion(); 86 pile->UpdateRecordedRegion();
77 return pile; 87 return pile;
78 } 88 }
79 89
80 TilingData& tiling() { return tiling_; } 90 TilingData& tiling() { return tiling_; }
81 91
82 void AddRecordingAt(int x, int y) { 92 void AddRecordingAt(int x, int y) {
83 EXPECT_GE(x, 0); 93 EXPECT_GE(x, 0);
84 EXPECT_GE(y, 0); 94 EXPECT_GE(y, 0);
85 EXPECT_LT(x, tiling_.num_tiles_x()); 95 EXPECT_LT(x, tiling_.num_tiles_x());
86 EXPECT_LT(y, tiling_.num_tiles_y()); 96 EXPECT_LT(y, tiling_.num_tiles_y());
87 97
88 if (HasRecordingAt(x, y)) 98 if (HasRecordingAt(x, y))
89 return; 99 return;
90 gfx::Rect bounds(tiling().TileBounds(x, y)); 100 gfx::Rect bounds(tiling().TileBounds(x, y));
91 scoped_refptr<Picture> picture(Picture::Create(bounds)); 101 scoped_refptr<Picture> picture(Picture::Create(bounds));
92 FakeContentLayerClient client; 102 picture->Record(&client_, NULL, tile_grid_info_);
93 picture->Record(&client, NULL);
94 picture_list_map_[std::pair<int, int>(x, y)].push_back(picture); 103 picture_list_map_[std::pair<int, int>(x, y)].push_back(picture);
95 EXPECT_TRUE(HasRecordingAt(x, y)); 104 EXPECT_TRUE(HasRecordingAt(x, y));
96 105
97 UpdateRecordedRegion(); 106 UpdateRecordedRegion();
98 } 107 }
99 108
100 void RemoveRecordingAt(int x, int y) { 109 void RemoveRecordingAt(int x, int y) {
101 EXPECT_GE(x, 0); 110 EXPECT_GE(x, 0);
102 EXPECT_GE(y, 0); 111 EXPECT_GE(y, 0);
103 EXPECT_LT(x, tiling_.num_tiles_x()); 112 EXPECT_LT(x, tiling_.num_tiles_x());
104 EXPECT_LT(y, tiling_.num_tiles_y()); 113 EXPECT_LT(y, tiling_.num_tiles_y());
105 114
106 if (!HasRecordingAt(x, y)) 115 if (!HasRecordingAt(x, y))
107 return; 116 return;
108 picture_list_map_.erase(std::pair<int, int>(x, y)); 117 picture_list_map_.erase(std::pair<int, int>(x, y));
109 EXPECT_FALSE(HasRecordingAt(x, y)); 118 EXPECT_FALSE(HasRecordingAt(x, y));
110 119
111 UpdateRecordedRegion(); 120 UpdateRecordedRegion();
112 } 121 }
113 122
123 void addDrawRect(const gfx::Rect& rect) {
124 client_.addDrawRect(rect);
125 }
126
114 protected: 127 protected:
115 virtual ~TestablePicturePileImpl() { 128 virtual ~TestablePicturePileImpl() {
116 } 129 }
130
131 FakeContentLayerClient client_;
117 }; 132 };
118 133
119 class ImplSidePaintingSettings : public LayerTreeSettings { 134 class MockCanvas : public SkCanvas {
120 public: 135 public:
121 ImplSidePaintingSettings() { 136 explicit MockCanvas(SkDevice* device) : SkCanvas(device) { }
122 implSidePainting = true; 137
138 virtual void drawRect(const SkRect& rect, const SkPaint& paint) {
139 // Capture calls before SkCanvas quickReject kicks in
140 rects_.push_back(rect);
123 } 141 }
142
143 std::vector<SkRect> rects_;
124 }; 144 };
125 145
126 class PictureLayerImplTest : public testing::Test { 146 class PictureLayerImplTest : public testing::Test {
127 public: 147 public:
128 PictureLayerImplTest() 148 PictureLayerImplTest()
129 : host_impl_(ImplSidePaintingSettings(), &proxy_), 149 : host_impl_(ImplSidePaintingSettings(), &proxy_),
130 id_(7) { 150 id_(7) {
131 host_impl_.initializeRenderer(createFakeOutputSurface()); 151 host_impl_.initializeRenderer(createFakeOutputSurface());
132 } 152 }
133 153
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 gfx::Size result_bounds; 207 gfx::Size result_bounds;
188 pending_layer_->calculateContentsScale( 208 pending_layer_->calculateContentsScale(
189 scale, animating_transform, 209 scale, animating_transform,
190 &result_scale_x, &result_scale_y, &result_bounds); 210 &result_scale_x, &result_scale_y, &result_bounds);
191 active_layer_->calculateContentsScale( 211 active_layer_->calculateContentsScale(
192 scale, animating_transform, 212 scale, animating_transform,
193 &result_scale_x, &result_scale_y, &result_bounds); 213 &result_scale_x, &result_scale_y, &result_bounds);
194 } 214 }
195 215
196 protected: 216 protected:
217 void TestTileGridAlignmentCommon() {
218 // Layer to span 4 raster tiles in x and in y
219 ImplSidePaintingSettings settings;
220 gfx::Size layer_size(
221 settings.defaultTileSize.width() * 7 / 2,
222 settings.defaultTileSize.height() * 7 / 2);
223
224 scoped_refptr<TestablePicturePileImpl> pending_pile =
225 TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size);
226 scoped_refptr<TestablePicturePileImpl> active_pile =
227 TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size);
228
229 SetupTrees(pending_pile, active_pile);
230
231 host_impl_.activeTree()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f);
232 float result_scale_x, result_scale_y;
233 gfx::Size result_bounds;
234 active_layer_->calculateContentsScale(
235 1.f, false, &result_scale_x, &result_scale_y, &result_bounds);
236
237 // Add 1x1 rects at the centers of each tile, then re-record pile contents
238 std::vector<Tile*> tiles =
239 active_layer_->tilings().tiling_at(0)->AllTilesForTesting();
240 EXPECT_EQ(16, tiles.size());
241 std::vector<SkRect> rects;
242 std::vector<Tile*>::const_iterator tile_iter;
243 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
244 gfx::Point tile_center = (*tile_iter)->content_rect().CenterPoint();
245 gfx::Rect rect(tile_center.x(), tile_center.y(), 1, 1);
246 active_pile->addDrawRect(rect);
247 rects.push_back(SkRect::MakeXYWH(rect.x(), rect.y(), 1, 1));
248 }
249 // Force re-record with newly injected content
250 active_pile->RemoveRecordingAt(0, 0);
251 active_pile->AddRecordingAt(0, 0);
252
253 SkBitmap store;
254 store.setConfig(SkBitmap::kNo_Config, 1000, 1000);
255 SkDevice device(store);
256 int64 pixelsRasterized;
257
258 std::vector<SkRect>::const_iterator rect_iter = rects.begin();
259 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) {
260 MockCanvas mock_canvas(&device);
261 active_pile->Raster(&mock_canvas, (*tile_iter)->content_rect(),
262 1.0f, &pixelsRasterized);
263
264 // This test verifies that when drawing the contents of a specific tile
265 // at content scale 1.0, the playback canvas never receives content from
266 // neighboring tiles which indicates that the tile grid embedded in
267 // SkPicture is perfectly aligned with the compositor's tiles.
268 // Note: There are two rects: the initial clear and the explicitly
269 // recorded rect. We only care about the second one.
270 EXPECT_EQ(2, mock_canvas.rects_.size());
271 EXPECT_EQ(*rect_iter, mock_canvas.rects_[1]);
272 rect_iter++;
273 }
274 }
275
197 FakeImplProxy proxy_; 276 FakeImplProxy proxy_;
198 FakeLayerTreeHostImpl host_impl_; 277 FakeLayerTreeHostImpl host_impl_;
199 int id_; 278 int id_;
200 TestablePictureLayerImpl* pending_layer_; 279 TestablePictureLayerImpl* pending_layer_;
201 TestablePictureLayerImpl* active_layer_; 280 TestablePictureLayerImpl* active_layer_;
202 281
203 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); 282 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
204 }; 283 };
205 284
285 TEST_F(PictureLayerImplTest, tileGridAlignment) {
286 host_impl_.setDeviceScaleFactor(1.f);
287 TestTileGridAlignmentCommon();
288 }
289
290 TEST_F(PictureLayerImplTest, tileGridAlignmentHiDPI) {
291 host_impl_.setDeviceScaleFactor(2.f);
292 TestTileGridAlignmentCommon();
293 }
294
206 TEST_F(PictureLayerImplTest, cloneNoInvalidation) { 295 TEST_F(PictureLayerImplTest, cloneNoInvalidation) {
207 gfx::Size tile_size(100, 100); 296 gfx::Size tile_size(100, 100);
208 gfx::Size layer_bounds(400, 400); 297 gfx::Size layer_bounds(400, 400);
209 298
210 scoped_refptr<TestablePicturePileImpl> pending_pile = 299 scoped_refptr<TestablePicturePileImpl> pending_pile =
211 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 300 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
212 scoped_refptr<TestablePicturePileImpl> active_pile = 301 scoped_refptr<TestablePicturePileImpl> active_pile =
213 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 302 TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
214 303
215 SetupTrees(pending_pile, active_pile); 304 SetupTrees(pending_pile, active_pile);
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 692 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
604 ASSERT_EQ(3u, active_layer_->tilings().num_tilings()); 693 ASSERT_EQ(3u, active_layer_->tilings().num_tilings());
605 used_tilings.clear(); 694 used_tilings.clear();
606 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings); 695 active_layer_->CleanUpTilingsOnActiveLayer(used_tilings);
607 ASSERT_EQ(2u, active_layer_->tilings().num_tilings()); 696 ASSERT_EQ(2u, active_layer_->tilings().num_tilings());
608 697
609 } 698 }
610 699
611 } // namespace 700 } // namespace
612 } // namespace cc 701 } // namespace cc
OLDNEW
« no previous file with comments | « cc/picture_layer.cc ('k') | cc/picture_pile.cc » ('j') | cc/picture_pile_base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698