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/layers/content_layer.h" | 5 #include "cc/layers/content_layer.h" |
6 | 6 |
7 #include "cc/layers/content_layer_client.h" | 7 #include "cc/layers/content_layer_client.h" |
8 #include "cc/resources/bitmap_content_layer_updater.h" | 8 #include "cc/resources/bitmap_content_layer_updater.h" |
| 9 #include "cc/resources/content_layer_painter.h" |
9 #include "cc/test/fake_rendering_stats_instrumentation.h" | 10 #include "cc/test/fake_rendering_stats_instrumentation.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 namespace cc { | 16 namespace cc { |
16 namespace { | 17 namespace { |
17 | 18 |
18 class MockContentLayerClient : public ContentLayerClient { | 19 class MockContentLayerClient : public ContentLayerClient { |
19 public: | 20 public: |
20 explicit MockContentLayerClient(const gfx::Rect& opaque_layer_rect) | 21 explicit MockContentLayerClient(const gfx::Rect& opaque_layer_rect) |
21 : opaque_layer_rect_(opaque_layer_rect) {} | 22 : opaque_layer_rect_(opaque_layer_rect) {} |
22 | 23 |
23 virtual void PaintContents( | 24 virtual void PaintContents( |
24 SkCanvas* canvas, | 25 SkCanvas* canvas, |
25 const gfx::Rect& clip, | 26 const gfx::Rect& clip, |
| 27 bool can_paint_lcd_text, |
26 gfx::RectF* opaque, | 28 gfx::RectF* opaque, |
27 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { | 29 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE { |
28 *opaque = gfx::RectF(opaque_layer_rect_); | 30 *opaque = gfx::RectF(opaque_layer_rect_); |
29 } | 31 } |
30 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} | 32 virtual bool PaintsLCDText() const OVERRIDE { return false; } |
31 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } | 33 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
32 | 34 |
33 private: | 35 private: |
34 gfx::Rect opaque_layer_rect_; | 36 gfx::Rect opaque_layer_rect_; |
35 }; | 37 }; |
36 | 38 |
37 TEST(ContentLayerTest, ContentLayerPainterWithDeviceScale) { | 39 TEST(ContentLayerTest, ContentLayerPainterWithDeviceScale) { |
38 float contents_scale = 2.f; | 40 float contents_scale = 2.f; |
39 gfx::Rect content_rect(10, 10, 100, 100); | 41 gfx::Rect content_rect(10, 10, 100, 100); |
40 gfx::Rect opaque_rect_in_layer_space(5, 5, 20, 20); | 42 gfx::Rect opaque_rect_in_layer_space(5, 5, 20, 20); |
41 gfx::Rect opaque_rect_in_content_space = gfx::ScaleToEnclosingRect( | 43 gfx::Rect opaque_rect_in_content_space = gfx::ScaleToEnclosingRect( |
42 opaque_rect_in_layer_space, contents_scale, contents_scale); | 44 opaque_rect_in_layer_space, contents_scale, contents_scale); |
43 MockContentLayerClient client(opaque_rect_in_layer_space); | 45 MockContentLayerClient client(opaque_rect_in_layer_space); |
44 FakeRenderingStatsInstrumentation stats_instrumentation; | 46 FakeRenderingStatsInstrumentation stats_instrumentation; |
45 scoped_refptr<BitmapContentLayerUpdater> updater = | 47 scoped_refptr<BitmapContentLayerUpdater> updater = |
46 BitmapContentLayerUpdater::Create( | 48 BitmapContentLayerUpdater::Create( |
47 ContentLayerPainter::Create(&client).PassAs<LayerPainter>(), | 49 ContentLayerPainter::Create(&client), &stats_instrumentation, 0); |
48 &stats_instrumentation, | |
49 0); | |
50 | 50 |
51 gfx::Rect resulting_opaque_rect; | 51 gfx::Rect resulting_opaque_rect; |
52 updater->PrepareToUpdate(content_rect, | 52 updater->PrepareToUpdate(content_rect, |
53 gfx::Size(256, 256), | 53 gfx::Size(256, 256), |
54 contents_scale, | 54 contents_scale, |
55 contents_scale, | 55 contents_scale, |
56 &resulting_opaque_rect); | 56 &resulting_opaque_rect); |
57 | 57 |
58 EXPECT_EQ(opaque_rect_in_content_space.ToString(), | 58 EXPECT_EQ(opaque_rect_in_content_space.ToString(), |
59 resulting_opaque_rect.ToString()); | 59 resulting_opaque_rect.ToString()); |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 } // namespace cc | 63 } // namespace cc |
OLD | NEW |