1    // C function EGLSurface eglCreateWindowSurface ( EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list )
2
3    private static native EGLSurface _eglCreateWindowSurface(
4        EGLDisplay dpy,
5        EGLConfig config,
6        Object win,
7        int[] attrib_list,
8        int offset
9    );
10
11    private static native EGLSurface _eglCreateWindowSurfaceTexture(
12        EGLDisplay dpy,
13        EGLConfig config,
14        Object win,
15        int[] attrib_list,
16        int offset
17    );
18
19    public static EGLSurface eglCreateWindowSurface(EGLDisplay dpy,
20        EGLConfig config,
21        Object win,
22        int[] attrib_list,
23        int offset
24    ){
25        Surface sur = null;
26        if (win instanceof SurfaceView) {
27            SurfaceView surfaceView = (SurfaceView)win;
28            sur = surfaceView.getHolder().getSurface();
29        } else if (win instanceof SurfaceHolder) {
30            SurfaceHolder holder = (SurfaceHolder)win;
31            sur = holder.getSurface();
32        }
33
34        EGLSurface surface;
35        if (sur != null) {
36            surface = _eglCreateWindowSurface(dpy, config, sur, attrib_list, offset);
37        } else if (win instanceof SurfaceTexture) {
38            surface = _eglCreateWindowSurfaceTexture(dpy, config,
39                    win, attrib_list, offset);
40        } else {
41            throw new java.lang.UnsupportedOperationException(
42                "eglCreateWindowSurface() can only be called with an instance of " +
43                "SurfaceView, SurfaceTexture or SurfaceHolder at the moment, " +
44                "this will be fixed later.");
45        }
46
47        return surface;
48    }
49