Problem with executor service in Eclipse

Problems with Canvas, OpenGL, etc...

Problem with executor service in Eclipse

Postby waikin7 » Tue Sep 13, 2011 7:18 pm

Basically, i'm developing an OpenGL live wallpaper for android phones. This is my wallpaper service class.

Code: Select all
public class Wallpaper extends GLWallpaperService {

private class MyEngine extends Engine {

    private GLRenderer glRenderer;
    private GL10 gl;
    private EGL10 egl;
    private EGLContext glc;
    private EGLDisplay glDisplay;
    private EGLSurface glSurface;

    private ExecutorService executor;
    private Runnable drawCommand;

    public void onCreate(final SurfaceHolder holder) {
        super.onCreate(holder);


        executor = Executors.newScheduledThreadPool(BIND_AUTO_CREATE);

        drawCommand = new Runnable() {
            public void run() {
                glRenderer.onDrawFrame(gl);
                egl.eglSwapBuffers(glDisplay, glSurface);
                if (isVisible()
                        && egl.eglGetError() != EGL11.EGL_CONTEXT_LOST) {
                    executor.execute(drawCommand);
                }
            }
        };

    }

    public void onSurfaceCreated(final SurfaceHolder holder) {
        super.onSurfaceCreated(holder);

        Runnable surfaceCreatedCommand = new Runnable() {
            public void run() {
                // Initialize OpenGL
                egl = (EGL10) EGLContext.getEGL();
                glDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
                int[] version = new int[2];
                egl.eglInitialize(glDisplay, version);
                int[] configSpec = { EGL10.EGL_RED_SIZE, 5,
                        EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5,
                        EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
                EGLConfig[] configs = new EGLConfig[1];
                int[] numConfig = new int[1];
                egl.eglChooseConfig(glDisplay, configSpec, configs, 1,
                        numConfig);
                EGLConfig config = configs[0];

                glc = egl.eglCreateContext(glDisplay, config,
                        EGL10.EGL_NO_CONTEXT, null);

                glSurface = egl.eglCreateWindowSurface(glDisplay, config,
                        holder, null);
                egl.eglMakeCurrent(glDisplay, glSurface, glSurface, glc);
                gl = (GL10) (glc.getGL());

                // Initialize Renderer
                glRenderer = new GLRenderer(Wallpaper.this);
                glRenderer.onSurfaceCreated(gl, config);
            }
        };
        executor.execute(surfaceCreatedCommand);

    }


    public void onSurfaceDestroyed(final SurfaceHolder holder) {

        Runnable surfaceDestroyedCommand = new Runnable() {
            public void run() {
                // Free OpenGL resources
                egl.eglMakeCurrent(glDisplay, EGL10.EGL_NO_SURFACE,
                        EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
                egl.eglDestroySurface(glDisplay, glSurface);
                egl.eglDestroyContext(glDisplay, glc);
                egl.eglTerminate(glDisplay);

            }
        };
        executor.execute(surfaceDestroyedCommand);

        super.onSurfaceDestroyed(holder);
    }


    public void onSurfaceChanged(final SurfaceHolder holder,
            final int format, final int width, final int height) {
        super.onSurfaceChanged(holder, format, width, height);

        Runnable surfaceChangedCommand = new Runnable() {
            public void run() {
                glRenderer.onSurfaceChanged(gl, width, height);
            }
        };
        executor.execute(surfaceChangedCommand);

    }

    public void onDestroy() {

        executor.shutdownNow();

        super.onDestroy();
    }


    public void onVisibilityChanged(final boolean visible) {
        super.onVisibilityChanged(visible);

        if (visible) {
            executor.execute(drawCommand);
        }

    }


    public void onOffsetsChanged(final float xOffset, final float yOffset,
            final float xOffsetStep, final float yOffsetStep,
            final int xPixelOffset, final int yPixelOffset) {
        super.onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep,
                xPixelOffset, yPixelOffset);

        Runnable offsetsChangedCommand = new Runnable() {
            public void run() {
                if (1 / xOffsetStep + 1 != 0f) {
                    glRenderer.setParallax(xOffset - 1f);
                }
            }
        };
        executor.execute(offsetsChangedCommand);

    }

}


public Engine onCreateEngine() {
    return new MyEngine();
}


It works perfectly on my phone (Samsung Galaxy S2) and several others, BUT there have been reports saying it doesnt load. The live wallpaper can't be previewed at all, even from the Galaxy S1 model! Since this works on my phone I cant figure out whats wrong with it. I don't have the phones that cant run the program so i cant fix the problem. HELP!!!
waikin7
Freshman
Freshman
 
Posts: 2
Joined: Tue Sep 13, 2011 7:17 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest