blob: 8a7124d10304798bc404bcc6cd591545bcd27ad4 [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
21import android.view.Surface;
22import android.view.SurfaceView;
23import android.view.SurfaceHolder;
24import android.view.View;
25
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);
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 Palevichd682ab72009-12-04 17:07:31 +080036 public native boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 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 Palevichd682ab72009-12-04 17:07:31 +080049 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 Project9066cfe2009-03-03 19:31:44 -080054 }
55
56 public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) {
Jack Palevichd682ab72009-12-04 17:07:31 +080057 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 Project9066cfe2009-03-03 19:31:44 -080062 }
Jack Palevichd682ab72009-12-04 17:07:31 +080063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 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 Palevichd682ab72009-12-04 17:07:31 +080067 if (sur.mEGLSurface == 0) {
68 return EGL10.EGL_NO_SURFACE;
69 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 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 Palevichd682ab72009-12-04 17:07:31 +080086 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 Project9066cfe2009-03-03 19:31:44 -080091 }
Jack Palevichd682ab72009-12-04 17:07:31 +080092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 public synchronized EGLDisplay eglGetDisplay(Object native_display) {
94 int value = _eglGetDisplay(native_display);
Jack Palevichd682ab72009-12-04 17:07:31 +080095 if (value == 0) {
96 return EGL10.EGL_NO_DISPLAY;
97 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 if (mDisplay.mEGLDisplay != value)
99 mDisplay = new EGLDisplayImpl(value);
100 return mDisplay;
101 }
102
103 public synchronized EGLContext eglGetCurrentContext() {
104 int value = _eglGetCurrentContext();
Jack Palevichd682ab72009-12-04 17:07:31 +0800105 if (value == 0) {
106 return EGL10.EGL_NO_CONTEXT;
107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 if (mContext.mEGLContext != value)
109 mContext = new EGLContextImpl(value);
110 return mContext;
111 }
Jack Palevichd682ab72009-12-04 17:07:31 +0800112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 public synchronized EGLDisplay eglGetCurrentDisplay() {
114 int value = _eglGetCurrentDisplay();
Jack Palevichd682ab72009-12-04 17:07:31 +0800115 if (value == 0) {
116 return EGL10.EGL_NO_DISPLAY;
117 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 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 Palevichd682ab72009-12-04 17:07:31 +0800125 if (value == 0) {
126 return EGL10.EGL_NO_SURFACE;
127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 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 Palevichd682ab72009-12-04 17:07:31 +0800136 private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 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}