| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/gfx/platform_device_mac.h" | 5 #include "PlatformDeviceMac.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/gfx/skia_utils_mac.h" | 8 #include "base/gfx/skia_utils_mac.h" |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 #include "SkUtils.h" | 11 #include "SkUtils.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 CGContextClosePath(context); | 94 CGContextClosePath(context); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // static | 97 // static |
| 98 void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context, | 98 void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context, |
| 99 const SkMatrix& matrix) { | 99 const SkMatrix& matrix) { |
| 100 // CoreGraphics can concatenate transforms, but not reset the current one. | 100 // CoreGraphics can concatenate transforms, but not reset the current one. |
| 101 // So in order to get the required behavior here, we need to first make | 101 // So in order to get the required behavior here, we need to first make |
| 102 // the current transformation matrix identity and only then load the new one. | 102 // the current transformation matrix identity and only then load the new one. |
| 103 | 103 |
| 104 // Reset matrix to identity. | 104 // Reset matrix to identity. |
| 105 CGAffineTransform orig_cg_matrix = CGContextGetCTM(context); | 105 CGAffineTransform orig_cg_matrix = CGContextGetCTM(context); |
| 106 CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix)
; | 106 CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix)
; |
| 107 CGContextConcatCTM(context, orig_cg_matrix_inv); | 107 CGContextConcatCTM(context, orig_cg_matrix_inv); |
| 108 | 108 |
| 109 // assert that we have indeed returned to the identity Matrix. | 109 // assert that we have indeed returned to the identity Matrix. |
| 110 DCHECK(CGAffineTransformIsIdentity(CGContextGetCTM(context))); | 110 DCHECK(CGAffineTransformIsIdentity(CGContextGetCTM(context))); |
| 111 | 111 |
| 112 // Convert xform to CG-land. | 112 // Convert xform to CG-land. |
| 113 // Our coordinate system is flipped to match WebKit's so we need to modify | 113 // Our coordinate system is flipped to match WebKit's so we need to modify |
| 114 // the xform to match that. | 114 // the xform to match that. |
| 115 SkMatrix transformed_matrix = matrix; | 115 SkMatrix transformed_matrix = matrix; |
| 116 SkScalar sy = matrix.getScaleY() * (SkScalar)-1; | 116 SkScalar sy = matrix.getScaleY() * (SkScalar)-1; |
| 117 transformed_matrix.setScaleY(sy); | 117 transformed_matrix.setScaleY(sy); |
| 118 size_t height = CGBitmapContextGetHeight(context); | 118 size_t height = CGBitmapContextGetHeight(context); |
| 119 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. | 119 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. |
| 120 transformed_matrix.setTranslateY(ty + (SkScalar)height); | 120 transformed_matrix.setTranslateY(ty + (SkScalar)height); |
| 121 | 121 |
| 122 CGAffineTransform cg_matrix = SkMatrixToCGAffineTransform(transformed_matrix); | 122 CGAffineTransform cg_matrix = SkMatrixToCGAffineTransform(transformed_matrix); |
| 123 | 123 |
| 124 // Load final transform into context. | 124 // Load final transform into context. |
| 125 CGContextConcatCTM(context, cg_matrix); | 125 CGContextConcatCTM(context, cg_matrix); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // static | 128 // static |
| 129 void PlatformDeviceMac::LoadClippingRegionToCGContext( | 129 void PlatformDeviceMac::LoadClippingRegionToCGContext( |
| 130 CGContextRef context, | 130 CGContextRef context, |
| 131 const SkRegion& region, | 131 const SkRegion& region, |
| 132 const SkMatrix& transformation) { | 132 const SkMatrix& transformation) { |
| 133 if (region.isEmpty()) { | 133 if (region.isEmpty()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 149 region.getBoundaryPath(&path); | 149 region.getBoundaryPath(&path); |
| 150 // Clip. Note that windows clipping regions are not affected by the | 150 // Clip. Note that windows clipping regions are not affected by the |
| 151 // transform so apply it manually. | 151 // transform so apply it manually. |
| 152 path.transform(transformation); | 152 path.transform(transformation); |
| 153 // TODO(playmobil): Implement. | 153 // TODO(playmobil): Implement. |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 // LoadPathToDC(context, path); | 155 // LoadPathToDC(context, path); |
| 156 // hrgn = PathToRegion(context); | 156 // hrgn = PathToRegion(context); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace gfx | 160 } // namespace gfx |
| 161 | 161 |
| OLD | NEW |