1 /*
2  * Copyright (C) 2022 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 #ifndef ANDROID_HWC_COMMON_H
18 #define ANDROID_HWC_COMMON_H
19 
20 #include <inttypes.h>
21 
22 #include <string>
23 
24 #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
25 
26 #undef LOG_TAG
27 #define LOG_TAG "RanchuHwc"
28 
29 #include <aidl/android/hardware/graphics/composer3/IComposerClient.h>
30 #include <android-base/logging.h>
31 #include <log/log.h>
32 #include <utils/Trace.h>
33 
34 // Uncomment to enable additional debug logging.
35 // #define DEBUG_RANCHU_HWC
36 
37 #if defined(DEBUG_RANCHU_HWC)
38 #define DEBUG_LOG ALOGE
39 #else
40 #define DEBUG_LOG(...) ((void)0)
41 #endif
42 
43 namespace aidl::android::hardware::graphics::composer3::impl {
44 
45 bool IsAutoDevice();
46 bool IsCuttlefish();
47 bool IsCuttlefishFoldable();
48 
49 bool IsInNoOpCompositionMode();
50 bool IsInClientCompositionMode();
51 
52 bool IsInGem5DisplayFinderMode();
53 bool IsInNoOpDisplayFinderMode();
54 bool IsInDrmDisplayFinderMode();
55 
56 namespace HWC3 {
57 enum class Error : int32_t {
58     None = 0,
59     BadConfig = aidl::android::hardware::graphics::composer3::IComposerClient::EX_BAD_CONFIG,
60     BadDisplay = aidl::android::hardware::graphics::composer3::IComposerClient::EX_BAD_DISPLAY,
61     BadLayer = aidl::android::hardware::graphics::composer3::IComposerClient::EX_BAD_LAYER,
62     BadParameter = aidl::android::hardware::graphics::composer3::IComposerClient::EX_BAD_PARAMETER,
63     NoResources = aidl::android::hardware::graphics::composer3::IComposerClient::EX_NO_RESOURCES,
64     NotValidated = aidl::android::hardware::graphics::composer3::IComposerClient::EX_NOT_VALIDATED,
65     Unsupported = aidl::android::hardware::graphics::composer3::IComposerClient::EX_UNSUPPORTED,
66     SeamlessNotAllowed =
67         aidl::android::hardware::graphics::composer3::IComposerClient::EX_SEAMLESS_NOT_ALLOWED,
68 };
69 }  // namespace HWC3
70 
71 std::string toString(HWC3::Error error);
72 
ToBinderStatus(HWC3::Error error)73 inline ndk::ScopedAStatus ToBinderStatus(HWC3::Error error) {
74     if (error != HWC3::Error::None) {
75         return ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(error));
76     }
77     return ndk::ScopedAStatus::ok();
78 }
79 
80 }  // namespace aidl::android::hardware::graphics::composer3::impl
81 
82 #endif
83