blob: af8e5a3d69c20c57da538d5bc9bc2ffc0f299876
1 | /* |
2 | * Copyright (c) 2014 Amlogic, Inc. All rights reserved. |
3 | * |
4 | * This source code is subject to the terms and conditions defined in the |
5 | * file 'LICENSE' which is part of this source code package. |
6 | * |
7 | * Description: |
8 | */ |
9 | |
10 | |
11 | |
12 | #define LOG_TAG "amavutils" |
13 | |
14 | #include <stdlib.h> |
15 | #include <fcntl.h> |
16 | #include <errno.h> |
17 | #include <string.h> |
18 | #include <cutils/log.h> |
19 | #include <sys/ioctl.h> |
20 | #include "include/Amdisplayutils.h" |
21 | #include "include/Amsysfsutils.h" |
22 | |
23 | |
24 | #define FB_DEVICE_PATH "/sys/class/graphics/fb0/virtual_size" |
25 | #define SCALE_AXIS_PATH "/sys/class/graphics/fb0/scale_axis" |
26 | #define SCALE_PATH "/sys/class/graphics/fb0/scale" |
27 | #define SCALE_REQUEST "/sys/class/graphics/fb0/request2XScale" |
28 | #define OSD_ROTATION_PATH "/sys/class/graphics/fb0/prot_angle" |
29 | #define OSD_ROTATION_ON "/sys/class/graphics/fb0/prot_on" |
30 | #define SYSCMD_BUFSIZE 40 |
31 | |
32 | |
33 | //Temp solution, finally we will move out all the functions about display, |
34 | //it should be not part of player. |
35 | #ifndef FB_BUFFER_NUM |
36 | #define FB_BUFFER_NUM (2) |
37 | #endif |
38 | |
39 | #ifndef LOGD |
40 | #define LOGV ALOGV |
41 | #define LOGD ALOGD |
42 | #define LOGI ALOGI |
43 | #define LOGW ALOGW |
44 | #define LOGE ALOGE |
45 | #endif |
46 | |
47 | //#define LOG_FUNCTION_NAME LOGI("%s-%d\n",__FUNCTION__,__LINE__); |
48 | #define LOG_FUNCTION_NAME |
49 | |
50 | static void get_display_mode(char *mode) |
51 | { |
52 | int fd; |
53 | char *path = "/sys/class/display/mode"; |
54 | if (!mode) { |
55 | LOGE("[get_display_mode]Invalide parameter!"); |
56 | return; |
57 | } |
58 | fd = open(path, O_RDONLY); |
59 | if (fd >= 0) { |
60 | memset(mode, 0, 16); // clean buffer and read 15 byte to avoid strlen > 15 |
61 | read(fd, mode, 15); |
62 | LOGI("[get_display_mode]mode=%s strlen=%d\n", mode, strlen(mode)); |
63 | mode[strlen(mode)] = '\0'; |
64 | close(fd); |
65 | } else { |
66 | sprintf(mode, "%s", "fail"); |
67 | }; |
68 | LOGI("[get_display_mode]display_mode=%s\n", mode); |
69 | return ; |
70 | } |
71 | int amdisplay_utils_get_size(int *width, int *height) |
72 | { |
73 | LOG_FUNCTION_NAME |
74 | char buf[SYSCMD_BUFSIZE]; |
75 | int disp_w = 0; |
76 | int disp_h = 0; |
77 | int ret; |
78 | ret = amsysfs_get_sysfs_str(FB_DEVICE_PATH, buf, SYSCMD_BUFSIZE); |
79 | if (ret < 0) { |
80 | return ret; |
81 | } |
82 | if (sscanf(buf, "%d,%d", &disp_w, &disp_h) == 2) { |
83 | LOGI("disp resolution %dx%d\n", disp_w, disp_h); |
84 | disp_h = disp_h / FB_BUFFER_NUM; |
85 | } else { |
86 | return -2;/*format unknow*/ |
87 | } |
88 | *width = disp_w; |
89 | *height = disp_h; |
90 | return 0; |
91 | } |
92 | |
93 | #define FB_DEVICE_PATH_FB2 "/sys/class/graphics/fb2/virtual_size" |
94 | int amdisplay_utils_get_size_fb2(int *width, int *height) |
95 | { |
96 | LOG_FUNCTION_NAME |
97 | char buf[SYSCMD_BUFSIZE]; |
98 | int disp_w = 0; |
99 | int disp_h = 0; |
100 | int ret; |
101 | ret = amsysfs_get_sysfs_str(FB_DEVICE_PATH_FB2, buf, SYSCMD_BUFSIZE); |
102 | if (ret < 0) { |
103 | return ret; |
104 | } |
105 | if (sscanf(buf, "%d,%d", &disp_w, &disp_h) == 2) { |
106 | LOGI("disp resolution %dx%d\n", disp_w, disp_h); |
107 | disp_h = disp_h / FB_BUFFER_NUM; |
108 | } else { |
109 | return -2;/*format unknow*/ |
110 | } |
111 | *width = disp_w; |
112 | *height = disp_h; |
113 | return 0; |
114 | } |
115 | |
116 | int amdisplay_utils_set_scale_mode(int scale_wx, int scale_hx) |
117 | { |
118 | int width, height; |
119 | int ret; |
120 | int neww, newh; |
121 | char buf[40]; |
122 | |
123 | /*scale mode only support x2,x1*/ |
124 | if ((scale_wx != 1 && scale_wx != 2) || (scale_hx != 1 && scale_hx != 2)) { |
125 | LOGI("unsupport scaling mode,x1,x2 only\n", scale_wx, scale_hx); |
126 | return -1; |
127 | } |
128 | |
129 | if (scale_wx == 2) { |
130 | ret = amsysfs_set_sysfs_str(SCALE_REQUEST, "1"); |
131 | } else if (scale_wx == 1) { |
132 | ret = amsysfs_set_sysfs_str(SCALE_REQUEST, "2"); |
133 | } |
134 | |
135 | if (ret < 0) { |
136 | LOGI("set [%s]=[%s] failed\n", SCALE_AXIS_PATH, buf); |
137 | return -2; |
138 | } |
139 | |
140 | return ret; |
141 | } |
142 | |
143 | |
144 | int amdisplay_utils_get_osd_rotation() |
145 | { |
146 | char buf[40]; |
147 | int ret; |
148 | |
149 | ret = amsysfs_get_sysfs_str(OSD_ROTATION_ON, buf, SYSCMD_BUFSIZE); |
150 | if ((ret < 0) || strstr(buf, "OFF")) { |
151 | return 0;//no rotation+ |
152 | } |
153 | memset(buf, 0 , 40); |
154 | |
155 | |
156 | ret = amsysfs_get_sysfs_str(OSD_ROTATION_PATH, buf, SYSCMD_BUFSIZE); |
157 | if (ret < 0) { |
158 | return 0; //no rotation |
159 | } |
160 | |
161 | int rotation = 0; |
162 | if (sscanf(buf, "osd_rotate:%d", &rotation) == 1) { |
163 | LOGI("get osd rotation %d\n", rotation); |
164 | } |
165 | |
166 | switch (rotation) { |
167 | case 0: |
168 | rotation = 0; |
169 | break; |
170 | case 1: |
171 | rotation = 90; |
172 | break; |
173 | case 2: |
174 | rotation = 270; |
175 | break; |
176 | default: |
177 | break; |
178 | } |
179 | |
180 | LOGD("amdisplay_utils_get_osd_rotation return %d", rotation); |
181 | return rotation; |
182 | } |
183 | |
184 | |
185 |