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

Side by Side Diff: ui/gfx/image/image_unittest_util.cc

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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 30 matching lines...) Expand all
41 bool ColorsClose(SkColor color1, SkColor color2) { 41 bool ColorsClose(SkColor color1, SkColor color2) {
42 // Be tolerant of floating point rounding and lossy color space conversions. 42 // Be tolerant of floating point rounding and lossy color space conversions.
43 return ColorComponentsClose(SkColorGetR(color1), SkColorGetR(color2)) && 43 return ColorComponentsClose(SkColorGetR(color1), SkColorGetR(color2)) &&
44 ColorComponentsClose(SkColorGetG(color1), SkColorGetG(color2)) && 44 ColorComponentsClose(SkColorGetG(color1), SkColorGetG(color2)) &&
45 ColorComponentsClose(SkColorGetB(color1), SkColorGetB(color2)) && 45 ColorComponentsClose(SkColorGetB(color1), SkColorGetB(color2)) &&
46 ColorComponentsClose(SkColorGetA(color1), SkColorGetA(color2)); 46 ColorComponentsClose(SkColorGetA(color1), SkColorGetA(color2));
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 std::vector<ui::ScaleFactor> Get1xAnd2xScaleFactors() { 51 std::vector<float> Get1xAnd2xScales() {
52 std::vector<ui::ScaleFactor> scale_factors; 52 std::vector<float> scales;
53 scale_factors.push_back(ui::SCALE_FACTOR_100P); 53 scales.push_back(1.0f);
54 scale_factors.push_back(ui::SCALE_FACTOR_200P); 54 scales.push_back(2.0f);
55 return scale_factors; 55 return scales;
56 } 56 }
57 57
58 const SkBitmap CreateBitmap(int width, int height) { 58 const SkBitmap CreateBitmap(int width, int height) {
59 SkBitmap bitmap; 59 SkBitmap bitmap;
60 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 60 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
61 bitmap.allocPixels(); 61 bitmap.allocPixels();
62 bitmap.eraseRGB(0, 255, 0); 62 bitmap.eraseRGB(0, 255, 0);
63 return bitmap; 63 return bitmap;
64 } 64 }
65 65
(...skipping 16 matching lines...) Expand all
82 return gfx::Image::CreateFrom1xBitmap(CreateBitmap(width, height)); 82 return gfx::Image::CreateFrom1xBitmap(CreateBitmap(width, height));
83 } 83 }
84 84
85 bool IsEqual(const gfx::Image& img1, const gfx::Image& img2) { 85 bool IsEqual(const gfx::Image& img1, const gfx::Image& img2) {
86 std::vector<gfx::ImageSkiaRep> img1_reps = img1.AsImageSkia().image_reps(); 86 std::vector<gfx::ImageSkiaRep> img1_reps = img1.AsImageSkia().image_reps();
87 gfx::ImageSkia image_skia2 = img2.AsImageSkia(); 87 gfx::ImageSkia image_skia2 = img2.AsImageSkia();
88 if (image_skia2.image_reps().size() != img1_reps.size()) 88 if (image_skia2.image_reps().size() != img1_reps.size())
89 return false; 89 return false;
90 90
91 for (size_t i = 0; i < img1_reps.size(); ++i) { 91 for (size_t i = 0; i < img1_reps.size(); ++i) {
92 ui::ScaleFactor scale_factor = img1_reps[i].scale_factor(); 92 float scale = img1_reps[i].scale();
93 const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation( 93 const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(scale);
94 scale_factor); 94 if (image_rep2.scale() != scale ||
95 if (image_rep2.scale_factor() != scale_factor ||
96 !IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) { 95 !IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) {
97 return false; 96 return false;
98 } 97 }
99 } 98 }
100 return true; 99 return true;
101 } 100 }
102 101
103 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) { 102 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) {
104 if (bmp1.isNull() && bmp2.isNull()) 103 if (bmp1.isNull() && bmp2.isNull())
105 return true; 104 return true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 EXPECT_LE(16, bitmap.width()); 142 EXPECT_LE(16, bitmap.width());
144 EXPECT_LE(16, bitmap.height()); 143 EXPECT_LE(16, bitmap.height());
145 SkAutoLockPixels auto_lock(bitmap); 144 SkAutoLockPixels auto_lock(bitmap);
146 CheckColors(bitmap.getColor(10, 10), SK_ColorRED); 145 CheckColors(bitmap.getColor(10, 10), SK_ColorRED);
147 } 146 }
148 147
149 bool ImageSkiaStructureMatches( 148 bool ImageSkiaStructureMatches(
150 const gfx::ImageSkia& image_skia, 149 const gfx::ImageSkia& image_skia,
151 int width, 150 int width,
152 int height, 151 int height,
153 const std::vector<ui::ScaleFactor>& scale_factors) { 152 const std::vector<float>& scales) {
154 if (image_skia.isNull() || 153 if (image_skia.isNull() ||
155 image_skia.width() != width || 154 image_skia.width() != width ||
156 image_skia.height() != height || 155 image_skia.height() != height ||
157 image_skia.image_reps().size() != scale_factors.size()) { 156 image_skia.image_reps().size() != scales.size()) {
158 return false; 157 return false;
159 } 158 }
160 159
161 for (size_t i = 0; i < scale_factors.size(); ++i) { 160 for (size_t i = 0; i < scales.size(); ++i) {
162 gfx::ImageSkiaRep image_rep = 161 gfx::ImageSkiaRep image_rep =
163 image_skia.GetRepresentation(scale_factors[i]); 162 image_skia.GetRepresentation(scales[i]);
164 if (image_rep.is_null() || 163 if (image_rep.is_null() || image_rep.scale() != scales[i])
165 image_rep.scale_factor() != scale_factors[i])
166 return false; 164 return false;
167 165
168 float scale = ui::GetScaleFactorScale(scale_factors[i]); 166 if (image_rep.pixel_width() != static_cast<int>(width * scales[i]) ||
169 if (image_rep.pixel_width() != static_cast<int>(width * scale) || 167 image_rep.pixel_height() != static_cast<int>(height * scales[i])) {
170 image_rep.pixel_height() != static_cast<int>(height * scale)) {
171 return false; 168 return false;
172 } 169 }
173 } 170 }
174 return true; 171 return true;
175 } 172 }
176 173
177 bool IsEmpty(const gfx::Image& image) { 174 bool IsEmpty(const gfx::Image& image) {
178 const SkBitmap& bmp = *image.ToSkBitmap(); 175 const SkBitmap& bmp = *image.ToSkBitmap();
179 return bmp.isNull() || 176 return bmp.isNull() ||
180 (bmp.width() == 0 && bmp.height() == 0); 177 (bmp.width() == 0 && bmp.height() == 0);
181 } 178 }
182 179
183 PlatformImage CreatePlatformImage() { 180 PlatformImage CreatePlatformImage() {
184 const SkBitmap bitmap(CreateBitmap(25, 25)); 181 const SkBitmap bitmap(CreateBitmap(25, 25));
185 #if defined(OS_IOS) 182 #if defined(OS_IOS)
186 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor(); 183 float scale = ImageSkia::GetSupportedScales().back();
187 float scale = ui::GetScaleFactorScale(scale_factor);
188 184
189 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( 185 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
190 CGColorSpaceCreateDeviceRGB()); 186 CGColorSpaceCreateDeviceRGB());
191 UIImage* image = 187 UIImage* image =
192 gfx::SkBitmapToUIImageWithColorSpace(bitmap, scale, color_space); 188 gfx::SkBitmapToUIImageWithColorSpace(bitmap, scale, color_space);
193 base::mac::NSObjectRetain(image); 189 base::mac::NSObjectRetain(image);
194 return image; 190 return image;
195 #elif defined(OS_MACOSX) 191 #elif defined(OS_MACOSX)
196 NSImage* image = gfx::SkBitmapToNSImage(bitmap); 192 NSImage* image = gfx::SkBitmapToNSImage(bitmap);
197 base::mac::NSObjectRetain(image); 193 base::mac::NSObjectRetain(image);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { 274 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) {
279 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) 275 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
280 return image1 == image2; 276 return image1 == image2;
281 #else 277 #else
282 return image1.BackedBySameObjectAs(image2); 278 return image1.BackedBySameObjectAs(image2);
283 #endif 279 #endif
284 } 280 }
285 281
286 } // namespace test 282 } // namespace test
287 } // namespace gfx 283 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698