| 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/bitmap_platform_device_mac.h" | 5 #include "skia/ext/bitmap_platform_device_mac.h" |
| 6 | 6 |
| 7 #include <time.h> | 7 #include <time.h> |
| 8 | 8 |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } else { | 40 } else { |
| 41 // Fill up available size. | 41 // Fill up available size. |
| 42 *size = available_size - *position; | 42 *size = available_size - *position; |
| 43 } | 43 } |
| 44 return true; | 44 return true; |
| 45 } | 45 } |
| 46 | 46 |
| 47 static CGContextRef CGContextForData(void* data, int width, int height) { | 47 static CGContextRef CGContextForData(void* data, int width, int height) { |
| 48 CGColorSpaceRef color_space = | 48 CGColorSpaceRef color_space = |
| 49 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); | 49 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); |
| 50 #define HAS_ARGB_SHIFTS(a, r, g, b) \ |
| 51 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ |
| 52 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) |
| 53 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) |
| 50 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple | 54 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple |
| 51 // recommends these flags for improved CG performance. | 55 // recommends these flags for improved CG performance. |
| 52 CGContextRef context = | 56 CGContextRef context = |
| 53 CGBitmapContextCreate(data, width, height, 8, width * 4, | 57 CGBitmapContextCreate(data, width, height, 8, width * 4, |
| 54 color_space, | 58 color_space, |
| 55 kCGImageAlphaPremultipliedFirst | | 59 kCGImageAlphaPremultipliedFirst | |
| 56 kCGBitmapByteOrder32Host); | 60 kCGBitmapByteOrder32Host); |
| 61 #else |
| 62 #error We require that Skia's and CoreGraphics's recommended \ |
| 63 image memory layout match. |
| 64 #endif |
| 65 #undef HAS_ARGB_SHIFTS |
| 57 CGColorSpaceRelease(color_space); | 66 CGColorSpaceRelease(color_space); |
| 58 | 67 |
| 59 if (!context) | 68 if (!context) |
| 60 return NULL; | 69 return NULL; |
| 61 | 70 |
| 62 // Change the coordinate system to match WebCore's | 71 // Change the coordinate system to match WebCore's |
| 63 CGContextTranslateCTM(context, 0, height); | 72 CGContextTranslateCTM(context, 0, height); |
| 64 CGContextScaleCTM(context, 1.0, -1.0); | 73 CGContextScaleCTM(context, 1.0, -1.0); |
| 65 | 74 |
| 66 return context; | 75 return context; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 for (int i = 0; i < height; i++) { | 348 for (int i = 0; i < height; i++) { |
| 340 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; | 349 size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x; |
| 341 for (int j = 0; j < width; j++) { | 350 for (int j = 0; j < width; j++) { |
| 342 adjustor(data + offset + j); | 351 adjustor(data + offset + j); |
| 343 } | 352 } |
| 344 } | 353 } |
| 345 } | 354 } |
| 346 } | 355 } |
| 347 | 356 |
| 348 } // namespace skia | 357 } // namespace skia |
| OLD | NEW |