android.opengl.EGLContext Java Examples
The following examples show how to use
android.opengl.EGLContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EncodeRenderHandler.java From CameraRecorder-android with MIT License | 6 votes |
final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface) { Log.i(TAG, "setEglContext:"); if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder)) { throw new RuntimeException("unsupported window type:" + surface); } synchronized (sync) { if (requestRelease) return; sharedContext = shared_context; texId = tex_id; this.surface = surface; this.isRecordable = true; requestSetEglContext = true; sync.notifyAll(); try { sync.wait(); } catch (final InterruptedException e) { } } }
Example #2
Source File: EGLSurfaceTexture.java From MediaSDK with Apache License 2.0 | 6 votes |
private static EGLContext createEGLContext( EGLDisplay display, EGLConfig config, @SecureMode int secureMode) { int[] glAttributes; if (secureMode == SECURE_MODE_NONE) { glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; } else { glAttributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL_PROTECTED_CONTENT_EXT, EGL14.EGL_TRUE, EGL14.EGL_NONE }; } EGLContext context = EGL14.eglCreateContext( display, config, EGL14.EGL_NO_CONTEXT, glAttributes, 0); if (context == null) { throw new GlException("eglCreateContext failed"); } return context; }
Example #3
Source File: RenderHandler.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
public final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface, final boolean isRecordable) { if (DEBUG) Log.i(TAG, "setEglContext:"); if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder)) throw new RuntimeException("unsupported window type:" + surface); synchronized (mSync) { if (mRequestRelease) return; mShard_context = shared_context; mTexId = tex_id; mSurface = surface; mIsRecordable = isRecordable; mRequestSetEglContext = true; Matrix.setIdentityM(mMatrix, 0); Matrix.setIdentityM(mMatrix, 16); mSync.notifyAll(); try { mSync.wait(); } catch (final InterruptedException e) { } } }
Example #4
Source File: EglBase14.java From UltraGpuImage with MIT License | 6 votes |
private static EGLContext createEglContext( @Nullable EglBase14.Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) { if (sharedContext != null && sharedContext.egl14Context == EGL14.EGL_NO_CONTEXT) { throw new RuntimeException("Invalid sharedContext"); } int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; EGLContext rootContext = sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext.egl14Context; final EGLContext eglContext; synchronized (EglBase.lock) { eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0); } if (eglContext == EGL14.EGL_NO_CONTEXT) { throw new RuntimeException( "Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError())); } return eglContext; }
Example #5
Source File: EncodeRenderHandler.java From GPUVideo-android with MIT License | 6 votes |
final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface) { Log.i(TAG, "setEglContext:"); if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder)) { throw new RuntimeException("unsupported window type:" + surface); } synchronized (sync) { if (requestRelease) return; sharedContext = shared_context; texId = tex_id; this.surface = surface; this.isRecordable = true; requestSetEglContext = true; sync.notifyAll(); try { sync.wait(); } catch (final InterruptedException e) { } } }
Example #6
Source File: EglBase14Impl.java From webrtc_android with MIT License | 6 votes |
private static EGLContext createEglContext( EGLContext sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) { if (sharedContext != null && sharedContext == EGL14.EGL_NO_CONTEXT) { throw new RuntimeException("Invalid sharedContext"); } int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; EGLContext rootContext = sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext; final EGLContext eglContext; synchronized (EglBase.lock) { eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0); } if (eglContext == EGL14.EGL_NO_CONTEXT) { throw new RuntimeException( "Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError())); } return eglContext; }
Example #7
Source File: TextureMovieEncoder.java From mobile-ar-sensor-logger with GNU General Public License v3.0 | 6 votes |
/** * Tears down the EGL surface and context we've been using to feed the MediaCodec input * surface, and replaces it with a new one that shares with the new context. * <p> * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView * that got torn down) and we need to hook up with the new one. */ private void handleUpdateSharedContext(EGLContext newSharedContext) { Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext); // Release the EGLSurface and EGLContext. mInputWindowSurface.releaseEglSurface(); mFullScreen.release(false); mEglCore.release(); // Create a new EGLContext and recreate the window surface. mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE); mInputWindowSurface.recreate(mEglCore); mInputWindowSurface.makeCurrent(); // Create new programs and such for the new context. mFullScreen = new FullFrameRect( new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT)); }
Example #8
Source File: EGLSurfaceTexture.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private static EGLContext createEGLContext( EGLDisplay display, EGLConfig config, @SecureMode int secureMode) { int[] glAttributes; if (secureMode == SECURE_MODE_NONE) { glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; } else { glAttributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL_PROTECTED_CONTENT_EXT, EGL14.EGL_TRUE, EGL14.EGL_NONE }; } EGLContext context = EGL14.eglCreateContext( display, config, android.opengl.EGL14.EGL_NO_CONTEXT, glAttributes, 0); if (context == null) { throw new GlException("eglCreateContext failed"); } return context; }
Example #9
Source File: UgiRenderer.java From UltraGpuImage with MIT License | 6 votes |
public UgiRenderer(String name, EGLContext sharedContext, int[] configAttributes) { mName = name; mTransformation = new UgiTransformation(480, 640, 480, 640); mNativeHandle = nativeCreate(mTransformation.mNativeHandle); logInfo("new UgiRenderer, handle " + mNativeHandle); HandlerThread renderThread = new HandlerThread("UgiRenderer-" + name); renderThread.start(); mRenderHandler = new Handler(renderThread.getLooper()); // Create EGL context on the newly created render thread. It should be possibly to create // the context on this thread and make it current on the render thread, but this causes // failure on some Marvel based JB devices. // https://bugs.chromium.org/p/webrtc/issues/detail?id=6350. ThreadUtils.invokeAtFrontUninterruptibly(mRenderHandler, () -> mEglBase = EglBase.create( sharedContext == null ? null : new EglBase14.Context(sharedContext), configAttributes)); logInfo("new UgiRenderer success"); }
Example #10
Source File: RtmpPublisher.java From RtmpPublisher with Apache License 2.0 | 6 votes |
@Override public void startPublishing() { streamer.open(url, width, height); glView.queueEvent(new Runnable() { @Override public void run() { // EGL14.eglGetCurrentContext() should be called from glView thread. final EGLContext context = EGL14.eglGetCurrentContext(); glView.post(new Runnable() { @Override public void run() { // back to main thread streamer.startStreaming(context, width, height, audioBitrate, videoBitrate); } }); } }); }
Example #11
Source File: TextureMovieEncoder.java From TikTok with Apache License 2.0 | 6 votes |
/** * Tears down the EGL surface and context we've been using to feed the MediaCodec input * surface, and replaces it with a new one that shares with the new context. * <p> * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView * that got torn down) and we need to hook up with the new one. */ private void handleUpdateSharedContext(EGLContext newSharedContext) { Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext); // Release the EGLSurface and EGLContext. mInputWindowSurface.releaseEglSurface(); mInput.destroy(); mEglCore.release(); // Create a new EGLContext and recreate the window surface. mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE); mInputWindowSurface.recreate(mEglCore); mInputWindowSurface.makeCurrent(); // Create new programs and such for the new context. mInput = new MagicCameraInputFilter(); mInput.init(); filter = MagicFilterFactory.getInstance().newGPUImageFilterGroup(); if(filter != null){ filter.init(); filter.onDisplaySizeChanged(mVideoWidth, mVideoHeight); filter.onInputSizeChanged(mPreviewWidth, mPreviewHeight); } }
Example #12
Source File: TextureMovieEncoder.java From TikTok with Apache License 2.0 | 6 votes |
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate, File outputFile) { try { mVideoEncoder = new ImageEncoderCore(width, height, mOnImageEncoderListener); } catch (Exception ioe) { throw new RuntimeException(ioe); } mVideoWidth = width; mVideoHeight = height; mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE); mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true); mInputWindowSurface.makeCurrent(); mInput = new MagicCameraInputFilter(); mInput.init(); filter = MagicFilterFactory.getInstance().newGPUImageFilterGroup(); if(filter != null){ filter.init(); filter.onDisplaySizeChanged(mVideoWidth, mVideoHeight); filter.onInputSizeChanged(mPreviewWidth, mPreviewHeight); } }
Example #13
Source File: EglCore.java From sealrtc-android with MIT License | 6 votes |
/** Writes the current display, context, and surface to the log. */ public static void logCurrent(String msg) { EGLDisplay display; EGLContext context; EGLSurface surface; display = EGL14.eglGetCurrentDisplay(); context = EGL14.eglGetCurrentContext(); surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); Log.i( TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface); }
Example #14
Source File: RenderHandler.java From In77Camera with MIT License | 6 votes |
public final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface, final boolean isRecordable) { if (DEBUG) Log.i(TAG, "setEglContext:"); if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder)) throw new RuntimeException("unsupported window type:" + surface); synchronized (mSync) { if (mRequestRelease) return; mShard_context = shared_context; mTexId = tex_id; mSurface = surface; mIsRecordable = isRecordable; mRequestSetEglContext = true; mSync.notifyAll(); try { mSync.wait(); } catch (final InterruptedException e) { } } }
Example #15
Source File: EglUtil.java From SimpleVideoEditor with Apache License 2.0 | 6 votes |
/** * Destroys the GL context identified by {@code eglDisplay} and {@code eglContext}. */ static void destroyEglContext(EGLDisplay eglDisplay, EGLContext eglContext) { EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); int error = EGL14.eglGetError(); if (error != EGL14.EGL_SUCCESS) { throw new RuntimeException("error releasing context: " + error); } EGL14.eglDestroyContext(eglDisplay, eglContext); error = EGL14.eglGetError(); if (error != EGL14.EGL_SUCCESS) { throw new RuntimeException("error destroying context: " + error); } }
Example #16
Source File: EGLSurfaceTexture.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private static EGLContext createEGLContext( EGLDisplay display, EGLConfig config, @SecureMode int secureMode) { int[] glAttributes; if (secureMode == SECURE_MODE_NONE) { glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; } else { glAttributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL_PROTECTED_CONTENT_EXT, EGL14.EGL_TRUE, EGL14.EGL_NONE }; } EGLContext context = EGL14.eglCreateContext( display, config, android.opengl.EGL14.EGL_NO_CONTEXT, glAttributes, 0); if (context == null) { throw new GlException("eglCreateContext failed"); } return context; }
Example #17
Source File: TextureMovieEncoder.java From mobile-ar-sensor-logger with GNU General Public License v3.0 | 5 votes |
@Override // runs on encoder thread public void handleMessage(Message inputMessage) { int what = inputMessage.what; Object obj = inputMessage.obj; TextureMovieEncoder encoder = mWeakEncoder.get(); if (encoder == null) { Log.w(TAG, "EncoderHandler.handleMessage: encoder is null"); return; } switch (what) { case MSG_START_RECORDING: encoder.handleStartRecording((EncoderConfig) obj); break; case MSG_STOP_RECORDING: encoder.handleStopRecording(); break; case MSG_FRAME_AVAILABLE: long timestamp = (((long) inputMessage.arg1) << 32) | (((long) inputMessage.arg2) & 0xffffffffL); encoder.handleFrameAvailable((float[]) obj, timestamp); break; case MSG_SET_TEXTURE_ID: encoder.handleSetTexture(inputMessage.arg1); break; case MSG_UPDATE_SHARED_CONTEXT: encoder.handleUpdateSharedContext((EGLContext) inputMessage.obj); break; case MSG_QUIT: Looper.myLooper().quit(); break; default: throw new RuntimeException("Unhandled msg what=" + what); } }
Example #18
Source File: EglRenderThread.java From AudioVideoCodec with Apache License 2.0 | 5 votes |
public EglRenderThread(Surface surface, EGLContext eglContext, EglSurfaceView.Render surfaceRender, int renderMode, int width, int height) { this.surface = surface; this.eglContext = eglContext; this.surfaceRender = surfaceRender; this.renderMode = renderMode; this.width = width; this.height = height; }
Example #19
Source File: TextureMovieEncoder.java From mobile-ar-sensor-logger with GNU General Public License v3.0 | 5 votes |
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate, String outputFile, String metaFile) { try { mVideoEncoder = new VideoEncoderCore( width, height, bitRate, outputFile, metaFile); } catch (IOException ioe) { throw new RuntimeException(ioe); } mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE); mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true); mInputWindowSurface.makeCurrent(); mFullScreen = new FullFrameRect( new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT)); }
Example #20
Source File: EGLBase.java From CameraRecorder-android with MIT License | 5 votes |
private void init(EGLContext shared_context, final boolean with_depth_buffer, final boolean isRecordable) { if (DEBUG) Log.v(TAG, "init:"); if (eglDisplay != EGL14.EGL_NO_DISPLAY) { throw new RuntimeException("EGL already set up"); } eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); if (eglDisplay == EGL14.EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed"); } final int[] version = new int[2]; if (!EGL14.eglInitialize(eglDisplay, version, 0, version, 1)) { eglDisplay = null; throw new RuntimeException("eglInitialize failed"); } shared_context = shared_context != null ? shared_context : EGL14.EGL_NO_CONTEXT; if (eglContext == EGL14.EGL_NO_CONTEXT) { eglConfig = getConfig(with_depth_buffer, isRecordable); if (eglConfig == null) { throw new RuntimeException("chooseConfig failed"); } // create EGL rendering context eglContext = createContext(shared_context); } // confirm whether the EGL rendering context is successfully created final int[] values = new int[1]; EGL14.eglQueryContext(eglDisplay, eglContext, EGL14.EGL_CONTEXT_CLIENT_VERSION, values, 0); if (DEBUG) Log.d(TAG, "EGLContext created, client version " + values[0]); makeDefault(); // makeCurrent(EGL14.EGL_NO_SURFACE); }
Example #21
Source File: EglCore.java From VIA-AI with MIT License | 5 votes |
/** * Writes the current display, context, and surface to the log. */ public static void logCurrent(String msg) { EGLDisplay display; EGLContext context; EGLSurface surface; display = EGL14.eglGetCurrentDisplay(); context = EGL14.eglGetCurrentContext(); surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface); }
Example #22
Source File: EncoderSurface.java From Mp4Composer-android with MIT License | 5 votes |
/** * Creates an EncoderSurface from a Surface. */ EncoderSurface(Surface surface, EGLContext shareContext) { if (surface == null) { throw new NullPointerException(); } this.surface = surface; eglSetup(shareContext); }
Example #23
Source File: EglContextHacker.java From UltraGpuImage with MIT License | 5 votes |
public static EGLContext getContextFromEglBase(EglBase eglBase) { EglBase.Context context = eglBase.getEglBaseContext(); try { Field f = context.getClass().getDeclaredField("egl14Context"); f.setAccessible(true); return (EGLContext) f.get(context); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } return null; }
Example #24
Source File: EGLBase.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
private void init(EGLContext shared_context, final boolean with_depth_buffer, final boolean isRecordable) { LogUtil.i(TAG, "init:"); if (mEglDisplay != EGL14.EGL_NO_DISPLAY) { throw new RuntimeException("EGL already set up"); } mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL14.EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed"); } final int[] version = new int[2]; if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) { mEglDisplay = null; throw new RuntimeException("eglInitialize failed"); } shared_context = shared_context != null ? shared_context : EGL14.EGL_NO_CONTEXT; if (mEglContext == EGL14.EGL_NO_CONTEXT) { mEglConfig = getConfig(with_depth_buffer, isRecordable); if (mEglConfig == null) { throw new RuntimeException("chooseConfig failed"); } // create EGL rendering context mEglContext = createContext(shared_context); } // confirm whether the EGL rendering context is successfully created final int[] values = new int[1]; EGL14.eglQueryContext(mEglDisplay, mEglContext, EGL14.EGL_CONTEXT_CLIENT_VERSION, values, 0); LogUtil.i(TAG, "EGLContext created, client version " + values[0]); makeDefault(); // makeCurrent(EGL14.EGL_NO_SURFACE); }
Example #25
Source File: EGLBase.java From In77Camera with MIT License | 5 votes |
private EGLContext createContext(final EGLContext shared_context) { // if (DEBUG) Log.v(TAG, "createContext:"); final int[] attrib_list = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE }; final EGLContext context = EGL14.eglCreateContext(mEglDisplay, mEglConfig, shared_context, attrib_list, 0); checkEglError("eglCreateContext"); return context; }
Example #26
Source File: EGLBase.java From In77Camera with MIT License | 5 votes |
private void init(EGLContext shared_context, final boolean with_depth_buffer, final boolean isRecordable) { if (DEBUG) Log.v(TAG, "init:"); if (mEglDisplay != EGL14.EGL_NO_DISPLAY) { throw new RuntimeException("EGL already set up"); } mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL14.EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed"); } final int[] version = new int[2]; if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) { mEglDisplay = null; throw new RuntimeException("eglInitialize failed"); } shared_context = shared_context != null ? shared_context : EGL14.EGL_NO_CONTEXT; if (mEglContext == EGL14.EGL_NO_CONTEXT) { mEglConfig = getConfig(with_depth_buffer, isRecordable); if (mEglConfig == null) { throw new RuntimeException("chooseConfig failed"); } // create EGL rendering context mEglContext = createContext(shared_context); } // confirm whether the EGL rendering context is successfully created final int[] values = new int[1]; EGL14.eglQueryContext(mEglDisplay, mEglContext, EGL14.EGL_CONTEXT_CLIENT_VERSION, values, 0); if (DEBUG) Log.d(TAG, "EGLContext created, client version " + values[0]); makeDefault(); // makeCurrent(EGL14.EGL_NO_SURFACE); }
Example #27
Source File: Streamer.java From RtmpPublisher with Apache License 2.0 | 5 votes |
void startStreaming(EGLContext context, int width, int height, int audioBitrate, int videoBitrate) { if (muxer.isConnected()) { long startStreamingAt = System.currentTimeMillis(); videoHandler.setOnVideoEncoderStateListener(this); audioHandler.setOnAudioEncoderStateListener(this); videoHandler.start(width, height, videoBitrate, context, startStreamingAt); audioHandler.start(audioBitrate, startStreamingAt); } }
Example #28
Source File: VideoHandler.java From RtmpPublisher with Apache License 2.0 | 5 votes |
void start(final int width, final int height, final int bitRate, final EGLContext sharedEglContext, final long startStreamingAt) { handler.post(new Runnable() { @Override public void run() { try { videoEncoder.prepare(width, height, bitRate, FRAME_RATE, startStreamingAt); videoEncoder.start(); videoRenderer.initialize(sharedEglContext, videoEncoder.getInputSurface()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }); }
Example #29
Source File: EglCore.java From RtmpPublisher with Apache License 2.0 | 5 votes |
/** * Writes the current display, context, and surface to the log. */ public static void logCurrent(String msg) { EGLDisplay display; EGLContext context; EGLSurface surface; display = EGL14.eglGetCurrentDisplay(); context = EGL14.eglGetCurrentContext(); surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface); }
Example #30
Source File: EglCore.java From PhotoMovie with Apache License 2.0 | 5 votes |
/** * Writes the current display, context, and surface to the log. */ public static void logCurrent(String msg) { EGLDisplay display; EGLContext context; EGLSurface surface; display = EGL14.eglGetCurrentDisplay(); context = EGL14.eglGetCurrentContext(); surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface); }