diff options
author | Romain Guy <romainguy@google.com> | 2010-09-17 15:31:32 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2010-09-17 15:31:32 -0700 |
commit | c95c8d6bf8fda5c4e8ebd0033b789be7868e6e07 (patch) | |
tree | 3f5a4ca860841db0de4678065d6f392590749780 /libs | |
parent | 31529ff7918ce891fba9a660d0a861eb313ea554 (diff) | |
download | frameworks_base-c95c8d6bf8fda5c4e8ebd0033b789be7868e6e07.zip frameworks_base-c95c8d6bf8fda5c4e8ebd0033b789be7868e6e07.tar.gz frameworks_base-c95c8d6bf8fda5c4e8ebd0033b789be7868e6e07.tar.bz2 |
Add support for non AA lines.
Change-Id: Id5200e94815404d62760437d0d2dbb0a9276c700
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/Line.h | 8 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 42 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h | 6 |
3 files changed, 44 insertions, 12 deletions
diff --git a/libs/hwui/Line.h b/libs/hwui/Line.h index 75f3321e..820793c 100644 --- a/libs/hwui/Line.h +++ b/libs/hwui/Line.h @@ -80,8 +80,12 @@ public: glDeleteTextures(1, &mTexture); } + inline float getLength(float x1, float y1, float x2, float y2) { + return sqrtf((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); + } + void update(float x1, float y1, float x2, float y2, float lineWidth, float& tx, float& ty) { - const float length = sqrtf((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); + const float length = getLength(x1, y1, x2, y2); const float half = lineWidth * 0.5f; mPatch->updateVertices(gLineTextureWidth, gLineTextureHeight, @@ -89,7 +93,7 @@ public: mXDivs, mYDivs, mXDivsCount, mYDivsCount); tx = -gLineAABias; - ty = -half - gLineAABias; + ty = lineWidth == 1.0f ? -gLineAABias : -half - gLineAABias; } inline GLvoid* getVertices() const { diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index ecc02fa..eb85169 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -612,16 +612,29 @@ void OpenGLRenderer::drawLines(float* points, int count, const SkPaint* paint) { const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f; const GLfloat b = a * ((color ) & 0xFF) / 255.0f; - GLuint textureUnit = 0; - setupTextureAlpha8(mLine.getTexture(), 0, 0, textureUnit, 0.0f, 0.0f, r, g, b, a, - mode, false, true, mLine.getVertices(), mLine.getTexCoords()); + const bool isAA = paint->isAntiAlias(); + if (isAA) { + GLuint textureUnit = 0; + setupTextureAlpha8(mLine.getTexture(), 0, 0, textureUnit, 0.0f, 0.0f, r, g, b, a, + mode, false, true, mLine.getVertices(), mLine.getTexCoords()); + } else { + setupColorRect(0.0f, 0.0f, 1.0f, 1.0f, r, g, b, a, mode, false); + } + + const float strokeWidth = paint->getStrokeWidth(); + const GLsizei elementsCount = isAA ? mLine.getElementsCount() : gMeshCount; + const GLenum drawMode = isAA ? GL_TRIANGLES : GL_TRIANGLE_STRIP; for (int i = 0; i < count; i += 4) { float tx = 0.0f; float ty = 0.0f; - mLine.update(points[i], points[i + 1], points[i + 2], points[i + 3], - paint->getStrokeWidth(), tx, ty); + if (isAA) { + mLine.update(points[i], points[i + 1], points[i + 2], points[i + 3], + strokeWidth, tx, ty); + } else { + ty = -strokeWidth * 0.5f; + } const float dx = points[i + 2] - points[i]; const float dy = points[i + 3] - points[i + 1]; @@ -633,13 +646,17 @@ void OpenGLRenderer::drawLines(float* points, int count, const SkPaint* paint) { mModelView.rotate(angle * RAD_TO_DEG, 0.0f, 0.0f, 1.0f); } mModelView.translate(tx, ty, 0.0f); + if (!isAA) { + float length = mLine.getLength(points[i], points[i + 1], points[i + 2], points[i + 3]); + mModelView.scale(length, strokeWidth, 1.0f); + } mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform); if (mShader) { mShader->updateTransforms(mCaches.currentProgram, mModelView, *mSnapshot); } - glDrawArrays(GL_TRIANGLES, 0, mLine.getElementsCount()); + glDrawArrays(drawMode, 0, elementsCount); } glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords")); @@ -978,6 +995,14 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f; const GLfloat b = a * ((color ) & 0xFF) / 255.0f; + setupColorRect(left, top, right, bottom, r, g, b, a, mode, ignoreTransform); + + // Draw the mesh + glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); +} + +void OpenGLRenderer::setupColorRect(float left, float top, float right, float bottom, + float r, float g, float b, float a, SkXfermode::Mode mode, bool ignoreTransform) { GLuint textureUnit = 0; // Describe the required shaders @@ -990,7 +1015,7 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot } // Setup the blending mode - chooseBlending(alpha < 255 || (mShader && mShader->blend()), mode, description); + chooseBlending(a < 1.0f || (mShader && mShader->blend()), mode, description); // Build and use the appropriate shader useProgram(mCaches.programCache.get(description)); @@ -1017,9 +1042,6 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot if (mColorFilter) { mColorFilter->setupProgram(mCaches.currentProgram); } - - // Draw the mesh - glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); } void OpenGLRenderer::drawTextureRect(float left, float top, float right, float bottom, diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index cd7963f..eba0f41 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -189,6 +189,12 @@ private: int color, SkXfermode::Mode mode, bool ignoreTransform = false); /** + * Setups shaders to draw a colored rect. + */ + void setupColorRect(float left, float top, float right, float bottom, + float r, float g, float b, float a, SkXfermode::Mode mode, bool ignoreTransform); + + /** * Draws a textured rectangle with the specified texture. The specified coordinates * are transformed by the current snapshot's transform matrix. * |