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