xref: /aosp_15_r20/frameworks/native/libs/gui/Flags.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2024 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #include <gui/Flags.h>
18*38e8c45fSAndroid Build Coastguard Worker #include <gui/IGraphicBufferProducer.h>
19*38e8c45fSAndroid Build Coastguard Worker #include <gui/Surface.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <gui/view/Surface.h>
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker namespace android {
23*38e8c45fSAndroid Build Coastguard Worker namespace flagtools {
surfaceToSurfaceType(const sp<Surface> & surface)24*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceType> surfaceToSurfaceType(const sp<Surface>& surface) {
25*38e8c45fSAndroid Build Coastguard Worker #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
26*38e8c45fSAndroid Build Coastguard Worker     return surface;
27*38e8c45fSAndroid Build Coastguard Worker #else
28*38e8c45fSAndroid Build Coastguard Worker     return surface->getIGraphicBufferProducer();
29*38e8c45fSAndroid Build Coastguard Worker #endif
30*38e8c45fSAndroid Build Coastguard Worker }
31*38e8c45fSAndroid Build Coastguard Worker 
surfaceTypeToIGBP(const sp<SurfaceType> & surface)32*38e8c45fSAndroid Build Coastguard Worker sp<IGraphicBufferProducer> surfaceTypeToIGBP(const sp<SurfaceType>& surface) {
33*38e8c45fSAndroid Build Coastguard Worker #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
34*38e8c45fSAndroid Build Coastguard Worker     return surface->getIGraphicBufferProducer();
35*38e8c45fSAndroid Build Coastguard Worker #else
36*38e8c45fSAndroid Build Coastguard Worker     return surface;
37*38e8c45fSAndroid Build Coastguard Worker #endif
38*38e8c45fSAndroid Build Coastguard Worker }
39*38e8c45fSAndroid Build Coastguard Worker 
isSurfaceTypeValid(const sp<SurfaceType> & surface)40*38e8c45fSAndroid Build Coastguard Worker bool isSurfaceTypeValid(const sp<SurfaceType>& surface) {
41*38e8c45fSAndroid Build Coastguard Worker #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
42*38e8c45fSAndroid Build Coastguard Worker     return Surface::isValid(surface);
43*38e8c45fSAndroid Build Coastguard Worker #else
44*38e8c45fSAndroid Build Coastguard Worker     return surface != nullptr;
45*38e8c45fSAndroid Build Coastguard Worker #endif
46*38e8c45fSAndroid Build Coastguard Worker }
47*38e8c45fSAndroid Build Coastguard Worker 
toParcelableSurfaceType(const view::Surface & surface)48*38e8c45fSAndroid Build Coastguard Worker ParcelableSurfaceType toParcelableSurfaceType(const view::Surface& surface) {
49*38e8c45fSAndroid Build Coastguard Worker #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
50*38e8c45fSAndroid Build Coastguard Worker     return surface;
51*38e8c45fSAndroid Build Coastguard Worker #else
52*38e8c45fSAndroid Build Coastguard Worker     return surface.graphicBufferProducer;
53*38e8c45fSAndroid Build Coastguard Worker #endif
54*38e8c45fSAndroid Build Coastguard Worker }
55*38e8c45fSAndroid Build Coastguard Worker 
convertSurfaceTypeToParcelable(sp<SurfaceType> surface)56*38e8c45fSAndroid Build Coastguard Worker ParcelableSurfaceType convertSurfaceTypeToParcelable(sp<SurfaceType> surface) {
57*38e8c45fSAndroid Build Coastguard Worker #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
58*38e8c45fSAndroid Build Coastguard Worker     return view::Surface::fromSurface(surface);
59*38e8c45fSAndroid Build Coastguard Worker #else
60*38e8c45fSAndroid Build Coastguard Worker     return surface;
61*38e8c45fSAndroid Build Coastguard Worker #endif
62*38e8c45fSAndroid Build Coastguard Worker }
63*38e8c45fSAndroid Build Coastguard Worker 
convertParcelableSurfaceTypeToSurface(const ParcelableSurfaceType & surface)64*38e8c45fSAndroid Build Coastguard Worker sp<SurfaceType> convertParcelableSurfaceTypeToSurface(const ParcelableSurfaceType& surface) {
65*38e8c45fSAndroid Build Coastguard Worker #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
66*38e8c45fSAndroid Build Coastguard Worker     return surface.toSurface();
67*38e8c45fSAndroid Build Coastguard Worker #else
68*38e8c45fSAndroid Build Coastguard Worker     return surface;
69*38e8c45fSAndroid Build Coastguard Worker #endif
70*38e8c45fSAndroid Build Coastguard Worker }
71*38e8c45fSAndroid Build Coastguard Worker 
72*38e8c45fSAndroid Build Coastguard Worker } // namespace flagtools
73*38e8c45fSAndroid Build Coastguard Worker } // namespace android