1 /* 2 * Copyright 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 androidx.camera.viewfinder.core 18 19 import androidx.annotation.RestrictTo 20 21 /** 22 * The implementation mode of a Viewfinder. 23 * 24 * User preference on how the viewfinder should render the viewfinder. The viewfinder is displayed 25 * with either a SurfaceView/AndroidExternalSurface or a TextureView/AndroidEmbeddedExternalSurface. 26 * - [EXTERNAL] uses a SurfaceView/AndroidExternalSurface, it is generally better when it comes to 27 * certain key metrics, including power and latency. 28 * - [EMBEDDED] uses a TextureView/AndroidEmbeddedExternalSurface it is better supported by a wider 29 * range of devices. 30 * 31 * The option is used to decide what is the best internal implementation given the device 32 * capabilities and user configurations. 33 */ 34 enum class ImplementationMode(private val id: Int) { 35 /** 36 * Use a SurfaceView/AndroidExternalSurface for the Viewfinder when possible. It has somewhat 37 * lower latency and less performance and power overhead. It offers more control on a single 38 * drawing board, but does not support certain animations. 39 */ 40 EXTERNAL(0), 41 42 /** Use a TextureView/AndroidEmbeddedExternalSurface for the Viewfinder. */ 43 EMBEDDED(1); 44 45 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) getIdnull46 fun getId(): Int { 47 return id 48 } 49 50 companion object { 51 /** 52 * Convert an Int id to ImplementationMode 53 * 54 * @throws IllegalArgumentException if id doesn't below to any ImplementationMode 55 */ 56 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 57 @JvmStatic fromIdnull58 fun fromId(id: Int): ImplementationMode { 59 for (implementationMode in ImplementationMode.values()) { 60 if (implementationMode.id == id) { 61 return implementationMode 62 } 63 } 64 throw IllegalArgumentException("Unknown implementation mode id $id") 65 } 66 } 67 } 68