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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_unittest.cc
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc
index fa97e9d163c5a254dffa8c1b3ad66b6d4dc255a1..9970033c2e7544c54c1a82aab5366c5d28f94f59 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -1093,7 +1093,6 @@ class TestOpacityChangeLayerDelegate : public ContentLayerClient {
if (test_layer_)
test_layer_->SetOpacity(0.f);
}
- void DidChangeLayerCanUseLCDText() override {}
bool FillsBoundsCompletely() const override { return false; }
private:
@@ -2278,14 +2277,15 @@ class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted
SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted);
-class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
+class LayerTreeHostTestLcdNotification : public LayerTreeHostTest {
public:
class NotificationClient : public ContentLayerClient {
public:
NotificationClient()
- : layer_(0), paint_count_(0), lcd_notification_count_(0) {}
+ : layer_(nullptr), paint_count_(0), lcd_notification_count_(0) {}
void set_layer(Layer* layer) { layer_ = layer; }
+
int paint_count() const { return paint_count_; }
int lcd_notification_count() const { return lcd_notification_count_; }
@@ -2295,10 +2295,12 @@ class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
ContentLayerClient::GraphicsContextStatus gc_status) override {
++paint_count_;
}
- void DidChangeLayerCanUseLCDText() override {
+
+ void DidChangeLayerCanUseLcdText() override {
++lcd_notification_count_;
layer_->SetNeedsDisplay();
}
+
bool FillsBoundsCompletely() const override { return false; }
private:
@@ -2313,11 +2315,11 @@ class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
root_layer = PictureLayer::Create(&client_);
else
root_layer = ContentLayer::Create(&client_);
+ client_.set_layer(root_layer.get());
root_layer->SetIsDrawable(true);
root_layer->SetBounds(gfx::Size(1, 1));
layer_tree_host()->SetRootLayer(root_layer);
- client_.set_layer(root_layer.get());
// The expecations are based on the assumption that the default
// LCD settings are:
@@ -2333,8 +2335,8 @@ class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
void DidCommit() override {
switch (layer_tree_host()->source_frame_number()) {
case 1:
- // The first update consists of one LCD notification and one paint.
- EXPECT_EQ(1, client_.lcd_notification_count());
+ // The first update consists of a paint, without a notification.
+ EXPECT_EQ(0, client_.lcd_notification_count());
EXPECT_EQ(1, client_.paint_count());
// LCD text must have been enabled on the layer.
EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
@@ -2343,24 +2345,31 @@ class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
case 2:
// Since nothing changed on layer, there should be no notification
// or paint on the second update.
- EXPECT_EQ(1, client_.lcd_notification_count());
+ EXPECT_EQ(0, client_.lcd_notification_count());
EXPECT_EQ(1, client_.paint_count());
// LCD text must not have changed.
EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
- // Change layer opacity that should trigger lcd notification.
+ // Change layer opacity that should trigger lcd change.
layer_tree_host()->root_layer()->SetOpacity(.5f);
- // No need to request a commit - setting opacity will do it.
break;
- default:
- // Verify that there is no extra commit due to layer invalidation.
- EXPECT_EQ(3, layer_tree_host()->source_frame_number());
+ case 3:
// LCD notification count should have incremented due to
// change in layer opacity.
- EXPECT_EQ(2, client_.lcd_notification_count());
+ EXPECT_EQ(1, client_.lcd_notification_count());
// Paint count should be incremented due to invalidation.
EXPECT_EQ(2, client_.paint_count());
// LCD text must have been disabled on the layer due to opacity.
EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text());
+ // Change layer opacity that should not trigger lcd change.
+ layer_tree_host()->root_layer()->SetOpacity(1.f);
+ break;
+ case 4:
+ // Since nothing changed on layer, there should be no notification or
+ // paint.
+ EXPECT_EQ(1, client_.lcd_notification_count());
+ EXPECT_EQ(2, client_.paint_count());
+ // Even though LCD text could be allowed.
+ EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
EndTest();
break;
}
@@ -2370,7 +2379,74 @@ class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
NotificationClient client_;
};
-SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification);
+SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLcdNotification);
+
+class LayerTreeHostTestLcdInvalidationNoExtraCommit : public LayerTreeHostTest {
+ public:
+ class InvalidationClient : public ContentLayerClient {
+ public:
+ InvalidationClient() : layer_(nullptr) {}
+
+ void set_layer(Layer* layer) { layer_ = layer; }
+
+ void PaintContents(
+ SkCanvas* canvas,
+ const gfx::Rect& clip,
+ ContentLayerClient::GraphicsContextStatus gc_status) override {}
+
+ void DidChangeLayerCanUseLcdText() override { layer_->SetNeedsDisplay(); }
+
+ bool FillsBoundsCompletely() const override { return false; }
+
+ private:
+ Layer* layer_;
+ };
+
+ void SetupTree() override {
+ scoped_refptr<Layer> root_layer;
+ if (layer_tree_host()->settings().impl_side_painting)
+ root_layer = PictureLayer::Create(&client_);
+ else
+ root_layer = ContentLayer::Create(&client_);
+ client_.set_layer(root_layer.get());
+ root_layer->SetIsDrawable(true);
+ root_layer->SetBounds(gfx::Size(1, 1));
+
+ layer_tree_host()->SetRootLayer(root_layer);
+
+ // The expecations are based on the assumption that the default
+ // LCD settings are:
+ EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
+ EXPECT_FALSE(root_layer->can_use_lcd_text());
+
+ LayerTreeHostTest::SetupTree();
+ }
+
+ void BeginTest() override { PostSetNeedsCommitToMainThread(); }
+ void AfterTest() override {}
+
+ void DidCommit() override {
+ switch (layer_tree_host()->source_frame_number()) {
+ case 1:
+ EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
+ layer_tree_host()->root_layer()->SetOpacity(.5f);
+ break;
+ case 2:
+ EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text());
+ EndTest();
+ break;
+ case 3:
+ // Verify that there is no extra commit due to layer invalidation.
+ ADD_FAILURE() << "Extra commit happened due to LCD text change";
+ break;
+ }
+ }
+
+ private:
+ InvalidationClient client_;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLcdInvalidationNoExtraCommit);
// Verify that the BeginFrame notification is used to initiate rendering.
class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest {
@@ -2541,8 +2617,6 @@ class LayerTreeHostTestChangeLayerPropertiesInPaintContents
layer_->SetBounds(gfx::Size(2, 2));
}
- void DidChangeLayerCanUseLCDText() override {}
-
bool FillsBoundsCompletely() const override { return false; }
private:

Powered by Google App Engine
This is Rietveld 408576698