OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/content_layer.h" | |
6 | |
7 #include "cc/content_layer_client.h" | |
8 #include "cc/resources/bitmap_content_layer_updater.h" | |
9 #include "cc/test/geometry_test_utils.h" | |
10 #include "skia/ext/platform_canvas.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "ui/gfx/rect_conversions.h" | |
13 | |
14 using namespace WebKit; | |
15 | |
16 namespace cc { | |
17 namespace { | |
18 | |
19 class MockContentLayerClient : public ContentLayerClient { | |
20 public: | |
21 explicit MockContentLayerClient(gfx::Rect opaque_layer_rect) | |
22 : opaque_layer_rect_(opaque_layer_rect) {} | |
23 | |
24 virtual void PaintContents(SkCanvas* canvas, | |
25 gfx::Rect clip, | |
26 gfx::RectF* opaque) OVERRIDE { | |
27 *opaque = gfx::RectF(opaque_layer_rect_); | |
28 } | |
29 | |
30 private: | |
31 gfx::Rect opaque_layer_rect_; | |
32 }; | |
33 | |
34 TEST(ContentLayerTest, ContentLayerPainterWithDeviceScale) { | |
35 float contents_scale = 2.f; | |
36 gfx::Rect content_rect(10, 10, 100, 100); | |
37 gfx::Rect opaque_rect_in_layer_space(5, 5, 20, 20); | |
38 gfx::RectF opaque_rect_in_content_space = gfx::ScaleRect( | |
39 opaque_rect_in_layer_space, contents_scale, contents_scale); | |
40 MockContentLayerClient client(opaque_rect_in_layer_space); | |
41 scoped_refptr<BitmapContentLayerUpdater> updater = | |
42 BitmapContentLayerUpdater::Create(ContentLayerPainter::Create(&client). | |
43 PassAs<LayerPainter>()); | |
44 | |
45 gfx::Rect resulting_opaque_rect; | |
46 updater->PrepareToUpdate(content_rect, | |
47 gfx::Size(256, 256), | |
48 contents_scale, | |
49 contents_scale, | |
50 &resulting_opaque_rect, | |
51 NULL); | |
52 | |
53 EXPECT_RECT_EQ(gfx::ToEnclosingRect(opaque_rect_in_content_space), | |
54 resulting_opaque_rect); | |
55 } | |
56 | |
57 } // namespace | |
58 } // namespace cc | |
OLD | NEW |