| 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/platform_device_win.h" | 5 #include "skia/ext/platform_device_win.h" |
| 6 | 6 |
| 7 #include "skia/ext/skia_utils_win.h" | 7 #include "skia/ext/skia_utils_win.h" |
| 8 #include "SkMatrix.h" | 8 #include "SkMatrix.h" |
| 9 #include "SkPath.h" | 9 #include "SkPath.h" |
| 10 #include "SkRegion.h" | 10 #include "SkRegion.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 // static | 194 // static |
| 195 void PlatformDeviceWin::LoadClippingRegionToDC(HDC context, | 195 void PlatformDeviceWin::LoadClippingRegionToDC(HDC context, |
| 196 const SkRegion& region, | 196 const SkRegion& region, |
| 197 const SkMatrix& transformation) { | 197 const SkMatrix& transformation) { |
| 198 HRGN hrgn; | 198 HRGN hrgn; |
| 199 if (region.isEmpty()) { | 199 if (region.isEmpty()) { |
| 200 // region can be empty, in which case everything will be clipped. | 200 // region can be empty, in which case everything will be clipped. |
| 201 hrgn = CreateRectRgn(0, 0, 0, 0); | 201 hrgn = CreateRectRgn(0, 0, 0, 0); |
| 202 } else if (region.isRect()) { | 202 } else if (region.isRect()) { |
| 203 // Do the transformation. | 203 // We don't apply transformation, because the translation is already applied |
| 204 SkRect rect; | 204 // to the region. |
| 205 rect.set(region.getBounds()); | 205 hrgn = CreateRectRgnIndirect(&SkIRectToRECT(region.getBounds())); |
| 206 transformation.mapRect(&rect); | |
| 207 SkIRect irect; | |
| 208 rect.round(&irect); | |
| 209 hrgn = CreateRectRgnIndirect(&SkIRectToRECT(irect)); | |
| 210 } else { | 206 } else { |
| 211 // It is complex. | 207 // It is complex. |
| 212 SkPath path; | 208 SkPath path; |
| 213 region.getBoundaryPath(&path); | 209 region.getBoundaryPath(&path); |
| 214 // Clip. Note that windows clipping regions are not affected by the | 210 // Clip. Note that windows clipping regions are not affected by the |
| 215 // transform so apply it manually. | 211 // transform so apply it manually. |
| 216 path.transform(transformation); | 212 // Since the transform is given as the original translation of canvas, we |
| 213 // should apply it in reverse. |
| 214 SkMatrix t(transformation); |
| 215 t.setTranslateX(-t.getTranslateX()); |
| 216 t.setTranslateY(-t.getTranslateY()); |
| 217 path.transform(t); |
| 217 LoadPathToDC(context, path); | 218 LoadPathToDC(context, path); |
| 218 hrgn = PathToRegion(context); | 219 hrgn = PathToRegion(context); |
| 219 } | 220 } |
| 220 int result = SelectClipRgn(context, hrgn); | 221 int result = SelectClipRgn(context, hrgn); |
| 221 SkASSERT(result != ERROR); | 222 SkASSERT(result != ERROR); |
| 222 result = DeleteObject(hrgn); | 223 result = DeleteObject(hrgn); |
| 223 SkASSERT(result != 0); | 224 SkASSERT(result != 0); |
| 224 } | 225 } |
| 225 | 226 |
| 226 } // namespace skia | 227 } // namespace skia |
| 227 | 228 |
| OLD | NEW |