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.hardware; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import libcore.util.NativeAllocationRegistry; 24 25 /** 26 * The class provides overlay properties of the device. OverlayProperties 27 * exposes some capabilities from HWC e.g. if fp16 can be supported for HWUI. 28 * 29 * In the future, more capabilities can be added, e.g., whether or not 30 * per-layer colorspaces are supported. 31 * 32 * @hide 33 */ 34 public final class OverlayProperties implements Parcelable { 35 36 private static final NativeAllocationRegistry sRegistry = 37 NativeAllocationRegistry.createMalloced(OverlayProperties.class.getClassLoader(), 38 nGetDestructor()); 39 40 private long mNativeObject; 41 // Invoked on destruction 42 private Runnable mCloser; 43 OverlayProperties(long nativeObject)44 public OverlayProperties(long nativeObject) { 45 if (nativeObject != 0) { 46 mCloser = sRegistry.registerNativeAllocation(this, nativeObject); 47 } 48 mNativeObject = nativeObject; 49 } 50 51 /** 52 * @return True if the device can support fp16, false otherwise. 53 */ supportFp16ForHdr()54 public boolean supportFp16ForHdr() { 55 if (mNativeObject == 0) { 56 return false; 57 } 58 return nSupportFp16ForHdr(mNativeObject); 59 } 60 61 /** 62 * @return True if the device can support mixed colorspaces, false otherwise. 63 */ supportMixedColorSpaces()64 public boolean supportMixedColorSpaces() { 65 if (mNativeObject == 0) { 66 return false; 67 } 68 return nSupportMixedColorSpaces(mNativeObject); 69 } 70 71 /** 72 * Release the local reference. 73 */ release()74 public void release() { 75 if (mNativeObject != 0) { 76 mCloser.run(); 77 mNativeObject = 0; 78 } 79 } 80 81 @Override describeContents()82 public int describeContents() { 83 return 0; 84 } 85 86 /** 87 * Flatten this object in to a Parcel. 88 * 89 * @param dest The Parcel in which the object should be written. 90 * @param flags Additional flags about how the object should be written. 91 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. 92 */ 93 @Override writeToParcel(@onNull Parcel dest, int flags)94 public void writeToParcel(@NonNull Parcel dest, int flags) { 95 if (mNativeObject == 0) { 96 dest.writeInt(0); 97 return; 98 } 99 dest.writeInt(1); 100 nWriteOverlayPropertiesToParcel(mNativeObject, dest); 101 } 102 103 public static final @NonNull Parcelable.Creator<OverlayProperties> CREATOR = 104 new Parcelable.Creator<OverlayProperties>() { 105 public OverlayProperties createFromParcel(Parcel in) { 106 if (in.readInt() != 0) { 107 return new OverlayProperties(nReadOverlayPropertiesFromParcel(in)); 108 } 109 return null; 110 } 111 112 public OverlayProperties[] newArray(int size) { 113 return new OverlayProperties[size]; 114 } 115 }; 116 nGetDestructor()117 private static native long nGetDestructor(); nSupportFp16ForHdr(long nativeObject)118 private static native boolean nSupportFp16ForHdr(long nativeObject); nSupportMixedColorSpaces(long nativeObject)119 private static native boolean nSupportMixedColorSpaces(long nativeObject); nWriteOverlayPropertiesToParcel(long nativeObject, Parcel dest)120 private static native void nWriteOverlayPropertiesToParcel(long nativeObject, Parcel dest); nReadOverlayPropertiesFromParcel(Parcel in)121 private static native long nReadOverlayPropertiesFromParcel(Parcel in); 122 } 123