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

Commit 33069f40 authored by Igor Murashkin's avatar Igor Murashkin Committed by Android Git Automerger
Browse files

am 47869404: am 2cad64c0: Merge "Surface: Change OutOfResourcesException to be...

am 47869404: am 2cad64c0: Merge "Surface: Change OutOfResourcesException to be a runtime exception" into klp-dev

* commit '47869404':
  Surface: Change OutOfResourcesException to be a runtime exception
parents 2805ec57 47869404
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -9966,7 +9966,7 @@ package android.graphics {
    method public abstract void onFrameAvailable(android.graphics.SurfaceTexture);
  }
  public static class SurfaceTexture.OutOfResourcesException extends java.lang.Exception {
  public static deprecated class SurfaceTexture.OutOfResourcesException extends java.lang.Exception {
    ctor public SurfaceTexture.OutOfResourcesException();
    ctor public SurfaceTexture.OutOfResourcesException(java.lang.String);
  }
@@ -27366,7 +27366,7 @@ package android.view {
    field public static final int ROTATION_90 = 1; // 0x1
  }
  public static class Surface.OutOfResourcesException extends java.lang.Exception {
  public static class Surface.OutOfResourcesException extends java.lang.RuntimeException {
    ctor public Surface.OutOfResourcesException();
    ctor public Surface.OutOfResourcesException(java.lang.String);
  }
+58 −56
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Surface.OutOfResourcesException;

import com.google.android.gles_jni.EGLImpl;

import javax.microedition.khronos.egl.EGL10;
@@ -270,14 +272,14 @@ public abstract class HardwareRenderer {
     *
     * @return True if the initialization was successful, false otherwise.
     */
    abstract boolean initialize(Surface surface) throws Surface.OutOfResourcesException;
    abstract boolean initialize(Surface surface) throws OutOfResourcesException;

    /**
     * Updates the hardware renderer for the specified surface.
     *
     * @param surface The surface to hardware accelerate
     */
    abstract void updateSurface(Surface surface) throws Surface.OutOfResourcesException;
    abstract void updateSurface(Surface surface) throws OutOfResourcesException;

    /**
     * Destroys the layers used by the specified view hierarchy.
@@ -596,7 +598,7 @@ public abstract class HardwareRenderer {
     *         false might mean that the surface was already initialized.
     */
    boolean initializeIfNeeded(int width, int height, Surface surface)
            throws Surface.OutOfResourcesException {
            throws OutOfResourcesException {
        if (isRequested()) {
            // We lost the gl context, so recreate it.
            if (!isEnabled()) {
@@ -1050,7 +1052,7 @@ public abstract class HardwareRenderer {
        }

        @Override
        boolean initialize(Surface surface) throws Surface.OutOfResourcesException {
        boolean initialize(Surface surface) throws OutOfResourcesException {
            if (isRequested() && !isEnabled()) {
                boolean contextCreated = initializeEgl();
                mGl = createEglSurface(surface);
@@ -1080,7 +1082,7 @@ public abstract class HardwareRenderer {
        }

        @Override
        void updateSurface(Surface surface) throws Surface.OutOfResourcesException {
        void updateSurface(Surface surface) throws OutOfResourcesException {
            if (isRequested() && isEnabled()) {
                createEglSurface(surface);
            }
@@ -1216,7 +1218,7 @@ public abstract class HardwareRenderer {
            Log.d(LOG_TAG, "  CONFIG_CAVEAT = 0x" + Integer.toHexString(value[0]));
        }

        GL createEglSurface(Surface surface) throws Surface.OutOfResourcesException {
        GL createEglSurface(Surface surface) throws OutOfResourcesException {
            // Check preconditions.
            if (sEgl == null) {
                throw new RuntimeException("egl not initialized");
+12 −11
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ public class Surface implements Parcelable {
     *
     * @param surfaceTexture The {@link SurfaceTexture} that is updated by this
     * Surface.
     * @throws OutOfResourcesException if the surface could not be created.
     */
    public Surface(SurfaceTexture surfaceTexture) {
        if (surfaceTexture == null) {
@@ -124,12 +125,7 @@ public class Surface implements Parcelable {

        synchronized (mLock) {
            mName = surfaceTexture.toString();
            try {
            setNativeObjectLocked(nativeCreateFromSurfaceTexture(surfaceTexture));
            } catch (OutOfResourcesException ex) {
                // We can't throw OutOfResourcesException because it would be an API change.
                throw new RuntimeException(ex);
            }
        }
    }

@@ -229,9 +225,12 @@ public class Surface implements Parcelable {
     * The caller may also pass <code>null</code> instead, in the case where the
     * entire surface should be redrawn.
     * @return A canvas for drawing into the surface.
     *
     * @throws IllegalArgumentException If the inOutDirty rectangle is not valid.
     * @throws OutOfResourcesException If the canvas cannot be locked.
     */
    public Canvas lockCanvas(Rect inOutDirty)
            throws OutOfResourcesException, IllegalArgumentException {
            throws Surface.OutOfResourcesException, IllegalArgumentException {
        synchronized (mLock) {
            checkNotReleasedLocked();
            if (mLockedObject != 0) {
@@ -239,7 +238,7 @@ public class Surface implements Parcelable {
                // double-lock, but that won't happen if mNativeObject was updated.  We can't
                // abandon the old mLockedObject because it might still be in use, so instead
                // we just refuse to re-lock the Surface.
                throw new RuntimeException("Surface was already locked");
                throw new IllegalStateException("Surface was already locked");
            }
            mLockedObject = nativeLockCanvas(mNativeObject, mCanvas, inOutDirty);
            return mCanvas;
@@ -266,7 +265,7 @@ public class Surface implements Parcelable {
                        Integer.toHexString(mLockedObject) +")");
            }
            if (mLockedObject == 0) {
                throw new RuntimeException("Surface was not locked");
                throw new IllegalStateException("Surface was not locked");
            }
            nativeUnlockCanvasAndPost(mLockedObject, canvas);
            nativeRelease(mLockedObject);
@@ -411,9 +410,11 @@ public class Surface implements Parcelable {
    }

    /**
     * Exception thrown when a surface couldn't be created or resized.
     * Exception thrown when a Canvas couldn't be locked with {@link Surface#lockCanvas}, or
     * when a SurfaceTexture could not successfully be allocated.
     */
    public static class OutOfResourcesException extends Exception {
    @SuppressWarnings("serial")
    public static class OutOfResourcesException extends RuntimeException {
        public OutOfResourcesException() {
        }
        public OutOfResourcesException(String name) {
+4 −12
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.view.Surface;
import android.os.IBinder;
import android.os.SystemProperties;
import android.util.Log;
import android.view.Surface.OutOfResourcesException;

/**
 * SurfaceControl
@@ -75,23 +76,12 @@ public class SurfaceControl {


    private final CloseGuard mCloseGuard = CloseGuard.get();
    private String mName;
    private final String mName;
    int mNativeObject; // package visibility only for Surface.java access

    private static final boolean HEADLESS = "1".equals(
        SystemProperties.get("ro.config.headless", "0"));

    /**
     * Exception thrown when a surface couldn't be created or resized.
     */
    public static class OutOfResourcesException extends Exception {
        public OutOfResourcesException() {
        }
        public OutOfResourcesException(String name) {
            super(name);
        }
    }

    /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */

    /**
@@ -220,6 +210,8 @@ public class SurfaceControl {
     * @param h The surface initial height.
     * @param flags The surface creation flags.  Should always include {@link #HIDDEN}
     * in the creation flags.
     *
     * @throws throws OutOfResourcesException If the SurfaceControl cannot be created.
     */
    public SurfaceControl(SurfaceSession session,
            String name, int w, int h, int format, int flags)
+56 −38
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ public class SurfaceView extends View {

    final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener
            = new ViewTreeObserver.OnScrollChangedListener() {
                    @Override
                    public void onScrollChanged() {
                        updateWindow(false, false);
                    }
@@ -672,10 +673,12 @@ public class SurfaceView extends View {
            }
        }

        @Override
        public void dispatchAppVisibility(boolean visible) {
            // The point of SurfaceView is to let the app control the surface.
        }

        @Override
        public void dispatchGetNewSurface() {
            SurfaceView surfaceView = mSurfaceView.get();
            if (surfaceView != null) {
@@ -684,10 +687,12 @@ public class SurfaceView extends View {
            }
        }

        @Override
        public void windowFocusChanged(boolean hasFocus, boolean touchEnabled) {
            Log.w("SurfaceView", "Unexpected focus in surface: focus=" + hasFocus + ", touchEnabled=" + touchEnabled);
        }

        @Override
        public void executeCommand(String command, String parameters, ParcelFileDescriptor out) {
        }

@@ -695,14 +700,16 @@ public class SurfaceView extends View {
        int mCurHeight = -1;
    }

    private SurfaceHolder mSurfaceHolder = new SurfaceHolder() {
    private final SurfaceHolder mSurfaceHolder = new SurfaceHolder() {

        private static final String LOG_TAG = "SurfaceHolder";

        @Override
        public boolean isCreating() {
            return mIsCreating;
        }

        @Override
        public void addCallback(Callback callback) {
            synchronized (mCallbacks) {
                // This is a linear search, but in practice we'll
@@ -713,12 +720,14 @@ public class SurfaceView extends View {
            }
        }

        @Override
        public void removeCallback(Callback callback) {
            synchronized (mCallbacks) {
                mCallbacks.remove(callback);
            }
        }

        @Override
        public void setFixedSize(int width, int height) {
            if (mRequestedWidth != width || mRequestedHeight != height) {
                mRequestedWidth = width;
@@ -727,6 +736,7 @@ public class SurfaceView extends View {
            }
        }

        @Override
        public void setSizeFromLayout() {
            if (mRequestedWidth != -1 || mRequestedHeight != -1) {
                mRequestedWidth = mRequestedHeight = -1;
@@ -734,6 +744,7 @@ public class SurfaceView extends View {
            }
        }

        @Override
        public void setFormat(int format) {

            // for backward compatibility reason, OPAQUE always
@@ -750,9 +761,11 @@ public class SurfaceView extends View {
        /**
         * @deprecated setType is now ignored.
         */
        @Override
        @Deprecated
        public void setType(int type) { }

        @Override
        public void setKeepScreenOn(boolean screenOn) {
            Message msg = mHandler.obtainMessage(KEEP_SCREEN_ON_MSG);
            msg.arg1 = screenOn ? 1 : 0;
@@ -768,6 +781,7 @@ public class SurfaceView extends View {
         * The caller must redraw the entire surface.
         * @return A canvas for drawing into the surface.
         */
        @Override
        public Canvas lockCanvas() {
            return internalLockCanvas(null);
        }
@@ -787,6 +801,7 @@ public class SurfaceView extends View {
         * entire surface should be redrawn.
         * @return A canvas for drawing into the surface.
         */
        @Override
        public Canvas lockCanvas(Rect inOutDirty) {
            return internalLockCanvas(inOutDirty);
        }
@@ -836,15 +851,18 @@ public class SurfaceView extends View {
         *
         * @param canvas The canvas previously obtained from {@link #lockCanvas}.
         */
        @Override
        public void unlockCanvasAndPost(Canvas canvas) {
            mSurface.unlockCanvasAndPost(canvas);
            mSurfaceLock.unlock();
        }

        @Override
        public Surface getSurface() {
            return mSurface;
        }

        @Override
        public Rect getSurfaceFrame() {
            return mSurfaceFrame;
        }
Loading