| 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 #include <Cocoa/Cocoa.h> | 5 #include <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
| 11 #include "ui/gfx/image/image_png_rep.h" | 11 #include "ui/gfx/image/image_png_rep.h" |
| 12 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
| 13 #include "ui/gfx/image/image_skia_util_mac.h" | 13 #include "ui/gfx/image/image_skia_util_mac.h" |
| 14 #include "ui/gfx/image/image_unittest_util.h" | 14 #include "ui/gfx/image/image_unittest_util.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Returns true if the structure of |ns_image| matches the structure | 18 // Returns true if the structure of |ns_image| matches the structure |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 TEST_F(ImageMacTest, MultiResolutionNSImageToImageSkia) { | 92 TEST_F(ImageMacTest, MultiResolutionNSImageToImageSkia) { |
| 93 const int kWidth1x = 10; | 93 const int kWidth1x = 10; |
| 94 const int kHeight1x = 12; | 94 const int kHeight1x = 12; |
| 95 const int kWidth2x = 20; | 95 const int kWidth2x = 20; |
| 96 const int kHeight2x = 24; | 96 const int kHeight2x = 24; |
| 97 | 97 |
| 98 NSBitmapImageRep* ns_image_rep1; | 98 NSBitmapImageRep* ns_image_rep1; |
| 99 BitmapImageRep(kWidth1x, kHeight1x, &ns_image_rep1); | 99 BitmapImageRep(kWidth1x, kHeight1x, &ns_image_rep1); |
| 100 NSBitmapImageRep* ns_image_rep2; | 100 NSBitmapImageRep* ns_image_rep2; |
| 101 BitmapImageRep(kWidth2x, kHeight2x, &ns_image_rep2); | 101 BitmapImageRep(kWidth2x, kHeight2x, &ns_image_rep2); |
| 102 scoped_nsobject<NSImage> ns_image( | 102 base::scoped_nsobject<NSImage> ns_image( |
| 103 [[NSImage alloc] initWithSize:NSMakeSize(kWidth1x, kHeight1x)]); | 103 [[NSImage alloc] initWithSize:NSMakeSize(kWidth1x, kHeight1x)]); |
| 104 [ns_image addRepresentation:ns_image_rep1]; | 104 [ns_image addRepresentation:ns_image_rep1]; |
| 105 [ns_image addRepresentation:ns_image_rep2]; | 105 [ns_image addRepresentation:ns_image_rep2]; |
| 106 | 106 |
| 107 gfx::Image image(ns_image.release()); | 107 gfx::Image image(ns_image.release()); |
| 108 | 108 |
| 109 EXPECT_EQ(1u, image.RepresentationCount()); | 109 EXPECT_EQ(1u, image.RepresentationCount()); |
| 110 | 110 |
| 111 const gfx::ImageSkia* image_skia = image.ToImageSkia(); | 111 const gfx::ImageSkia* image_skia = image.ToImageSkia(); |
| 112 | 112 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 124 // other than 1x and 2x results in an ImageSkia with scale factors 1x and | 124 // other than 1x and 2x results in an ImageSkia with scale factors 1x and |
| 125 // 2x; | 125 // 2x; |
| 126 TEST_F(ImageMacTest, UnalignedMultiResolutionNSImageToImageSkia) { | 126 TEST_F(ImageMacTest, UnalignedMultiResolutionNSImageToImageSkia) { |
| 127 const int kWidth1x = 10; | 127 const int kWidth1x = 10; |
| 128 const int kHeight1x= 12; | 128 const int kHeight1x= 12; |
| 129 const int kWidth4x = 40; | 129 const int kWidth4x = 40; |
| 130 const int kHeight4x = 48; | 130 const int kHeight4x = 48; |
| 131 | 131 |
| 132 NSBitmapImageRep* ns_image_rep4; | 132 NSBitmapImageRep* ns_image_rep4; |
| 133 BitmapImageRep(kWidth4x, kHeight4x, &ns_image_rep4); | 133 BitmapImageRep(kWidth4x, kHeight4x, &ns_image_rep4); |
| 134 scoped_nsobject<NSImage> ns_image( | 134 base::scoped_nsobject<NSImage> ns_image( |
| 135 [[NSImage alloc] initWithSize:NSMakeSize(kWidth1x, kHeight1x)]); | 135 [[NSImage alloc] initWithSize:NSMakeSize(kWidth1x, kHeight1x)]); |
| 136 [ns_image addRepresentation:ns_image_rep4]; | 136 [ns_image addRepresentation:ns_image_rep4]; |
| 137 | 137 |
| 138 gfx::Image image(ns_image.release()); | 138 gfx::Image image(ns_image.release()); |
| 139 | 139 |
| 140 EXPECT_EQ(1u, image.RepresentationCount()); | 140 EXPECT_EQ(1u, image.RepresentationCount()); |
| 141 | 141 |
| 142 const gfx::ImageSkia* image_skia = image.ToImageSkia(); | 142 const gfx::ImageSkia* image_skia = image.ToImageSkia(); |
| 143 | 143 |
| 144 std::vector<ui::ScaleFactor> scale_factors; | 144 std::vector<ui::ScaleFactor> scale_factors; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 // Convert to ImageSkia to check pixel contents of NSImageReps. | 205 // Convert to ImageSkia to check pixel contents of NSImageReps. |
| 206 gfx::ImageSkia image_skia = gfx::ImageSkiaFromNSImage(ns_image); | 206 gfx::ImageSkia image_skia = gfx::ImageSkiaFromNSImage(ns_image); |
| 207 EXPECT_TRUE(gt::IsEqual(bytes1x, | 207 EXPECT_TRUE(gt::IsEqual(bytes1x, |
| 208 image_skia.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap())); | 208 image_skia.GetRepresentation(ui::SCALE_FACTOR_100P).sk_bitmap())); |
| 209 EXPECT_TRUE(gt::IsEqual(bytes2x, | 209 EXPECT_TRUE(gt::IsEqual(bytes2x, |
| 210 image_skia.GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap())); | 210 image_skia.GetRepresentation(ui::SCALE_FACTOR_200P).sk_bitmap())); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace | 213 } // namespace |
| OLD | NEW |