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

Side by Side Diff: cc/playback/discardable_image_map_unittest.cc

Issue 2327903002: gfx: Do the ToEnclosingRect in double precision. (Closed)
Patch Set: update Created 4 years, 3 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
« no previous file with comments | « no previous file | ui/gfx/geometry/rect_conversions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/playback/discardable_image_map.h" 5 #include "cc/playback/discardable_image_map.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 visible_rect.size()); 398 visible_rect.size());
399 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); 399 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f);
400 } 400 }
401 std::vector<PositionDrawImage> images = 401 std::vector<PositionDrawImage> images =
402 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); 402 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1));
403 EXPECT_EQ(1u, images.size()); 403 EXPECT_EQ(1u, images.size());
404 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect); 404 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect);
405 405
406 images = GetDiscardableImagesInRect(image_map, gfx::Rect(10000, 0, 1, 1)); 406 images = GetDiscardableImagesInRect(image_map, gfx::Rect(10000, 0, 1, 1));
407 EXPECT_EQ(2u, images.size()); 407 EXPECT_EQ(2u, images.size());
408 int expected10k = static_cast<int>(static_cast<float>(dimension - 10000)); 408 EXPECT_EQ(gfx::Rect(10000, 0, dimension - 10000, dimension),
409 int expected500 = static_cast<int>(static_cast<float>(dimension - 500)); 409 images[1].image_rect);
410 EXPECT_EQ(gfx::Rect(10000, 0, expected10k, dimension), images[1].image_rect);
411 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect); 410 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect);
412 411
412 // Since we adjust negative offsets before using ToEnclosingRect, the expected
413 // width will be converted to float, which means that we lose some precision.
414 // The expected value is whatever the value is converted to float and then
415 // back to int.
416 int expected10k = static_cast<int>(static_cast<float>(dimension - 10000));
413 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); 417 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1));
414 EXPECT_EQ(2u, images.size()); 418 EXPECT_EQ(2u, images.size());
415 EXPECT_EQ(gfx::Rect(0, 500, expected10k, expected500), images[1].image_rect); 419 EXPECT_EQ(gfx::Rect(0, 500, expected10k, dimension - 500),
420 images[1].image_rect);
416 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect); 421 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), images[0].image_rect);
417 } 422 }
418 423
419 TEST_F(DiscardableImageMapTest, GetDiscardableImagesRectInBounds) { 424 TEST_F(DiscardableImageMapTest, GetDiscardableImagesRectInBounds) {
420 gfx::Rect visible_rect(1000, 1000); 425 gfx::Rect visible_rect(1000, 1000);
421 FakeContentLayerClient content_layer_client; 426 FakeContentLayerClient content_layer_client;
422 content_layer_client.set_bounds(visible_rect.size()); 427 content_layer_client.set_bounds(visible_rect.size());
423 428
424 sk_sp<SkImage> discardable_image = 429 sk_sp<SkImage> discardable_image =
425 CreateDiscardableImage(gfx::Size(100, 100)); 430 CreateDiscardableImage(gfx::Size(100, 100));
(...skipping 26 matching lines...) Expand all
452 images = GetDiscardableImagesInRect(image_map, gfx::Rect(999, 999, 1, 1)); 457 images = GetDiscardableImagesInRect(image_map, gfx::Rect(999, 999, 1, 1));
453 EXPECT_EQ(1u, images.size()); 458 EXPECT_EQ(1u, images.size());
454 EXPECT_EQ(gfx::Rect(950, 951, 50, 49), images[0].image_rect); 459 EXPECT_EQ(gfx::Rect(950, 951, 50, 49), images[0].image_rect);
455 460
456 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); 461 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1));
457 EXPECT_EQ(1u, images.size()); 462 EXPECT_EQ(1u, images.size());
458 EXPECT_EQ(gfx::Rect(0, 500, 1000, 100), images[0].image_rect); 463 EXPECT_EQ(gfx::Rect(0, 500, 1000, 100), images[0].image_rect);
459 } 464 }
460 465
461 } // namespace cc 466 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/geometry/rect_conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698