OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/skia_utils_mac.h" | 5 #include "skia/ext/skia_utils_mac.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
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 SkColorGetA(color) / 255.0); | 186 SkColorGetA(color) / 255.0); |
187 } | 187 } |
188 | 188 |
189 SkBitmap CGImageToSkBitmap(CGImageRef image) { | 189 SkBitmap CGImageToSkBitmap(CGImageRef image) { |
190 if (!image) | 190 if (!image) |
191 return SkBitmap(); | 191 return SkBitmap(); |
192 | 192 |
193 int width = CGImageGetWidth(image); | 193 int width = CGImageGetWidth(image); |
194 int height = CGImageGetHeight(image); | 194 int height = CGImageGetHeight(image); |
195 | 195 |
196 scoped_ptr<skia::BitmapPlatformDevice> device( | 196 scoped_ptr<SkDevice> device( |
197 skia::BitmapPlatformDevice::Create(NULL, width, height, false)); | 197 skia::BitmapPlatformDevice::Create(NULL, width, height, false)); |
198 | 198 |
199 CGContextRef context = device->GetBitmapContext(); | 199 CGContextRef context = skia::GetBitmapContext(device.get()); |
200 | 200 |
201 // We need to invert the y-axis of the canvas so that Core Graphics drawing | 201 // We need to invert the y-axis of the canvas so that Core Graphics drawing |
202 // happens right-side up. Skia has an upper-left origin and CG has a lower- | 202 // happens right-side up. Skia has an upper-left origin and CG has a lower- |
203 // left one. | 203 // left one. |
204 CGContextScaleCTM(context, 1.0, -1.0); | 204 CGContextScaleCTM(context, 1.0, -1.0); |
205 CGContextTranslateCTM(context, 0, -height); | 205 CGContextTranslateCTM(context, 0, -height); |
206 | 206 |
207 // We want to copy transparent pixels from |image|, instead of blending it | 207 // We want to copy transparent pixels from |image|, instead of blending it |
208 // onto uninitialized pixels. | 208 // onto uninitialized pixels. |
209 CGContextSetBlendMode(context, kCGBlendModeCopy); | 209 CGContextSetBlendMode(context, kCGBlendModeCopy); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 // Apply content matrix. | 338 // Apply content matrix. |
339 const SkMatrix& skMatrix = canvas_->getTotalMatrix(); | 339 const SkMatrix& skMatrix = canvas_->getTotalMatrix(); |
340 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); | 340 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); |
341 CGContextConcatCTM(cgContext_, affine); | 341 CGContextConcatCTM(cgContext_, affine); |
342 | 342 |
343 return cgContext_; | 343 return cgContext_; |
344 } | 344 } |
345 | 345 |
346 } // namespace gfx | 346 } // namespace gfx |
OLD | NEW |