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 | |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 21 | import android.graphics.SurfaceTexture; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.view.Surface; |
| 23 | import android.view.SurfaceView; |
| 24 | import android.view.SurfaceHolder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 34 | /** @hide **/ |
| 35 | public native boolean eglReleaseThread(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | public native boolean eglChooseConfig(EGLDisplay display, int[] attrib_list, EGLConfig[] configs, int config_size, int[] num_config); |
| 37 | public native boolean eglGetConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int[] value); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 38 | 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] | 39 | public native int eglGetError(); |
| 40 | public native boolean eglDestroyContext(EGLDisplay display, EGLContext context); |
| 41 | public native boolean eglDestroySurface(EGLDisplay display, EGLSurface surface); |
| 42 | public native boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context); |
| 43 | public native String eglQueryString(EGLDisplay display, int name); |
| 44 | public native boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface); |
| 45 | public native boolean eglTerminate(EGLDisplay display); |
| 46 | public native boolean eglCopyBuffers(EGLDisplay display, EGLSurface surface, Object native_pixmap); |
| 47 | public native boolean eglWaitGL(); |
| 48 | public native boolean eglWaitNative(int engine, Object bindTarget); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 49 | |
| 50 | /** @hide **/ |
| 51 | public static native int getInitCount(EGLDisplay display); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
| 53 | public EGLContext eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 54 | long eglContextId = _eglCreateContext(display, config, share_context, attrib_list); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 55 | if (eglContextId == 0) { |
| 56 | return EGL10.EGL_NO_CONTEXT; |
| 57 | } |
| 58 | return new EGLContextImpl( eglContextId ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 62 | long eglSurfaceId = _eglCreatePbufferSurface(display, config, attrib_list); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 63 | if (eglSurfaceId == 0) { |
| 64 | return EGL10.EGL_NO_SURFACE; |
| 65 | } |
| 66 | return new EGLSurfaceImpl( eglSurfaceId ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | } |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) { |
| 70 | EGLSurfaceImpl sur = new EGLSurfaceImpl(); |
| 71 | _eglCreatePixmapSurface(sur, display, config, native_pixmap, attrib_list); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 72 | if (sur.mEGLSurface == 0) { |
| 73 | return EGL10.EGL_NO_SURFACE; |
| 74 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | return sur; |
| 76 | } |
| 77 | |
| 78 | public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 79 | Surface sur = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | if (native_window instanceof SurfaceView) { |
| 81 | SurfaceView surfaceView = (SurfaceView)native_window; |
| 82 | sur = surfaceView.getHolder().getSurface(); |
| 83 | } else if (native_window instanceof SurfaceHolder) { |
| 84 | SurfaceHolder holder = (SurfaceHolder)native_window; |
| 85 | sur = holder.getSurface(); |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 86 | } else if (native_window instanceof Surface) { |
| 87 | sur = (Surface) native_window; |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 90 | long eglSurfaceId; |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 91 | if (sur != null) { |
| 92 | eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list); |
| 93 | } else if (native_window instanceof SurfaceTexture) { |
| 94 | eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 95 | native_window, attrib_list); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | } else { |
| 97 | throw new java.lang.UnsupportedOperationException( |
| 98 | "eglCreateWindowSurface() can only be called with an instance of " + |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 99 | "Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | } |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 101 | |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 102 | if (eglSurfaceId == 0) { |
| 103 | return EGL10.EGL_NO_SURFACE; |
| 104 | } |
| 105 | return new EGLSurfaceImpl( eglSurfaceId ); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | } |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | public synchronized EGLDisplay eglGetDisplay(Object native_display) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 109 | long value = _eglGetDisplay(native_display); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 110 | if (value == 0) { |
| 111 | return EGL10.EGL_NO_DISPLAY; |
| 112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | if (mDisplay.mEGLDisplay != value) |
| 114 | mDisplay = new EGLDisplayImpl(value); |
| 115 | return mDisplay; |
| 116 | } |
| 117 | |
| 118 | public synchronized EGLContext eglGetCurrentContext() { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 119 | long value = _eglGetCurrentContext(); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 120 | if (value == 0) { |
| 121 | return EGL10.EGL_NO_CONTEXT; |
| 122 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | if (mContext.mEGLContext != value) |
| 124 | mContext = new EGLContextImpl(value); |
| 125 | return mContext; |
| 126 | } |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | public synchronized EGLDisplay eglGetCurrentDisplay() { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 129 | long value = _eglGetCurrentDisplay(); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 130 | if (value == 0) { |
| 131 | return EGL10.EGL_NO_DISPLAY; |
| 132 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | if (mDisplay.mEGLDisplay != value) |
| 134 | mDisplay = new EGLDisplayImpl(value); |
| 135 | return mDisplay; |
| 136 | } |
| 137 | |
| 138 | public synchronized EGLSurface eglGetCurrentSurface(int readdraw) { |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 139 | long value = _eglGetCurrentSurface(readdraw); |
Jack Palevich | d682ab7 | 2009-12-04 17:07:31 +0800 | [diff] [blame] | 140 | if (value == 0) { |
| 141 | return EGL10.EGL_NO_SURFACE; |
| 142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | if (mSurface.mEGLSurface != value) |
| 144 | mSurface = new EGLSurfaceImpl(value); |
| 145 | return mSurface; |
| 146 | } |
| 147 | |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 148 | private native long _eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list); |
| 149 | private native long _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list); |
Ashok Bhat | 863f98b | 2014-01-27 16:58:46 +0000 | [diff] [blame] | 151 | private native long _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); |
| 152 | private native long _eglCreateWindowSurfaceTexture(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); |
| 153 | private native long _eglGetDisplay(Object native_display); |
| 154 | private native long _eglGetCurrentContext(); |
| 155 | private native long _eglGetCurrentDisplay(); |
| 156 | private native long _eglGetCurrentSurface(int readdraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | |
| 158 | native private static void _nativeClassInit(); |
| 159 | static { _nativeClassInit(); } |
| 160 | } |