Skip to content

Commit 75040f8

Browse files
committed
Handle different x, y scales in drawLines AA path
bug:7114630 Fixes different x, y scales, and fixes boundaryWidthProportion to be from center, not edge. Also adds drawLine tests that previously drew blurry. Change-Id: I2b648a60361ad3931eac67647b9b27909525ee1e
1 parent 9147cd4 commit 75040f8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

libs/hwui/OpenGLRenderer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,10 @@ status_t OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
19781978

19791979
// Find the normal to the line
19801980
vec2 n = (b - a).copyNormalized() * halfStrokeWidth;
1981+
float x = n.x;
1982+
n.x = -n.y;
1983+
n.y = x;
1984+
19811985
if (isHairLine) {
19821986
if (isAA) {
19831987
float wideningFactor;
@@ -2002,14 +2006,10 @@ status_t OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
20022006

20032007
float extendedNLength = extendedN.length();
20042008
// We need to set this value on the shader prior to drawing
2005-
boundaryWidthProportion = extendedNLength / (halfStrokeWidth + extendedNLength);
2009+
boundaryWidthProportion = .5 - extendedNLength / (halfStrokeWidth + extendedNLength);
20062010
n += extendedN;
20072011
}
20082012

2009-
float x = n.x;
2010-
n.x = -n.y;
2011-
n.y = x;
2012-
20132013
// aa lines expand the endpoint vertices to encompass the AA boundary
20142014
if (isAA) {
20152015
vec2 abVector = (b - a);

tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ protected void onDraw(Canvas canvas) {
153153
canvas.drawLine(10.0f, 45.0f, 20.0f, 55.0f, mSmallPaint);
154154
canvas.drawLine(10.0f, 60.0f, 50.0f, 60.0f, mHairLinePaint);
155155
canvas.restore();
156+
157+
canvas.save();
158+
canvas.scale(10.0f, 50.0f);
159+
mSmallPaint.setStrokeWidth(0.0f);
160+
canvas.drawLine(20.0f, 9.0f, 30.0f, 11.0f, mSmallPaint);
161+
mSmallPaint.setStrokeWidth(1.0f);
162+
canvas.drawLine(30.0f, 9.0f, 40.0f, 11.0f, mSmallPaint);
163+
canvas.restore();
156164
}
157165
}
158166
}

0 commit comments

Comments
 (0)