1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.car.builtin.view; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.RequiresApi; 22 import android.annotation.SystemApi; 23 import android.car.builtin.annotation.AddedIn; 24 import android.car.builtin.annotation.PlatformVersion; 25 import android.os.Build; 26 import android.os.RemoteException; 27 import android.util.Log; 28 import android.view.SurfaceControl; 29 import android.view.WindowManagerGlobal; 30 31 /** 32 * Provides access to {@code android.view.SurfaceControl} calls. 33 * @hide 34 */ 35 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 36 public final class SurfaceControlHelper { 37 private static final String TAG = SurfaceControlHelper.class.getSimpleName(); SurfaceControlHelper()38 private SurfaceControlHelper() { 39 throw new UnsupportedOperationException(); 40 } 41 42 /** 43 * Creates a mirrored hierarchy for the mirror of {@link SurfaceControl}. 44 * 45 * <p>For the detail, see {@link SurfaceControl#mirrorSurface(SurfaceControl)} 46 */ 47 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 48 @AddedIn(PlatformVersion.UPSIDE_DOWN_CAKE_0) 49 @NonNull mirrorSurface(@onNull SurfaceControl mirrorOf)50 public static SurfaceControl mirrorSurface(@NonNull SurfaceControl mirrorOf) { 51 return SurfaceControl.mirrorSurface(mirrorOf); 52 } 53 54 /** 55 * Creates a mirrored Surface for the given Display. 56 */ 57 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 58 @AddedIn(PlatformVersion.UPSIDE_DOWN_CAKE_0) 59 @Nullable mirrorDisplay(int displayId)60 public static SurfaceControl mirrorDisplay(int displayId) { 61 try { 62 SurfaceControl outSurfaceControl = new SurfaceControl(); 63 boolean success = WindowManagerGlobal.getWindowManagerService().mirrorDisplay(displayId, 64 outSurfaceControl); 65 return success ? outSurfaceControl : null; 66 } catch (RemoteException e) { 67 Log.e(TAG, "Unable to reach window manager", e); 68 } 69 return null; 70 } 71 72 /** 73 * See {@link SurfaceControl(SurfaceControl)}}. 74 */ 75 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) 76 @AddedIn(PlatformVersion.UPSIDE_DOWN_CAKE_0) copy(SurfaceControl source)77 public static SurfaceControl copy(SurfaceControl source) { 78 return new SurfaceControl(source, SurfaceControlHelper.class.getSimpleName()); 79 } 80 } 81