Skip to content

Commit 0429938

Browse files
author
Romain Guy
committed
Clip lines, AA rects and points correctly
Change-Id: I900dd986f397b66f133e6021aa4c2539e7abc2b9
1 parent dfab50d commit 0429938

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

libs/hwui/OpenGLRenderer.cpp

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,7 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17831783
int color, SkXfermode::Mode mode) {
17841784
float inverseScaleX = 1.0f;
17851785
float inverseScaleY = 1.0f;
1786+
17861787
// The quad that we use needs to account for scaling.
17871788
if (CC_UNLIKELY(!mSnapshot->transform->isPureTranslate())) {
17881789
Matrix4 *mat = mSnapshot->transform;
@@ -1798,24 +1799,6 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
17981799
inverseScaleY = (scaleY != 0) ? (inverseScaleY / scaleY) : 0;
17991800
}
18001801

1801-
setupDraw();
1802-
setupDrawNoTexture();
1803-
setupDrawAALine();
1804-
setupDrawColor(color, ((color >> 24) & 0xFF) * mSnapshot->alpha);
1805-
setupDrawColorFilter();
1806-
setupDrawShader();
1807-
setupDrawBlending(true, mode);
1808-
setupDrawProgram();
1809-
setupDrawModelViewIdentity(true);
1810-
setupDrawColorUniforms();
1811-
setupDrawColorFilterUniforms();
1812-
setupDrawShaderIdentityUniforms();
1813-
1814-
AAVertex rects[4];
1815-
AAVertex* aaVertices = &rects[0];
1816-
void* widthCoords = ((GLbyte*) aaVertices) + gVertexAAWidthOffset;
1817-
void* lengthCoords = ((GLbyte*) aaVertices) + gVertexAALengthOffset;
1818-
18191802
float boundarySizeX = .5 * inverseScaleX;
18201803
float boundarySizeY = .5 * inverseScaleY;
18211804

@@ -1825,32 +1808,51 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
18251808
top -= boundarySizeY;
18261809
bottom += boundarySizeY;
18271810

1828-
float width = right - left;
1829-
float height = bottom - top;
1811+
if (!quickReject(left, top, right, bottom)) {
1812+
setupDraw();
1813+
setupDrawNoTexture();
1814+
setupDrawAALine();
1815+
setupDrawColor(color, ((color >> 24) & 0xFF) * mSnapshot->alpha);
1816+
setupDrawColorFilter();
1817+
setupDrawShader();
1818+
setupDrawBlending(true, mode);
1819+
setupDrawProgram();
1820+
setupDrawModelViewIdentity(true);
1821+
setupDrawColorUniforms();
1822+
setupDrawColorFilterUniforms();
1823+
setupDrawShaderIdentityUniforms();
1824+
1825+
AAVertex rects[4];
1826+
AAVertex* aaVertices = &rects[0];
1827+
void* widthCoords = ((GLbyte*) aaVertices) + gVertexAAWidthOffset;
1828+
void* lengthCoords = ((GLbyte*) aaVertices) + gVertexAALengthOffset;
18301829

1831-
int widthSlot;
1832-
int lengthSlot;
1830+
int widthSlot;
1831+
int lengthSlot;
18331832

1834-
float boundaryWidthProportion = (width != 0) ? (2 * boundarySizeX) / width : 0;
1835-
float boundaryHeightProportion = (height != 0) ? (2 * boundarySizeY) / height : 0;
1836-
setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords,
1837-
boundaryWidthProportion, widthSlot, lengthSlot);
1833+
float width = right - left;
1834+
float height = bottom - top;
18381835

1839-
int boundaryLengthSlot = mCaches.currentProgram->getUniform("boundaryLength");
1840-
int inverseBoundaryLengthSlot = mCaches.currentProgram->getUniform("inverseBoundaryLength");
1841-
glUniform1f(boundaryLengthSlot, boundaryHeightProportion);
1842-
glUniform1f(inverseBoundaryLengthSlot, (1.0f / boundaryHeightProportion));
1836+
float boundaryWidthProportion = (width != 0) ? (2 * boundarySizeX) / width : 0;
1837+
float boundaryHeightProportion = (height != 0) ? (2 * boundarySizeY) / height : 0;
1838+
setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords,
1839+
boundaryWidthProportion, widthSlot, lengthSlot);
1840+
1841+
int boundaryLengthSlot = mCaches.currentProgram->getUniform("boundaryLength");
1842+
int inverseBoundaryLengthSlot = mCaches.currentProgram->getUniform("inverseBoundaryLength");
1843+
glUniform1f(boundaryLengthSlot, boundaryHeightProportion);
1844+
glUniform1f(inverseBoundaryLengthSlot, (1.0f / boundaryHeightProportion));
18431845

1844-
if (!quickReject(left, top, right, bottom)) {
18451846
AAVertex::set(aaVertices++, left, bottom, 1, 1);
18461847
AAVertex::set(aaVertices++, left, top, 1, 0);
18471848
AAVertex::set(aaVertices++, right, bottom, 0, 1);
18481849
AAVertex::set(aaVertices++, right, top, 0, 0);
18491850
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
1851+
18501852
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
1851-
}
18521853

1853-
finishDrawAALine(widthSlot, lengthSlot);
1854+
finishDrawAALine(widthSlot, lengthSlot);
1855+
}
18541856
}
18551857

18561858
/**
@@ -1922,6 +1924,9 @@ status_t OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
19221924
}
19231925

19241926
getAlphaAndMode(paint, &alpha, &mode);
1927+
1928+
mCaches.enableScissor();
1929+
19251930
setupDraw();
19261931
setupDrawNoTexture();
19271932
if (isAA) {
@@ -2052,7 +2057,7 @@ status_t OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
20522057
const float top = fmin(p1.y, fmin(p2.y, fmin(p3.y, p4.y)));
20532058
const float bottom = fmax(p1.y, fmax(p2.y, fmax(p3.y, p4.y)));
20542059

2055-
if (!quickReject(left, top, right, bottom)) {
2060+
if (!quickRejectNoScissor(left, top, right, bottom)) {
20562061
if (!isAA) {
20572062
if (prevVertex != NULL) {
20582063
// Issue two repeat vertices to create degenerate triangles to bridge
@@ -2157,6 +2162,10 @@ status_t OpenGLRenderer::drawPoints(float* points, int count, SkPaint* paint) {
21572162
TextureVertex pointsData[verticesCount];
21582163
TextureVertex* vertex = &pointsData[0];
21592164

2165+
// TODO: We should optimize this method to not generate vertices for points
2166+
// that lie outside of the clip.
2167+
mCaches.enableScissor();
2168+
21602169
setupDraw();
21612170
setupDrawNoTexture();
21622171
setupDrawPoint(strokeWidth);

0 commit comments

Comments
 (0)