void power_off(int signal) { if (signal != 0 && gl_info.mode_gfx == 1) my_putstr("\nHit escape key for exit\n"); else { (void)signal; my_putstr("\nDestroy thread...\n"); #ifdef __SDL__ if (gl_info.mode_gfx == 1) { destroy_surface(gl_info.gfx.status); destroy_surface(gl_info.gfx.character); destroy_surface(gl_info.gfx.backdrop); destroy_surface(gl_info.gfx.video); destroy_screen(); } #endif /* !__SDL__ */ gl_info.end = 1; free(gl_info.stick); free(gl_info.status); free(gl_info.hp); free(gl_info.threads); my_putstr(PWR_OFF_MESG); exit(0); } }
void util_surfaces_destroy(struct util_surfaces *us, struct pipe_resource *pt, void (*destroy_surface) (struct pipe_surface *)) { if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE) { /* or 2D array */ if(us->u.hash) { struct cso_hash_iter iter; iter = cso_hash_first_node(us->u.hash); while (!cso_hash_iter_is_null(iter)) { destroy_surface(cso_hash_iter_data(iter)); iter = cso_hash_iter_next(iter); } cso_hash_delete(us->u.hash); us->u.hash = NULL; } } else { if(us->u.array) { unsigned i; for(i = 0; i <= pt->last_level; ++i) { struct pipe_surface *ps = us->u.array[i]; if(ps) destroy_surface(ps); } FREE(us->u.array); us->u.array = NULL; } } }
LStringBox::~LStringBox() ///////////////////////// { //free the surfaces made in the constructor destroy_surface( backSurface ); destroy_surface( textSurface ); }
void intro(void){ int i, sound = 0; time_t begin, now; float speed[6]; circle *planet[6], *moon1; camera *cam = new_camera(0.0, 0.0, 800.0, 800.0); surface *dark_weaver = new_image("dark_weaver.png"); surface *credits = new_image("credits.png"); for(i = 0; i < 6; i ++){ speed[i] = ((rand() % 20) + 10) / 1000.0; planet[i] = new_circle(450.0 + i*50, 450.0 + i*50, (rand() % 20) + 10.0); } moon1 = new_circle(planet[2] -> x + 40.0, planet[2] -> y + 40.0, 10.0); limit_camera(cam, window_width / 2 - 400, window_height / 2 - 400, 800, 800); begin = time(NULL); initialize_star(); for(;;){ now = time(NULL); if(now - begin > 3){ draw_surface(dark_weaver, window, (window_width - dark_weaver -> width) / 2, (window_height - dark_weaver -> height) / 2); draw_surface(credits, window, (window_width - credits -> width) / 2, 0); if(sound == 0){ sound = 1; play_sound("weaver.ogg"); } if(now - begin > 5) break; } for(i = 0; i < 6; i ++) erase_fullcircle(cam, planet[i]); erase_fullcircle(cam, moon1); for(i = 0; i < 6; i ++) rotate_circle(planet[i], 400.0, 400.0, speed[i]); rotate_circle(moon1, planet[2] -> x, planet[2] -> y, speed[2]*10.0); film_fullcircle(cam, planet[0], 0x220000); film_fullcircle(cam, planet[1], 0x002200); film_fullcircle(cam, planet[2], 0x000022); film_fullcircle(cam, planet[3], 0x002222); film_fullcircle(cam, planet[4], 0x220022); film_fullcircle(cam, planet[5], 0x222222); film_fullcircle(cam, moon1, 0x444400); update_star(); weaver_rest(10000000); } destroy_surface(dark_weaver); destroy_surface(credits); destroy_star(); }
boolean la_t_edge_connector(uint *vertex) { double *vertex_array; uint *edge, edge_length, *crease, create_final[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }, crease_final[8] = {0, 0, 0, 0, 0, 0, 0, 0}; uint *ref, ref_length, vertex_length; udg_get_geometry(&vertex_length, &ref_length, &vertex_array, &ref, &crease); if(crease_edge(crease, vertex, ref, ref_length)) return FALSE; edge = udg_get_edge_data(&edge_length); // print_edge_list(edge, edge_length); GlobalSurfaceCreate.list_length[0] = 0; GlobalSurfaceCreate.list_length[1] = 0; GlobalSurfaceCreate.create_length = 0; find_neighbor_polygon(ref, ref_length, vertex_length, vertex); find_neighbor_edges(edge, edge_length, vertex); // print_neighbor(); find_triangles(vertex); find_quads(vertex, ref, ref_length, edge, edge_length); if(GlobalSurfaceCreate.create_length == 0) return TRUE; select_found(vertex_array, vertex, create_final); destroy_edges(edge, edge_length, create_final); destroy_surface(ref, crease, vertex_length, ref_length, create_final, crease_final); create_surface(create_final, crease_final); return FALSE; }
static void gst_gl_window_wayland_egl_close (GstGLWindow * window) { GstGLWindowWaylandEGL *window_egl; window_egl = GST_GL_WINDOW_WAYLAND_EGL (window); destroy_surface (window_egl); if (window_egl->display.cursor_surface) wl_surface_destroy (window_egl->display.cursor_surface); if (window_egl->display.cursor_theme) wl_cursor_theme_destroy (window_egl->display.cursor_theme); if (window_egl->display.shell) wl_shell_destroy (window_egl->display.shell); if (window_egl->display.compositor) wl_compositor_destroy (window_egl->display.compositor); if (window_egl->display.display) { wl_display_flush (window_egl->display.display); wl_display_disconnect (window_egl->display.display); } }
static EGLBoolean egl_g3d_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) { if (_eglPutSurface(surf)) destroy_surface(dpy, surf); return EGL_TRUE; }
void DisplayChannel::handle_surface_destroy(RedPeer::InMessage* message) { SpiceMsgSurfaceDestroy* surface_destroy = (SpiceMsgSurfaceDestroy*)message->data(); if (surface_destroy->surface_id == 0) { //fixme destroy_primary_surface(); } else { destroy_surface(surface_destroy->surface_id); } }
void draw_gametype(unsigned type, int x, int y){ surface *select = new_image("select.png"); surface *cpu = new_image("cpu.png"); surface *human = new_image("human.png"); draw_surface(select, window, x, y); if(type % 2) draw_surface(human, window, x + select -> width / 2 - cpu -> width, y); else draw_surface(cpu, window, x + select -> width / 2 - cpu -> width, y); if((type / 2) % 2) draw_surface(human, window, x + select -> width / 2, y); else draw_surface(cpu, window, x + select -> width / 2, y); destroy_surface(human); destroy_surface(cpu); destroy_surface(select); }
void copyleft(void){ int width, height; surface *c = new_image("copyleft.png"); width = c -> width; height = c -> height; fill_screen(BLACK); draw_surface(c, window, (window_width - width)/2, (window_height - height)/2); weaver_rest(1); sleep(1); destroy_surface(c); return; }
int main(int argc, char **argv) { struct sigaction sigint; struct display display = { 0 }; struct window window = { 0 }; window.display = &display; window.geometry.width = 250; window.geometry.height = 250; display.display = wl_display_connect(NULL); assert(display.display); wl_display_add_global_listener(display.display, display_handle_global, &display); wl_display_get_fd(display.display, event_mask_update, &display); wl_display_iterate(display.display, WL_DISPLAY_READABLE); init_egl(&display); create_surface(&window); init_gl(&window); sigint.sa_handler = signal_int; sigemptyset(&sigint.sa_mask); sigint.sa_flags = SA_RESETHAND; sigaction(SIGINT, &sigint, NULL); redraw(&window, NULL, 0); while (running) wl_display_iterate(display.display, display.mask); fprintf(stderr, "simple-egl exiting\n"); destroy_surface(&window); fini_egl(&display); if (display.shell) wl_shell_destroy(display.shell); if (display.compositor) wl_compositor_destroy(display.compositor); wl_display_flush(display.display); wl_display_disconnect(display.display); return 0; }
int main(int argc, char **argv){ unsigned type = PLR_X_CPU; int key_pressed = 0; awake_the_weaver(); // Initializing Weaver API hide_cursor(); copyleft(); intro(); surface *title = new_image("title.png"); for(;;){ int esc_pressed = 0; int x = (window_width - title -> width) / 2; int y = (window_height - title -> height) / 2; fill_screen(BLACK); draw_surface(title, window, x, y); draw_gametype(type % 4, x + 120, y + 60); key_pressed = 0; for(;;){ get_input(); if(keyboard[ESC]){ esc_pressed = 1; break; } if(keyboard[ENTER]){ fill_screen(BLACK); flush(); game(type % 4); break; } else if(keyboard[LEFT]){ if(!key_pressed){ type --; draw_gametype(type % 4, x + 120, y + 60); } } else if(keyboard[RIGHT]){ if(!key_pressed){ type ++; draw_gametype(type % 4, x + 120, y + 60); } } key_pressed = keyboard[ANY]; weaver_rest(10000000); } if(esc_pressed) break; } destroy_surface(title); may_the_weaver_sleep(); return 0; }
// This function initializes our background. It should be called once in // the beginning of the program void initialize_background(void){ // First we load the file "texture.png" located in the directory "images" surface *texture = new_image("texture.png"); // Next we allocate space for our background. It'll have the same // width than the screen. But how the first 100 lines of the screen // will be occupied by the scores, it'll have a height 100 pixels // smaller. background = new_surface(window_width, window_height - 100); // Now we apply the texture to our bigger surface. apply_texture(texture, background); // Done. Now we don't need the texture anymore. We destroy the surface // that stores the texture. destroy_surface(texture); }
static void produce_command(void) { static int target_surface = 0; static int cmd_index = 0; Command *command; if (has_secondary) target_surface = 1; ASSERT(g_num_commands); command = &g_commands[cmd_index]; if (command->cb) { command->cb(command); } switch (command->command) { case SLEEP: printf("sleep %u seconds\n", command->sleep.secs); sleep(command->sleep.secs); break; case PATH_PROGRESS: path_progress(&path); break; case SIMPLE_UPDATE: { QXLRect rect = {.left = 0, .right = (target_surface == 0 ? test_width : SURF_WIDTH), .top = 0, .bottom = (target_surface == 0 ? test_height : SURF_HEIGHT)}; qxl_worker->update_area(qxl_worker, target_surface, &rect, NULL, 0, 1); break; } /* Drawing commands, they all push a command to the command ring */ case SIMPLE_COPY_BITS: case SIMPLE_DRAW_SOLID: case SIMPLE_DRAW_BITMAP: case SIMPLE_DRAW: { SimpleSpiceUpdate *update; if (has_automated_tests) { if (control == 0) { return; } regression_test(); } switch (command->command) { case SIMPLE_COPY_BITS: update = test_spice_create_update_copy_bits(0); break; case SIMPLE_DRAW: update = test_spice_create_update_draw(0, path.t); break; case SIMPLE_DRAW_BITMAP: update = test_spice_create_update_from_bitmap(command->bitmap.surface_id, command->bitmap.bbox, command->bitmap.bitmap, command->bitmap.num_clip_rects, command->bitmap.clip_rects); break; case SIMPLE_DRAW_SOLID: update = test_spice_create_update_solid(command->solid.surface_id, command->solid.bbox, command->solid.color); break; } push_command(&update->ext); break; } case SIMPLE_CREATE_SURFACE: { SimpleSurfaceCmd *update; target_surface = MAX_SURFACE_NUM - 1; update = create_surface(target_surface, SURF_WIDTH, SURF_HEIGHT, g_secondary_surface); push_command(&update->ext); has_secondary = 1; break; } case SIMPLE_DESTROY_SURFACE: { SimpleSurfaceCmd *update; has_secondary = 0; update = destroy_surface(target_surface); target_surface = 0; push_command(&update->ext); break; } case DESTROY_PRIMARY: qxl_worker->destroy_primary_surface(qxl_worker, 0); break; case CREATE_PRIMARY: create_primary_surface(qxl_worker, command->create_primary.width, command->create_primary.height); break; } cmd_index = (cmd_index + 1) % g_num_commands; } SpiceTimer *wakeup_timer; int wakeup_ms = 50; SpiceCoreInterface *g_core; static int req_cmd_notification(QXLInstance *qin) { g_core->timer_start(wakeup_timer, wakeup_ms); return TRUE; }
int game(int type){ int game_over = 0; { surface *background = new_image("background.png"); apply_texture(background, window); destroy_surface(background); } initialize_cameras();initialize_star();initialize_ships(2);initialize_dust(); initialize_shot();initialize_ai(); play_music("music.ogg"); draw_tank(0, (window_width / 2 - 421), window_height / 2 - 150); draw_tank(1, window_width / 2 + 401, window_height / 2 - 150); // Main loop for(;;){ int i; get_input(); if(keyboard[ESC] || game_over){ break; } for(i = 0; i < 2; i ++) if(ship[i].status == DEAD){ struct timeval now; gettimeofday(&now, NULL); if((int) (now.tv_sec - ship[i].time.tv_sec) > 2) game_over = 1; } erase_ships(); erase_shot(); if(type != CPU_X_CPU){ // Rotation: 10 Propulse: 20 Fire: 20 Hyper: 180 int my_ship; // Player 1 moves if(type == CPU_X_PLR){ ai_play(0); my_ship = 1; } else if(type == PLR_X_CPU){ my_ship = 0; ai_play(1); } else my_ship = 0; if(keyboard[LEFT]) rotate_ship(my_ship, LEFT); if(keyboard[RIGHT]) rotate_ship(my_ship, RIGHT); if(keyboard[UP]) propulse_ship(my_ship); if(keyboard[DOWN]) ship_fire(my_ship); if(keyboard[RIGHT_CTRL]) goto_hyperspace(my_ship); } else{ ai_play(0); ai_play(1); } if(type == PLR_X_PLR){ // Player 2 moves if(keyboard[A]) rotate_ship(1, LEFT); if(keyboard[D]) rotate_ship(1, RIGHT); if(keyboard[W]) propulse_ship(1); if(keyboard[L]) blow_up(1); if(keyboard[S]) ship_fire(1); if(keyboard[LEFT_CTRL]) goto_hyperspace(1); } update_star(); // 6 update_ships(); // 2 update_dust(); // 145 update_shot(); // 16 film_ships(); // Até 16 film_dust(); // 20 film_shot(); // Até 20 weaver_rest(10000000); } stop_music(); destroy_star(); destroy_ships(); destroy_cameras(); destroy_dust(); destroy_shot(); clean_keyboard(); return 0; }
static EGLBoolean egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx) { struct egl_g3d_context *gctx = egl_g3d_context(ctx); struct egl_g3d_surface *gdraw = egl_g3d_surface(draw); struct egl_g3d_surface *gread = egl_g3d_surface(read); struct egl_g3d_context *old_gctx; _EGLContext *old_ctx; _EGLSurface *old_draw, *old_read; EGLBoolean ok = EGL_TRUE; /* make new bindings */ if (!_eglBindContext(ctx, draw, read, &old_ctx, &old_draw, &old_read)) return EGL_FALSE; old_gctx = egl_g3d_context(old_ctx); if (old_gctx) { /* flush old context */ old_gctx->stctxi->flush(old_gctx->stctxi, ST_FLUSH_FRONT, NULL); } if (gctx) { ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi, (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL); if (ok) { if (gdraw) { if (gdraw->base.Type == EGL_WINDOW_BIT) { gctx->base.WindowRenderBuffer = (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ? EGL_SINGLE_BUFFER : EGL_BACK_BUFFER; } } } } else if (old_gctx) { ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL); if (ok) old_gctx->base.WindowRenderBuffer = EGL_NONE; } if (ok) { if (_eglPutContext(old_ctx)) destroy_context(dpy, old_ctx); if (_eglPutSurface(old_draw)) destroy_surface(dpy, old_draw); if (_eglPutSurface(old_read)) destroy_surface(dpy, old_read); } else { /* undo the previous _eglBindContext */ _eglBindContext(old_ctx, old_draw, old_read, &ctx, &draw, &read); assert(&gctx->base == ctx && &gdraw->base == draw && &gread->base == read); _eglPutSurface(draw); _eglPutSurface(read); _eglPutContext(ctx); _eglPutSurface(old_draw); _eglPutSurface(old_read); _eglPutContext(old_ctx); } return ok; }
static void produce_command(Test *test) { Command *command; QXLWorker *qxl_worker = test->qxl_worker; spice_assert(qxl_worker); if (test->has_secondary) test->target_surface = 1; if (!test->num_commands) { usleep(1000); return; } command = &test->commands[test->cmd_index]; if (command->cb) { command->cb(test, command); } switch (command->command) { case SLEEP: printf("sleep %u seconds\n", command->sleep.secs); sleep(command->sleep.secs); break; case PATH_PROGRESS: path_progress(&path); break; case SIMPLE_UPDATE: { QXLRect rect = { .left = 0, .right = (test->target_surface == 0 ? test->primary_width : test->width), .top = 0, .bottom = (test->target_surface == 0 ? test->primary_height : test->height) }; if (rect.right > 0 && rect.bottom > 0) { spice_qxl_update_area(&test->qxl_instance, test->target_surface, &rect, NULL, 0, 1); } break; } /* Drawing commands, they all push a command to the command ring */ case SIMPLE_COPY_BITS: case SIMPLE_DRAW_SOLID: case SIMPLE_DRAW_BITMAP: case SIMPLE_DRAW: { SimpleSpiceUpdate *update; if (has_automated_tests) { if (control == 0) { return; } regression_test(); } switch (command->command) { case SIMPLE_COPY_BITS: update = test_spice_create_update_copy_bits(test, 0); break; case SIMPLE_DRAW: update = test_spice_create_update_draw(test, 0, path.t); break; case SIMPLE_DRAW_BITMAP: update = test_spice_create_update_from_bitmap(command->bitmap.surface_id, command->bitmap.bbox, command->bitmap.bitmap, command->bitmap.num_clip_rects, command->bitmap.clip_rects); break; case SIMPLE_DRAW_SOLID: update = test_spice_create_update_solid(command->solid.surface_id, command->solid.bbox, command->solid.color); break; default: /* Just to shut up GCC warning (-Wswitch) */ break; } push_command(&update->ext); break; } case SIMPLE_CREATE_SURFACE: { SimpleSurfaceCmd *update; if (command->create_surface.data) { spice_assert(command->create_surface.surface_id > 0); spice_assert(command->create_surface.surface_id < MAX_SURFACE_NUM); spice_assert(command->create_surface.surface_id == 1); update = create_surface(command->create_surface.surface_id, command->create_surface.format, command->create_surface.width, command->create_surface.height, command->create_surface.data); } else { update = create_surface(test->target_surface, SPICE_SURFACE_FMT_32_xRGB, SURF_WIDTH, SURF_HEIGHT, test->secondary_surface); } push_command(&update->ext); test->has_secondary = 1; break; } case SIMPLE_DESTROY_SURFACE: { SimpleSurfaceCmd *update; test->has_secondary = 0; update = destroy_surface(test->target_surface); test->target_surface = 0; push_command(&update->ext); break; } case DESTROY_PRIMARY: spice_qxl_destroy_primary_surface(&test->qxl_instance, 0); break; case CREATE_PRIMARY: create_primary_surface(test, command->create_primary.width, command->create_primary.height); break; } test->cmd_index = (test->cmd_index + 1) % test->num_commands; } static int req_cmd_notification(QXLInstance *qin) { Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); test->core->timer_start(test->wakeup_timer, test->wakeup_ms); return TRUE; }
int main(int argc, char **argv) { struct sigaction sigint; struct display display = { 0 }; struct window window = { 0 }; int i, ret = 0; window.display = &display; display.window = &window; window.window_size.width = 250; window.window_size.height = 250; window.buffer_size = 32; window.frame_sync = 1; for (i = 1; i < argc; i++) { if (strcmp("-f", argv[i]) == 0) window.fullscreen = 1; else if (strcmp("-o", argv[i]) == 0) window.opaque = 1; else if (strcmp("-s", argv[i]) == 0) window.buffer_size = 16; else if (strcmp("-b", argv[i]) == 0) window.frame_sync = 0; else if (strcmp("-h", argv[i]) == 0) usage(EXIT_SUCCESS); else usage(EXIT_FAILURE); } display.display = wl_display_connect(NULL); assert(display.display); display.registry = wl_display_get_registry(display.display); wl_registry_add_listener(display.registry, ®istry_listener, &display); wl_display_dispatch(display.display); init_egl(&display, &window); create_surface(&window); init_gl(&window); display.cursor_surface = wl_compositor_create_surface(display.compositor); sigint.sa_handler = signal_int; sigemptyset(&sigint.sa_mask); sigint.sa_flags = SA_RESETHAND; sigaction(SIGINT, &sigint, NULL); /* The mainloop here is a little subtle. Redrawing will cause * EGL to read events so we can just call * wl_display_dispatch_pending() to handle any events that got * queued up as a side effect. */ while (running && ret != -1) { wl_display_dispatch_pending(display.display); redraw(&window, NULL, 0); } fprintf(stderr, "simple-egl exiting\n"); destroy_surface(&window); fini_egl(&display); wl_surface_destroy(display.cursor_surface); if (display.cursor_theme) wl_cursor_theme_destroy(display.cursor_theme); if (display.shell) xdg_shell_destroy(display.shell); if (display.compositor) wl_compositor_destroy(display.compositor); wl_registry_destroy(display.registry); wl_display_flush(display.display); wl_display_disconnect(display.display); return 0; }
int main(int argc, char **argv) { struct sigaction sigint; struct display display = { 0 }; struct window window = { 0 }; int i, ret = 0; window.display = &display; display.window = &window; window.window_size.width = 250; window.window_size.height = 250; for (i = 1; i < argc; i++) { if (strcmp("-f", argv[i]) == 0) window.fullscreen = 1; else if (strcmp("-o", argv[i]) == 0) window.opaque = 1; else if (strcmp("-h", argv[i]) == 0) usage(EXIT_SUCCESS); else usage(EXIT_FAILURE); } display.display = wl_display_connect(NULL); assert(display.display); display.registry = wl_display_get_registry(display.display); wl_registry_add_listener(display.registry, ®istry_listener, &display); wl_display_dispatch(display.display); init_egl(&display, window.opaque); create_surface(&window); init_gl(&window); display.cursor_surface = wl_compositor_create_surface(display.compositor); sigint.sa_handler = signal_int; sigemptyset(&sigint.sa_mask); sigint.sa_flags = SA_RESETHAND; sigaction(SIGINT, &sigint, NULL); while (running && ret != -1) ret = wl_display_dispatch(display.display); fprintf(stderr, "simple-egl exiting\n"); destroy_surface(&window); fini_egl(&display); wl_surface_destroy(display.cursor_surface); if (display.cursor_theme) wl_cursor_theme_destroy(display.cursor_theme); if (display.shell) wl_shell_destroy(display.shell); if (display.compositor) wl_compositor_destroy(display.compositor); wl_registry_destroy(display.registry); wl_display_flush(display.display); wl_display_disconnect(display.display); return 0; }