| 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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "ui/base/layout.h" | 9 #include "ui/base/layout.h" |
| 10 #include "ui/gfx/image/image_unittest_util.h" | 10 #include "ui/gfx/image/image_unittest_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 | 13 |
| 14 #if defined(TOOLKIT_GTK) | 14 #if defined(TOOLKIT_GTK) |
| 15 #include <gtk/gtk.h> | 15 #include <gtk/gtk.h> |
| 16 #include "ui/gfx/gtk_util.h" | 16 #include "ui/gfx/gtk_util.h" |
| 17 #elif defined(OS_IOS) |
| 18 #include "base/mac/foundation_util.h" |
| 19 #include "base/mac/scoped_cftyperef.h" |
| 20 #include "skia/ext/skia_utils_ios.h" |
| 17 #elif defined(OS_MACOSX) | 21 #elif defined(OS_MACOSX) |
| 18 #include "base/mac/mac_util.h" | 22 #include "base/mac/mac_util.h" |
| 19 #include "skia/ext/skia_utils_mac.h" | 23 #include "skia/ext/skia_utils_mac.h" |
| 20 #endif | 24 #endif |
| 21 | 25 |
| 22 namespace gfx { | 26 namespace gfx { |
| 23 namespace test { | 27 namespace test { |
| 24 | 28 |
| 25 void SetSupportedScaleFactorsTo1xAnd2x() { | 29 void SetSupportedScaleFactorsTo1xAnd2x() { |
| 26 std::vector<ui::ScaleFactor> supported_scale_factors; | 30 std::vector<ui::ScaleFactor> supported_scale_factors; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 76 } |
| 73 | 77 |
| 74 bool IsEmpty(const gfx::Image& image) { | 78 bool IsEmpty(const gfx::Image& image) { |
| 75 const SkBitmap& bmp = *image.ToSkBitmap(); | 79 const SkBitmap& bmp = *image.ToSkBitmap(); |
| 76 return bmp.isNull() || | 80 return bmp.isNull() || |
| 77 (bmp.width() == 0 && bmp.height() == 0); | 81 (bmp.width() == 0 && bmp.height() == 0); |
| 78 } | 82 } |
| 79 | 83 |
| 80 PlatformImage CreatePlatformImage() { | 84 PlatformImage CreatePlatformImage() { |
| 81 const SkBitmap bitmap(CreateBitmap(25, 25)); | 85 const SkBitmap bitmap(CreateBitmap(25, 25)); |
| 82 #if defined(OS_MACOSX) | 86 #if defined(OS_IOS) |
| 87 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
| 88 CGColorSpaceCreateDeviceRGB()); |
| 89 UIImage* image = gfx::SkBitmapToUIImageWithColorSpace(bitmap, color_space); |
| 90 base::mac::NSObjectRetain(image); |
| 91 return image; |
| 92 #elif defined(OS_MACOSX) |
| 83 NSImage* image = gfx::SkBitmapToNSImage(bitmap); | 93 NSImage* image = gfx::SkBitmapToNSImage(bitmap); |
| 84 base::mac::NSObjectRetain(image); | 94 base::mac::NSObjectRetain(image); |
| 85 return image; | 95 return image; |
| 86 #elif defined(TOOLKIT_GTK) | 96 #elif defined(TOOLKIT_GTK) |
| 87 return gfx::GdkPixbufFromSkBitmap(bitmap); | 97 return gfx::GdkPixbufFromSkBitmap(bitmap); |
| 88 #else | 98 #else |
| 89 return bitmap; | 99 return bitmap; |
| 90 #endif | 100 #endif |
| 91 } | 101 } |
| 92 | 102 |
| 93 gfx::Image::RepresentationType GetPlatformRepresentationType() { | 103 gfx::Image::RepresentationType GetPlatformRepresentationType() { |
| 94 #if defined(OS_MACOSX) | 104 #if defined(OS_IOS) |
| 105 return gfx::Image::kImageRepCocoaTouch; |
| 106 #elif defined(OS_MACOSX) |
| 95 return gfx::Image::kImageRepCocoa; | 107 return gfx::Image::kImageRepCocoa; |
| 96 #elif defined(TOOLKIT_GTK) | 108 #elif defined(TOOLKIT_GTK) |
| 97 return gfx::Image::kImageRepGdk; | 109 return gfx::Image::kImageRepGdk; |
| 98 #else | 110 #else |
| 99 return gfx::Image::kImageRepSkia; | 111 return gfx::Image::kImageRepSkia; |
| 100 #endif | 112 #endif |
| 101 } | 113 } |
| 102 | 114 |
| 103 PlatformImage ToPlatformType(const gfx::Image& image) { | 115 PlatformImage ToPlatformType(const gfx::Image& image) { |
| 104 #if defined(OS_MACOSX) | 116 #if defined(OS_IOS) |
| 117 return image.ToUIImage(); |
| 118 #elif defined(OS_MACOSX) |
| 105 return image.ToNSImage(); | 119 return image.ToNSImage(); |
| 106 #elif defined(TOOLKIT_GTK) | 120 #elif defined(TOOLKIT_GTK) |
| 107 return image.ToGdkPixbuf(); | 121 return image.ToGdkPixbuf(); |
| 108 #else | 122 #else |
| 109 return *image.ToSkBitmap(); | 123 return *image.ToSkBitmap(); |
| 110 #endif | 124 #endif |
| 111 } | 125 } |
| 112 | 126 |
| 113 PlatformImage CopyPlatformType(const gfx::Image& image) { | 127 PlatformImage CopyPlatformType(const gfx::Image& image) { |
| 114 #if defined(OS_MACOSX) | 128 #if defined(OS_IOS) |
| 129 return image.CopyUIImage(); |
| 130 #elif defined(OS_MACOSX) |
| 115 return image.CopyNSImage(); | 131 return image.CopyNSImage(); |
| 116 #elif defined(TOOLKIT_GTK) | 132 #elif defined(TOOLKIT_GTK) |
| 117 return image.CopyGdkPixbuf(); | 133 return image.CopyGdkPixbuf(); |
| 118 #else | 134 #else |
| 119 return *image.ToSkBitmap(); | 135 return *image.ToSkBitmap(); |
| 120 #endif | 136 #endif |
| 121 } | 137 } |
| 122 | 138 |
| 123 #if defined(OS_MACOSX) | 139 #if defined(OS_MACOSX) |
| 124 // Defined in image_unittest_util_mac.mm. | 140 // Defined in image_unittest_util_mac.mm. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { | 175 bool PlatformImagesEqual(PlatformImage image1, PlatformImage image2) { |
| 160 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) | 176 #if defined(OS_MACOSX) || defined(TOOLKIT_GTK) |
| 161 return image1 == image2; | 177 return image1 == image2; |
| 162 #else | 178 #else |
| 163 return image1.getPixels() == image2.getPixels(); | 179 return image1.getPixels() == image2.getPixels(); |
| 164 #endif | 180 #endif |
| 165 } | 181 } |
| 166 | 182 |
| 167 } // namespace test | 183 } // namespace test |
| 168 } // namespace gfx | 184 } // namespace gfx |
| OLD | NEW |