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.
23 #include <sys/types.h>
30 #include <sys/ioctl.h>
34 ** - sync with vsync to avoid tearing
36 /* This version number defines the format of the fbinfo struct.
37 It must match versioning in ddms where this data is consumed. */
38 #define DDMS_RAWIMAGE_VERSION 1
45 unsigned int red_offset;
46 unsigned int red_length;
47 unsigned int blue_offset;
48 unsigned int blue_length;
49 unsigned int green_offset;
50 unsigned int green_length;
51 unsigned int alpha_offset;
52 unsigned int alpha_length;
53 } __attribute__((packed));
55 void framebuffer_service(int fd, void *cookie)
65 if (pipe(fds) < 0) goto done;
68 if (pid < 0) goto done;
71 dup2(fds[1], STDOUT_FILENO);
74 const char* command = "screencap";
75 const char *args[2] = {command, NULL};
76 execvp(command, (char**)args);
80 fd_screencap = fds[0];
82 /* read w, h & format */
83 if(readx(fd_screencap, &w, 4)) goto done;
84 if(readx(fd_screencap, &h, 4)) goto done;
85 if(readx(fd_screencap, &f, 4)) goto done;
87 fbinfo.version = DDMS_RAWIMAGE_VERSION;
88 /* see hardware/hardware.h */
90 case 1: /* RGBA_8888 */
92 fbinfo.size = w * h * 4;
95 fbinfo.red_offset = 0;
96 fbinfo.red_length = 8;
97 fbinfo.green_offset = 8;
98 fbinfo.green_length = 8;
99 fbinfo.blue_offset = 16;
100 fbinfo.blue_length = 8;
101 fbinfo.alpha_offset = 24;
102 fbinfo.alpha_length = 8;
104 case 2: /* RGBX_8888 */
106 fbinfo.size = w * h * 4;
109 fbinfo.red_offset = 0;
110 fbinfo.red_length = 8;
111 fbinfo.green_offset = 8;
112 fbinfo.green_length = 8;
113 fbinfo.blue_offset = 16;
114 fbinfo.blue_length = 8;
115 fbinfo.alpha_offset = 24;
116 fbinfo.alpha_length = 0;
118 case 3: /* RGB_888 */
120 fbinfo.size = w * h * 3;
123 fbinfo.red_offset = 0;
124 fbinfo.red_length = 8;
125 fbinfo.green_offset = 8;
126 fbinfo.green_length = 8;
127 fbinfo.blue_offset = 16;
128 fbinfo.blue_length = 8;
129 fbinfo.alpha_offset = 24;
130 fbinfo.alpha_length = 0;
132 case 4: /* RGB_565 */
134 fbinfo.size = w * h * 2;
137 fbinfo.red_offset = 11;
138 fbinfo.red_length = 5;
139 fbinfo.green_offset = 5;
140 fbinfo.green_length = 6;
141 fbinfo.blue_offset = 0;
142 fbinfo.blue_length = 5;
143 fbinfo.alpha_offset = 0;
144 fbinfo.alpha_length = 0;
146 case 5: /* BGRA_8888 */
148 fbinfo.size = w * h * 4;
151 fbinfo.red_offset = 16;
152 fbinfo.red_length = 8;
153 fbinfo.green_offset = 8;
154 fbinfo.green_length = 8;
155 fbinfo.blue_offset = 0;
156 fbinfo.blue_length = 8;
157 fbinfo.alpha_offset = 24;
158 fbinfo.alpha_length = 8;
165 if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;
168 for(i = 0; i < fbinfo.size; i += sizeof(buf)) {
169 if(readx(fd_screencap, buf, sizeof(buf))) goto done;
170 if(writex(fd, buf, sizeof(buf))) goto done;
172 if(readx(fd_screencap, buf, fbinfo.size % sizeof(buf))) goto done;
173 if(writex(fd, buf, fbinfo.size % sizeof(buf))) goto done;
176 TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0));