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:43:35 -08:00
|
|
|
import javax.microedition.khronos.egl.EGL10;
|
2015-12-15 02:48:07 -08: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
|
|
|
*/
|
2017-11-30 11:23:33 +01:00
|
|
|
public interface EglBase {
|
2015-12-15 02:48:07 -08:00
|
|
|
// EGL wrapper for an actual EGLContext.
|
2017-09-18 11:26:30 +02:00
|
|
|
public interface Context { long getNativeEglContext(); }
|
2015-12-15 02:48:07 -08:00
|
|
|
|
2016-03-31 13:17:11 +02:00
|
|
|
// According to the documentation, EGL can be used from multiple threads at the same time if each
|
|
|
|
|
// thread has its own EGLContext, but in practice it deadlocks on some devices when doing this.
|
|
|
|
|
// Therefore, synchronize on this global lock before calling dangerous EGL functions that might
|
|
|
|
|
// deadlock. See https://bugs.chromium.org/p/webrtc/issues/detail?id=5702 for more info.
|
|
|
|
|
public static final Object lock = new Object();
|
|
|
|
|
|
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
|
2017-08-25 06:28:00 -07:00
|
|
|
public static final int EGL_OPENGL_ES2_BIT = 4;
|
2015-06-11 10:08:59 +02:00
|
|
|
// Android-specific extension.
|
2017-08-25 06:28:00 -07:00
|
|
|
public static final int EGL_RECORDABLE_ANDROID = 0x3142;
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2015-10-22 16:52:39 -07:00
|
|
|
// clang-format off
|
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
|
|
|
|
|
};
|
2016-03-31 13:17:11 +02:00
|
|
|
// clang-format on
|
2015-12-07 01:17:16 -08:00
|
|
|
|
2017-04-21 01:34:12 -07:00
|
|
|
/**
|
|
|
|
|
* Create a new context with the specified config attributes, sharing data with |sharedContext|.
|
|
|
|
|
* If |sharedContext| is null, a root context is created. This function will try to create an EGL
|
|
|
|
|
* 1.4 context if possible, and an EGL 1.0 context otherwise.
|
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
2017-04-21 01:34:12 -07:00
|
|
|
/**
|
|
|
|
|
* Helper function for creating a plain root context. This function will try to create an EGL 1.4
|
|
|
|
|
* context if possible, and an EGL 1.0 context otherwise.
|
|
|
|
|
*/
|
2015-12-02 01:07:18 -08:00
|
|
|
public static EglBase create() {
|
2017-04-21 01:34:12 -07:00
|
|
|
return create(null /* shaderContext */, CONFIG_PLAIN);
|
2015-12-02 01:07:18 -08:00
|
|
|
}
|
|
|
|
|
|
2017-04-21 01:34:12 -07:00
|
|
|
/**
|
|
|
|
|
* Helper function for creating a plain context, sharing data with |sharedContext|. This function
|
|
|
|
|
* will try to create an EGL 1.4 context if possible, and an EGL 1.0 context otherwise.
|
|
|
|
|
*/
|
2016-01-27 15:25:46 +01:00
|
|
|
public static EglBase create(Context sharedContext) {
|
|
|
|
|
return create(sharedContext, CONFIG_PLAIN);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 01:34:12 -07:00
|
|
|
/**
|
|
|
|
|
* Explicitly create a root EGl 1.0 context with the specified config attributes.
|
|
|
|
|
*/
|
|
|
|
|
public static EglBase createEgl10(int[] configAttributes) {
|
|
|
|
|
return new EglBase10(null /* shaderContext */, configAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 10:11:25 -07:00
|
|
|
/**
|
|
|
|
|
* Explicitly create a root EGl 1.0 context with the specified config attributes
|
|
|
|
|
* and shared context.
|
|
|
|
|
*/
|
|
|
|
|
public static EglBase createEgl10(
|
|
|
|
|
javax.microedition.khronos.egl.EGLContext sharedContext, int[] configAttributes) {
|
|
|
|
|
return new EglBase10(new EglBase10.Context(sharedContext), configAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 01:34:12 -07:00
|
|
|
/**
|
|
|
|
|
* Explicitly create a root EGl 1.4 context with the specified config attributes.
|
|
|
|
|
*/
|
|
|
|
|
public static EglBase createEgl14(int[] configAttributes) {
|
|
|
|
|
return new EglBase14(null /* shaderContext */, configAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 10:11:25 -07:00
|
|
|
/**
|
|
|
|
|
* Explicitly create a root EGl 1.4 context with the specified config attributes
|
|
|
|
|
* and shared context.
|
|
|
|
|
*/
|
|
|
|
|
public static EglBase createEgl14(
|
|
|
|
|
android.opengl.EGLContext sharedContext, int[] configAttributes) {
|
|
|
|
|
return new EglBase14(new EglBase14.Context(sharedContext), configAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
void createSurface(Surface surface);
|
2015-09-28 11:05:44 +02:00
|
|
|
|
|
|
|
|
// Create EGLSurface from the Android SurfaceTexture.
|
2017-11-30 11:23:33 +01:00
|
|
|
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.
|
2017-11-30 11:23:33 +01:00
|
|
|
void createDummyPbufferSurface();
|
2015-07-26 05:17:19 -07:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
void createPbufferSurface(int width, int height);
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
Context getEglBaseContext();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
boolean hasSurface();
|
2015-08-20 09:58:31 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
int surfaceWidth();
|
2015-08-20 09:58:31 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
int surfaceHeight();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
void releaseSurface();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
void release();
|
2015-06-11 10:08:59 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
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.
|
2017-11-30 11:23:33 +01:00
|
|
|
void detachCurrent();
|
2015-09-15 09:44:07 +02:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
void swapBuffers();
|
2017-08-25 06:28:00 -07:00
|
|
|
|
2017-11-30 11:23:33 +01:00
|
|
|
void swapBuffers(long presentationTimeStampNs);
|
2015-06-11 10:08:59 +02:00
|
|
|
}
|