OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "skia/ext/bitmap_platform_device_mac.h" | 12 #include "skia/ext/bitmap_platform_device_mac.h" |
13 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 13 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
14 | 14 |
15 namespace gfx { | 15 namespace gfx { |
16 | 16 |
17 CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix) { | 17 CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix) { |
18 // CGAffineTransforms don't support perspective transforms, so make sure | 18 // CGAffineTransforms don't support perspective transforms, so make sure |
19 // we don't get those. | 19 // we don't get those. |
20 DCHECK(matrix[SkMatrix::kMPersp0] == 0.0f); | 20 DCHECK(matrix[SkMatrix::kMPersp0] == 0.0f); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 116 } |
117 | 117 |
118 SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque) { | 118 SkBitmap NSImageToSkBitmap(NSImage* image, NSSize size, bool is_opaque) { |
119 SkBitmap bitmap; | 119 SkBitmap bitmap; |
120 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width, size.height); | 120 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width, size.height); |
121 if (bitmap.allocPixels() != true) | 121 if (bitmap.allocPixels() != true) |
122 return bitmap; // Return |bitmap| which should respond true to isNull(). | 122 return bitmap; // Return |bitmap| which should respond true to isNull(). |
123 | 123 |
124 bitmap.setIsOpaque(is_opaque); | 124 bitmap.setIsOpaque(is_opaque); |
125 | 125 |
126 scoped_cftyperef<CGColorSpaceRef> color_space( | 126 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
127 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 127 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
128 void* data = bitmap.getPixels(); | 128 void* data = bitmap.getPixels(); |
129 | 129 |
130 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple | 130 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple |
131 // recommends these flags for improved CG performance. | 131 // recommends these flags for improved CG performance. |
132 #define HAS_ARGB_SHIFTS(a, r, g, b) \ | 132 #define HAS_ARGB_SHIFTS(a, r, g, b) \ |
133 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ | 133 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ |
134 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) | 134 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) |
135 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) | 135 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) |
136 scoped_cftyperef<CGContextRef> context( | 136 base::mac::ScopedCFTypeRef<CGContextRef> context( |
137 CGBitmapContextCreate(data, size.width, size.height, 8, size.width*4, | 137 CGBitmapContextCreate(data, size.width, size.height, 8, size.width*4, |
138 color_space, | 138 color_space, |
139 kCGImageAlphaPremultipliedFirst | | 139 kCGImageAlphaPremultipliedFirst | |
140 kCGBitmapByteOrder32Host)); | 140 kCGBitmapByteOrder32Host)); |
141 #else | 141 #else |
142 #error We require that Skia's and CoreGraphics's recommended \ | 142 #error We require that Skia's and CoreGraphics's recommended \ |
143 image memory layout match. | 143 image memory layout match. |
144 #endif | 144 #endif |
145 #undef HAS_ARGB_SHIFTS | 145 #undef HAS_ARGB_SHIFTS |
146 | 146 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; | 183 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; |
184 return image; | 184 return image; |
185 } | 185 } |
186 | 186 |
187 SkBitmap AppplicationIconAtSize(int size) { | 187 SkBitmap AppplicationIconAtSize(int size) { |
188 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 188 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
189 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true); | 189 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true); |
190 } | 190 } |
191 | 191 |
192 } // namespace gfx | 192 } // namespace gfx |
OLD | NEW |