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

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

Issue 315393002: Record SkPicture with correct LCD text setting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better unittest Created 6 years, 6 months 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 | Annotate | Revision Log
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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 964
965 class TestOpacityChangeLayerDelegate : public ContentLayerClient { 965 class TestOpacityChangeLayerDelegate : public ContentLayerClient {
966 public: 966 public:
967 TestOpacityChangeLayerDelegate() : test_layer_(0) {} 967 TestOpacityChangeLayerDelegate() : test_layer_(0) {}
968 968
969 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } 969 void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; }
970 970
971 virtual void PaintContents( 971 virtual void PaintContents(
972 SkCanvas* canvas, 972 SkCanvas* canvas,
973 const gfx::Rect& clip, 973 const gfx::Rect& clip,
974 bool can_paint_lcd_text,
974 gfx::RectF* opaque, 975 gfx::RectF* opaque,
975 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { 976 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {
976 // Set layer opacity to 0. 977 // Set layer opacity to 0.
977 if (test_layer_) 978 if (test_layer_)
978 test_layer_->SetOpacity(0.f); 979 test_layer_->SetOpacity(0.f);
979 } 980 }
980 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} 981 virtual bool PaintsLCDText() const OVERRIDE { return false; }
981 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } 982 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
982 983
983 private: 984 private:
984 Layer* test_layer_; 985 Layer* test_layer_;
985 }; 986 };
986 987
987 class ContentLayerWithUpdateTracking : public ContentLayer { 988 class ContentLayerWithUpdateTracking : public ContentLayer {
988 public: 989 public:
989 static scoped_refptr<ContentLayerWithUpdateTracking> Create( 990 static scoped_refptr<ContentLayerWithUpdateTracking> Create(
990 ContentLayerClient* client) { 991 ContentLayerClient* client) {
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 FakeContentLayerClient client_; 2176 FakeContentLayerClient client_;
2176 scoped_refptr<FakeContentLayer> root_layer_; 2177 scoped_refptr<FakeContentLayer> root_layer_;
2177 scoped_refptr<FakeContentLayer> child_layer1_; 2178 scoped_refptr<FakeContentLayer> child_layer1_;
2178 scoped_refptr<FakeContentLayer> child_layer2_; 2179 scoped_refptr<FakeContentLayer> child_layer2_;
2179 int num_commits_; 2180 int num_commits_;
2180 }; 2181 };
2181 2182
2182 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( 2183 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F(
2183 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); 2184 LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted);
2184 2185
2185 class LayerTreeHostTestLCDNotification : public LayerTreeHostTest { 2186 class LayerTreeHostTestLCDText : public LayerTreeHostTest {
2186 public: 2187 public:
2187 class NotificationClient : public ContentLayerClient { 2188 class LCDTextClient : public ContentLayerClient {
2188 public: 2189 public:
2189 NotificationClient() 2190 LCDTextClient(bool paints_lcd_text)
2190 : layer_(0), paint_count_(0), lcd_notification_count_(0) {} 2191 : paints_lcd_text_(paints_lcd_text),
2192 paint_count_(0),
2193 could_paint_lcd_text_last_frame_(false) {}
2191 2194
2192 void set_layer(Layer* layer) { layer_ = layer; }
2193 int paint_count() const { return paint_count_; } 2195 int paint_count() const { return paint_count_; }
2194 int lcd_notification_count() const { return lcd_notification_count_; } 2196 int could_paint_lcd_text_last_frame() const {
2197 return could_paint_lcd_text_last_frame_;
2198 }
2195 2199
2196 virtual void PaintContents( 2200 virtual void PaintContents(
2197 SkCanvas* canvas, 2201 SkCanvas* canvas,
2198 const gfx::Rect& clip, 2202 const gfx::Rect& clip,
2203 bool can_paint_lcd_text,
2199 gfx::RectF* opaque, 2204 gfx::RectF* opaque,
2200 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { 2205 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {
2201 ++paint_count_; 2206 ++paint_count_;
2207 could_paint_lcd_text_last_frame_ = can_paint_lcd_text;
2202 } 2208 }
2203 virtual void DidChangeLayerCanUseLCDText() OVERRIDE { 2209 virtual bool PaintsLCDText() const OVERRIDE { return paints_lcd_text_; }
2204 ++lcd_notification_count_;
2205 layer_->SetNeedsDisplay();
2206 }
2207 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } 2210 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
2208 2211
2209 private: 2212 private:
2210 Layer* layer_; 2213 bool paints_lcd_text_;
2211 int paint_count_; 2214 int paint_count_;
2212 int lcd_notification_count_; 2215 bool could_paint_lcd_text_last_frame_;
2213 }; 2216 };
2214 2217
2215 virtual void SetupTree() OVERRIDE { 2218 virtual void SetupTree() OVERRIDE {
2216 scoped_refptr<ContentLayer> root_layer = ContentLayer::Create(&client_); 2219 LayerTreeHostTest::SetupTree();
2217 root_layer->SetIsDrawable(true);
2218 root_layer->SetBounds(gfx::Size(1, 1));
2219 2220
2220 layer_tree_host()->SetRootLayer(root_layer); 2221 lcd_text_client_.reset(new LCDTextClient(true));
2221 client_.set_layer(root_layer.get()); 2222 regular_text_client_.reset(new LCDTextClient(false));
2222 2223
2223 // The expecations are based on the assumption that the default 2224 if (layer_tree_host()->settings().impl_side_painting) {
2224 // LCD settings are: 2225 lcd_text_layer_ = PictureLayer::Create(lcd_text_client_.get());
2226 regular_text_layer_ = PictureLayer::Create(regular_text_client_.get());
2227 } else {
2228 lcd_text_layer_ = ContentLayer::Create(lcd_text_client_.get());
2229 regular_text_layer_ = ContentLayer::Create(regular_text_client_.get());
2230 }
2231 lcd_text_layer_->SetIsDrawable(true);
2232 lcd_text_layer_->SetBounds(gfx::Size(1, 1));
2233 layer_tree_host()->root_layer()->AddChild(lcd_text_layer_);
2234 regular_text_layer_->SetIsDrawable(true);
2235 regular_text_layer_->SetBounds(gfx::Size(1, 1));
2236 layer_tree_host()->root_layer()->AddChild(regular_text_layer_);
2237
2238 // The expecations are based on the assumption that LCD text is enabled.
2225 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); 2239 EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text);
2226 EXPECT_FALSE(root_layer->can_use_lcd_text());
2227
2228 LayerTreeHostTest::SetupTree();
2229 } 2240 }
2230 2241
2231 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } 2242 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
2232 virtual void AfterTest() OVERRIDE {} 2243 virtual void AfterTest() OVERRIDE {}
2233 2244
2234 virtual void DidCommit() OVERRIDE { 2245 virtual void DidCommit() OVERRIDE {
2235 switch (layer_tree_host()->source_frame_number()) { 2246 switch (layer_tree_host()->source_frame_number()) {
2236 case 1: 2247 case 1:
2237 // The first update consists one LCD notification and one paint. 2248 // LCD text must be enabled on both layers.
2238 EXPECT_EQ(1, client_.lcd_notification_count()); 2249 EXPECT_TRUE(lcd_text_layer_->can_use_lcd_text());
2239 EXPECT_EQ(1, client_.paint_count()); 2250 EXPECT_TRUE(regular_text_layer_->can_use_lcd_text());
2240 // LCD text must have been enabled on the layer. 2251 // Both layers must be painted.
2241 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2252 EXPECT_EQ(1, lcd_text_client_->paint_count());
2253 EXPECT_EQ(1, regular_text_client_->paint_count());
2254 // LCD text must have been allowed on both layers.
2255 EXPECT_TRUE(lcd_text_client_->could_paint_lcd_text_last_frame());
2256 EXPECT_TRUE(regular_text_client_->could_paint_lcd_text_last_frame());
2242 PostSetNeedsCommitToMainThread(); 2257 PostSetNeedsCommitToMainThread();
2243 break; 2258 break;
2244 case 2: 2259 case 2:
2245 // Since nothing changed on layer, there should be no notification 2260 // Since nothing changed on any of the layers,
2246 // or paint on the second update. 2261 // everything should remain the same and they should not be repainted.
2247 EXPECT_EQ(1, client_.lcd_notification_count()); 2262 EXPECT_TRUE(lcd_text_layer_->can_use_lcd_text());
2248 EXPECT_EQ(1, client_.paint_count()); 2263 EXPECT_TRUE(regular_text_layer_->can_use_lcd_text());
2249 // LCD text must not have changed. 2264 EXPECT_EQ(1, lcd_text_client_->paint_count());
2250 EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2265 EXPECT_EQ(1, regular_text_client_->paint_count());
2251 // Change layer opacity that should trigger lcd notification. 2266 // Change layer opacity that should trigger lcd change.
2252 layer_tree_host()->root_layer()->SetOpacity(.5f); 2267 lcd_text_layer_->SetOpacity(.5f);
2268 regular_text_layer_->SetOpacity(.5f);
2253 // No need to request a commit - setting opacity will do it. 2269 // No need to request a commit - setting opacity will do it.
2254 break; 2270 break;
2271 case 3:
2272 // LCD text must have been disabled on layers due to opacity.
2273 EXPECT_FALSE(lcd_text_layer_->can_use_lcd_text());
2274 EXPECT_FALSE(regular_text_layer_->can_use_lcd_text());
2275 // Layer with lcd text should have been repainted with LCD AA.
2276 EXPECT_EQ(2, lcd_text_client_->paint_count());
2277 EXPECT_FALSE(lcd_text_client_->could_paint_lcd_text_last_frame());
2278 // Layer with regular text should not have been repainted.
2279 EXPECT_EQ(1, regular_text_client_->paint_count());
2280 // Reset layer opacity - making it possible to use LCD text again.
2281 lcd_text_layer_->SetOpacity(1.f);
2282 regular_text_layer_->SetOpacity(1.f);
2283 break;
2255 default: 2284 default:
2256 // Verify that there is not extra commit due to layer invalidation. 2285 // Verify that there is no extra commit due to layer invalidation.
2257 EXPECT_EQ(3, layer_tree_host()->source_frame_number()); 2286 EXPECT_EQ(4, layer_tree_host()->source_frame_number());
2258 // LCD notification count should have incremented due to 2287 // LCD text is now allowed.
2259 // change in layer opacity. 2288 EXPECT_TRUE(lcd_text_layer_->can_use_lcd_text());
2260 EXPECT_EQ(2, client_.lcd_notification_count()); 2289 EXPECT_TRUE(regular_text_layer_->can_use_lcd_text());
2261 // Paint count should be incremented due to invalidation. 2290 // Although LCD text is allowed, it is not used.
2262 EXPECT_EQ(2, client_.paint_count()); 2291 // Once LCD is disabled, it cannot be switched back ON.
2263 // LCD text must have been disabled on the layer due to opacity. 2292 // So there should not be any invalidation or painting.
2264 EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); 2293 EXPECT_EQ(2, lcd_text_client_->paint_count());
2294 EXPECT_EQ(1, regular_text_client_->paint_count());
2265 EndTest(); 2295 EndTest();
2266 break; 2296 break;
2267 } 2297 }
2268 } 2298 }
2269 2299
2270 private: 2300 private:
2271 NotificationClient client_; 2301 scoped_ptr<LCDTextClient> lcd_text_client_;
2302 scoped_ptr<LCDTextClient> regular_text_client_;
2303
2304 scoped_refptr<Layer> lcd_text_layer_;
2305 scoped_refptr<Layer> regular_text_layer_;
2272 }; 2306 };
2273 2307
2274 SINGLE_THREAD_TEST_F(LayerTreeHostTestLCDNotification); 2308 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDText);
2275 2309
2276 // Verify that the BeginFrame notification is used to initiate rendering. 2310 // Verify that the BeginFrame notification is used to initiate rendering.
2277 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { 2311 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest {
2278 public: 2312 public:
2279 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { 2313 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
2280 settings->begin_frame_scheduling_enabled = true; 2314 settings->begin_frame_scheduling_enabled = true;
2281 } 2315 }
2282 2316
2283 virtual void BeginTest() OVERRIDE { 2317 virtual void BeginTest() OVERRIDE {
2284 // This will trigger a SetNeedsBeginFrame which will trigger a 2318 // This will trigger a SetNeedsBeginFrame which will trigger a
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 public: 2466 public:
2433 class SetBoundsClient : public ContentLayerClient { 2467 class SetBoundsClient : public ContentLayerClient {
2434 public: 2468 public:
2435 SetBoundsClient() : layer_(0) {} 2469 SetBoundsClient() : layer_(0) {}
2436 2470
2437 void set_layer(Layer* layer) { layer_ = layer; } 2471 void set_layer(Layer* layer) { layer_ = layer; }
2438 2472
2439 virtual void PaintContents( 2473 virtual void PaintContents(
2440 SkCanvas* canvas, 2474 SkCanvas* canvas,
2441 const gfx::Rect& clip, 2475 const gfx::Rect& clip,
2476 bool can_paint_lcd_text,
2442 gfx::RectF* opaque, 2477 gfx::RectF* opaque,
2443 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { 2478 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {
2444 layer_->SetBounds(gfx::Size(2, 2)); 2479 layer_->SetBounds(gfx::Size(2, 2));
2445 } 2480 }
2446 2481
2447 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} 2482 virtual bool PaintsLCDText() const OVERRIDE { return false; }
2448 2483
2449 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } 2484 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
2450 2485
2451 private: 2486 private:
2452 Layer* layer_; 2487 Layer* layer_;
2453 }; 2488 };
2454 2489
2455 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} 2490 LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {}
2456 2491
2457 virtual void SetupTree() OVERRIDE { 2492 virtual void SetupTree() OVERRIDE {
(...skipping 2436 matching lines...) Expand 10 before | Expand all | Expand 10 after
4894 const gfx::Size bounds_; 4929 const gfx::Size bounds_;
4895 FakeContentLayerClient client_; 4930 FakeContentLayerClient client_;
4896 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_; 4931 scoped_refptr<ContentLayerWithUpdateTracking> content_layer_;
4897 scoped_refptr<FakePictureLayer> picture_layer_; 4932 scoped_refptr<FakePictureLayer> picture_layer_;
4898 Layer* child_layer_; 4933 Layer* child_layer_;
4899 }; 4934 };
4900 4935
4901 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting); 4936 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousPainting);
4902 4937
4903 } // namespace cc 4938 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698