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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 #endif | 149 #endif |
150 | 150 |
151 if (!context) { | 151 if (!context) { |
152 context = CGContextForData(data, width, height); | 152 context = CGContextForData(data, width, height); |
153 if (!context) | 153 if (!context) |
154 return NULL; | 154 return NULL; |
155 } else | 155 } else |
156 CGContextRetain(context); | 156 CGContextRetain(context); |
157 | 157 |
158 BitmapPlatformDevice* rv = new BitmapPlatformDevice( | 158 BitmapPlatformDevice* rv = new BitmapPlatformDevice( |
159 new BitmapPlatformDeviceData(context), bitmap); | 159 skia::AdoptRef(new BitmapPlatformDeviceData(context)), bitmap); |
160 | 160 |
161 // The device object took ownership of the graphics context with its own | 161 // The device object took ownership of the graphics context with its own |
162 // CGContextRetain call. | 162 // CGContextRetain call. |
163 CGContextRelease(context); | 163 CGContextRelease(context); |
164 | 164 |
165 return rv; | 165 return rv; |
166 } | 166 } |
167 | 167 |
168 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, | 168 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, |
169 int height, | 169 int height, |
(...skipping 18 matching lines...) Expand all Loading... |
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 SkDevice's bitmap. |
197 BitmapPlatformDevice::BitmapPlatformDevice( | 197 BitmapPlatformDevice::BitmapPlatformDevice( |
198 BitmapPlatformDeviceData* data, const SkBitmap& bitmap) | 198 const skia::RefPtr<BitmapPlatformDeviceData>& data, const SkBitmap& bitmap) |
199 : SkDevice(bitmap), | 199 : SkDevice(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 data_->unref(); | |
206 } | 205 } |
207 | 206 |
208 CGContextRef BitmapPlatformDevice::GetBitmapContext() { | 207 CGContextRef BitmapPlatformDevice::GetBitmapContext() { |
209 data_->LoadConfig(); | 208 data_->LoadConfig(); |
210 return data_->bitmap_context(); | 209 return data_->bitmap_context(); |
211 } | 210 } |
212 | 211 |
213 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, | 212 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, |
214 const SkRegion& region, | 213 const SkRegion& region, |
215 const SkClipStack&) { | 214 const SkClipStack&) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 257 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
259 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, | 258 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, |
260 isOpaque); | 259 isOpaque); |
261 return bitmap_device; | 260 return bitmap_device; |
262 } | 261 } |
263 | 262 |
264 // PlatformCanvas impl | 263 // PlatformCanvas impl |
265 | 264 |
266 SkCanvas* CreatePlatformCanvas(CGContextRef ctx, int width, int height, | 265 SkCanvas* CreatePlatformCanvas(CGContextRef ctx, int width, int height, |
267 bool is_opaque, OnFailureType failureType) { | 266 bool is_opaque, OnFailureType failureType) { |
268 SkDevice* dev = BitmapPlatformDevice::Create(ctx, width, height, is_opaque); | 267 skia::RefPtr<SkDevice> dev = skia::AdoptRef( |
| 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 SkDevice* dev = BitmapPlatformDevice::CreateWithData(data, width, height, | 274 skia::RefPtr<SkDevice> dev = skia::AdoptRef( |
275 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 |