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.core.processing.util;
18 
19 import static androidx.camera.core.processing.util.GLUtils.VERSION_UNKNOWN;
20 
21 import androidx.annotation.RestrictTo;
22 
23 import com.google.auto.value.AutoValue;
24 
25 import org.jspecify.annotations.NonNull;
26 
27 /**
28  * Information about an initialized graphics device.
29  *
30  * <p>This information can be used to determine which version or extensions of OpenGL and EGL
31  * are supported on the device to ensure the attached output surface will have expected
32  * characteristics.
33  */
34 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
35 @AutoValue
36 public abstract class GraphicDeviceInfo {
37     /**
38      * Returns the OpenGL version this graphics device has been initialized to.
39      *
40      * <p>The version is in the form &lt;major&gt;.&lt;minor&gt;.
41      *
42      * <p>Returns {@link GLUtils#VERSION_UNKNOWN} if version information can't be
43      * retrieved.
44      */
getGlVersion()45     public abstract @NonNull String getGlVersion();
46 
47     /**
48      * Returns the EGL version this graphics device has been initialized to.
49      *
50      * <p>The version is in the form &lt;major&gt;.&lt;minor&gt;.
51      *
52      * <p>Returns {@link GLUtils#VERSION_UNKNOWN} if version information can't be
53      * retrieved.
54      */
getEglVersion()55     public abstract @NonNull String getEglVersion();
56 
57     /**
58      * Returns a space separated list of OpenGL extensions or an empty string if extensions
59      * could not be retrieved.
60      */
getGlExtensions()61     public abstract @NonNull String getGlExtensions();
62 
63     /**
64      * Returns a space separated list of EGL extensions or an empty string if extensions
65      * could not be retrieved.
66      */
getEglExtensions()67     public abstract @NonNull String getEglExtensions();
68 
69     /**
70      * Returns the Builder.
71      */
builder()72     public static @NonNull Builder builder() {
73         return new AutoValue_GraphicDeviceInfo.Builder()
74                 .setGlVersion(VERSION_UNKNOWN)
75                 .setEglVersion(VERSION_UNKNOWN)
76                 .setGlExtensions("")
77                 .setEglExtensions("");
78     }
79 
80     // Should not be instantiated directly
GraphicDeviceInfo()81     GraphicDeviceInfo() {
82     }
83 
84     /**
85      * Builder for {@link GraphicDeviceInfo}.
86      */
87     @AutoValue.Builder
88     public abstract static class Builder {
89         /**
90          * Sets the gl version.
91          */
setGlVersion(@onNull String version)92         public abstract @NonNull Builder setGlVersion(@NonNull String version);
93 
94         /**
95          * Sets the egl version.
96          */
setEglVersion(@onNull String version)97         public abstract @NonNull Builder setEglVersion(@NonNull String version);
98 
99         /**
100          * Sets the gl extensions.
101          */
setGlExtensions(@onNull String extensions)102         public abstract @NonNull Builder setGlExtensions(@NonNull String extensions);
103 
104         /**
105          * Sets the egl extensions.
106          */
setEglExtensions(@onNull String extensions)107         public abstract @NonNull Builder setEglExtensions(@NonNull String extensions);
108 
109         /**
110          * Builds the {@link GraphicDeviceInfo}.
111          */
build()112         public abstract @NonNull GraphicDeviceInfo build();
113     }
114 }
115