2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include <X11/extensions/Xrandr.h>
30 #include <system_info.h>
31 #include <system_info_private.h>
37 #define LOG_TAG "TIZEN_N_SYSTEM_INFO"
39 typedef struct _progInfo ProgInfo;
48 int event_base, error_base;
50 XRRScreenResources *res;
53 static int RCA_SUPPORTED;
54 static int HDMI_SUPPORTED;
55 static int SCREEN_DPI;
56 static int BITS_PER_PIXEL;
57 static int SCREEN_WIDTH;
58 static int SCREEN_HEIGHT;
59 static int PHYSICAL_SCREEN_WIDTH;
60 static int PHYSICAL_SCREEN_HEIGHT;
61 int system_info_screen_initialized;
63 int system_info_screen_init()
66 XPixmapFormatValues *pmf;
68 memset(&g_pinfo, 0x0, sizeof(ProgInfo));
70 g_pinfo.dpy = XOpenDisplay(NULL);
71 if (NULL == g_pinfo.dpy)
74 if (0 > g_pinfo.screen)
75 g_pinfo.screen = DefaultScreen(g_pinfo.dpy);
76 g_pinfo.root = RootWindow(g_pinfo.dpy, g_pinfo.screen);
78 if (!XRRQueryExtension(g_pinfo.dpy, &g_pinfo.event_base, &g_pinfo.error_base) ||
79 !XRRQueryVersion(g_pinfo.dpy, &g_pinfo.major, &g_pinfo.minor)) {
83 g_pinfo.res = XRRGetScreenResources(g_pinfo.dpy, g_pinfo.root);
88 pmf = XListPixmapFormats(g_pinfo.dpy, &n);
90 for (i = 0; i < n; i++) {
91 if (BITS_PER_PIXEL < pmf->bits_per_pixel)
92 BITS_PER_PIXEL = pmf->bits_per_pixel;
96 for (i = 0; i < g_pinfo.res->noutput; i++) {
97 XRROutputInfo *output_info = XRRGetOutputInfo(g_pinfo.dpy, g_pinfo.res, g_pinfo.res->outputs[i]);
101 /* find target lcd */
102 if (!strcmp(output_info->name, "LVDS1")) {
103 /* XRRCrtcInfo information */
104 XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(g_pinfo.dpy, g_pinfo.res, output_info->crtc);
108 SCREEN_WIDTH = crtc_info->width;
109 SCREEN_HEIGHT = crtc_info->height;
110 PHYSICAL_SCREEN_WIDTH = output_info->mm_width;
111 PHYSICAL_SCREEN_HEIGHT = output_info->mm_height;
113 XRRFreeCrtcInfo(crtc_info);
114 } else if (!strcmp(output_info->name, "HDMI1"))
115 HDMI_SUPPORTED = true;
116 XRRFreeOutputInfo(output_info);
119 if (BITS_PER_PIXEL == 0)
123 SCREEN_WIDTH = DisplayWidth(g_pinfo.dpy, DefaultScreen(g_pinfo.dpy));
129 SCREEN_HEIGHT = DisplayHeight(g_pinfo.dpy, DefaultScreen(g_pinfo.dpy));
134 if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
137 char str[MAXBUFSIZE];
139 cmdline = fopen(CMDLINE_PATH, "r");
140 if (NULL == cmdline) {
141 LOGE("[%s] cannot file open %s file!!!", __func__, CPU_INFO_FILE_PATH);
142 return SYSTEM_INFO_ERROR_IO_ERROR;
144 while (fgets(str, MAXBUFSIZE, cmdline)) {
145 dpi = strstr(str, "dpi=");
146 SCREEN_DPI = atoi(dpi+4) / 10;
153 double ratio, width_inch;
155 width_inch = PHYSICAL_SCREEN_WIDTH / 10 / 2.54;
156 max_resolution = SCREEN_WIDTH + SCREEN_HEIGHT;
157 ratio = SCREEN_WIDTH / SCREEN_HEIGHT;
159 SCREEN_DPI = max_resolution / (width_inch + (ratio * width_inch)) + 0.5;
162 XCloseDisplay(g_pinfo.dpy);
164 system_info_screen_initialized = 1;
169 int system_info_get_screen_bits_per_pixel(system_info_key_e key, system_info_data_type_e data_type, void **value)
176 if (0 == system_info_screen_initialized) {
177 ret_val = system_info_screen_init();
182 *bpp = BITS_PER_PIXEL;
184 return SYSTEM_INFO_ERROR_NONE;
187 int system_info_get_screen_width(system_info_key_e key, system_info_data_type_e data_type, void **value)
192 width = (int *)value;
194 if (0 == system_info_screen_initialized) {
195 ret_val = system_info_screen_init();
200 *width = SCREEN_WIDTH;
202 return SYSTEM_INFO_ERROR_NONE;
205 int system_info_get_screen_height(system_info_key_e key, system_info_data_type_e data_type, void **value)
210 height = (int *)value;
212 if (0 == system_info_screen_initialized) {
213 ret_val = system_info_screen_init();
218 *height = SCREEN_HEIGHT;
220 return SYSTEM_INFO_ERROR_NONE;
223 int system_info_get_screen_DPI(system_info_key_e key, system_info_data_type_e data_type, void **value)
230 if (0 == system_info_screen_initialized) {
231 ret_val = system_info_screen_init();
238 return SYSTEM_INFO_ERROR_NONE;
241 int system_info_get_hdmi_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
246 if (0 == system_info_screen_initialized) {
247 ret_val = system_info_screen_init();
252 supported = (bool *)value;
254 *supported = HDMI_SUPPORTED;
256 return SYSTEM_INFO_ERROR_NONE;
259 int system_info_get_rca_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
263 supported = (bool *)value;
265 *supported = RCA_SUPPORTED;
267 return SYSTEM_INFO_ERROR_NONE;
270 int system_info_get_physical_screen_height(system_info_key_e key, system_info_data_type_e data_type, void **value)
277 if (0 == system_info_screen_initialized) {
278 ret_val = system_info_screen_init();
283 *bpp = PHYSICAL_SCREEN_HEIGHT;
285 return SYSTEM_INFO_ERROR_NONE;
288 int system_info_get_physical_screen_width(system_info_key_e key, system_info_data_type_e data_type, void **value)
295 if (0 == system_info_screen_initialized) {
296 ret_val = system_info_screen_init();
301 *bpp = PHYSICAL_SCREEN_WIDTH;
303 return SYSTEM_INFO_ERROR_NONE;