blob: 2a8da87794102e5e23ffcbe98f97b3b8953d47ed [file] [log] [blame]
Chong Zhang6d332d22016-09-07 12:06:50 -07001/*
2 * Copyright (C) 2016 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 _OMX_FENCE_PARCELABLE_
18#define _OMX_FENCE_PARCELABLE_
19
20#include <binder/Parcel.h>
21
22namespace android {
23
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080024struct OMXFenceParcelable;
25
26// This is needed temporarily for the OMX HIDL transition.
27namespace hardware {
28 struct hidl_handle;
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080029namespace media { namespace omx { namespace V1_0 {
30namespace implementation {
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080031 void wrapAs(::android::OMXFenceParcelable* l,
32 ::android::hardware::hidl_handle const& t);
33 bool convertTo(::android::OMXFenceParcelable* l,
34 ::android::hardware::hidl_handle const& t);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080035}
36namespace utils {
37 void wrapAs(::android::OMXFenceParcelable* l,
38 ::android::hardware::hidl_handle const& t);
39 bool convertTo(::android::OMXFenceParcelable* l,
40 ::android::hardware::hidl_handle const& t);
41}
42}}}}
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080043
Chong Zhang6d332d22016-09-07 12:06:50 -070044struct OMXFenceParcelable : public Parcelable {
45 OMXFenceParcelable() : mFenceFd(-1) {}
46 OMXFenceParcelable(int fenceFd) : mFenceFd(fenceFd) {}
47
48 int get() const { return mFenceFd; }
49
50 status_t readFromParcel(const Parcel* parcel) override;
51 status_t writeToParcel(Parcel* parcel) const override;
52
53private:
54 // Disable copy ctor and operator=
55 OMXFenceParcelable(const OMXFenceParcelable &);
56 OMXFenceParcelable &operator=(const OMXFenceParcelable &);
57
58 int mFenceFd;
Pawin Vongmasa517b0e02016-12-02 05:15:17 -080059
60 // This is needed temporarily for OMX HIDL transition.
61 friend void (::android::hardware::media::omx::V1_0::implementation::
62 wrapAs)(OMXFenceParcelable* l,
63 ::android::hardware::hidl_handle const& t);
64 friend bool (::android::hardware::media::omx::V1_0::implementation::
65 convertTo)(OMXFenceParcelable* l,
66 ::android::hardware::hidl_handle const& t);
Pawin Vongmasaeeac97b2017-01-18 05:03:07 -080067 friend void (::android::hardware::media::omx::V1_0::utils::
68 wrapAs)(OMXFenceParcelable* l,
69 ::android::hardware::hidl_handle const& t);
70 friend bool (::android::hardware::media::omx::V1_0::utils::
71 convertTo)(OMXFenceParcelable* l,
72 ::android::hardware::hidl_handle const& t);
Chong Zhang6d332d22016-09-07 12:06:50 -070073};
74
75inline status_t OMXFenceParcelable::readFromParcel(const Parcel* parcel) {
76 int32_t haveFence;
77 status_t err = parcel->readInt32(&haveFence);
78 if (err == OK && haveFence) {
79 int fd = ::dup(parcel->readFileDescriptor());
80 if (fd < 0) {
81 return fd;
82 }
83 mFenceFd = fd;
84 }
85 return err;
86}
87
88inline status_t OMXFenceParcelable::writeToParcel(Parcel* parcel) const {
89 status_t err = parcel->writeInt32(mFenceFd >= 0);
90 if (err == OK && mFenceFd >= 0) {
91 err = parcel->writeFileDescriptor(mFenceFd, true /* takeOwnership */);
92 }
93 return err;
94}
95
96} // namespace android
97
98#endif // _OMX_FENCE_PARCELABLE_