Loading packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java +28 −3 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.graphics.PixelFormat; import android.os.Bundle; import android.os.IBinder; import android.util.Size; import android.view.SurfaceControl; import android.view.SurfaceControlViewHost; import android.view.View; Loading @@ -43,13 +44,27 @@ public class SurfaceViewRequestReceiver { mOpacity = opacity; } /** Called whenever a surface view request is received. */ /** See {@link #onReceive(Context, Bundle, View, Size)}. */ public void onReceive(Context context, Bundle bundle, View view) { onReceive(context, bundle, view, null); } /** * Called whenever a surface view request is received. * @param view the view rendering content, on the receiver end of the surface request. * @param viewSize when {@param viewSize} is not specified, we will use the surface control size * to attach the view to the window. */ public void onReceive(Context context, Bundle bundle, View view, Size viewSize) { if (mSurfaceControlViewHost != null) { mSurfaceControlViewHost.die(); } SurfaceControl surfaceControl = SurfaceViewRequestUtils.getSurfaceControl(bundle); if (surfaceControl != null) { if (viewSize == null) { viewSize = new Size(surfaceControl.getWidth(), surfaceControl.getHeight()); } IBinder hostToken = SurfaceViewRequestUtils.getHostToken(bundle); WindowlessWindowManager windowlessWindowManager = Loading @@ -59,12 +74,22 @@ public class SurfaceViewRequestReceiver { context.getDisplayNoVerify(), windowlessWindowManager); WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams( surfaceControl.getWidth(), surfaceControl.getHeight(), viewSize.getWidth(), viewSize.getHeight(), WindowManager.LayoutParams.TYPE_APPLICATION, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, mOpacity); // This aspect scales the view to fit in the surface and centers it final float scale = Math.min(surfaceControl.getWidth() / (float) viewSize.getWidth(), surfaceControl.getHeight() / (float) viewSize.getHeight()); view.setScaleX(scale); view.setScaleY(scale); view.setPivotX(0); view.setPivotY(0); view.setTranslationX((surfaceControl.getWidth() - scale * viewSize.getWidth()) / 2); view.setTranslationY((surfaceControl.getHeight() - scale * viewSize.getHeight()) / 2); mSurfaceControlViewHost.addView(view, layoutParams); } } Loading packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public class SurfaceViewRequestUtils { } /** * Retrieves the SurfaceControl from an Intent created by * Retrieves the SurfaceControl from a bundle created by * {@link #createSurfaceBundle(SurfaceView)}. **/ public static SurfaceControl getSurfaceControl(Bundle bundle) { Loading @@ -44,7 +44,7 @@ public class SurfaceViewRequestUtils { } /** * Retrieves the input token from an Intent created by * Retrieves the input token from a bundle created by * {@link #createSurfaceBundle(SurfaceView)}. **/ public static @Nullable IBinder getHostToken(Bundle bundle) { Loading Loading
packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestReceiver.java +28 −3 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.graphics.PixelFormat; import android.os.Bundle; import android.os.IBinder; import android.util.Size; import android.view.SurfaceControl; import android.view.SurfaceControlViewHost; import android.view.View; Loading @@ -43,13 +44,27 @@ public class SurfaceViewRequestReceiver { mOpacity = opacity; } /** Called whenever a surface view request is received. */ /** See {@link #onReceive(Context, Bundle, View, Size)}. */ public void onReceive(Context context, Bundle bundle, View view) { onReceive(context, bundle, view, null); } /** * Called whenever a surface view request is received. * @param view the view rendering content, on the receiver end of the surface request. * @param viewSize when {@param viewSize} is not specified, we will use the surface control size * to attach the view to the window. */ public void onReceive(Context context, Bundle bundle, View view, Size viewSize) { if (mSurfaceControlViewHost != null) { mSurfaceControlViewHost.die(); } SurfaceControl surfaceControl = SurfaceViewRequestUtils.getSurfaceControl(bundle); if (surfaceControl != null) { if (viewSize == null) { viewSize = new Size(surfaceControl.getWidth(), surfaceControl.getHeight()); } IBinder hostToken = SurfaceViewRequestUtils.getHostToken(bundle); WindowlessWindowManager windowlessWindowManager = Loading @@ -59,12 +74,22 @@ public class SurfaceViewRequestReceiver { context.getDisplayNoVerify(), windowlessWindowManager); WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams( surfaceControl.getWidth(), surfaceControl.getHeight(), viewSize.getWidth(), viewSize.getHeight(), WindowManager.LayoutParams.TYPE_APPLICATION, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, mOpacity); // This aspect scales the view to fit in the surface and centers it final float scale = Math.min(surfaceControl.getWidth() / (float) viewSize.getWidth(), surfaceControl.getHeight() / (float) viewSize.getHeight()); view.setScaleX(scale); view.setScaleY(scale); view.setPivotX(0); view.setPivotY(0); view.setTranslationX((surfaceControl.getWidth() - scale * viewSize.getWidth()) / 2); view.setTranslationY((surfaceControl.getHeight() - scale * viewSize.getHeight()) / 2); mSurfaceControlViewHost.addView(view, layoutParams); } } Loading
packages/SystemUI/shared/src/com/android/systemui/shared/system/SurfaceViewRequestUtils.java +2 −2 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public class SurfaceViewRequestUtils { } /** * Retrieves the SurfaceControl from an Intent created by * Retrieves the SurfaceControl from a bundle created by * {@link #createSurfaceBundle(SurfaceView)}. **/ public static SurfaceControl getSurfaceControl(Bundle bundle) { Loading @@ -44,7 +44,7 @@ public class SurfaceViewRequestUtils { } /** * Retrieves the input token from an Intent created by * Retrieves the input token from a bundle created by * {@link #createSurfaceBundle(SurfaceView)}. **/ public static @Nullable IBinder getHostToken(Bundle bundle) { Loading