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