Surface.cpp revision c90a77f1e5b42d8fcf336d2b9bd2259280814df2
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 27namespace android { 28namespace view { 29 30status_t Surface::writeToParcel(Parcel* parcel) const { 31 return writeToParcel(parcel, false); 32} 33 34status_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 return IGraphicBufferProducer::exportToParcel(graphicBufferProducer, parcel); 49} 50 51status_t Surface::readFromParcel(const Parcel* parcel) { 52 return readFromParcel(parcel, false); 53} 54 55status_t Surface::readFromParcel(const Parcel* parcel, bool nameAlreadyRead) { 56 if (parcel == nullptr) return BAD_VALUE; 57 58 status_t res = OK; 59 if (!nameAlreadyRead) { 60 name = readMaybeEmptyString16(parcel); 61 // Discard this for now 62 int isSingleBuffered; 63 res = parcel->readInt32(&isSingleBuffered); 64 if (res != OK) { 65 ALOGE("Can't read isSingleBuffered"); 66 return res; 67 } 68 } 69 70 graphicBufferProducer = IGraphicBufferProducer::createFromParcel(parcel); 71 return OK; 72} 73 74String16 Surface::readMaybeEmptyString16(const Parcel* parcel) { 75 size_t len; 76 const char16_t* str = parcel->readString16Inplace(&len); 77 if (str != nullptr) { 78 return String16(str, len); 79 } else { 80 return String16(); 81 } 82} 83 84} // namespace view 85} // namespace android 86