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 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 961 |
962 class TestOpacityChangeLayerDelegate : public ContentLayerClient { | 962 class TestOpacityChangeLayerDelegate : public ContentLayerClient { |
963 public: | 963 public: |
964 TestOpacityChangeLayerDelegate() : test_layer_(0) {} | 964 TestOpacityChangeLayerDelegate() : test_layer_(0) {} |
965 | 965 |
966 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } | 966 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } |
967 | 967 |
968 virtual void PaintContents( | 968 virtual void PaintContents( |
969 SkCanvas* canvas, | 969 SkCanvas* canvas, |
970 const gfx::Rect& clip, | 970 const gfx::Rect& clip, |
| 971 bool can_paint_lcd_text, |
971 gfx::RectF* opaque, | 972 gfx::RectF* opaque, |
972 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { | 973 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { |
973 // Set layer opacity to 0. | 974 // Set layer opacity to 0. |
974 if (test_layer_) | 975 if (test_layer_) |
975 test_layer_->SetOpacity(0.f); | 976 test_layer_->SetOpacity(0.f); |
976 } | 977 } |
977 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} | 978 virtual bool PaintsLCDText() const OVERRIDE { return false; } |
978 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } | 979 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
979 | 980 |
980 private: | 981 private: |
981 Layer* test_layer_; | 982 Layer* test_layer_; |
982 }; | 983 }; |
983 | 984 |
984 class ContentLayerWithUpdateTracking : public ContentLayer { | 985 class ContentLayerWithUpdateTracking : public ContentLayer { |
985 public: | 986 public: |
986 static scoped_refptr<ContentLayerWithUpdateTracking> Create( | 987 static scoped_refptr<ContentLayerWithUpdateTracking> Create( |
987 ContentLayerClient* client) { | 988 ContentLayerClient* client) { |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 FakeContentLayerClient client_; | 2177 FakeContentLayerClient client_; |
2177 scoped_refptr<FakeContentLayer> root_layer_; | 2178 scoped_refptr<FakeContentLayer> root_layer_; |
2178 scoped_refptr<FakeContentLayer> child_layer1_; | 2179 scoped_refptr<FakeContentLayer> child_layer1_; |
2179 scoped_refptr<FakeContentLayer> child_layer2_; | 2180 scoped_refptr<FakeContentLayer> child_layer2_; |
2180 int num_commits_; | 2181 int num_commits_; |
2181 }; | 2182 }; |
2182 | 2183 |
2183 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 2184 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
2184 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); | 2185 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |
2185 | 2186 |
2186 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { | 2187 class LayerTreeHostTestLCDText : public LayerTreeHostTest { |
2187 public: | 2188 public: |
2188 class NotificationClient : public ContentLayerClient { | 2189 class PaintTracker : public ContentLayerClient { |
2189 public: | 2190 public: |
2190 NotificationClient() | 2191 PaintTracker() : paint_count_(0), did_paint_lcd_text_(false) {} |
2191 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} | |
2192 | 2192 |
2193 void set_layer(Layer* layer) { layer_ = layer; } | |
2194 int paint_count() const { return paint_count_; } | 2193 int paint_count() const { return paint_count_; } |
2195 int lcd_notification_count() const { return lcd_notification_count_; } | 2194 int did_paint_lcd_text() const { return did_paint_lcd_text_; } |
2196 | 2195 |
2197 virtual void PaintContents( | 2196 virtual void PaintContents( |
2198 SkCanvas* canvas, | 2197 SkCanvas* canvas, |
2199 const gfx::Rect& clip, | 2198 const gfx::Rect& clip, |
| 2199 bool can_paint_lcd_text, |
2200 gfx::RectF* opaque, | 2200 gfx::RectF* opaque, |
2201 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { | 2201 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { |
2202 ++paint_count_; | 2202 ++paint_count_; |
| 2203 did_paint_lcd_text_ = can_paint_lcd_text; |
2203 } | 2204 } |
2204 virtual void DidChangeLayerCanUseLCDText() OVERRIDE { | 2205 virtual bool PaintsLCDText() const OVERRIDE { return true; } |
2205 ++lcd_notification_count_; | |
2206 layer_->SetNeedsDisplay(); | |
2207 } | |
2208 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } | 2206 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
2209 | 2207 |
2210 private: | 2208 private: |
2211 Layer* layer_; | |
2212 int paint_count_; | 2209 int paint_count_; |
2213 int lcd_notification_count_; | 2210 bool did_paint_lcd_text_; |
2214 }; | 2211 }; |
2215 | 2212 |
2216 virtual void SetupTree() OVERRIDE { | 2213 virtual void SetupTree() OVERRIDE { |
2217 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_); | 2214 scoped_refptr<Layer> root_layer; |
| 2215 if (layer_tree_host()->settings().impl_side_painting) |
| 2216 root_layer = PictureLayer::Create(&client_); |
| 2217 else |
| 2218 root_layer = ContentLayer::Create(&client_); |
2218 root_layer->SetIsDrawable(true); | 2219 root_layer->SetIsDrawable(true); |
2219 root_layer->SetBounds(gfx::Size(1, 1)); | 2220 root_layer->SetBounds(gfx::Size(1, 1)); |
2220 | |
2221 layer_tree_host()->SetRootLayer(root_layer); | 2221 layer_tree_host()->SetRootLayer(root_layer); |
2222 client_.set_layer(root_layer.get()); | |
2223 | 2222 |
2224 // The expecations are based on the assumption that the default | 2223 // The expecations are based on the assumption that the default |
2225 // LCD settings are: | 2224 // LCD settings are: |
2226 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | 2225 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
2227 EXPECT_FALSE(root_layer->can_use_lcd_text()); | 2226 EXPECT_FALSE(root_layer->can_use_lcd_text()); |
2228 | 2227 |
2229 LayerTreeHostTest::SetupTree(); | 2228 LayerTreeHostTest::SetupTree(); |
2230 } | 2229 } |
2231 | 2230 |
2232 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 2231 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
2233 virtual void AfterTest() OVERRIDE {} | 2232 virtual void AfterTest() OVERRIDE {} |
2234 | 2233 |
2235 virtual void DidCommit() OVERRIDE { | 2234 virtual void DidCommit() OVERRIDE { |
2236 switch (layer_tree_host()->source_frame_number()) { | 2235 switch (layer_tree_host()->source_frame_number()) { |
2237 case 1: | 2236 case 1: |
2238 // The first update consists one LCD notification and one paint. | |
2239 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2240 EXPECT_EQ(1, client_.paint_count()); | |
2241 // LCD text must have been enabled on the layer. | 2237 // LCD text must have been enabled on the layer. |
2242 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2238 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
| 2239 // LCD text must be painted on the first paint. |
| 2240 EXPECT_EQ(1, client_.paint_count()); |
| 2241 EXPECT_TRUE(client_.did_paint_lcd_text()); |
2243 PostSetNeedsCommitToMainThread(); | 2242 PostSetNeedsCommitToMainThread(); |
2244 break; | 2243 break; |
2245 case 2: | 2244 case 2: |
2246 // Since nothing changed on layer, there should be no notification | 2245 // Since nothing changed on layer, there should be paint on the second |
2247 // or paint on the second update. | 2246 // update. |
2248 EXPECT_EQ(1, client_.lcd_notification_count()); | |
2249 EXPECT_EQ(1, client_.paint_count()); | 2247 EXPECT_EQ(1, client_.paint_count()); |
2250 // LCD text must not have changed. | 2248 // LCD text must not have changed. |
2251 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2249 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2252 // Change layer opacity that should trigger lcd notification. | 2250 // Change layer opacity that should trigger lcd change. |
2253 layer_tree_host()->root_layer()->SetOpacity(.5f); | 2251 layer_tree_host()->root_layer()->SetOpacity(.5f); |
2254 // No need to request a commit - setting opacity will do it. | 2252 // No need to request a commit - setting opacity will do it. |
2255 break; | 2253 break; |
2256 default: | 2254 default: |
2257 // Verify that there is not extra commit due to layer invalidation. | 2255 // Verify that there is not extra commit due to layer invalidation. |
2258 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); | 2256 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); |
2259 // LCD notification count should have incremented due to | 2257 // LCD text must have been disabled on the layer due to opacity. |
2260 // change in layer opacity. | 2258 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); |
2261 EXPECT_EQ(2, client_.lcd_notification_count()); | |
2262 // Paint count should be incremented due to invalidation. | 2259 // Paint count should be incremented due to invalidation. |
2263 EXPECT_EQ(2, client_.paint_count()); | 2260 EXPECT_EQ(2, client_.paint_count()); |
2264 // LCD text must have been disabled on the layer due to opacity. | 2261 // Last paint should be without LCD text. |
2265 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); | 2262 EXPECT_FALSE(client_.did_paint_lcd_text()); |
2266 EndTest(); | 2263 EndTest(); |
2267 break; | 2264 break; |
2268 } | 2265 } |
2269 } | 2266 } |
2270 | 2267 |
2271 private: | 2268 private: |
2272 NotificationClient client_; | 2269 PaintTracker client_; |
2273 }; | 2270 }; |
2274 | 2271 |
2275 SINGLE_THREAD_TEST_F(LayerTreeHostTestLCDNotification); | 2272 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDText); |
2276 | 2273 |
2277 // Verify that the BeginFrame notification is used to initiate rendering. | 2274 // Verify that the BeginFrame notification is used to initiate rendering. |
2278 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { | 2275 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |
2279 public: | 2276 public: |
2280 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { | 2277 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
2281 settings->begin_frame_scheduling_enabled = true; | 2278 settings->begin_frame_scheduling_enabled = true; |
2282 } | 2279 } |
2283 | 2280 |
2284 virtual void BeginTest() OVERRIDE { | 2281 virtual void BeginTest() OVERRIDE { |
2285 // This will trigger a SetNeedsBeginFrame which will trigger a | 2282 // This will trigger a SetNeedsBeginFrame which will trigger a |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2433 public: | 2430 public: |
2434 class SetBoundsClient : public ContentLayerClient { | 2431 class SetBoundsClient : public ContentLayerClient { |
2435 public: | 2432 public: |
2436 SetBoundsClient() : layer_(0) {} | 2433 SetBoundsClient() : layer_(0) {} |
2437 | 2434 |
2438 void set_layer(Layer* layer) { layer_ = layer; } | 2435 void set_layer(Layer* layer) { layer_ = layer; } |
2439 | 2436 |
2440 virtual void PaintContents( | 2437 virtual void PaintContents( |
2441 SkCanvas* canvas, | 2438 SkCanvas* canvas, |
2442 const gfx::Rect& clip, | 2439 const gfx::Rect& clip, |
| 2440 bool can_paint_lcd_text, |
2443 gfx::RectF* opaque, | 2441 gfx::RectF* opaque, |
2444 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { | 2442 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { |
2445 layer_->SetBounds(gfx::Size(2, 2)); | 2443 layer_->SetBounds(gfx::Size(2, 2)); |
2446 } | 2444 } |
2447 | 2445 |
2448 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} | 2446 virtual bool PaintsLCDText() const OVERRIDE { return false; } |
2449 | 2447 |
2450 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } | 2448 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
2451 | 2449 |
2452 private: | 2450 private: |
2453 Layer* layer_; | 2451 Layer* layer_; |
2454 }; | 2452 }; |
2455 | 2453 |
2456 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} | 2454 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} |
2457 | 2455 |
2458 virtual void SetupTree() OVERRIDE { | 2456 virtual void SetupTree() OVERRIDE { |
(...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4902 const gfx::Size bounds_; | 4900 const gfx::Size bounds_; |
4903 FakeContentLayerClient client_; | 4901 FakeContentLayerClient client_; |
4904 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; | 4902 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; |
4905 scoped_refptr<FakePictureLayer> picture_layer_; | 4903 scoped_refptr<FakePictureLayer> picture_layer_; |
4906 Layer* child_layer_; | 4904 Layer* child_layer_; |
4907 }; | 4905 }; |
4908 | 4906 |
4909 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); | 4907 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); |
4910 | 4908 |
4911 } // namespace cc | 4909 } // namespace cc |
OLD | NEW |