EGLImpl.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
168e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes/* 268e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** 368e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** Copyright 2006, The Android Open Source Project 468e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** 568e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** Licensed under the Apache License, Version 2.0 (the "License"); 668e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** you may not use this file except in compliance with the License. 768e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** You may obtain a copy of the License at 868e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** 968e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** http://www.apache.org/licenses/LICENSE-2.0 1068e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** 1168e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** Unless required by applicable law or agreed to in writing, software 1268e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** distributed under the License is distributed on an "AS IS" BASIS, 1368e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1468e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** See the License for the specific language governing permissions and 1568e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes** limitations under the License. 1668e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes*/ 1768e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes 1868e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughespackage com.google.android.gles_jni; 1968e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes 200399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogersimport javax.microedition.khronos.egl.*; 2168e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes 226d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogersimport android.view.Surface; 23bfe487be25652c5456236661b9d9c3579d2296c1Elliott Hughesimport android.view.SurfaceView; 2468e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughesimport android.view.SurfaceHolder; 2511d1b0c31ddd710d26068da8e0e4621002205b4bElliott Hughesimport android.view.View; 2611d1b0c31ddd710d26068da8e0e4621002205b4bElliott Hughes 27ce4cc0d1818e872c1c7f3c3519a82259afd5c288TDYapublic class EGLImpl implements EGL10 { 280399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers private EGLContextImpl mContext = new EGLContextImpl(-1); 290399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers private EGLDisplayImpl mDisplay = new EGLDisplayImpl(-1); 300399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers private EGLSurfaceImpl mSurface = new EGLSurfaceImpl(-1); 310399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers 320399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglInitialize(EGLDisplay display, int[] major_minor); 33ce4cc0d1818e872c1c7f3c3519a82259afd5c288TDYa public native boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value); 34ce4cc0d1818e872c1c7f3c3519a82259afd5c288TDYa public native boolean eglQuerySurface(EGLDisplay display, EGLSurface surface, int attribute, int[] value); 35ce4cc0d1818e872c1c7f3c3519a82259afd5c288TDYa public native boolean eglChooseConfig(EGLDisplay display, int[] attrib_list, EGLConfig[] configs, int config_size, int[] num_config); 36ce4cc0d1818e872c1c7f3c3519a82259afd5c288TDYa public native boolean eglGetConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int[] value); 370399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config); 38efccc565091b3409ed1372615b4ea4e2f6c39323buzbee public native int eglGetError(); 390399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglDestroyContext(EGLDisplay display, EGLContext context); 40b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes public native boolean eglDestroySurface(EGLDisplay display, EGLSurface surface); 41b3bd5f07884f5a1f2b84224363b1372d7c28d447Elliott Hughes public native boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context); 420399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native String eglQueryString(EGLDisplay display, int name); 430399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface); 440399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglTerminate(EGLDisplay display); 450399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglCopyBuffers(EGLDisplay display, EGLSurface surface, Object native_pixmap); 460399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglWaitGL(); 470399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public native boolean eglWaitNative(int engine, Object bindTarget); 480399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers 490399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public EGLContext eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list) { 500399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers return new EGLContextImpl( _eglCreateContext(display, config, share_context, attrib_list) ); 510399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers } 520399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers 5368e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) { 5468e76526e98432625464022cb26f66b9ef6f5af4Elliott Hughes return new EGLSurfaceImpl( _eglCreatePbufferSurface(display, config, attrib_list) ); 550399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers } 560399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers 570399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) { 580399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers EGLSurfaceImpl sur = new EGLSurfaceImpl(); 590c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers _eglCreatePixmapSurface(sur, display, config, native_pixmap, attrib_list); 600399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers return sur; 610399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers } 620399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers 630399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { 640399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers Surface sur; 650c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers if (native_window instanceof SurfaceView) { 660c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers SurfaceView surfaceView = (SurfaceView)native_window; 670c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers sur = surfaceView.getHolder().getSurface(); 680c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers } else if (native_window instanceof SurfaceHolder) { 690c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers SurfaceHolder holder = (SurfaceHolder)native_window; 702bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers sur = holder.getSurface(); 710ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers } else { 720ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers throw new java.lang.UnsupportedOperationException( 732bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers "eglCreateWindowSurface() can only be called with an instance of " + 740ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers "SurfaceView or SurfaceHolder at the moment, this will be fixed later."); 750ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers } 760ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers return new EGLSurfaceImpl( _eglCreateWindowSurface(display, config, sur, attrib_list) ); 772bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers } 782bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers 792bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers public synchronized EGLDisplay eglGetDisplay(Object native_display) { 802bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers int value = _eglGetDisplay(native_display); 812bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers if (mDisplay.mEGLDisplay != value) 820ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers mDisplay = new EGLDisplayImpl(value); 830ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers return mDisplay; 840ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers } 850ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers 862bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers public synchronized EGLContext eglGetCurrentContext() { 872bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers int value = _eglGetCurrentContext(); 880399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers if (mContext.mEGLContext != value) 890399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers mContext = new EGLContextImpl(value); 908e950c117975d23f50ed7e32ca5db01a813c25d0TDYa return mContext; 910399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers } 926d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers 936d4d9fcb4f01e287ee29e81cd1c941ee5d11d379Ian Rogers public synchronized EGLDisplay eglGetCurrentDisplay() { 942bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers int value = _eglGetCurrentDisplay(); 950ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers if (mDisplay.mEGLDisplay != value) 960ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers mDisplay = new EGLDisplayImpl(value); 970ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers return mDisplay; 980ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers } 990ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers 1000ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers public synchronized EGLSurface eglGetCurrentSurface(int readdraw) { 1012bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers int value = _eglGetCurrentSurface(readdraw); 1026702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier if (mSurface.mEGLSurface != value) 1036702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier mSurface = new EGLSurfaceImpl(value); 1046702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier return mSurface; 1056702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier } 1066702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier 1076702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native int _eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list); 1086702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native int _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list); 1096702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list); 1106702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); 1116702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native int _eglGetDisplay(Object native_display); 1126702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native int _eglGetCurrentContext(); 1136702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native int _eglGetCurrentDisplay(); 1146702243ea2332b566d8e8b871cc9db0906d835adMathieu Chartier private native int _eglGetCurrentSurface(int readdraw); 1150ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers 1160ec569a3e653e0358fcb59c89f2aad708843db53Ian Rogers native private static void _nativeClassInit(); 1172bcb4a496b7aa00d996df3a070524f7568fb35a1Ian Rogers static { _nativeClassInit(); } 1180399dde18753aa9bd2bd0d7cf60beef154d164a4Ian Rogers} 119cccd84f1f972f1a260c3be418c8388a5d30cf59eElliott Hughes