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

Side by Side Diff: cc/picture_layer_tiling_unittest.cc

Issue 12287027: cc: Compute the inflated rect to cover a fixed number of tiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use sqrt(double) for android Created 7 years, 10 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
« cc/picture_layer_tiling.cc ('K') | « cc/picture_layer_tiling.cc ('k') | no next file » | 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/picture_layer_tiling.h" 5 #include "cc/picture_layer_tiling.h"
6 6
7 #include "cc/test/fake_picture_layer_tiling_client.h" 7 #include "cc/test/fake_picture_layer_tiling_client.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/rect_conversions.h" 9 #include "ui/gfx/rect_conversions.h"
10 #include "ui/gfx/size_conversions.h" 10 #include "ui/gfx/size_conversions.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000)); 172 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, -1000, 2000, 2000));
173 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000)); 173 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, -1000, 2000, 2000));
174 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000)); 174 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, -1000, 2000, 2000));
175 175
176 // Partially covering content, but too large 176 // Partially covering content, but too large
177 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100)); 177 VerifyTilesCoverNonContainedRect(1.0f, gfx::Rect(-1000, 100, 2000, 100));
178 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100)); 178 VerifyTilesCoverNonContainedRect(1.5f, gfx::Rect(-1000, 100, 2000, 100));
179 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100)); 179 VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100));
180 } 180 }
181 181
182 TEST(PictureLayerTilingTest, ExpandRectEqual) {
183 gfx::Rect in(40, 50, 100, 200);
184 gfx::Rect bounds(-1000, -1000, 10000, 10000);
185 int64 target_area = 100 * 200;
186 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
187 in, target_area, bounds);
188 EXPECT_EQ(in.ToString(), out.ToString());
189 }
190
191 TEST(PictureLayerTilingTest, ExpandRectSmaller) {
192 gfx::Rect in(40, 50, 100, 200);
193 gfx::Rect bounds(-1000, -1000, 10000, 10000);
194 int64 target_area = 100 * 100;
195 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
196 in, target_area, bounds);
197 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
198 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
199 EXPECT_EQ(out.width() - in.width(), out.height() - in.height());
200 EXPECT_NEAR(100 * 100, out.width() * out.height(), 50);
201 EXPECT_TRUE(bounds.Contains(out));
202 }
203
204 TEST(PictureLayerTilingTest, ExpandRectUnbounded) {
205 gfx::Rect in(40, 50, 100, 200);
206 gfx::Rect bounds(-1000, -1000, 10000, 10000);
207 int64 target_area = 200 * 200;
208 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
209 in, target_area, bounds);
210 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
211 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
212 EXPECT_EQ(out.width() - in.width(), out.height() - in.height());
213 EXPECT_NEAR(200 * 200, out.width() * out.height(), 100);
214 EXPECT_TRUE(bounds.Contains(out));
215 }
216
217 TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) {
218 gfx::Rect in(40, 50, 100, 200);
219 gfx::Rect bounds(50, 60, 40, 30);
220 int64 target_area = 200 * 200;
221 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
222 in, target_area, bounds);
223 EXPECT_EQ(bounds.ToString(), out.ToString());
224 }
225
226 TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) {
227 gfx::Rect in(40, 50, 100, 200);
228 gfx::Rect bounds = in;
229 int64 target_area = 200 * 200;
230 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
231 in, target_area, bounds);
232 EXPECT_EQ(bounds.ToString(), out.ToString());
233 }
234
235 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) {
236 gfx::Rect in(40, 50, 100, 200);
237 gfx::Rect bounds(45, 0, 90, 300);
238 int64 target_area = 200 * 200;
239 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
240 in, target_area, bounds);
241 EXPECT_EQ(bounds.ToString(), out.ToString());
242 }
243
244 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) {
245 gfx::Rect in(40, 50, 100, 200);
246 gfx::Rect bounds(40, 0, 100, 300);
247 int64 target_area = 200 * 200;
248 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
249 in, target_area, bounds);
250 EXPECT_EQ(bounds.ToString(), out.ToString());
251 }
252
253 TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) {
254 gfx::Rect in(40, 50, 100, 200);
255 gfx::Rect bounds(0, 55, 180, 190);
256 int64 target_area = 200 * 200;
257 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
258 in, target_area, bounds);
259 EXPECT_EQ(bounds.ToString(), out.ToString());
260 }
261
262 TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) {
263 gfx::Rect in(40, 50, 100, 200);
264 gfx::Rect bounds(0, 50, 180, 200);
265 int64 target_area = 200 * 200;
266 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
267 in, target_area, bounds);
268 EXPECT_EQ(bounds.ToString(), out.ToString());
269 }
270
271 TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) {
272 gfx::Rect in(40, 50, 100, 200);
273 gfx::Rect bounds(20, -1000, 10000, 10000);
274 int64 target_area = 200 * 200;
275 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
276 in, target_area, bounds);
277 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
278 EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right());
279 EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
280 EXPECT_TRUE(bounds.Contains(out));
281 }
282
283 TEST(PictureLayerTilingTest, ExpandRectBoundedRight) {
284 gfx::Rect in(40, 50, 100, 200);
285 gfx::Rect bounds(-1000, -1000, 1000+120, 10000);
286 int64 target_area = 200 * 200;
287 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
288 in, target_area, bounds);
289 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
290 EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x());
291 EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
292 EXPECT_TRUE(bounds.Contains(out));
293 }
294
295 TEST(PictureLayerTilingTest, ExpandRectBoundedTop) {
296 gfx::Rect in(40, 50, 100, 200);
297 gfx::Rect bounds(-1000, 30, 10000, 10000);
298 int64 target_area = 200 * 200;
299 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
300 in, target_area, bounds);
301 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
302 EXPECT_EQ(out.right() - in.right(), out.bottom() - in.bottom());
303 EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
304 EXPECT_TRUE(bounds.Contains(out));
305 }
306
307 TEST(PictureLayerTilingTest, ExpandRectBoundedBottom) {
308 gfx::Rect in(40, 50, 100, 200);
309 gfx::Rect bounds(-1000, -1000, 10000, 1000 + 220);
310 int64 target_area = 200 * 200;
311 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
312 in, target_area, bounds);
313 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
314 EXPECT_EQ(out.right() - in.right(), in.y() - out.y());
315 EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
316 EXPECT_TRUE(bounds.Contains(out));
317 }
318
319 TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) {
320 gfx::Rect in(40, 50, 100, 200);
321 gfx::Rect bounds(0, -4000, 100+40+20, 100000);
322 int64 target_area = 400 * 400;
323 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
324 in, target_area, bounds);
325 EXPECT_EQ(20, out.right() - in.right());
326 EXPECT_EQ(40, in.x() - out.x());
327 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
328 EXPECT_NEAR(400 * 400, out.width() * out.height(), 500);
329 EXPECT_TRUE(bounds.Contains(out));
330 }
331
332 TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) {
333 gfx::Rect in(40, 50, 100, 200);
334 gfx::Rect bounds(-4000, 0, 100000, 200+50+30);
335 int64 target_area = 400 * 400;
336 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
337 in, target_area, bounds);
338 EXPECT_EQ(30, out.bottom() - in.bottom());
339 EXPECT_EQ(50, in.y() - out.y());
340 EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
341 EXPECT_NEAR(400 * 400, out.width() * out.height(), 500);
342 EXPECT_TRUE(bounds.Contains(out));
343 }
344
182 } // namespace 345 } // namespace
183 } // namespace cc 346 } // namespace cc
OLDNEW
« cc/picture_layer_tiling.cc ('K') | « cc/picture_layer_tiling.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698