| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/graphics/skia/SkiaUtils.h" | 32 #include "platform/graphics/skia/SkiaUtils.h" |
| 33 | 33 |
| 34 #include "platform/graphics/GraphicsContext.h" | 34 #include "platform/graphics/GraphicsContext.h" |
| 35 #include "third_party/skia/include/core/SkRegion.h" | |
| 36 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 35 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
| 37 | 36 |
| 38 namespace blink { | 37 namespace blink { |
| 39 | 38 |
| 40 static const struct CompositOpToXfermodeMode { | 39 static const struct CompositOpToXfermodeMode { |
| 41 CompositeOperator mCompositOp; | 40 CompositeOperator mCompositOp; |
| 42 SkXfermode::Mode m_xfermodeMode; | 41 SkXfermode::Mode m_xfermodeMode; |
| 43 } gMapCompositOpsToXfermodeModes[] = { | 42 } gMapCompositOpsToXfermodeModes[] = { |
| 44 { CompositeClear, SkXfermode::kClear_Mode }, | 43 { CompositeClear, SkXfermode::kClear_Mode }, |
| 45 { CompositeCopy, SkXfermode::kSrc_Mode }, | 44 { CompositeCopy, SkXfermode::kSrc_Mode }, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 case SkXfermode::kColor_Mode: | 161 case SkXfermode::kColor_Mode: |
| 163 return WebBlendModeColor; | 162 return WebBlendModeColor; |
| 164 case SkXfermode::kLuminosity_Mode: | 163 case SkXfermode::kLuminosity_Mode: |
| 165 return WebBlendModeLuminosity; | 164 return WebBlendModeLuminosity; |
| 166 default: | 165 default: |
| 167 break; | 166 break; |
| 168 } | 167 } |
| 169 return WebBlendModeNormal; | 168 return WebBlendModeNormal; |
| 170 } | 169 } |
| 171 | 170 |
| 172 bool SkPathContainsPoint(const SkPath& originalPath, const FloatPoint& point, Sk
Path::FillType ft) | |
| 173 { | |
| 174 SkRect bounds = originalPath.getBounds(); | |
| 175 | |
| 176 // We can immediately return false if the point is outside the bounding | |
| 177 // rect. We don't use bounds.contains() here, since it would exclude | |
| 178 // points on the right and bottom edges of the bounding rect, and we want | |
| 179 // to include them. | |
| 180 SkScalar fX = SkFloatToScalar(point.x()); | |
| 181 SkScalar fY = SkFloatToScalar(point.y()); | |
| 182 if (fX < bounds.fLeft || fX > bounds.fRight || fY < bounds.fTop || fY > boun
ds.fBottom) | |
| 183 return false; | |
| 184 | |
| 185 // Scale the path to a large size before hit testing for two reasons: | |
| 186 // 1) Skia has trouble with coordinates close to the max signed 16-bit value
s, so we scale larger paths down. | |
| 187 // TODO: when Skia is patched to work properly with large values, this wi
ll not be necessary. | |
| 188 // 2) Skia does not support analytic hit testing, so we scale paths up to do
raster hit testing with subpixel accuracy. | |
| 189 // 3) Scale the x/y axis separately so an extreme large/small scale factor o
n one axis won't | |
| 190 // ruin the resolution of the other axis. | |
| 191 SkScalar biggestCoordX = std::max(bounds.fRight, -bounds.fLeft); | |
| 192 SkScalar biggestCoordY = std::max(bounds.fBottom, -bounds.fTop); | |
| 193 if (SkScalarNearlyZero(biggestCoordX) || SkScalarNearlyZero(biggestCoordY)) | |
| 194 return false; | |
| 195 | |
| 196 biggestCoordX = std::max(biggestCoordX, std::fabs(fX) + 1); | |
| 197 biggestCoordY = std::max(biggestCoordY, std::fabs(fY) + 1); | |
| 198 | |
| 199 const SkScalar kMaxCoordinate = SkIntToScalar(1 << 15); | |
| 200 SkScalar scaleX = kMaxCoordinate / biggestCoordX; | |
| 201 SkScalar scaleY = kMaxCoordinate / biggestCoordY; | |
| 202 | |
| 203 SkRegion rgn; | |
| 204 SkRegion clip; | |
| 205 SkMatrix m; | |
| 206 SkPath scaledPath(originalPath); | |
| 207 | |
| 208 scaledPath.setFillType(ft); | |
| 209 m.setScale(scaleX, scaleY); | |
| 210 scaledPath.transform(m, 0); | |
| 211 | |
| 212 int x = static_cast<int>(floorf(0.5f + point.x() * scaleX)); | |
| 213 int y = static_cast<int>(floorf(0.5f + point.y() * scaleY)); | |
| 214 clip.setRect(x - 1, y - 1, x + 1, y + 1); | |
| 215 | |
| 216 return rgn.setPath(scaledPath, clip); | |
| 217 } | |
| 218 | |
| 219 SkMatrix affineTransformToSkMatrix(const AffineTransform& source) | 171 SkMatrix affineTransformToSkMatrix(const AffineTransform& source) |
| 220 { | 172 { |
| 221 SkMatrix result; | 173 SkMatrix result; |
| 222 | 174 |
| 223 result.setScaleX(WebCoreDoubleToSkScalar(source.a())); | 175 result.setScaleX(WebCoreDoubleToSkScalar(source.a())); |
| 224 result.setSkewX(WebCoreDoubleToSkScalar(source.c())); | 176 result.setSkewX(WebCoreDoubleToSkScalar(source.c())); |
| 225 result.setTranslateX(WebCoreDoubleToSkScalar(source.e())); | 177 result.setTranslateX(WebCoreDoubleToSkScalar(source.e())); |
| 226 | 178 |
| 227 result.setScaleY(WebCoreDoubleToSkScalar(source.d())); | 179 result.setScaleY(WebCoreDoubleToSkScalar(source.d())); |
| 228 result.setSkewY(WebCoreDoubleToSkScalar(source.b())); | 180 result.setSkewY(WebCoreDoubleToSkScalar(source.b())); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 paint.setAlpha(128); | 347 paint.setAlpha(128); |
| 396 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); | 348 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); |
| 397 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); | 349 drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
| 398 #endif | 350 #endif |
| 399 } | 351 } |
| 400 | 352 |
| 401 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, SkCan
vas*, SkColor, int width); | 353 template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, SkCan
vas*, SkColor, int width); |
| 402 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, SkCan
vas*, SkColor, int width); | 354 template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, SkCan
vas*, SkColor, int width); |
| 403 | 355 |
| 404 } // namespace blink | 356 } // namespace blink |
| OLD | NEW |