NativeStateMir::~NativeStateMir()
{
    if (mir_surface_)
        mir_surface_release_sync(mir_surface_);
    if (mir_connection_)
        mir_connection_release(mir_connection_);
}
示例#2
0
文件: mir_init.c 项目: cpichard/glfw
void _glfwPlatformTerminate(void)
{
    _glfwTerminateContextAPI();
    _glfwTerminateJoysticks();

    mir_connection_release(_glfw.mir.connection);
}
示例#3
0
static void
gdk_mir_display_finalize (GObject *object)
{
  GdkMirDisplay *display = GDK_MIR_DISPLAY (object);

  mir_connection_release (display->connection);

  G_OBJECT_CLASS (gdk_mir_display_parent_class)->finalize (object);
}
示例#4
0
GdkDisplay *
_gdk_mir_display_open (const gchar *display_name)
{
  MirConnection *connection;
  MirPixelFormat sw_pixel_format, hw_pixel_format;
  GdkMirDisplay *display;

  //g_printerr ("gdk_mir_display_open\n");

  connection = mir_connect_sync (NULL, "GDK-Mir");
  if (!connection)
     return NULL;

  if (!mir_connection_is_valid (connection))
    {
      g_printerr ("Failed to connect to Mir: %s\n", mir_connection_get_error_message (connection));
      mir_connection_release (connection);
      return NULL;
    }

  get_pixel_formats (connection, &sw_pixel_format, &hw_pixel_format);

  if (sw_pixel_format == mir_pixel_format_invalid ||
      hw_pixel_format == mir_pixel_format_invalid)
    {
      g_printerr ("Mir display does not support required pixel formats\n");
      mir_connection_release (connection);
      return NULL;
    }

  display = g_object_new (GDK_TYPE_MIR_DISPLAY, NULL);

  display->connection = connection;
  GDK_DISPLAY (display)->device_manager = _gdk_mir_device_manager_new (GDK_DISPLAY (display));
  display->screen = _gdk_mir_screen_new (GDK_DISPLAY (display));
  display->sw_pixel_format = sw_pixel_format;
  display->hw_pixel_format = hw_pixel_format;

  g_signal_emit_by_name (display, "opened");

  return GDK_DISPLAY (display);
}
示例#5
0
void _glfwPlatformTerminate(void)
{
    _glfwTerminateContextAPI();
    _glfwTerminateJoysticks();

    _glfwDeleteEventQueue(_glfw.mir.event_queue);

    pthread_mutex_destroy(&_glfw.mir.event_mutex);

    mir_connection_release(_glfw.mir.connection);
}
示例#6
0
void _glfwPlatformTerminate(void)
{
    _glfwTerminateEGL();
    _glfwTerminateJoysticksLinux();
    _glfwTerminateThreadLocalStoragePOSIX();

    _glfwDeleteEventQueueMir(_glfw.mir.eventQueue);

    pthread_mutex_destroy(&_glfw.mir.eventMutex);

    mir_connection_release(_glfw.mir.connection);
}
示例#7
0
void stop_session(MirDemoState* mcd, const char* name)
{
    if (mcd->surface)
    {
        // We should release our surface
        mir_surface_release_sync(mcd->surface);
        mcd->surface = 0;
        printf("%s: Surface released\n", name);
    }

    // We should release our connection
    mir_connection_release(mcd->connection);
    printf("%s: Connection released\n", name);
}
bool uamc::Instance::connect(std::string const& application_name)
{
    auto mir_connection = mir_connect_sync(NULL, application_name.c_str());

    // mir_connect_sync() always returns a connection object, even in case
    // of a failed connection. We need to release this object in all cases.
    con = ConnectionPtr(mir_connection,
        [](MirConnection *c)
        {
            mir_connection_release(c);
        });

    return mir_connection_is_valid(mir_connection);
}
示例#9
0
int Mir_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
    this->hidden->connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__);

    if (!mir_connection_is_valid(this->hidden->connection))
    {
        SDL_SetError("Failed to connect to the Mir Server: %s",
                     mir_connection_get_error_message(this->hidden->connection));
        mir_connection_release(this->hidden->connection);
        return -1;
    }

    MirPixelFormat formats[mir_pixel_formats];
    Uint32 n_formats;

    mir_connection_get_available_surface_formats (this->hidden->connection, formats,
                                                  mir_pixel_formats, &n_formats);

    if (n_formats == 0 || formats[0] == mir_pixel_format_invalid)
    {
        SDL_SetError("No valid pixel formats found");
        mir_connection_release(this->hidden->connection);
        return -1;
    }

    this->hidden->pixel_format = formats[0];
    vformat->BitsPerPixel = MIR_BYTES_PER_PIXEL(this->hidden->pixel_format) * 8;

    Mir_InitQueue(this->hidden->buffer_queue);
    Mir_ModeListUpdate(this);
    mir_connection_set_display_config_change_callback(this->hidden->connection,
                                                      Mir_DisplayConfigChanged, this);

    this->info.wm_available = 1;

    return 0;
}
// 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.
}
示例#11
0
// FIXME Make sure we clean everything up, Also:
// we get a crash (call of virtual function) when releasing the connection :(
void Mir_VideoQuit(_THIS)
{
    Mir_DeleteQueue(this->hidden->buffer_queue);

    if (this->hidden->buffer_queue)
    {
        SDL_free(this->hidden->buffer_queue);
    }

    if (this->hidden->surface)
    {
        mir_surface_release_sync(this->hidden->surface);
        this->hidden->surface = NULL;
    }

#if SDL_VIDEO_OPENGL
    if (this->gl_config.driver_loaded != 0)
    {
        Mir_GL_DeleteContext(this);
        Mir_GL_UnloadLibrary(this);
    }
#endif // SDL_VIDEO_OPENGL

    if (mir_connection_is_valid(this->hidden->connection))
    {
        mir_connection_set_display_config_change_callback(this->hidden->connection,
                                                          NULL, NULL);
    }

    if (this->hidden->connection)
    {
        mir_connection_release(this->hidden->connection);
        this->hidden->connection = NULL;
    }

    Mir_ModeListFree(this);
}
TEST_F(UnresponsiveClient, does_not_hang_server)
{
    mt::CrossProcessAction server_send_events;
    mt::CrossProcessAction client_connect;
    mt::CrossProcessAction client_release;
    mt::CrossProcessAction server_finish;

    SessionListener sessions;

    init_server([&]
         {
            server.override_the_session_listener([&]
                { return mt::fake_shared(sessions); });
         });

    run_in_server([&]
        {
            mt::AutoJoinThread t{
                [&] {
                    server_send_events.exec([&]
                        {
                            for (int i = 0; i < 1000; ++i)
                            {
                                sessions.for_each(
                                    [i] (std::shared_ptr<ms::Session> const& session)
                                    {
                                        session->default_surface()->resize({i + 1, i + 1});
                                    });
                            }
                        });
                }};

            server_finish.exec([]{});
        });

    auto const client_code = [&]
    {
        MirConnection* connection = nullptr;
        MirSurface* surface = nullptr;

        client_connect.exec([&]
            {
                connection = mir_connect_sync(mir_test_socket, __PRETTY_FUNCTION__);

                surface = mtf::make_any_surface(connection);
            });

        client_release.exec([&]
            {
                // We would normally explicitly release the surface at this
                // point. However, because we have been filling the server
                // send socket buffer, releasing the surface may cause the
                // server to try to write to a full socket buffer when
                // responding, leading the server to believe that the client
                // is blocked, and causing a premature client disconnection.
                mir_connection_release(connection);
            });
    };

    auto client_process = new_client_process(client_code);

    if (is_test_process())
    {
        client_connect();
        kill(client_pid(), SIGSTOP);
        try 
        { 
            server_send_events(std::chrono::seconds{10});
        }
        catch(...)
        { 
            ADD_FAILURE() << "Server blocked while sending events";
        }
        kill(client_pid(), SIGCONT);
        client_release();
        server_finish();

        auto const result = client_process->wait_for_termination();
        EXPECT_THAT(result.exit_code, testing::Eq(EXIT_SUCCESS));
    }
}
示例#13
0
MirDisplayConnection::~MirDisplayConnection() {
  mir_connection_release(connection_);
}