Disable GPU acceleration for narrow ovals.
GPU anti-aliasing is currently not correct for ellipses where the ratio of long
axis length to short axis length is greater than 2 (see
https://code.google.com/p/skia/issues/detail?id=1249). This disables the GPU
path for those cases.
Review URL: https://codereview.chromium.org/13925015/
git-svn-id: http://skia.googlecode.com/svn/trunk@8694 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrOvalRenderer.h b/include/gpu/GrOvalRenderer.h
index 88dd0a4..7e46dac 100644
--- a/include/gpu/GrOvalRenderer.h
+++ b/include/gpu/GrOvalRenderer.h
@@ -33,7 +33,7 @@
bool drawOval(GrDrawTarget* target, const GrContext* context, const GrPaint& paint,
const GrRect& oval, const SkStrokeRec& stroke);
private:
- void drawEllipse(GrDrawTarget* target, const GrPaint& paint,
+ bool drawEllipse(GrDrawTarget* target, const GrPaint& paint,
const GrRect& ellipse,
const SkStrokeRec& stroke);
void drawCircle(GrDrawTarget* target, const GrPaint& paint,
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index 71052bc..ff468fd 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -297,7 +297,7 @@
// and axis-aligned ellipses only
} else if (vm.rectStaysRect()) {
- drawEllipse(target, paint, oval, stroke);
+ return drawEllipse(target, paint, oval, stroke);
} else {
return false;
@@ -406,7 +406,7 @@
target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds);
}
-void GrOvalRenderer::drawEllipse(GrDrawTarget* target,
+bool GrOvalRenderer::drawEllipse(GrDrawTarget* target,
const GrPaint& paint,
const GrRect& ellipse,
const SkStrokeRec& stroke)
@@ -425,10 +425,15 @@
vm.mapPoints(¢er, 1);
SkRect xformedRect;
vm.mapRect(&xformedRect, ellipse);
+ SkScalar xRadius = SkScalarHalf(xformedRect.width());
+ SkScalar yRadius = SkScalarHalf(xformedRect.height());
+ if (SkScalarDiv(xRadius, yRadius) > 2 || SkScalarDiv(yRadius, xRadius) > 2) {
+ return false;
+ }
GrDrawState::AutoDeviceCoordDraw adcd(drawState);
if (!adcd.succeeded()) {
- return;
+ return false;
}
// position + edge
@@ -443,7 +448,7 @@
GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
- return;
+ return false;
}
EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(geo.vertices());
@@ -463,8 +468,6 @@
drawState->setEffect(kEdgeEffectStage, effect,
kEllipseCenterAttrIndex, kEllipseEdgeAttrIndex)->unref();
- SkScalar xRadius = SkScalarHalf(xformedRect.width());
- SkScalar yRadius = SkScalarHalf(xformedRect.height());
SkScalar innerXRadius = 0.0f;
SkScalar innerRatio = 1.0f;
@@ -538,4 +541,6 @@
verts[3].fInnerOffset = SkPoint::Make(xRadius, innerRatio*yRadius);
target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, 4, &bounds);
+
+ return true;
}