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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 | 936 |
937 class TestOpacityChangeLayerDelegate : public ContentLayerClient { | 937 class TestOpacityChangeLayerDelegate : public ContentLayerClient { |
938 public: | 938 public: |
939 TestOpacityChangeLayerDelegate() : test_layer_(0) {} | 939 TestOpacityChangeLayerDelegate() : test_layer_(0) {} |
940 | 940 |
941 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } | 941 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } |
942 | 942 |
943 void PaintContents( | 943 void PaintContents( |
944 SkCanvas* canvas, | 944 SkCanvas* canvas, |
945 const gfx::Rect& clip, | 945 const gfx::Rect& clip, |
| 946 bool can_use_lcd_text, |
| 947 bool contents_opaque, |
946 ContentLayerClient::GraphicsContextStatus gc_status) override { | 948 ContentLayerClient::GraphicsContextStatus gc_status) override { |
947 // Set layer opacity to 0. | 949 // Set layer opacity to 0. |
948 if (test_layer_) | 950 if (test_layer_) |
949 test_layer_->SetOpacity(0.f); | 951 test_layer_->SetOpacity(0.f); |
950 } | 952 } |
951 void DidChangeLayerCanUseLCDText() override {} | |
952 bool FillsBoundsCompletely() const override { return false; } | 953 bool FillsBoundsCompletely() const override { return false; } |
953 | 954 |
954 private: | 955 private: |
955 Layer* test_layer_; | 956 Layer* test_layer_; |
956 }; | 957 }; |
957 | 958 |
958 class ContentLayerWithUpdateTracking : public ContentLayer { | 959 class ContentLayerWithUpdateTracking : public ContentLayer { |
959 public: | 960 public: |
960 static scoped_refptr<ContentLayerWithUpdateTracking> Create( | 961 static scoped_refptr<ContentLayerWithUpdateTracking> Create( |
961 ContentLayerClient* client) { | 962 ContentLayerClient* client) { |
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2122 FakeContentLayerClient client_; | 2123 FakeContentLayerClient client_; |
2123 scoped_refptr<FakeContentLayer> root_layer_; | 2124 scoped_refptr<FakeContentLayer> root_layer_; |
2124 scoped_refptr<FakeContentLayer> child_layer1_; | 2125 scoped_refptr<FakeContentLayer> child_layer1_; |
2125 scoped_refptr<FakeContentLayer> child_layer2_; | 2126 scoped_refptr<FakeContentLayer> child_layer2_; |
2126 int num_commits_; | 2127 int num_commits_; |
2127 }; | 2128 }; |
2128 | 2129 |
2129 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 2130 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
2130 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); | 2131 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |
2131 | 2132 |
2132 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { | 2133 class LayerTreeHostTestLCDText : public LayerTreeHostTest { |
2133 public: | 2134 public: |
2134 class NotificationClient : public ContentLayerClient { | 2135 class TextClient : public ContentLayerClient { |
2135 public: | 2136 public: |
2136 NotificationClient() | 2137 TextClient() : layer_(0), paint_count_(0), last_can_use_lcd_text_(false) {} |
2137 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} | |
2138 | 2138 |
2139 void set_layer(Layer* layer) { layer_ = layer; } | 2139 void set_layer(Layer* layer) { layer_ = layer; } |
2140 int paint_count() const { return paint_count_; } | 2140 int paint_count() const { return paint_count_; } |
2141 int lcd_notification_count() const { return lcd_notification_count_; } | 2141 int last_can_use_lcd_text() const { return last_can_use_lcd_text_; } |
| 2142 gfx::Rect last_paint_rect() const { return last_paint_rect_; } |
2142 | 2143 |
2143 void PaintContents( | 2144 void PaintContents( |
2144 SkCanvas* canvas, | 2145 SkCanvas* canvas, |
2145 const gfx::Rect& clip, | 2146 const gfx::Rect& paint_rect, |
| 2147 bool can_use_lcd_text, |
| 2148 bool contents_opaque, |
2146 ContentLayerClient::GraphicsContextStatus gc_status) override { | 2149 ContentLayerClient::GraphicsContextStatus gc_status) override { |
2147 ++paint_count_; | 2150 ++paint_count_; |
2148 } | 2151 last_can_use_lcd_text_ = can_use_lcd_text; |
2149 void DidChangeLayerCanUseLCDText() override { | 2152 last_paint_rect_ = paint_rect; |
2150 ++lcd_notification_count_; | |
2151 layer_->SetNeedsDisplay(); | |
2152 } | 2153 } |
2153 bool FillsBoundsCompletely() const override { return false; } | 2154 bool FillsBoundsCompletely() const override { return false; } |
2154 | 2155 |
2155 private: | 2156 private: |
2156 Layer* layer_; | 2157 Layer* layer_; |
2157 int paint_count_; | 2158 int paint_count_; |
2158 int lcd_notification_count_; | 2159 bool last_can_use_lcd_text_; |
| 2160 gfx::Rect last_paint_rect_; |
2159 }; | 2161 }; |
2160 | 2162 |
2161 void SetupTree() override { | 2163 void SetupTree() override { |
2162 scoped_refptr<Layer> root_layer; | 2164 scoped_refptr<Layer> root_layer; |
2163 if (layer_tree_host()->settings().impl_side_painting) | 2165 if (layer_tree_host()->settings().impl_side_painting) |
2164 root_layer = PictureLayer::Create(&client_); | 2166 root_layer = PictureLayer::Create(&client_); |
2165 else | 2167 else |
2166 root_layer = ContentLayer::Create(&client_); | 2168 root_layer = ContentLayer::Create(&client_); |
2167 root_layer->SetIsDrawable(true); | 2169 root_layer->SetIsDrawable(true); |
2168 root_layer->SetBounds(gfx::Size(1, 1)); | 2170 root_layer->SetBounds(gfx::Size(10, 10)); |
2169 | 2171 |
2170 layer_tree_host()->SetRootLayer(root_layer); | 2172 layer_tree_host()->SetRootLayer(root_layer); |
2171 client_.set_layer(root_layer.get()); | 2173 client_.set_layer(root_layer.get()); |
2172 | 2174 |
2173 // The expecations are based on the assumption that the default | 2175 // The expecations are based on the assumption that the default |
2174 // LCD settings are: | 2176 // LCD settings are: |
2175 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | 2177 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
2176 EXPECT_FALSE(root_layer->can_use_lcd_text()); | 2178 EXPECT_FALSE(root_layer->can_use_lcd_text()); |
2177 | 2179 |
2178 LayerTreeHostTest::SetupTree(); | 2180 LayerTreeHostTest::SetupTree(); |
2179 } | 2181 } |
2180 | 2182 |
2181 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 2183 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
2182 void AfterTest() override {} | 2184 void AfterTest() override {} |
2183 | 2185 |
2184 void DidCommit() override { | 2186 void DidCommit() override { |
2185 switch (layer_tree_host()->source_frame_number()) { | 2187 switch (layer_tree_host()->source_frame_number()) { |
2186 case 1: | 2188 case 1: |
2187 // The first update consists of one LCD notification and one paint. | 2189 // The first update was the whole layer, and with lcd text. |
2188 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2189 EXPECT_EQ(1, client_.paint_count()); | 2190 EXPECT_EQ(1, client_.paint_count()); |
| 2191 EXPECT_TRUE(client_.last_can_use_lcd_text()); |
| 2192 EXPECT_TRUE(client_.last_paint_rect().Contains(gfx::Rect(10, 10))); |
2190 // LCD text must have been enabled on the layer. | 2193 // LCD text must have been enabled on the layer. |
2191 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2194 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2192 PostSetNeedsCommitToMainThread(); | 2195 layer_tree_host()->SetNeedsCommit(); |
2193 break; | 2196 break; |
2194 case 2: | 2197 case 2: |
2195 // Since nothing changed on layer, there should be no notification | 2198 // Since nothing changed on layer, there should be no paint on the |
2196 // or paint on the second update. | 2199 // second update. |
2197 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2198 EXPECT_EQ(1, client_.paint_count()); | 2200 EXPECT_EQ(1, client_.paint_count()); |
2199 // LCD text must not have changed. | 2201 // LCD text must not have changed. |
2200 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2202 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2201 // Change layer opacity that should trigger lcd notification. | 2203 // Change layer opacity that should trigger lcd notification, but would |
| 2204 // not normally invalidate causing a paint. |
2202 layer_tree_host()->root_layer()->SetOpacity(.5f); | 2205 layer_tree_host()->root_layer()->SetOpacity(.5f); |
2203 // No need to request a commit - setting opacity will do it. | 2206 // No need to request a commit - setting opacity will do it. |
2204 break; | 2207 break; |
2205 default: | 2208 case 3: |
2206 // Verify that there is no extra commit due to layer invalidation. | 2209 // Paint count should be incremented due to the LCD change. |
2207 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); | |
2208 // LCD notification count should have incremented due to | |
2209 // change in layer opacity. | |
2210 EXPECT_EQ(2, client_.lcd_notification_count()); | |
2211 // Paint count should be incremented due to invalidation. | |
2212 EXPECT_EQ(2, client_.paint_count()); | 2210 EXPECT_EQ(2, client_.paint_count()); |
| 2211 // The paint was not done with LCD text enabled. |
| 2212 EXPECT_FALSE(client_.last_can_use_lcd_text()); |
| 2213 // And the whole layer was invalidated and repainted. |
| 2214 EXPECT_TRUE(client_.last_paint_rect().Contains(gfx::Rect(10, 10))); |
2213 // LCD text must have been disabled on the layer due to opacity. | 2215 // LCD text must have been disabled on the layer due to opacity. |
2214 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2216 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2215 EndTest(); | 2217 EndTest(); |
2216 break; | 2218 break; |
| 2219 case 4: |
| 2220 // Verify that there is no extra commit due to layer invalidation. |
| 2221 EXPECT_TRUE(false); |
| 2222 break; |
2217 } | 2223 } |
2218 } | 2224 } |
2219 | 2225 |
2220 private: | 2226 private: |
2221 NotificationClient client_; | 2227 TextClient client_; |
2222 }; | 2228 }; |
2223 | 2229 |
2224 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification); | 2230 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDText); |
2225 | 2231 |
2226 // Verify that the BeginFrame notification is used to initiate rendering. | 2232 // Verify that the BeginFrame notification is used to initiate rendering. |
2227 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { | 2233 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |
2228 public: | 2234 public: |
2229 void InitializeSettings(LayerTreeSettings* settings) override { | 2235 void InitializeSettings(LayerTreeSettings* settings) override { |
2230 settings->begin_frame_scheduling_enabled = true; | 2236 settings->begin_frame_scheduling_enabled = true; |
2231 } | 2237 } |
2232 | 2238 |
2233 void BeginTest() override { | 2239 void BeginTest() override { |
2234 // This will trigger a SetNeedsBeginFrame which will trigger a | 2240 // This will trigger a SetNeedsBeginFrame which will trigger a |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 public: | 2387 public: |
2382 class SetBoundsClient : public ContentLayerClient { | 2388 class SetBoundsClient : public ContentLayerClient { |
2383 public: | 2389 public: |
2384 SetBoundsClient() : layer_(0) {} | 2390 SetBoundsClient() : layer_(0) {} |
2385 | 2391 |
2386 void set_layer(Layer* layer) { layer_ = layer; } | 2392 void set_layer(Layer* layer) { layer_ = layer; } |
2387 | 2393 |
2388 void PaintContents( | 2394 void PaintContents( |
2389 SkCanvas* canvas, | 2395 SkCanvas* canvas, |
2390 const gfx::Rect& clip, | 2396 const gfx::Rect& clip, |
| 2397 bool can_use_lcd_text, |
| 2398 bool contents_opaque, |
2391 ContentLayerClient::GraphicsContextStatus gc_status) override { | 2399 ContentLayerClient::GraphicsContextStatus gc_status) override { |
2392 layer_->SetBounds(gfx::Size(2, 2)); | 2400 layer_->SetBounds(gfx::Size(2, 2)); |
2393 } | 2401 } |
2394 | 2402 |
2395 void DidChangeLayerCanUseLCDText() override {} | |
2396 | |
2397 bool FillsBoundsCompletely() const override { return false; } | 2403 bool FillsBoundsCompletely() const override { return false; } |
2398 | 2404 |
2399 private: | 2405 private: |
2400 Layer* layer_; | 2406 Layer* layer_; |
2401 }; | 2407 }; |
2402 | 2408 |
2403 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} | 2409 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} |
2404 | 2410 |
2405 void SetupTree() override { | 2411 void SetupTree() override { |
2406 if (layer_tree_host()->settings().impl_side_painting) { | 2412 if (layer_tree_host()->settings().impl_side_painting) { |
(...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5199 void AfterTest() override { | 5205 void AfterTest() override { |
5200 EXPECT_TRUE(deltas_sent_to_client_); | 5206 EXPECT_TRUE(deltas_sent_to_client_); |
5201 } | 5207 } |
5202 | 5208 |
5203 ScrollAndScaleSet info_; | 5209 ScrollAndScaleSet info_; |
5204 bool deltas_sent_to_client_; | 5210 bool deltas_sent_to_client_; |
5205 }; | 5211 }; |
5206 | 5212 |
5207 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); | 5213 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); |
5208 } // namespace cc | 5214 } // namespace cc |
OLD | NEW |