xref: /aosp_15_r20/frameworks/native/include/gui/view/Surface.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2010 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 #ifndef ANDROID_GUI_VIEW_SURFACE_H
18 #define ANDROID_GUI_VIEW_SURFACE_H
19 
20 #include <utils/Errors.h>
21 #include <utils/StrongPointer.h>
22 #include <utils/String16.h>
23 
24 #include <binder/IBinder.h>
25 #include <binder/Parcelable.h>
26 
27 #include <gui/Flags.h>
28 #include <gui/IGraphicBufferProducer.h>
29 #include <gui/Surface.h>
30 
31 namespace android {
32 
33 namespace view {
34 
35 /**
36  * A simple holder for an IGraphicBufferProducer, to match the managed-side
37  * android.view.Surface parcelable behavior.
38  *
39  * This implements android/view/Surface.aidl
40  *
41  * TODO: Convert IGraphicBufferProducer into AIDL so that it can be directly
42  * used in managed Binder calls.
43  */
44 class Surface : public Parcelable {
45   public:
46 
47     String16 name;
48     sp<IGraphicBufferProducer> graphicBufferProducer;
49     sp<IBinder> surfaceControlHandle;
50 
51 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
52     // functions used to convert to a parcelable Surface so it can be passed over binder.
53     static Surface fromSurface(const sp<android::Surface>& surface);
54     sp<android::Surface> toSurface() const;
55 
56     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; }
73 #endif
74 
75     virtual status_t writeToParcel(Parcel* parcel) const override;
76     virtual status_t readFromParcel(const Parcel* parcel) override;
77 
78     // nameAlreadyWritten set to true by Surface.java, because it splits
79     // Parceling itself between managed and native code, so it only wants a part
80     // of the full parceling to happen on its native side.
81     status_t writeToParcel(Parcel* parcel, bool nameAlreadyWritten) const;
82 
83     // nameAlreadyRead set to true by Surface.java, because it splits
84     // Parceling itself between managed and native code, so it only wants a part
85     // of the full parceling to happen on its native side.
86     status_t readFromParcel(const Parcel* parcel, bool nameAlreadyRead);
87 
88     std::string toString() const;
89 
90 private:
91     static String16 readMaybeEmptyString16(const Parcel* parcel);
92 };
93 
94 } // namespace view
95 } // namespace android
96 
97 #endif  // ANDROID_GUI_VIEW_SURFACE_H
98