1 /* 2 * Copyright (C) 2023 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 package com.android.internal.widget.remotecompose.core.operations.utilities; 17 18 import com.android.internal.widget.remotecompose.core.operations.Utils; 19 20 /** 21 * This defines the major id maps and ranges used by remote compose Generally ids ranging from 1 ... 22 * 7FFFFF (4095) are for ids The data range is divided int to bits 0xxxxx are allocated for 23 * Predefined Global System Variables 1xxxxx are allocated to normal variables 2xxxxx are allocated 24 * to List&MAPS (Arrays of stuff) 3xxxxx are allocated to path & float operations 25 * 4xxxxx,5xxxxx,7xxxxx are reserved for future use 0x1000-0x1100 are used for path operations in 26 * PathData 0x1100-0x1200 are used for math operations in Animated float 0x 27 */ 28 public class NanMap { 29 public static final int MOVE = 0x300_000; 30 public static final int LINE = 0x300_001; 31 public static final int QUADRATIC = 0x300_002; 32 public static final int CONIC = 0x300_003; 33 public static final int CUBIC = 0x300_004; 34 public static final int CLOSE = 0x300_005; 35 public static final int DONE = 0x300_006; 36 public static final float MOVE_NAN = Utils.asNan(MOVE); 37 public static final float LINE_NAN = Utils.asNan(LINE); 38 public static final float QUADRATIC_NAN = Utils.asNan(QUADRATIC); 39 public static final float CONIC_NAN = Utils.asNan(CONIC); 40 public static final float CUBIC_NAN = Utils.asNan(CUBIC); 41 public static final float CLOSE_NAN = Utils.asNan(CLOSE); 42 public static final float DONE_NAN = Utils.asNan(DONE); 43 44 /** 45 * Returns true if the float id is a system variable 46 * 47 * @param value the id encoded as float NaN 48 * @return 49 */ isSystemVariable(float value)50 public static boolean isSystemVariable(float value) { 51 return (fromNaN(value) >> 20) == 0; 52 } 53 54 /** 55 * Returns true if the float id is a normal variable 56 * 57 * @param value the id encoded as float NaN 58 * @return 59 */ isNormalVariable(float value)60 public static boolean isNormalVariable(float value) { 61 return (fromNaN(value) >> 20) == 1; 62 } 63 64 /** 65 * Returns true if the float id is a data variable 66 * 67 * @param value the id encoded as float NaN 68 * @return 69 */ isDataVariable(float value)70 public static boolean isDataVariable(float value) { 71 return (fromNaN(value) >> 20) == 2; 72 } 73 74 /** 75 * Returns true if the float id is an operation variable 76 * 77 * @param value the id encoded as float NaN 78 * @return 79 */ isOperationVariable(float value)80 public static boolean isOperationVariable(float value) { 81 return (fromNaN(value) >> 20) == 3; 82 } 83 84 public static final int START_VAR = (1 << 20) + 42; 85 public static final int START_ARRAY = (2 << 20) + 42; 86 public static final int TYPE_SYSTEM = 0; 87 public static final int TYPE_VARIABLE = 1; 88 public static final int TYPE_ARRAY = 2; 89 public static final int TYPE_OPERATION = 3; 90 public static final int ID_REGION_MASK = 0x700000; 91 public static final int ID_REGION_ARRAY = 0x200000; 92 93 /** 94 * Get ID from Nan float 95 * 96 * @param v 97 * @return 98 */ fromNaN(float v)99 public static int fromNaN(float v) { 100 int b = Float.floatToRawIntBits(v); 101 return b & 0x7FFFFF; 102 } 103 104 /** 105 * Given id return as a Nan float 106 * 107 * @param v 108 * @return 109 */ asNan(int v)110 public static float asNan(int v) { 111 return Float.intBitsToFloat(v | 0xFF800000); 112 } 113 } 114