diff options
author | 2010-07-29 18:48:04 -0700 | |
---|---|---|
committer | 2010-07-29 18:48:04 -0700 | |
commit | ae5575b3421c8fbe590ab046d7d5f2b36ecfd821 (patch) | |
tree | 2e4cfe7b83c81492a577428e0f8b7cb33faaa551 | |
parent | 889f8d1403761d5668115ced6cbb3f767cfe966d (diff) |
Fix gradients rendering and destructor crashes.
This changes binds all textures to GL_TEXTURE0, this will have
to be changed when combining shader capabilities.
Change-Id: I02df4f5ba41e9b01ffa52fd7c26b41477c7ed18f
-rw-r--r-- | libs/hwui/FontRenderer.cpp | 1 | ||||
-rw-r--r-- | libs/hwui/GenerationCache.h | 12 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 34 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h | 6 | ||||
-rw-r--r-- | libs/hwui/Snapshot.h | 2 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java | 2 |
6 files changed, 22 insertions, 35 deletions
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp index 6074ec83ba81..5595ab0220d6 100644 --- a/libs/hwui/FontRenderer.cpp +++ b/libs/hwui/FontRenderer.cpp @@ -327,7 +327,6 @@ void FontRenderer::initTextTexture() { mTextTexture = new unsigned char[mCacheWidth * mCacheHeight]; mUploadTexture = false; - glActiveTexture(GL_TEXTURE0); glGenTextures(1, &mTextureId); glBindTexture(GL_TEXTURE_2D, mTextureId); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); diff --git a/libs/hwui/GenerationCache.h b/libs/hwui/GenerationCache.h index 5c1b5e142c0d..45b3ffaf074a 100644 --- a/libs/hwui/GenerationCache.h +++ b/libs/hwui/GenerationCache.h @@ -34,13 +34,12 @@ template<typename EntryKey, typename EntryValue> struct Entry: public LightRefBase<Entry<EntryKey, EntryValue> > { Entry() { } Entry(const Entry<EntryKey, EntryValue>& e): - key(e.key), value(e.value), index(e.index), parent(e.parent), child(e.child) { } + key(e.key), value(e.value), parent(e.parent), child(e.child) { } Entry(sp<Entry<EntryKey, EntryValue> > e): - key(e->key), value(e->value), index(e->index), parent(e->parent), child(e->child) { } + key(e->key), value(e->value), parent(e->parent), child(e->child) { } EntryKey key; EntryValue value; - ssize_t index; sp<Entry<EntryKey, EntryValue> > parent; sp<Entry<EntryKey, EntryValue> > child; @@ -156,7 +155,7 @@ template<typename K, typename V> void GenerationCache<K, V>::addToCache(sp<Entry<K, V> > entry, K key, V value) { entry->key = key; entry->value = value; - entry->index = mCache.add(key, entry); + mCache.add(key, entry); attachToCache(entry); } @@ -185,7 +184,10 @@ V GenerationCache<K, V>::removeAt(ssize_t index) { template<typename K, typename V> V GenerationCache<K, V>::removeOldest() { if (mOldest.get()) { - return removeAt(mOldest->index); + ssize_t index = mCache.indexOfKey(mOldest->key); + if (index >= 0) { + return removeAt(index); + } } return NULL; diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 3d9aa261edeb..3c36f954947f 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -144,11 +144,13 @@ OpenGLRenderer::OpenGLRenderer(): memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices)); - glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxTextureUnits); - if (mMaxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) { + mFirstSnapshot = new Snapshot; + + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) { LOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT); } - mLastTexture[0] = mLastTexture[1] = mLastTexture[2] = 0; } OpenGLRenderer::~OpenGLRenderer() { @@ -171,11 +173,11 @@ void OpenGLRenderer::setViewport(int width, int height) { mWidth = width; mHeight = height; - mFirstSnapshot.height = height; + mFirstSnapshot->height = height; } void OpenGLRenderer::prepare() { - mSnapshot = &mFirstSnapshot; + mSnapshot = mFirstSnapshot; mSaveCount = 0; glDisable(GL_SCISSOR_TEST); @@ -265,10 +267,6 @@ void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) { glScissor(clip.left, mHeight - clip.bottom, clip.getWidth(), clip.getHeight()); Layer* layer = current->layer; - - // Compute the correct texture coordinates for the FBO texture - // The texture is currently as big as the window but drawn with - // a quad of the appropriate size const Rect& rect = layer->layer; drawTextureRect(rect.left, rect.top, rect.right, rect.bottom, @@ -323,7 +321,6 @@ int OpenGLRenderer::saveLayerAlpha(float left, float top, float right, float bot bool OpenGLRenderer::createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode,int flags) { - LAYER_LOGD("Requesting layer %fx%f", right - left, bottom - top); LAYER_LOGD("Layer cache size = %d", mLayerCache.getSize()); @@ -537,8 +534,6 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, return; } - glActiveTexture(GL_TEXTURE0); - float length; switch (paint->getTextAlign()) { case SkPaint::kCenter_Align: @@ -687,7 +682,6 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right, float bottom, float alpha, SkXfermode::Mode mode) { - glActiveTexture(GL_TEXTURE1); Texture* texture = mGradientCache.get(mShaderKey); if (!texture) { SkShader::TileMode tileMode = SkShader::kClamp_TileMode; @@ -714,8 +708,8 @@ void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right mCurrentProgram->set(mOrthoMatrix, mModelView, mSnapshot->transform); chooseBlending(mShaderBlend || alpha < 1.0f, mode); - bindTexture(texture->id, mShaderTileX, mShaderTileY, 1); - glUniform1i(mCurrentProgram->getUniform("gradientSampler"), 1); + bindTexture(texture->id, mShaderTileX, mShaderTileY, 0); + glUniform1i(mCurrentProgram->getUniform("gradientSampler"), 0); Rect start(mShaderBounds[0], mShaderBounds[1], mShaderBounds[2], mShaderBounds[3]); if (mShaderMatrix) { @@ -747,7 +741,6 @@ void OpenGLRenderer::drawLinearGradientShader(float left, float top, float right void OpenGLRenderer::drawBitmapShader(float left, float top, float right, float bottom, float alpha, SkXfermode::Mode mode) { - glActiveTexture(GL_TEXTURE2); const Texture* texture = mTextureCache.get(mShaderBitmap); const float width = texture->width; @@ -782,8 +775,8 @@ void OpenGLRenderer::drawBitmapShader(float left, float top, float right, float chooseBlending(texture->blend || alpha < 1.0f, mode); // Texture - bindTexture(texture->id, mShaderTileX, mShaderTileY, 2); - glUniform1i(mCurrentProgram->getUniform("bitmapSampler"), 2); + bindTexture(texture->id, mShaderTileX, mShaderTileY, 0); + glUniform1i(mCurrentProgram->getUniform("bitmapSampler"), 0); glUniformMatrix4fv(mCurrentProgram->getUniform("textureTransform"), 1, GL_FALSE, &textureTransform.data[0]); glUniform2f(mCurrentProgram->getUniform("textureDimension"), 1.0f / width, 1.0f / height); @@ -917,10 +910,7 @@ void OpenGLRenderer::getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermod void OpenGLRenderer::bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT, GLuint textureUnit) { glActiveTexture(gTextureUnits[textureUnit]); - if (texture != mLastTexture[textureUnit]) { - glBindTexture(GL_TEXTURE_2D, texture); - mLastTexture[textureUnit] = texture; - } + glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT); } diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 5e5c021c6f46..937ff08a8904 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -315,7 +315,7 @@ private: // Number of saved states int mSaveCount; // Base state - Snapshot mFirstSnapshot; + sp<Snapshot> mFirstSnapshot; // Current state sp<Snapshot> mSnapshot; @@ -325,10 +325,6 @@ private: // Used to draw textured quads TextureVertex mMeshVertices[4]; - // Current texture state - GLuint mLastTexture[REQUIRED_TEXTURE_UNITS_COUNT]; - GLint mMaxTextureUnits; - // Last known blend state bool mBlend; GLenum mLastSrcMode; diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h index cc7fde968f51..020bdb0fe5de 100644 --- a/libs/hwui/Snapshot.h +++ b/libs/hwui/Snapshot.h @@ -50,7 +50,7 @@ public: * assumed to be dirty. The specified snapshot is stored as the previous * snapshot. */ - Snapshot(const sp<Snapshot> s): + Snapshot(const sp<Snapshot>& s): height(s->height), transform(s->transform), clipRect(s->clipRect), diff --git a/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java b/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java index abd741cc3807..0cd14267b75e 100644 --- a/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java +++ b/tests/HwAccelerationTest/src/com/google/android/test/hwui/ShadersActivity.java @@ -78,7 +78,7 @@ public class ShadersActivity extends Activity { mScaledShader.setLocalMatrix(m2); mHorGradient = new LinearGradient(0.0f, 0.0f, mDrawWidth, 0.0f, - Color.RED, Color.GREEN, Shader.TileMode.REPEAT); + Color.RED, Color.GREEN, Shader.TileMode.CLAMP); mDiagGradient = new LinearGradient(0.0f, 0.0f, mDrawWidth / 1.5f, mDrawHeight, Color.BLUE, Color.MAGENTA, Shader.TileMode.CLAMP); |