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; }
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; }