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

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 684543006: cc: Toggle LCD text at raster time instead of record time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcdraster: header Created 6 years, 1 month 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
OLDNEW
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 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } 1086 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; }
1087 1087
1088 void PaintContents( 1088 void PaintContents(
1089 SkCanvas* canvas, 1089 SkCanvas* canvas,
1090 const gfx::Rect& clip, 1090 const gfx::Rect& clip,
1091 ContentLayerClient::GraphicsContextStatus gc_status) override { 1091 ContentLayerClient::GraphicsContextStatus gc_status) override {
1092 // Set layer opacity to 0. 1092 // Set layer opacity to 0.
1093 if (test_layer_) 1093 if (test_layer_)
1094 test_layer_->SetOpacity(0.f); 1094 test_layer_->SetOpacity(0.f);
1095 } 1095 }
1096 void DidChangeLayerCanUseLCDText() override {}
1097 bool FillsBoundsCompletely() const override { return false; } 1096 bool FillsBoundsCompletely() const override { return false; }
1098 1097
1099 private: 1098 private:
1100 Layer* test_layer_; 1099 Layer* test_layer_;
1101 }; 1100 };
1102 1101
1103 class ContentLayerWithUpdateTracking : public ContentLayer { 1102 class ContentLayerWithUpdateTracking : public ContentLayer {
1104 public: 1103 public:
1105 static scoped_refptr<ContentLayerWithUpdateTracking> Create( 1104 static scoped_refptr<ContentLayerWithUpdateTracking> Create(
1106 ContentLayerClient* client) { 1105 ContentLayerClient* client) {
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 FakeContentLayerClient client_; 2270 FakeContentLayerClient client_;
2272 scoped_refptr<FakeContentLayer> root_layer_; 2271 scoped_refptr<FakeContentLayer> root_layer_;
2273 scoped_refptr<FakeContentLayer> child_layer1_; 2272 scoped_refptr<FakeContentLayer> child_layer1_;
2274 scoped_refptr<FakeContentLayer> child_layer2_; 2273 scoped_refptr<FakeContentLayer> child_layer2_;
2275 int num_commits_; 2274 int num_commits_;
2276 }; 2275 };
2277 2276
2278 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( 2277 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
2279 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); 2278 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted);
2280 2279
2281 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { 2280 class LayerTreeHostTestLcdNotification : public LayerTreeHostTest {
2282 public: 2281 public:
2283 class NotificationClient : public ContentLayerClient { 2282 class NotificationClient : public ContentLayerClient {
2284 public: 2283 public:
2285 NotificationClient() 2284 NotificationClient()
2286 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} 2285 : layer_(nullptr), paint_count_(0), lcd_notification_count_(0) {}
2287 2286
2288 void set_layer(Layer* layer) { layer_ = layer; } 2287 void set_layer(Layer* layer) { layer_ = layer; }
2288
2289 int paint_count() const { return paint_count_; } 2289 int paint_count() const { return paint_count_; }
2290 int lcd_notification_count() const { return lcd_notification_count_; } 2290 int lcd_notification_count() const { return lcd_notification_count_; }
2291 2291
2292 void PaintContents( 2292 void PaintContents(
2293 SkCanvas* canvas, 2293 SkCanvas* canvas,
2294 const gfx::Rect& clip, 2294 const gfx::Rect& clip,
2295 ContentLayerClient::GraphicsContextStatus gc_status) override { 2295 ContentLayerClient::GraphicsContextStatus gc_status) override {
2296 ++paint_count_; 2296 ++paint_count_;
2297 } 2297 }
2298 void DidChangeLayerCanUseLCDText() override { 2298
2299 void DidChangeLayerCanUseLcdText() override {
2299 ++lcd_notification_count_; 2300 ++lcd_notification_count_;
2300 layer_->SetNeedsDisplay(); 2301 layer_->SetNeedsDisplay();
2301 } 2302 }
2303
2302 bool FillsBoundsCompletely() const override { return false; } 2304 bool FillsBoundsCompletely() const override { return false; }
2303 2305
2304 private: 2306 private:
2305 Layer* layer_; 2307 Layer* layer_;
2306 int paint_count_; 2308 int paint_count_;
2307 int lcd_notification_count_; 2309 int lcd_notification_count_;
2308 }; 2310 };
2309 2311
2310 void SetupTree() override { 2312 void SetupTree() override {
2311 scoped_refptr<Layer> root_layer; 2313 scoped_refptr<Layer> root_layer;
2312 if (layer_tree_host()->settings().impl_side_painting) 2314 if (layer_tree_host()->settings().impl_side_painting)
2313 root_layer = PictureLayer::Create(&client_); 2315 root_layer = PictureLayer::Create(&client_);
2314 else 2316 else
2315 root_layer = ContentLayer::Create(&client_); 2317 root_layer = ContentLayer::Create(&client_);
2318 client_.set_layer(root_layer.get());
2316 root_layer->SetIsDrawable(true); 2319 root_layer->SetIsDrawable(true);
2317 root_layer->SetBounds(gfx::Size(1, 1)); 2320 root_layer->SetBounds(gfx::Size(1, 1));
2318 2321
2319 layer_tree_host()->SetRootLayer(root_layer); 2322 layer_tree_host()->SetRootLayer(root_layer);
2320 client_.set_layer(root_layer.get());
2321 2323
2322 // The expecations are based on the assumption that the default 2324 // The expecations are based on the assumption that the default
2323 // LCD settings are: 2325 // LCD settings are:
2324 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); 2326 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
2325 EXPECT_FALSE(root_layer->can_use_lcd_text()); 2327 EXPECT_FALSE(root_layer->can_use_lcd_text());
2326 2328
2327 LayerTreeHostTest::SetupTree(); 2329 LayerTreeHostTest::SetupTree();
2328 } 2330 }
2329 2331
2330 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2332 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2331 void AfterTest() override {} 2333 void AfterTest() override {}
2332 2334
2333 void DidCommit() override { 2335 void DidCommit() override {
2334 switch (layer_tree_host()->source_frame_number()) { 2336 switch (layer_tree_host()->source_frame_number()) {
2335 case 1: 2337 case 1:
2336 // The first update consists of one LCD notification and one paint. 2338 // The first update consists of a paint, without a notification.
2337 EXPECT_EQ(1, client_.lcd_notification_count()); 2339 EXPECT_EQ(0, client_.lcd_notification_count());
2338 EXPECT_EQ(1, client_.paint_count()); 2340 EXPECT_EQ(1, client_.paint_count());
2339 // LCD text must have been enabled on the layer. 2341 // LCD text must have been enabled on the layer.
2340 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2342 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2341 PostSetNeedsCommitToMainThread(); 2343 PostSetNeedsCommitToMainThread();
2342 break; 2344 break;
2343 case 2: 2345 case 2:
2344 // Since nothing changed on layer, there should be no notification 2346 // Since nothing changed on layer, there should be no notification
2345 // or paint on the second update. 2347 // or paint on the second update.
2346 EXPECT_EQ(1, client_.lcd_notification_count()); 2348 EXPECT_EQ(0, client_.lcd_notification_count());
2347 EXPECT_EQ(1, client_.paint_count()); 2349 EXPECT_EQ(1, client_.paint_count());
2348 // LCD text must not have changed. 2350 // LCD text must not have changed.
2349 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2351 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2350 // Change layer opacity that should trigger lcd notification. 2352 // Change layer opacity that should trigger lcd change.
2351 layer_tree_host()->root_layer()->SetOpacity(.5f); 2353 layer_tree_host()->root_layer()->SetOpacity(.5f);
2352 // No need to request a commit - setting opacity will do it.
2353 break; 2354 break;
2354 default: 2355 case 3:
2355 // Verify that there is no extra commit due to layer invalidation.
2356 EXPECT_EQ(3, layer_tree_host()->source_frame_number());
2357 // LCD notification count should have incremented due to 2356 // LCD notification count should have incremented due to
2358 // change in layer opacity. 2357 // change in layer opacity.
2359 EXPECT_EQ(2, client_.lcd_notification_count()); 2358 EXPECT_EQ(1, client_.lcd_notification_count());
2360 // Paint count should be incremented due to invalidation. 2359 // Paint count should be incremented due to invalidation.
2361 EXPECT_EQ(2, client_.paint_count()); 2360 EXPECT_EQ(2, client_.paint_count());
2362 // LCD text must have been disabled on the layer due to opacity. 2361 // LCD text must have been disabled on the layer due to opacity.
2363 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2362 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text());
2363 // Change layer opacity that should not trigger lcd change.
2364 layer_tree_host()->root_layer()->SetOpacity(1.f);
2365 break;
2366 case 4:
2367 // Since nothing changed on layer, there should be no notification or
2368 // paint.
2369 EXPECT_EQ(1, client_.lcd_notification_count());
2370 EXPECT_EQ(2, client_.paint_count());
2371 // Even though LCD text could be allowed.
2372 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2364 EndTest(); 2373 EndTest();
2365 break; 2374 break;
2366 } 2375 }
2367 } 2376 }
2368 2377
2369 private: 2378 private:
2370 NotificationClient client_; 2379 NotificationClient client_;
2371 }; 2380 };
2372 2381
2373 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification); 2382 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLcdNotification);
2383
2384 class LayerTreeHostTestLcdInvalidationNoExtraCommit : public LayerTreeHostTest {
2385 public:
2386 class InvalidationClient : public ContentLayerClient {
2387 public:
2388 InvalidationClient() : layer_(nullptr) {}
2389
2390 void set_layer(Layer* layer) { layer_ = layer; }
2391
2392 void PaintContents(
2393 SkCanvas* canvas,
2394 const gfx::Rect& clip,
2395 ContentLayerClient::GraphicsContextStatus gc_status) override {}
2396
2397 void DidChangeLayerCanUseLcdText() override { layer_->SetNeedsDisplay(); }
2398
2399 bool FillsBoundsCompletely() const override { return false; }
2400
2401 private:
2402 Layer* layer_;
2403 };
2404
2405 void SetupTree() override {
2406 scoped_refptr<Layer> root_layer;
2407 if (layer_tree_host()->settings().impl_side_painting)
2408 root_layer = PictureLayer::Create(&client_);
2409 else
2410 root_layer = ContentLayer::Create(&client_);
2411 client_.set_layer(root_layer.get());
2412 root_layer->SetIsDrawable(true);
2413 root_layer->SetBounds(gfx::Size(1, 1));
2414
2415 layer_tree_host()->SetRootLayer(root_layer);
2416
2417 // The expecations are based on the assumption that the default
2418 // LCD settings are:
2419 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
2420 EXPECT_FALSE(root_layer->can_use_lcd_text());
2421
2422 LayerTreeHostTest::SetupTree();
2423 }
2424
2425 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2426 void AfterTest() override {}
2427
2428 void DidCommit() override {
2429 switch (layer_tree_host()->source_frame_number()) {
2430 case 1:
2431 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2432 layer_tree_host()->root_layer()->SetOpacity(.5f);
2433 break;
2434 case 2:
2435 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text());
2436 EndTest();
2437 break;
2438 case 3:
2439 // Verify that there is no extra commit due to layer invalidation.
2440 ADD_FAILURE() << "Extra commit happened due to LCD text change";
2441 break;
2442 }
2443 }
2444
2445 private:
2446 InvalidationClient client_;
2447 };
2448
2449 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLcdInvalidationNoExtraCommit);
2374 2450
2375 // Verify that the BeginFrame notification is used to initiate rendering. 2451 // Verify that the BeginFrame notification is used to initiate rendering.
2376 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { 2452 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest {
2377 public: 2453 public:
2378 void InitializeSettings(LayerTreeSettings* settings) override { 2454 void InitializeSettings(LayerTreeSettings* settings) override {
2379 settings->use_external_begin_frame_source = true; 2455 settings->use_external_begin_frame_source = true;
2380 } 2456 }
2381 2457
2382 void BeginTest() override { 2458 void BeginTest() override {
2383 // This will trigger a SetNeedsBeginFrame which will trigger a 2459 // This will trigger a SetNeedsBeginFrame which will trigger a
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 2610
2535 void set_layer(Layer* layer) { layer_ = layer; } 2611 void set_layer(Layer* layer) { layer_ = layer; }
2536 2612
2537 void PaintContents( 2613 void PaintContents(
2538 SkCanvas* canvas, 2614 SkCanvas* canvas,
2539 const gfx::Rect& clip, 2615 const gfx::Rect& clip,
2540 ContentLayerClient::GraphicsContextStatus gc_status) override { 2616 ContentLayerClient::GraphicsContextStatus gc_status) override {
2541 layer_->SetBounds(gfx::Size(2, 2)); 2617 layer_->SetBounds(gfx::Size(2, 2));
2542 } 2618 }
2543 2619
2544 void DidChangeLayerCanUseLCDText() override {}
2545
2546 bool FillsBoundsCompletely() const override { return false; } 2620 bool FillsBoundsCompletely() const override { return false; }
2547 2621
2548 private: 2622 private:
2549 Layer* layer_; 2623 Layer* layer_;
2550 }; 2624 };
2551 2625
2552 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} 2626 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {}
2553 2627
2554 void SetupTree() override { 2628 void SetupTree() override {
2555 if (layer_tree_host()->settings().impl_side_painting) { 2629 if (layer_tree_host()->settings().impl_side_painting) {
(...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after
5348 void AfterTest() override { 5422 void AfterTest() override {
5349 EXPECT_TRUE(deltas_sent_to_client_); 5423 EXPECT_TRUE(deltas_sent_to_client_);
5350 } 5424 }
5351 5425
5352 ScrollAndScaleSet info_; 5426 ScrollAndScaleSet info_;
5353 bool deltas_sent_to_client_; 5427 bool deltas_sent_to_client_;
5354 }; 5428 };
5355 5429
5356 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); 5430 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer);
5357 } // namespace cc 5431 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698