OLD | NEW |
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 protected: |
| 26 virtual ~FakeContentLayer() { } |
| 27 virtual void createUpdaterIfNeeded() OVERRIDE { } |
| 28 }; |
| 29 |
20 class MockContentLayerClient : public ContentLayerClient { | 30 class MockContentLayerClient : public ContentLayerClient { |
21 public: | 31 public: |
22 explicit MockContentLayerClient(gfx::Rect opaqueLayerRect) | 32 explicit MockContentLayerClient(gfx::Rect opaqueLayerRect) |
23 : m_opaqueLayerRect(opaqueLayerRect) | 33 : m_opaqueLayerRect(opaqueLayerRect) |
24 { | 34 { |
25 } | 35 } |
26 | 36 |
27 virtual void paintContents(SkCanvas*, const gfx::Rect&, gfx::RectF& opaque)
OVERRIDE | 37 virtual void paintContents(SkCanvas*, const gfx::Rect&, gfx::RectF& opaque)
OVERRIDE |
28 { | 38 { |
29 opaque = gfx::RectF(m_opaqueLayerRect); | 39 opaque = gfx::RectF(m_opaqueLayerRect); |
(...skipping 12 matching lines...) Expand all Loading... |
42 MockContentLayerClient client(opaqueRectInLayerSpace); | 52 MockContentLayerClient client(opaqueRectInLayerSpace); |
43 scoped_refptr<BitmapContentLayerUpdater> updater = BitmapContentLayerUpdater
::create(ContentLayerPainter::create(&client).PassAs<LayerPainter>()); | 53 scoped_refptr<BitmapContentLayerUpdater> updater = BitmapContentLayerUpdater
::create(ContentLayerPainter::create(&client).PassAs<LayerPainter>()); |
44 | 54 |
45 gfx::Rect resultingOpaqueRect; | 55 gfx::Rect resultingOpaqueRect; |
46 RenderingStats stats; | 56 RenderingStats stats; |
47 updater->prepareToUpdate(contentRect, gfx::Size(256, 256), contentsScale, co
ntentsScale, resultingOpaqueRect, stats); | 57 updater->prepareToUpdate(contentRect, gfx::Size(256, 256), contentsScale, co
ntentsScale, resultingOpaqueRect, stats); |
48 | 58 |
49 EXPECT_RECT_EQ(gfx::ToEnclosingRect(opaqueRectInContentSpace), resultingOpaq
ueRect); | 59 EXPECT_RECT_EQ(gfx::ToEnclosingRect(opaqueRectInContentSpace), resultingOpaq
ueRect); |
50 } | 60 } |
51 | 61 |
| 62 TEST(ContentLayerTest, CanUseLCDTextEnableCount) |
| 63 { |
| 64 scoped_refptr<FakeContentLayer> layer = new FakeContentLayer(NULL); |
| 65 |
| 66 // By default LCD text is disabled. |
| 67 EXPECT_FALSE(layer->canUseLCDText()); |
| 68 |
| 69 // LCD text can be enabled once. |
| 70 layer->setCanUseLCDText(true); |
| 71 EXPECT_TRUE(layer->canUseLCDText()); |
| 72 |
| 73 // LCD text can always be disabled. |
| 74 layer->setCanUseLCDText(false); |
| 75 EXPECT_FALSE(layer->canUseLCDText()); |
| 76 |
| 77 // LCD text cannot be enabled anymore. |
| 78 layer->setCanUseLCDText(true); |
| 79 EXPECT_FALSE(layer->canUseLCDText()); |
| 80 } |
| 81 |
| 82 TEST(ContentLayerTest, CanUseLCDTextChangeTriggersRepaint) |
| 83 { |
| 84 scoped_refptr<FakeContentLayer> layer = new FakeContentLayer(NULL); |
| 85 layer->setBounds(gfx::Size(100, 100)); |
| 86 ResourceUpdateQueue queue; |
| 87 RenderingStats stats; |
| 88 // Reset needsDisplay bit. |
| 89 layer->update(queue, NULL, stats); |
| 90 EXPECT_FALSE(layer->canUseLCDText()); |
| 91 EXPECT_FALSE(layer->needsDisplay()); |
| 92 |
| 93 layer->setCanUseLCDText(true); |
| 94 EXPECT_TRUE(layer->canUseLCDText()); |
| 95 EXPECT_TRUE(layer->needsDisplay()); |
| 96 |
| 97 // Reset needsDisplay bit. |
| 98 layer->update(queue, NULL, stats); |
| 99 EXPECT_FALSE(layer->needsDisplay()); |
| 100 |
| 101 layer->setCanUseLCDText(false); |
| 102 EXPECT_FALSE(layer->canUseLCDText()); |
| 103 EXPECT_TRUE(layer->needsDisplay()); |
| 104 } |
| 105 |
52 } // namespace | 106 } // namespace |
53 } // namespace cc | 107 } // namespace cc |
OLD | NEW |