blob: 41fb07228791cdc00b75e62eeb837478be300da4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
Dan Bornsteinc086ca12010-12-07 15:35:20 -08002 * 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 Project9066cfe2009-03-03 19:31:44 -080016
17package com.google.android.gles_jni;
18
19import javax.microedition.khronos.egl.*;
20
Romain Guy8f0095c2011-05-02 17:24:22 -070021import android.graphics.SurfaceTexture;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.view.Surface;
23import android.view.SurfaceView;
24import android.view.SurfaceHolder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26public 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 Palevichd682ab72009-12-04 17:07:31 +080032 public native boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 public native boolean eglQuerySurface(EGLDisplay display, EGLSurface surface, int attribute, int[] value);
Romain Guy8ff6b9e2011-11-09 20:10:18 -080034 /** @hide **/
35 public native boolean eglReleaseThread();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 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 Palevichd682ab72009-12-04 17:07:31 +080038 public native boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 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 Guy8ff6b9e2011-11-09 20:10:18 -080049
50 /** @hide **/
51 public static native int getInitCount(EGLDisplay display);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
53 public EGLContext eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, int[] attrib_list) {
Ashok Bhat863f98b2014-01-27 16:58:46 +000054 long eglContextId = _eglCreateContext(display, config, share_context, attrib_list);
Jack Palevichd682ab72009-12-04 17:07:31 +080055 if (eglContextId == 0) {
56 return EGL10.EGL_NO_CONTEXT;
57 }
58 return new EGLContextImpl( eglContextId );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 }
60
61 public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) {
Ashok Bhat863f98b2014-01-27 16:58:46 +000062 long eglSurfaceId = _eglCreatePbufferSurface(display, config, attrib_list);
Jack Palevichd682ab72009-12-04 17:07:31 +080063 if (eglSurfaceId == 0) {
64 return EGL10.EGL_NO_SURFACE;
65 }
66 return new EGLSurfaceImpl( eglSurfaceId );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 }
Jack Palevichd682ab72009-12-04 17:07:31 +080068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 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 Palevichd682ab72009-12-04 17:07:31 +080072 if (sur.mEGLSurface == 0) {
73 return EGL10.EGL_NO_SURFACE;
74 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 return sur;
76 }
77
78 public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) {
Romain Guy8f0095c2011-05-02 17:24:22 -070079 Surface sur = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 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 Guy786fc932012-07-24 16:24:56 -070086 } else if (native_window instanceof Surface) {
87 sur = (Surface) native_window;
Romain Guy8f0095c2011-05-02 17:24:22 -070088 }
89
Ashok Bhat863f98b2014-01-27 16:58:46 +000090 long eglSurfaceId;
Romain Guy8f0095c2011-05-02 17:24:22 -070091 if (sur != null) {
92 eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
93 } else if (native_window instanceof SurfaceTexture) {
94 eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config,
Romain Guy8ff6b9e2011-11-09 20:10:18 -080095 native_window, attrib_list);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 } else {
97 throw new java.lang.UnsupportedOperationException(
98 "eglCreateWindowSurface() can only be called with an instance of " +
Romain Guy786fc932012-07-24 16:24:56 -070099 "Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
Romain Guy8f0095c2011-05-02 17:24:22 -0700101
Jack Palevichd682ab72009-12-04 17:07:31 +0800102 if (eglSurfaceId == 0) {
103 return EGL10.EGL_NO_SURFACE;
104 }
105 return new EGLSurfaceImpl( eglSurfaceId );
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 }
Jack Palevichd682ab72009-12-04 17:07:31 +0800107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 public synchronized EGLDisplay eglGetDisplay(Object native_display) {
Ashok Bhat863f98b2014-01-27 16:58:46 +0000109 long value = _eglGetDisplay(native_display);
Jack Palevichd682ab72009-12-04 17:07:31 +0800110 if (value == 0) {
111 return EGL10.EGL_NO_DISPLAY;
112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 if (mDisplay.mEGLDisplay != value)
114 mDisplay = new EGLDisplayImpl(value);
115 return mDisplay;
116 }
117
118 public synchronized EGLContext eglGetCurrentContext() {
Ashok Bhat863f98b2014-01-27 16:58:46 +0000119 long value = _eglGetCurrentContext();
Jack Palevichd682ab72009-12-04 17:07:31 +0800120 if (value == 0) {
121 return EGL10.EGL_NO_CONTEXT;
122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 if (mContext.mEGLContext != value)
124 mContext = new EGLContextImpl(value);
125 return mContext;
126 }
Jack Palevichd682ab72009-12-04 17:07:31 +0800127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 public synchronized EGLDisplay eglGetCurrentDisplay() {
Ashok Bhat863f98b2014-01-27 16:58:46 +0000129 long value = _eglGetCurrentDisplay();
Jack Palevichd682ab72009-12-04 17:07:31 +0800130 if (value == 0) {
131 return EGL10.EGL_NO_DISPLAY;
132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 if (mDisplay.mEGLDisplay != value)
134 mDisplay = new EGLDisplayImpl(value);
135 return mDisplay;
136 }
137
138 public synchronized EGLSurface eglGetCurrentSurface(int readdraw) {
Ashok Bhat863f98b2014-01-27 16:58:46 +0000139 long value = _eglGetCurrentSurface(readdraw);
Jack Palevichd682ab72009-12-04 17:07:31 +0800140 if (value == 0) {
141 return EGL10.EGL_NO_SURFACE;
142 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 if (mSurface.mEGLSurface != value)
144 mSurface = new EGLSurfaceImpl(value);
145 return mSurface;
146 }
147
Ashok Bhat863f98b2014-01-27 16:58:46 +0000148 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 Project9066cfe2009-03-03 19:31:44 -0800150 private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list);
Ashok Bhat863f98b2014-01-27 16:58:46 +0000151 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 Project9066cfe2009-03-03 19:31:44 -0800157
158 native private static void _nativeClassInit();
159 static { _nativeClassInit(); }
160}