| 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 "skia/ext/bitmap_platform_device_mac.h" | 5 #include "skia/ext/bitmap_platform_device_mac.h" |
| 6 | 6 |
| 7 #include "skia/ext/skia_utils_mac.h" | 7 #include "skia/ext/skia_utils_mac.h" |
| 8 #include "third_party/skia/include/core/SkMatrix.h" | 8 #include "third_party/skia/include/core/SkMatrix.h" |
| 9 #include "third_party/skia/include/core/SkPath.h" | 9 #include "third_party/skia/include/core/SkPath.h" |
| 10 #include "third_party/skia/include/core/SkTypes.h" | 10 #include "third_party/skia/include/core/SkTypes.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 if (overflow > 0) { | 28 if (overflow > 0) { |
| 29 *size -= overflow; | 29 *size -= overflow; |
| 30 } | 30 } |
| 31 return true; | 31 return true; |
| 32 } | 32 } |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 PlatformDeviceMac::PlatformDeviceMac(const SkBitmap& bitmap) | 38 PlatformDevice::PlatformDevice(const SkBitmap& bitmap) : SkDevice(bitmap) { |
| 39 : SkDevice(bitmap) { | |
| 40 } | 39 } |
| 41 | 40 |
| 42 // Set up the CGContextRef for peaceful coexistence with Skia | 41 // Set up the CGContextRef for peaceful coexistence with Skia |
| 43 void PlatformDeviceMac::InitializeCGContext(CGContextRef context) { | 42 void PlatformDevice::InitializeCGContext(CGContextRef context) { |
| 44 // CG defaults to the same settings as Skia | 43 // CG defaults to the same settings as Skia |
| 45 } | 44 } |
| 46 | 45 |
| 47 // static | 46 // static |
| 48 void PlatformDeviceMac::LoadPathToCGContext(CGContextRef context, | 47 void PlatformDevice::LoadPathToCGContext(CGContextRef context, |
| 49 const SkPath& path) { | 48 const SkPath& path) { |
| 50 // instead of a persistent attribute of the context, CG specifies the fill | 49 // instead of a persistent attribute of the context, CG specifies the fill |
| 51 // type per call, so we just have to load up the geometry. | 50 // type per call, so we just have to load up the geometry. |
| 52 CGContextBeginPath(context); | 51 CGContextBeginPath(context); |
| 53 | 52 |
| 54 SkPoint points[4] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} }; | 53 SkPoint points[4] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} }; |
| 55 SkPath::Iter iter(path, false); | 54 SkPath::Iter iter(path, false); |
| 56 for (SkPath::Verb verb = iter.next(points); verb != SkPath::kDone_Verb; | 55 for (SkPath::Verb verb = iter.next(points); verb != SkPath::kDone_Verb; |
| 57 verb = iter.next(points)) { | 56 verb = iter.next(points)) { |
| 58 switch (verb) { | 57 switch (verb) { |
| 59 case SkPath::kMove_Verb: { // iter.next returns 1 point | 58 case SkPath::kMove_Verb: { // iter.next returns 1 point |
| (...skipping 22 matching lines...) Expand all Loading... |
| 82 default: { | 81 default: { |
| 83 SkASSERT(false); | 82 SkASSERT(false); |
| 84 break; | 83 break; |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 CGContextClosePath(context); | 87 CGContextClosePath(context); |
| 89 } | 88 } |
| 90 | 89 |
| 91 // static | 90 // static |
| 92 void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context, | 91 void PlatformDevice::LoadTransformToCGContext(CGContextRef context, |
| 93 const SkMatrix& matrix) { | 92 const SkMatrix& matrix) { |
| 94 // CoreGraphics can concatenate transforms, but not reset the current one. | 93 // CoreGraphics can concatenate transforms, but not reset the current one. |
| 95 // So in order to get the required behavior here, we need to first make | 94 // So in order to get the required behavior here, we need to first make |
| 96 // the current transformation matrix identity and only then load the new one. | 95 // the current transformation matrix identity and only then load the new one. |
| 97 | 96 |
| 98 // Reset matrix to identity. | 97 // Reset matrix to identity. |
| 99 CGAffineTransform orig_cg_matrix = CGContextGetCTM(context); | 98 CGAffineTransform orig_cg_matrix = CGContextGetCTM(context); |
| 100 CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix)
; | 99 CGAffineTransform orig_cg_matrix_inv = CGAffineTransformInvert(orig_cg_matrix)
; |
| 101 CGContextConcatCTM(context, orig_cg_matrix_inv); | 100 CGContextConcatCTM(context, orig_cg_matrix_inv); |
| 102 | 101 |
| 103 // assert that we have indeed returned to the identity Matrix. | 102 // assert that we have indeed returned to the identity Matrix. |
| 104 SkASSERT(CGAffineTransformIsIdentity(CGContextGetCTM(context))); | 103 SkASSERT(CGAffineTransformIsIdentity(CGContextGetCTM(context))); |
| 105 | 104 |
| 106 // Convert xform to CG-land. | 105 // Convert xform to CG-land. |
| 107 // Our coordinate system is flipped to match WebKit's so we need to modify | 106 // Our coordinate system is flipped to match WebKit's so we need to modify |
| 108 // the xform to match that. | 107 // the xform to match that. |
| 109 SkMatrix transformed_matrix = matrix; | 108 SkMatrix transformed_matrix = matrix; |
| 110 SkScalar sy = matrix.getScaleY() * (SkScalar)-1; | 109 SkScalar sy = matrix.getScaleY() * (SkScalar)-1; |
| 111 transformed_matrix.setScaleY(sy); | 110 transformed_matrix.setScaleY(sy); |
| 112 size_t height = CGBitmapContextGetHeight(context); | 111 size_t height = CGBitmapContextGetHeight(context); |
| 113 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. | 112 SkScalar ty = -matrix.getTranslateY(); // y axis is flipped. |
| 114 transformed_matrix.setTranslateY(ty + (SkScalar)height); | 113 transformed_matrix.setTranslateY(ty + (SkScalar)height); |
| 115 | 114 |
| 116 CGAffineTransform cg_matrix = SkMatrixToCGAffineTransform(transformed_matrix); | 115 CGAffineTransform cg_matrix = SkMatrixToCGAffineTransform(transformed_matrix); |
| 117 | 116 |
| 118 // Load final transform into context. | 117 // Load final transform into context. |
| 119 CGContextConcatCTM(context, cg_matrix); | 118 CGContextConcatCTM(context, cg_matrix); |
| 120 } | 119 } |
| 121 | 120 |
| 122 // static | 121 // static |
| 123 void PlatformDeviceMac::LoadClippingRegionToCGContext( | 122 void PlatformDevice::LoadClippingRegionToCGContext( |
| 124 CGContextRef context, | 123 CGContextRef context, |
| 125 const SkRegion& region, | 124 const SkRegion& region, |
| 126 const SkMatrix& transformation) { | 125 const SkMatrix& transformation) { |
| 127 if (region.isEmpty()) { | 126 if (region.isEmpty()) { |
| 128 // region can be empty, in which case everything will be clipped. | 127 // region can be empty, in which case everything will be clipped. |
| 129 SkRect rect; | 128 SkRect rect; |
| 130 rect.setEmpty(); | 129 rect.setEmpty(); |
| 131 CGContextClipToRect(context, SkRectToCGRect(rect)); | 130 CGContextClipToRect(context, SkRectToCGRect(rect)); |
| 132 } else if (region.isRect()) { | 131 } else if (region.isRect()) { |
| 133 // Do the transformation. | 132 // Do the transformation. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 146 path.transform(transformation); | 145 path.transform(transformation); |
| 147 // TODO(playmobil): Implement. | 146 // TODO(playmobil): Implement. |
| 148 SkASSERT(false); | 147 SkASSERT(false); |
| 149 // LoadPathToDC(context, path); | 148 // LoadPathToDC(context, path); |
| 150 // hrgn = PathToRegion(context); | 149 // hrgn = PathToRegion(context); |
| 151 } | 150 } |
| 152 } | 151 } |
| 153 | 152 |
| 154 } // namespace skia | 153 } // namespace skia |
| 155 | 154 |
| OLD | NEW |