summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-04-04 11:53:28 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-04 11:53:28 -0700
commitfda531c9e4e49cfd962d3784b3501f6a1e64dc22 (patch)
tree87adda86eddc128b9b4ec4ea917cd37323a94c07 /libs
parent30bd284cca7540be3eba2e7874a2c69e051771ce (diff)
parent7b63142d2f4bc32beacedcc761453b8aea1f3a86 (diff)
downloadframeworks_base-fda531c9e4e49cfd962d3784b3501f6a1e64dc22.zip
frameworks_base-fda531c9e4e49cfd962d3784b3501f6a1e64dc22.tar.gz
frameworks_base-fda531c9e4e49cfd962d3784b3501f6a1e64dc22.tar.bz2
Merge "Disable AA lines vertex attrib arrays after rendering"
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/OpenGLRenderer.cpp61
-rw-r--r--libs/hwui/OpenGLRenderer.h3
2 files changed, 56 insertions, 8 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 216c451..39d2e39 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1328,18 +1328,18 @@ void OpenGLRenderer::setupDrawVertices(GLvoid* vertices) {
* are set up for each individual segment.
*/
void OpenGLRenderer::setupDrawAALine(GLvoid* vertices, GLvoid* widthCoords,
- GLvoid* lengthCoords, float boundaryWidthProportion) {
+ GLvoid* lengthCoords, float boundaryWidthProportion, int& widthSlot, int& lengthSlot) {
bool force = mCaches.unbindMeshBuffer();
mCaches.bindPositionVertexPointer(force, mCaches.currentProgram->position,
vertices, gAAVertexStride);
mCaches.resetTexCoordsVertexPointer();
mCaches.unbindIndicesBuffer();
- int widthSlot = mCaches.currentProgram->getAttrib("vtxWidth");
+ widthSlot = mCaches.currentProgram->getAttrib("vtxWidth");
glEnableVertexAttribArray(widthSlot);
glVertexAttribPointer(widthSlot, 1, GL_FLOAT, GL_FALSE, gAAVertexStride, widthCoords);
- int lengthSlot = mCaches.currentProgram->getAttrib("vtxLength");
+ lengthSlot = mCaches.currentProgram->getAttrib("vtxLength");
glEnableVertexAttribArray(lengthSlot);
glVertexAttribPointer(lengthSlot, 1, GL_FLOAT, GL_FALSE, gAAVertexStride, lengthCoords);
@@ -1348,7 +1348,12 @@ void OpenGLRenderer::setupDrawAALine(GLvoid* vertices, GLvoid* widthCoords,
// Setting the inverse value saves computations per-fragment in the shader
int inverseBoundaryWidthSlot = mCaches.currentProgram->getUniform("inverseBoundaryWidth");
- glUniform1f(inverseBoundaryWidthSlot, (1 / boundaryWidthProportion));
+ glUniform1f(inverseBoundaryWidthSlot, 1.0f / boundaryWidthProportion);
+}
+
+void OpenGLRenderer::finishDrawAALine(const int widthSlot, const int lengthSlot) {
+ glDisableVertexAttribArray(widthSlot);
+ glDisableVertexAttribArray(lengthSlot);
}
void OpenGLRenderer::finishDrawTexture() {
@@ -1720,13 +1725,18 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
float width = right - left;
float height = bottom - top;
+ int widthSlot;
+ int lengthSlot;
+
float boundaryWidthProportion = (width != 0) ? (2 * boundarySizeX) / width : 0;
float boundaryHeightProportion = (height != 0) ? (2 * boundarySizeY) / height : 0;
- setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords, boundaryWidthProportion);
+ setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords,
+ boundaryWidthProportion, widthSlot, lengthSlot);
+
int boundaryLengthSlot = mCaches.currentProgram->getUniform("boundaryLength");
int inverseBoundaryLengthSlot = mCaches.currentProgram->getUniform("inverseBoundaryLength");
glUniform1f(boundaryLengthSlot, boundaryHeightProportion);
- glUniform1f(inverseBoundaryLengthSlot, (1 / boundaryHeightProportion));
+ glUniform1f(inverseBoundaryLengthSlot, (1.0f / boundaryHeightProportion));
if (!quickReject(left, top, right, bottom)) {
AAVertex::set(aaVertices++, left, bottom, 1, 1);
@@ -1736,6 +1746,8 @@ void OpenGLRenderer::drawAARect(float left, float top, float right, float bottom
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
+
+ finishDrawAALine(widthSlot, lengthSlot);
}
/**
@@ -1766,11 +1778,14 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
// A stroke width of 0 has a special meaning in Skia:
// it draws a line 1 px wide regardless of current transform
bool isHairLine = paint->getStrokeWidth() == 0.0f;
+
float inverseScaleX = 1.0f;
float inverseScaleY = 1.0f;
bool scaled = false;
+
int alpha;
SkXfermode::Mode mode;
+
int generatedVerticesCount = 0;
int verticesCount = count;
if (count > 4) {
@@ -1790,10 +1805,13 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
float m10 = mat->data[Matrix4::kSkewX];
float m11 = mat->data[Matrix4::kScaleX];
float m12 = mat->data[6];
+
float scaleX = sqrtf(m00 * m00 + m01 * m01);
float scaleY = sqrtf(m10 * m10 + m11 * m11);
+
inverseScaleX = (scaleX != 0) ? (inverseScaleX / scaleX) : 0;
inverseScaleY = (scaleY != 0) ? (inverseScaleY / scaleY) : 0;
+
if (inverseScaleX != 1.0f || inverseScaleY != 1.0f) {
scaled = true;
}
@@ -1823,10 +1841,16 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
// Expand boundary to enable AA calculations on the quad border
halfStrokeWidth += .5f;
}
+
+ int widthSlot;
+ int lengthSlot;
+
Vertex lines[verticesCount];
Vertex* vertices = &lines[0];
+
AAVertex wLines[verticesCount];
AAVertex* aaVertices = &wLines[0];
+
if (CC_UNLIKELY(!isAA)) {
setupDrawVertices(vertices);
} else {
@@ -1838,7 +1862,8 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
// We will need to calculate the actual width proportion on each segment for
// scaled non-hairlines, since the boundary proportion may differ per-axis when scaled.
float boundaryWidthProportion = 1 / (2 * halfStrokeWidth);
- setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords, boundaryWidthProportion);
+ setupDrawAALine((void*) aaVertices, widthCoords, lengthCoords,
+ boundaryWidthProportion, widthSlot, lengthSlot);
}
AAVertex* prevAAVertex = NULL;
@@ -1848,10 +1873,12 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
int inverseBoundaryLengthSlot = -1;
int boundaryWidthSlot = -1;
int inverseBoundaryWidthSlot = -1;
+
for (int i = 0; i < count; i += 4) {
// a = start point, b = end point
vec2 a(points[i], points[i + 1]);
vec2 b(points[i + 2], points[i + 3]);
+
float length = 0;
float boundaryLengthProportion = 0;
float boundaryWidthProportion = 0;
@@ -1868,6 +1895,7 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
}
n *= wideningFactor;
}
+
if (scaled) {
n.x *= inverseScaleX;
n.y *= inverseScaleY;
@@ -1878,11 +1906,13 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
extendedN /= 2;
extendedN.x *= inverseScaleX;
extendedN.y *= inverseScaleY;
+
float extendedNLength = extendedN.length();
// We need to set this value on the shader prior to drawing
boundaryWidthProportion = extendedNLength / (halfStrokeWidth + extendedNLength);
n += extendedN;
}
+
float x = n.x;
n.x = -n.y;
n.y = x;
@@ -1892,6 +1922,7 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
vec2 abVector = (b - a);
length = abVector.length();
abVector.normalize();
+
if (scaled) {
abVector.x *= inverseScaleX;
abVector.y *= inverseScaleY;
@@ -1900,6 +1931,7 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
} else {
boundaryLengthProportion = .5 / (length + 1);
}
+
abVector /= 2;
a -= abVector;
b += abVector;
@@ -1928,10 +1960,12 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
Vertex::set(vertices++, p1.x, p1.y);
generatedVerticesCount += 2;
}
+
Vertex::set(vertices++, p1.x, p1.y);
Vertex::set(vertices++, p2.x, p2.y);
Vertex::set(vertices++, p4.x, p4.y);
Vertex::set(vertices++, p3.x, p3.y);
+
prevVertex = vertices - 1;
generatedVerticesCount += 4;
} else {
@@ -1944,14 +1978,17 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
inverseBoundaryWidthSlot =
mCaches.currentProgram->getUniform("inverseBoundaryWidth");
}
+
glUniform1f(boundaryWidthSlot, boundaryWidthProportion);
glUniform1f(inverseBoundaryWidthSlot, (1 / boundaryWidthProportion));
}
+
if (boundaryLengthSlot < 0) {
boundaryLengthSlot = mCaches.currentProgram->getUniform("boundaryLength");
inverseBoundaryLengthSlot =
mCaches.currentProgram->getUniform("inverseBoundaryLength");
}
+
glUniform1f(boundaryLengthSlot, boundaryLengthProportion);
glUniform1f(inverseBoundaryLengthSlot, (1 / boundaryLengthProportion));
@@ -1965,21 +2002,29 @@ void OpenGLRenderer::drawLines(float* points, int count, SkPaint* paint) {
AAVertex::set(aaVertices++, p4.x, p4.y, 1, 1);
generatedVerticesCount += 2;
}
+
AAVertex::set(aaVertices++, p4.x, p4.y, 1, 1);
AAVertex::set(aaVertices++, p1.x, p1.y, 1, 0);
AAVertex::set(aaVertices++, p3.x, p3.y, 0, 1);
AAVertex::set(aaVertices++, p2.x, p2.y, 0, 0);
+
prevAAVertex = aaVertices - 1;
generatedVerticesCount += 4;
}
+
dirtyLayer(a.x == b.x ? left - 1 : left, a.y == b.y ? top - 1 : top,
a.x == b.x ? right: right, a.y == b.y ? bottom: bottom,
*mSnapshot->transform);
}
}
+
if (generatedVerticesCount > 0) {
glDrawArrays(GL_TRIANGLE_STRIP, 0, generatedVerticesCount);
}
+
+ if (isAA) {
+ finishDrawAALine(widthSlot, lengthSlot);
+ }
}
void OpenGLRenderer::drawPoints(float* points, int count, SkPaint* paint) {
@@ -2025,10 +2070,12 @@ void OpenGLRenderer::drawPoints(float* points, int count, SkPaint* paint) {
for (int i = 0; i < count; i += 2) {
TextureVertex::set(vertex++, points[i], points[i + 1], 0.0f, 0.0f);
generatedVerticesCount++;
+
float left = points[i] - halfWidth;
float right = points[i] + halfWidth;
float top = points[i + 1] - halfWidth;
float bottom = points [i + 1] + halfWidth;
+
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
}
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index ab137cc..b52d2b0 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -553,7 +553,8 @@ private:
void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords);
void setupDrawVertices(GLvoid* vertices);
void setupDrawAALine(GLvoid* vertices, GLvoid* distanceCoords, GLvoid* lengthCoords,
- float strokeWidth);
+ float strokeWidth, int& widthSlot, int& lengthSlot);
+ void finishDrawAALine(const int widthSlot, const int lengthSlot);
void finishDrawTexture();
void accountForClear(SkXfermode::Mode mode);