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
writeToParcel(Parcel * parcel) const30 status_t Surface::writeToParcel(Parcel* parcel) const {
31 return writeToParcel(parcel, false);
32 }
33
writeToParcel(Parcel * parcel,bool nameAlreadyWritten) const34 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
48 res = parcel->writeStrongBinder(
49 IGraphicBufferProducer::asBinder(graphicBufferProducer));
50
51 return res;
52 }
53
readFromParcel(const Parcel * parcel)54 status_t Surface::readFromParcel(const Parcel* parcel) {
55 return readFromParcel(parcel, false);
56 }
57
readFromParcel(const Parcel * parcel,bool nameAlreadyRead)58 status_t Surface::readFromParcel(const Parcel* parcel, bool nameAlreadyRead) {
59 if (parcel == nullptr) return BAD_VALUE;
60
61 status_t res = OK;
62 if (!nameAlreadyRead) {
63 name = readMaybeEmptyString16(parcel);
64 // Discard this for now
65 int isSingleBuffered;
66 res = parcel->readInt32(&isSingleBuffered);
67 if (res != OK) {
68 ALOGE("Can't read isSingleBuffered");
69 return res;
70 }
71 }
72
73 sp<IBinder> binder;
74
75 res = parcel->readNullableStrongBinder(&binder);
76 if (res != OK) {
77 ALOGE("%s: Can't read strong binder", __FUNCTION__);
78 return res;
79 }
80
81 graphicBufferProducer = interface_cast<IGraphicBufferProducer>(binder);
82
83 return OK;
84 }
85
readMaybeEmptyString16(const Parcel * parcel)86 String16 Surface::readMaybeEmptyString16(const Parcel* parcel) {
87 size_t len;
88 const char16_t* str = parcel->readString16Inplace(&len);
89 if (str != nullptr) {
90 return String16(str, len);
91 } else {
92 return String16();
93 }
94 }
95
96 } // namespace view
97 } // namespace android
98