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

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 974603002: Remove unittests based on wrong assumption of compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // LayerDelegate that paints colors to the layer. 211 // LayerDelegate that paints colors to the layer.
212 class TestLayerDelegate : public LayerDelegate { 212 class TestLayerDelegate : public LayerDelegate {
213 public: 213 public:
214 explicit TestLayerDelegate() { reset(); } 214 explicit TestLayerDelegate() { reset(); }
215 ~TestLayerDelegate() override {} 215 ~TestLayerDelegate() override {}
216 216
217 void AddColor(SkColor color) { 217 void AddColor(SkColor color) {
218 colors_.push_back(color); 218 colors_.push_back(color);
219 } 219 }
220 220
221 const gfx::Size& paint_size() const { return paint_size_; }
222 int color_index() const { return color_index_; } 221 int color_index() const { return color_index_; }
223 222
224 std::string ToScaleString() const {
225 return base::StringPrintf("%.1f %.1f", scale_x_, scale_y_);
226 }
227
228 float device_scale_factor() const { 223 float device_scale_factor() const {
229 return device_scale_factor_; 224 return device_scale_factor_;
230 } 225 }
231 226
232 // Overridden from LayerDelegate: 227 // Overridden from LayerDelegate:
233 void OnPaintLayer(gfx::Canvas* canvas) override { 228 void OnPaintLayer(gfx::Canvas* canvas) override {
234 SkISize size = canvas->sk_canvas()->getBaseLayerSize();
235 paint_size_ = gfx::Size(size.width(), size.height());
236 canvas->DrawColor(colors_[color_index_]); 229 canvas->DrawColor(colors_[color_index_]);
237 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size()); 230 color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
238 const SkMatrix& matrix = canvas->sk_canvas()->getTotalMatrix();
239 scale_x_ = matrix.getScaleX();
240 scale_y_ = matrix.getScaleY();
241 } 231 }
242 232
243 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} 233 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
244 234
245 void OnDeviceScaleFactorChanged(float device_scale_factor) override { 235 void OnDeviceScaleFactorChanged(float device_scale_factor) override {
246 device_scale_factor_ = device_scale_factor; 236 device_scale_factor_ = device_scale_factor;
247 } 237 }
248 238
249 base::Closure PrepareForLayerBoundsChange() override { 239 base::Closure PrepareForLayerBoundsChange() override {
250 return base::Closure(); 240 return base::Closure();
251 } 241 }
252 242
253 void reset() { 243 void reset() {
254 color_index_ = 0; 244 color_index_ = 0;
255 paint_size_.SetSize(0, 0);
256 scale_x_ = scale_y_ = 0.0f;
257 device_scale_factor_ = 0.0f; 245 device_scale_factor_ = 0.0f;
258 } 246 }
259 247
260 private: 248 private:
261 std::vector<SkColor> colors_; 249 std::vector<SkColor> colors_;
262 int color_index_; 250 int color_index_;
263 gfx::Size paint_size_;
264 float scale_x_;
265 float scale_y_;
266 float device_scale_factor_; 251 float device_scale_factor_;
267 252
268 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate); 253 DISALLOW_COPY_AND_ASSIGN(TestLayerDelegate);
269 }; 254 };
270 255
271 // LayerDelegate that verifies that a layer was asked to update its canvas. 256 // LayerDelegate that verifies that a layer was asked to update its canvas.
272 class DrawTreeLayerDelegate : public LayerDelegate { 257 class DrawTreeLayerDelegate : public LayerDelegate {
273 public: 258 public:
274 DrawTreeLayerDelegate() : painted_(false) {} 259 DrawTreeLayerDelegate() : painted_(false) {}
275 ~DrawTreeLayerDelegate() override {} 260 ~DrawTreeLayerDelegate() override {}
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 gfx::Point point1_in_l1_coords(25, 25); 487 gfx::Point point1_in_l1_coords(25, 25);
503 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords); 488 EXPECT_EQ(point1_in_l1_coords, point1_in_l3_coords);
504 489
505 gfx::Point point2_in_l1_coords(5, 5); 490 gfx::Point point2_in_l1_coords(5, 5);
506 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords); 491 Layer::ConvertPointToLayer(l1.get(), l3.get(), &point2_in_l1_coords);
507 gfx::Point point2_in_l3_coords(-15, -15); 492 gfx::Point point2_in_l3_coords(-15, -15);
508 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); 493 EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords);
509 } 494 }
510 495
511 TEST_F(LayerWithRealCompositorTest, Delegate) { 496 TEST_F(LayerWithRealCompositorTest, Delegate) {
512 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, 497 scoped_ptr<Layer> l1(
513 gfx::Rect(20, 20, 400, 400))); 498 CreateColorLayer(SK_ColorBLACK, gfx::Rect(20, 20, 400, 400)));
514 GetCompositor()->SetRootLayer(l1.get()); 499 GetCompositor()->SetRootLayer(l1.get());
515 WaitForDraw(); 500 WaitForDraw();
516 501
517 TestLayerDelegate delegate; 502 TestLayerDelegate delegate;
518 l1->set_delegate(&delegate); 503 l1->set_delegate(&delegate);
519 delegate.AddColor(SK_ColorWHITE); 504 delegate.AddColor(SK_ColorWHITE);
520 delegate.AddColor(SK_ColorYELLOW); 505 delegate.AddColor(SK_ColorYELLOW);
521 delegate.AddColor(SK_ColorGREEN); 506 delegate.AddColor(SK_ColorGREEN);
522 507
523 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400)); 508 l1->SchedulePaint(gfx::Rect(0, 0, 400, 400));
524 WaitForDraw(); 509 WaitForDraw();
525 510
526 EXPECT_EQ(delegate.color_index(), 1); 511 EXPECT_EQ(1, delegate.color_index());
527 EXPECT_EQ(delegate.paint_size(), l1->bounds().size());
sky 2015/03/06 23:32:08 It's still good to check the paint regions. Can yo
danakj 2015/03/07 00:02:36 I think a test that verifies invalidating X gets b
sky 2015/03/09 15:38:42 Isn't this verified the paint makes it through to
weiliangc 2015/03/09 16:54:03 |color_index| is updated when paint makes it throu
528 512
529 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200)); 513 l1->SchedulePaint(gfx::Rect(10, 10, 200, 200));
530 WaitForDraw(); 514 WaitForDraw();
531 EXPECT_EQ(delegate.color_index(), 2); 515 EXPECT_EQ(2, delegate.color_index());
532 EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200));
533 516
534 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50)); 517 l1->SchedulePaint(gfx::Rect(5, 5, 50, 50));
535 WaitForDraw(); 518 WaitForDraw();
536 EXPECT_EQ(delegate.color_index(), 0); 519 EXPECT_EQ(0, delegate.color_index());
537 EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
538 } 520 }
539 521
540 TEST_F(LayerWithRealCompositorTest, DrawTree) { 522 TEST_F(LayerWithRealCompositorTest, DrawTree) {
541 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, 523 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
542 gfx::Rect(20, 20, 400, 400))); 524 gfx::Rect(20, 20, 400, 400)));
543 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, 525 scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
544 gfx::Rect(10, 10, 350, 350))); 526 gfx::Rect(10, 10, 350, 350)));
545 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW, 527 scoped_ptr<Layer> l3(CreateColorLayer(SK_ColorYELLOW,
546 gfx::Rect(10, 10, 100, 100))); 528 gfx::Rect(10, 10, 100, 100)));
547 l1->Add(l2.get()); 529 l1->Add(l2.get());
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1283 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1302 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1284 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1303 gfx::Size cc_bounds_size = root->cc_layer()->bounds(); 1285 gfx::Size cc_bounds_size = root->cc_layer()->bounds();
1304 EXPECT_EQ("200x220", cc_bounds_size.ToString()); 1286 EXPECT_EQ("200x220", cc_bounds_size.ToString());
1305 cc_bounds_size = l1->cc_layer()->bounds(); 1287 cc_bounds_size = l1->cc_layer()->bounds();
1306 EXPECT_EQ("140x180", cc_bounds_size.ToString()); 1288 EXPECT_EQ("140x180", cc_bounds_size.ToString());
1307 // No scale change, so no scale notification. 1289 // No scale change, so no scale notification.
1308 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); 1290 EXPECT_EQ(0.0f, root_delegate.device_scale_factor());
1309 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1291 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1310 1292
1311 EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
1312 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1313
1314 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP. 1293 // Scale up to 2.0. Changing scale doesn't change the bounds in DIP.
1315 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); 1294 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
1316 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1295 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1317 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1296 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1318 // CC layer should still match the UI layer bounds. 1297 // CC layer should still match the UI layer bounds.
1319 cc_bounds_size = root->cc_layer()->bounds(); 1298 cc_bounds_size = root->cc_layer()->bounds();
1320 EXPECT_EQ("200x220", cc_bounds_size.ToString()); 1299 EXPECT_EQ("200x220", cc_bounds_size.ToString());
1321 cc_bounds_size = l1->cc_layer()->bounds(); 1300 cc_bounds_size = l1->cc_layer()->bounds();
1322 EXPECT_EQ("140x180", cc_bounds_size.ToString()); 1301 EXPECT_EQ("140x180", cc_bounds_size.ToString());
1323 // New scale factor must have been notified. 1302 // New scale factor must have been notified. Make sure painting happens at
1303 // right scale.
1324 EXPECT_EQ(2.0f, root_delegate.device_scale_factor()); 1304 EXPECT_EQ(2.0f, root_delegate.device_scale_factor());
1325 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); 1305 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor());
1326 1306
1327 // Canvas size must have been scaled down up.
1328 WaitForDraw();
1329 EXPECT_EQ("400x440", root_delegate.paint_size().ToString());
1330 EXPECT_EQ("2.0 2.0", root_delegate.ToScaleString());
1331 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
1332 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
1333
1334 // Scale down back to 1.0f. 1307 // Scale down back to 1.0f.
1335 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1308 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1336 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1309 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1337 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1310 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1338 // CC layer should still match the UI layer bounds. 1311 // CC layer should still match the UI layer bounds.
1339 cc_bounds_size = root->cc_layer()->bounds(); 1312 cc_bounds_size = root->cc_layer()->bounds();
1340 EXPECT_EQ("200x220", cc_bounds_size.ToString()); 1313 EXPECT_EQ("200x220", cc_bounds_size.ToString());
1341 cc_bounds_size = l1->cc_layer()->bounds(); 1314 cc_bounds_size = l1->cc_layer()->bounds();
1342 EXPECT_EQ("140x180", cc_bounds_size.ToString()); 1315 EXPECT_EQ("140x180", cc_bounds_size.ToString());
1343 // New scale factor must have been notified. 1316 // New scale factor must have been notified. Make sure painting happens at
1317 // right scale.
1344 EXPECT_EQ(1.0f, root_delegate.device_scale_factor()); 1318 EXPECT_EQ(1.0f, root_delegate.device_scale_factor());
1345 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor()); 1319 EXPECT_EQ(1.0f, l1_delegate.device_scale_factor());
1346 1320
1347 // Canvas size must have been scaled down too.
1348 WaitForDraw();
1349 EXPECT_EQ("200x220", root_delegate.paint_size().ToString());
1350 EXPECT_EQ("1.0 1.0", root_delegate.ToScaleString());
1351 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1352 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
1353
1354 root_delegate.reset(); 1321 root_delegate.reset();
1355 l1_delegate.reset(); 1322 l1_delegate.reset();
1356 // Just changing the size shouldn't notify the scale change nor 1323 // Just changing the size shouldn't notify the scale change nor
1357 // trigger repaint. 1324 // trigger repaint.
1358 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); 1325 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(1000, 1000));
1359 // No scale change, so no scale notification. 1326 // No scale change, so no scale notification.
1360 EXPECT_EQ(0.0f, root_delegate.device_scale_factor()); 1327 EXPECT_EQ(0.0f, root_delegate.device_scale_factor());
1361 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1328 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1362 WaitForDraw();
1363 EXPECT_EQ("0x0", root_delegate.paint_size().ToString());
1364 EXPECT_EQ("0.0 0.0", root_delegate.ToScaleString());
1365 EXPECT_EQ("0x0", l1_delegate.paint_size().ToString());
1366 EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString());
1367 } 1329 }
1368 1330
1369 TEST_F(LayerWithRealCompositorTest, ScaleReparent) { 1331 TEST_F(LayerWithRealCompositorTest, ScaleReparent) {
1370 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, 1332 scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE,
1371 gfx::Rect(10, 20, 200, 220))); 1333 gfx::Rect(10, 20, 200, 220)));
1372 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, 1334 scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE,
1373 gfx::Rect(10, 20, 140, 180))); 1335 gfx::Rect(10, 20, 140, 180)));
1374 TestLayerDelegate l1_delegate; 1336 TestLayerDelegate l1_delegate;
1375 l1_delegate.AddColor(SK_ColorWHITE); 1337 l1_delegate.AddColor(SK_ColorWHITE);
1376 l1->set_delegate(&l1_delegate); 1338 l1->set_delegate(&l1_delegate);
1377 1339
1378 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500)); 1340 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(500, 500));
1379 GetCompositor()->SetRootLayer(root.get()); 1341 GetCompositor()->SetRootLayer(root.get());
1380 WaitForDraw();
1381 1342
1382 root->Add(l1.get()); 1343 root->Add(l1.get());
1383 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1344 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1384 gfx::Size cc_bounds_size = l1->cc_layer()->bounds(); 1345 gfx::Size cc_bounds_size = l1->cc_layer()->bounds();
1385 EXPECT_EQ("140x180", cc_bounds_size.ToString()); 1346 EXPECT_EQ("140x180", cc_bounds_size.ToString());
1386 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor()); 1347 EXPECT_EQ(0.0f, l1_delegate.device_scale_factor());
1387 1348
1388 WaitForDraw();
1389 EXPECT_EQ("140x180", l1_delegate.paint_size().ToString());
1390 EXPECT_EQ("1.0 1.0", l1_delegate.ToScaleString());
1391
1392 // Remove l1 from root and change the scale. 1349 // Remove l1 from root and change the scale.
1393 root->Remove(l1.get()); 1350 root->Remove(l1.get());
1394 EXPECT_EQ(NULL, l1->parent()); 1351 EXPECT_EQ(NULL, l1->parent());
1395 EXPECT_EQ(NULL, l1->GetCompositor()); 1352 EXPECT_EQ(NULL, l1->GetCompositor());
1396 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500)); 1353 GetCompositor()->SetScaleAndSize(2.0f, gfx::Size(500, 500));
1397 // Sanity check on root and l1. 1354 // Sanity check on root and l1.
1398 EXPECT_EQ("10,20 200x220", root->bounds().ToString()); 1355 EXPECT_EQ("10,20 200x220", root->bounds().ToString());
1399 cc_bounds_size = l1->cc_layer()->bounds(); 1356 cc_bounds_size = l1->cc_layer()->bounds();
1400 EXPECT_EQ("140x180", cc_bounds_size.ToString()); 1357 EXPECT_EQ("140x180", cc_bounds_size.ToString());
1401 1358
1402 root->Add(l1.get()); 1359 root->Add(l1.get());
1403 EXPECT_EQ("10,20 140x180", l1->bounds().ToString()); 1360 EXPECT_EQ("10,20 140x180", l1->bounds().ToString());
1404 cc_bounds_size = l1->cc_layer()->bounds(); 1361 cc_bounds_size = l1->cc_layer()->bounds();
1405 EXPECT_EQ("140x180", cc_bounds_size.ToString()); 1362 EXPECT_EQ("140x180", cc_bounds_size.ToString());
1406 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor()); 1363 EXPECT_EQ(2.0f, l1_delegate.device_scale_factor());
1407 WaitForDraw();
1408 EXPECT_EQ("280x360", l1_delegate.paint_size().ToString());
1409 EXPECT_EQ("2.0 2.0", l1_delegate.ToScaleString());
1410 } 1364 }
1411 1365
1412 // Verifies that when changing bounds on a layer that is invisible, and then 1366 // Verifies that when changing bounds on a layer that is invisible, and then
1413 // made visible, the right thing happens: 1367 // made visible, the right thing happens:
1414 // - if just a move, then no painting should happen. 1368 // - if just a move, then no painting should happen.
1415 // - if a resize, the layer should be repainted. 1369 // - if a resize, the layer should be repainted.
1416 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) { 1370 TEST_F(LayerWithDelegateTest, SetBoundsWhenInvisible) {
1417 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000))); 1371 scoped_ptr<Layer> root(CreateNoTextureLayer(gfx::Rect(0, 0, 1000, 1000)));
1418 1372
1419 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED)); 1373 scoped_ptr<Layer> child(CreateLayer(LAYER_TEXTURED));
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 MakeFrameData(gfx::Size(10, 10)))); 1720 MakeFrameData(gfx::Size(10, 10))));
1767 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); 1721 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10));
1768 1722
1769 EXPECT_FALSE(delegate.delegated_frame_damage_called()); 1723 EXPECT_FALSE(delegate.delegated_frame_damage_called());
1770 layer->OnDelegatedFrameDamage(damage_rect); 1724 layer->OnDelegatedFrameDamage(damage_rect);
1771 EXPECT_TRUE(delegate.delegated_frame_damage_called()); 1725 EXPECT_TRUE(delegate.delegated_frame_damage_called());
1772 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); 1726 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect());
1773 } 1727 }
1774 1728
1775 } // namespace ui 1729 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698