| Mathias Agopian | 05debe1 | 2017-02-08 17:04:18 -0800 | [diff] [blame] | 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 | #define LOG_TAG "Surface" | 
|  | 18 |  | 
|  | 19 | #include <gui/view/Surface.h> | 
|  | 20 |  | 
|  | 21 | #include <binder/Parcel.h> | 
|  | 22 |  | 
|  | 23 | #include <utils/Log.h> | 
|  | 24 |  | 
|  | 25 | #include <gui/IGraphicBufferProducer.h> | 
|  | 26 |  | 
|  | 27 | namespace android { | 
|  | 28 | namespace view { | 
|  | 29 |  | 
|  | 30 | status_t Surface::writeToParcel(Parcel* parcel) const { | 
|  | 31 | return writeToParcel(parcel, false); | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | status_t Surface::writeToParcel(Parcel* parcel, bool nameAlreadyWritten) const { | 
|  | 35 | if (parcel == nullptr) return BAD_VALUE; | 
|  | 36 |  | 
|  | 37 | status_t res = OK; | 
|  | 38 |  | 
|  | 39 | if (!nameAlreadyWritten) { | 
|  | 40 | res = parcel->writeString16(name); | 
|  | 41 | if (res != OK) return res; | 
|  | 42 |  | 
|  | 43 | /* isSingleBuffered defaults to no */ | 
|  | 44 | res = parcel->writeInt32(0); | 
|  | 45 | if (res != OK) return res; | 
|  | 46 | } | 
|  | 47 |  | 
| Vishnu Nair | 992496b | 2020-10-22 17:27:21 -0700 | [diff] [blame] | 48 | res = IGraphicBufferProducer::exportToParcel(graphicBufferProducer, parcel); | 
|  | 49 | if (res != OK) return res; | 
|  | 50 | return parcel->writeStrongBinder(surfaceControlHandle); | 
| Mathias Agopian | 05debe1 | 2017-02-08 17:04:18 -0800 | [diff] [blame] | 51 | } | 
|  | 52 |  | 
|  | 53 | status_t Surface::readFromParcel(const Parcel* parcel) { | 
|  | 54 | return readFromParcel(parcel, false); | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | status_t Surface::readFromParcel(const Parcel* parcel, bool nameAlreadyRead) { | 
|  | 58 | if (parcel == nullptr) return BAD_VALUE; | 
|  | 59 |  | 
|  | 60 | status_t res = OK; | 
|  | 61 | if (!nameAlreadyRead) { | 
|  | 62 | name = readMaybeEmptyString16(parcel); | 
|  | 63 | // Discard this for now | 
|  | 64 | int isSingleBuffered; | 
|  | 65 | res = parcel->readInt32(&isSingleBuffered); | 
|  | 66 | if (res != OK) { | 
|  | 67 | ALOGE("Can't read isSingleBuffered"); | 
|  | 68 | return res; | 
|  | 69 | } | 
|  | 70 | } | 
|  | 71 |  | 
| Jiwen 'Steve' Cai | c90a77f | 2018-01-14 15:42:29 -0800 | [diff] [blame] | 72 | graphicBufferProducer = IGraphicBufferProducer::createFromParcel(parcel); | 
| Vishnu Nair | 992496b | 2020-10-22 17:27:21 -0700 | [diff] [blame] | 73 | surfaceControlHandle = parcel->readStrongBinder(); | 
| Mathias Agopian | 05debe1 | 2017-02-08 17:04:18 -0800 | [diff] [blame] | 74 | return OK; | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | String16 Surface::readMaybeEmptyString16(const Parcel* parcel) { | 
| Steven Moreland | 46f79a2 | 2020-11-04 23:40:49 +0000 | [diff] [blame] | 78 | std::optional<String16> str; | 
|  | 79 | parcel->readString16(&str); | 
|  | 80 | return str.value_or(String16()); | 
| Mathias Agopian | 05debe1 | 2017-02-08 17:04:18 -0800 | [diff] [blame] | 81 | } | 
|  | 82 |  | 
|  | 83 | } // namespace view | 
|  | 84 | } // namespace android |