poly_manager *poly_alloc(running_machine *machine, int max_polys, size_t extra_data_size, UINT8 flags) { poly_manager *poly; /* allocate the manager itself */ poly = auto_alloc_clear(machine, poly_manager); poly->flags = flags; /* allocate polygons */ poly->polygon_size = sizeof(polygon_info); poly->polygon_count = MAX(max_polys, 1); poly->polygon_next = 0; poly->polygon = (polygon_info **)allocate_array(machine, &poly->polygon_size, poly->polygon_count); /* allocate extra data */ poly->extra_size = extra_data_size; poly->extra_count = poly->polygon_count; poly->extra_next = 1; poly->extra = allocate_array(machine, &poly->extra_size, poly->extra_count); /* allocate triangle work units */ poly->unit_size = (flags & POLYFLAG_ALLOW_QUADS) ? sizeof(quad_work_unit) : sizeof(tri_work_unit); poly->unit_count = MIN(poly->polygon_count * UNITS_PER_POLY, 65535); poly->unit_next = 0; poly->unit = (work_unit **)allocate_array(machine, &poly->unit_size, poly->unit_count); /* create the work queue */ if (!(flags & POLYFLAG_NO_WORK_QUEUE)) poly->queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_MULTI | WORK_QUEUE_FLAG_HIGH_FREQ); /* request a pre-save callback for synchronization */ state_save_register_presave(machine, poly_state_presave, poly); return poly; }
void palette_init(running_machine *machine) { int format; palette_private *palette = auto_malloc(sizeof(*palette)); const device_config *device = video_screen_first(machine->config); /* get the format from the first screen, or use BITMAP_FORMAT_INVALID, if screenless */ if (device != NULL) { screen_config *config = device->inline_config; format = config->format; } else format = BITMAP_FORMAT_INVALID; /* request cleanup */ machine->palette_data = palette; add_exit_callback(machine, palette_exit); /* reset all our data */ memset(palette, 0, sizeof(*palette)); palette->format = format; /* determine the color mode */ switch (format) { case BITMAP_FORMAT_INDEXED16: case BITMAP_FORMAT_RGB15: case BITMAP_FORMAT_RGB32: /* indexed and RGB modes are fine for everything */ break; case BITMAP_FORMAT_INVALID: /* invalid format means no palette - or at least it should */ assert(machine->config->total_colors == 0); return; default: fatalerror("Unsupported screen bitmap format!"); break; } /* allocate all the data structures */ if (machine->config->total_colors > 0) { int numcolors; allocate_palette(machine, palette); allocate_color_tables(machine, palette); allocate_shadow_tables(machine, palette); /* set up save/restore of the palette */ numcolors = palette_get_num_colors(machine->palette); palette->save_pen = auto_malloc(sizeof(*palette->save_pen) * numcolors); palette->save_bright = auto_malloc(sizeof(*palette->save_bright) * numcolors); state_save_register_global_pointer(palette->save_pen, numcolors); state_save_register_global_pointer(palette->save_bright, numcolors); state_save_register_presave(machine, palette_presave, palette); state_save_register_postload(machine, palette_postload, palette); } }