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 <time.h> | 8 #include <time.h> |
9 | 9 |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 SkBitmap bitmap; | 103 SkBitmap bitmap; |
104 // TODO: verify that the CG Context's pixels will have tight rowbytes or pass
in the correct | 104 // TODO: verify that the CG Context's pixels will have tight rowbytes or pass
in the correct |
105 // rowbytes for the case when context != NULL. | 105 // rowbytes for the case when context != NULL. |
106 bitmap.setInfo(SkImageInfo::MakeN32(width, height, is_opaque ? kOpaque_SkAlpha
Type : kPremul_SkAlphaType)); | 106 bitmap.setInfo(SkImageInfo::MakeN32(width, height, is_opaque ? kOpaque_SkAlpha
Type : kPremul_SkAlphaType)); |
107 | 107 |
108 void* data; | 108 void* data; |
109 if (context) { | 109 if (context) { |
110 data = CGBitmapContextGetData(context); | 110 data = CGBitmapContextGetData(context); |
111 bitmap.setPixels(data); | 111 bitmap.setPixels(data); |
112 } else { | 112 } else { |
113 if (!bitmap.tryAllocPixels()) | 113 if (!bitmap.allocPixels()) |
114 return NULL; | 114 return NULL; |
115 data = bitmap.getPixels(); | 115 data = bitmap.getPixels(); |
116 } | 116 } |
117 | 117 |
118 // If we were given data, then don't clobber it! | 118 // If we were given data, then don't clobber it! |
119 #ifndef NDEBUG | 119 #ifndef NDEBUG |
120 if (!context && is_opaque) { | 120 if (!context && is_opaque) { |
121 // To aid in finding bugs, we set the background color to something | 121 // To aid in finding bugs, we set the background color to something |
122 // obviously wrong so it will be noticable when it is not cleared | 122 // obviously wrong so it will be noticable when it is not cleared |
123 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 123 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 264 |
265 PlatformBitmap::~PlatformBitmap() { | 265 PlatformBitmap::~PlatformBitmap() { |
266 if (surface_) | 266 if (surface_) |
267 CGContextRelease(surface_); | 267 CGContextRelease(surface_); |
268 } | 268 } |
269 | 269 |
270 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | 270 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { |
271 if (RasterDeviceTooBigToAllocate(width, height)) | 271 if (RasterDeviceTooBigToAllocate(width, height)) |
272 return false; | 272 return false; |
273 | 273 |
274 if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque)) | 274 if (!bitmap_.allocN32Pixels(width, height, is_opaque)) |
275 return false; | 275 return false; |
276 | 276 |
277 if (!is_opaque) | 277 if (!is_opaque) |
278 bitmap_.eraseColor(0); | 278 bitmap_.eraseColor(0); |
279 | 279 |
280 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), | 280 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), |
281 bitmap_.height()); | 281 bitmap_.height()); |
282 return true; | 282 return true; |
283 } | 283 } |
284 | 284 |
285 } // namespace skia | 285 } // namespace skia |
OLD | NEW |