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, |
259 isOpaque); | 259 height, |
| 260 isOpaque); |
260 return bitmap_device; | 261 return bitmap_device; |
261 } | 262 } |
262 | 263 |
263 // PlatformCanvas impl | 264 // PlatformCanvas impl |
264 | 265 |
265 SkCanvas* CreatePlatformCanvas(CGContextRef ctx, int width, int height, | 266 SkCanvas* CreatePlatformCanvas(CGContextRef ctx, int width, int height, |
266 bool is_opaque, OnFailureType failureType) { | 267 bool is_opaque, OnFailureType failureType) { |
267 skia::RefPtr<SkDevice> dev = skia::AdoptRef( | 268 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
268 BitmapPlatformDevice::Create(ctx, width, height, is_opaque)); | 269 BitmapPlatformDevice::Create(ctx, width, height, is_opaque)); |
269 return CreateCanvas(dev, failureType); | 270 return CreateCanvas(dev, failureType); |
270 } | 271 } |
271 | 272 |
272 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, | 273 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, |
273 uint8_t* data, OnFailureType failureType) { | 274 uint8_t* data, OnFailureType failureType) { |
274 skia::RefPtr<SkDevice> dev = skia::AdoptRef( | 275 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
275 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); | 276 BitmapPlatformDevice::CreateWithData(data, width, height, is_opaque)); |
276 return CreateCanvas(dev, failureType); | 277 return CreateCanvas(dev, failureType); |
277 } | 278 } |
278 | 279 |
279 // Port of PlatformBitmap to mac | 280 // Port of PlatformBitmap to mac |
280 | 281 |
281 PlatformBitmap::~PlatformBitmap() { | 282 PlatformBitmap::~PlatformBitmap() { |
282 if (surface_) | 283 if (surface_) |
283 CGContextRelease(surface_); | 284 CGContextRelease(surface_); |
284 } | 285 } |
285 | 286 |
286 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | 287 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { |
287 if (RasterDeviceTooBigToAllocate(width, height)) | 288 if (RasterDeviceTooBigToAllocate(width, height)) |
288 return false; | 289 return false; |
289 | 290 |
290 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, width * 4); | 291 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, width * 4); |
291 if (!bitmap_.allocPixels()) | 292 if (!bitmap_.allocPixels()) |
292 return false; | 293 return false; |
293 | 294 |
294 if (!is_opaque) | 295 if (!is_opaque) |
295 bitmap_.eraseColor(0); | 296 bitmap_.eraseColor(0); |
296 bitmap_.setIsOpaque(is_opaque); | 297 bitmap_.setIsOpaque(is_opaque); |
297 | 298 |
298 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), | 299 surface_ = CGContextForData(bitmap_.getPixels(), bitmap_.width(), |
299 bitmap_.height()); | 300 bitmap_.height()); |
300 return true; | 301 return true; |
301 } | 302 } |
302 | 303 |
303 } // namespace skia | 304 } // namespace skia |
OLD | NEW |