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/bitmap_platform_device_mac.h" | 5 #include "skia/ext/bitmap_platform_device_mac.h" |
6 | 6 |
7 #import <ApplicationServices/ApplicationServices.h> | 7 #import <ApplicationServices/ApplicationServices.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <time.h> | 9 #include <time.h> |
10 | 10 |
11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "skia/ext/bitmap_platform_device.h" | 13 #include "skia/ext/bitmap_platform_device.h" |
14 #include "skia/ext/platform_canvas.h" | 14 #include "skia/ext/platform_canvas.h" |
15 #include "skia/ext/skia_utils_mac.h" | 15 #include "skia/ext/skia_utils_mac.h" |
16 #include "third_party/skia/include/core/SkMatrix.h" | 16 #include "third_party/skia/include/core/SkMatrix.h" |
17 #include "third_party/skia/include/core/SkPath.h" | 17 #include "third_party/skia/include/core/SkPath.h" |
18 #include "third_party/skia/include/core/SkRegion.h" | 18 #include "third_party/skia/include/core/SkRegion.h" |
19 #include "third_party/skia/include/core/SkTypes.h" | 19 #include "third_party/skia/include/core/SkTypes.h" |
20 #include "third_party/skia/include/core/SkUtils.h" | 20 #include "third_party/skia/include/core/SkUtils.h" |
21 | 21 |
22 namespace skia { | 22 namespace skia { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
| 26 // Returns true if it is unsafe to attempt to allocate an offscreen buffer |
| 27 // given these dimensions. |
| 28 bool RasterDeviceTooBigToAllocate(int width, int height) { |
| 29 |
| 30 #ifndef SKIA_EXT_RASTER_DEVICE_ALLOCATION_MAX |
| 31 #define SKIA_EXT_RASTER_DEVICE_ALLOCATION_MAX (2 * 256 * 1024 * 1024) |
| 32 #endif |
| 33 |
| 34 int bytesPerPixel = 4; |
| 35 int64_t bytes = (int64_t)width * height * bytesPerPixel; |
| 36 return bytes > SKIA_EXT_RASTER_DEVICE_ALLOCATION_MAX; |
| 37 } |
| 38 |
26 static CGContextRef CGContextForData(void* data, int width, int height) { | 39 static CGContextRef CGContextForData(void* data, int width, int height) { |
27 #define HAS_ARGB_SHIFTS(a, r, g, b) \ | 40 #define HAS_ARGB_SHIFTS(a, r, g, b) \ |
28 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ | 41 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ |
29 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) | 42 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) |
30 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) | 43 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) |
31 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple | 44 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple |
32 // recommends these flags for improved CG performance. | 45 // recommends these flags for improved CG performance. |
33 | 46 |
34 // CGBitmapContextCreate returns NULL if width/height are 0. However, our | 47 // CGBitmapContextCreate returns NULL if width/height are 0. However, our |
35 // callers expect to get a canvas back (which they later resize/reallocate) | 48 // callers expect to get a canvas back (which they later resize/reallocate) |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 306 } |
294 | 307 |
295 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, | 308 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, |
296 uint8_t* data, OnFailureType failureType) { | 309 uint8_t* data, OnFailureType failureType) { |
297 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( | 310 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
298 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); | 311 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); |
299 return CreateCanvas(dev, failureType); | 312 return CreateCanvas(dev, failureType); |
300 } | 313 } |
301 | 314 |
302 } // namespace skia | 315 } // namespace skia |
OLD | NEW |