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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 return CreateCanvas(dev, failureType); | 291 return CreateCanvas(dev, failureType); |
292 } | 292 } |
293 | 293 |
294 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, | 294 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, |
295 uint8_t* data, OnFailureType failureType) { | 295 uint8_t* data, OnFailureType failureType) { |
296 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( | 296 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
297 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); | 297 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); |
298 return CreateCanvas(dev, failureType); | 298 return CreateCanvas(dev, failureType); |
299 } | 299 } |
300 | 300 |
301 // Port of PlatformBitmap to mac | |
302 | |
303 PlatformBitmap::~PlatformBitmap() { | |
304 if (surface_) | |
305 CGContextRelease(surface_); | |
306 } | |
307 | |
308 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | |
309 if (RasterDeviceTooBigToAllocate(width, height)) | |
310 return false; | |
311 | |
312 if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque)) | |
313 return false; | |
314 | |
315 if (!is_opaque) | |
316 bitmap_.eraseColor(0); | |
317 | |
318 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), | |
319 bitmap_.height()); | |
320 return true; | |
321 } | |
322 | |
323 } // namespace skia | 301 } // namespace skia |
OLD | NEW |