void gr_buffertest() { GGLContext *gr_context = 0; gglInit(&gr_context); GGLContext *gl = gr_context; gr_mem_surface2.data = NULL; get_memory_surface(&gr_mem_surface2); gl->colorBuffer(gl, &gr_mem_surface2); unsigned int r = 0; unsigned int g = 255; unsigned int b = 0; unsigned int a = 255; GGLint color[4]; color[0] = ((r << 8) | r) + 1; color[1] = ((g << 8) | g) + 1; color[2] = ((b << 8) | b) + 1; color[3] = ((a << 8) | a) + 1; #ifdef COLORS_REVERSED color[0] = ((b << 8) | b) + 1; color[2] = ((r << 8) | r) + 1; #endif gl->color4xv(gl, color); gl->disable(gl, GGL_TEXTURE_2D); gl->recti(gl, 150, 150, 300, 300); }
int gr_init(void) { gglInit(&gr_context); GGLContext *gl = gr_context; gr_mem_surface.data = NULL; gr_init_font(); gr_vt_fd = open("/dev/tty0", O_RDWR | O_SYNC); if (gr_vt_fd < 0) { gr_vt_fd = open("/dev/tty", O_RDWR | O_SYNC); } if (gr_vt_fd < 0) { // This is non-fatal; post-Cupcake kernels don't have tty0. perror("can't open /dev/tty0"); } else { ioctl(gr_vt_fd, KDGETMODE, &gr_vt_mode); if (ioctl(gr_vt_fd, KDSETMODE, (void*) KD_GRAPHICS)) { // However, if we do open tty0, we expect the ioctl to work. perror("failed KDSETMODE to KD_GRAPHICS on tty0"); gr_exit(); return -1; } } gr_fb_fd = get_framebuffer(gr_framebuffer); if (gr_fb_fd < 0) { perror("unable to get framebuffer"); gr_exit(); return -1; } get_memory_surface(&gr_mem_surface); fprintf(stderr, "framebuffer: fd %d (%d x %d)\n", gr_fb_fd, gr_framebuffer[0].width, gr_framebuffer[0].height); /* start with 0 as front (displayed) and 1 as back (drawing) */ gr_active_fb = 0; set_active_framebuffer(0); gl->colorBuffer(gl, &gr_mem_surface); gl->activeTexture(gl, 0); gl->enable(gl, GGL_BLEND); gl->blendFunc(gl, GGL_SRC_ALPHA, GGL_ONE_MINUS_SRC_ALPHA); gr_fb_blank(true); gr_fb_blank(false); return 0; }
int gr_get_surface(gr_surface* surface) { GGLSurface* ms = malloc(sizeof(GGLSurface)); if (!ms) return -1; // Allocate the data get_memory_surface(ms); // Now, copy the data memcpy(ms->data, gr_mem_surface.data, vi.xres * vi.yres * vi.bits_per_pixel / 8); *surface = (gr_surface*) ms; return 0; }
int gr_init(void) { gglInit(&gr_context); GGLContext *gl = gr_context; gr_init_font(); gr_vt_fd = open("/dev/tty0", O_RDWR | O_SYNC); if (gr_vt_fd < 0) { // This is non-fatal; post-Cupcake kernels don't have tty0. } else if (ioctl(gr_vt_fd, KDSETMODE, (void*) KD_GRAPHICS)) { // However, if we do open tty0, we expect the ioctl to work. perror("failed KDSETMODE to KD_GRAPHICS on tty0"); gr_exit(); return -1; } gr_fb_fd = get_framebuffer(gr_framebuffer); if (gr_fb_fd < 0) { perror("Unable to get framebuffer.\n"); gr_exit(); return -1; } get_memory_surface(&gr_mem_surface); fprintf(stderr, "framebuffer: fd %d (%d x %d)\n", gr_fb_fd, gr_framebuffer[0].width, gr_framebuffer[0].height); /* start with 0 as front (displayed) and 1 as back (drawing) */ gr_active_fb = 0; if (!has_overlay) set_active_framebuffer(0); gl->colorBuffer(gl, &gr_mem_surface); gl->activeTexture(gl, 0); gl->enable(gl, GGL_BLEND); gl->blendFunc(gl, GGL_SRC_ALPHA, GGL_ONE_MINUS_SRC_ALPHA); #ifdef TW_SCREEN_BLANK_ON_BOOT printf("TW_SCREEN_BLANK_ON_BOOT := true\n"); gr_fb_blank(true); gr_fb_blank(false); #endif if (!alloc_ion_mem(fi.line_length * vi.yres)) allocate_overlay(gr_fb_fd, gr_framebuffer); return 0; }
int main(int argc, char *argv[]) { time_t start = time(NULL); printf("Starting recovery on %s", ctime(&start)); gr_fb_fd = get_framebuffer(gr_framebuffer); if (gr_fb_fd < 0) { return -1; } get_memory_surface(&gr_mem_surface); typedef unsigned short pixel; pixel* dst = gr_framebuffer[gr_active_fb].data; pixel* src = gr_mem_surface.data; int i,j; switch(ROTATE){ case ROTATE_90: for(i = 0;i < vi.yres;i++) { for(j = 0;j < vi.xres;j++) { dst[i * vi.xres + vi.xres - 1 - j] = src[i + j * vi.yres]; } } break; case ROTATE_270: for(i = 0;i < vi.yres;i++) { for(j = 0;j < vi.xres;j++) { dst[(vi.yres -1 - i) * vi.xres + j] = src[i + j * vi.yres]; } } break; default://0 memcpy(gr_framebuffer[gr_active_fb].data, gr_mem_surface.data, vi.xres * vi.yres * 2); break; } set_active_framebuffer(0); ioctl(gr_fb_fd, FBIOPAN_DISPLAY, &vi); exit: munmap(gr_framebuffer[0].data, vi.yres * vi.xres * 2); munmap(gr_framebuffer[1].data, vi.yres * vi.xres * 2); munmap(recovery_ebc_buffer_base, recovery_ebc_buffer_len); close(gr_fb_fd); close(recovery_ebc_fd); return 0; }