31 private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
32 private static final int EGL_OPENGL_ES2_BIT = 4;
33 private static final int STENCIL_BUFFER_SIZE = 8;
34 private static final long TIME_OUT_MS = 10000;
35 private static final String LOG_TAG =
"SkottiePlayer";
39 private HandlerThread mGLThreadLooper;
40 private Handler mGLThread;
46 private long mNativeProxy;
49 System.loadLibrary(
"skottie_android");
55 if (sInstance ==
null) {
99 Log.e(
LOG_TAG,
"update failed", t);
100 throw new RuntimeException(t);
106 mGLThreadLooper =
new HandlerThread(
"SkottieAnimator");
107 mGLThreadLooper.start();
108 mGLThread =
new Handler(mGLThreadLooper.getLooper());
123 private class RunSignalAndCatch
implements Runnable {
124 public Throwable
error;
125 private Runnable mRunnable;
126 private CountDownLatch mFence;
128 RunSignalAndCatch(Runnable
run, CountDownLatch fence) {
137 }
catch (Throwable t) {
149 private void runOnGLThread(Runnable r,
boolean postAtFront)
throws Throwable {
151 CountDownLatch fence =
new CountDownLatch(1);
152 RunSignalAndCatch wrapper =
new RunSignalAndCatch(r, fence);
154 mGLThread.postAtFrontOfQueue(wrapper);
156 mGLThread.post(wrapper);
158 if (!fence.await(TIME_OUT_MS, TimeUnit.MILLISECONDS)) {
159 throw new TimeoutException();
161 if (wrapper.error !=
null) {
166 private void initGl()
171 catch (Throwable t) {
172 Log.e(LOG_TAG,
"initGl failed", t);
173 throw new RuntimeException(t);
177 private Runnable mDoInitGL =
new Runnable() {
180 mEgl = (EGL10) EGLContext.getEGL();
184 throw new RuntimeException(
"eglGetDisplay failed "
185 + GLUtils.getEGLErrorString(
mEgl.eglGetError()));
190 throw new RuntimeException(
"eglInitialize failed " +
191 GLUtils.getEGLErrorString(
mEgl.eglGetError()));
196 throw new RuntimeException(
"eglConfig not initialized");
201 int[] attribs =
new int[] {
210 throw new RuntimeException(
"createPbufferSurface failed "
211 + GLUtils.getEGLErrorString(
error));
215 throw new RuntimeException(
"eglMakeCurrent failed "
216 + GLUtils.getEGLErrorString(
mEgl.eglGetError()));
219 mNativeProxy = nCreateProxy();
223 EGLContext
createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
224 int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
225 return egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
228 private EGLConfig chooseEglConfig() {
229 int[] configsCount =
new int[1];
230 EGLConfig[] configs =
new EGLConfig[1];
231 int[] configSpec = getConfig();
232 if (!
mEgl.eglChooseConfig(
mEglDisplay, configSpec, configs, 1, configsCount)) {
233 throw new IllegalArgumentException(
"eglChooseConfig failed " +
234 GLUtils.getEGLErrorString(
mEgl.eglGetError()));
235 }
else if (configsCount[0] > 0) {
241 private int[] getConfig() {
243 EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
244 EGL10.EGL_RED_SIZE, 8,
245 EGL10.EGL_GREEN_SIZE, 8,
246 EGL10.EGL_BLUE_SIZE, 8,
247 EGL10.EGL_ALPHA_SIZE, 8,
248 EGL10.EGL_DEPTH_SIZE, 0,
254 private void doFinishGL() {
255 nDeleteProxy(mNativeProxy);
267 mEgl.eglMakeCurrent(
mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
268 EGL10.EGL_NO_CONTEXT);
280 private static native
long nCreateProxy();
281 private static native
void nDeleteProxy(
long nativeProxy);
282 private static native
void nSetMaxCacheSize(
int maxCacheSize,
long mNativeProxy);
const uint8_t uint32_t uint32_t GError ** error