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 /**
20  * The request to get an [android.view.Surface] to display viewfinder input.
21  *
22  * This request contains requirements for the surface resolution and viewfinder input and output
23  * information.
24  *
25  * @constructor Creates a new surface request with given resolution, and optional implementation
26  *   mode request ID.
27  * @property width The requested surface width.
28  * @property height The requested surface height.
29  * @property implementationMode The [ImplementationMode] to apply to the viewfinder. Defaults to
30  *   `null`, which will use the viewfinder's default implementation mode.
31  * @property requestId An optional request ID to allow requests to be differentiated via [equals].
32  *   Defaults to `null`.
33  */
34 class ViewfinderSurfaceRequest
35 @JvmOverloads
36 constructor(
37     val width: Int,
38     val height: Int,
39     val implementationMode: ImplementationMode? = null,
40     val requestId: String? = null
41 ) {
equalsnull42     override fun equals(other: Any?): Boolean {
43         if (this === other) return true
44         if (other !is ViewfinderSurfaceRequest) return false
45 
46         if (width != other.width) return false
47         if (height != other.height) return false
48         if (implementationMode != other.implementationMode) return false
49         if (requestId != other.requestId) return false
50 
51         return true
52     }
53 
hashCodenull54     override fun hashCode(): Int {
55         var result = width.hashCode()
56         result = result * 31 + height.hashCode()
57         result = result * 31 + implementationMode.hashCode()
58         result = result * 31 + requestId.hashCode()
59 
60         return result
61     }
62 
toStringnull63     override fun toString(): String {
64         return "ViewfinderSurfaceRequest(" +
65             "width=$width" +
66             "height=$height" +
67             "implementationMode=$implementationMode" +
68             "requestId=$requestId" +
69             ")"
70     }
71 
72     /**
73      * Creates a copy of this viewfinder surface request, allowing named properties to be altered
74      * while keeping the rest unchanged.
75      */
76     @JvmSynthetic
copynull77     fun copy(
78         width: Int = this.width,
79         height: Int = this.height,
80         implementationMode: ImplementationMode? = this.implementationMode,
81         requestId: String? = this.requestId
82     ): ViewfinderSurfaceRequest =
83         ViewfinderSurfaceRequest(width, height, implementationMode, requestId)
84 }
85