1 /* 2 * Copyright (C) 2024 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.FlaggedApi; 20 import android.annotation.IntDef; 21 import android.annotation.NonNull; 22 import android.hardware.flags.Flags; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * Provides Lut properties of the device. 29 * 30 * <p> 31 * A Lut (Look-Up Table) is a pre-calculated table for color correction. 32 * Applications may be interested in the Lut properties exposed by 33 * this class to determine if the Lut(s) they select using 34 * {@link android.view.SurfaceControl.Transaction#setLuts} are by the HWC. 35 * </p> 36 */ 37 @FlaggedApi(Flags.FLAG_LUTS_API) 38 public final class LutProperties { 39 private final @Dimension int mDimension; 40 private final int mSize; 41 private final @SamplingKey int[] mSamplingKeys; 42 43 /** @hide */ 44 @Retention(RetentionPolicy.SOURCE) 45 @IntDef(prefix = {"SAMPLING_KEY_"}, value = { 46 SAMPLING_KEY_RGB, 47 SAMPLING_KEY_MAX_RGB, 48 SAMPLING_KEY_CIE_Y 49 }) 50 public @interface SamplingKey { 51 } 52 53 /** use r,g,b channel as the gain value of a Lut */ 54 @FlaggedApi(Flags.FLAG_LUTS_API) 55 public static final int SAMPLING_KEY_RGB = 0; 56 57 /** use max of r,g,b channel as the gain value of a Lut */ 58 @FlaggedApi(Flags.FLAG_LUTS_API) 59 public static final int SAMPLING_KEY_MAX_RGB = 1; 60 61 /** use y of CIE XYZ as the gain value of a lut */ 62 @FlaggedApi(Flags.FLAG_LUTS_API) 63 public static final int SAMPLING_KEY_CIE_Y = 2; 64 65 /** @hide */ 66 @Retention(RetentionPolicy.SOURCE) 67 @IntDef(value = { 68 ONE_DIMENSION, 69 THREE_DIMENSION 70 }) 71 public @interface Dimension { 72 } 73 74 /** The Lut is one dimensional */ 75 @FlaggedApi(Flags.FLAG_LUTS_API) 76 public static final int ONE_DIMENSION = 1; 77 78 /** The Lut is three dimensional */ 79 @FlaggedApi(Flags.FLAG_LUTS_API) 80 public static final int THREE_DIMENSION = 3; 81 82 @FlaggedApi(Flags.FLAG_LUTS_API) getDimension()83 public @Dimension int getDimension() { 84 return mDimension; 85 } 86 87 /** 88 * @return the size of the Lut for each dimension 89 */ 90 @FlaggedApi(Flags.FLAG_LUTS_API) getSize()91 public int getSize() { 92 return mSize; 93 } 94 95 /** 96 * @return the list of sampling keys 97 */ 98 @FlaggedApi(Flags.FLAG_LUTS_API) 99 @NonNull getSamplingKeys()100 public @SamplingKey int[] getSamplingKeys() { 101 if (mSamplingKeys.length == 0) { 102 throw new IllegalStateException("no sampling key!"); 103 } 104 return mSamplingKeys; 105 } 106 107 /* use in the native code */ LutProperties(@imension int dimension, int size, @SamplingKey int[] samplingKeys)108 private LutProperties(@Dimension int dimension, int size, @SamplingKey int[] samplingKeys) { 109 if (dimension != ONE_DIMENSION || dimension != THREE_DIMENSION) { 110 throw new IllegalArgumentException("The dimension is either 1 or 3!"); 111 } 112 mDimension = dimension; 113 mSize = size; 114 mSamplingKeys = samplingKeys; 115 } 116 } 117