| 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 870f2df5f89f1a459c9433eb894d1cb52a8eb2d0..7c7a26b9fb979f3c026d76e84df01147f975688d 100644
|
| --- a/cc/trees/layer_tree_host_unittest.cc
|
| +++ b/cc/trees/layer_tree_host_unittest.cc
|
| @@ -971,13 +971,14 @@ class TestOpacityChangeLayerDelegate : public ContentLayerClient {
|
| virtual void PaintContents(
|
| SkCanvas* canvas,
|
| const gfx::Rect& clip,
|
| + bool can_paint_lcd_text,
|
| gfx::RectF* opaque,
|
| ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {
|
| // Set layer opacity to 0.
|
| if (test_layer_)
|
| test_layer_->SetOpacity(0.f);
|
| }
|
| - virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
|
| + virtual bool PaintsLCDText() const OVERRIDE { return false; }
|
| virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
|
|
|
| private:
|
| @@ -2182,50 +2183,60 @@ class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted
|
| SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
|
| LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted);
|
|
|
| -class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
|
| +class LayerTreeHostTestLCDText : public LayerTreeHostTest {
|
| public:
|
| - class NotificationClient : public ContentLayerClient {
|
| + class LCDTextClient : public ContentLayerClient {
|
| public:
|
| - NotificationClient()
|
| - : layer_(0), paint_count_(0), lcd_notification_count_(0) {}
|
| + LCDTextClient(bool paints_lcd_text)
|
| + : paints_lcd_text_(paints_lcd_text),
|
| + paint_count_(0),
|
| + could_paint_lcd_text_last_frame_(false) {}
|
|
|
| - void set_layer(Layer* layer) { layer_ = layer; }
|
| int paint_count() const { return paint_count_; }
|
| - int lcd_notification_count() const { return lcd_notification_count_; }
|
| + int could_paint_lcd_text_last_frame() const {
|
| + return could_paint_lcd_text_last_frame_;
|
| + }
|
|
|
| virtual void PaintContents(
|
| SkCanvas* canvas,
|
| const gfx::Rect& clip,
|
| + bool can_paint_lcd_text,
|
| gfx::RectF* opaque,
|
| ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {
|
| ++paint_count_;
|
| + could_paint_lcd_text_last_frame_ = can_paint_lcd_text;
|
| }
|
| - virtual void DidChangeLayerCanUseLCDText() OVERRIDE {
|
| - ++lcd_notification_count_;
|
| - layer_->SetNeedsDisplay();
|
| - }
|
| + virtual bool PaintsLCDText() const OVERRIDE { return paints_lcd_text_; }
|
| virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
|
|
|
| private:
|
| - Layer* layer_;
|
| + bool paints_lcd_text_;
|
| int paint_count_;
|
| - int lcd_notification_count_;
|
| + bool could_paint_lcd_text_last_frame_;
|
| };
|
|
|
| virtual void SetupTree() OVERRIDE {
|
| - scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_);
|
| - root_layer->SetIsDrawable(true);
|
| - root_layer->SetBounds(gfx::Size(1, 1));
|
| + LayerTreeHostTest::SetupTree();
|
|
|
| - layer_tree_host()->SetRootLayer(root_layer);
|
| - client_.set_layer(root_layer.get());
|
| + lcd_text_client_.reset(new LCDTextClient(true));
|
| + regular_text_client_.reset(new LCDTextClient(false));
|
|
|
| - // The expecations are based on the assumption that the default
|
| - // LCD settings are:
|
| + if (layer_tree_host()->settings().impl_side_painting) {
|
| + lcd_text_layer_ = PictureLayer::Create(lcd_text_client_.get());
|
| + regular_text_layer_ = PictureLayer::Create(regular_text_client_.get());
|
| + } else {
|
| + lcd_text_layer_ = ContentLayer::Create(lcd_text_client_.get());
|
| + regular_text_layer_ = ContentLayer::Create(regular_text_client_.get());
|
| + }
|
| + lcd_text_layer_->SetIsDrawable(true);
|
| + lcd_text_layer_->SetBounds(gfx::Size(1, 1));
|
| + layer_tree_host()->root_layer()->AddChild(lcd_text_layer_);
|
| + regular_text_layer_->SetIsDrawable(true);
|
| + regular_text_layer_->SetBounds(gfx::Size(1, 1));
|
| + layer_tree_host()->root_layer()->AddChild(regular_text_layer_);
|
| +
|
| + // The expecations are based on the assumption that LCD text is enabled.
|
| EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
|
| - EXPECT_FALSE(root_layer->can_use_lcd_text());
|
| -
|
| - LayerTreeHostTest::SetupTree();
|
| }
|
|
|
| virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
|
| @@ -2234,44 +2245,67 @@ class LayerTreeHostTestLCDNotification : public LayerTreeHostTest {
|
| virtual void DidCommit() OVERRIDE {
|
| switch (layer_tree_host()->source_frame_number()) {
|
| case 1:
|
| - // The first update consists one LCD notification and one paint.
|
| - EXPECT_EQ(1, 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());
|
| + // LCD text must be enabled on both layers.
|
| + EXPECT_TRUE(lcd_text_layer_->can_use_lcd_text());
|
| + EXPECT_TRUE(regular_text_layer_->can_use_lcd_text());
|
| + // Both layers must be painted.
|
| + EXPECT_EQ(1, lcd_text_client_->paint_count());
|
| + EXPECT_EQ(1, regular_text_client_->paint_count());
|
| + // LCD text must have been allowed on both layers.
|
| + EXPECT_TRUE(lcd_text_client_->could_paint_lcd_text_last_frame());
|
| + EXPECT_TRUE(regular_text_client_->could_paint_lcd_text_last_frame());
|
| PostSetNeedsCommitToMainThread();
|
| break;
|
| 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(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.
|
| - layer_tree_host()->root_layer()->SetOpacity(.5f);
|
| + // Since nothing changed on any of the layers,
|
| + // everything should remain the same and they should not be repainted.
|
| + EXPECT_TRUE(lcd_text_layer_->can_use_lcd_text());
|
| + EXPECT_TRUE(regular_text_layer_->can_use_lcd_text());
|
| + EXPECT_EQ(1, lcd_text_client_->paint_count());
|
| + EXPECT_EQ(1, regular_text_client_->paint_count());
|
| + // Change layer opacity that should trigger lcd change.
|
| + lcd_text_layer_->SetOpacity(.5f);
|
| + regular_text_layer_->SetOpacity(.5f);
|
| // No need to request a commit - setting opacity will do it.
|
| break;
|
| + case 3:
|
| + // LCD text must have been disabled on layers due to opacity.
|
| + EXPECT_FALSE(lcd_text_layer_->can_use_lcd_text());
|
| + EXPECT_FALSE(regular_text_layer_->can_use_lcd_text());
|
| + // Layer with lcd text should have been repainted with LCD AA.
|
| + EXPECT_EQ(2, lcd_text_client_->paint_count());
|
| + EXPECT_FALSE(lcd_text_client_->could_paint_lcd_text_last_frame());
|
| + // Layer with regular text should not have been repainted.
|
| + EXPECT_EQ(1, regular_text_client_->paint_count());
|
| + // Reset layer opacity - making it possible to use LCD text again.
|
| + lcd_text_layer_->SetOpacity(1.f);
|
| + regular_text_layer_->SetOpacity(1.f);
|
| + break;
|
| default:
|
| - // Verify that there is not extra commit due to layer invalidation.
|
| - EXPECT_EQ(3, layer_tree_host()->source_frame_number());
|
| - // LCD notification count should have incremented due to
|
| - // change in layer opacity.
|
| - EXPECT_EQ(2, 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());
|
| + // Verify that there is no extra commit due to layer invalidation.
|
| + EXPECT_EQ(4, layer_tree_host()->source_frame_number());
|
| + // LCD text is now allowed.
|
| + EXPECT_TRUE(lcd_text_layer_->can_use_lcd_text());
|
| + EXPECT_TRUE(regular_text_layer_->can_use_lcd_text());
|
| + // Although LCD text is allowed, it is not used.
|
| + // Once LCD is disabled, it cannot be switched back ON.
|
| + // So there should not be any invalidation or painting.
|
| + EXPECT_EQ(2, lcd_text_client_->paint_count());
|
| + EXPECT_EQ(1, regular_text_client_->paint_count());
|
| EndTest();
|
| break;
|
| }
|
| }
|
|
|
| private:
|
| - NotificationClient client_;
|
| + scoped_ptr<LCDTextClient> lcd_text_client_;
|
| + scoped_ptr<LCDTextClient> regular_text_client_;
|
| +
|
| + scoped_refptr<Layer> lcd_text_layer_;
|
| + scoped_refptr<Layer> regular_text_layer_;
|
| };
|
|
|
| -SINGLE_THREAD_TEST_F(LayerTreeHostTestLCDNotification);
|
| +SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDText);
|
|
|
| // Verify that the BeginFrame notification is used to initiate rendering.
|
| class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest {
|
| @@ -2439,12 +2473,13 @@ class LayerTreeHostTestChangeLayerPropertiesInPaintContents
|
| virtual void PaintContents(
|
| SkCanvas* canvas,
|
| const gfx::Rect& clip,
|
| + bool can_paint_lcd_text,
|
| gfx::RectF* opaque,
|
| ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {
|
| layer_->SetBounds(gfx::Size(2, 2));
|
| }
|
|
|
| - virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
|
| + virtual bool PaintsLCDText() const OVERRIDE { return false; }
|
|
|
| virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
|
|
|
|
|