Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 912a7b32 authored by Romain Guy's avatar Romain Guy
Browse files

Make sure we have a current EGL context when invoking EGL

Bug #5081795

Change-Id: Iee3382d362a71c1e6c5c498b319bf7f7bcf5a2f0
parent 7c0d89ac
Loading
Loading
Loading
Loading
+34 −20
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public abstract class HardwareRenderer {
     *              see {@link android.content.ComponentCallbacks}
     */
    static void trimMemory(int level) {
        Gl20Renderer.flushCaches(level);
        Gl20Renderer.trimMemory(level);
    }

    /**
@@ -677,19 +677,10 @@ public abstract class HardwareRenderer {
        }

        EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
            int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, mGlVersion, EGL_NONE };
            int[] attribs = { EGL_CONTEXT_CLIENT_VERSION, mGlVersion, EGL_NONE };

            return egl.eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT,
                    mGlVersion != 0 ? attrib_list : null);            
        }

        @Override
        void initializeIfNeeded(int width, int height, View.AttachInfo attachInfo,
                SurfaceHolder holder) throws Surface.OutOfResourcesException {
            if (isRequested()) {
                checkEglErrors();
                super.initializeIfNeeded(width, height, attachInfo, holder);
            }
                    mGlVersion != 0 ? attribs : null);            
        }

        @Override
@@ -726,6 +717,7 @@ public abstract class HardwareRenderer {

        @Override
        void setup(int width, int height) {
            checkCurrent();
            mCanvas.setViewport(width, height);
        }

@@ -819,7 +811,7 @@ public abstract class HardwareRenderer {
         *         {@link #SURFACE_STATE_UPDATED} if the EGL context was changed or
         *         {@link #SURFACE_STATE_SUCCESS} if the EGL context was the correct one
         */
        private int checkCurrent() {
        int checkCurrent() {
            if (mEglThread != Thread.currentThread()) {
                throw new IllegalStateException("Hardware acceleration can only be used with a " +
                        "single UI thread.\nOriginal thread: " + mEglThread + "\n" +
@@ -847,6 +839,9 @@ public abstract class HardwareRenderer {
    static class Gl20Renderer extends GlRenderer {
        private GLES20Canvas mGlCanvas;

        private static EGLSurface sPbuffer;
        private static final Object[] sPbufferLock = new Object[0];

        Gl20Renderer(boolean translucent) {
            super(2, translucent);
        }
@@ -926,14 +921,26 @@ public abstract class HardwareRenderer {
            return ((GLES20TextureLayer) layer).getSurfaceTexture();
        }

        static HardwareRenderer create(boolean translucent) {
            if (GLES20Canvas.isAvailable()) {
                return new Gl20Renderer(translucent);
        static void trimMemory(int level) {
            if (sEgl == null || sEglConfig == null) return;

            EGLContext eglContext = sEglContextStorage.get();
            // We do not have OpenGL objects
            if (eglContext == null) {
                return;
            } else {
                synchronized (sPbufferLock) {
                    // Create a temporary 1x1 pbuffer so we have a context
                    // to clear our OpenGL objects
                    if (sPbuffer == null) {
                        sPbuffer = sEgl.eglCreatePbufferSurface(sEglDisplay, sEglConfig, new int[] {
                                EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE
                        });
                    }
            return null;
                }
                sEgl.eglMakeCurrent(sEglDisplay, sPbuffer, sPbuffer, eglContext);
            }

        static void flushCaches(int level) {
            switch (level) {
                case ComponentCallbacks.TRIM_MEMORY_MODERATE:
                    GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_MODERATE);
@@ -943,5 +950,12 @@ public abstract class HardwareRenderer {
                    break;
            }
        }

        static HardwareRenderer create(boolean translucent) {
            if (GLES20Canvas.isAvailable()) {
                return new Gl20Renderer(translucent);
            }
            return null;
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -235,6 +235,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,
    final Configuration mLastConfiguration = new Configuration();
    final Configuration mPendingConfiguration = new Configuration();

    
    class ResizedInfo {
        Rect coveredInsets;
        Rect visibleInsets;
+4 −0
Original line number Diff line number Diff line
@@ -191,6 +191,10 @@ struct Layer {
        if (texture.id) glDeleteTextures(1, &texture.id);
    }

    inline void deleteFbo() {
        if (fbo) glDeleteFramebuffers(1, &fbo);
    }

    inline void allocateTexture(GLenum format, GLenum storage) {
        glTexImage2D(renderTarget, 0, format, getWidth(), getHeight(), 0, format, storage, NULL);
    }
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ void LayerCache::setMaxSize(uint32_t maxSize) {
void LayerCache::deleteLayer(Layer* layer) {
    if (layer) {
        mSize -= layer->getWidth() * layer->getHeight() * 4;
        layer->deleteFbo();
        layer->deleteTexture();
        delete layer;
    }
+1 −1
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ void TextureCache::clearGarbage() {

void TextureCache::clear() {
    mCache.clear();
    TEXTURE_LOGD("TextureCache:clear(), miSize = %d", mSize);
    TEXTURE_LOGD("TextureCache:clear(), mSize = %d", mSize);
}

void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool regenerate) {