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" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "skia/ext/bitmap_platform_device_data.h" | 12 #include "skia/ext/bitmap_platform_device_data.h" |
| 13 #include "skia/ext/platform_canvas.h" |
13 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
14 #include "third_party/skia/include/core/SkMatrix.h" | 15 #include "third_party/skia/include/core/SkMatrix.h" |
15 #include "third_party/skia/include/core/SkRegion.h" | 16 #include "third_party/skia/include/core/SkRegion.h" |
16 #include "third_party/skia/include/core/SkTypes.h" | 17 #include "third_party/skia/include/core/SkTypes.h" |
17 #include "third_party/skia/include/core/SkUtils.h" | 18 #include "third_party/skia/include/core/SkUtils.h" |
18 | 19 |
19 namespace skia { | 20 namespace skia { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 248 |
248 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 249 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
249 SkBitmap::Config config, int width, int height, bool isOpaque, | 250 SkBitmap::Config config, int width, int height, bool isOpaque, |
250 Usage /*usage*/) { | 251 Usage /*usage*/) { |
251 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 252 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
252 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, | 253 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, |
253 isOpaque); | 254 isOpaque); |
254 return bitmap_device; | 255 return bitmap_device; |
255 } | 256 } |
256 | 257 |
| 258 // Port of PlatformBitmap to mac |
| 259 |
| 260 PlatformBitmap::~PlatformBitmap() { |
| 261 if (surface_) |
| 262 CGContextRelease(surface_); |
| 263 } |
| 264 |
| 265 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { |
| 266 if (RasterDeviceTooBigToAllocate(width, height)) |
| 267 return false; |
| 268 |
| 269 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, width * 4); |
| 270 if (!bitmap_.allocPixels()) |
| 271 return false; |
| 272 |
| 273 if (!is_opaque) |
| 274 bitmap_.eraseColor(0); |
| 275 bitmap_.setIsOpaque(is_opaque); |
| 276 |
| 277 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), |
| 278 bitmap_.height()); |
| 279 return true; |
| 280 } |
| 281 |
257 } // namespace skia | 282 } // namespace skia |
OLD | NEW |