Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 // to include them. | 181 // to include them. |
| 182 SkScalar fX = SkFloatToScalar(point.x()); | 182 SkScalar fX = SkFloatToScalar(point.x()); |
| 183 SkScalar fY = SkFloatToScalar(point.y()); | 183 SkScalar fY = SkFloatToScalar(point.y()); |
| 184 if (fX < bounds.fLeft || fX > bounds.fRight || fY < bounds.fTop || fY > boun ds.fBottom) | 184 if (fX < bounds.fLeft || fX > bounds.fRight || fY < bounds.fTop || fY > boun ds.fBottom) |
| 185 return false; | 185 return false; |
| 186 | 186 |
| 187 // Scale the path to a large size before hit testing for two reasons: | 187 // Scale the path to a large size before hit testing for two reasons: |
| 188 // 1) Skia has trouble with coordinates close to the max signed 16-bit value s, so we scale larger paths down. | 188 // 1) Skia has trouble with coordinates close to the max signed 16-bit value s, so we scale larger paths down. |
| 189 // TODO: when Skia is patched to work properly with large values, this wi ll not be necessary. | 189 // TODO: when Skia is patched to work properly with large values, this wi ll not be necessary. |
| 190 // 2) Skia does not support analytic hit testing, so we scale paths up to do raster hit testing with subpixel accuracy. | 190 // 2) Skia does not support analytic hit testing, so we scale paths up to do raster hit testing with subpixel accuracy. |
| 191 SkScalar biggestCoord = std::max(std::max(std::max(bounds.fRight, bounds.fBo ttom), -bounds.fLeft), -bounds.fTop); | 191 // 3) Scale the x/y axis separately so an extreme large/small scale factor o n one axis won't |
| 192 if (SkScalarNearlyZero(biggestCoord)) | 192 // ruin the resolution of the other axis. |
| 193 SkScalar biggestCoordX = std::max(bounds.fRight, -bounds.fLeft); | |
| 194 SkScalar biggestCoordY = std::max(bounds.fBottom, -bounds.fTop); | |
| 195 if (SkScalarNearlyZero(biggestCoordX) || SkScalarNearlyZero(biggestCoordY)) | |
| 193 return false; | 196 return false; |
| 194 biggestCoord = std::max(std::max(biggestCoord, fX + 1), fY + 1); | 197 |
| 198 biggestCoordX = std::max(biggestCoordX, fX + 1); | |
|
f(malita)
2015/08/20 09:29:06
Not new to this CL, but are we missing a fabs(fX)
Yufeng Shen (Slow to review)
2015/08/24 20:13:07
right, also it makes the code easier to follow.
| |
| 199 biggestCoordY = std::max(biggestCoordY, fY + 1); | |
|
f(malita)
2015/08/20 09:29:06
Ditto for fY.
Yufeng Shen (Slow to review)
2015/08/24 20:13:07
Done.
| |
| 195 | 200 |
| 196 const SkScalar kMaxCoordinate = SkIntToScalar(1 << 15); | 201 const SkScalar kMaxCoordinate = SkIntToScalar(1 << 15); |
| 197 SkScalar scale = kMaxCoordinate / biggestCoord; | 202 SkScalar scaleX = kMaxCoordinate / biggestCoordX; |
| 203 SkScalar scaleY = kMaxCoordinate / biggestCoordY; | |
| 198 | 204 |
| 199 SkRegion rgn; | 205 SkRegion rgn; |
| 200 SkRegion clip; | 206 SkRegion clip; |
| 201 SkMatrix m; | 207 SkMatrix m; |
| 202 SkPath scaledPath(originalPath); | 208 SkPath scaledPath(originalPath); |
| 203 | 209 |
| 204 scaledPath.setFillType(ft); | 210 scaledPath.setFillType(ft); |
| 205 m.setScale(scale, scale); | 211 m.setScale(scaleX, scaleY); |
| 206 scaledPath.transform(m, 0); | 212 scaledPath.transform(m, 0); |
| 207 | 213 |
| 208 int x = static_cast<int>(floorf(0.5f + point.x() * scale)); | 214 int x = static_cast<int>(floorf(0.5f + point.x() * scaleX)); |
| 209 int y = static_cast<int>(floorf(0.5f + point.y() * scale)); | 215 int y = static_cast<int>(floorf(0.5f + point.y() * scaleY)); |
| 210 clip.setRect(x - 1, y - 1, x + 1, y + 1); | 216 clip.setRect(x - 1, y - 1, x + 1, y + 1); |
| 211 | 217 |
| 212 return rgn.setPath(scaledPath, clip); | 218 return rgn.setPath(scaledPath, clip); |
| 213 } | 219 } |
| 214 | 220 |
| 215 SkMatrix affineTransformToSkMatrix(const AffineTransform& source) | 221 SkMatrix affineTransformToSkMatrix(const AffineTransform& source) |
| 216 { | 222 { |
| 217 SkMatrix result; | 223 SkMatrix result; |
| 218 | 224 |
| 219 result.setScaleX(WebCoreDoubleToSkScalar(source.a())); | 225 result.setScaleX(WebCoreDoubleToSkScalar(source.a())); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 paint.setAlpha(128); | 397 paint.setAlpha(128); |
| 392 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); | 398 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); |
| 393 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); | 399 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
| 394 #endif | 400 #endif |
| 395 } | 401 } |
| 396 | 402 |
| 397 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, SkCan vas*, SkColor, int width); | 403 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, SkCan vas*, SkColor, int width); |
| 398 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, SkCan vas*, SkColor, int width); | 404 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, SkCan vas*, SkColor, int width); |
| 399 | 405 |
| 400 } // namespace blink | 406 } // namespace blink |
| OLD | NEW |