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

Side by Side Diff: cc/picture_layer_tiling_set_unittest.cc

Issue 12471007: Part 8 of cc/ directory shuffles: resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
« no previous file with comments | « cc/picture_layer_tiling_set.cc ('k') | cc/picture_layer_tiling_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
(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/picture_layer_tiling_set.h"
6
7 #include "cc/resource_pool.h"
8 #include "cc/resource_provider.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_picture_layer_tiling_client.h"
11 #include "cc/test/fake_tile_manager_client.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/size_conversions.h"
14
15 namespace cc {
16 namespace {
17
18 TEST(PictureLayerTilingSetTest, NoResources) {
19 FakePictureLayerTilingClient client;
20 PictureLayerTilingSet set(&client);
21 client.SetTileSize(gfx::Size(256, 256));
22
23 gfx::Size layer_bounds(1000, 800);
24 set.SetLayerBounds(layer_bounds);
25
26 set.AddTiling(1.0);
27 set.AddTiling(1.5);
28 set.AddTiling(2.0);
29
30 float contents_scale = 2.0;
31 gfx::Size content_bounds(
32 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
33 gfx::Rect content_rect(gfx::Point(), content_bounds);
34
35 Region remaining(content_rect);
36 PictureLayerTilingSet::Iterator iter(
37 &set,
38 contents_scale,
39 content_rect,
40 contents_scale,
41 PictureLayerTiling::LayerDeviceAlignmentUnknown);
42 for (; iter; ++iter) {
43 gfx::Rect geometry_rect = iter.geometry_rect();
44 EXPECT_TRUE(content_rect.Contains(geometry_rect));
45 ASSERT_TRUE(remaining.Contains(geometry_rect));
46 remaining.Subtract(geometry_rect);
47
48 // No tiles have resources, so no iter represents a real tile.
49 EXPECT_FALSE(*iter);
50 }
51 EXPECT_TRUE(remaining.IsEmpty());
52 }
53
54 class PictureLayerTilingSetTestWithResources : public testing::Test {
55 public:
56 void runTest(
57 int num_tilings,
58 float min_scale,
59 float scale_increment,
60 float ideal_contents_scale,
61 float expected_scale) {
62 scoped_ptr<FakeOutputSurface> output_surface =
63 FakeOutputSurface::Create3d();
64 scoped_ptr<ResourceProvider> resource_provider =
65 ResourceProvider::Create(output_surface.get());
66
67 FakePictureLayerTilingClient client;
68 client.SetTileSize(gfx::Size(256, 256));
69 PictureLayerTilingSet set(&client);
70
71 gfx::Size layer_bounds(1000, 800);
72 set.SetLayerBounds(layer_bounds);
73
74 float scale = min_scale;
75 for (int i = 0; i < num_tilings; ++i, scale += scale_increment) {
76 PictureLayerTiling* tiling = set.AddTiling(scale);
77 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
78 for (size_t i = 0; i < tiles.size(); ++i) {
79 EXPECT_FALSE(tiles[i]->drawing_info().GetResourceForTesting());
80
81 tiles[i]->drawing_info().GetResourceForTesting() =
82 make_scoped_ptr(new ResourcePool::Resource(
83 resource_provider.get(),
84 gfx::Size(1, 1),
85 resource_provider->best_texture_format()));
86 }
87 }
88
89 float max_contents_scale = scale;
90 gfx::Size content_bounds(
91 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, max_contents_scale)));
92 gfx::Rect content_rect(gfx::Point(), content_bounds);
93
94 Region remaining(content_rect);
95 PictureLayerTilingSet::Iterator iter(
96 &set,
97 max_contents_scale,
98 content_rect,
99 ideal_contents_scale,
100 PictureLayerTiling::LayerDeviceAlignmentUnknown);
101 for (; iter; ++iter) {
102 gfx::Rect geometry_rect = iter.geometry_rect();
103 EXPECT_TRUE(content_rect.Contains(geometry_rect));
104 ASSERT_TRUE(remaining.Contains(geometry_rect));
105 remaining.Subtract(geometry_rect);
106
107 float scale = iter.CurrentTiling()->contents_scale();
108 EXPECT_EQ(expected_scale, scale);
109
110 if (num_tilings)
111 EXPECT_TRUE(*iter);
112 else
113 EXPECT_FALSE(*iter);
114 }
115 EXPECT_TRUE(remaining.IsEmpty());
116 }
117 };
118
119 TEST_F(PictureLayerTilingSetTestWithResources, NoTilings) {
120 runTest(0, 0.f, 0.f, 2.f, 0.f);
121 }
122 TEST_F(PictureLayerTilingSetTestWithResources, OneTiling_Smaller) {
123 runTest(1, 1.f, 0.f, 2.f, 1.f);
124 }
125 TEST_F(PictureLayerTilingSetTestWithResources, OneTiling_Larger) {
126 runTest(1, 3.f, 0.f, 2.f, 3.f);
127 }
128 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_Smaller) {
129 runTest(2, 1.f, 1.f, 3.f, 2.f);
130 }
131
132 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_SmallerEqual) {
133 runTest(2, 1.f, 1.f, 2.f, 2.f);
134 }
135
136 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_LargerEqual) {
137 runTest(2, 1.f, 1.f, 1.f, 1.f);
138 }
139
140 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_Larger) {
141 runTest(2, 2.f, 8.f, 1.f, 2.f);
142 }
143
144 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_Equal) {
145 runTest(10, 1.f, 1.f, 5.f, 5.f);
146 }
147
148 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_NotEqual) {
149 runTest(10, 1.f, 1.f, 4.5f, 5.f);
150 }
151
152 } // namespace
153 } // namespace cc
OLDNEW
« no previous file with comments | « cc/picture_layer_tiling_set.cc ('k') | cc/picture_layer_tiling_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698