示例#1
0
int _glfwPlatformInit(void)
{
    int error;

    _glfw.mir.connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__);

    if (!mir_connection_is_valid(_glfw.mir.connection))
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Mir: Unable to connect to Server");
        return GL_FALSE;
    }

    _glfw.mir.display =
        mir_connection_get_egl_native_display(_glfw.mir.connection);

    if (!_glfwInitContextAPI())
        return GL_FALSE;

    _glfwInitTimer();
    _glfwInitJoysticks();

    _glfw.mir.event_queue = calloc(1, sizeof(EventQueue));
    _glfwInitEventQueue(_glfw.mir.event_queue);

    error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL);
    if (error)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Mir: Failed to create Event Mutex Error: %i\n", error);
        return GL_FALSE;
    }

    return GL_TRUE;
}
void*
NativeStateMir::display()
{
    if (mir_connection_is_valid(mir_connection_))
        return static_cast<void*>(mir_connection_get_egl_native_display(mir_connection_));

    return 0;
}
bool IsValidMatcher::MatchAndExplain(MirConnection* connection, MatchResultListener* listener) const
{
    if (connection == nullptr)
    {
        return false;
    }
    if (!mir_connection_is_valid(connection))
    {
        *listener << "error is: " << mir_connection_get_error_message(connection);
        return false;
    }
    return true;
}
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);
}
示例#5
0
MirDisplayConnection::MirDisplayConnection()
    : connection_(nullptr),
      output_id_(-1),
      vertical_resolution_(0),
      horizontal_resolution_(0) {
  auto xdg_runtime_dir = ::getenv("XDG_RUNTIME_DIR");
  if (!xdg_runtime_dir)
    BOOST_THROW_EXCEPTION(std::runtime_error("Failed to find XDG_RUNTIME_DIR"));

  std::string socket_path = xdg_runtime_dir;
  socket_path += "/mir_socket";

  connection_ = mir_connect_sync(socket_path.c_str(), "anbox");
  if (!mir_connection_is_valid(connection_)) {
    std::string msg;
    msg += "Failed to connect with Mir server: ";
    msg += mir_connection_get_error_message(connection_);
    BOOST_THROW_EXCEPTION(std::runtime_error(msg.c_str()));
  }

  mir_connection_set_display_config_change_callback(
      connection_,
      [](MirConnection *connection, void *context) {
        auto thiz = reinterpret_cast<MirDisplayConnection *>(context);
        DEBUG("");
      },
      this);

  MirDisplayConfiguration *display_config =
      mir_connection_create_display_config(connection_);

  const MirDisplayOutput *output = find_active_output(display_config);
  if (!output)
    BOOST_THROW_EXCEPTION(
        std::runtime_error("Failed to find active output display"));

  DEBUG("Selecting output id %d", output->output_id);

  output_id_ = output->output_id;

  const MirDisplayMode *mode = &output->modes[output->current_mode];

  vertical_resolution_ = mode->vertical_resolution;
  horizontal_resolution_ = mode->horizontal_resolution;

  mir_display_config_destroy(display_config);
}
示例#6
0
文件: mir_init.c 项目: dumganhar/glfw
int _glfwPlatformInit(void)
{
    int error;

    _glfw.mir.connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__);

    if (!mir_connection_is_valid(_glfw.mir.connection))
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Mir: Unable to connect to server: %s",
                        mir_connection_get_error_message(_glfw.mir.connection));

        return GLFW_FALSE;
    }

    _glfw.mir.display =
        mir_connection_get_egl_native_display(_glfw.mir.connection);

    createKeyTables();

    if (!_glfwInitThreadLocalStoragePOSIX())
        return GLFW_FALSE;

    if (!_glfwInitJoysticksLinux())
        return GLFW_FALSE;

    _glfwInitTimerPOSIX();

    // Need the default conf for when we set a NULL cursor
    _glfw.mir.defaultConf  = mir_cursor_configuration_from_name(mir_default_cursor_name);
    _glfw.mir.disabledConf = mir_cursor_configuration_from_name(mir_disabled_cursor_name);

    _glfw.mir.eventQueue = calloc(1, sizeof(EventQueue));
    _glfwInitEventQueueMir(_glfw.mir.eventQueue);

    error = pthread_mutex_init(&_glfw.mir.eventMutex, NULL);
    if (error)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Mir: Failed to create event mutex: %s",
                        strerror(error));
        return GLFW_FALSE;
    }

    _glfwPollMonitorsMir();
    return GLFW_TRUE;
}
示例#7
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);
}
bool
NativeStateMir::init_display()
{
    struct sigaction sa;
    sa.sa_handler = &NativeStateMir::quit_handler;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);

    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);

    mir_connection_ = mir_connect_sync(NULL, "glmark2");

    if (!mir_connection_is_valid(mir_connection_)) {
        Log::error("Couldn't connect to the Mir display server\n");
        return false;
    }

    return true;
}
示例#9
0
文件: mir_init.c 项目: cpichard/glfw
int _glfwPlatformInit(void)
{
    _glfw.mir.connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__);

    if (!mir_connection_is_valid(_glfw.mir.connection))
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Mir: Unable to connect to Server");
        return GL_FALSE;
    }

    _glfw.mir.display =
        mir_connection_get_egl_native_display(_glfw.mir.connection);

    if (!_glfwInitContextAPI())
        return GL_FALSE;

    _glfwInitTimer();
    _glfwInitJoysticks();

    return GL_TRUE;
}
示例#10
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);
}
示例#11
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;
}
示例#12
0
void start_session(const char* server, const char* name, MirDemoState* mcd)
{
    // Call mir_connect synchronously
    mcd->connection = mir_connect_sync(server, name);

    // We expect a connection handle;
    // we expect it to be valid; and,
    // we don't expect an error description
    assert(mcd->connection != NULL);
    assert(mir_connection_is_valid(mcd->connection));
    assert(strcmp(mir_connection_get_error_message(mcd->connection), "") == 0);
    printf("%s: Connected\n", name);

    // We can query information about the platform we're running on
    {
        MirPlatformPackage platform_package;
        platform_package.data_items = -1;
        platform_package.fd_items = -1;

        mir_connection_get_platform(mcd->connection, &platform_package);
        assert(0 <= platform_package.data_items);
        assert(0 <= platform_package.fd_items);
    }
}
bool
NativeStateMir::create_window(WindowProperties const& properties)
{
    static const char *win_name("glmark2 "GLMARK_VERSION);

    if (!mir_connection_is_valid(mir_connection_)) {
        Log::error("Cannot create a Mir surface without a valid connection "
                   "to the Mir display server!\n");
        return false;
    }

    /* Recreate an existing window only if it has actually been resized */
    if (mir_surface_) {
        if (properties_.fullscreen != properties.fullscreen ||
            (properties.fullscreen == false &&
             (properties_.width != properties.width ||
              properties_.height != properties.height)))
        {
            mir_surface_release_sync(mir_surface_);
            mir_surface_ = 0;
        }
        else
        {
            return true;
        }
    }

    uint32_t output_id = mir_display_output_id_invalid;

    properties_ = properties;

    if (properties_.fullscreen) {
        DisplayConfiguration display_config(mir_connection_);
        if (!display_config.is_valid()) {
            Log::error("Couldn't get display configuration from the Mir display server!\n");
            return false;
        }

        const MirDisplayOutput* active_output = find_active_output(display_config);
        if (active_output == NULL) {
            Log::error("Couldn't find an active output in the Mir display server!\n");
            return false;
        }

        const MirDisplayMode* current_mode =
            &active_output->modes[active_output->current_mode];

        properties_.width = current_mode->horizontal_resolution;
        properties_.height = current_mode->vertical_resolution;
        output_id = active_output->output_id;

        Log::debug("Making Mir surface fullscreen on output %u (%ux%u)\n",
                   output_id, properties_.width, properties_.height);
    }

    MirPixelFormat surface_format = find_best_surface_format(mir_connection_);
    if (surface_format == mir_pixel_format_invalid) {
        Log::error("Couldn't find a pixel format to use for the Mir surface!\n");
        return false;
    }

    Log::debug("Using pixel format %u for the Mir surface\n", surface_format);

    MirSurfaceParameters surface_parameters = {
        win_name,
        properties_.width, properties_.height,
        surface_format,
        mir_buffer_usage_hardware,
        output_id
    };

    mir_surface_ = mir_connection_create_surface_sync(mir_connection_,
                                                      &surface_parameters);

    if (!mir_surface_ || !mir_surface_is_valid(mir_surface_)) {
        Log::error("Failed to create Mir surface!\n");
        return false;
    }

    return true;
}