| /* | |
| * Copyright (C) 2026 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| #include <view/SurfaceControl.h> | |
| #include <gui/SurfaceControl.h> | |
| namespace android { | |
| namespace view { | |
| SurfaceControl::SurfaceControl(const sp<android::SurfaceControl>& surfaceControl) | |
| : mSurfaceControl(surfaceControl) {} | |
| status_t SurfaceControl::readFromParcel(const Parcel* parcel) { | |
| int32_t width, height, presence; | |
| status_t res = parcel->readInt32(&width); | |
| if (res != OK) { | |
| ALOGE("%s: Failed to read width res=%d", __PRETTY_FUNCTION__, res); | |
| return res; | |
| } | |
| res = parcel->readInt32(&height); | |
| if (res != OK) { | |
| ALOGE("%s: Failed to read height res=%d", __PRETTY_FUNCTION__, res); | |
| return res; | |
| } | |
| res = parcel->readInt32(&presence); | |
| if (res != OK) { | |
| ALOGE("%s: Failed to read presence res=%d", __PRETTY_FUNCTION__, res); | |
| return res; | |
| } | |
| if (presence == 0) { | |
| mSurfaceControl = nullptr; | |
| return OK; | |
| } | |
| return android::SurfaceControl::readFromParcel(*parcel, &mSurfaceControl); | |
| } | |
| status_t SurfaceControl::writeToParcel(Parcel* parcel) const { | |
| int32_t width = mSurfaceControl ? mSurfaceControl->mWidth : 0; | |
| status_t res = parcel->writeInt32(width); | |
| if (res != OK) { | |
| ALOGE("%s: Failed to write width res=%d", __PRETTY_FUNCTION__, res); | |
| return res; | |
| } | |
| int32_t height = mSurfaceControl ? mSurfaceControl->mHeight : 0; | |
| res = parcel->writeInt32(height); | |
| if (res != OK) { | |
| ALOGE("%s: Failed to write height res=%d", __PRETTY_FUNCTION__, res); | |
| return res; | |
| } | |
| if (mSurfaceControl) { | |
| res = parcel->writeInt32(1); | |
| if (res != OK) { | |
| ALOGE("%s: Failed to write presence res=%d", __PRETTY_FUNCTION__, res); | |
| return res; | |
| } | |
| return mSurfaceControl->writeToParcel(*parcel); | |
| } else { | |
| return parcel->writeInt32(0); | |
| } | |
| } | |
| SurfaceControl::operator sp<android::SurfaceControl>() const { | |
| return mSurfaceControl; | |
| } | |
| SurfaceControl::operator bool() const { | |
| return mSurfaceControl != nullptr; | |
| } | |
| android::SurfaceControl* SurfaceControl::operator->() const { | |
| return mSurfaceControl.get(); | |
| } | |
| bool SurfaceControl::operator==(const SurfaceControl& other) const { | |
| return mSurfaceControl == other.mSurfaceControl; | |
| } | |
| bool SurfaceControl::operator<(const SurfaceControl& other) const { | |
| return mSurfaceControl < other.mSurfaceControl; | |
| } | |
| std::string SurfaceControl::toString() const { | |
| return mSurfaceControl ? mSurfaceControl->getName() : "<null>"; | |
| } | |
| } // namespace view | |
| } // namespace android |