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

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

Issue 24262008: Revert 224473 "Remove dependency on ui::ScaleFactor from ui/gfx" (Closed) Base URL: svn://svn.chromium.org/chrome/
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
« no previous file with comments | « trunk/src/ui/gfx/image/image_unittest_util.h ('k') | trunk/src/ui/gfx/image/image_util.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 (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<float> Get1xAnd2xScales() { 51 std::vector<ui::ScaleFactor> Get1xAnd2xScaleFactors() {
52 std::vector<float> scales; 52 std::vector<ui::ScaleFactor> scale_factors;
53 scales.push_back(1.0f); 53 scale_factors.push_back(ui::SCALE_FACTOR_100P);
54 scales.push_back(2.0f); 54 scale_factors.push_back(ui::SCALE_FACTOR_200P);
55 return scales; 55 return scale_factors;
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 float scale = img1_reps[i].scale(); 92 ui::ScaleFactor scale_factor = img1_reps[i].scale_factor();
93 const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(scale); 93 const gfx::ImageSkiaRep& image_rep2 = image_skia2.GetRepresentation(
94 if (image_rep2.scale() != scale || 94 scale_factor);
95 if (image_rep2.scale_factor() != scale_factor ||
95 !IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) { 96 !IsEqual(img1_reps[i].sk_bitmap(), image_rep2.sk_bitmap())) {
96 return false; 97 return false;
97 } 98 }
98 } 99 }
99 return true; 100 return true;
100 } 101 }
101 102
102 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) { 103 bool IsEqual(const SkBitmap& bmp1, const SkBitmap& bmp2) {
103 if (bmp1.isNull() && bmp2.isNull()) 104 if (bmp1.isNull() && bmp2.isNull())
104 return true; 105 return true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_LE(16, bitmap.width()); 143 EXPECT_LE(16, bitmap.width());
143 EXPECT_LE(16, bitmap.height()); 144 EXPECT_LE(16, bitmap.height());
144 SkAutoLockPixels auto_lock(bitmap); 145 SkAutoLockPixels auto_lock(bitmap);
145 CheckColors(bitmap.getColor(10, 10), SK_ColorRED); 146 CheckColors(bitmap.getColor(10, 10), SK_ColorRED);
146 } 147 }
147 148
148 bool ImageSkiaStructureMatches( 149 bool ImageSkiaStructureMatches(
149 const gfx::ImageSkia& image_skia, 150 const gfx::ImageSkia& image_skia,
150 int width, 151 int width,
151 int height, 152 int height,
152 const std::vector<float>& scales) { 153 const std::vector<ui::ScaleFactor>& scale_factors) {
153 if (image_skia.isNull() || 154 if (image_skia.isNull() ||
154 image_skia.width() != width || 155 image_skia.width() != width ||
155 image_skia.height() != height || 156 image_skia.height() != height ||
156 image_skia.image_reps().size() != scales.size()) { 157 image_skia.image_reps().size() != scale_factors.size()) {
157 return false; 158 return false;
158 } 159 }
159 160
160 for (size_t i = 0; i < scales.size(); ++i) { 161 for (size_t i = 0; i < scale_factors.size(); ++i) {
161 gfx::ImageSkiaRep image_rep = 162 gfx::ImageSkiaRep image_rep =
162 image_skia.GetRepresentation(scales[i]); 163 image_skia.GetRepresentation(scale_factors[i]);
163 if (image_rep.is_null() || image_rep.scale() != scales[i]) 164 if (image_rep.is_null() ||
165 image_rep.scale_factor() != scale_factors[i])
164 return false; 166 return false;
165 167
166 if (image_rep.pixel_width() != static_cast<int>(width * scales[i]) || 168 float scale = ui::GetScaleFactorScale(scale_factors[i]);
167 image_rep.pixel_height() != static_cast<int>(height * scales[i])) { 169 if (image_rep.pixel_width() != static_cast<int>(width * scale) ||
170 image_rep.pixel_height() != static_cast<int>(height * scale)) {
168 return false; 171 return false;
169 } 172 }
170 } 173 }
171 return true; 174 return true;
172 } 175 }
173 176
174 bool IsEmpty(const gfx::Image& image) { 177 bool IsEmpty(const gfx::Image& image) {
175 const SkBitmap& bmp = *image.ToSkBitmap(); 178 const SkBitmap& bmp = *image.ToSkBitmap();
176 return bmp.isNull() || 179 return bmp.isNull() ||
177 (bmp.width() == 0 && bmp.height() == 0); 180 (bmp.width() == 0 && bmp.height() == 0);
178 } 181 }
179 182
180 PlatformImage CreatePlatformImage() { 183 PlatformImage CreatePlatformImage() {
181 const SkBitmap bitmap(CreateBitmap(25, 25)); 184 const SkBitmap bitmap(CreateBitmap(25, 25));
182 #if defined(OS_IOS) 185 #if defined(OS_IOS)
183 float scale = ImageSkia::GetMaxSupportedScale(); 186 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
187 float scale = ui::GetScaleFactorScale(scale_factor);
184 188
185 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( 189 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
186 CGColorSpaceCreateDeviceRGB()); 190 CGColorSpaceCreateDeviceRGB());
187 UIImage* image = 191 UIImage* image =
188 gfx::SkBitmapToUIImageWithColorSpace(bitmap, scale, color_space); 192 gfx::SkBitmapToUIImageWithColorSpace(bitmap, scale, color_space);
189 base::mac::NSObjectRetain(image); 193 base::mac::NSObjectRetain(image);
190 return image; 194 return image;
191 #elif defined(OS_MACOSX) 195 #elif defined(OS_MACOSX)
192 NSImage* image = gfx::SkBitmapToNSImage(bitmap); 196 NSImage* image = gfx::SkBitmapToNSImage(bitmap);
193 base::mac::NSObjectRetain(image); 197 base::mac::NSObjectRetain(image);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { 278 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) {
275 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) 279 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
276 return image1 == image2; 280 return image1 == image2;
277 #else 281 #else
278 return image1.BackedBySameObjectAs(image2); 282 return image1.BackedBySameObjectAs(image2);
279 #endif 283 #endif
280 } 284 }
281 285
282 } // namespace test 286 } // namespace test
283 } // namespace gfx 287 } // namespace gfx
OLDNEW
« no previous file with comments | « trunk/src/ui/gfx/image/image_unittest_util.h ('k') | trunk/src/ui/gfx/image/image_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698