| 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/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/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 CGColorRef CGColorCreateFromSkColor(SkColor color) { | 144 CGColorRef CGColorCreateFromSkColor(SkColor color) { |
| 145 return CGColorCreateGenericRGB(SkColorGetR(color) / 255.0, | 145 return CGColorCreateGenericRGB(SkColorGetR(color) / 255.0, |
| 146 SkColorGetG(color) / 255.0, | 146 SkColorGetG(color) / 255.0, |
| 147 SkColorGetB(color) / 255.0, | 147 SkColorGetB(color) / 255.0, |
| 148 SkColorGetA(color) / 255.0); | 148 SkColorGetA(color) / 255.0); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Converts NSColor to ARGB | 151 // Converts NSColor to ARGB |
| 152 SkColor NSDeviceColorToSkColor(NSColor* color) { | 152 SkColor NSDeviceColorToSkColor(NSColor* color) { |
| 153 DCHECK([color colorSpace] == [NSColorSpace genericRGBColorSpace] || | 153 DCHECK([color colorSpace] == [NSColorSpace genericRGBColorSpace] || |
| 154 [color colorSpace] == [NSColorSpace deviceRGBColorSpace]); | 154 [color colorSpace] == [NSColorSpace deviceRGBColorSpace]) |
| 155 << [[color colorSpace] localizedName]; |
| 155 CGFloat red, green, blue, alpha; | 156 CGFloat red, green, blue, alpha; |
| 156 color = [color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; | 157 color = [color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; |
| 157 [color getRed:&red green:&green blue:&blue alpha:&alpha]; | 158 [color getRed:&red green:&green blue:&blue alpha:&alpha]; |
| 158 return SkColorSetARGB(SkScalarRoundToInt(255.0 * alpha), | 159 return SkColorSetARGB(SkScalarRoundToInt(255.0 * alpha), |
| 159 SkScalarRoundToInt(255.0 * red), | 160 SkScalarRoundToInt(255.0 * red), |
| 160 SkScalarRoundToInt(255.0 * green), | 161 SkScalarRoundToInt(255.0 * green), |
| 161 SkScalarRoundToInt(255.0 * blue)); | 162 SkScalarRoundToInt(255.0 * blue)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 // Converts ARGB to NSColor. | 165 // Converts ARGB to NSColor. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 bitmap_.lockPixels(); | 383 bitmap_.lockPixels(); |
| 383 } else { | 384 } else { |
| 384 bitmap_.setConfig( | 385 bitmap_.setConfig( |
| 385 SkBitmap::kARGB_8888_Config, deviceBits.width(), deviceBits.height()); | 386 SkBitmap::kARGB_8888_Config, deviceBits.width(), deviceBits.height()); |
| 386 bitmap_.allocPixels(); | 387 bitmap_.allocPixels(); |
| 387 bitmap_.eraseColor(0); | 388 bitmap_.eraseColor(0); |
| 388 } | 389 } |
| 389 base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( | 390 base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( |
| 390 CGColorSpaceCreateDeviceRGB()); | 391 CGColorSpaceCreateDeviceRGB()); |
| 391 cgContext_ = CGBitmapContextCreate(bitmap_.getPixels(), bitmap_.width(), | 392 cgContext_ = CGBitmapContextCreate(bitmap_.getPixels(), bitmap_.width(), |
| 392 bitmap_.height(), 8, bitmap_.rowBytes(), colorSpace, | 393 bitmap_.height(), 8, bitmap_.rowBytes(), colorSpace, |
| 393 kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst); | 394 kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst); |
| 394 | 395 |
| 395 // Apply device matrix. | 396 // Apply device matrix. |
| 396 CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1); | 397 CGAffineTransform contentsTransform = CGAffineTransformMakeScale(1, -1); |
| 397 contentsTransform = CGAffineTransformTranslate(contentsTransform, 0, | 398 contentsTransform = CGAffineTransformTranslate(contentsTransform, 0, |
| 398 -device->height()); | 399 -device->height()); |
| 399 CGContextConcatCTM(cgContext_, contentsTransform); | 400 CGContextConcatCTM(cgContext_, contentsTransform); |
| 400 | 401 |
| 401 const SkIPoint& pt = device->getOrigin(); | 402 const SkIPoint& pt = device->getOrigin(); |
| 402 // Skip applying the clip when not writing directly to device. | 403 // Skip applying the clip when not writing directly to device. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 423 CGContextAddPath(cgContext_, clipPath); | 424 CGContextAddPath(cgContext_, clipPath); |
| 424 CGContextClip(cgContext_); | 425 CGContextClip(cgContext_); |
| 425 CGPathRelease(clipPath); | 426 CGPathRelease(clipPath); |
| 426 } | 427 } |
| 427 | 428 |
| 428 // Apply content matrix. | 429 // Apply content matrix. |
| 429 SkMatrix skMatrix = canvas_->getTotalMatrix(); | 430 SkMatrix skMatrix = canvas_->getTotalMatrix(); |
| 430 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); | 431 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); |
| 431 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); | 432 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); |
| 432 CGContextConcatCTM(cgContext_, affine); | 433 CGContextConcatCTM(cgContext_, affine); |
| 433 | 434 |
| 434 return cgContext_; | 435 return cgContext_; |
| 435 } | 436 } |
| 436 | 437 |
| 437 } // namespace gfx | 438 } // namespace gfx |
| OLD | NEW |