| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.wallpapereffectsgeneration; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.graphics.Bitmap; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
|
| 26 |
import java.lang.annotation.Retention; |
| 27 |
import java.lang.annotation.RetentionPolicy; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
@SystemApi |
| 38 |
public final class TexturedMesh implements Parcelable { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
@NonNull |
| 43 |
private Bitmap mBitmap; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
@NonNull |
| 49 |
private int[] mIndices; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
@NonNull |
| 55 |
private float[] mVertices; |
| 56 |
|
| 57 |
|
| 58 |
@IntDef(prefix = {"INDICES_LAYOUT_"}, value = { |
| 59 |
INDICES_LAYOUT_UNDEFINED, |
| 60 |
INDICES_LAYOUT_TRIANGLES}) |
| 61 |
@Retention(RetentionPolicy.SOURCE) |
| 62 |
public @interface IndicesLayoutType { |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
public static final int INDICES_LAYOUT_UNDEFINED = 0; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public static final int INDICES_LAYOUT_TRIANGLES = 1; |
| 72 |
|
| 73 |
@IndicesLayoutType |
| 74 |
private int mIndicesLayoutType; |
| 75 |
|
| 76 |
|
| 77 |
@IntDef(prefix = {"VERTICES_LAYOUT_"}, value = { |
| 78 |
VERTICES_LAYOUT_UNDEFINED, |
| 79 |
VERTICES_LAYOUT_POSITION3_UV2}) |
| 80 |
@Retention(RetentionPolicy.SOURCE) |
| 81 |
public @interface VerticesLayoutType { |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static final int VERTICES_LAYOUT_UNDEFINED = 0; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public static final int VERTICES_LAYOUT_POSITION3_UV2 = 1; |
| 93 |
|
| 94 |
@VerticesLayoutType |
| 95 |
private int mVerticesLayoutType; |
| 96 |
|
| 97 |
private TexturedMesh(Parcel in) { |
| 98 |
this.mIndicesLayoutType = in.readInt(); |
| 99 |
this.mVerticesLayoutType = in.readInt(); |
| 100 |
this.mBitmap = in.readTypedObject(Bitmap.CREATOR); |
| 101 |
Parcel data = Parcel.obtain(); |
| 102 |
try { |
| 103 |
byte[] bytes = in.readBlob(); |
| 104 |
data.unmarshall(bytes, 0, bytes.length); |
| 105 |
data.setDataPosition(0); |
| 106 |
this.mIndices = data.createIntArray(); |
| 107 |
this.mVertices = data.createFloatArray(); |
| 108 |
} finally { |
| 109 |
data.recycle(); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
private TexturedMesh(@NonNull Bitmap bitmap, @NonNull int[] indices, |
| 114 |
@NonNull float[] vertices, @IndicesLayoutType int indicesLayoutType, |
| 115 |
@VerticesLayoutType int verticesLayoutType) { |
| 116 |
mBitmap = bitmap; |
| 117 |
mIndices = indices; |
| 118 |
mVertices = vertices; |
| 119 |
mIndicesLayoutType = indicesLayoutType; |
| 120 |
mVerticesLayoutType = verticesLayoutType; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
@NonNull |
| 125 |
public Bitmap getBitmap() { |
| 126 |
return mBitmap; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
@NonNull |
| 135 |
public int[] getIndices() { |
| 136 |
return mIndices; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
@NonNull |
| 146 |
public float[] getVertices() { |
| 147 |
return mVertices; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
@IndicesLayoutType |
| 152 |
@NonNull |
| 153 |
public int getIndicesLayoutType() { |
| 154 |
return mIndicesLayoutType; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
@VerticesLayoutType |
| 159 |
@NonNull |
| 160 |
public int getVerticesLayoutType() { |
| 161 |
return mVerticesLayoutType; |
| 162 |
} |
| 163 |
|
| 164 |
@NonNull |
| 165 |
public static final Creator<TexturedMesh> CREATOR = new Creator<TexturedMesh>() { |
| 166 |
@Override |
| 167 |
public TexturedMesh createFromParcel(Parcel in) { |
| 168 |
return new TexturedMesh(in); |
| 169 |
} |
| 170 |
|
| 171 |
@Override |
| 172 |
public TexturedMesh[] newArray(int size) { |
| 173 |
return new TexturedMesh[size]; |
| 174 |
} |
| 175 |
}; |
| 176 |
|
| 177 |
@Override |
| 178 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 179 |
out.writeInt(mIndicesLayoutType); |
| 180 |
out.writeInt(mVerticesLayoutType); |
| 181 |
out.writeTypedObject(mBitmap, flags); |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
Parcel data = Parcel.obtain(); |
| 186 |
try { |
| 187 |
data.writeIntArray(mIndices); |
| 188 |
data.writeFloatArray(mVertices); |
| 189 |
out.writeBlob(data.marshall()); |
| 190 |
} finally { |
| 191 |
data.recycle(); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
@Override |
| 196 |
public int describeContents() { |
| 197 |
return 0; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
@SystemApi |
| 206 |
public static final class Builder { |
| 207 |
private Bitmap mBitmap; |
| 208 |
private int[] mIndices; |
| 209 |
private float[] mVertices; |
| 210 |
@IndicesLayoutType |
| 211 |
private int mIndicesLayoutType; |
| 212 |
@VerticesLayoutType |
| 213 |
private int mVerticesLayouttype; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
@SystemApi |
| 221 |
public Builder(@NonNull Bitmap bitmap) { |
| 222 |
mBitmap = bitmap; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
@NonNull |
| 231 |
public Builder setIndices(@NonNull int[] indices) { |
| 232 |
mIndices = indices; |
| 233 |
return this; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
@NonNull |
| 243 |
public Builder setVertices(@NonNull float[] vertices) { |
| 244 |
mVertices = vertices; |
| 245 |
return this; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
@NonNull |
| 252 |
public Builder setIndicesLayoutType(@IndicesLayoutType int indicesLayoutType) { |
| 253 |
mIndicesLayoutType = indicesLayoutType; |
| 254 |
return this; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
@NonNull |
| 261 |
public Builder setVerticesLayoutType(@VerticesLayoutType int verticesLayoutype) { |
| 262 |
mVerticesLayouttype = verticesLayoutype; |
| 263 |
return this; |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
@NonNull |
| 268 |
public TexturedMesh build() { |
| 269 |
return new TexturedMesh(mBitmap, mIndices, mVertices, mIndicesLayoutType, |
| 270 |
mVerticesLayouttype); |
| 271 |
} |
| 272 |
} |
| 273 |
} |