The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package com.google.android.gles_jni; |
| 19 | |
| 20 | import javax.microedition.khronos.egl.*; |
| 21 | |
| 22 | import android.view.Surface; |
| 23 | import android.view.SurfaceView; |
| 24 | import android.view.SurfaceHolder; |
| 25 | import android.view.View; |
| 26 | |
| 27 | public 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); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 33 | public native boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 37 | public native boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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) { |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 50 | int eglContextId = _eglCreateContext(display, config, share_context, attrib_list); |
| 51 | if (eglContextId == 0) { |
| 52 | return EGL10.EGL_NO_CONTEXT; |
| 53 | } |
| 54 | return new EGLContextImpl( eglContextId ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) { |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 58 | int eglSurfaceId = _eglCreatePbufferSurface(display, config, attrib_list); |
| 59 | if (eglSurfaceId == 0) { |
| 60 | return EGL10.EGL_NO_SURFACE; |
| 61 | } |
| 62 | return new EGLSurfaceImpl( eglSurfaceId ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | } |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 64 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) { |
| 66 | EGLSurfaceImpl sur = new EGLSurfaceImpl(); |
| 67 | _eglCreatePixmapSurface(sur, display, config, native_pixmap, attrib_list); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 68 | if (sur.mEGLSurface == 0) { |
| 69 | return EGL10.EGL_NO_SURFACE; |
| 70 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | return sur; |
| 72 | } |
| 73 | |
| 74 | public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { |
| 75 | Surface sur; |
| 76 | if (native_window instanceof SurfaceView) { |
| 77 | SurfaceView surfaceView = (SurfaceView)native_window; |
| 78 | sur = surfaceView.getHolder().getSurface(); |
| 79 | } else if (native_window instanceof SurfaceHolder) { |
| 80 | SurfaceHolder holder = (SurfaceHolder)native_window; |
| 81 | sur = holder.getSurface(); |
| 82 | } else { |
| 83 | throw new java.lang.UnsupportedOperationException( |
| 84 | "eglCreateWindowSurface() can only be called with an instance of " + |
| 85 | "SurfaceView or SurfaceHolder at the moment, this will be fixed later."); |
| 86 | } |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 87 | int eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list); |
| 88 | if (eglSurfaceId == 0) { |
| 89 | return EGL10.EGL_NO_SURFACE; |
| 90 | } |
| 91 | return new EGLSurfaceImpl( eglSurfaceId ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | public synchronized EGLDisplay eglGetDisplay(Object native_display) { |
| 95 | int value = _eglGetDisplay(native_display); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 96 | if (value == 0) { |
| 97 | return EGL10.EGL_NO_DISPLAY; |
| 98 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | if (mDisplay.mEGLDisplay != value) |
| 100 | mDisplay = new EGLDisplayImpl(value); |
| 101 | return mDisplay; |
| 102 | } |
| 103 | |
| 104 | public synchronized EGLContext eglGetCurrentContext() { |
| 105 | int value = _eglGetCurrentContext(); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 106 | if (value == 0) { |
| 107 | return EGL10.EGL_NO_CONTEXT; |
| 108 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | if (mContext.mEGLContext != value) |
| 110 | mContext = new EGLContextImpl(value); |
| 111 | return mContext; |
| 112 | } |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | public synchronized EGLDisplay eglGetCurrentDisplay() { |
| 115 | int value = _eglGetCurrentDisplay(); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 116 | if (value == 0) { |
| 117 | return EGL10.EGL_NO_DISPLAY; |
| 118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | if (mDisplay.mEGLDisplay != value) |
| 120 | mDisplay = new EGLDisplayImpl(value); |
| 121 | return mDisplay; |
| 122 | } |
| 123 | |
| 124 | public synchronized EGLSurface eglGetCurrentSurface(int readdraw) { |
| 125 | int value = _eglGetCurrentSurface(readdraw); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 126 | if (value == 0) { |
| 127 | return EGL10.EGL_NO_SURFACE; |
| 128 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | if (mSurface.mEGLSurface != value) |
| 130 | mSurface = new EGLSurfaceImpl(value); |
| 131 | return mSurface; |
| 132 | } |
| 133 | |
| 134 | private native int _eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list); |
| 135 | private native int _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list); |
| 136 | private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame^] | 137 | private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | private native int _eglGetDisplay(Object native_display); |
| 139 | private native int _eglGetCurrentContext(); |
| 140 | private native int _eglGetCurrentDisplay(); |
| 141 | private native int _eglGetCurrentSurface(int readdraw); |
| 142 | |
| 143 | native private static void _nativeClassInit(); |
| 144 | static { _nativeClassInit(); } |
| 145 | } |