Skip to content

Commit 0cc2e2c

Browse files
author
Carlos Martinez Romero
committed
Use view::Surface instead of IGBPs in OutputConfiguration
We are currently limitig the use of IGBPs outside of libgui to allow for further development of bufferqueues without external breakages. More information at go/warren-buffers. BYPASS_IGBP_IGBC_API_REASON: this CL is part of the migration. Bug: 342197849 Test: atest android.hardware.cts.CameraTest Flag: com.android.graphics.libgui.flags.wb_libcameraservice Change-Id: I299be522d47849ca67bcbf22519535a39343ed37
1 parent f9854d2 commit 0cc2e2c

5 files changed

Lines changed: 117 additions & 3 deletions

File tree

libs/gui/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ filegroup {
264264
"DisplayEventDispatcher.cpp",
265265
"DisplayEventReceiver.cpp",
266266
"FenceMonitor.cpp",
267+
"Flags.cpp",
267268
"GLConsumer.cpp",
268269
"IConsumerListener.cpp",
269270
"IGraphicBufferConsumer.cpp",

libs/gui/Flags.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 {
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+
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+
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+
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+
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+
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

libs/gui/include/gui/Flags.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
#pragma once
1818

1919
#include <com_android_graphics_libgui_flags.h>
20-
#include <gui/IGraphicBufferProducer.h>
21-
#include <gui/Surface.h>
20+
#include <utils/StrongPointer.h>
21+
22+
namespace android {
23+
24+
class IGraphicBufferProducer;
25+
class Surface;
26+
namespace view {
27+
class Surface;
28+
}
2229

2330
#define WB_CAMERA3_AND_PROCESSORS_WITH_DEPENDENCIES \
2431
(COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CAMERA3_AND_PROCESSORS) && \
@@ -31,6 +38,19 @@
3138

3239
#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
3340
typedef android::Surface SurfaceType;
41+
typedef android::view::Surface ParcelableSurfaceType;
3442
#else
3543
typedef android::IGraphicBufferProducer SurfaceType;
36-
#endif
44+
typedef android::sp<android::IGraphicBufferProducer> ParcelableSurfaceType;
45+
#endif
46+
47+
namespace flagtools {
48+
sp<SurfaceType> surfaceToSurfaceType(const sp<Surface>& surface);
49+
ParcelableSurfaceType toParcelableSurfaceType(const view::Surface& surface);
50+
sp<IGraphicBufferProducer> surfaceTypeToIGBP(const sp<SurfaceType>& surface);
51+
bool isSurfaceTypeValid(const sp<SurfaceType>& surface);
52+
ParcelableSurfaceType convertSurfaceTypeToParcelable(sp<SurfaceType> surface);
53+
sp<SurfaceType> convertParcelableSurfaceTypeToSurface(const ParcelableSurfaceType& surface);
54+
} // namespace flagtools
55+
56+
} // namespace android

libs/gui/include/gui/view/Surface.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ class Surface : public Parcelable {
5454
sp<android::Surface> toSurface() const;
5555

5656
status_t getUniqueId(/* out */ uint64_t* id) const;
57+
58+
bool isEmpty() const;
59+
60+
bool operator==(const Surface& other) const {
61+
return graphicBufferProducer == other.graphicBufferProducer;
62+
}
63+
bool operator!=(const Surface& other) const { return !(*this == other); }
64+
bool operator==(const sp<android::Surface> other) const {
65+
if (other == nullptr) return graphicBufferProducer == nullptr;
66+
return graphicBufferProducer == other->getIGraphicBufferProducer();
67+
}
68+
bool operator!=(const sp<android::Surface> other) const { return !(*this == other); }
69+
bool operator<(const Surface& other) const {
70+
return graphicBufferProducer < other.graphicBufferProducer;
71+
}
72+
bool operator>(const Surface& other) const { return other < *this; }
5773
#endif
5874

5975
virtual status_t writeToParcel(Parcel* parcel) const override;

libs/gui/view/Surface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ status_t Surface::getUniqueId(uint64_t* out_id) const {
151151
}
152152
return OK;
153153
}
154+
155+
bool Surface::isEmpty() const {
156+
return graphicBufferProducer == nullptr;
157+
}
154158
#endif
155159

156160
std::string Surface::toString() const {

0 commit comments

Comments
 (0)