diff options
| author | 2020-05-01 15:45:09 -0700 | |
|---|---|---|
| committer | 2020-05-01 15:48:04 -0700 | |
| commit | 226849f197df78aef78dc270185c685ff8dca970 (patch) | |
| tree | 478068ea9b1dce57cab4799e2f0f4b1e497d4c36 /packages/SystemUI/shared | |
| parent | 479962ed01f29fb5c3092955d2fd51bf6acc9f61 (diff) | |
Exposing some ViewRoomImple methods in shared lib
This would allow us to implement SyncRtSurfaceTransactionApplierCompat directly in Launcher
so that we can better handle surface lifecycle
Also removing java 7 restriction from librayr as the latest gradle properly handle java-8 jars
Bug: 148885018
Bug: 148194313
Test: Verified jar works with Launcher
Change-Id: I57adfea4b41ce12c8f8f2697dc554feca7ccc6b6
Diffstat (limited to 'packages/SystemUI/shared')
6 files changed, 120 insertions, 41 deletions
diff --git a/packages/SystemUI/shared/Android.bp b/packages/SystemUI/shared/Android.bp index 592f6c2a0dff..68f4b746caa2 100644 --- a/packages/SystemUI/shared/Android.bp +++ b/packages/SystemUI/shared/Android.bp @@ -38,9 +38,7 @@ android_library { "PluginCoreLib", ], - // Enforce that the library is built against java 7 so that there are - // no compatibility issues with launcher - java_version: "1.7", + java_version: "1.8", min_sdk_version: "26", } diff --git a/packages/SystemUI/shared/AndroidManifest.xml b/packages/SystemUI/shared/AndroidManifest.xml index 43b9c7574141..aaadea6ec38f 100644 --- a/packages/SystemUI/shared/AndroidManifest.xml +++ b/packages/SystemUI/shared/AndroidManifest.xml @@ -18,7 +18,5 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.systemui.shared"> - <uses-sdk - android:minSdkVersion="26" /> </manifest> diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java index c2a4af93b917..acc691304ca5 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceControlCompat.java @@ -20,6 +20,9 @@ import android.view.SurfaceControl; import android.view.View; import android.view.ViewRootImpl; +/** + * TODO: Remove this class + */ public class SurfaceControlCompat { final SurfaceControl mSurfaceControl; @@ -37,4 +40,8 @@ public class SurfaceControlCompat { public boolean isValid() { return mSurfaceControl != null && mSurfaceControl.isValid(); } + + public SurfaceControl getSurfaceControl() { + return mSurfaceControl; + } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java index 2e6b195d6a16..31fe22e57084 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/SyncRtSurfaceTransactionApplierCompat.java @@ -23,8 +23,8 @@ import android.os.Handler; import android.os.Handler.Callback; import android.os.Message; import android.os.Trace; -import android.view.Surface; import android.view.SurfaceControl; +import android.view.SurfaceControl.Transaction; import android.view.View; import android.view.ViewRootImpl; @@ -108,13 +108,12 @@ public class SyncRtSurfaceTransactionApplierCompat { return; } Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Sync transaction frameNumber=" + frame); - TransactionCompat t = new TransactionCompat(); + Transaction t = new Transaction(); for (int i = params.length - 1; i >= 0; i--) { SyncRtSurfaceTransactionApplierCompat.SurfaceParams surfaceParams = params[i]; - SurfaceControlCompat surface = surfaceParams.surface; - t.deferTransactionUntil(surface, mBarrierSurfaceControl, frame); - applyParams(t, surfaceParams); + t.deferTransactionUntil(surfaceParams.surface, mBarrierSurfaceControl, frame); + surfaceParams.applyTo(t); } t.setEarlyWakeup(); t.apply(); @@ -152,31 +151,7 @@ public class SyncRtSurfaceTransactionApplierCompat { public static void applyParams(TransactionCompat t, SyncRtSurfaceTransactionApplierCompat.SurfaceParams params) { - if ((params.flags & FLAG_MATRIX) != 0) { - t.setMatrix(params.surface, params.matrix); - } - if ((params.flags & FLAG_WINDOW_CROP) != 0) { - t.setWindowCrop(params.surface, params.windowCrop); - } - if ((params.flags & FLAG_ALPHA) != 0) { - t.setAlpha(params.surface, params.alpha); - } - if ((params.flags & FLAG_LAYER) != 0) { - t.setLayer(params.surface, params.layer); - } - if ((params.flags & FLAG_CORNER_RADIUS) != 0) { - t.setCornerRadius(params.surface, params.cornerRadius); - } - if ((params.flags & FLAG_BACKGROUND_BLUR_RADIUS) != 0) { - t.setBackgroundBlurRadius(params.surface, params.backgroundBlurRadius); - } - if ((params.flags & FLAG_VISIBILITY) != 0) { - if (params.visible) { - t.show(params.surface); - } else { - t.hide(params.surface); - } - } + params.applyTo(t.mTransaction); } /** @@ -210,7 +185,7 @@ public class SyncRtSurfaceTransactionApplierCompat { public static class SurfaceParams { public static class Builder { - final SurfaceControlCompat surface; + final SurfaceControl surface; int flags; float alpha; float cornerRadius; @@ -224,6 +199,13 @@ public class SyncRtSurfaceTransactionApplierCompat { * @param surface The surface to modify. */ public Builder(SurfaceControlCompat surface) { + this(surface.mSurfaceControl); + } + + /** + * @param surface The surface to modify. + */ + public Builder(SurfaceControl surface) { this.surface = surface; } @@ -317,11 +299,12 @@ public class SyncRtSurfaceTransactionApplierCompat { */ public SurfaceParams(SurfaceControlCompat surface, float alpha, Matrix matrix, Rect windowCrop, int layer, float cornerRadius) { - this(surface, FLAG_ALL & ~(FLAG_VISIBILITY | FLAG_BACKGROUND_BLUR_RADIUS), alpha, + this(surface.mSurfaceControl, + FLAG_ALL & ~(FLAG_VISIBILITY | FLAG_BACKGROUND_BLUR_RADIUS), alpha, matrix, windowCrop, layer, cornerRadius, 0 /* backgroundBlurRadius */, true); } - private SurfaceParams(SurfaceControlCompat surface, int flags, float alpha, Matrix matrix, + private SurfaceParams(SurfaceControl surface, int flags, float alpha, Matrix matrix, Rect windowCrop, int layer, float cornerRadius, int backgroundBlurRadius, boolean visible) { this.flags = flags; @@ -336,8 +319,9 @@ public class SyncRtSurfaceTransactionApplierCompat { } private final int flags; + private final float[] mTmpValues = new float[9]; - public final SurfaceControlCompat surface; + public final SurfaceControl surface; public final float alpha; public final float cornerRadius; public final int backgroundBlurRadius; @@ -345,5 +329,33 @@ public class SyncRtSurfaceTransactionApplierCompat { public final Rect windowCrop; public final int layer; public final boolean visible; + + public void applyTo(SurfaceControl.Transaction t) { + if ((flags & FLAG_MATRIX) != 0) { + t.setMatrix(surface, matrix, mTmpValues); + } + if ((flags & FLAG_WINDOW_CROP) != 0) { + t.setWindowCrop(surface, windowCrop); + } + if ((flags & FLAG_ALPHA) != 0) { + t.setAlpha(surface, alpha); + } + if ((flags & FLAG_LAYER) != 0) { + t.setLayer(surface, layer); + } + if ((flags & FLAG_CORNER_RADIUS) != 0) { + t.setCornerRadius(surface, cornerRadius); + } + if ((flags & FLAG_BACKGROUND_BLUR_RADIUS) != 0) { + t.setBackgroundBlurRadius(surface, backgroundBlurRadius); + } + if ((flags & FLAG_VISIBILITY) != 0) { + if (visible) { + t.show(surface); + } else { + t.hide(surface); + } + } + } } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java index c1c91f7e5079..bdb6c063521f 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/TransactionCompat.java @@ -18,9 +18,8 @@ package com.android.systemui.shared.system; import android.graphics.Matrix; import android.graphics.Rect; -import android.view.Surface; -import android.view.SurfaceControl.Transaction; import android.view.SurfaceControl; +import android.view.SurfaceControl.Transaction; public class TransactionCompat { @@ -109,4 +108,13 @@ public class TransactionCompat { mTransaction.setColor(surfaceControl.mSurfaceControl, color); return this; } + + public static void deferTransactionUntil(Transaction t, SurfaceControl surfaceControl, + SurfaceControl barrier, long frameNumber) { + t.deferTransactionUntil(surfaceControl, barrier, frameNumber); + } + + public static void setEarlyWakeup(Transaction t) { + t.setEarlyWakeup(); + } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ViewRootImplCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ViewRootImplCompat.java new file mode 100644 index 000000000000..dd613263e5c2 --- /dev/null +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ViewRootImplCompat.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package com.android.systemui.shared.system; + +import android.view.SurfaceControl; +import android.view.View; +import android.view.ViewRootImpl; + +import java.util.function.LongConsumer; + +/** + * Helper class to expose some ViewRoomImpl methods + */ +public class ViewRootImplCompat { + + private final ViewRootImpl mViewRoot; + + public ViewRootImplCompat(View view) { + mViewRoot = view == null ? null : view.getViewRootImpl(); + } + + public SurfaceControl getRenderSurfaceControl() { + return mViewRoot == null ? null : mViewRoot.getRenderSurfaceControl(); + } + + public SurfaceControl getSurfaceControl() { + return mViewRoot == null ? null : mViewRoot.getSurfaceControl(); + } + + public boolean isValid() { + return mViewRoot != null; + } + + public View getView() { + return mViewRoot == null ? null : mViewRoot.getView(); + } + + public void registerRtFrameCallback(LongConsumer callback) { + if (mViewRoot != null) { + mViewRoot.registerRtFrameCallback(callback::accept); + } + } +} |