blob: 3e06deda661cee9dd830d188990b11eaf0d53134 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2006, The Android Open Source Project
4**
Jack Palevichd682ab72009-12-04 17:07:31 +08005** 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 Project9066cfe2009-03-03 19:31:44 -08008**
Jack Palevichd682ab72009-12-04 17:07:31 +08009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010**
Jack Palevichd682ab72009-12-04 17:07:31 +080011** 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 Project9066cfe2009-03-03 19:31:44 -080015** 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);
Jack Palevichd682ab72009-12-04 17:07:31 +080033 public native boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 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 Palevichd682ab72009-12-04 17:07:31 +080037 public native boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038 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 Palevichd682ab72009-12-04 17:07:31 +080050 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 Project9066cfe2009-03-03 19:31:44 -080055 }
56
57 public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) {
Jack Palevichd682ab72009-12-04 17:07:31 +080058 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 Project9066cfe2009-03-03 19:31:44 -080063 }
Jack Palevichd682ab72009-12-04 17:07:31 +080064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 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 Palevichd682ab72009-12-04 17:07:31 +080068 if (sur.mEGLSurface == 0) {
69 return EGL10.EGL_NO_SURFACE;
70 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 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 Palevichd682ab72009-12-04 17:07:31 +080087 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 Project9066cfe2009-03-03 19:31:44 -080092 }
Jack Palevichd682ab72009-12-04 17:07:31 +080093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 public synchronized EGLDisplay eglGetDisplay(Object native_display) {
95 int value = _eglGetDisplay(native_display);
Jack Palevichd682ab72009-12-04 17:07:31 +080096 if (value == 0) {
97 return EGL10.EGL_NO_DISPLAY;
98 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 if (mDisplay.mEGLDisplay != value)
100 mDisplay = new EGLDisplayImpl(value);
101 return mDisplay;
102 }
103
104 public synchronized EGLContext eglGetCurrentContext() {
105 int value = _eglGetCurrentContext();
Jack Palevichd682ab72009-12-04 17:07:31 +0800106 if (value == 0) {
107 return EGL10.EGL_NO_CONTEXT;
108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 if (mContext.mEGLContext != value)
110 mContext = new EGLContextImpl(value);
111 return mContext;
112 }
Jack Palevichd682ab72009-12-04 17:07:31 +0800113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 public synchronized EGLDisplay eglGetCurrentDisplay() {
115 int value = _eglGetCurrentDisplay();
Jack Palevichd682ab72009-12-04 17:07:31 +0800116 if (value == 0) {
117 return EGL10.EGL_NO_DISPLAY;
118 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 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 Palevichd682ab72009-12-04 17:07:31 +0800126 if (value == 0) {
127 return EGL10.EGL_NO_SURFACE;
128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 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 Palevichd682ab72009-12-04 17:07:31 +0800137 private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 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}