1 /*
2  * Copyright (C) 2012 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 #ifndef HWC_DEBUG_H
17 #define HWC_DEBUG_H
18 
19 #include <utils/String8.h>
20 #include "ExynosHWC.h"
21 #include "ExynosHWCHelper.h"
22 
23 enum {
24     eDebugDefault                 =   0x00000001,
25     eDebugWindowUpdate            =   0x00000002,
26     eDebugWinConfig               =   0x00000004,
27     eDebugSkipStaicLayer          =   0x00000008,
28     eDebugOverlaySupported        =   0x00000010,
29     eDebugResourceAssigning       =   0x00000020,
30     eDebugFence                   =   0x00000040,
31     eDebugResourceManager         =   0x00000080,
32     eDebugMPP                     =   0x00000100,
33     eDebugHWC                     =   0x00000200,
34     eDebugLayer                   =   0x00000400,
35     eDebugBuf                     =   0x00000800,
36     eDebugVirtualDisplay          =   0x00001000,
37     eDebugCapacity                =   0x00002000,
38     eDebugExternalDisplay         =   0x00004000,
39     eDebugSkipResourceAssign      =   0x00008000,
40     eDebugSkipValidate            =   0x00010000,
41     eDebugDynamicRecomp           =   0x00020000,
42     eDebugDisplayInterfaceConfig  =   0x00040000,
43     eDebugColorManagement         =   0x00080000,
44     eDebugAttrSetting             =   0x00100000,
45     eDebugDisplayConfig           =   0x00400000,
46 };
47 
48 class ExynosDisplay;
49 
50 extern int hwcDebug;
51 extern int hwcFenceDebug[FENCE_IP_ALL];
52 
hwcCheckDebugMessages(uint32_t type)53 inline bool hwcCheckDebugMessages(uint32_t type)
54 {
55     return hwcDebug & type;
56 }
57 
hwcCheckFenceDebug(ExynosDisplay * display,uint32_t fence_type,uint32_t ip_type,int fence)58 inline int hwcCheckFenceDebug(ExynosDisplay *display, uint32_t fence_type, uint32_t ip_type, int fence)
59 {
60     if ((hwcFenceDebug[ip_type] & (1 << fence_type)) && fence_valid(fence))
61         return fence_close(fence, display, FENCE_TYPE_ALL, FENCE_IP_ALL);
62     else
63         return fence;
64 }
65 
66 int32_t saveErrorLog(const android::String8 &errString, ExynosDisplay *display = NULL);
67 int32_t saveFenceTrace(ExynosDisplay *display);
68 
69 #if defined(DISABLE_HWC_DEBUG)
70 #define HDEBUGLOGD(...)
71 #define HDEBUGLOGV(type,...) \
72         ALOGV(__VA_ARGS__);
73 #define HDEBUGLOGE(type,...) \
74         ALOGE(__VA_ARGS__);
75 #else
76 #define HDEBUGLOGD(type, ...) \
77     {\
78         if (hwcCheckDebugMessages(type)) \
79             ALOGD(__VA_ARGS__); \
80     }
81 #define HDEBUGLOGV(type, ...) \
82         ALOGV(__VA_ARGS__);
83 #define HDEBUGLOGE(type, ...) \
84         ALOGE(__VA_ARGS__);
85 #endif
86 
87 #if defined(DISABLE_HWC_DEBUG)
88 #define DISPLAY_LOGD(...)
89 #define MPP_LOGD(...)
90 #else
91 #define DISPLAY_LOGD(type, msg, ...) \
92     {\
93         if (hwcCheckDebugMessages(type)) \
94             ALOGD("%s:: [%s] " msg, __func__, mDisplayName.string(), ##__VA_ARGS__); \
95     }
96 #define MPP_LOGD(type, msg, ...) \
97     {\
98     if (hwcCheckDebugMessages(type)) \
99         ALOGD("%s:: [%s][%d] " msg, __func__, mName.string(), mLogicalIndex, ##__VA_ARGS__); \
100     }
101 #endif
102 #define DISPLAY_LOGV(msg, ...) ALOGV("[%s] " msg, mDisplayName.string(), ##__VA_ARGS__)
103 #define DISPLAY_LOGI(msg, ...) ALOGI("[%s] " msg, mDisplayName.string(), ##__VA_ARGS__)
104 #define DISPLAY_LOGW(msg, ...) ALOGW("[%s] " msg, mDisplayName.string(), ##__VA_ARGS__)
105 #define DISPLAY_LOGE(msg, ...) \
106     {\
107         ALOGE("[%s] " msg, mDisplayName.string(), ##__VA_ARGS__); \
108         String8 saveString; \
109         saveString.appendFormat(msg, ##__VA_ARGS__); \
110         saveErrorLog(saveString, this); \
111     }
112 
113 #define MPP_LOGV(msg, ...) ALOGV("[%s][%d] " msg, mName.string(), mLogicalIndex, ##__VA_ARGS__)
114 #define MPP_LOGI(msg, ...) ALOGI("[%s][%d] " msg, mName.string(), mLogicalIndex, ##__VA_ARGS__)
115 #define MPP_LOGW(msg, ...) ALOGW("[%s][%d] " msg, mName.string(), mLogicalIndex, ##__VA_ARGS__)
116 #define MPP_LOGE(msg, ...) \
117     {\
118         ALOGE("[%s][%d] " msg, mName.string(), mLogicalIndex, ##__VA_ARGS__); \
119         String8 saveString; \
120         saveString.appendFormat(msg, ##__VA_ARGS__); \
121         saveErrorLog(saveString, mAssignedDisplay); \
122     }
123 
124 #define HWC_LOGE(display, msg, ...) \
125     {\
126         ALOGE(msg, ##__VA_ARGS__); \
127         String8 saveString; \
128         saveString.appendFormat(msg, ##__VA_ARGS__); \
129         saveErrorLog(saveString, display); \
130     }
131 
132 #endif
133