if we can't bind context to thread we try to reinitialize EGL and try once more

This commit is contained in:
ExMix 2013-10-02 13:45:46 +03:00 committed by Alex Zolotarev
parent a4d3a8148a
commit d7fe3d7e8e
2 changed files with 16 additions and 39 deletions

View file

@ -17,6 +17,12 @@ public class EglOperationException extends RuntimeException
{
return mErrorCode;
}
@Override
public String toString()
{
return super.toString() + " EGL code = " + Integer.toHexString(mErrorCode);
}
private int mErrorCode;
}

View file

@ -103,51 +103,22 @@ public class PixelBuffer
public void attachToThread()
{
int attempt = 0;
boolean succeed = false;
while ((attempt < MAX_TRY) && !succeed)
{
succeed = EGL14.eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
if (!succeed)
{
someSleep();
++attempt;
}
else
Log.d(TAG, "Pixel buffer attached");
}
if (!succeed)
if (!EGL14.eglMakeCurrent(mDisplay, mSurface, mSurface, mContext))
{
Log.d(TAG, "Throwed");
throw new EglOperationException("EGL error : Context was not binded to thread", EGL14.eglGetError());
terminate();
init();
if (!EGL14.eglMakeCurrent(mDisplay, mSurface, mSurface, mContext))
throw new EglOperationException("EGL error : Context was not binded to thread", EGL14.eglGetError());
}
}
public void detachFromThread()
{
int attempt = 0;
boolean succeed = false;
while ((attempt < MAX_TRY) && !succeed)
{
succeed = EGL14.eglMakeCurrent(mDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
if (!succeed)
{
someSleep();
++attempt;
}
else
Log.d(TAG, "Pixel buffer detached");
}
if (!succeed)
{
Log.d(TAG, "Throwed");
throw new EglOperationException("EGL error : Context was not binded to the thread", EGL14.eglGetError());
}
if (!EGL14.eglMakeCurrent(mDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT))
{
terminate();
init();
}
}
public Bitmap readBitmap()