Class EglCore


  • public final class EglCore
    extends java.lang.Object
    Core EGL state (display, context, config).

    The EGLContext must only be attached to one thread at a time. This class is not thread-safe.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int FLAG_RECORDABLE
      Constructor flag: surface must be recordable.
      static int FLAG_TRY_GLES3
      Constructor flag: ask for GLES3, fall back to GLES2 if not available.
    • Constructor Summary

      Constructors 
      Constructor Description
      EglCore()
      Prepares EGL display and context.
      EglCore​(android.opengl.EGLContext sharedContext, int flags)
      Prepares EGL display and context.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      android.opengl.EGLSurface createOffscreenSurface​(int width, int height)
      Creates an EGL surface associated with an offscreen buffer.
      android.opengl.EGLSurface createWindowSurface​(java.lang.Object surface)
      Creates an EGL surface associated with a Surface.
      protected void finalize()  
      android.opengl.EGLContext getEGLContext()  
      int getGlVersion()
      Returns the GLES version this context is configured for (currently 2 or 3).
      boolean isCurrent​(android.opengl.EGLSurface eglSurface)
      Returns true if our context and the specified surface are current.
      static void logCurrent​(java.lang.String msg)
      Writes the current display, context, and surface to the log
      void makeCurrent​(android.opengl.EGLSurface eglSurface)
      Makes our EGL context current, using the supplied surface for both "draw" and "read".
      void makeCurrent​(android.opengl.EGLSurface drawSurface, android.opengl.EGLSurface readSurface)
      Makes our EGL context current, using the supplied "draw" and "read" surfaces.
      void makeNothingCurrent()
      Makes no context current.
      java.lang.String queryString​(int what)
      Queries a string value.
      int querySurface​(android.opengl.EGLSurface eglSurface, int what)
      Performs a simple surface query.
      void release()
      Discards all resources held by this class, notably the EGL context.
      void releaseSurface​(android.opengl.EGLSurface eglSurface)
      Destroys the specified surface.
      void setPresentationTime​(android.opengl.EGLSurface eglSurface, long nsecs)
      Sends the presentation time stamp to EGL.
      boolean swapBuffers​(android.opengl.EGLSurface eglSurface)
      Calls eglSwapBuffers.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FLAG_RECORDABLE

        public static final int FLAG_RECORDABLE
        Constructor flag: surface must be recordable. This discourages EGL from using a pixel format that cannot be converted efficiently to something usable by the video encoder.
        See Also:
        Constant Field Values
      • FLAG_TRY_GLES3

        public static final int FLAG_TRY_GLES3
        Constructor flag: ask for GLES3, fall back to GLES2 if not available. Without this flag, GLES2 is used.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EglCore

        public EglCore()
        Prepares EGL display and context.

        Equivalent to EglCore(null, 0).

      • EglCore

        public EglCore​(android.opengl.EGLContext sharedContext,
                       int flags)
        Prepares EGL display and context.

        Parameters:
        sharedContext - The context to share, or null if sharing is not desired.
        flags - Configuration bit flags, e.g. FLAG_RECORDABLE.
    • Method Detail

      • getEGLContext

        public android.opengl.EGLContext getEGLContext()
      • release

        public void release()
        Discards all resources held by this class, notably the EGL context. This must be called from the thread where the context was created.

        On completion, no context will be current.

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • releaseSurface

        public void releaseSurface​(android.opengl.EGLSurface eglSurface)
        Destroys the specified surface. Note the EGLSurface won't actually be destroyed if it's still current in a context.
      • createWindowSurface

        public android.opengl.EGLSurface createWindowSurface​(java.lang.Object surface)
        Creates an EGL surface associated with a Surface.

        If this is destined for MediaCodec, the EGLConfig should have the "recordable" attribute.

      • createOffscreenSurface

        public android.opengl.EGLSurface createOffscreenSurface​(int width,
                                                                int height)
        Creates an EGL surface associated with an offscreen buffer.
      • makeCurrent

        public void makeCurrent​(android.opengl.EGLSurface eglSurface)
        Makes our EGL context current, using the supplied surface for both "draw" and "read".
      • makeCurrent

        public void makeCurrent​(android.opengl.EGLSurface drawSurface,
                                android.opengl.EGLSurface readSurface)
        Makes our EGL context current, using the supplied "draw" and "read" surfaces.
      • makeNothingCurrent

        public void makeNothingCurrent()
        Makes no context current.
      • swapBuffers

        public boolean swapBuffers​(android.opengl.EGLSurface eglSurface)
        Calls eglSwapBuffers. Use this to "publish" the current frame.
        Returns:
        false on failure
      • setPresentationTime

        public void setPresentationTime​(android.opengl.EGLSurface eglSurface,
                                        long nsecs)
        Sends the presentation time stamp to EGL. Time is expressed in nanoseconds.
      • isCurrent

        public boolean isCurrent​(android.opengl.EGLSurface eglSurface)
        Returns true if our context and the specified surface are current.
      • querySurface

        public int querySurface​(android.opengl.EGLSurface eglSurface,
                                int what)
        Performs a simple surface query.
      • queryString

        public java.lang.String queryString​(int what)
        Queries a string value.
      • getGlVersion

        public int getGlVersion()
        Returns the GLES version this context is configured for (currently 2 or 3).
      • logCurrent

        public static void logCurrent​(java.lang.String msg)
        Writes the current display, context, and surface to the log