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

Side by Side Diff: cc/content_layer_unittest.cc

Issue 11360093: Mark layers that can use LCD text based on layer transform and opacity. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reverted whitespace change Created 8 years 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
« no previous file with comments | « cc/content_layer.cc ('k') | cc/damage_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/content_layer.h" 5 #include "cc/content_layer.h"
6 6
7 #include "cc/bitmap_content_layer_updater.h" 7 #include "cc/bitmap_content_layer_updater.h"
8 #include "cc/content_layer_client.h" 8 #include "cc/content_layer_client.h"
9 #include "cc/rendering_stats.h" 9 #include "cc/rendering_stats.h"
10 #include "cc/resource_update_queue.h"
10 #include "cc/test/geometry_test_utils.h" 11 #include "cc/test/geometry_test_utils.h"
11 #include "skia/ext/platform_canvas.h" 12 #include "skia/ext/platform_canvas.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/rect_conversions.h" 14 #include "ui/gfx/rect_conversions.h"
14 15
15 using namespace WebKit; 16 using namespace WebKit;
16 17
17 namespace cc { 18 namespace cc {
18 namespace { 19 namespace {
19 20
21 class FakeContentLayer : public ContentLayer {
22 public:
23 explicit FakeContentLayer(ContentLayerClient* client) : ContentLayer(client) { }
24
25 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect) OVERRIDE
26 {
27 m_lastDirtyRect = dirtyRect;
28 ContentLayer::setNeedsDisplayRect(dirtyRect);
29 }
30 gfx::RectF lastDirtyRect() const { return m_lastDirtyRect; }
31
32 protected:
33 virtual ~FakeContentLayer() { }
34 virtual void createUpdaterIfNeeded() OVERRIDE { }
35
36 private:
37 gfx::RectF m_lastDirtyRect;
38 };
39
20 class MockContentLayerClient : public ContentLayerClient { 40 class MockContentLayerClient : public ContentLayerClient {
21 public: 41 public:
22 explicit MockContentLayerClient(gfx::Rect opaqueLayerRect) 42 explicit MockContentLayerClient(gfx::Rect opaqueLayerRect)
23 : m_opaqueLayerRect(opaqueLayerRect) 43 : m_opaqueLayerRect(opaqueLayerRect)
24 { 44 {
25 } 45 }
26 46
27 virtual void paintContents(SkCanvas*, const gfx::Rect&, gfx::RectF& opaque) OVERRIDE 47 virtual void paintContents(SkCanvas*, const gfx::Rect&, gfx::RectF& opaque) OVERRIDE
28 { 48 {
29 opaque = gfx::RectF(m_opaqueLayerRect); 49 opaque = gfx::RectF(m_opaqueLayerRect);
(...skipping 12 matching lines...) Expand all
42 MockContentLayerClient client(opaqueRectInLayerSpace); 62 MockContentLayerClient client(opaqueRectInLayerSpace);
43 scoped_refptr<BitmapContentLayerUpdater> updater = BitmapContentLayerUpdater ::create(ContentLayerPainter::create(&client).PassAs<LayerPainter>()); 63 scoped_refptr<BitmapContentLayerUpdater> updater = BitmapContentLayerUpdater ::create(ContentLayerPainter::create(&client).PassAs<LayerPainter>());
44 64
45 gfx::Rect resultingOpaqueRect; 65 gfx::Rect resultingOpaqueRect;
46 RenderingStats stats; 66 RenderingStats stats;
47 updater->prepareToUpdate(contentRect, gfx::Size(256, 256), contentsScale, co ntentsScale, resultingOpaqueRect, stats); 67 updater->prepareToUpdate(contentRect, gfx::Size(256, 256), contentsScale, co ntentsScale, resultingOpaqueRect, stats);
48 68
49 EXPECT_RECT_EQ(gfx::ToEnclosingRect(opaqueRectInContentSpace), resultingOpaq ueRect); 69 EXPECT_RECT_EQ(gfx::ToEnclosingRect(opaqueRectInContentSpace), resultingOpaq ueRect);
50 } 70 }
51 71
72 TEST(ContentLayerTest, UseLCDTextEnableCount)
73 {
74 scoped_refptr<FakeContentLayer> layer = new FakeContentLayer(NULL);
75 layer->setBounds(gfx::Size(100, 100));
76 ResourceUpdateQueue queue;
77 RenderingStats stats;
78
79 // By default LCD text is disabled.
80 EXPECT_FALSE(layer->useLCDText());
81
82 // LCD text can be enabled once.
83 layer->drawProperties().can_use_lcd_text = true;
84 layer->update(queue, NULL, stats);
85 EXPECT_TRUE(layer->useLCDText());
86
87 // LCD text can always be disabled.
88 layer->drawProperties().can_use_lcd_text = false;
89 layer->update(queue, NULL, stats);
90 EXPECT_FALSE(layer->useLCDText());
91
92 // LCD text cannot be enabled anymore.
93 layer->drawProperties().can_use_lcd_text = true;
94 layer->update(queue, NULL, stats);
95 EXPECT_FALSE(layer->useLCDText());
96 }
97
98 TEST(ContentLayerTest, UseLCDTextChangeTriggersRepaint)
99 {
100 scoped_refptr<FakeContentLayer> layer = new FakeContentLayer(NULL);
101 layer->setBounds(gfx::Size(100, 100));
102 gfx::RectF dirtyRect(100, 100);
103 ResourceUpdateQueue queue;
104 RenderingStats stats;
105
106 // By default LCD text is disabled.
107 EXPECT_FALSE(layer->useLCDText());
108
109 // Enable LCD text and verify that it triggers invalidation.
110 layer->drawProperties().can_use_lcd_text = true;
111 layer->update(queue, NULL, stats);
112 EXPECT_TRUE(layer->useLCDText());
113 EXPECT_EQ(dirtyRect, layer->lastDirtyRect());
114
115 // Reset dirty rect.
116 layer->setNeedsDisplayRect(gfx::RectF());
117 EXPECT_EQ(gfx::RectF(), layer->lastDirtyRect());
118
119 // Disable LCD text and verify that it triggers invalidation.
120 layer->drawProperties().can_use_lcd_text = false;
121 layer->update(queue, NULL, stats);
122 EXPECT_FALSE(layer->useLCDText());
123 EXPECT_EQ(dirtyRect, layer->lastDirtyRect());
124 }
125
52 } // namespace 126 } // namespace
53 } // namespace cc 127 } // namespace cc
OLDNEW
« no previous file with comments | « cc/content_layer.cc ('k') | cc/damage_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698