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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 { | 132 { |
| 133 return SkPMColorToColor(pm); | 133 return SkPMColorToColor(pm); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void ClipRectToCanvas(const GraphicsContext* context, const SkRect& srcRect, SkR ect* destRect) | 136 void ClipRectToCanvas(const GraphicsContext* context, const SkRect& srcRect, SkR ect* destRect) |
| 137 { | 137 { |
| 138 if (!context->getClipBounds(destRect) || !destRect->intersect(srcRect)) | 138 if (!context->getClipBounds(destRect) || !destRect->intersect(srcRect)) |
| 139 destRect->setEmpty(); | 139 destRect->setEmpty(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool SkPathContainsPoint(SkPath* originalPath, const FloatPoint& point, SkPath:: FillType ft) | 142 bool SkPathContainsPoint(const SkPath& originalPath, const FloatPoint& point, Sk Path::FillType ft) |
| 143 { | 143 { |
| 144 SkRect bounds = originalPath->getBounds(); | 144 SkRect bounds = originalPath.getBounds(); |
| 145 | 145 |
| 146 // We can immediately return false if the point is outside the bounding | 146 // We can immediately return false if the point is outside the bounding |
| 147 // rect. We don't use bounds.contains() here, since it would exclude | 147 // rect. We don't use bounds.contains() here, since it would exclude |
| 148 // points on the right and bottom edges of the bounding rect, and we want | 148 // points on the right and bottom edges of the bounding rect, and we want |
| 149 // to include them. | 149 // to include them. |
| 150 SkScalar fX = SkFloatToScalar(point.x()); | 150 SkScalar fX = SkFloatToScalar(point.x()); |
| 151 SkScalar fY = SkFloatToScalar(point.y()); | 151 SkScalar fY = SkFloatToScalar(point.y()); |
| 152 if (fX < bounds.fLeft || fX > bounds.fRight || fY < bounds.fTop || fY > boun ds.fBottom) | 152 if (fX < bounds.fLeft || fX > bounds.fRight || fY < bounds.fTop || fY > boun ds.fBottom) |
| 153 return false; | 153 return false; |
| 154 | 154 |
| 155 // Scale the path to a large size before hit testing for two reasons: | 155 // Scale the path to a large size before hit testing for two reasons: |
| 156 // 1) Skia has trouble with coordinates close to the max signed 16-bit value s, so we scale larger paths down. | 156 // 1) Skia has trouble with coordinates close to the max signed 16-bit value s, so we scale larger paths down. |
| 157 // TODO: when Skia is patched to work properly with large values, this wi ll not be necessary. | 157 // TODO: when Skia is patched to work properly with large values, this wi ll not be necessary. |
| 158 // 2) Skia does not support analytic hit testing, so we scale paths up to do raster hit testing with subpixel accuracy. | 158 // 2) Skia does not support analytic hit testing, so we scale paths up to do raster hit testing with subpixel accuracy. |
| 159 SkScalar biggestCoord = std::max(std::max(std::max(bounds.fRight, bounds.fBo ttom), -bounds.fLeft), -bounds.fTop); | 159 SkScalar biggestCoord = std::max(std::max(std::max(bounds.fRight, bounds.fBo ttom), -bounds.fLeft), -bounds.fTop); |
| 160 if (SkScalarNearlyZero(biggestCoord)) | 160 if (SkScalarNearlyZero(biggestCoord)) |
| 161 return false; | 161 return false; |
| 162 biggestCoord = std::max(std::max(biggestCoord, fX + 1), fY + 1); | 162 biggestCoord = std::max(std::max(biggestCoord, fX + 1), fY + 1); |
| 163 | 163 |
| 164 const SkScalar kMaxCoordinate = SkIntToScalar(1 << 15); | 164 const SkScalar kMaxCoordinate = SkIntToScalar(1 << 15); |
| 165 SkScalar scale = SkScalarDiv(kMaxCoordinate, biggestCoord); | 165 SkScalar scale = SkScalarDiv(kMaxCoordinate, biggestCoord); |
| 166 | 166 |
| 167 SkRegion rgn; | 167 SkRegion rgn; |
| 168 SkRegion clip; | 168 SkRegion clip; |
| 169 SkMatrix m; | 169 SkMatrix m; |
| 170 SkPath scaledPath; | 170 SkPath scaledPath(originalPath); |
| 171 | 171 |
| 172 SkPath::FillType originalFillType = originalPath->getFillType(); | 172 scaledPath.setFillType(ft); |
| 173 originalPath->setFillType(ft); | |
| 174 | |
| 175 m.setScale(scale, scale); | 173 m.setScale(scale, scale); |
| 176 originalPath->transform(m, &scaledPath); | 174 scaledPath.transform(m, 0); |
|
pdr.
2013/07/23 00:27:21
Oh my, we create a transform just to scale the pat
| |
| 177 | 175 |
| 178 int x = static_cast<int>(floorf(0.5f + point.x() * scale)); | 176 int x = static_cast<int>(floorf(0.5f + point.x() * scale)); |
| 179 int y = static_cast<int>(floorf(0.5f + point.y() * scale)); | 177 int y = static_cast<int>(floorf(0.5f + point.y() * scale)); |
| 180 clip.setRect(x - 1, y - 1, x + 1, y + 1); | 178 clip.setRect(x - 1, y - 1, x + 1, y + 1); |
| 181 | 179 |
| 182 bool contains = rgn.setPath(scaledPath, clip); | 180 return rgn.setPath(scaledPath, clip); |
| 183 originalPath->setFillType(originalFillType); | |
| 184 return contains; | |
| 185 } | 181 } |
| 186 | 182 |
| 187 } // namespace WebCore | 183 } // namespace WebCore |
| OLD | NEW |