The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 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 | |
David 'Digit' Turner | 414ff7d | 2009-05-18 17:07:46 +0200 | [diff] [blame] | 23 | #include "fdevent.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 24 | #include "adb.h" |
| 25 | |
| 26 | #include <linux/fb.h> |
| 27 | #include <sys/ioctl.h> |
| 28 | #include <sys/mman.h> |
| 29 | |
| 30 | /* TODO: |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 31 | ** - sync with vsync to avoid tearing |
| 32 | */ |
| 33 | |
| 34 | void framebuffer_service(int fd, void *cookie) |
| 35 | { |
| 36 | struct fb_var_screeninfo vinfo; |
Rebecca Schultz Zavin | 04bee29 | 2009-09-09 21:39:41 -0700 | [diff] [blame^] | 37 | int fb, offset; |
| 38 | char x[256]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 39 | |
| 40 | unsigned fbinfo[4]; |
Rebecca Schultz Zavin | 04bee29 | 2009-09-09 21:39:41 -0700 | [diff] [blame^] | 41 | unsigned i, bytespp; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 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 | |
Rebecca Schultz Zavin | 04bee29 | 2009-09-09 21:39:41 -0700 | [diff] [blame^] | 49 | bytespp = vinfo.bits_per_pixel / 8; |
| 50 | |
| 51 | fbinfo[0] = vinfo.bits_per_pixel; |
| 52 | fbinfo[1] = vinfo.xres * vinfo.yres * bytespp; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 53 | fbinfo[2] = vinfo.xres; |
| 54 | fbinfo[3] = vinfo.yres; |
| 55 | |
Rebecca Schultz Zavin | 04bee29 | 2009-09-09 21:39:41 -0700 | [diff] [blame^] | 56 | /* HACK: for several of our 3d cores a specific alignment |
| 57 | * is required so the start of the fb may not be an integer number of lines |
| 58 | * from the base. As a result we are storing the additional offset in |
| 59 | * xoffset. This is not the correct usage for xoffset, it should be added |
| 60 | * to each line, not just once at the beginning */ |
| 61 | offset = vinfo.xoffset * bytespp; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 62 | |
Rebecca Schultz Zavin | 04bee29 | 2009-09-09 21:39:41 -0700 | [diff] [blame^] | 63 | offset += vinfo.xres * vinfo.yoffset * bytespp; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 64 | |
Rebecca Schultz Zavin | 04bee29 | 2009-09-09 21:39:41 -0700 | [diff] [blame^] | 65 | if(writex(fd, fbinfo, sizeof(fbinfo))) goto done; |
| 66 | |
| 67 | lseek(fb, offset, SEEK_SET); |
| 68 | for(i = 0; i < fbinfo[1]; i += 256) { |
| 69 | if(readx(fb, &x, 256)) goto done; |
| 70 | if(writex(fd, &x, 256)) goto done; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Rebecca Schultz Zavin | 04bee29 | 2009-09-09 21:39:41 -0700 | [diff] [blame^] | 73 | if(readx(fb, &x, fbinfo[1] % 256)) goto done; |
| 74 | if(writex(fd, &x, fbinfo[1] % 256)) goto done; |
| 75 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 76 | done: |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 77 | if(fb >= 0) close(fb); |
| 78 | close(fd); |
| 79 | } |