summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2010-12-14 16:05:50 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-12-14 16:05:50 -0800
commita9c9b532358fd3ca3e33dc8076c76d89f32c8651 (patch)
treefb1dbfdae87da92abe8087ca5fcb5910b7aa534e /libs
parent0cf9a22b9ee8b660ed932205484a645b0762e4b1 (diff)
parent86568198f2c83d4ce5c4cd692eda074ba9de9ed2 (diff)
downloadframeworks_base-a9c9b532358fd3ca3e33dc8076c76d89f32c8651.zip
frameworks_base-a9c9b532358fd3ca3e33dc8076c76d89f32c8651.tar.gz
frameworks_base-a9c9b532358fd3ca3e33dc8076c76d89f32c8651.tar.bz2
Merge "Continue cleanup refactoring in OpenGLRenderer."
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/OpenGLRenderer.cpp236
-rw-r--r--libs/hwui/OpenGLRenderer.h71
2 files changed, 84 insertions, 223 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 72c8950..e99f73a 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -856,6 +856,16 @@ void OpenGLRenderer::setupDrawColor(int color) {
mSetShaderColor = mDescription.setColor(mColorR, mColorG, mColorB, mColorA);
}
+void OpenGLRenderer::setupDrawAlpha8Color(int color, int alpha) {
+ mColorA = alpha / 255.0f;
+ const float a = mColorA / 255.0f;
+ mColorR = a * ((color >> 16) & 0xFF);
+ mColorG = a * ((color >> 8) & 0xFF);
+ mColorB = a * ((color ) & 0xFF);
+ mColorSet = true;
+ mSetShaderColor = mDescription.setAlpha8Color(mColorR, mColorG, mColorB, mColorA);
+}
+
void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) {
mColorA = a;
mColorR = r;
@@ -865,6 +875,15 @@ void OpenGLRenderer::setupDrawColor(float r, float g, float b, float a) {
mSetShaderColor = mDescription.setColor(r, g, b, a);
}
+void OpenGLRenderer::setupDrawAlpha8Color(float r, float g, float b, float a) {
+ mColorA = a;
+ mColorR = r;
+ mColorG = g;
+ mColorB = b;
+ mColorSet = true;
+ mSetShaderColor = mDescription.setAlpha8Color(r, g, b, a);
+}
+
void OpenGLRenderer::setupDrawShader() {
if (mShader) {
mShader->describe(mDescription, mCaches.extensions);
@@ -912,16 +931,19 @@ void OpenGLRenderer::setupDrawModelView(float left, float top, float right, floa
if (!ignoreModelView) {
mModelView.loadTranslate(left, top, 0.0f);
mModelView.scale(right - left, bottom - top, 1.0f);
- if (!ignoreTransform) {
- mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
- if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
- } else {
- mCaches.currentProgram->set(mOrthoMatrix, mModelView, mIdentity);
- if (mTrackDirtyRegions) dirtyLayer(left, top, right, bottom);
- }
} else {
mModelView.loadIdentity();
}
+ bool dirty = right - left > 0.0f && bottom - top > 0.0f;
+ if (!ignoreTransform) {
+ mCaches.currentProgram->set(mOrthoMatrix, mModelView, *mSnapshot->transform);
+ if (mTrackDirtyRegions && dirty) {
+ dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
+ }
+ } else {
+ mCaches.currentProgram->set(mOrthoMatrix, mModelView, mIdentity);
+ if (mTrackDirtyRegions && dirty) dirtyLayer(left, top, right, bottom);
+ }
}
void OpenGLRenderer::setupDrawColorUniforms() {
@@ -930,9 +952,9 @@ void OpenGLRenderer::setupDrawColorUniforms() {
}
}
-void OpenGLRenderer::setupDrawColorAlphaUniforms() {
+void OpenGLRenderer::setupDrawPureColorUniforms() {
if (mSetShaderColor) {
- mCaches.currentProgram->setColor(mColorA, mColorA, mColorA, mColorA);
+ mCaches.currentProgram->setColor(mColorR, mColorG, mColorB, mColorA);
}
}
@@ -1000,7 +1022,7 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint
return;
}
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture(gTextureUnits[0]);
Texture* texture = mCaches.textureCache.get(bitmap);
if (!texture) return;
const AutoTexture autoCleanup(texture);
@@ -1017,7 +1039,7 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* pai
return;
}
- glActiveTexture(GL_TEXTURE0);
+ glActiveTexture(gTextureUnits[0]);
Texture* texture = mCaches.textureCache.get(bitmap);
if (!texture) return;
const AutoTexture autoCleanup(texture);
@@ -1325,48 +1347,60 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
}
- int alpha;
- SkXfermode::Mode mode;
- getAlphaAndMode(paint, &alpha, &mode);
-
- uint32_t color = paint->getColor();
- const GLfloat a = alpha / 255.0f;
- const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
- const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
- const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
-
FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
paint->getTextSize());
- setupDraw();
+ int alpha;
+ SkXfermode::Mode mode;
+ getAlphaAndMode(paint, &alpha, &mode);
if (mHasShadow) {
- glActiveTexture(gTextureUnits[0]);
mCaches.dropShadowCache.setFontRenderer(fontRenderer);
const ShadowTexture* shadow = mCaches.dropShadowCache.get(paint, text, bytesCount,
count, mShadowRadius);
const AutoTexture autoCleanup(shadow);
- setupShadow(shadow, x, y, mode, a, pureTranslate);
+ const float sx = x - shadow->left + mShadowDx;
+ const float sy = y - shadow->top + mShadowDy;
+
+ const int shadowAlpha = ((mShadowColor >> 24) & 0xFF);
+
+ glActiveTexture(gTextureUnits[0]);
+ setupDraw();
+ setupDrawWithTexture(true);
+ setupDrawAlpha8Color(mShadowColor, shadowAlpha < 255 ? shadowAlpha : alpha);
+ setupDrawBlending(true, mode);
+ setupDrawProgram();
+ setupDrawModelView(sx, sy, sx + shadow->width, sy + shadow->height, pureTranslate);
+ setupDrawTexture(shadow->id);
+ setupDrawPureColorUniforms();
+ setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
- // Draw the mesh
glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
- glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
+ finishDrawTexture();
}
- GLuint textureUnit = 0;
- glActiveTexture(gTextureUnits[textureUnit]);
-
// Pick the appropriate texture filtering
bool linearFilter = mSnapshot->transform->changesBounds();
if (pureTranslate && !linearFilter) {
linearFilter = fabs(y - (int) y) > 0.0f || fabs(x - (int) x) > 0.0f;
}
- // Dimensions are set to (0,0), the layer (if any) won't be dirtied
- setupTextureAlpha8(fontRenderer.getTexture(linearFilter), 0, 0, textureUnit,
- x, y, r, g, b, a, mode, false, true, NULL, NULL, 0, pureTranslate);
+ glActiveTexture(gTextureUnits[0]);
+ setupDraw();
+ setupDrawDirtyRegionsDisabled();
+ setupDrawWithTexture(true);
+ setupDrawAlpha8Color(paint->getColor(), alpha);
+ setupDrawColorFilter();
+ setupDrawShader();
+ setupDrawBlending(true, mode);
+ setupDrawProgram();
+ setupDrawModelView(x, y, x, y, pureTranslate, true);
+ setupDrawTexture(fontRenderer.getTexture(linearFilter));
+ setupDrawPureColorUniforms();
+ setupDrawColorFilterUniforms();
+ setupDrawShaderUniforms(pureTranslate);
const Rect* clip = pureTranslate ? mSnapshot->clipRect : &mSnapshot->getLocalClip();
Rect bounds(FLT_MAX / 2.0f, FLT_MAX / 2.0f, FLT_MIN / 2.0f, FLT_MIN / 2.0f);
@@ -1421,19 +1455,23 @@ void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
SkXfermode::Mode mode;
getAlphaAndMode(paint, &alpha, &mode);
- uint32_t color = paint->getColor();
- const GLfloat a = alpha / 255.0f;
- const GLfloat r = a * ((color >> 16) & 0xFF) / 255.0f;
- const GLfloat g = a * ((color >> 8) & 0xFF) / 255.0f;
- const GLfloat b = a * ((color ) & 0xFF) / 255.0f;
-
- setupTextureAlpha8(texture, textureUnit, x, y, r, g, b, a, mode, true, true);
-
setupDraw();
+ setupDrawWithTexture(true);
+ setupDrawAlpha8Color(paint->getColor(), alpha);
+ setupDrawColorFilter();
+ setupDrawShader();
+ setupDrawBlending(true, mode);
+ setupDrawProgram();
+ setupDrawModelView(x, y, x + texture->width, y + texture->height);
+ setupDrawTexture(texture->id);
+ setupDrawPureColorUniforms();
+ setupDrawColorFilterUniforms();
+ setupDrawShaderUniforms();
+ setupDrawMesh(NULL, (GLvoid*) gMeshTextureOffset);
- // Draw the mesh
glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount);
- glDisableVertexAttribArray(mCaches.currentProgram->getAttrib("texCoords"));
+
+ finishDrawTexture();
}
///////////////////////////////////////////////////////////////////////////////
@@ -1483,118 +1521,6 @@ void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) {
// Drawing implementation
///////////////////////////////////////////////////////////////////////////////
-void OpenGLRenderer::setupShadow(const ShadowTexture* texture, float x, float y,
- SkXfermode::Mode mode, float alpha, bool ignoreTransforms) {
- const float sx = x - texture->left + mShadowDx;
- const float sy = y - texture->top + mShadowDy;
-
- const int shadowAlpha = ((mShadowColor >> 24) & 0xFF);
- const GLfloat a = shadowAlpha < 255 ? shadowAlpha / 255.0f : alpha;
- const GLfloat r = a * ((mShadowColor >> 16) & 0xFF) / 255.0f;
- const GLfloat g = a * ((mShadowColor >> 8) & 0xFF) / 255.0f;
- const GLfloat b = a * ((mShadowColor ) & 0xFF) / 255.0f;
-
- GLuint textureUnit = 0;
- setupTextureAlpha8(texture->id, texture->width, texture->height, textureUnit,
- sx, sy, r, g, b, a, mode, true, false,
- (GLvoid*) 0, (GLvoid*) gMeshTextureOffset, 0, ignoreTransforms);
-}
-
-void OpenGLRenderer::setupTextureAlpha8(const Texture* texture, GLuint& textureUnit,
- float x, float y, float r, float g, float b, float a, SkXfermode::Mode mode,
- bool transforms, bool applyFilters) {
- setupTextureAlpha8(texture->id, texture->width, texture->height, textureUnit,
- x, y, r, g, b, a, mode, transforms, applyFilters,
- (GLvoid*) 0, (GLvoid*) gMeshTextureOffset);
-}
-
-void OpenGLRenderer::setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
- GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
- SkXfermode::Mode mode, bool transforms, bool applyFilters) {
- setupTextureAlpha8(texture, width, height, textureUnit, x, y, r, g, b, a, mode,
- transforms, applyFilters, (GLvoid*) 0, (GLvoid*) gMeshTextureOffset);
-}
-
-void OpenGLRenderer::setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
- GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
- SkXfermode::Mode mode, bool transforms, bool applyFilters,
- GLvoid* vertices, GLvoid* texCoords, GLuint vbo, bool ignoreTransform) {
- // Describe the required shaders
- ProgramDescription description;
- description.hasTexture = true;
- description.hasAlpha8Texture = true;
- const bool setColor = description.setAlpha8Color(r, g, b, a);
-
- if (applyFilters) {
- if (mShader) {
- mShader->describe(description, mCaches.extensions);
- }
- if (mColorFilter) {
- mColorFilter->describe(description, mCaches.extensions);
- }
- }
-
- // Setup the blending mode
- chooseBlending(true, mode, description);
-
- // Build and use the appropriate shader
- useProgram(mCaches.programCache.get(description));
-
- bindTexture(texture);
- glUniform1i(mCaches.currentProgram->getUniform("sampler"), textureUnit);
-
- int texCoordsSlot = mCaches.currentProgram->getAttrib("texCoords");
- glEnableVertexAttribArray(texCoordsSlot);
-
- if (texCoords) {
- // Setup attributes
- if (!vertices) {
- mCaches.bindMeshBuffer(vbo == 0 ? mCaches.meshBuffer : vbo);
- } else {
- mCaches.unbindMeshBuffer();
- }
- glVertexAttribPointer(mCaches.currentProgram->position, 2, GL_FLOAT, GL_FALSE,
- gMeshStride, vertices);
- glVertexAttribPointer(texCoordsSlot, 2, GL_FLOAT, GL_FALSE, gMeshStride, texCoords);
- }
-
- // Setup uniforms
- if (transforms) {
- mModelView.loadTranslate(x, y, 0.0f);
- mModelView.scale(width, height, 1.0f);
- } else {
- mModelView.loadIdentity();
- }
-
- mat4 t;
- if (!ignoreTransform) {
- t.load(*mSnapshot->transform);
- }
-
- mCaches.currentProgram->set(mOrthoMatrix, mModelView, t);
- if (width > 0 && height > 0) {
- dirtyLayer(x, y, x + width, y + height, t);
- }
-
- if (setColor) {
- mCaches.currentProgram->setColor(r, g, b, a);
- }
-
- textureUnit++;
- if (applyFilters) {
- // Setup attributes and uniforms required by the shaders
- if (mShader) {
- if (ignoreTransform) {
- mModelView.loadInverse(*mSnapshot->transform);
- }
- mShader->setupProgram(mCaches.currentProgram, mModelView, *mSnapshot, &textureUnit);
- }
- if (mColorFilter) {
- mColorFilter->setupProgram(mCaches.currentProgram);
- }
- }
-}
-
// Same values used by Skia
#define kStdStrikeThru_Offset (-6.0f / 21.0f)
#define kStdUnderline_Offset (1.0f / 9.0f)
@@ -1727,7 +1653,7 @@ void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float b
} else {
setupDrawModelViewTranslate(left, top, right, bottom, ignoreTransform);
}
- setupDrawColorAlphaUniforms();
+ setupDrawPureColorUniforms();
setupDrawColorFilterUniforms();
setupDrawTexture(texture);
setupDrawMesh(vertices, texCoords, vbo);
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 5d8653d..c3c6ad6 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -279,73 +279,6 @@ private:
bool ignoreScale = false, bool dirty = true);
/**
- * Prepares the renderer to draw the specified shadow. The active texture
- * unit must be 0 and the other units must be unbound.
- *
- * @param texture The shadow texture
- * @param x The x coordinate of the shadow
- * @param y The y coordinate of the shadow
- * @param mode The blending mode
- * @param alpha The alpha value
- * @param ignoreTransforms True if the coordinates are already in screen space
- */
- void setupShadow(const ShadowTexture* texture, float x, float y, SkXfermode::Mode mode,
- float alpha, bool ignoreTransforms = false);
-
- /**
- * Prepares the renderer to draw the specified Alpha8 texture as a rectangle.
- *
- * @param texture The texture to render with
- * @param textureUnit The texture unit to use, may be modified
- * @param x The x coordinate of the rectangle to draw
- * @param y The y coordinate of the rectangle to draw
- * @param r The red component of the color
- * @param g The green component of the color
- * @param b The blue component of the color
- * @param a The alpha component of the color
- * @param mode The blending mode
- * @param transforms True if the matrix passed to the shader should be multiplied
- * by the model-view matrix
- * @param applyFilters Whether or not to take color filters and
- * shaders into account
- */
- void setupTextureAlpha8(const Texture* texture, GLuint& textureUnit, float x, float y,
- float r, float g, float b, float a, SkXfermode::Mode mode, bool transforms,
- bool applyFilters);
-
- /**
- * Prepares the renderer to draw the specified Alpha8 texture as a rectangle.
- *
- * @param texture The texture to render with
- * @param width The width of the texture
- * @param height The height of the texture
- * @param textureUnit The texture unit to use, may be modified
- * @param x The x coordinate of the rectangle to draw
- * @param y The y coordinate of the rectangle to draw
- * @param r The red component of the color
- * @param g The green component of the color
- * @param b The blue component of the color
- * @param a The alpha component of the color
- * @param mode The blending mode
- * @param transforms True if the matrix passed to the shader should be multiplied
- * by the model-view matrix
- * @param applyFilters Whether or not to take color filters and
- * shaders into account
- */
- void setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
- GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
- SkXfermode::Mode mode, bool transforms, bool applyFilters);
-
- /**
- * Same as above setupTextureAlpha8() but specifies the mesh's vertices
- * and texCoords pointers. The pointers become offsets when a VBO is bound.
- */
- void setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
- GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
- SkXfermode::Mode mode, bool transforms, bool applyFilters,
- GLvoid* vertices, GLvoid* texCoords, GLuint vbo = 0, bool ignoreTransform = false);
-
- /**
* Draws text underline and strike-through if needed.
*
* @param text The text to decor
@@ -430,6 +363,8 @@ private:
void setupDrawWithTexture(bool isAlpha8 = false);
void setupDrawColor(int color);
void setupDrawColor(float r, float g, float b, float a);
+ void setupDrawAlpha8Color(int color, int alpha);
+ void setupDrawAlpha8Color(float r, float g, float b, float a);
void setupDrawShader();
void setupDrawColorFilter();
void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
@@ -443,7 +378,7 @@ private:
void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
bool ignoreTransform = false);
void setupDrawColorUniforms();
- void setupDrawColorAlphaUniforms();
+ void setupDrawPureColorUniforms();
void setupDrawShaderUniforms(bool ignoreTransform = false);
void setupDrawColorFilterUniforms();
void setupDrawSimpleMesh();