2015-06-11 10:08:59 +02:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
2015-06-11 10:08:59 +02:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2015-06-11 10:08:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.webrtc;
|
|
|
|
|
|
2015-09-28 11:05:44 +02:00
|
|
|
import android.graphics.SurfaceTexture;
|
2015-11-16 02:04:50 -08:00
|
|
|
import android.view.Surface;
|
2015-12-14 06:21:13 -08:00
|
|
|
|
2015-12-14 06:43:35 -08:00
|
|
|
import javax.microedition.khronos.egl.EGL10;
|
2015-12-15 02:48:07 -08:00
|
|
|
|
2015-10-22 16:52:39 -07:00
|
|
|
|
2015-06-11 10:08:59 +02:00
|
|
|
/**
|
2015-12-02 01:07:18 -08:00
|
|
|
* Holds EGL state and utility methods for handling an egl 1.0 EGLContext, an EGLDisplay,
|
|
|
|
|
* and an EGLSurface.
|
2015-06-11 10:08:59 +02:00
|
|
|
*/
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract class EglBase {
|
|
|
|
|
// EGL wrapper for an actual EGLContext.
|
|
|
|
|
public static class Context {
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 16:52:39 -07:00
|
|
|
// These constants are taken from EGL14.EGL_OPENGL_ES2_BIT and EGL14.EGL_CONTEXT_CLIENT_VERSION.
|
|
|
|
|
// https://android.googlesource.com/platform/frameworks/base/+/master/opengl/java/android/opengl/EGL14.java
|
|
|
|
|
// This is similar to how GlSurfaceView does:
|
|
|
|
|
// http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/opengl/GLSurfaceView.java#760
|
|
|
|
|
private static final int EGL_OPENGL_ES2_BIT = 4;
|
2015-06-11 10:08:59 +02:00
|
|
|
// Android-specific extension.
|
|
|
|
|
private static final int EGL_RECORDABLE_ANDROID = 0x3142;
|
|
|
|
|
|
2015-12-07 01:17:16 -08:00
|
|
|
public static final int[] CONFIG_PLAIN = {
|
|
|
|
|
EGL10.EGL_RED_SIZE, 8,
|
|
|
|
|
EGL10.EGL_GREEN_SIZE, 8,
|
|
|
|
|
EGL10.EGL_BLUE_SIZE, 8,
|
|
|
|
|
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
|
EGL10.EGL_NONE
|
|
|
|
|
};
|
2015-12-15 16:22:29 +01:00
|
|
|
public static final int[] CONFIG_RGBA = {
|
|
|
|
|
EGL10.EGL_RED_SIZE, 8,
|
|
|
|
|
EGL10.EGL_GREEN_SIZE, 8,
|
|
|
|
|
EGL10.EGL_BLUE_SIZE, 8,
|
|
|
|
|
EGL10.EGL_ALPHA_SIZE, 8,
|
|
|
|
|
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
|
EGL10.EGL_NONE
|
|
|
|
|
};
|
2015-12-07 01:17:16 -08:00
|
|
|
public static final int[] CONFIG_PIXEL_BUFFER = {
|
|
|
|
|
EGL10.EGL_RED_SIZE, 8,
|
|
|
|
|
EGL10.EGL_GREEN_SIZE, 8,
|
|
|
|
|
EGL10.EGL_BLUE_SIZE, 8,
|
|
|
|
|
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
|
EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
|
|
|
|
|
EGL10.EGL_NONE
|
|
|
|
|
};
|
2015-12-10 06:23:33 -08:00
|
|
|
public static final int[] CONFIG_PIXEL_RGBA_BUFFER = {
|
|
|
|
|
EGL10.EGL_RED_SIZE, 8,
|
|
|
|
|
EGL10.EGL_GREEN_SIZE, 8,
|
|
|
|
|
EGL10.EGL_BLUE_SIZE, 8,
|
|
|
|
|
EGL10.EGL_ALPHA_SIZE, 8,
|
|
|
|
|
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
|
EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
|
|
|
|
|
EGL10.EGL_NONE
|
|
|
|
|
};
|
2015-12-07 01:17:16 -08:00
|
|
|
public static final int[] CONFIG_RECORDABLE = {
|
|
|
|
|
EGL10.EGL_RED_SIZE, 8,
|
|
|
|
|
EGL10.EGL_GREEN_SIZE, 8,
|
|
|
|
|
EGL10.EGL_BLUE_SIZE, 8,
|
|
|
|
|
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
|
EGL_RECORDABLE_ANDROID, 1,
|
|
|
|
|
EGL10.EGL_NONE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Create a new context with the specified config attributes, sharing data with sharedContext.
|
2015-12-02 01:07:18 -08:00
|
|
|
// |sharedContext| can be null.
|
2015-12-07 01:17:16 -08:00
|
|
|
public static EglBase create(Context sharedContext, int[] configAttributes) {
|
2015-12-02 01:07:18 -08:00
|
|
|
return (EglBase14.isEGL14Supported()
|
|
|
|
|
&& (sharedContext == null || sharedContext instanceof EglBase14.Context))
|
2015-12-07 01:17:16 -08:00
|
|
|
? new EglBase14((EglBase14.Context) sharedContext, configAttributes)
|
2015-12-15 02:48:07 -08:00
|
|
|
: new EglBase10((EglBase10.Context) sharedContext, configAttributes);
|
2015-12-02 01:07:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static EglBase create() {
|
2015-12-07 01:17:16 -08:00
|
|
|
return create(null, CONFIG_PLAIN);
|
2015-12-02 01:07:18 -08:00
|
|
|
}
|
|
|
|
|
|
2016-01-27 15:25:46 +01:00
|
|
|
public static EglBase create(Context sharedContext) {
|
|
|
|
|
return create(sharedContext, CONFIG_PLAIN);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void createSurface(Surface surface);
|
2015-09-28 11:05:44 +02:00
|
|
|
|
|
|
|
|
// Create EGLSurface from the Android SurfaceTexture.
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void createSurface(SurfaceTexture surfaceTexture);
|
2015-06-11 10:08:59 +02:00
|
|
|
|
|
|
|
|
// Create dummy 1x1 pixel buffer surface so the context can be made current.
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void createDummyPbufferSurface();
|
2015-07-26 05:17:19 -07:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void createPbufferSurface(int width, int height);
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract Context getEglBaseContext();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract boolean hasSurface();
|
2015-08-20 09:58:31 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract int surfaceWidth();
|
2015-08-20 09:58:31 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract int surfaceHeight();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void releaseSurface();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void release();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void makeCurrent();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2015-09-15 09:44:07 +02:00
|
|
|
// Detach the current EGL context, so that it can be made current on another thread.
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void detachCurrent();
|
2015-09-15 09:44:07 +02:00
|
|
|
|
2015-12-15 02:48:07 -08:00
|
|
|
public abstract void swapBuffers();
|
2015-06-11 10:08:59 +02:00
|
|
|
}
|