Index: Source/platform/graphics/skia/SkiaUtils.cpp |
diff --git a/Source/platform/graphics/skia/SkiaUtils.cpp b/Source/platform/graphics/skia/SkiaUtils.cpp |
index 0abeb31c85df163d69304e29a81d8b3e93bd60a4..fb28dea9c101ba5b2b87879720b333019d833263 100644 |
--- a/Source/platform/graphics/skia/SkiaUtils.cpp |
+++ b/Source/platform/graphics/skia/SkiaUtils.cpp |
@@ -330,36 +330,6 @@ InterpolationQuality computeInterpolationQuality( |
return InterpolationLow; |
} |
- |
-bool shouldDrawAntiAliased(const GraphicsContext* context, const SkRect& destRect) |
-{ |
- if (!context->shouldAntialias()) |
- return false; |
- const SkMatrix totalMatrix = context->getTotalMatrix(); |
- // Don't disable anti-aliasing if we're rotated or skewed. |
- if (!totalMatrix.rectStaysRect()) |
- return true; |
- // Disable anti-aliasing for scales or n*90 degree rotations. |
- // Allow to opt out of the optimization though for "hairline" geometry |
- // images - using the shouldAntialiasHairlineImages() GraphicsContext flag. |
- if (!context->shouldAntialiasHairlineImages()) |
- return false; |
- // Check if the dimensions of the destination are "small" (less than one |
- // device pixel). To prevent sudden drop-outs. Since we know that |
- // kRectStaysRect_Mask is set, the matrix either has scale and no skew or |
- // vice versa. We can query the kAffine_Mask flag to determine which case |
- // it is. |
- // FIXME: This queries the CTM while drawing, which is generally |
- // discouraged. Always drawing with AA can negatively impact performance |
- // though - that's why it's not always on. |
- SkScalar widthExpansion, heightExpansion; |
- if (totalMatrix.getType() & SkMatrix::kAffine_Mask) |
- widthExpansion = totalMatrix[SkMatrix::kMSkewY], heightExpansion = totalMatrix[SkMatrix::kMSkewX]; |
- else |
- widthExpansion = totalMatrix[SkMatrix::kMScaleX], heightExpansion = totalMatrix[SkMatrix::kMScaleY]; |
- return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fabs(heightExpansion) < 1; |
-} |
- |
int clampedAlphaForBlending(float alpha) |
{ |
if (alpha < 0) |
@@ -381,4 +351,56 @@ SkColor scaleAlpha(SkColor color, int alpha) |
return (color & 0x00FFFFFF) | (a << 24); |
} |
+template<typename PrimitiveType> |
+void drawFocusRingPrimitive(const PrimitiveType&, SkCanvas*, const SkPaint&, float cornerRadius) |
+{ |
+ ASSERT_NOT_REACHED(); // Missing an explicit specialization? |
+} |
+ |
+template<> |
+void drawFocusRingPrimitive<SkRect>(const SkRect& rect, SkCanvas* canvas, const SkPaint& paint, float cornerRadius) |
+{ |
+ SkRRect rrect; |
+ rrect.setRectXY(rect, SkFloatToScalar(cornerRadius), SkFloatToScalar(cornerRadius)); |
+ canvas->drawRRect(rrect, paint); |
+} |
+ |
+template<> |
+void drawFocusRingPrimitive<SkPath>(const SkPath& path, SkCanvas* canvas, const SkPaint& paint, float cornerRadius) |
+{ |
+ SkPaint pathPaint = paint; |
+ pathPaint.setPathEffect(SkCornerPathEffect::Create(SkFloatToScalar(cornerRadius)))->unref(); |
+ canvas->drawPath(path, pathPaint); |
+} |
+ |
+template<typename PrimitiveType> |
+void drawPlatformFocusRing(const PrimitiveType& primitive, SkCanvas* canvas, SkColor color, int width) |
+{ |
+ SkPaint paint; |
+ paint.setAntiAlias(true); |
+ paint.setStyle(SkPaint::kStroke_Style); |
+ paint.setColor(color); |
+ |
+#if OS(MACOSX) |
+ paint.setStrokeWidth(width); |
+ paint.setAlpha(64); |
+ float cornerRadius = (width - 1) * 0.5f; |
+#else |
+ paint.setStrokeWidth(1); |
+ const float cornerRadius = 1; |
+#endif |
+ |
+ drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
+ |
+#if OS(MACOSX) |
+ // Inner part |
+ paint.setAlpha(128); |
+ paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); |
+ drawFocusRingPrimitive(primitive, canvas, paint, cornerRadius); |
+#endif |
+} |
+ |
+template void PLATFORM_EXPORT drawPlatformFocusRing<SkRect>(const SkRect&, SkCanvas*, SkColor, int width); |
+template void PLATFORM_EXPORT drawPlatformFocusRing<SkPath>(const SkPath&, SkCanvas*, SkColor, int width); |
+ |
} // namespace blink |