1 /* 2 * Copyright 2024, 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 #pragma once 18 19 #include <android/binder_auto_utils.h> 20 #include <ui/GraphicBuffer.h> 21 #include <utils/Errors.h> 22 23 #include <aidl/android/hardware/graphics/common/Dataspace.h> 24 #include <aidl/android/hardware/graphics/common/PixelFormat.h> 25 #include <aidl/android/media/AidlColorAspects.h> 26 27 namespace android::media::aidl_conversion { 28 fromAidlStatus(const::ndk::ScopedAStatus & status)29inline status_t fromAidlStatus(const ::ndk::ScopedAStatus &status) { 30 if (!status.isOk()) { 31 if (status.getExceptionCode() == EX_SERVICE_SPECIFIC) { 32 return static_cast<status_t>(status.getServiceSpecificError()); 33 } else { 34 return static_cast<status_t>(FAILED_TRANSACTION); 35 } 36 } 37 return NO_ERROR; 38 } 39 toAidlStatus(status_t status)40inline ::ndk::ScopedAStatus toAidlStatus(status_t status) { 41 if (status == NO_ERROR) { 42 return ::ndk::ScopedAStatus::ok(); 43 } 44 return ::ndk::ScopedAStatus::fromServiceSpecificError(status); 45 } 46 compactFromAidlColorAspects(::aidl::android::media::AidlColorAspects const & s)47inline int32_t compactFromAidlColorAspects(::aidl::android::media::AidlColorAspects const& s) { 48 return static_cast<int32_t>( 49 (static_cast<uint32_t>(s.range) << 24) | 50 (static_cast<uint32_t>(s.primaries) << 16) | 51 (static_cast<uint32_t>(s.transfer)) | 52 (static_cast<uint32_t>(s.matrixCoeffs) << 8)); 53 } 54 rawFromAidlDataspace(::aidl::android::hardware::graphics::common::Dataspace const & s)55inline int32_t rawFromAidlDataspace( 56 ::aidl::android::hardware::graphics::common::Dataspace const& s) { 57 return static_cast<int32_t>(s); 58 } 59 60 } // namespace android::media::aidl_conversion 61