OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/gfx/image/image_skia.h" | 5 #include "ui/gfx/image/image_skia.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/simple_thread.h" | 9 #include "base/threading/simple_thread.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 ImageSkiaRep rep_2x(Size(100, 100), 2.0f); | 417 ImageSkiaRep rep_2x(Size(100, 100), 2.0f); |
418 | 418 |
419 // When reps for other scales are added, the unscaled image | 419 // When reps for other scales are added, the unscaled image |
420 // becomes scaled. | 420 // becomes scaled. |
421 image_skia.AddRepresentation(rep_2x); | 421 image_skia.AddRepresentation(rep_2x); |
422 EXPECT_FALSE(image_skia.GetRepresentation(1.0f).unscaled()); | 422 EXPECT_FALSE(image_skia.GetRepresentation(1.0f).unscaled()); |
423 EXPECT_FALSE(image_skia.GetRepresentation(2.0f).unscaled()); | 423 EXPECT_FALSE(image_skia.GetRepresentation(2.0f).unscaled()); |
424 } | 424 } |
425 | 425 |
426 TEST_F(ImageSkiaTest, ArbitraryScaleFactor) { | 426 TEST_F(ImageSkiaTest, ArbitraryScaleFactor) { |
427 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
428 switches::kAllowArbitraryScaleFactorInImageSkia); | |
429 | |
430 // Do not test if the ImageSkia doesn't support arbitrary scale factors. | 427 // Do not test if the ImageSkia doesn't support arbitrary scale factors. |
431 if (!ImageSkia::IsDSFScalingInImageSkiaEnabled()) | 428 if (!ImageSkia::IsDSFScalingInImageSkiaEnabled()) |
432 return; | 429 return; |
433 | 430 |
434 // source is owned by |image| | 431 // source is owned by |image| |
435 DynamicSource* source = new DynamicSource(Size(100, 200)); | 432 DynamicSource* source = new DynamicSource(Size(100, 200)); |
436 ImageSkia image(source, gfx::Size(100, 200)); | 433 ImageSkia image(source, gfx::Size(100, 200)); |
437 | 434 |
438 image.GetRepresentation(1.5f); | 435 image.GetRepresentation(1.5f); |
439 EXPECT_EQ(2.0f, source->GetLastRequestedScaleAndReset()); | 436 EXPECT_EQ(2.0f, source->GetLastRequestedScaleAndReset()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 487 |
491 // Scale factor greater than 2.0f is falled back to 2.0f because it's not | 488 // Scale factor greater than 2.0f is falled back to 2.0f because it's not |
492 // supported. | 489 // supported. |
493 image.GetRepresentation(3.0f); | 490 image.GetRepresentation(3.0f); |
494 EXPECT_EQ(0.0f, source->GetLastRequestedScaleAndReset()); | 491 EXPECT_EQ(0.0f, source->GetLastRequestedScaleAndReset()); |
495 image_reps = image.image_reps(); | 492 image_reps = image.image_reps(); |
496 EXPECT_EQ(7u, image_reps.size()); | 493 EXPECT_EQ(7u, image_reps.size()); |
497 } | 494 } |
498 | 495 |
499 TEST_F(ImageSkiaTest, ArbitraryScaleFactorWithMissingResource) { | 496 TEST_F(ImageSkiaTest, ArbitraryScaleFactorWithMissingResource) { |
500 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
501 switches::kAllowArbitraryScaleFactorInImageSkia); | |
502 | |
503 // Do not test if the ImageSkia doesn't support arbitrary scale factors. | 497 // Do not test if the ImageSkia doesn't support arbitrary scale factors. |
504 if (!ImageSkia::IsDSFScalingInImageSkiaEnabled()) | 498 if (!ImageSkia::IsDSFScalingInImageSkiaEnabled()) |
505 return; | 499 return; |
506 | 500 |
507 ImageSkia image(new FixedSource( | 501 ImageSkia image(new FixedSource( |
508 ImageSkiaRep(Size(100, 200), 1.0f)), Size(100, 200)); | 502 ImageSkiaRep(Size(100, 200), 1.0f)), Size(100, 200)); |
509 | 503 |
510 // Requesting 1.5f -- falls back to 2.0f, but couldn't find. It should | 504 // Requesting 1.5f -- falls back to 2.0f, but couldn't find. It should |
511 // look up 1.0f and then rescale it. | 505 // look up 1.0f and then rescale it. |
512 const ImageSkiaRep& rep = image.GetRepresentation(1.5f); | 506 const ImageSkiaRep& rep = image.GetRepresentation(1.5f); |
513 EXPECT_EQ(1.5f, rep.scale()); | 507 EXPECT_EQ(1.5f, rep.scale()); |
514 EXPECT_EQ(2U, image.image_reps().size()); | 508 EXPECT_EQ(2U, image.image_reps().size()); |
515 EXPECT_EQ(1.0f, image.image_reps()[0].scale()); | 509 EXPECT_EQ(1.0f, image.image_reps()[0].scale()); |
516 EXPECT_EQ(1.5f, image.image_reps()[1].scale()); | 510 EXPECT_EQ(1.5f, image.image_reps()[1].scale()); |
517 } | 511 } |
518 | 512 |
519 TEST_F(ImageSkiaTest, UnscaledImageForArbitraryScaleFactor) { | 513 TEST_F(ImageSkiaTest, UnscaledImageForArbitraryScaleFactor) { |
520 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
521 switches::kAllowArbitraryScaleFactorInImageSkia); | |
522 | |
523 // Do not test if the ImageSkia doesn't support arbitrary scale factors. | 514 // Do not test if the ImageSkia doesn't support arbitrary scale factors. |
524 if (!ImageSkia::IsDSFScalingInImageSkiaEnabled()) | 515 if (!ImageSkia::IsDSFScalingInImageSkiaEnabled()) |
525 return; | 516 return; |
526 | 517 |
527 // 0.0f means unscaled. | 518 // 0.0f means unscaled. |
528 ImageSkia image(new FixedSource( | 519 ImageSkia image(new FixedSource( |
529 ImageSkiaRep(Size(100, 200), 0.0f)), Size(100, 200)); | 520 ImageSkiaRep(Size(100, 200), 0.0f)), Size(100, 200)); |
530 | 521 |
531 // Requesting 2.0f, which should return 1.0f unscaled image. | 522 // Requesting 2.0f, which should return 1.0f unscaled image. |
532 const ImageSkiaRep& rep = image.GetRepresentation(2.0f); | 523 const ImageSkiaRep& rep = image.GetRepresentation(2.0f); |
(...skipping 10 matching lines...) Expand all Loading... |
543 EXPECT_EQ(1U, image.image_reps().size()); | 534 EXPECT_EQ(1U, image.image_reps().size()); |
544 | 535 |
545 const ImageSkiaRep& rep12 = image.GetRepresentation(1.2f); | 536 const ImageSkiaRep& rep12 = image.GetRepresentation(1.2f); |
546 EXPECT_EQ(1.0f, rep12.scale()); | 537 EXPECT_EQ(1.0f, rep12.scale()); |
547 EXPECT_EQ("100x200", rep12.pixel_size().ToString()); | 538 EXPECT_EQ("100x200", rep12.pixel_size().ToString()); |
548 EXPECT_TRUE(rep12.unscaled()); | 539 EXPECT_TRUE(rep12.unscaled()); |
549 EXPECT_EQ(1U, image.image_reps().size()); | 540 EXPECT_EQ(1U, image.image_reps().size()); |
550 } | 541 } |
551 | 542 |
552 } // namespace gfx | 543 } // namespace gfx |
OLD | NEW |