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 "skia/ext/skia_utils_mac.h" | 5 #include "skia/ext/skia_utils_mac.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 bitmap.installPixels(info, bits, info.minRowBytes()); | 148 bitmap.installPixels(info, bits, info.minRowBytes()); |
149 | 149 |
150 SkCanvas canvas(bitmap); | 150 SkCanvas canvas(bitmap); |
151 if (test & TestTranslate) | 151 if (test & TestTranslate) |
152 canvas.translate(width / 2, 0); | 152 canvas.translate(width / 2, 0); |
153 if (test & TestClip) { | 153 if (test & TestClip) { |
154 SkRect clipRect = {0, height / 2, width, height}; | 154 SkRect clipRect = {0, height / 2, width, height}; |
155 canvas.clipRect(clipRect); | 155 canvas.clipRect(clipRect); |
156 } | 156 } |
157 { | 157 { |
158 gfx::SkiaBitLocker bitLocker(&canvas); | 158 skia::SkiaBitLocker bitLocker(&canvas); |
159 CGContextRef cgContext = bitLocker.cgContext(); | 159 CGContextRef cgContext = bitLocker.cgContext(); |
160 CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); | 160 CGColorRef testColor = CGColorGetConstantColor(kCGColorWhite); |
161 CGContextSetFillColorWithColor(cgContext, testColor); | 161 CGContextSetFillColorWithColor(cgContext, testColor); |
162 CGRect cgRect = {{0, 0}, {width, height}}; | 162 CGRect cgRect = {{0, 0}, {width, height}}; |
163 CGContextFillRect(cgContext, cgRect); | 163 CGContextFillRect(cgContext, cgRect); |
164 if (test & TestNoBits) { | 164 if (test & TestNoBits) { |
165 if (test & TestClip) { | 165 if (test & TestClip) { |
166 SkRect clipRect = {0, height / 2, width, height}; | 166 SkRect clipRect = {0, height / 2, width, height}; |
167 canvas.clipRect(clipRect); | 167 canvas.clipRect(clipRect); |
168 } | 168 } |
169 } | 169 } |
170 } | 170 } |
171 const unsigned results[][storageSize] = { | 171 const unsigned results[][storageSize] = { |
172 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}, // identity | 172 {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}, // identity |
173 {0xFF333333, 0xFFFFFFFF, 0xFF999999, 0xFFFFFFFF}, // translate | 173 {0xFF333333, 0xFFFFFFFF, 0xFF999999, 0xFFFFFFFF}, // translate |
174 {0xFF333333, 0xFF666666, 0xFFFFFFFF, 0xFFFFFFFF}, // clip | 174 {0xFF333333, 0xFF666666, 0xFFFFFFFF, 0xFFFFFFFF}, // clip |
175 {0xFF333333, 0xFF666666, 0xFF999999, 0xFFFFFFFF} // translate | clip | 175 {0xFF333333, 0xFF666666, 0xFF999999, 0xFFFFFFFF} // translate | clip |
176 }; | 176 }; |
177 for (unsigned index = 0; index < storageSize; index++) | 177 for (unsigned index = 0; index < storageSize; index++) |
178 EXPECT_EQ(results[test & ~TestNoBits][index], bits[index]); | 178 EXPECT_EQ(results[test & ~TestNoBits][index], bits[index]); |
179 } | 179 } |
180 | 180 |
181 void SkiaUtilsMacTest::ShapeHelper(int width, int height, | 181 void SkiaUtilsMacTest::ShapeHelper(int width, int height, |
182 bool isred, bool tfbit) { | 182 bool isred, bool tfbit) { |
183 SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit)); | 183 SkBitmap thing(CreateSkBitmap(width, height, isred, tfbit)); |
184 | 184 |
185 // Confirm size | 185 // Confirm size |
186 NSImage* image = gfx::SkBitmapToNSImage(thing); | 186 NSImage* image = skia::SkBitmapToNSImage(thing); |
187 EXPECT_DOUBLE_EQ([image size].width, (double)width); | 187 EXPECT_DOUBLE_EQ([image size].width, (double)width); |
188 EXPECT_DOUBLE_EQ([image size].height, (double)height); | 188 EXPECT_DOUBLE_EQ([image size].height, (double)height); |
189 | 189 |
190 EXPECT_TRUE([[image representations] count] == 1); | 190 EXPECT_TRUE([[image representations] count] == 1); |
191 EXPECT_TRUE([[[image representations] lastObject] | 191 EXPECT_TRUE([[[image representations] lastObject] |
192 isKindOfClass:[NSBitmapImageRep class]]); | 192 isKindOfClass:[NSBitmapImageRep class]]); |
193 TestImageRep(base::mac::ObjCCastStrict<NSBitmapImageRep>( | 193 TestImageRep(base::mac::ObjCCastStrict<NSBitmapImageRep>( |
194 [[image representations] lastObject]), | 194 [[image representations] lastObject]), |
195 isred); | 195 isred); |
196 } | 196 } |
197 | 197 |
198 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) { | 198 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_RedSquare64x64) { |
199 ShapeHelper(64, 64, true, true); | 199 ShapeHelper(64, 64, true, true); |
200 } | 200 } |
201 | 201 |
202 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle199x19) { | 202 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle199x19) { |
203 ShapeHelper(199, 19, false, true); | 203 ShapeHelper(199, 19, false, true); |
204 } | 204 } |
205 | 205 |
206 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle444) { | 206 TEST_F(SkiaUtilsMacTest, BitmapToNSImage_BlueRectangle444) { |
207 ShapeHelper(200, 200, false, false); | 207 ShapeHelper(200, 200, false, false); |
208 } | 208 } |
209 | 209 |
210 TEST_F(SkiaUtilsMacTest, BitmapToNSBitmapImageRep_BlueRectangle20x30) { | 210 TEST_F(SkiaUtilsMacTest, BitmapToNSBitmapImageRep_BlueRectangle20x30) { |
211 int width = 20; | 211 int width = 20; |
212 int height = 30; | 212 int height = 30; |
213 | 213 |
214 SkBitmap bitmap(CreateSkBitmap(width, height, false, true)); | 214 SkBitmap bitmap(CreateSkBitmap(width, height, false, true)); |
215 NSBitmapImageRep* imageRep = gfx::SkBitmapToNSBitmapImageRep(bitmap); | 215 NSBitmapImageRep* imageRep = skia::SkBitmapToNSBitmapImageRep(bitmap); |
216 | 216 |
217 EXPECT_DOUBLE_EQ(width, [imageRep size].width); | 217 EXPECT_DOUBLE_EQ(width, [imageRep size].width); |
218 EXPECT_DOUBLE_EQ(height, [imageRep size].height); | 218 EXPECT_DOUBLE_EQ(height, [imageRep size].height); |
219 TestImageRep(imageRep, false); | 219 TestImageRep(imageRep, false); |
220 } | 220 } |
221 | 221 |
222 TEST_F(SkiaUtilsMacTest, NSImageRepToSkBitmap) { | 222 TEST_F(SkiaUtilsMacTest, NSImageRepToSkBitmap) { |
223 int width = 10; | 223 int width = 10; |
224 int height = 15; | 224 int height = 15; |
225 | 225 |
226 NSImage* image = CreateNSImage(width, height); | 226 NSImage* image = CreateNSImage(width, height); |
227 EXPECT_EQ(1u, [[image representations] count]); | 227 EXPECT_EQ(1u, [[image representations] count]); |
228 NSBitmapImageRep* imageRep = base::mac::ObjCCastStrict<NSBitmapImageRep>( | 228 NSBitmapImageRep* imageRep = base::mac::ObjCCastStrict<NSBitmapImageRep>( |
229 [[image representations] lastObject]); | 229 [[image representations] lastObject]); |
230 NSColorSpace* colorSpace = [NSColorSpace genericRGBColorSpace]; | 230 NSColorSpace* colorSpace = [NSColorSpace genericRGBColorSpace]; |
231 SkBitmap bitmap(gfx::NSImageRepToSkBitmapWithColorSpace( | 231 SkBitmap bitmap(skia::NSImageRepToSkBitmapWithColorSpace( |
232 imageRep, [image size], false, [colorSpace CGColorSpace])); | 232 imageRep, [image size], false, [colorSpace CGColorSpace])); |
233 TestSkBitmap(bitmap); | 233 TestSkBitmap(bitmap); |
234 } | 234 } |
235 | 235 |
236 TEST_F(SkiaUtilsMacTest, BitLocker_Identity) { | 236 TEST_F(SkiaUtilsMacTest, BitLocker_Identity) { |
237 RunBitLockerTest(SkiaUtilsMacTest::TestIdentity); | 237 RunBitLockerTest(SkiaUtilsMacTest::TestIdentity); |
238 } | 238 } |
239 | 239 |
240 TEST_F(SkiaUtilsMacTest, BitLocker_Translate) { | 240 TEST_F(SkiaUtilsMacTest, BitLocker_Translate) { |
241 RunBitLockerTest(SkiaUtilsMacTest::TestTranslate); | 241 RunBitLockerTest(SkiaUtilsMacTest::TestTranslate); |
(...skipping 18 matching lines...) Expand all Loading... |
260 TEST_F(SkiaUtilsMacTest, BitLocker_ClipNoBits) { | 260 TEST_F(SkiaUtilsMacTest, BitLocker_ClipNoBits) { |
261 RunBitLockerTest(SkiaUtilsMacTest::TestClipNoBits); | 261 RunBitLockerTest(SkiaUtilsMacTest::TestClipNoBits); |
262 } | 262 } |
263 | 263 |
264 TEST_F(SkiaUtilsMacTest, BitLocker_XClipNoBits) { | 264 TEST_F(SkiaUtilsMacTest, BitLocker_XClipNoBits) { |
265 RunBitLockerTest(SkiaUtilsMacTest::TestXClipNoBits); | 265 RunBitLockerTest(SkiaUtilsMacTest::TestXClipNoBits); |
266 } | 266 } |
267 | 267 |
268 } // namespace | 268 } // namespace |
269 | 269 |
OLD | NEW |