| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layers/tiled_layer.h" | 5 #include "cc/layers/tiled_layer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 gfx::Rect(layer->content_bounds()); | 1448 gfx::Rect(layer->content_bounds()); |
| 1449 layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600)); | 1449 layer->InvalidateContentRect(gfx::Rect(0, 0, 600, 600)); |
| 1450 layer->SetTexturePriorities(priority_calculator_); | 1450 layer->SetTexturePriorities(priority_calculator_); |
| 1451 resource_manager_->PrioritizeTextures(); | 1451 resource_manager_->PrioritizeTextures(); |
| 1452 layer->SavePaintProperties(); | 1452 layer->SavePaintProperties(); |
| 1453 layer->Update(queue_.get(), &occluded); | 1453 layer->Update(queue_.get(), &occluded); |
| 1454 int visible_tiles3 = 6 * 6 - 6; | 1454 int visible_tiles3 = 6 * 6 - 6; |
| 1455 EXPECT_EQ(visible_tiles3, layer->fake_layer_updater()->update_count()); | 1455 EXPECT_EQ(visible_tiles3, layer->fake_layer_updater()->update_count()); |
| 1456 } | 1456 } |
| 1457 | 1457 |
| 1458 TEST_F(TiledLayerTest, VisibleContentOpaqueRegion) { | |
| 1459 scoped_refptr<FakeTiledLayer> layer = | |
| 1460 make_scoped_refptr(new FakeTiledLayer(resource_manager_.get())); | |
| 1461 RenderSurfaceLayerList render_surface_layer_list; | |
| 1462 TestOcclusionTracker occluded; | |
| 1463 occlusion_ = &occluded; | |
| 1464 layer_tree_host_->SetViewportSize(gfx::Size(1000, 1000)); | |
| 1465 | |
| 1466 layer_tree_host_->root_layer()->AddChild(layer); | |
| 1467 | |
| 1468 // The tile size is 100x100, so this invalidates and then paints two tiles in | |
| 1469 // various ways. | |
| 1470 | |
| 1471 gfx::Rect opaque_paint_rect; | |
| 1472 SimpleEnclosedRegion opaque_contents; | |
| 1473 | |
| 1474 gfx::Rect content_bounds = gfx::Rect(0, 0, 100, 200); | |
| 1475 gfx::Rect visible_bounds = gfx::Rect(0, 0, 100, 150); | |
| 1476 | |
| 1477 layer->SetBounds(content_bounds.size()); | |
| 1478 CalcDrawProps(&render_surface_layer_list); | |
| 1479 layer->draw_properties().drawable_content_rect = visible_bounds; | |
| 1480 layer->draw_properties().visible_content_rect = visible_bounds; | |
| 1481 | |
| 1482 // If the layer doesn't paint opaque content, then the | |
| 1483 // VisibleContentOpaqueRegion should be empty. | |
| 1484 layer->fake_layer_updater()->SetOpaquePaintRect(gfx::Rect()); | |
| 1485 layer->InvalidateContentRect(content_bounds); | |
| 1486 layer->SetTexturePriorities(priority_calculator_); | |
| 1487 resource_manager_->PrioritizeTextures(); | |
| 1488 layer->SavePaintProperties(); | |
| 1489 layer->Update(queue_.get(), &occluded); | |
| 1490 opaque_contents = layer->VisibleContentOpaqueRegion(); | |
| 1491 EXPECT_TRUE(opaque_contents.IsEmpty()); | |
| 1492 | |
| 1493 // VisibleContentOpaqueRegion should match the visible part of what is painted | |
| 1494 // opaque. | |
| 1495 opaque_paint_rect = gfx::Rect(10, 10, 90, 190); | |
| 1496 layer->fake_layer_updater()->SetOpaquePaintRect(opaque_paint_rect); | |
| 1497 layer->InvalidateContentRect(content_bounds); | |
| 1498 layer->SetTexturePriorities(priority_calculator_); | |
| 1499 resource_manager_->PrioritizeTextures(); | |
| 1500 layer->SavePaintProperties(); | |
| 1501 layer->Update(queue_.get(), &occluded); | |
| 1502 UpdateTextures(); | |
| 1503 opaque_contents = layer->VisibleContentOpaqueRegion(); | |
| 1504 EXPECT_EQ(gfx::IntersectRects(opaque_paint_rect, visible_bounds).ToString(), | |
| 1505 opaque_contents.ToString()); | |
| 1506 | |
| 1507 // If we paint again without invalidating, the same stuff should be opaque. | |
| 1508 layer->fake_layer_updater()->SetOpaquePaintRect(gfx::Rect()); | |
| 1509 layer->SetTexturePriorities(priority_calculator_); | |
| 1510 resource_manager_->PrioritizeTextures(); | |
| 1511 layer->SavePaintProperties(); | |
| 1512 layer->Update(queue_.get(), &occluded); | |
| 1513 UpdateTextures(); | |
| 1514 opaque_contents = layer->VisibleContentOpaqueRegion(); | |
| 1515 EXPECT_EQ(gfx::IntersectRects(opaque_paint_rect, visible_bounds).ToString(), | |
| 1516 opaque_contents.ToString()); | |
| 1517 | |
| 1518 // If we repaint a non-opaque part of the tile, then it shouldn't lose its | |
| 1519 // opaque-ness. And other tiles should not be affected. | |
| 1520 layer->fake_layer_updater()->SetOpaquePaintRect(gfx::Rect()); | |
| 1521 layer->InvalidateContentRect(gfx::Rect(0, 0, 1, 1)); | |
| 1522 layer->SetTexturePriorities(priority_calculator_); | |
| 1523 resource_manager_->PrioritizeTextures(); | |
| 1524 layer->SavePaintProperties(); | |
| 1525 layer->Update(queue_.get(), &occluded); | |
| 1526 UpdateTextures(); | |
| 1527 opaque_contents = layer->VisibleContentOpaqueRegion(); | |
| 1528 EXPECT_EQ(gfx::IntersectRects(opaque_paint_rect, visible_bounds).ToString(), | |
| 1529 opaque_contents.ToString()); | |
| 1530 | |
| 1531 // If we repaint an opaque part of the tile, then it should lose its | |
| 1532 // opaque-ness. But other tiles should still not be affected. | |
| 1533 layer->fake_layer_updater()->SetOpaquePaintRect(gfx::Rect()); | |
| 1534 layer->InvalidateContentRect(gfx::Rect(10, 10, 1, 1)); | |
| 1535 layer->SetTexturePriorities(priority_calculator_); | |
| 1536 resource_manager_->PrioritizeTextures(); | |
| 1537 layer->SavePaintProperties(); | |
| 1538 layer->Update(queue_.get(), &occluded); | |
| 1539 UpdateTextures(); | |
| 1540 opaque_contents = layer->VisibleContentOpaqueRegion(); | |
| 1541 EXPECT_EQ(gfx::IntersectRects(gfx::Rect(10, 100, 90, 100), | |
| 1542 visible_bounds).ToString(), | |
| 1543 opaque_contents.ToString()); | |
| 1544 } | |
| 1545 | |
| 1546 TEST_F(TiledLayerTest, DontAllocateContentsWhenTargetSurfaceCantBeAllocated) { | 1458 TEST_F(TiledLayerTest, DontAllocateContentsWhenTargetSurfaceCantBeAllocated) { |
| 1547 // Tile size is 100x100. | 1459 // Tile size is 100x100. |
| 1548 gfx::Rect root_rect(0, 0, 300, 200); | 1460 gfx::Rect root_rect(0, 0, 300, 200); |
| 1549 gfx::Rect child_rect(0, 0, 300, 100); | 1461 gfx::Rect child_rect(0, 0, 300, 100); |
| 1550 gfx::Rect child2_rect(0, 100, 300, 100); | 1462 gfx::Rect child2_rect(0, 100, 300, 100); |
| 1551 | 1463 |
| 1552 scoped_refptr<FakeTiledLayer> root = make_scoped_refptr( | 1464 scoped_refptr<FakeTiledLayer> root = make_scoped_refptr( |
| 1553 new FakeTiledLayer(layer_tree_host_->contents_texture_manager())); | 1465 new FakeTiledLayer(layer_tree_host_->contents_texture_manager())); |
| 1554 scoped_refptr<Layer> surface = Layer::Create(); | 1466 scoped_refptr<Layer> surface = Layer::Create(); |
| 1555 scoped_refptr<FakeTiledLayer> child = make_scoped_refptr( | 1467 scoped_refptr<FakeTiledLayer> child = make_scoped_refptr( |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 resource_provider_.get()); | 1615 resource_provider_.get()); |
| 1704 layer_tree_host_->SetRootLayer(NULL); | 1616 layer_tree_host_->SetRootLayer(NULL); |
| 1705 } | 1617 } |
| 1706 | 1618 |
| 1707 class TrackingLayerPainter : public LayerPainter { | 1619 class TrackingLayerPainter : public LayerPainter { |
| 1708 public: | 1620 public: |
| 1709 static scoped_ptr<TrackingLayerPainter> Create() { | 1621 static scoped_ptr<TrackingLayerPainter> Create() { |
| 1710 return make_scoped_ptr(new TrackingLayerPainter()); | 1622 return make_scoped_ptr(new TrackingLayerPainter()); |
| 1711 } | 1623 } |
| 1712 | 1624 |
| 1713 virtual void Paint(SkCanvas* canvas, | 1625 virtual void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) OVERRIDE { |
| 1714 const gfx::Rect& content_rect, | |
| 1715 gfx::RectF* opaque) OVERRIDE { | |
| 1716 painted_rect_ = content_rect; | 1626 painted_rect_ = content_rect; |
| 1717 } | 1627 } |
| 1718 | 1628 |
| 1719 gfx::Rect PaintedRect() const { return painted_rect_; } | 1629 gfx::Rect PaintedRect() const { return painted_rect_; } |
| 1720 void ResetPaintedRect() { painted_rect_ = gfx::Rect(); } | 1630 void ResetPaintedRect() { painted_rect_ = gfx::Rect(); } |
| 1721 | 1631 |
| 1722 private: | 1632 private: |
| 1723 gfx::Rect painted_rect_; | 1633 gfx::Rect painted_rect_; |
| 1724 }; | 1634 }; |
| 1725 | 1635 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 // Invalidate the entire layer in layer space. When painting, the rect given | 1725 // Invalidate the entire layer in layer space. When painting, the rect given |
| 1816 // to webkit should match the layer's bounds. | 1726 // to webkit should match the layer's bounds. |
| 1817 layer->SetNeedsDisplayRect(layer_rect); | 1727 layer->SetNeedsDisplayRect(layer_rect); |
| 1818 layer->Update(queue_.get(), NULL); | 1728 layer->Update(queue_.get(), NULL); |
| 1819 | 1729 |
| 1820 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); | 1730 EXPECT_RECT_EQ(layer_rect, layer->tracking_layer_painter()->PaintedRect()); |
| 1821 } | 1731 } |
| 1822 | 1732 |
| 1823 } // namespace | 1733 } // namespace |
| 1824 } // namespace cc | 1734 } // namespace cc |
| OLD | NEW |