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

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: bettertestsyay 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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ContentLayerClient::GraphicsContextStatus gc_status) override { 946 ContentLayerClient::GraphicsContextStatus gc_status) override {
947 // Set layer opacity to 0. 947 // Set layer opacity to 0.
948 if (test_layer_) 948 if (test_layer_)
949 test_layer_->SetOpacity(0.f); 949 test_layer_->SetOpacity(0.f);
950 } 950 }
951 void DidChangeLayerCanUseLCDText() override {}
952 bool FillsBoundsCompletely() const override { return false; } 951 bool FillsBoundsCompletely() const override { return false; }
953 952
954 private: 953 private:
955 Layer* test_layer_; 954 Layer* test_layer_;
956 }; 955 };
957 956
958 class ContentLayerWithUpdateTracking : public ContentLayer { 957 class ContentLayerWithUpdateTracking : public ContentLayer {
959 public: 958 public:
960 static scoped_refptr<ContentLayerWithUpdateTracking> Create( 959 static scoped_refptr<ContentLayerWithUpdateTracking> Create(
961 ContentLayerClient* client) { 960 ContentLayerClient* client) {
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 FakeContentLayerClient client_; 2121 FakeContentLayerClient client_;
2123 scoped_refptr<FakeContentLayer> root_layer_; 2122 scoped_refptr<FakeContentLayer> root_layer_;
2124 scoped_refptr<FakeContentLayer> child_layer1_; 2123 scoped_refptr<FakeContentLayer> child_layer1_;
2125 scoped_refptr<FakeContentLayer> child_layer2_; 2124 scoped_refptr<FakeContentLayer> child_layer2_;
2126 int num_commits_; 2125 int num_commits_;
2127 }; 2126 };
2128 2127
2129 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( 2128 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
2130 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); 2129 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted);
2131 2130
2132 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { 2131 class LayerTreeHostTestLCDInvalidation : public LayerTreeHostTest {
2133 public: 2132 public:
2134 class NotificationClient : public ContentLayerClient { 2133 class InvalidationClient : public ContentLayerClient {
2135 public: 2134 public:
2136 NotificationClient() 2135 InvalidationClient() : paint_count_(0) {}
2137 : layer_(0), paint_count_(0), lcd_notification_count_(0) {}
2138 2136
2139 void set_layer(Layer* layer) { layer_ = layer; }
2140 int paint_count() const { return paint_count_; } 2137 int paint_count() const { return paint_count_; }
2141 int lcd_notification_count() const { return lcd_notification_count_; } 2138 gfx::Rect last_paint_rect() const { return last_paint_rect_; }
2142 2139
2143 void PaintContents( 2140 void PaintContents(
2144 SkCanvas* canvas, 2141 SkCanvas* canvas,
2145 const gfx::Rect& clip, 2142 const gfx::Rect& clip,
2146 ContentLayerClient::GraphicsContextStatus gc_status) override { 2143 ContentLayerClient::GraphicsContextStatus gc_status) override {
2147 ++paint_count_; 2144 ++paint_count_;
2145 last_paint_rect_ = clip;
2148 } 2146 }
2149 void DidChangeLayerCanUseLCDText() override { 2147
2150 ++lcd_notification_count_;
2151 layer_->SetNeedsDisplay();
2152 }
2153 bool FillsBoundsCompletely() const override { return false; } 2148 bool FillsBoundsCompletely() const override { return false; }
2154 2149
2155 private: 2150 private:
2156 Layer* layer_;
2157 int paint_count_; 2151 int paint_count_;
2158 int lcd_notification_count_; 2152 gfx::Rect last_paint_rect_;
2159 }; 2153 };
2160 2154
2161 void SetupTree() override { 2155 void SetupTree() override {
2162 scoped_refptr<Layer> root_layer; 2156 scoped_refptr<Layer> root_layer;
2163 if (layer_tree_host()->settings().impl_side_painting) 2157 if (layer_tree_host()->settings().impl_side_painting)
2164 root_layer = PictureLayer::Create(&client_); 2158 root_layer = PictureLayer::Create(&client_);
2165 else 2159 else
2166 root_layer = ContentLayer::Create(&client_); 2160 root_layer = ContentLayer::Create(&client_);
2167 root_layer->SetIsDrawable(true); 2161 root_layer->SetIsDrawable(true);
2168 root_layer->SetBounds(gfx::Size(1, 1)); 2162 root_layer->SetBounds(gfx::Size(10, 10));
2169 2163
2170 layer_tree_host()->SetRootLayer(root_layer); 2164 layer_tree_host()->SetRootLayer(root_layer);
2171 client_.set_layer(root_layer.get());
2172 2165
2173 // The expecations are based on the assumption that the default 2166 // The expecations are based on the assumption that the default
2174 // LCD settings are: 2167 // LCD settings are:
2175 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); 2168 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
2176 EXPECT_FALSE(root_layer->can_use_lcd_text()); 2169 EXPECT_FALSE(root_layer->can_use_lcd_text());
2177 2170
2178 LayerTreeHostTest::SetupTree(); 2171 LayerTreeHostTest::SetupTree();
2179 } 2172 }
2180 2173
2181 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 2174 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2182 void AfterTest() override {} 2175 void AfterTest() override {}
2183 2176
2184 void DidCommit() override { 2177 void DidCommit() override {
2185 switch (layer_tree_host()->source_frame_number()) { 2178 switch (layer_tree_host()->source_frame_number()) {
2186 case 1: 2179 case 1:
2187 // The first update consists of one LCD notification and one paint. 2180 // The first update consists of a paint of the whole layer.
2188 EXPECT_EQ(1, client_.lcd_notification_count());
2189 EXPECT_EQ(1, client_.paint_count()); 2181 EXPECT_EQ(1, client_.paint_count());
2182 EXPECT_TRUE(client_.last_paint_rect().Contains(gfx::Rect(10, 10)));
2190 // LCD text must have been enabled on the layer. 2183 // LCD text must have been enabled on the layer.
2191 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2184 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2192 PostSetNeedsCommitToMainThread(); 2185 PostSetNeedsCommitToMainThread();
2193 break; 2186 break;
2194 case 2: 2187 case 2:
2195 // Since nothing changed on layer, there should be no notification 2188 // Since nothing changed on layer, there should be no paint.
2196 // or paint on the second update.
2197 EXPECT_EQ(1, client_.lcd_notification_count());
2198 EXPECT_EQ(1, client_.paint_count()); 2189 EXPECT_EQ(1, client_.paint_count());
2199 // LCD text must not have changed. 2190 // LCD text must not have changed.
2200 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2191 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2201 // Change layer opacity that should trigger lcd notification. 2192 // Change layer opacity that should trigger lcd change.
2202 layer_tree_host()->root_layer()->SetOpacity(.5f); 2193 layer_tree_host()->root_layer()->SetOpacity(.5f);
2203 // No need to request a commit - setting opacity will do it.
2204 break; 2194 break;
2205 default: 2195 case 3:
2206 // Verify that there is no extra commit due to layer invalidation. 2196 // Verify that there is no extra commit due to layer invalidation.
2207 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); 2197 EXPECT_EQ(3, layer_tree_host()->source_frame_number());
2208 // LCD notification count should have incremented due to 2198 // Paint count should be incremented due to invalidation, and the paint
2209 // change in layer opacity. 2199 // should cover the whole layer.
2210 EXPECT_EQ(2, client_.lcd_notification_count());
2211 // Paint count should be incremented due to invalidation.
2212 EXPECT_EQ(2, client_.paint_count()); 2200 EXPECT_EQ(2, client_.paint_count());
2201 EXPECT_TRUE(client_.last_paint_rect().Contains(gfx::Rect(10, 10)));
2213 // LCD text must have been disabled on the layer due to opacity. 2202 // LCD text must have been disabled on the layer due to opacity.
2214 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2203 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text());
2204 // Change layer opacity that should not trigger lcd change.
2205 layer_tree_host()->root_layer()->SetOpacity(1.f);
2206 break;
2207 case 4:
2208 // Since nothing changed on layer, there should be no paint.
2209 EXPECT_EQ(2, client_.paint_count());
2210 // Even though LCD text could be allowed.
2211 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2215 EndTest(); 2212 EndTest();
2216 break; 2213 break;
2217 } 2214 }
2218 } 2215 }
2219 2216
2220 private: 2217 private:
2221 NotificationClient client_; 2218 InvalidationClient client_;
2222 }; 2219 };
2223 2220
2224 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDNotification); 2221 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDInvalidation);
2222
2223 class LayerTreeHostTestLCDInvalidationNoExtraCommit : public LayerTreeHostTest {
2224 public:
2225 void SetupTree() override {
2226 scoped_refptr<Layer> root_layer;
2227 if (layer_tree_host()->settings().impl_side_painting)
2228 root_layer = PictureLayer::Create(&client_);
2229 else
2230 root_layer = ContentLayer::Create(&client_);
2231 root_layer->SetIsDrawable(true);
2232 root_layer->SetBounds(gfx::Size(1, 1));
2233
2234 layer_tree_host()->SetRootLayer(root_layer);
2235
2236 // The expecations are based on the assumption that the default
2237 // LCD settings are:
2238 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
2239 EXPECT_FALSE(root_layer->can_use_lcd_text());
2240
2241 LayerTreeHostTest::SetupTree();
2242 }
2243
2244 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
2245 void AfterTest() override {}
2246
2247 void DidCommit() override {
2248 switch (layer_tree_host()->source_frame_number()) {
2249 case 1:
2250 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text());
2251 layer_tree_host()->root_layer()->SetOpacity(.5f);
2252 break;
2253 case 2:
2254 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text());
2255 EndTest();
2256 break;
2257 case 3:
2258 // Verify that there is no extra commit due to layer invalidation.
2259 ADD_FAILURE() << "Extra commit happened due to LCD text change";
2260 break;
2261 }
2262 }
2263
2264 private:
2265 FakeContentLayerClient client_;
2266 };
2267
2268 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDInvalidationNoExtraCommit);
2225 2269
2226 // Verify that the BeginFrame notification is used to initiate rendering. 2270 // Verify that the BeginFrame notification is used to initiate rendering.
2227 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { 2271 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest {
2228 public: 2272 public:
2229 void InitializeSettings(LayerTreeSettings* settings) override { 2273 void InitializeSettings(LayerTreeSettings* settings) override {
2230 settings->begin_frame_scheduling_enabled = true; 2274 settings->begin_frame_scheduling_enabled = true;
2231 } 2275 }
2232 2276
2233 void BeginTest() override { 2277 void BeginTest() override {
2234 // This will trigger a SetNeedsBeginFrame which will trigger a 2278 // This will trigger a SetNeedsBeginFrame which will trigger a
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 2429
2386 void set_layer(Layer* layer) { layer_ = layer; } 2430 void set_layer(Layer* layer) { layer_ = layer; }
2387 2431
2388 void PaintContents( 2432 void PaintContents(
2389 SkCanvas* canvas, 2433 SkCanvas* canvas,
2390 const gfx::Rect& clip, 2434 const gfx::Rect& clip,
2391 ContentLayerClient::GraphicsContextStatus gc_status) override { 2435 ContentLayerClient::GraphicsContextStatus gc_status) override {
2392 layer_->SetBounds(gfx::Size(2, 2)); 2436 layer_->SetBounds(gfx::Size(2, 2));
2393 } 2437 }
2394 2438
2395 void DidChangeLayerCanUseLCDText() override {}
2396
2397 bool FillsBoundsCompletely() const override { return false; } 2439 bool FillsBoundsCompletely() const override { return false; }
2398 2440
2399 private: 2441 private:
2400 Layer* layer_; 2442 Layer* layer_;
2401 }; 2443 };
2402 2444
2403 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} 2445 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {}
2404 2446
2405 void SetupTree() override { 2447 void SetupTree() override {
2406 if (layer_tree_host()->settings().impl_side_painting) { 2448 if (layer_tree_host()->settings().impl_side_painting) {
(...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after
5199 void AfterTest() override { 5241 void AfterTest() override {
5200 EXPECT_TRUE(deltas_sent_to_client_); 5242 EXPECT_TRUE(deltas_sent_to_client_);
5201 } 5243 }
5202 5244
5203 ScrollAndScaleSet info_; 5245 ScrollAndScaleSet info_;
5204 bool deltas_sent_to_client_; 5246 bool deltas_sent_to_client_;
5205 }; 5247 };
5206 5248
5207 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); 5249 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer);
5208 } // namespace cc 5250 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698