Ejemplo n.º 1
0
    void SetUp() override
    {
        mtf::ConnectedClientWithASurface::SetUp();

        // Need fullscreen for the cursor events
        auto const spec = mir_connection_create_spec_for_changes(connection);
        mir_surface_spec_set_fullscreen_on_output(spec, 1);
        mir_surface_apply_spec(surface, spec);
        mir_surface_spec_release(spec);

        mir_surface_set_event_handler(surface, &cookie_capturing_callback, this);
        mir_buffer_stream_swap_buffers_sync(mir_surface_get_buffer_stream(surface));
    }
Ejemplo n.º 2
0
static int createSurface(_GLFWwindow* window)
{
    MirSurfaceSpec* spec;
    MirBufferUsage buffer_usage = mir_buffer_usage_hardware;
    MirPixelFormat pixel_format = findValidPixelFormat();

    if (pixel_format == mir_pixel_format_invalid)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Mir: Unable to find a correct pixel format");
        return GL_FALSE;
    }
 
    spec = mir_connection_create_spec_for_normal_surface(_glfw.mir.connection,
                                                         window->mir.width,
                                                         window->mir.height,
                                                         pixel_format);

    mir_surface_spec_set_buffer_usage(spec, buffer_usage);
    mir_surface_spec_set_name(spec, "MirSurface");

    window->mir.surface = mir_surface_create_sync(spec);
    mir_surface_spec_release(spec);

    if (!mir_surface_is_valid(window->mir.surface))
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Mir: Unable to create surface: %s",
                        mir_surface_get_error_message(window->mir.surface));

        return GL_FALSE;
    }

    mir_surface_set_event_handler(window->mir.surface, addNewEvent, window);

    return GL_TRUE;
}
Ejemplo n.º 3
0
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);
}