static int get_fb_from_adb(struct fb *fb) { char buf[1024]; const struct fbinfo* fbinfo; int bytes_read; /* Init socket */ adb_fd = remote_socket("localhost", 5037); if (adb_fd < 0) { E("Failed to create socket, %s", strerror(errno)); return -1; } adb_write("host:transport-"); bytes_read = adb_read(buf, 1024); if (bytes_read <= 0) return -1; adb_write("framebuffer:"); bytes_read = adb_read(buf, 1024); if (bytes_read <= 0) return -1; /* Parse FB header. */ bytes_read = adb_read(buf, sizeof(struct fbinfo)); if (bytes_read <= 0 || (unsigned int)bytes_read < sizeof (struct fbinfo)) { E("Failed to read the FB Info data!", strerror(errno)); return -1; } fbinfo = (struct fbinfo*) buf; if (fbinfo->version != DDMS_RAWIMAGE_VERSION) { E("Unsupported adb version."); return -1; } /* Assemble struct fb */ memcpy(fb, &fbinfo->bpp, sizeof(struct fbinfo) - 4); fb_dump(fb); fb->data = malloc(fb->size); if (!fb->data) return -1; /* Read out the whole framebuffer */ bytes_read = 0; while ((unsigned int)bytes_read < fb->size) { int br = adb_read((char*)fb->data + bytes_read, fb->size - bytes_read); if (br <= 0) return -1; bytes_read += br; } return 0; }
int fb2png(const char *path) { struct fb fb; int ret; #ifdef ANDROID ret = get_device_fb("/dev/graphics/fb0", &fb); #else ret = get_device_fb("/dev/fb0", &fb); #endif if (ret) { D("Failed to read framebuffer."); return -1; } fb_dump(&fb); return fb_save_png(&fb, path); }
struct gui_t *gui_init(int angle) { struct gui_t *gui; FB *fb; gui = malloc(sizeof(*gui)); if (NULL == gui) { DPRINTF("Can't allocate memory for GUI structure"); return NULL; } /* init framebuffer */ fb = fb_new(angle); if (NULL == fb) { log_msg(lg, "Can't initialize framebuffer"); free(gui); return NULL; } gui->fb = fb; /* Tune GUI size */ #ifdef USE_FBUI_WIDTH if (fb->width > USE_FBUI_WIDTH) gui->width = USE_FBUI_WIDTH; else #endif gui->width = fb->width; #ifdef USE_FBUI_HEIGHT if (fb->height > USE_FBUI_HEIGHT) gui->height = USE_FBUI_HEIGHT; else #endif gui->height = fb->height; gui->x = (fb->width - gui->width)/2; gui->y = (fb->height - gui->height)/2; #ifdef USE_ICONS /* Parse compiled images. * We don't care about result because drawing code is aware */ int bpp; bpp = fb->bpp; gui->icons = malloc(sizeof(*(gui->icons)) * ICON_ARRAY_SIZE); gui->icons[ICON_LOGO] = xpm_parse_image(logo_xpm, ROWS(logo_xpm), bpp); gui->icons[ICON_STORAGE] = xpm_parse_image(storage_xpm, ROWS(storage_xpm), bpp); gui->icons[ICON_MMC] = xpm_parse_image(mmc_xpm, ROWS(mmc_xpm), bpp); gui->icons[ICON_MEMORY] = xpm_parse_image(memory_xpm, ROWS(memory_xpm), bpp); gui->icons[ICON_SYSTEM] = xpm_parse_image(system_xpm, ROWS(system_xpm), bpp); gui->icons[ICON_BACK] = xpm_parse_image(back_xpm, ROWS(back_xpm), bpp); gui->icons[ICON_RESCAN] = xpm_parse_image(rescan_xpm, ROWS(rescan_xpm), bpp); gui->icons[ICON_DEBUG] = xpm_parse_image(debug_xpm, ROWS(debug_xpm), bpp); gui->icons[ICON_REBOOT] = xpm_parse_image(reboot_xpm, ROWS(reboot_xpm), bpp); gui->icons[ICON_SHUTDOWN] = xpm_parse_image(shutdown_xpm, ROWS(shutdown_xpm), bpp); gui->icons[ICON_EXIT] = xpm_parse_image(exit_xpm, ROWS(exit_xpm), bpp); #endif #ifdef USE_BG_BUFFER /* Pre-draw background and store it in special buffer */ draw_background_low(gui); gui->bg_buffer = fb_dump(fb); #endif return gui; }
int main(int argc, char *argv[]) { struct limare_state *state; int ret; float vertices[] = { -0.45, -0.75, 0.0, 0.45, -0.75, 0.0, -0.45, 0.75, 0.0, 0.45, 0.75, 0.0 }; float color[] = {1.0, 0.0, 0.0, 1.0 }; const char *vertex_shader_source = "precision mediump float; \n" "attribute vec4 aPosition; \n" " \n" "void main() \n" "{ \n" " gl_Position = aPosition; \n" "} \n"; const char *fragment_shader_source = "precision mediump float; \n" "uniform vec4 uColor; \n" " \n" "void main() \n" "{ \n" " gl_FragColor = uColor; \n" "} \n"; fb_clear(); state = limare_init(); if (!state) return -1; ret = limare_state_setup(state, WIDTH, HEIGHT, 0xFF505050); if (ret) return ret; vertex_shader_attach(state, vertex_shader_source); fragment_shader_attach(state, fragment_shader_source); limare_link(state); limare_attribute_pointer(state, "aPosition", 4, 3, vertices); limare_uniform_attach(state, "uColor", 4, 4, color); ret = limare_draw_arrays(state, GL_TRIANGLE_STRIP, 0, 4); if (ret) return ret; ret = limare_flush(state); if (ret) return ret; bmp_dump(state->pp->frame_address, state, "/sdcard/limare.bmp"); fb_dump(state->pp->frame_address, 0, state->width, state->height); limare_finish(); return 0; }