@Override public void run() { Request request = null; try { request = mRequestQueue.take(); } catch (final InterruptedException e) { // ignore } synchronized (mSync) { if ((request.arg2 == null) || (request.arg2 instanceof EGLContext)) mEglCore = new EglCore(((EGLContext) request.arg2), request.arg1); mSync.notifyAll(); if (mEglCore == null) { callOnError(new RuntimeException("failed to create EglCore")); return; } } mEglHolder = new OffScreenSurface(mEglCore, 1, 1); mEglHolder.makeCurrent(); try { onStart(); } catch (final Exception e) { if (callOnError(e)) mIsRunning = false; } LOOP: while (mIsRunning) { try { request = mRequestQueue.take(); mEglHolder.makeCurrent(); switch (request.request) { case REQUEST_EGL_TASK_NON: break; case REQUEST_EGL_TASK_RUN: if (request.arg2 instanceof Runnable) try { ((Runnable) request.arg2).run(); } catch (final Exception e) { if (callOnError(e)) break LOOP; } break; case REQUEST_EGL_TASK_QUIT: break LOOP; default: boolean result = false; try { result = processRequest(request.request, request.arg1, request.arg2); } catch (final Exception e) { if (callOnError(e)) break LOOP; } if (result) break LOOP; break; } request.request = REQUEST_EGL_TASK_NON; mRequestPool.offer(request); } catch (final InterruptedException e) { break; } } mEglHolder.makeCurrent(); try { onStop(); } catch (final Exception e) { callOnError(e); } mEglHolder.release(); mEglCore.release(); synchronized (mSync) { mIsRunning = false; mSync.notifyAll(); } }
protected void makeCurrent() { mEglHolder.makeCurrent(); }