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" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 186 |
| 187 // The device object took ownership of the graphics context with its own | 187 // The device object took ownership of the graphics context with its own |
| 188 // CGContextRetain call. | 188 // CGContextRetain call. |
| 189 if (context) | 189 if (context) |
| 190 CGContextRelease(context); | 190 CGContextRelease(context); |
| 191 | 191 |
| 192 return rv; | 192 return rv; |
| 193 } | 193 } |
| 194 | 194 |
| 195 // The device will own the bitmap, which corresponds to also owning the pixel | 195 // The device will own the bitmap, which corresponds to also owning the pixel |
| 196 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 196 // data. Therefore, we do not transfer ownership to the SkBitmapDevice's bitmap. |
| 197 BitmapPlatformDevice::BitmapPlatformDevice( | 197 BitmapPlatformDevice::BitmapPlatformDevice( |
| 198 const skia::RefPtr<BitmapPlatformDeviceData>& data, const SkBitmap& bitmap) | 198 const skia::RefPtr<BitmapPlatformDeviceData>& data, const SkBitmap& bitmap) |
| 199 : SkDevice(bitmap), | 199 : SkBitmapDevice(bitmap), |
| 200 data_(data) { | 200 data_(data) { |
| 201 SetPlatformDevice(this, this); | 201 SetPlatformDevice(this, this); |
| 202 } | 202 } |
| 203 | 203 |
| 204 BitmapPlatformDevice::~BitmapPlatformDevice() { | 204 BitmapPlatformDevice::~BitmapPlatformDevice() { |
| 205 } | 205 } |
| 206 | 206 |
| 207 CGContextRef BitmapPlatformDevice::GetBitmapContext() { | 207 CGContextRef BitmapPlatformDevice::GetBitmapContext() { |
| 208 data_->LoadConfig(); | 208 data_->LoadConfig(); |
| 209 return data_->bitmap_context(); | 209 return data_->bitmap_context(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 | 244 |
| 245 if (created_dc) | 245 if (created_dc) |
| 246 data_->ReleaseBitmapContext(); | 246 data_->ReleaseBitmapContext(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { | 249 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { |
| 250 // Not needed in CoreGraphics | 250 // Not needed in CoreGraphics |
| 251 return *bitmap; | 251 return *bitmap; |
| 252 } | 252 } |
| 253 | 253 |
| 254 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 254 SkBaseDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
| 255 SkBitmap::Config config, int width, int height, bool isOpaque, | 255 SkBitmap::Config config, int width, int height, bool isOpaque, |
| 256 Usage /*usage*/) { | 256 Usage /*usage*/) { |
| 257 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 257 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 258 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, | 258 SkBaseDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, heig ht, |
|
vandebo (ex-Chrome)
2013/08/22 20:41:58
80 col
robertphillips
2013/08/23 14:01:03
Done.
| |
| 259 isOpaque); | 259 isOpaque); |
| 260 return bitmap_device; | 260 return bitmap_device; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // PlatformCanvas impl | 263 // PlatformCanvas impl |
| 264 | 264 |
| 265 SkCanvas* CreatePlatformCanvas(CGContextRef ctx, int width, int height, | 265 SkCanvas* CreatePlatformCanvas(CGContextRef ctx, int width, int height, |
| 266 bool is_opaque, OnFailureType failureType) { | 266 bool is_opaque, OnFailureType failureType) { |
| 267 skia::RefPtr<SkDevice> dev = skia::AdoptRef( | 267 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
| 268 BitmapPlatformDevice::Create(ctx, width, height, is_opaque)); | 268 BitmapPlatformDevice::Create(ctx, width, height, is_opaque)); |
| 269 return CreateCanvas(dev, failureType); | 269 return CreateCanvas(dev, failureType); |
| 270 } | 270 } |
| 271 | 271 |
| 272 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, | 272 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, |
| 273 uint8_t* data, OnFailureType failureType) { | 273 uint8_t* data, OnFailureType failureType) { |
| 274 skia::RefPtr<SkDevice> dev = skia::AdoptRef( | 274 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
| 275 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); | 275 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); |
| 276 return CreateCanvas(dev, failureType); | 276 return CreateCanvas(dev, failureType); |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Port of PlatformBitmap to mac | 279 // Port of PlatformBitmap to mac |
| 280 | 280 |
| 281 PlatformBitmap::~PlatformBitmap() { | 281 PlatformBitmap::~PlatformBitmap() { |
| 282 if (surface_) | 282 if (surface_) |
| 283 CGContextRelease(surface_); | 283 CGContextRelease(surface_); |
| 284 } | 284 } |
| 285 | 285 |
| 286 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | 286 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { |
| 287 if (RasterDeviceTooBigToAllocate(width, height)) | 287 if (RasterDeviceTooBigToAllocate(width, height)) |
| 288 return false; | 288 return false; |
| 289 | 289 |
| 290 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, width * 4); | 290 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, width * 4); |
| 291 if (!bitmap_.allocPixels()) | 291 if (!bitmap_.allocPixels()) |
| 292 return false; | 292 return false; |
| 293 | 293 |
| 294 if (!is_opaque) | 294 if (!is_opaque) |
| 295 bitmap_.eraseColor(0); | 295 bitmap_.eraseColor(0); |
| 296 bitmap_.setIsOpaque(is_opaque); | 296 bitmap_.setIsOpaque(is_opaque); |
| 297 | 297 |
| 298 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), | 298 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), |
| 299 bitmap_.height()); | 299 bitmap_.height()); |
| 300 return true; | 300 return true; |
| 301 } | 301 } |
| 302 | 302 |
| 303 } // namespace skia | 303 } // namespace skia |
| OLD | NEW |