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

Commit 63cf0752 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Make HardwareRenderer able to target generic Surface objects"

parents f33efd9c 786fc93d
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -197,18 +197,18 @@ public abstract class HardwareRenderer {
    /**
     * Initializes the hardware renderer for the specified surface.
     * 
     * @param holder The holder for the surface to hardware accelerate.
     * @param surface The surface to hardware accelerate
     * 
     * @return True if the initialization was successful, false otherwise.
     */
    abstract boolean initialize(SurfaceHolder holder) throws Surface.OutOfResourcesException;
    abstract boolean initialize(Surface surface) throws Surface.OutOfResourcesException;
    
    /**
     * Updates the hardware renderer for the specified surface.
     *
     * @param holder The holder for the surface to hardware accelerate
     * @param surface The surface to hardware accelerate
     */
    abstract void updateSurface(SurfaceHolder holder) throws Surface.OutOfResourcesException;
    abstract void updateSurface(Surface surface) throws Surface.OutOfResourcesException;

    /**
     * Destroys the layers used by the specified view hierarchy.
@@ -229,9 +229,9 @@ public abstract class HardwareRenderer {
     * This method should be invoked whenever the current hardware renderer
     * context should be reset.
     *
     * @param holder The holder for the surface to hardware accelerate
     * @param surface The surface to hardware accelerate
     */
    abstract void invalidate(SurfaceHolder holder);
    abstract void invalidate(Surface surface);

    /**
     * This method should be invoked to ensure the hardware renderer is in
@@ -474,14 +474,14 @@ public abstract class HardwareRenderer {
     *
     * @param width The width of the drawing surface.
     * @param height The height of the drawing surface.
     * @param holder The target surface
     * @param surface The surface to hardware accelerate
     */
    void initializeIfNeeded(int width, int height, SurfaceHolder holder)
    void initializeIfNeeded(int width, int height, Surface surface)
            throws Surface.OutOfResourcesException {
        if (isRequested()) {
            // We lost the gl context, so recreate it.
            if (!isEnabled()) {
                if (initialize(holder)) {
                if (initialize(surface)) {
                    setup(width, height);
                }
            }
@@ -742,10 +742,10 @@ public abstract class HardwareRenderer {
        }

        @Override
        boolean initialize(SurfaceHolder holder) throws Surface.OutOfResourcesException {
        boolean initialize(Surface surface) throws Surface.OutOfResourcesException {
            if (isRequested() && !isEnabled()) {
                initializeEgl();
                mGl = createEglSurface(holder);
                mGl = createEglSurface(surface);
                mDestroyed = false;

                if (mGl != null) {
@@ -771,9 +771,9 @@ public abstract class HardwareRenderer {
        }
        
        @Override
        void updateSurface(SurfaceHolder holder) throws Surface.OutOfResourcesException {
        void updateSurface(Surface surface) throws Surface.OutOfResourcesException {
            if (isRequested() && isEnabled()) {
                createEglSurface(holder);
                createEglSurface(surface);
            }
        }

@@ -888,7 +888,7 @@ public abstract class HardwareRenderer {
            Log.d(LOG_TAG, "  SURFACE_TYPE = 0x" + Integer.toHexString(value[0]));
        }

        GL createEglSurface(SurfaceHolder holder) throws Surface.OutOfResourcesException {
        GL createEglSurface(Surface surface) throws Surface.OutOfResourcesException {
            // Check preconditions.
            if (sEgl == null) {
                throw new RuntimeException("egl not initialized");
@@ -908,7 +908,7 @@ public abstract class HardwareRenderer {
            destroySurface();

            // Create an EGL surface we can render into.
            if (!createSurface(holder)) {
            if (!createSurface(surface)) {
                return null;
            }

@@ -982,7 +982,7 @@ public abstract class HardwareRenderer {
        }

        @Override
        void invalidate(SurfaceHolder holder) {
        void invalidate(Surface surface) {
            // Cancels any existing buffer to ensure we'll get a buffer
            // of the right size before we call eglSwapBuffers
            sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@@ -993,8 +993,8 @@ public abstract class HardwareRenderer {
                setEnabled(false);
            }

            if (holder.getSurface().isValid()) {
                if (!createSurface(holder)) {
            if (surface.isValid()) {
                if (!createSurface(surface)) {
                    return;
                }

@@ -1006,8 +1006,8 @@ public abstract class HardwareRenderer {
            }
        }

        private boolean createSurface(SurfaceHolder holder) {
            mEglSurface = sEgl.eglCreateWindowSurface(sEglDisplay, sEglConfig, holder, null);
        private boolean createSurface(Surface surface) {
            mEglSurface = sEgl.eglCreateWindowSurface(sEglDisplay, sEglConfig, surface, null);

            if (mEglSurface == null || mEglSurface == EGL_NO_SURFACE) {
                int error = sEgl.eglGetError();
+5 −4
Original line number Diff line number Diff line
@@ -1500,7 +1500,8 @@ public final class ViewRootImpl implements ViewParent,

                        if (mAttachInfo.mHardwareRenderer != null) {
                            try {
                                hwInitialized = mAttachInfo.mHardwareRenderer.initialize(mHolder);
                                hwInitialized = mAttachInfo.mHardwareRenderer.initialize(
                                        mHolder.getSurface());
                            } catch (Surface.OutOfResourcesException e) {
                                Log.e(TAG, "OutOfResourcesException initializing HW surface", e);
                                try {
@@ -1533,7 +1534,7 @@ public final class ViewRootImpl implements ViewParent,
                        mSurfaceHolder == null && mAttachInfo.mHardwareRenderer != null) {
                    mFullRedrawNeeded = true;
                    try {
                        mAttachInfo.mHardwareRenderer.updateSurface(mHolder);
                        mAttachInfo.mHardwareRenderer.updateSurface(mHolder.getSurface());
                    } catch (Surface.OutOfResourcesException e) {
                        Log.e(TAG, "OutOfResourcesException updating HW surface", e);
                        try {
@@ -1624,7 +1625,7 @@ public final class ViewRootImpl implements ViewParent,
                        mHeight != mAttachInfo.mHardwareRenderer.getHeight()) {
                    mAttachInfo.mHardwareRenderer.setup(mWidth, mHeight);
                    if (!hwInitialized) {
                        mAttachInfo.mHardwareRenderer.invalidate(mHolder);
                        mAttachInfo.mHardwareRenderer.invalidate(mHolder.getSurface());
                    }
                }
            }
@@ -2887,7 +2888,7 @@ public final class ViewRootImpl implements ViewParent,
                            mFullRedrawNeeded = true;
                            try {
                                mAttachInfo.mHardwareRenderer.initializeIfNeeded(mWidth, mHeight,
                                        mHolder);
                                        mHolder.getSurface());
                            } catch (Surface.OutOfResourcesException e) {
                                Log.e(TAG, "OutOfResourcesException locking surface", e);
                                try {
+3 −2
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ public class EGLImpl implements EGL10 {
        } else if (native_window instanceof SurfaceHolder) {
            SurfaceHolder holder = (SurfaceHolder)native_window;
            sur = holder.getSurface();
        } else if (native_window instanceof Surface) {
            sur = (Surface) native_window;
        }

        int eglSurfaceId;
@@ -94,8 +96,7 @@ public class EGLImpl implements EGL10 {
        } else {
            throw new java.lang.UnsupportedOperationException(
                "eglCreateWindowSurface() can only be called with an instance of " +
                "SurfaceView, SurfaceHolder or SurfaceTexture at the moment, " + 
                "this will be fixed later.");
                "Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment.");
        }

        if (eglSurfaceId == 0) {
+4 −5
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
import android.opengl.GLUtils;
import android.os.Bundle;
@@ -278,7 +277,7 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa
            return texture;
        }
        
        private int buildProgram(String vertex, String fragment) {
        private static int buildProgram(String vertex, String fragment) {
            int vertexShader = buildShader(vertex, GL_VERTEX_SHADER);
            if (vertexShader == 0) return 0;

@@ -309,7 +308,7 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa
            return program;
        }
        
        private int buildShader(String source, int type) {
        private static int buildShader(String source, int type) {
            int shader = glCreateShader(type);

            glShaderSource(shader, source);
@@ -337,7 +336,7 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa
            }
        }

        private void checkGlError() {
        private static void checkGlError() {
            int error = glGetError();
            if (error != GL_NO_ERROR) {
                Log.w(LOG_TAG, "GL error = 0x" + Integer.toHexString(error));
@@ -420,7 +419,7 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa
            return null;
        }
        
        private int[] getConfig() {
        private static int[] getConfig() {
            return new int[] {
                    EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
                    EGL10.EGL_RED_SIZE, 8,