framebuffer_service.c revision 4f6e8d7a00cbeda1e70cc15be9c4af1018bdad53
1/* 2 * Copyright (C) 2007 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#include <stdlib.h> 18#include <stdio.h> 19#include <unistd.h> 20#include <string.h> 21#include <fcntl.h> 22 23#include <cutils/fdevent.h> 24#include "adb.h" 25 26#include <linux/fb.h> 27#include <sys/mman.h> 28 29/* TODO: 30** - grab the current buffer, not the first buffer 31** - sync with vsync to avoid tearing 32*/ 33 34void framebuffer_service(int fd, void *cookie) 35{ 36 struct fb_var_screeninfo vinfo; 37 int fb; 38 void *ptr = MAP_FAILED; 39 char x; 40 41 unsigned fbinfo[4]; 42 43 fb = open("/dev/graphics/fb0", O_RDONLY); 44 if(fb < 0) goto done; 45 46 if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done; 47 fcntl(fb, F_SETFD, FD_CLOEXEC); 48 49 fbinfo[0] = 16; 50 fbinfo[1] = vinfo.xres * vinfo.yres * 2; 51 fbinfo[2] = vinfo.xres; 52 fbinfo[3] = vinfo.yres; 53 54 ptr = mmap(0, fbinfo[1], PROT_READ, MAP_SHARED, fb, 0); 55 if(ptr == MAP_FAILED) goto done; 56 57 if(writex(fd, fbinfo, sizeof(unsigned) * 4)) goto done; 58 59 for(;;) { 60 if(readx(fd, &x, 1)) goto done; 61 if(writex(fd, ptr, fbinfo[1])) goto done; 62 } 63 64done: 65 if(ptr != MAP_FAILED) munmap(ptr, fbinfo[1]); 66 if(fb >= 0) close(fb); 67 close(fd); 68} 69 70