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

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

Issue 231733005: Delete the GTK+ port of Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remerge to ToT Created 6 years, 8 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>
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/gfx/codec/png_codec.h" 15 #include "ui/gfx/codec/png_codec.h"
16 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
17 17
18 #if defined(TOOLKIT_GTK) 18 #if defined(OS_IOS)
19 #include <gtk/gtk.h>
20 #include "ui/gfx/gtk_util.h"
21 #elif defined(OS_IOS)
22 #include "base/mac/foundation_util.h" 19 #include "base/mac/foundation_util.h"
23 #include "base/mac/scoped_cftyperef.h" 20 #include "base/mac/scoped_cftyperef.h"
24 #include "skia/ext/skia_utils_ios.h" 21 #include "skia/ext/skia_utils_ios.h"
25 #elif defined(OS_MACOSX) 22 #elif defined(OS_MACOSX)
26 #include "base/mac/mac_util.h" 23 #include "base/mac/mac_util.h"
27 #include "skia/ext/skia_utils_mac.h" 24 #include "skia/ext/skia_utils_mac.h"
28 #endif 25 #endif
29 26
30 namespace gfx { 27 namespace gfx {
31 namespace test { 28 namespace test {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( 182 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
186 CGColorSpaceCreateDeviceRGB()); 183 CGColorSpaceCreateDeviceRGB());
187 UIImage* image = 184 UIImage* image =
188 gfx::SkBitmapToUIImageWithColorSpace(bitmap, scale, color_space); 185 gfx::SkBitmapToUIImageWithColorSpace(bitmap, scale, color_space);
189 base::mac::NSObjectRetain(image); 186 base::mac::NSObjectRetain(image);
190 return image; 187 return image;
191 #elif defined(OS_MACOSX) 188 #elif defined(OS_MACOSX)
192 NSImage* image = gfx::SkBitmapToNSImage(bitmap); 189 NSImage* image = gfx::SkBitmapToNSImage(bitmap);
193 base::mac::NSObjectRetain(image); 190 base::mac::NSObjectRetain(image);
194 return image; 191 return image;
195 #elif defined(TOOLKIT_GTK)
196 return gfx::GdkPixbufFromSkBitmap(bitmap);
197 #else 192 #else
198 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 193 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
199 #endif 194 #endif
200 } 195 }
201 196
202 gfx::Image::RepresentationType GetPlatformRepresentationType() { 197 gfx::Image::RepresentationType GetPlatformRepresentationType() {
203 #if defined(OS_IOS) 198 #if defined(OS_IOS)
204 return gfx::Image::kImageRepCocoaTouch; 199 return gfx::Image::kImageRepCocoaTouch;
205 #elif defined(OS_MACOSX) 200 #elif defined(OS_MACOSX)
206 return gfx::Image::kImageRepCocoa; 201 return gfx::Image::kImageRepCocoa;
207 #elif defined(TOOLKIT_GTK)
208 return gfx::Image::kImageRepGdk;
209 #else 202 #else
210 return gfx::Image::kImageRepSkia; 203 return gfx::Image::kImageRepSkia;
211 #endif 204 #endif
212 } 205 }
213 206
214 PlatformImage ToPlatformType(const gfx::Image& image) { 207 PlatformImage ToPlatformType(const gfx::Image& image) {
215 #if defined(OS_IOS) 208 #if defined(OS_IOS)
216 return image.ToUIImage(); 209 return image.ToUIImage();
217 #elif defined(OS_MACOSX) 210 #elif defined(OS_MACOSX)
218 return image.ToNSImage(); 211 return image.ToNSImage();
219 #elif defined(TOOLKIT_GTK)
220 return image.ToGdkPixbuf();
221 #else 212 #else
222 return image.AsImageSkia(); 213 return image.AsImageSkia();
223 #endif 214 #endif
224 } 215 }
225 216
226 PlatformImage CopyPlatformType(const gfx::Image& image) { 217 PlatformImage CopyPlatformType(const gfx::Image& image) {
227 #if defined(OS_IOS) 218 #if defined(OS_IOS)
228 return image.CopyUIImage(); 219 return image.CopyUIImage();
229 #elif defined(OS_MACOSX) 220 #elif defined(OS_MACOSX)
230 return image.CopyNSImage(); 221 return image.CopyNSImage();
231 #elif defined(TOOLKIT_GTK)
232 return image.CopyGdkPixbuf();
233 #else 222 #else
234 return image.AsImageSkia(); 223 return image.AsImageSkia();
235 #endif 224 #endif
236 } 225 }
237 226
238 #if defined(OS_MACOSX) 227 #if defined(OS_MACOSX)
239 // Defined in image_unittest_util_mac.mm. 228 // Defined in image_unittest_util_mac.mm.
240 #elif defined(TOOLKIT_GTK)
241 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) {
242 int n_channels = gdk_pixbuf_get_n_channels(image);
243 int rowstride = gdk_pixbuf_get_rowstride(image);
244 guchar* gdk_pixels = gdk_pixbuf_get_pixels(image);
245
246 guchar* pixel = gdk_pixels + (y * rowstride) + (x * n_channels);
247 guchar alpha = gdk_pixbuf_get_has_alpha(image) ? pixel[3] : 255;
248 return SkColorSetARGB(alpha, pixel[0], pixel[1], pixel[2]);
249 }
250 #else 229 #else
251 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) { 230 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) {
252 SkBitmap bitmap = *image.bitmap(); 231 SkBitmap bitmap = *image.bitmap();
253 SkAutoLockPixels auto_lock(bitmap); 232 SkAutoLockPixels auto_lock(bitmap);
254 return bitmap.getColor(x, y); 233 return bitmap.getColor(x, y);
255 } 234 }
256 #endif 235 #endif
257 236
258 void CheckColors(SkColor color1, SkColor color2) { 237 void CheckColors(SkColor color1, SkColor color2) {
259 EXPECT_TRUE(ColorsClose(color1, color2)); 238 EXPECT_TRUE(ColorsClose(color1, color2));
260 } 239 }
261 240
262 void CheckIsTransparent(SkColor color) { 241 void CheckIsTransparent(SkColor color) {
263 EXPECT_LT(SkColorGetA(color) / 255.0, 0.05); 242 EXPECT_LT(SkColorGetA(color) / 255.0, 0.05);
264 } 243 }
265 244
266 bool IsPlatformImageValid(PlatformImage image) { 245 bool IsPlatformImageValid(PlatformImage image) {
267 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) 246 #if defined(OS_MACOSX)
268 return image != NULL; 247 return image != NULL;
269 #else 248 #else
270 return !image.isNull(); 249 return !image.isNull();
271 #endif 250 #endif
272 } 251 }
273 252
274 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { 253 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) {
275 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) 254 #if defined(OS_MACOSX)
276 return image1 == image2; 255 return image1 == image2;
277 #else 256 #else
278 return image1.BackedBySameObjectAs(image2); 257 return image1.BackedBySameObjectAs(image2);
279 #endif 258 #endif
280 } 259 }
281 260
282 } // namespace test 261 } // namespace test
283 } // namespace gfx 262 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698