void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) { if (mode == GLFW_CURSOR_DISABLED) { _glfw.mir.disabledCursorWindow = window; setSurfaceConfinement(window, mir_pointer_confined_to_surface); mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.disabledConf)); } else { // If we were disabled before lets undo that! if (_glfw.mir.disabledCursorWindow == window) { _glfw.mir.disabledCursorWindow = NULL; setSurfaceConfinement(window, mir_pointer_unconfined); } if (window->cursorMode == GLFW_CURSOR_NORMAL) { _glfwPlatformSetCursor(window, window->mir.currentCursor); } else if (window->cursorMode == GLFW_CURSOR_HIDDEN) { mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.disabledConf)); } } }
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) { if (cursor && cursor->mir.conf) { window->mir.currentCursor = cursor; mir_wait_for(mir_surface_configure_cursor(window->mir.surface, cursor->mir.conf)); if (cursor->mir.customCursor) { mir_buffer_stream_swap_buffers_sync(cursor->mir.customCursor); } } else { mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.defaultConf)); } }
void helper(const char* server) { MirDemoState mcd; mcd.connection = 0; mcd.surface = 0; mcd.prompt_session = 0; mcd.state = mir_prompt_session_state_stopped; mcd.client_fd_count = 0; start_session(server, "helper", &mcd); // We create a prompt session mcd.prompt_session = mir_connection_create_prompt_session_sync(mcd.connection, getpid(), prompt_session_event_callback, &mcd); assert(mcd.prompt_session != NULL); assert(mcd.state == mir_prompt_session_state_started); puts("helper: Started prompt session"); mir_wait_for(mir_prompt_session_new_fds_for_prompt_providers(mcd.prompt_session, 1, client_fd_callback, &mcd)); assert(mcd.client_fd_count == 1); puts("helper: Added waiting FD"); printf("helper: Starting child application 'mir_demo_client_basic' with fd://%d\n", mcd.client_fds[0]); mcd.child_pid = fork(); if (mcd.child_pid == 0) { char buffer[128] = {0}; sprintf(buffer, "fd://%d", mcd.client_fds[0]); char* args[4]; args[0] = "mir_demo_client_basic"; args[1] = "-m"; args[2] = &buffer[0]; args[3] = NULL; errno = 0; execvp("mir_demo_client_basic", args); return; } int status; printf("helper: Waiting on child application: %d\n", mcd.child_pid); waitpid(mcd.child_pid, &status, 0); if (mcd.state == mir_prompt_session_state_started) { mir_prompt_session_release_sync(mcd.prompt_session); mcd.prompt_session = NULL; puts("helper: Stopped prompt session"); } else { puts("helper: Prompt session stopped by server"); } puts("helper: Done"); stop_session(&mcd, "helper"); }
MirConnection *mir_toolkit::mir_connect_sync(char const *server, char const *app_name) { MirConnection *conn = nullptr; mir_wait_for(mir_connect(server, app_name, reinterpret_cast<mir_connected_callback> (assign_result), &conn)); return conn; }
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) { if (cursor && cursor->mir.conf) { mir_wait_for(mir_surface_configure_cursor(window->mir.surface, cursor->mir.conf)); if (cursor->mir.custom_cursor) { /* FIXME Bug https://bugs.launchpad.net/mir/+bug/1477285 Requires a triple buffer swap to get the cursor buffer on top! (since mir is tripled buffered) */ mir_buffer_stream_swap_buffers_sync(cursor->mir.custom_cursor); mir_buffer_stream_swap_buffers_sync(cursor->mir.custom_cursor); mir_buffer_stream_swap_buffers_sync(cursor->mir.custom_cursor); } } else { mir_wait_for(mir_surface_configure_cursor(window->mir.surface, _glfw.mir.default_conf)); } }
MirSurface *mir_toolkit::mir_surface_create_sync( MirConnection *connection, MirSurfaceParameters const *params) { MirSurface *surface = nullptr; mir_wait_for(mir_surface_create(connection, params, reinterpret_cast<mir_surface_lifecycle_callback>(assign_result), &surface)); return surface; }
// Regression test for LP:#1340669 // Test is not deterministic since we are testing a race, but failure can be // reproduced easily with repeated runs. TEST_F(ClientWithCustomDisplayConfiguration, does_not_deadlock_server_with_existing_client_when_disconnecting) { auto second_connection = mir_connect_sync(new_connection().c_str(), __PRETTY_FUNCTION__); auto second_surface = mtf::make_any_surface(connection); ASSERT_TRUE(mir_surface_is_valid(second_surface)); auto configuration = mir_connection_create_display_config(connection); mir_wait_for(mir_connection_apply_display_config(connection, configuration)); EXPECT_STREQ("", mir_connection_get_error_message(connection)); mir_display_config_destroy(configuration); mir_connection_release(second_connection); // Server (and therefore the test) will deadlock and won't be able to // shut down without the fix. It's not ideal to deadlock on test failure, // but it's the best check we have at the moment. }
SDL_Surface* Mir_SetVideoMode(_THIS, SDL_Surface* current, int width, int height, int bpp, Uint32 flags) { if (this->hidden->surface && mir_surface_is_valid(this->hidden->surface)) { mir_surface_release_sync(this->hidden->surface); this->hidden->surface = NULL; } Uint32 output_id = mir_display_output_id_invalid; if (flags & SDL_FULLSCREEN) { MirDisplayConfiguration* display_config = mir_connection_create_display_config(this->hidden->connection); Uint32 fallback_output_id = mir_display_output_id_invalid; Uint32 d; Uint32 m; this->hidden->mode_changed = SDL_FALSE; for (d = 0; d < display_config->num_outputs; ++d) { MirDisplayOutput const* out = display_config->outputs + d; if (out->used && out->connected) { if (out->modes[out->current_mode].horizontal_resolution == width && out->modes[out->current_mode].vertical_resolution == height) { output_id = out->output_id; break; } if (fallback_output_id == mir_display_output_id_invalid && out->modes[out->current_mode].horizontal_resolution >= width && out->modes[out->current_mode].vertical_resolution >= height) { fallback_output_id = out->output_id; } } } if (output_id == mir_display_output_id_invalid) { for (d = 0; d < display_config->num_outputs; ++d) { MirDisplayOutput* out = display_config->outputs + d; if (out->used && out->connected) { for (m = 0; m < out->num_modes; ++m) { if (out->modes[m].horizontal_resolution == width && out->modes[m].vertical_resolution == height) { this->hidden->mode_changed = SDL_TRUE; output_id = out->output_id; out->current_mode = m; mir_wait_for( mir_connection_apply_display_config(this->hidden->connection, display_config) ); break; } } } } } if (fallback_output_id == mir_display_output_id_invalid) { /* There's no native resolution for the requested format, so let's * just ensure we've an output large enough to show it */ for (d = 0; d < display_config->num_outputs; ++d) { MirDisplayOutput* out = display_config->outputs + d; if (out->used && out->connected) { for (m = 0; m < out->num_modes; ++m) { if (out->modes[m].horizontal_resolution >= width && out->modes[m].vertical_resolution >= height) { this->hidden->mode_changed = SDL_TRUE; fallback_output_id = out->output_id; out->current_mode = m; mir_wait_for( mir_connection_apply_display_config(this->hidden->connection, display_config) ); break; } } } } /* Setting output_id = fallback_output_id here seems to cause * troubles to mir in creating a new surface */ } mir_display_config_destroy(display_config); if (output_id == mir_display_output_id_invalid && fallback_output_id == mir_display_output_id_invalid) { SDL_SetError("Impossible to find a valid output for mode %dx%d", width, height); return NULL; } } else if (this->hidden->mode_changed) { Uint32 d; SDL_bool any_changed = SDL_FALSE; MirDisplayConfiguration* display_config = mir_connection_create_display_config(this->hidden->connection); for (d = 0; d < display_config->num_outputs; ++d) { MirDisplayOutput* out = display_config->outputs + d; if (out->used && out->connected) { if (out->current_mode != out->preferred_mode) { out->current_mode = out->preferred_mode; any_changed = SDL_TRUE; } } } if (any_changed) { mir_wait_for( mir_connection_apply_display_config(this->hidden->connection, display_config) ); } this->hidden->mode_changed = SDL_FALSE; mir_display_config_destroy(display_config); } MirSurfaceParameters surfaceparm = { .name = "MirSurface", .width = width, .height = height, .pixel_format = this->hidden->pixel_format, .output_id = output_id, .buffer_usage = (flags & SDL_OPENGL) ? mir_buffer_usage_hardware : mir_buffer_usage_software, }; this->hidden->surface = mir_connection_create_surface_sync(this->hidden->connection, &surfaceparm); if (!mir_surface_is_valid(this->hidden->surface)) { const char* error = mir_surface_get_error_message(this->hidden->surface); SDL_SetError("Failed to created a mir surface: %s", error); mir_surface_release_sync(this->hidden->surface); return NULL; } MirEventDelegate delegate = { Mir_HandleSurfaceEvent, NULL }; mir_surface_set_event_handler(this->hidden->surface, &delegate); if (flags & SDL_OPENGL) { current->flags |= SDL_OPENGL; if (Mir_GL_CreateESurface(this) < 0) { SDL_SetError("Could not Create EGL Surface"); return NULL; } if (Mir_GL_CreateContext(this) < 0) { SDL_SetError("Could not Create GL Context"); return NULL; } } else { if ((current->w != width || current->h != height)) { current->pixels = NULL; current->w = width; current->h = height; current->pitch = SDL_CalculatePitch(current); current->pixels = SDL_calloc(1, current->h * current->pitch); if (!current->pixels) { SDL_OutOfMemory(); return NULL; } this->UpdateRects = Mir_UpdateRects; } } return current; } static void Mir_ModeListFree(_THIS) { if (this->hidden->modelist) { int i = 0; while (this->hidden->modelist[i] != NULL) { SDL_free(this->hidden->modelist[i]); ++i; } SDL_free(this->hidden->modelist); this->hidden->modelist = NULL; } } static void Mir_ModeListUpdate(_THIS) { Uint32 d, m; Uint32 valid_outputs = 0; Mir_ModeListFree(this); MirDisplayConfiguration* display_config = mir_connection_create_display_config(this->hidden->connection); for (d = 0; d < display_config->num_outputs; d++) { MirDisplayOutput const* out = display_config->outputs + d; if (out->used && out->connected) valid_outputs += out->num_modes; } this->hidden->modelist = SDL_calloc(valid_outputs + 1, sizeof(SDL_Rect*)); valid_outputs = 0; for (d = 0; d < display_config->num_outputs; ++d) { MirDisplayOutput const* out = display_config->outputs + d; if (out->used && out->connected) { for (m = 0; m < out->num_modes; ++m) { SDL_Rect* sdl_output = SDL_calloc(1, sizeof(SDL_Rect)); sdl_output->x = out->position_x; sdl_output->y = out->position_y; sdl_output->w = out->modes[m].horizontal_resolution; sdl_output->h = out->modes[m].vertical_resolution; this->hidden->modelist[valid_outputs] = sdl_output; ++valid_outputs; } } } this->hidden->modelist[valid_outputs] = NULL; mir_display_config_destroy(display_config); }
void mir_buffer_stream_swap_buffers_sync(MirBufferStream* buffer_stream) { mir_wait_for(mir_buffer_stream_swap_buffers(buffer_stream, reinterpret_cast<mir_buffer_stream_callback>(assign_result), nullptr)); }
void mcla::ClientSurfaceInterpreter::driver_returns_buffer(ANativeWindowBuffer*) { mir_wait_for(surface.next_buffer(empty, NULL)); }
void mir_toolkit::mir_surface_next_buffer_sync(MirSurface *surface) { mir_wait_for(mir_surface_next_buffer(surface, reinterpret_cast<mir_surface_lifecycle_callback>(assign_result), nullptr)); }