xref: /aosp_15_r20/frameworks/native/libs/gui/Flags.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 #include <gui/Flags.h>
18 #include <gui/IGraphicBufferProducer.h>
19 #include <gui/Surface.h>
20 #include <gui/view/Surface.h>
21 
22 namespace android {
23 namespace flagtools {
surfaceToSurfaceType(const sp<Surface> & surface)24 sp<SurfaceType> surfaceToSurfaceType(const sp<Surface>& surface) {
25 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
26     return surface;
27 #else
28     return surface->getIGraphicBufferProducer();
29 #endif
30 }
31 
surfaceTypeToIGBP(const sp<SurfaceType> & surface)32 sp<IGraphicBufferProducer> surfaceTypeToIGBP(const sp<SurfaceType>& surface) {
33 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
34     return surface->getIGraphicBufferProducer();
35 #else
36     return surface;
37 #endif
38 }
39 
isSurfaceTypeValid(const sp<SurfaceType> & surface)40 bool isSurfaceTypeValid(const sp<SurfaceType>& surface) {
41 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
42     return Surface::isValid(surface);
43 #else
44     return surface != nullptr;
45 #endif
46 }
47 
toParcelableSurfaceType(const view::Surface & surface)48 ParcelableSurfaceType toParcelableSurfaceType(const view::Surface& surface) {
49 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
50     return surface;
51 #else
52     return surface.graphicBufferProducer;
53 #endif
54 }
55 
convertSurfaceTypeToParcelable(sp<SurfaceType> surface)56 ParcelableSurfaceType convertSurfaceTypeToParcelable(sp<SurfaceType> surface) {
57 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
58     return view::Surface::fromSurface(surface);
59 #else
60     return surface;
61 #endif
62 }
63 
convertParcelableSurfaceTypeToSurface(const ParcelableSurfaceType & surface)64 sp<SurfaceType> convertParcelableSurfaceTypeToSurface(const ParcelableSurfaceType& surface) {
65 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
66     return surface.toSurface();
67 #else
68     return surface;
69 #endif
70 }
71 
72 } // namespace flagtools
73 } // namespace android