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 // Because the unit tests for gfx::Image are spread across multiple | 5 // Because the unit tests for gfx::Image are spread across multiple |
6 // implementation files, this header contains the reusable components. | 6 // implementation files, this header contains the reusable components. |
7 | 7 |
8 #include "ui/gfx/image/image_unittest_util.h" | 8 #include "ui/gfx/image/image_unittest_util.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 gfx::Image CreateImage() { | 74 gfx::Image CreateImage() { |
75 return CreateImage(100, 50); | 75 return CreateImage(100, 50); |
76 } | 76 } |
77 | 77 |
78 gfx::Image CreateImage(int width, int height) { | 78 gfx::Image CreateImage(int width, int height) { |
79 return gfx::Image::CreateFrom1xBitmap(CreateBitmap(width, height)); | 79 return gfx::Image::CreateFrom1xBitmap(CreateBitmap(width, height)); |
80 } | 80 } |
81 | 81 |
82 bool IsEqual(const gfx::Image& img1, const gfx::Image& img2) { | 82 bool IsEqual(const gfx::Image& img1, const gfx::Image& img2) { |
83 img1.AsImageSkia().EnsureRepsForSupportedScales(); | |
84 img2.AsImageSkia().EnsureRepsForSupportedScales(); | |
85 std::vector<gfx::ImageSkiaRep> img1_reps = img1.AsImageSkia().image_reps(); | 83 std::vector<gfx::ImageSkiaRep> img1_reps = img1.AsImageSkia().image_reps(); |
86 gfx::ImageSkia image_skia2 = img2.AsImageSkia(); | 84 gfx::ImageSkia image_skia2 = img2.AsImageSkia(); |
87 if (image_skia2.image_reps().size() != img1_reps.size()) | 85 if (image_skia2.image_reps().size() != img1_reps.size()) |
88 return false; | 86 return false; |
89 | 87 |
90 for (size_t i = 0; i < img1_reps.size(); ++i) { | 88 for (size_t i = 0; i < img1_reps.size(); ++i) { |
91 float scale = img1_reps[i].scale(); | 89 float scale = img1_reps[i].scale(); |
92 const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(scale); | 90 const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(scale); |
93 if (image_rep2.scale() != scale || | 91 if (image_rep2.scale() != scale || |
94 !IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) { | 92 !IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { | 253 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { |
256 #if defined(OS_MACOSX) | 254 #if defined(OS_MACOSX) |
257 return image1 == image2; | 255 return image1 == image2; |
258 #else | 256 #else |
259 return image1.BackedBySameObjectAs(image2); | 257 return image1.BackedBySameObjectAs(image2); |
260 #endif | 258 #endif |
261 } | 259 } |
262 | 260 |
263 } // namespace test | 261 } // namespace test |
264 } // namespace gfx | 262 } // namespace gfx |
OLD | NEW |