Bug 751609 - Give up on locking a Surface after 10 failures r=blassey

This commit is contained in:
James Willcox 2012-05-07 14:18:30 -04:00
Родитель 57e20d6acb
Коммит cbf379b8a1
1 изменённых файлов: 22 добавлений и 6 удалений

Просмотреть файл

@ -912,6 +912,23 @@ NextPowerOfTwo(int value) {
return value + 1;
}
#define MAX_LOCK_ATTEMPTS 10
static bool LockWindowWithRetry(void* window, unsigned char** bits, int* width, int* height, int* format, int* stride)
{
int count = 0;
while (count < MAX_LOCK_ATTEMPTS) {
if (AndroidBridge::Bridge()->LockWindow(window, bits, width, height, format, stride))
return true;
count++;
usleep(500);
}
return false;
}
NS_EXPORT jobject JNICALL
Java_org_mozilla_gecko_GeckoAppShell_getSurfaceBits(JNIEnv* jenv, jclass, jobject surface)
{
@ -931,15 +948,14 @@ Java_org_mozilla_gecko_GeckoAppShell_getSurfaceBits(JNIEnv* jenv, jclass, jobjec
int srcWidth, srcHeight, format, srcStride;
// So we lock/unlock once here in order to get whatever is currently the front buffer. It sucks.
while (!AndroidBridge::Bridge()->LockWindow(window, &bits, &srcWidth, &srcHeight, &format, &srcStride)) {
usleep(1000);
}
if (!LockWindowWithRetry(window, &bits, &srcWidth, &srcHeight, &format, &srcStride))
return nsnull;
AndroidBridge::Bridge()->UnlockWindow(window);
// This is lock will result in the front buffer, since the last unlock rotated it to the back. Probably.
while (!AndroidBridge::Bridge()->LockWindow(window, &bits, &srcWidth, &srcHeight, &format, &srcStride)) {
usleep(1000);
}
if (!LockWindowWithRetry(window, &bits, &srcWidth, &srcHeight, &format, &srcStride))
return nsnull;
// These are from android.graphics.PixelFormat
int bpp;