OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "ui/gfx/image/image_unittest_util.h" | 9 #include "ui/gfx/image/image_unittest_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 | 12 |
13 #if defined(TOOLKIT_GTK) | 13 #if defined(TOOLKIT_GTK) |
14 #include "ui/gfx/gtk_util.h" | 14 #include "ui/gfx/gtk_util.h" |
15 #elif defined(OS_MACOSX) | 15 #elif defined(OS_MACOSX) |
16 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
17 #include "skia/ext/skia_utils_mac.h" | 17 #include "skia/ext/skia_utils_mac.h" |
18 #endif | 18 #endif |
19 | 19 |
20 namespace gfx { | 20 namespace gfx { |
21 namespace test { | 21 namespace test { |
22 | 22 |
23 const SkBitmap CreateBitmap(int width, int height) { | 23 SkBitmap* CreateBitmap(int width, int height) { |
24 SkBitmap bitmap; | 24 SkBitmap* bitmap = new SkBitmap(); |
25 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 25 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
26 bitmap.allocPixels(); | 26 bitmap->allocPixels(); |
27 bitmap.eraseRGB(255, 0, 0); | 27 bitmap->eraseRGB(255, 0, 0); |
28 return bitmap; | 28 return bitmap; |
29 } | 29 } |
30 | 30 |
31 gfx::Image CreateImage() { | 31 gfx::Image CreateImage() { |
32 return gfx::Image(CreateBitmap(100, 50)); | 32 return gfx::Image(CreateBitmap(100, 50)); |
33 } | 33 } |
34 | 34 |
35 bool IsEqual(const gfx::Image& image1, const gfx::Image& image2) { | 35 bool IsEqual(const gfx::Image& image1, const gfx::Image& image2) { |
36 const SkBitmap& bmp1 = *image1.ToSkBitmap(); | 36 const SkBitmap& bmp1 = *image1.ToSkBitmap(); |
37 const SkBitmap& bmp2 = *image2.ToSkBitmap(); | 37 const SkBitmap& bmp2 = *image2.ToSkBitmap(); |
(...skipping 20 matching lines...) Expand all Loading... |
58 return true; | 58 return true; |
59 } | 59 } |
60 | 60 |
61 bool IsEmpty(const gfx::Image& image) { | 61 bool IsEmpty(const gfx::Image& image) { |
62 const SkBitmap& bmp = *image.ToSkBitmap(); | 62 const SkBitmap& bmp = *image.ToSkBitmap(); |
63 return bmp.isNull() || | 63 return bmp.isNull() || |
64 (bmp.width() == 0 && bmp.height() == 0); | 64 (bmp.width() == 0 && bmp.height() == 0); |
65 } | 65 } |
66 | 66 |
67 PlatformImage CreatePlatformImage() { | 67 PlatformImage CreatePlatformImage() { |
68 const SkBitmap bitmap(CreateBitmap(25, 25)); | 68 scoped_ptr<SkBitmap> bitmap(CreateBitmap(25, 25)); |
69 #if defined(OS_MACOSX) | 69 #if defined(OS_MACOSX) |
70 NSImage* image = gfx::SkBitmapToNSImage(bitmap); | 70 NSImage* image = gfx::SkBitmapToNSImage(*(bitmap.get())); |
71 base::mac::NSObjectRetain(image); | 71 base::mac::NSObjectRetain(image); |
72 return image; | 72 return image; |
73 #elif defined(TOOLKIT_GTK) | 73 #elif defined(TOOLKIT_GTK) |
74 return gfx::GdkPixbufFromSkBitmap(&bitmap); | 74 return gfx::GdkPixbufFromSkBitmap(bitmap.get()); |
75 #else | 75 #else |
76 return bitmap; | 76 return bitmap.release(); |
77 #endif | 77 #endif |
78 } | 78 } |
79 | 79 |
80 gfx::Image::RepresentationType GetPlatformRepresentationType() { | 80 gfx::Image::RepresentationType GetPlatformRepresentationType() { |
81 #if defined(OS_MACOSX) | 81 #if defined(OS_MACOSX) |
82 return gfx::Image::kImageRepCocoa; | 82 return gfx::Image::kImageRepCocoa; |
83 #elif defined(TOOLKIT_GTK) | 83 #elif defined(TOOLKIT_GTK) |
84 return gfx::Image::kImageRepGdk; | 84 return gfx::Image::kImageRepGdk; |
85 #else | 85 #else |
86 return gfx::Image::kImageRepSkia; | 86 return gfx::Image::kImageRepSkia; |
87 #endif | 87 #endif |
88 } | 88 } |
89 | 89 |
90 PlatformImage ToPlatformType(const gfx::Image& image) { | 90 PlatformImage ToPlatformType(const gfx::Image& image) { |
91 #if defined(OS_MACOSX) | 91 #if defined(OS_MACOSX) |
92 return image.ToNSImage(); | 92 return image.ToNSImage(); |
93 #elif defined(TOOLKIT_GTK) | 93 #elif defined(TOOLKIT_GTK) |
94 return image.ToGdkPixbuf(); | 94 return image.ToGdkPixbuf(); |
95 #else | 95 #else |
96 return *image.ToSkBitmap(); | 96 return image.ToSkBitmap(); |
97 #endif | |
98 } | |
99 | |
100 bool IsPlatformImageValid(PlatformImage image) { | |
101 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) | |
102 return image != NULL; | |
103 #else | |
104 return !image.isNull(); | |
105 #endif | |
106 } | |
107 | |
108 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { | |
109 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) | |
110 return image1 == image2; | |
111 #else | |
112 return image1.getPixels() == image2.getPixels(); | |
113 #endif | 97 #endif |
114 } | 98 } |
115 | 99 |
116 } // namespace test | 100 } // namespace test |
117 } // namespace gfx | 101 } // namespace gfx |
OLD | NEW |