summaryrefslogtreecommitdiffstats
path: root/libs/hwui/OpenGLRenderer.cpp
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2010-07-20 13:09:13 -0700
committerRomain Guy <romainguy@google.com>2010-07-20 16:37:27 -0700
commita1db574036c9bc2d397b69f8200594027e1fff16 (patch)
treeece6071cd30838075c334e6b2eda391af45c0f12 /libs/hwui/OpenGLRenderer.cpp
parentc0ac193b9415680f0a69e20a3f5f22d16f8053be (diff)
downloadframeworks_base-a1db574036c9bc2d397b69f8200594027e1fff16.zip
frameworks_base-a1db574036c9bc2d397b69f8200594027e1fff16.tar.gz
frameworks_base-a1db574036c9bc2d397b69f8200594027e1fff16.tar.bz2
Add preliminary support for text rendering.
Change-Id: I547eb631dbda24d13960d54b4144fb8908fd8a49
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
-rw-r--r--libs/hwui/OpenGLRenderer.cpp56
1 files changed, 31 insertions, 25 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index e39385a..1fa76d2 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -138,8 +138,8 @@ OpenGLRenderer::OpenGLRenderer():
mCurrentProgram = mDrawTextureProgram;
mShader = kShaderNone;
- mShaderTileX = SkShader::kClamp_TileMode;
- mShaderTileY = SkShader::kClamp_TileMode;
+ mShaderTileX = GL_CLAMP_TO_EDGE;
+ mShaderTileY = GL_CLAMP_TO_EDGE;
mShaderMatrix = NULL;
mShaderBitmap = NULL;
@@ -535,8 +535,8 @@ void OpenGLRenderer::resetShader() {
mShader = OpenGLRenderer::kShaderNone;
mShaderKey = NULL;
mShaderBlend = false;
- mShaderTileX = SkShader::kClamp_TileMode;
- mShaderTileY = SkShader::kClamp_TileMode;
+ mShaderTileX = GL_CLAMP_TO_EDGE;
+ mShaderTileY = GL_CLAMP_TO_EDGE;
}
void OpenGLRenderer::setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tileX,
@@ -544,8 +544,8 @@ void OpenGLRenderer::setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tile
mShader = OpenGLRenderer::kShaderBitmap;
mShaderBlend = hasAlpha;
mShaderBitmap = bitmap;
- mShaderTileX = tileX;
- mShaderTileY = tileY;
+ mShaderTileX = gTileModes[tileX];
+ mShaderTileY = gTileModes[tileY];
mShaderMatrix = matrix;
}
@@ -556,8 +556,8 @@ void OpenGLRenderer::setupLinearGradientShader(SkShader* shader, float* bounds,
mShader = OpenGLRenderer::kShaderLinearGradient;
mShaderKey = shader;
mShaderBlend = hasAlpha;
- mShaderTileX = tileMode;
- mShaderTileY = tileMode;
+ mShaderTileX = gTileModes[tileMode];
+ mShaderTileY = gTileModes[tileMode];
mShaderMatrix = matrix;
mShaderBounds = bounds;
mShaderColors = colors;
@@ -623,8 +623,18 @@ void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right
float alpha, SkXfermode::Mode mode) {
Texture* texture = mGradientCache.get(mShaderKey);
if (!texture) {
+ SkShader::TileMode tileMode = SkShader::kClamp_TileMode;
+ switch (mShaderTileX) {
+ case GL_REPEAT:
+ tileMode = SkShader::kRepeat_TileMode;
+ break;
+ case GL_MIRRORED_REPEAT:
+ tileMode = SkShader::kMirror_TileMode;
+ break;
+ }
+
texture = mGradientCache.addLinearGradient(mShaderKey, mShaderBounds, mShaderColors,
- mShaderPositions, mShaderCount, mShaderTileX);
+ mShaderPositions, mShaderCount, tileMode);
}
mModelView.loadTranslate(left, top, 0.0f);
@@ -634,14 +644,7 @@ void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right
mDrawLinearGradientProgram->set(mOrthoMatrix, mModelView, mSnapshot->transform);
chooseBlending(mShaderBlend || alpha < 1.0f, mode);
-
- if (texture->id != mLastTexture) {
- glBindTexture(GL_TEXTURE_2D, texture->id);
- mLastTexture = texture->id;
- }
- // TODO: Don't set the texture parameters every time
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gTileModes[mShaderTileX]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gTileModes[mShaderTileX]);
+ bindTexture(texture->id, mShaderTileX, mShaderTileY);
Rect start(mShaderBounds[0], mShaderBounds[1], mShaderBounds[2], mShaderBounds[3]);
if (mShaderMatrix) {
@@ -736,14 +739,7 @@ void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float b
mDrawTextureProgram->set(mOrthoMatrix, mModelView, mSnapshot->transform);
chooseBlending(blend || alpha < 1.0f, mode);
-
- if (texture != mLastTexture) {
- glBindTexture(GL_TEXTURE_2D, texture);
- mLastTexture = texture;
- }
- // TODO: Don't set the texture parameters every time
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, gTileModes[mShaderTileX]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gTileModes[mShaderTileY]);
+ bindTexture(texture, mShaderTileX, mShaderTileY);
// Always premultiplied
//glUniform4f(mDrawTextureProgram->color, alpha, alpha, alpha, alpha);
@@ -826,5 +822,15 @@ void OpenGLRenderer::getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermod
}
}
+void OpenGLRenderer::bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT) {
+ if (texture != mLastTexture) {
+ glBindTexture(GL_TEXTURE_2D, texture);
+ mLastTexture = texture;
+ }
+ // TODO: Don't set the texture parameters every time
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
+}
+
}; // namespace uirenderer
}; // namespace android