Skip to content

Commit d43b22d

Browse files
author
Romain Guy
committed
Always use the correct pixel store size
Bug #7357394 When a bitmap is reused it may change configuration which can lead to a different pixel store alignment. Our current texture cache implementation assumes this never happens and keeps the old alignment which can lead to distorted texture (if the bitmap goes from ARGB8888 to RGB565 for instance.) Change-Id: Ic57acf2403411ae4d0924e92f221298350612617
1 parent 4682cf0 commit d43b22d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

libs/hwui/TextureCache.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,25 +228,22 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege
228228
texture->height = bitmap->height();
229229

230230
glBindTexture(GL_TEXTURE_2D, texture->id);
231-
if (!regenerate) {
232-
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
233-
}
234231

235232
switch (bitmap->getConfig()) {
236233
case SkBitmap::kA8_Config:
237-
if (!regenerate) {
238-
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
239-
}
234+
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
240235
uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), texture->height,
241236
GL_UNSIGNED_BYTE, bitmap->getPixels());
242237
texture->blend = true;
243238
break;
244239
case SkBitmap::kRGB_565_Config:
240+
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
245241
uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), texture->height,
246242
GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
247243
texture->blend = false;
248244
break;
249245
case SkBitmap::kARGB_8888_Config:
246+
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
250247
uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), texture->height,
251248
GL_UNSIGNED_BYTE, bitmap->getPixels());
252249
// Do this after calling getPixels() to make sure Skia's deferred
@@ -255,6 +252,7 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege
255252
break;
256253
case SkBitmap::kARGB_4444_Config:
257254
case SkBitmap::kIndex8_Config:
255+
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
258256
uploadLoFiTexture(resize, bitmap, texture->width, texture->height);
259257
texture->blend = !bitmap->isOpaque();
260258
break;

0 commit comments

Comments
 (0)