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

Commit 181c3fee authored by Tim Murray's avatar Tim Murray
Browse files

DisplayTransformManager: use a single SurfaceFlinger handle

Don't grab SurfaceFlinger every time. SurfaceFlinger can't change.

Test: boots, works
bug 140788621

Change-Id: I72ffef6858eeff82699663c13548b666e25d55b0
parent d4425705
Loading
Loading
Loading
Loading
+58 −71
Original line number Diff line number Diff line
@@ -111,6 +111,8 @@ public class DisplayTransformManager {
    @GuardedBy("mDaltonizerModeLock")
    private int mDaltonizerMode = -1;

    private static final IBinder sFlinger = ServiceManager.getService(SURFACE_FLINGER);

    /* package */ DisplayTransformManager() {
    }

@@ -195,8 +197,6 @@ public class DisplayTransformManager {
     * Propagates the provided color transformation matrix to the SurfaceFlinger.
     */
    private static void applyColorMatrix(float[] m) {
        final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER);
        if (flinger != null) {
        final Parcel data = Parcel.obtain();
        data.writeInterfaceToken("android.ui.ISurfaceComposer");
        if (m != null) {
@@ -208,33 +208,29 @@ public class DisplayTransformManager {
            data.writeInt(0);
        }
        try {
                flinger.transact(SURFACE_FLINGER_TRANSACTION_COLOR_MATRIX, data, null, 0);
            sFlinger.transact(SURFACE_FLINGER_TRANSACTION_COLOR_MATRIX, data, null, 0);
        } catch (RemoteException ex) {
            Slog.e(TAG, "Failed to set color transform", ex);
        } finally {
            data.recycle();
        }
    }
    }

    /**
     * Propagates the provided Daltonization mode to the SurfaceFlinger.
     */
    private static void applyDaltonizerMode(int mode) {
        final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER);
        if (flinger != null) {
        final Parcel data = Parcel.obtain();
        data.writeInterfaceToken("android.ui.ISurfaceComposer");
        data.writeInt(mode);
        try {
                flinger.transact(SURFACE_FLINGER_TRANSACTION_DALTONIZER, data, null, 0);
            sFlinger.transact(SURFACE_FLINGER_TRANSACTION_DALTONIZER, data, null, 0);
        } catch (RemoteException ex) {
            Slog.e(TAG, "Failed to set Daltonizer mode", ex);
        } finally {
            data.recycle();
        }
    }
    }

    /**
     * Return true when the color matrix works in linear space.
@@ -286,13 +282,11 @@ public class DisplayTransformManager {
     * #SURFACE_FLINGER_TRANSACTION_QUERY_COLOR_MANAGED}.
     */
    public boolean isDeviceColorManaged() {
        final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER);
        if (flinger != null) {
        final Parcel data = Parcel.obtain();
        final Parcel reply = Parcel.obtain();
        data.writeInterfaceToken("android.ui.ISurfaceComposer");
        try {
                flinger.transact(SURFACE_FLINGER_TRANSACTION_QUERY_COLOR_MANAGED, data, reply, 0);
            sFlinger.transact(SURFACE_FLINGER_TRANSACTION_QUERY_COLOR_MANAGED, data, reply, 0);
            return reply.readBoolean();
        } catch (RemoteException ex) {
            Slog.e(TAG, "Failed to query wide color support", ex);
@@ -300,7 +294,6 @@ public class DisplayTransformManager {
            data.recycle();
            reply.recycle();
        }
        }
        return false;
    }

@@ -309,20 +302,17 @@ public class DisplayTransformManager {
     */
    private void applySaturation(float saturation) {
        SystemProperties.set(PERSISTENT_PROPERTY_SATURATION, Float.toString(saturation));
        final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER);
        if (flinger != null) {
        final Parcel data = Parcel.obtain();
        data.writeInterfaceToken("android.ui.ISurfaceComposer");
        data.writeFloat(saturation);
        try {
                flinger.transact(SURFACE_FLINGER_TRANSACTION_SATURATION, data, null, 0);
            sFlinger.transact(SURFACE_FLINGER_TRANSACTION_SATURATION, data, null, 0);
        } catch (RemoteException ex) {
            Slog.e(TAG, "Failed to set saturation", ex);
        } finally {
            data.recycle();
        }
    }
    }

    /**
     * Toggles native mode on/off in SurfaceFlinger.
@@ -334,8 +324,6 @@ public class DisplayTransformManager {
                Integer.toString(compositionColorMode));
        }

        final IBinder flinger = ServiceManager.getService(SURFACE_FLINGER);
        if (flinger != null) {
        final Parcel data = Parcel.obtain();
        data.writeInterfaceToken("android.ui.ISurfaceComposer");
        data.writeInt(color);
@@ -343,14 +331,13 @@ public class DisplayTransformManager {
            data.writeInt(compositionColorMode);
        }
        try {
                flinger.transact(SURFACE_FLINGER_TRANSACTION_DISPLAY_COLOR, data, null, 0);
            sFlinger.transact(SURFACE_FLINGER_TRANSACTION_DISPLAY_COLOR, data, null, 0);
        } catch (RemoteException ex) {
            Slog.e(TAG, "Failed to set display color", ex);
        } finally {
            data.recycle();
        }
    }
    }

    private void updateConfiguration() {
        try {