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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/tiled_layer.h" | 7 #include "cc/tiled_layer.h" |
8 | 8 |
9 #include "cc/bitmap_content_layer_updater.h" | 9 #include "cc/bitmap_content_layer_updater.h" |
10 #include "cc/layer_painter.h" | 10 #include "cc/layer_painter.h" |
11 #include "cc/overdraw_metrics.h" | 11 #include "cc/overdraw_metrics.h" |
12 #include "cc/rendering_stats.h" | 12 #include "cc/rendering_stats.h" |
13 #include "cc/resource_update_controller.h" | 13 #include "cc/resource_update_controller.h" |
14 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread | 14 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread |
15 #include "cc/test/animation_test_common.h" | 15 #include "cc/test/animation_test_common.h" |
16 #include "cc/test/fake_graphics_context.h" | 16 #include "cc/test/fake_graphics_context.h" |
17 #include "cc/test/fake_layer_tree_host_client.h" | 17 #include "cc/test/fake_layer_tree_host_client.h" |
18 #include "cc/test/fake_proxy.h" | |
19 #include "cc/test/geometry_test_utils.h" | 18 #include "cc/test/geometry_test_utils.h" |
20 #include "cc/test/tiled_layer_test_common.h" | 19 #include "cc/test/tiled_layer_test_common.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/gfx/rect_conversions.h" | 21 #include "ui/gfx/rect_conversions.h" |
23 #include <public/WebTransformationMatrix.h> | 22 #include <public/WebTransformationMatrix.h> |
24 | 23 |
25 using namespace cc; | 24 using namespace cc; |
26 using namespace WebKitTests; | 25 using namespace WebKitTests; |
27 using WebKit::WebTransformationMatrix; | 26 using WebKit::WebTransformationMatrix; |
28 | 27 |
(...skipping 14 matching lines...) Expand all Loading... |
43 protected: | 42 protected: |
44 virtual gfx::Rect layerClipRectInTarget(const Layer* layer) const OVERRIDE {
return m_layerClipRectInTarget; } | 43 virtual gfx::Rect layerClipRectInTarget(const Layer* layer) const OVERRIDE {
return m_layerClipRectInTarget; } |
45 | 44 |
46 private: | 45 private: |
47 gfx::Rect m_layerClipRectInTarget; | 46 gfx::Rect m_layerClipRectInTarget; |
48 }; | 47 }; |
49 | 48 |
50 class TiledLayerTest : public testing::Test { | 49 class TiledLayerTest : public testing::Test { |
51 public: | 50 public: |
52 TiledLayerTest() | 51 TiledLayerTest() |
53 : m_proxy(NULL) | 52 : m_context(WebKit::createFakeGraphicsContext()) |
54 , m_context(WebKit::createFakeGraphicsContext()) | |
55 , m_queue(make_scoped_ptr(new ResourceUpdateQueue)) | 53 , m_queue(make_scoped_ptr(new ResourceUpdateQueue)) |
| 54 , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024,
Renderer::ContentPool)) |
56 , m_occlusion(0) | 55 , m_occlusion(0) |
57 { | 56 { |
58 } | 57 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
59 | |
60 virtual void SetUp() | |
61 { | |
62 m_layerTreeHost = LayerTreeHost::create(&m_fakeLayerImplTreeHostClient,
m_settings, scoped_ptr<Thread>(NULL)); | |
63 m_proxy = m_layerTreeHost->proxy(); | |
64 m_textureManager = PrioritizedTextureManager::create(60*1024*1024, 1024,
Renderer::ContentPool, m_proxy); | |
65 m_layerTreeHost->initializeRendererIfNeeded(); | |
66 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(m_proxy); | |
67 m_resourceProvider = ResourceProvider::create(m_context.get()); | 58 m_resourceProvider = ResourceProvider::create(m_context.get()); |
68 } | 59 } |
69 | 60 |
70 virtual ~TiledLayerTest() | 61 virtual ~TiledLayerTest() |
71 { | 62 { |
72 textureManagerClearAllMemory(m_textureManager.get(), m_resourceProvider.
get()); | 63 textureManagerClearAllMemory(m_textureManager.get(), m_resourceProvider.
get()); |
73 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(m_proxy); | 64 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
74 m_resourceProvider.reset(); | 65 m_resourceProvider.reset(); |
75 } | 66 } |
76 | 67 |
| 68 // Helper classes and functions that set the current thread to be the impl t
hread |
| 69 // before doing the action that they wrap. |
77 class ScopedFakeTiledLayerImpl { | 70 class ScopedFakeTiledLayerImpl { |
78 public: | 71 public: |
79 ScopedFakeTiledLayerImpl(int id) | 72 ScopedFakeTiledLayerImpl(int id) |
80 { | 73 { |
| 74 DebugScopedSetImplThread implThread; |
81 m_layerImpl = new FakeTiledLayerImpl(id); | 75 m_layerImpl = new FakeTiledLayerImpl(id); |
82 } | 76 } |
83 ~ScopedFakeTiledLayerImpl() | 77 ~ScopedFakeTiledLayerImpl() |
84 { | 78 { |
| 79 DebugScopedSetImplThread implThread; |
85 delete m_layerImpl; | 80 delete m_layerImpl; |
86 } | 81 } |
87 FakeTiledLayerImpl* get() | 82 FakeTiledLayerImpl* get() |
88 { | 83 { |
89 return m_layerImpl; | 84 return m_layerImpl; |
90 } | 85 } |
91 FakeTiledLayerImpl* operator->() | 86 FakeTiledLayerImpl* operator->() |
92 { | 87 { |
93 return m_layerImpl; | 88 return m_layerImpl; |
94 } | 89 } |
95 private: | 90 private: |
96 FakeTiledLayerImpl* m_layerImpl; | 91 FakeTiledLayerImpl* m_layerImpl; |
97 }; | 92 }; |
98 void textureManagerClearAllMemory(PrioritizedTextureManager* textureManager,
ResourceProvider* resourceProvider) | 93 void textureManagerClearAllMemory(PrioritizedTextureManager* textureManager,
ResourceProvider* resourceProvider) |
99 { | 94 { |
100 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(m_proxy); | 95 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
101 textureManager->clearAllMemory(resourceProvider); | 96 textureManager->clearAllMemory(resourceProvider); |
102 textureManager->reduceMemory(resourceProvider); | 97 textureManager->reduceMemory(resourceProvider); |
103 } | 98 } |
104 void updateTextures() | 99 void updateTextures() |
105 { | 100 { |
106 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(m_proxy); | 101 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
107 DCHECK(m_queue); | 102 DCHECK(m_queue); |
108 scoped_ptr<ResourceUpdateController> updateController = | 103 scoped_ptr<ResourceUpdateController> updateController = |
109 ResourceUpdateController::create( | 104 ResourceUpdateController::create( |
110 NULL, | 105 NULL, |
111 m_proxy->implThread(), | 106 Proxy::implThread(), |
112 m_queue.Pass(), | 107 m_queue.Pass(), |
113 m_resourceProvider.get(), | 108 m_resourceProvider.get()); |
114 m_proxy->hasImplThread()); | |
115 updateController->finalize(); | 109 updateController->finalize(); |
116 m_queue = make_scoped_ptr(new ResourceUpdateQueue); | 110 m_queue = make_scoped_ptr(new ResourceUpdateQueue); |
117 } | 111 } |
118 void layerPushPropertiesTo(FakeTiledLayer* layer, FakeTiledLayerImpl* layerI
mpl) | 112 void layerPushPropertiesTo(FakeTiledLayer* layer, FakeTiledLayerImpl* layerI
mpl) |
119 { | 113 { |
120 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked(m_proxy); | 114 DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBloc
ked; |
121 layer->pushPropertiesTo(layerImpl); | 115 layer->pushPropertiesTo(layerImpl); |
122 } | 116 } |
123 void layerUpdate(FakeTiledLayer* layer, TestOcclusionTracker* occluded) | 117 void layerUpdate(FakeTiledLayer* layer, TestOcclusionTracker* occluded) |
124 { | 118 { |
125 DebugScopedSetMainThread mainThread(m_proxy); | 119 DebugScopedSetMainThread mainThread; |
126 layer->update(*m_queue.get(), occluded, m_stats); | 120 layer->update(*m_queue.get(), occluded, m_stats); |
127 } | 121 } |
128 | 122 |
129 bool updateAndPush(FakeTiledLayer* layer1, | 123 bool updateAndPush(FakeTiledLayer* layer1, |
130 FakeTiledLayerImpl* layerImpl1, | 124 FakeTiledLayerImpl* layerImpl1, |
131 FakeTiledLayer* layer2 = 0, | 125 FakeTiledLayer* layer2 = 0, |
132 FakeTiledLayerImpl* layerImpl2 = 0) | 126 FakeTiledLayerImpl* layerImpl2 = 0) |
133 { | 127 { |
134 // Get textures | 128 // Get textures |
135 m_textureManager->clearPriorities(); | 129 m_textureManager->clearPriorities(); |
(...skipping 19 matching lines...) Expand all Loading... |
155 updateTextures(); | 149 updateTextures(); |
156 if (layer1) | 150 if (layer1) |
157 layerPushPropertiesTo(layer1, layerImpl1); | 151 layerPushPropertiesTo(layer1, layerImpl1); |
158 if (layer2) | 152 if (layer2) |
159 layerPushPropertiesTo(layer2, layerImpl2); | 153 layerPushPropertiesTo(layer2, layerImpl2); |
160 | 154 |
161 return needsUpdate; | 155 return needsUpdate; |
162 } | 156 } |
163 | 157 |
164 public: | 158 public: |
165 Proxy* m_proxy; | |
166 LayerTreeSettings m_settings; | |
167 scoped_ptr<GraphicsContext> m_context; | 159 scoped_ptr<GraphicsContext> m_context; |
168 scoped_ptr<ResourceProvider> m_resourceProvider; | 160 scoped_ptr<ResourceProvider> m_resourceProvider; |
169 scoped_ptr<ResourceUpdateQueue> m_queue; | 161 scoped_ptr<ResourceUpdateQueue> m_queue; |
170 RenderingStats m_stats; | 162 RenderingStats m_stats; |
171 PriorityCalculator m_priorityCalculator; | 163 PriorityCalculator m_priorityCalculator; |
172 FakeLayerImplTreeHostClient m_fakeLayerImplTreeHostClient; | |
173 scoped_ptr<LayerTreeHost> m_layerTreeHost; | |
174 scoped_ptr<PrioritizedTextureManager> m_textureManager; | 164 scoped_ptr<PrioritizedTextureManager> m_textureManager; |
175 TestOcclusionTracker* m_occlusion; | 165 TestOcclusionTracker* m_occlusion; |
176 }; | 166 }; |
177 | 167 |
178 TEST_F(TiledLayerTest, pushDirtyTiles) | 168 TEST_F(TiledLayerTest, pushDirtyTiles) |
179 { | 169 { |
180 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); | 170 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); |
181 ScopedFakeTiledLayerImpl layerImpl(1); | 171 ScopedFakeTiledLayerImpl layerImpl(1); |
182 | 172 |
183 // The tile size is 100x100, so this invalidates and then paints two tiles. | 173 // The tile size is 100x100, so this invalidates and then paints two tiles. |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 1)); | 505 EXPECT_TRUE(layer1Impl->hasResourceIdForTileAt(0, 1)); |
516 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 0)); | 506 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 0)); |
517 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 1)); | 507 EXPECT_TRUE(layer2Impl->hasResourceIdForTileAt(0, 1)); |
518 } | 508 } |
519 | 509 |
520 TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately) | 510 TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately) |
521 { | 511 { |
522 // Create a LayerTreeHost that has the right viewportsize, | 512 // Create a LayerTreeHost that has the right viewportsize, |
523 // so the layer is considered small enough. | 513 // so the layer is considered small enough. |
524 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; | 514 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; |
525 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm
plTreeHostClient, LayerTreeSettings(), scoped_ptr<Thread>(NULL)); | 515 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm
plTreeHostClient, LayerTreeSettings()); |
526 | 516 |
527 bool runOutOfMemory[2] = {false, true}; | 517 bool runOutOfMemory[2] = {false, true}; |
528 for (int i = 0; i < 2; i++) { | 518 for (int i = 0; i < 2; i++) { |
529 // Create a layer with 4x4 tiles. | 519 // Create a layer with 4x4 tiles. |
530 int layerWidth = 4 * FakeTiledLayer::tileSize().width(); | 520 int layerWidth = 4 * FakeTiledLayer::tileSize().width(); |
531 int layerHeight = 4 * FakeTiledLayer::tileSize().height(); | 521 int layerHeight = 4 * FakeTiledLayer::tileSize().height(); |
532 int memoryForLayer = layerWidth * layerHeight * 4; | 522 int memoryForLayer = layerWidth * layerHeight * 4; |
533 gfx::Size viewportSize = gfx::Size(layerWidth, layerHeight); | 523 gfx::Size viewportSize = gfx::Size(layerWidth, layerHeight); |
534 layerTreeHost->setViewportSize(viewportSize, viewportSize); | 524 layerTreeHost->setViewportSize(viewportSize, viewportSize); |
535 | 525 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 | 771 |
782 layerPushPropertiesTo(layer.get(), layerImpl.get()); | 772 layerPushPropertiesTo(layer.get(), layerImpl.get()); |
783 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 0)); | 773 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 0)); |
784 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1)); | 774 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(0, 1)); |
785 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 0)); | 775 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 0)); |
786 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 1)); | 776 EXPECT_FALSE(layerImpl->hasResourceIdForTileAt(1, 1)); |
787 } | 777 } |
788 | 778 |
789 TEST_F(TiledLayerTest, skipsDrawGetsReset) | 779 TEST_F(TiledLayerTest, skipsDrawGetsReset) |
790 { | 780 { |
| 781 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; |
| 782 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm
plTreeHostClient, LayerTreeSettings()); |
| 783 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); |
| 784 |
791 // Create two 300 x 300 tiled layers. | 785 // Create two 300 x 300 tiled layers. |
792 gfx::Size contentBounds(300, 300); | 786 gfx::Size contentBounds(300, 300); |
793 gfx::Rect contentRect(gfx::Point(), contentBounds); | 787 gfx::Rect contentRect(gfx::Point(), contentBounds); |
794 | 788 |
795 // We have enough memory for only one of the two layers. | 789 // We have enough memory for only one of the two layers. |
796 int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel. | 790 int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel. |
797 | 791 |
798 scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLa
yer(m_layerTreeHost->contentsTextureManager())); | 792 scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLa
yer(layerTreeHost->contentsTextureManager())); |
799 scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledL
ayer(m_layerTreeHost->contentsTextureManager())); | 793 scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledL
ayer(layerTreeHost->contentsTextureManager())); |
800 rootLayer->addChild(childLayer); | 794 rootLayer->addChild(childLayer); |
801 | 795 |
802 rootLayer->setBounds(contentBounds); | 796 rootLayer->setBounds(contentBounds); |
803 rootLayer->setVisibleContentRect(contentRect); | 797 rootLayer->setVisibleContentRect(contentRect); |
804 rootLayer->setPosition(gfx::PointF(0, 0)); | 798 rootLayer->setPosition(gfx::PointF(0, 0)); |
805 childLayer->setBounds(contentBounds); | 799 childLayer->setBounds(contentBounds); |
806 childLayer->setVisibleContentRect(contentRect); | 800 childLayer->setVisibleContentRect(contentRect); |
807 childLayer->setPosition(gfx::PointF(0, 0)); | 801 childLayer->setPosition(gfx::PointF(0, 0)); |
808 rootLayer->invalidateContentRect(contentRect); | 802 rootLayer->invalidateContentRect(contentRect); |
809 childLayer->invalidateContentRect(contentRect); | 803 childLayer->invalidateContentRect(contentRect); |
810 | 804 |
811 m_layerTreeHost->setRootLayer(rootLayer); | 805 layerTreeHost->setRootLayer(rootLayer); |
812 m_layerTreeHost->setViewportSize(gfx::Size(300, 300), gfx::Size(300, 300)); | 806 layerTreeHost->setViewportSize(gfx::Size(300, 300), gfx::Size(300, 300)); |
813 | 807 |
814 m_layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); | 808 layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); |
815 | 809 |
816 // We'll skip the root layer. | 810 // We'll skip the root layer. |
817 EXPECT_TRUE(rootLayer->skipsDraw()); | 811 EXPECT_TRUE(rootLayer->skipsDraw()); |
818 EXPECT_FALSE(childLayer->skipsDraw()); | 812 EXPECT_FALSE(childLayer->skipsDraw()); |
819 | 813 |
820 m_layerTreeHost->commitComplete(); | 814 layerTreeHost->commitComplete(); |
821 | 815 |
822 // Remove the child layer. | 816 // Remove the child layer. |
823 rootLayer->removeAllChildren(); | 817 rootLayer->removeAllChildren(); |
824 | 818 |
825 m_layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); | 819 layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); |
826 EXPECT_FALSE(rootLayer->skipsDraw()); | 820 EXPECT_FALSE(rootLayer->skipsDraw()); |
827 | 821 |
828 textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_re
sourceProvider.get()); | 822 textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_reso
urceProvider.get()); |
829 m_layerTreeHost->setRootLayer(0); | 823 layerTreeHost->setRootLayer(0); |
830 } | 824 } |
831 | 825 |
832 TEST_F(TiledLayerTest, resizeToSmaller) | 826 TEST_F(TiledLayerTest, resizeToSmaller) |
833 { | 827 { |
834 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); | 828 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); |
835 | 829 |
836 layer->setBounds(gfx::Size(700, 700)); | 830 layer->setBounds(gfx::Size(700, 700)); |
837 layer->setVisibleContentRect(gfx::Rect(0, 0, 700, 700)); | 831 layer->setVisibleContentRect(gfx::Rect(0, 0, 700, 700)); |
838 layer->invalidateContentRect(gfx::Rect(0, 0, 700, 700)); | 832 layer->invalidateContentRect(gfx::Rect(0, 0, 700, 700)); |
839 | 833 |
(...skipping 13 matching lines...) Expand all Loading... |
853 layer->setBounds(gfx::Size(size, size)); | 847 layer->setBounds(gfx::Size(size, size)); |
854 layer->setVisibleContentRect(gfx::Rect(0, 0, 700, 700)); | 848 layer->setVisibleContentRect(gfx::Rect(0, 0, 700, 700)); |
855 layer->invalidateContentRect(gfx::Rect(0, 0, size, size)); | 849 layer->invalidateContentRect(gfx::Rect(0, 0, size, size)); |
856 | 850 |
857 // Ensure no crash for bounds where size * size would overflow an int. | 851 // Ensure no crash for bounds where size * size would overflow an int. |
858 layer->setTexturePriorities(m_priorityCalculator); | 852 layer->setTexturePriorities(m_priorityCalculator); |
859 m_textureManager->prioritizeTextures(); | 853 m_textureManager->prioritizeTextures(); |
860 layer->update(*m_queue.get(), 0, m_stats); | 854 layer->update(*m_queue.get(), 0, m_stats); |
861 } | 855 } |
862 | 856 |
| 857 TEST_F(TiledLayerTest, partialUpdates) |
| 858 { |
| 859 LayerTreeSettings settings; |
| 860 settings.maxPartialTextureUpdates = 4; |
| 861 |
| 862 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; |
| 863 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm
plTreeHostClient, settings); |
| 864 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); |
| 865 |
| 866 // Create one 300 x 200 tiled layer with 3 x 2 tiles. |
| 867 gfx::Size contentBounds(300, 200); |
| 868 gfx::Rect contentRect(gfx::Point(), contentBounds); |
| 869 |
| 870 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
layerTreeHost->contentsTextureManager())); |
| 871 layer->setBounds(contentBounds); |
| 872 layer->setPosition(gfx::PointF(0, 0)); |
| 873 layer->setVisibleContentRect(contentRect); |
| 874 layer->invalidateContentRect(contentRect); |
| 875 |
| 876 layerTreeHost->setRootLayer(layer); |
| 877 layerTreeHost->setViewportSize(gfx::Size(300, 200), gfx::Size(300, 200)); |
| 878 |
| 879 // Full update of all 6 tiles. |
| 880 layerTreeHost->updateLayers( |
| 881 *m_queue.get(), std::numeric_limits<size_t>::max()); |
| 882 { |
| 883 ScopedFakeTiledLayerImpl layerImpl(1); |
| 884 EXPECT_EQ(6, m_queue->fullUploadSize()); |
| 885 EXPECT_EQ(0, m_queue->partialUploadSize()); |
| 886 updateTextures(); |
| 887 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); |
| 888 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
| 889 layer->fakeLayerUpdater()->clearUpdateCount(); |
| 890 layerPushPropertiesTo(layer.get(), layerImpl.get()); |
| 891 } |
| 892 layerTreeHost->commitComplete(); |
| 893 |
| 894 // Full update of 3 tiles and partial update of 3 tiles. |
| 895 layer->invalidateContentRect(gfx::Rect(0, 0, 300, 150)); |
| 896 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max
()); |
| 897 { |
| 898 ScopedFakeTiledLayerImpl layerImpl(1); |
| 899 EXPECT_EQ(3, m_queue->fullUploadSize()); |
| 900 EXPECT_EQ(3, m_queue->partialUploadSize()); |
| 901 updateTextures(); |
| 902 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); |
| 903 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
| 904 layer->fakeLayerUpdater()->clearUpdateCount(); |
| 905 layerPushPropertiesTo(layer.get(), layerImpl.get()); |
| 906 } |
| 907 layerTreeHost->commitComplete(); |
| 908 |
| 909 // Partial update of 6 tiles. |
| 910 layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); |
| 911 { |
| 912 ScopedFakeTiledLayerImpl layerImpl(1); |
| 913 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>:
:max()); |
| 914 EXPECT_EQ(2, m_queue->fullUploadSize()); |
| 915 EXPECT_EQ(4, m_queue->partialUploadSize()); |
| 916 updateTextures(); |
| 917 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); |
| 918 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
| 919 layer->fakeLayerUpdater()->clearUpdateCount(); |
| 920 layerPushPropertiesTo(layer.get(), layerImpl.get()); |
| 921 } |
| 922 layerTreeHost->commitComplete(); |
| 923 |
| 924 // Checkerboard all tiles. |
| 925 layer->invalidateContentRect(gfx::Rect(0, 0, 300, 200)); |
| 926 { |
| 927 ScopedFakeTiledLayerImpl layerImpl(1); |
| 928 layerPushPropertiesTo(layer.get(), layerImpl.get()); |
| 929 } |
| 930 layerTreeHost->commitComplete(); |
| 931 |
| 932 // Partial update of 6 checkerboard tiles. |
| 933 layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); |
| 934 { |
| 935 ScopedFakeTiledLayerImpl layerImpl(1); |
| 936 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>:
:max()); |
| 937 EXPECT_EQ(6, m_queue->fullUploadSize()); |
| 938 EXPECT_EQ(0, m_queue->partialUploadSize()); |
| 939 updateTextures(); |
| 940 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); |
| 941 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
| 942 layer->fakeLayerUpdater()->clearUpdateCount(); |
| 943 layerPushPropertiesTo(layer.get(), layerImpl.get()); |
| 944 } |
| 945 layerTreeHost->commitComplete(); |
| 946 |
| 947 // Partial update of 4 tiles. |
| 948 layer->invalidateContentRect(gfx::Rect(50, 50, 100, 100)); |
| 949 { |
| 950 ScopedFakeTiledLayerImpl layerImpl(1); |
| 951 layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>:
:max()); |
| 952 EXPECT_EQ(0, m_queue->fullUploadSize()); |
| 953 EXPECT_EQ(4, m_queue->partialUploadSize()); |
| 954 updateTextures(); |
| 955 EXPECT_EQ(4, layer->fakeLayerUpdater()->updateCount()); |
| 956 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
| 957 layer->fakeLayerUpdater()->clearUpdateCount(); |
| 958 layerPushPropertiesTo(layer.get(), layerImpl.get()); |
| 959 } |
| 960 layerTreeHost->commitComplete(); |
| 961 |
| 962 textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_reso
urceProvider.get()); |
| 963 layerTreeHost->setRootLayer(0); |
| 964 } |
| 965 |
863 TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion) | 966 TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion) |
864 { | 967 { |
865 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); | 968 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); |
866 | 969 |
867 // The tile size is 100x100, so this invalidates and then paints two tiles. | 970 // The tile size is 100x100, so this invalidates and then paints two tiles. |
868 layer->setBounds(gfx::Size(100, 200)); | 971 layer->setBounds(gfx::Size(100, 200)); |
869 layer->setDrawableContentRect(gfx::Rect(0, 0, 100, 200)); | 972 layer->setDrawableContentRect(gfx::Rect(0, 0, 100, 200)); |
870 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200)); | 973 layer->setVisibleContentRect(gfx::Rect(0, 0, 100, 200)); |
871 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 200)); | 974 layer->invalidateContentRect(gfx::Rect(0, 0, 100, 200)); |
872 | 975 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); | 1374 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); |
1272 } | 1375 } |
1273 | 1376 |
1274 TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) | 1377 TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) |
1275 { | 1378 { |
1276 // Tile size is 100x100. | 1379 // Tile size is 100x100. |
1277 gfx::Rect rootRect(0, 0, 300, 200); | 1380 gfx::Rect rootRect(0, 0, 300, 200); |
1278 gfx::Rect childRect(0, 0, 300, 100); | 1381 gfx::Rect childRect(0, 0, 300, 100); |
1279 gfx::Rect child2Rect(0, 100, 300, 100); | 1382 gfx::Rect child2Rect(0, 100, 300, 100); |
1280 | 1383 |
1281 scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(m
_layerTreeHost->contentsTextureManager())); | 1384 LayerTreeSettings settings; |
| 1385 FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; |
| 1386 scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerIm
plTreeHostClient, settings); |
| 1387 ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); |
| 1388 |
| 1389 scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(l
ayerTreeHost->contentsTextureManager())); |
1282 scoped_refptr<Layer> surface = Layer::create(); | 1390 scoped_refptr<Layer> surface = Layer::create(); |
1283 scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer(
m_layerTreeHost->contentsTextureManager())); | 1391 scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer(
layerTreeHost->contentsTextureManager())); |
1284 scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer
(m_layerTreeHost->contentsTextureManager())); | 1392 scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer
(layerTreeHost->contentsTextureManager())); |
1285 | 1393 |
1286 root->setBounds(rootRect.size()); | 1394 root->setBounds(rootRect.size()); |
1287 root->setAnchorPoint(gfx::PointF()); | 1395 root->setAnchorPoint(gfx::PointF()); |
1288 root->setDrawableContentRect(rootRect); | 1396 root->setDrawableContentRect(rootRect); |
1289 root->setVisibleContentRect(rootRect); | 1397 root->setVisibleContentRect(rootRect); |
1290 root->addChild(surface); | 1398 root->addChild(surface); |
1291 | 1399 |
1292 surface->setForceRenderSurface(true); | 1400 surface->setForceRenderSurface(true); |
1293 surface->setAnchorPoint(gfx::PointF()); | 1401 surface->setAnchorPoint(gfx::PointF()); |
1294 surface->setOpacity(0.5); | 1402 surface->setOpacity(0.5); |
1295 surface->addChild(child); | 1403 surface->addChild(child); |
1296 surface->addChild(child2); | 1404 surface->addChild(child2); |
1297 | 1405 |
1298 child->setBounds(childRect.size()); | 1406 child->setBounds(childRect.size()); |
1299 child->setAnchorPoint(gfx::PointF()); | 1407 child->setAnchorPoint(gfx::PointF()); |
1300 child->setPosition(childRect.origin()); | 1408 child->setPosition(childRect.origin()); |
1301 child->setVisibleContentRect(childRect); | 1409 child->setVisibleContentRect(childRect); |
1302 child->setDrawableContentRect(rootRect); | 1410 child->setDrawableContentRect(rootRect); |
1303 | 1411 |
1304 child2->setBounds(child2Rect.size()); | 1412 child2->setBounds(child2Rect.size()); |
1305 child2->setAnchorPoint(gfx::PointF()); | 1413 child2->setAnchorPoint(gfx::PointF()); |
1306 child2->setPosition(child2Rect.origin()); | 1414 child2->setPosition(child2Rect.origin()); |
1307 child2->setVisibleContentRect(child2Rect); | 1415 child2->setVisibleContentRect(child2Rect); |
1308 child2->setDrawableContentRect(rootRect); | 1416 child2->setDrawableContentRect(rootRect); |
1309 | 1417 |
1310 m_layerTreeHost->setRootLayer(root); | 1418 layerTreeHost->setRootLayer(root); |
1311 m_layerTreeHost->setViewportSize(rootRect.size(), rootRect.size()); | 1419 layerTreeHost->setViewportSize(rootRect.size(), rootRect.size()); |
1312 | 1420 |
1313 // With a huge memory limit, all layers should update and push their texture
s. | 1421 // With a huge memory limit, all layers should update and push their texture
s. |
1314 root->invalidateContentRect(rootRect); | 1422 root->invalidateContentRect(rootRect); |
1315 child->invalidateContentRect(childRect); | 1423 child->invalidateContentRect(childRect); |
1316 child2->invalidateContentRect(child2Rect); | 1424 child2->invalidateContentRect(child2Rect); |
1317 m_layerTreeHost->updateLayers( | 1425 layerTreeHost->updateLayers( |
1318 *m_queue.get(), std::numeric_limits<size_t>::max()); | 1426 *m_queue.get(), std::numeric_limits<size_t>::max()); |
1319 { | 1427 { |
1320 updateTextures(); | 1428 updateTextures(); |
1321 EXPECT_EQ(6, root->fakeLayerUpdater()->updateCount()); | 1429 EXPECT_EQ(6, root->fakeLayerUpdater()->updateCount()); |
1322 EXPECT_EQ(3, child->fakeLayerUpdater()->updateCount()); | 1430 EXPECT_EQ(3, child->fakeLayerUpdater()->updateCount()); |
1323 EXPECT_EQ(3, child2->fakeLayerUpdater()->updateCount()); | 1431 EXPECT_EQ(3, child2->fakeLayerUpdater()->updateCount()); |
1324 EXPECT_FALSE(m_queue->hasMoreUpdates()); | 1432 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
1325 | 1433 |
1326 root->fakeLayerUpdater()->clearUpdateCount(); | 1434 root->fakeLayerUpdater()->clearUpdateCount(); |
1327 child->fakeLayerUpdater()->clearUpdateCount(); | 1435 child->fakeLayerUpdater()->clearUpdateCount(); |
1328 child2->fakeLayerUpdater()->clearUpdateCount(); | 1436 child2->fakeLayerUpdater()->clearUpdateCount(); |
1329 | 1437 |
1330 ScopedFakeTiledLayerImpl rootImpl(root->id()); | 1438 ScopedFakeTiledLayerImpl rootImpl(root->id()); |
1331 ScopedFakeTiledLayerImpl childImpl(child->id()); | 1439 ScopedFakeTiledLayerImpl childImpl(child->id()); |
1332 ScopedFakeTiledLayerImpl child2Impl(child2->id()); | 1440 ScopedFakeTiledLayerImpl child2Impl(child2->id()); |
1333 layerPushPropertiesTo(root.get(), rootImpl.get()); | 1441 layerPushPropertiesTo(root.get(), rootImpl.get()); |
1334 layerPushPropertiesTo(child.get(), childImpl.get()); | 1442 layerPushPropertiesTo(child.get(), childImpl.get()); |
1335 layerPushPropertiesTo(child2.get(), child2Impl.get()); | 1443 layerPushPropertiesTo(child2.get(), child2Impl.get()); |
1336 | 1444 |
1337 for (unsigned i = 0; i < 3; ++i) { | 1445 for (unsigned i = 0; i < 3; ++i) { |
1338 for (unsigned j = 0; j < 2; ++j) | 1446 for (unsigned j = 0; j < 2; ++j) |
1339 EXPECT_TRUE(rootImpl->hasResourceIdForTileAt(i, j)); | 1447 EXPECT_TRUE(rootImpl->hasResourceIdForTileAt(i, j)); |
1340 EXPECT_TRUE(childImpl->hasResourceIdForTileAt(i, 0)); | 1448 EXPECT_TRUE(childImpl->hasResourceIdForTileAt(i, 0)); |
1341 EXPECT_TRUE(child2Impl->hasResourceIdForTileAt(i, 0)); | 1449 EXPECT_TRUE(child2Impl->hasResourceIdForTileAt(i, 0)); |
1342 } | 1450 } |
1343 } | 1451 } |
1344 m_layerTreeHost->commitComplete(); | 1452 layerTreeHost->commitComplete(); |
1345 | 1453 |
1346 // With a memory limit that includes only the root layer (3x2 tiles) and hal
f the surface that | 1454 // With a memory limit that includes only the root layer (3x2 tiles) and hal
f the surface that |
1347 // the child layers draw into, the child layers will not be allocated. If th
e surface isn't | 1455 // the child layers draw into, the child layers will not be allocated. If th
e surface isn't |
1348 // accounted for, then one of the children would fit within the memory limit
. | 1456 // accounted for, then one of the children would fit within the memory limit
. |
1349 root->invalidateContentRect(rootRect); | 1457 root->invalidateContentRect(rootRect); |
1350 child->invalidateContentRect(childRect); | 1458 child->invalidateContentRect(childRect); |
1351 child2->invalidateContentRect(child2Rect); | 1459 child2->invalidateContentRect(child2Rect); |
1352 m_layerTreeHost->updateLayers( | 1460 layerTreeHost->updateLayers( |
1353 *m_queue.get(), (3 * 2 + 3 * 1) * (100 * 100) * 4); | 1461 *m_queue.get(), (3 * 2 + 3 * 1) * (100 * 100) * 4); |
1354 { | 1462 { |
1355 updateTextures(); | 1463 updateTextures(); |
1356 EXPECT_EQ(6, root->fakeLayerUpdater()->updateCount()); | 1464 EXPECT_EQ(6, root->fakeLayerUpdater()->updateCount()); |
1357 EXPECT_EQ(0, child->fakeLayerUpdater()->updateCount()); | 1465 EXPECT_EQ(0, child->fakeLayerUpdater()->updateCount()); |
1358 EXPECT_EQ(0, child2->fakeLayerUpdater()->updateCount()); | 1466 EXPECT_EQ(0, child2->fakeLayerUpdater()->updateCount()); |
1359 EXPECT_FALSE(m_queue->hasMoreUpdates()); | 1467 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
1360 | 1468 |
1361 root->fakeLayerUpdater()->clearUpdateCount(); | 1469 root->fakeLayerUpdater()->clearUpdateCount(); |
1362 child->fakeLayerUpdater()->clearUpdateCount(); | 1470 child->fakeLayerUpdater()->clearUpdateCount(); |
1363 child2->fakeLayerUpdater()->clearUpdateCount(); | 1471 child2->fakeLayerUpdater()->clearUpdateCount(); |
1364 | 1472 |
1365 ScopedFakeTiledLayerImpl rootImpl(root->id()); | 1473 ScopedFakeTiledLayerImpl rootImpl(root->id()); |
1366 ScopedFakeTiledLayerImpl childImpl(child->id()); | 1474 ScopedFakeTiledLayerImpl childImpl(child->id()); |
1367 ScopedFakeTiledLayerImpl child2Impl(child2->id()); | 1475 ScopedFakeTiledLayerImpl child2Impl(child2->id()); |
1368 layerPushPropertiesTo(root.get(), rootImpl.get()); | 1476 layerPushPropertiesTo(root.get(), rootImpl.get()); |
1369 layerPushPropertiesTo(child.get(), childImpl.get()); | 1477 layerPushPropertiesTo(child.get(), childImpl.get()); |
1370 layerPushPropertiesTo(child2.get(), child2Impl.get()); | 1478 layerPushPropertiesTo(child2.get(), child2Impl.get()); |
1371 | 1479 |
1372 for (unsigned i = 0; i < 3; ++i) { | 1480 for (unsigned i = 0; i < 3; ++i) { |
1373 for (unsigned j = 0; j < 2; ++j) | 1481 for (unsigned j = 0; j < 2; ++j) |
1374 EXPECT_TRUE(rootImpl->hasResourceIdForTileAt(i, j)); | 1482 EXPECT_TRUE(rootImpl->hasResourceIdForTileAt(i, j)); |
1375 EXPECT_FALSE(childImpl->hasResourceIdForTileAt(i, 0)); | 1483 EXPECT_FALSE(childImpl->hasResourceIdForTileAt(i, 0)); |
1376 EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0)); | 1484 EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0)); |
1377 } | 1485 } |
1378 } | 1486 } |
1379 m_layerTreeHost->commitComplete(); | 1487 layerTreeHost->commitComplete(); |
1380 | 1488 |
1381 // With a memory limit that includes only half the root layer, no contents w
ill be | 1489 // With a memory limit that includes only half the root layer, no contents w
ill be |
1382 // allocated. If render surface memory wasn't accounted for, there is enough
space | 1490 // allocated. If render surface memory wasn't accounted for, there is enough
space |
1383 // for one of the children layers, but they draw into a surface that can't b
e | 1491 // for one of the children layers, but they draw into a surface that can't b
e |
1384 // allocated. | 1492 // allocated. |
1385 root->invalidateContentRect(rootRect); | 1493 root->invalidateContentRect(rootRect); |
1386 child->invalidateContentRect(childRect); | 1494 child->invalidateContentRect(childRect); |
1387 child2->invalidateContentRect(child2Rect); | 1495 child2->invalidateContentRect(child2Rect); |
1388 m_layerTreeHost->updateLayers( | 1496 layerTreeHost->updateLayers( |
1389 *m_queue.get(), (3 * 1) * (100 * 100) * 4); | 1497 *m_queue.get(), (3 * 1) * (100 * 100) * 4); |
1390 { | 1498 { |
1391 updateTextures(); | 1499 updateTextures(); |
1392 EXPECT_EQ(0, root->fakeLayerUpdater()->updateCount()); | 1500 EXPECT_EQ(0, root->fakeLayerUpdater()->updateCount()); |
1393 EXPECT_EQ(0, child->fakeLayerUpdater()->updateCount()); | 1501 EXPECT_EQ(0, child->fakeLayerUpdater()->updateCount()); |
1394 EXPECT_EQ(0, child2->fakeLayerUpdater()->updateCount()); | 1502 EXPECT_EQ(0, child2->fakeLayerUpdater()->updateCount()); |
1395 EXPECT_FALSE(m_queue->hasMoreUpdates()); | 1503 EXPECT_FALSE(m_queue->hasMoreUpdates()); |
1396 | 1504 |
1397 root->fakeLayerUpdater()->clearUpdateCount(); | 1505 root->fakeLayerUpdater()->clearUpdateCount(); |
1398 child->fakeLayerUpdater()->clearUpdateCount(); | 1506 child->fakeLayerUpdater()->clearUpdateCount(); |
1399 child2->fakeLayerUpdater()->clearUpdateCount(); | 1507 child2->fakeLayerUpdater()->clearUpdateCount(); |
1400 | 1508 |
1401 ScopedFakeTiledLayerImpl rootImpl(root->id()); | 1509 ScopedFakeTiledLayerImpl rootImpl(root->id()); |
1402 ScopedFakeTiledLayerImpl childImpl(child->id()); | 1510 ScopedFakeTiledLayerImpl childImpl(child->id()); |
1403 ScopedFakeTiledLayerImpl child2Impl(child2->id()); | 1511 ScopedFakeTiledLayerImpl child2Impl(child2->id()); |
1404 layerPushPropertiesTo(root.get(), rootImpl.get()); | 1512 layerPushPropertiesTo(root.get(), rootImpl.get()); |
1405 layerPushPropertiesTo(child.get(), childImpl.get()); | 1513 layerPushPropertiesTo(child.get(), childImpl.get()); |
1406 layerPushPropertiesTo(child2.get(), child2Impl.get()); | 1514 layerPushPropertiesTo(child2.get(), child2Impl.get()); |
1407 | 1515 |
1408 for (unsigned i = 0; i < 3; ++i) { | 1516 for (unsigned i = 0; i < 3; ++i) { |
1409 for (unsigned j = 0; j < 2; ++j) | 1517 for (unsigned j = 0; j < 2; ++j) |
1410 EXPECT_FALSE(rootImpl->hasResourceIdForTileAt(i, j)); | 1518 EXPECT_FALSE(rootImpl->hasResourceIdForTileAt(i, j)); |
1411 EXPECT_FALSE(childImpl->hasResourceIdForTileAt(i, 0)); | 1519 EXPECT_FALSE(childImpl->hasResourceIdForTileAt(i, 0)); |
1412 EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0)); | 1520 EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0)); |
1413 } | 1521 } |
1414 } | 1522 } |
1415 m_layerTreeHost->commitComplete(); | 1523 layerTreeHost->commitComplete(); |
1416 | 1524 |
1417 textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_re
sourceProvider.get()); | 1525 textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_reso
urceProvider.get()); |
1418 m_layerTreeHost->setRootLayer(0); | 1526 layerTreeHost->setRootLayer(0); |
1419 } | 1527 } |
1420 | 1528 |
1421 class TrackingLayerPainter : public LayerPainter { | 1529 class TrackingLayerPainter : public LayerPainter { |
1422 public: | 1530 public: |
1423 static scoped_ptr<TrackingLayerPainter> create() { return make_scoped_ptr(ne
w TrackingLayerPainter()); } | 1531 static scoped_ptr<TrackingLayerPainter> create() { return make_scoped_ptr(ne
w TrackingLayerPainter()); } |
1424 | 1532 |
1425 virtual void paint(SkCanvas*, const gfx::Rect& contentRect, gfx::RectF&) OVE
RRIDE | 1533 virtual void paint(SkCanvas*, const gfx::Rect& contentRect, gfx::RectF&) OVE
RRIDE |
1426 { | 1534 { |
1427 m_paintedRect = contentRect; | 1535 m_paintedRect = contentRect; |
1428 } | 1536 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 EXPECT_RECT_EQ(gfx::Rect(), layer->trackingLayerPainter()->paintedRect()); | 1620 EXPECT_RECT_EQ(gfx::Rect(), layer->trackingLayerPainter()->paintedRect()); |
1513 updateTextures(); | 1621 updateTextures(); |
1514 | 1622 |
1515 // Invalidate the entire layer in layer space. When painting, the rect given
to webkit should match the layer's bounds. | 1623 // Invalidate the entire layer in layer space. When painting, the rect given
to webkit should match the layer's bounds. |
1516 layer->setNeedsDisplayRect(layerRect); | 1624 layer->setNeedsDisplayRect(layerRect); |
1517 layer->update(*m_queue.get(), 0, m_stats); | 1625 layer->update(*m_queue.get(), 0, m_stats); |
1518 | 1626 |
1519 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); | 1627 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); |
1520 } | 1628 } |
1521 | 1629 |
1522 class TiledLayerPartialUpdateTest : public TiledLayerTest { | |
1523 public: | |
1524 TiledLayerPartialUpdateTest() | |
1525 { | |
1526 m_settings.maxPartialTextureUpdates = 4; | |
1527 } | |
1528 }; | |
1529 | |
1530 TEST_F(TiledLayerPartialUpdateTest, partialUpdates) | |
1531 { | |
1532 // Create one 300 x 200 tiled layer with 3 x 2 tiles. | |
1533 gfx::Size contentBounds(300, 200); | |
1534 gfx::Rect contentRect(gfx::Point(), contentBounds); | |
1535 | |
1536 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_layerTreeHost->contentsTextureManager())); | |
1537 layer->setBounds(contentBounds); | |
1538 layer->setPosition(gfx::PointF(0, 0)); | |
1539 layer->setVisibleContentRect(contentRect); | |
1540 layer->invalidateContentRect(contentRect); | |
1541 | |
1542 m_layerTreeHost->setRootLayer(layer); | |
1543 m_layerTreeHost->setViewportSize(gfx::Size(300, 200), gfx::Size(300, 200)); | |
1544 | |
1545 // Full update of all 6 tiles. | |
1546 m_layerTreeHost->updateLayers( | |
1547 *m_queue.get(), std::numeric_limits<size_t>::max()); | |
1548 { | |
1549 ScopedFakeTiledLayerImpl layerImpl(1); | |
1550 EXPECT_EQ(6, m_queue->fullUploadSize()); | |
1551 EXPECT_EQ(0, m_queue->partialUploadSize()); | |
1552 updateTextures(); | |
1553 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); | |
1554 EXPECT_FALSE(m_queue->hasMoreUpdates()); | |
1555 layer->fakeLayerUpdater()->clearUpdateCount(); | |
1556 layerPushPropertiesTo(layer.get(), layerImpl.get()); | |
1557 } | |
1558 m_layerTreeHost->commitComplete(); | |
1559 | |
1560 // Full update of 3 tiles and partial update of 3 tiles. | |
1561 layer->invalidateContentRect(gfx::Rect(0, 0, 300, 150)); | |
1562 m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::m
ax()); | |
1563 { | |
1564 ScopedFakeTiledLayerImpl layerImpl(1); | |
1565 EXPECT_EQ(3, m_queue->fullUploadSize()); | |
1566 EXPECT_EQ(3, m_queue->partialUploadSize()); | |
1567 updateTextures(); | |
1568 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); | |
1569 EXPECT_FALSE(m_queue->hasMoreUpdates()); | |
1570 layer->fakeLayerUpdater()->clearUpdateCount(); | |
1571 layerPushPropertiesTo(layer.get(), layerImpl.get()); | |
1572 } | |
1573 m_layerTreeHost->commitComplete(); | |
1574 | |
1575 // Partial update of 6 tiles. | |
1576 layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); | |
1577 { | |
1578 ScopedFakeTiledLayerImpl layerImpl(1); | |
1579 m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t
>::max()); | |
1580 EXPECT_EQ(2, m_queue->fullUploadSize()); | |
1581 EXPECT_EQ(4, m_queue->partialUploadSize()); | |
1582 updateTextures(); | |
1583 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); | |
1584 EXPECT_FALSE(m_queue->hasMoreUpdates()); | |
1585 layer->fakeLayerUpdater()->clearUpdateCount(); | |
1586 layerPushPropertiesTo(layer.get(), layerImpl.get()); | |
1587 } | |
1588 m_layerTreeHost->commitComplete(); | |
1589 | |
1590 // Checkerboard all tiles. | |
1591 layer->invalidateContentRect(gfx::Rect(0, 0, 300, 200)); | |
1592 { | |
1593 ScopedFakeTiledLayerImpl layerImpl(1); | |
1594 layerPushPropertiesTo(layer.get(), layerImpl.get()); | |
1595 } | |
1596 m_layerTreeHost->commitComplete(); | |
1597 | |
1598 // Partial update of 6 checkerboard tiles. | |
1599 layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); | |
1600 { | |
1601 ScopedFakeTiledLayerImpl layerImpl(1); | |
1602 m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t
>::max()); | |
1603 EXPECT_EQ(6, m_queue->fullUploadSize()); | |
1604 EXPECT_EQ(0, m_queue->partialUploadSize()); | |
1605 updateTextures(); | |
1606 EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); | |
1607 EXPECT_FALSE(m_queue->hasMoreUpdates()); | |
1608 layer->fakeLayerUpdater()->clearUpdateCount(); | |
1609 layerPushPropertiesTo(layer.get(), layerImpl.get()); | |
1610 } | |
1611 m_layerTreeHost->commitComplete(); | |
1612 | |
1613 // Partial update of 4 tiles. | |
1614 layer->invalidateContentRect(gfx::Rect(50, 50, 100, 100)); | |
1615 { | |
1616 ScopedFakeTiledLayerImpl layerImpl(1); | |
1617 m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t
>::max()); | |
1618 EXPECT_EQ(0, m_queue->fullUploadSize()); | |
1619 EXPECT_EQ(4, m_queue->partialUploadSize()); | |
1620 updateTextures(); | |
1621 EXPECT_EQ(4, layer->fakeLayerUpdater()->updateCount()); | |
1622 EXPECT_FALSE(m_queue->hasMoreUpdates()); | |
1623 layer->fakeLayerUpdater()->clearUpdateCount(); | |
1624 layerPushPropertiesTo(layer.get(), layerImpl.get()); | |
1625 } | |
1626 m_layerTreeHost->commitComplete(); | |
1627 | |
1628 textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_re
sourceProvider.get()); | |
1629 m_layerTreeHost->setRootLayer(0); | |
1630 } | |
1631 | |
1632 } // namespace | 1630 } // namespace |
OLD | NEW |