Skip to content

Commit 574cf60

Browse files
author
Romain Guy
committed
Make sure we never bind to texture #0
Bug #7195815 Change-Id: Ibec4b2aa4c580419eb5eb61adae6c9c960694d0c
1 parent 8e586f6 commit 574cf60

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

libs/hwui/font/CacheTexture.h

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ class CacheTexture {
7777
}
7878

7979
~CacheTexture() {
80-
if (mTexture) {
81-
delete[] mTexture;
82-
}
83-
if (mTextureId) {
84-
glDeleteTextures(1, &mTextureId);
85-
}
80+
releaseTexture();
8681
reset();
8782
}
8883

@@ -105,38 +100,40 @@ class CacheTexture {
105100

106101
void releaseTexture() {
107102
if (mTexture) {
108-
glDeleteTextures(1, &mTextureId);
109103
delete[] mTexture;
110104
mTexture = NULL;
105+
}
106+
if (mTextureId) {
107+
glDeleteTextures(1, &mTextureId);
111108
mTextureId = 0;
112109
}
110+
mDirty = false;
113111
}
114112

115113
/**
116114
* This method assumes that the proper texture unit is active.
117115
*/
118116
void allocateTexture() {
119-
int width = mWidth;
120-
int height = mHeight;
121-
122-
mTexture = new uint8_t[width * height];
117+
if (!mTexture) {
118+
mTexture = new uint8_t[mWidth * mHeight];
119+
}
123120

124121
if (!mTextureId) {
125122
glGenTextures(1, &mTextureId);
126-
}
127123

128-
glBindTexture(GL_TEXTURE_2D, mTextureId);
129-
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
130-
// Initialize texture dimensions
131-
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0,
132-
GL_ALPHA, GL_UNSIGNED_BYTE, 0);
124+
glBindTexture(GL_TEXTURE_2D, mTextureId);
125+
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
126+
// Initialize texture dimensions
127+
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, mWidth, mHeight, 0,
128+
GL_ALPHA, GL_UNSIGNED_BYTE, 0);
133129

134-
const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST;
135-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
136-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
130+
const GLenum filtering = getLinearFiltering() ? GL_LINEAR : GL_NEAREST;
131+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
132+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
137133

138-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
139-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
134+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
135+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
136+
}
140137
}
141138

142139
bool fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY);
@@ -153,7 +150,8 @@ class CacheTexture {
153150
return mTexture;
154151
}
155152

156-
inline GLuint getTextureId() const {
153+
GLuint getTextureId() {
154+
allocateTexture();
157155
return mTextureId;
158156
}
159157

0 commit comments

Comments
 (0)