Chromium Code Reviews| 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/skia_utils_mac.h" | 13 #include "skia/ext/skia_utils_mac.h" |
| 14 #include "third_party/skia/include/core/SkMatrix.h" | 14 #include "third_party/skia/include/core/SkMatrix.h" |
| 15 #include "third_party/skia/include/core/SkRegion.h" | 15 #include "third_party/skia/include/core/SkRegion.h" |
| 16 #include "third_party/skia/include/core/SkTypes.h" | 16 #include "third_party/skia/include/core/SkTypes.h" |
| 17 #include "third_party/skia/include/core/SkUtils.h" | 17 #include "third_party/skia/include/core/SkUtils.h" |
| 18 | 18 |
| 19 #include "skia/ext/platform_canvas.h" | |
|
brettw
2012/10/09 20:40:12
This should go in the above block in order.
reed1
2012/10/09 21:06:43
Done.
| |
| 20 | |
| 19 namespace skia { | 21 namespace skia { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 static CGContextRef CGContextForData(void* data, int width, int height) { | 25 static CGContextRef CGContextForData(void* data, int width, int height) { |
| 24 #define HAS_ARGB_SHIFTS(a, r, g, b) \ | 26 #define HAS_ARGB_SHIFTS(a, r, g, b) \ |
| 25 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ | 27 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ |
| 26 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) | 28 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) |
| 27 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) | 29 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) |
| 28 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple | 30 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 | 249 |
| 248 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 250 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
| 249 SkBitmap::Config config, int width, int height, bool isOpaque, | 251 SkBitmap::Config config, int width, int height, bool isOpaque, |
| 250 Usage /*usage*/) { | 252 Usage /*usage*/) { |
| 251 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 253 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 252 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, | 254 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, |
| 253 isOpaque); | 255 isOpaque); |
| 254 return bitmap_device; | 256 return bitmap_device; |
| 255 } | 257 } |
| 256 | 258 |
| 259 // Port of PlatformBitmap to mac | |
| 260 | |
| 261 PlatformBitmap::~PlatformBitmap() { | |
| 262 if (surface_) | |
| 263 CGContextRelease(surface_); | |
| 264 } | |
| 265 | |
| 266 bool PlatformBitmap::Allocate(int width, int height, bool isOpaque) { | |
| 267 if (RasterDeviceTooBigToAllocate(width, height)) | |
| 268 return false; | |
| 269 | |
| 270 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, width * 4); | |
| 271 if (!bitmap_.allocPixels()) | |
| 272 return false; | |
| 273 | |
| 274 if (!isOpaque) | |
| 275 bitmap_.eraseColor(0); | |
| 276 bitmap_.setIsOpaque(isOpaque); | |
| 277 return true; | |
| 278 } | |
| 279 | |
| 280 PlatformSurface PlatformBitmap::LockSurface() { | |
| 281 if (!surface_ && bitmap_.getPixels()) | |
| 282 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), | |
| 283 bitmap_.height()); | |
| 284 return surface_; | |
| 285 } | |
| 286 | |
| 287 void PlatformBitmap::UnlockSurface() { | |
| 288 // nothing to do for our CGContext. It will be released in our destructor | |
| 289 } | |
| 290 | |
| 257 } // namespace skia | 291 } // namespace skia |
| OLD | NEW |