EGLImpl.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
1/* 2** 3** Copyright 2006, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18package com.google.android.gles_jni; 19 20import javax.microedition.khronos.egl.*; 21 22import android.view.Surface; 23import android.view.SurfaceView; 24import android.view.SurfaceHolder; 25import android.view.View; 26 27public class EGLImpl implements EGL10 { 28 private EGLContextImpl mContext = new EGLContextImpl(-1); 29 private EGLDisplayImpl mDisplay = new EGLDisplayImpl(-1); 30 private EGLSurfaceImpl mSurface = new EGLSurfaceImpl(-1); 31 32 public native boolean eglInitialize(EGLDisplay display, int[] major_minor); 33 public native boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value); 34 public native boolean eglQuerySurface(EGLDisplay display, EGLSurface surface, int attribute, int[] value); 35 public native boolean eglChooseConfig(EGLDisplay display, int[] attrib_list, EGLConfig[] configs, int config_size, int[] num_config); 36 public native boolean eglGetConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int[] value); 37 public native boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config); 38 public native int eglGetError(); 39 public native boolean eglDestroyContext(EGLDisplay display, EGLContext context); 40 public native boolean eglDestroySurface(EGLDisplay display, EGLSurface surface); 41 public native boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context); 42 public native String eglQueryString(EGLDisplay display, int name); 43 public native boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface); 44 public native boolean eglTerminate(EGLDisplay display); 45 public native boolean eglCopyBuffers(EGLDisplay display, EGLSurface surface, Object native_pixmap); 46 public native boolean eglWaitGL(); 47 public native boolean eglWaitNative(int engine, Object bindTarget); 48 49 public EGLContext eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list) { 50 return new EGLContextImpl( _eglCreateContext(display, config, share_context, attrib_list) ); 51 } 52 53 public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) { 54 return new EGLSurfaceImpl( _eglCreatePbufferSurface(display, config, attrib_list) ); 55 } 56 57 public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) { 58 EGLSurfaceImpl sur = new EGLSurfaceImpl(); 59 _eglCreatePixmapSurface(sur, display, config, native_pixmap, attrib_list); 60 return sur; 61 } 62 63 public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { 64 Surface sur; 65 if (native_window instanceof SurfaceView) { 66 SurfaceView surfaceView = (SurfaceView)native_window; 67 sur = surfaceView.getHolder().getSurface(); 68 } else if (native_window instanceof SurfaceHolder) { 69 SurfaceHolder holder = (SurfaceHolder)native_window; 70 sur = holder.getSurface(); 71 } else { 72 throw new java.lang.UnsupportedOperationException( 73 "eglCreateWindowSurface() can only be called with an instance of " + 74 "SurfaceView or SurfaceHolder at the moment, this will be fixed later."); 75 } 76 return new EGLSurfaceImpl( _eglCreateWindowSurface(display, config, sur, attrib_list) ); 77 } 78 79 public synchronized EGLDisplay eglGetDisplay(Object native_display) { 80 int value = _eglGetDisplay(native_display); 81 if (mDisplay.mEGLDisplay != value) 82 mDisplay = new EGLDisplayImpl(value); 83 return mDisplay; 84 } 85 86 public synchronized EGLContext eglGetCurrentContext() { 87 int value = _eglGetCurrentContext(); 88 if (mContext.mEGLContext != value) 89 mContext = new EGLContextImpl(value); 90 return mContext; 91 } 92 93 public synchronized EGLDisplay eglGetCurrentDisplay() { 94 int value = _eglGetCurrentDisplay(); 95 if (mDisplay.mEGLDisplay != value) 96 mDisplay = new EGLDisplayImpl(value); 97 return mDisplay; 98 } 99 100 public synchronized EGLSurface eglGetCurrentSurface(int readdraw) { 101 int value = _eglGetCurrentSurface(readdraw); 102 if (mSurface.mEGLSurface != value) 103 mSurface = new EGLSurfaceImpl(value); 104 return mSurface; 105 } 106 107 private native int _eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list); 108 private native int _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list); 109 private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list); 110 private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); 111 private native int _eglGetDisplay(Object native_display); 112 private native int _eglGetCurrentContext(); 113 private native int _eglGetCurrentDisplay(); 114 private native int _eglGetCurrentSurface(int readdraw); 115 116 native private static void _nativeClassInit(); 117 static { _nativeClassInit(); } 118} 119