예제 #1
0
int
MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
                            void** pixels, int* pitch)
{
    MIR_Data* mir_data = _this->driverdata;
    MIR_Window* mir_window;
    MirSurfaceParameters surfaceparm;

    if (MIR_CreateWindow(_this, window) < 0)
        return SDL_SetError("Failed to created a mir window.");

    mir_window = window->driverdata;

    MIR_mir_surface_get_parameters(mir_window->surface, &surfaceparm);

    *format = MIR_GetSDLPixelFormat(surfaceparm.pixel_format);
    if (*format == SDL_PIXELFORMAT_UNKNOWN)
        return SDL_SetError("Unknown pixel format");

    *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);

    *pixels = SDL_malloc(window->h*(*pitch));
    if (*pixels == NULL)
        return SDL_OutOfMemory();

    mir_window->surface = MIR_mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
    if (!MIR_mir_surface_is_valid(mir_window->surface)) {
        const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
        return SDL_SetError("Failed to created a mir surface: %s", error);
    }

    return 0;
}
예제 #2
0
int
IsSurfaceValid(MIR_Window* mir_window)
{
    if (!MIR_mir_surface_is_valid(mir_window->surface)) {
        const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
        return SDL_SetError("Failed to created a mir surface: %s", error);
    }

    return 0;
}
예제 #3
0
int
MIR_CreateWindow(_THIS, SDL_Window* window)
{
    MIR_Window* mir_window;
    MIR_Data* mir_data;

    MirSurfaceParameters surfaceparm =
    {
        .name = "MirSurface",
        .width = window->w,
        .height = window->h,
        .pixel_format = mir_pixel_format_invalid,
        .buffer_usage = mir_buffer_usage_hardware,
        .output_id = mir_display_output_id_invalid
    };

    MirEventDelegate delegate = {
        MIR_HandleInput,
        window
    };

    mir_window = SDL_calloc(1, sizeof(MIR_Window));
    if (!mir_window)
        return SDL_OutOfMemory();

    mir_data = _this->driverdata;
    window->driverdata = mir_window;

    if (mir_data->software)
        surfaceparm.buffer_usage = mir_buffer_usage_software;

    if (window->x == SDL_WINDOWPOS_UNDEFINED)
        window->x = 0;

    if (window->y == SDL_WINDOWPOS_UNDEFINED)
        window->y = 0;

    mir_window->mir_data = mir_data;
    mir_window->sdl_window = window;

    surfaceparm.pixel_format = FindValidPixelFormat(mir_data);
    if (surfaceparm.pixel_format == mir_pixel_format_invalid) {
        return SDL_SetError("Failed to find a valid pixel format.");
    }

    mir_window->surface = MIR_mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
    if (!MIR_mir_surface_is_valid(mir_window->surface)) {
        const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
        return SDL_SetError("Failed to created a mir surface: %s", error);
    }

    if (window->flags & SDL_WINDOW_OPENGL) {
        EGLNativeWindowType egl_native_window =
                        (EGLNativeWindowType)MIR_mir_surface_get_egl_native_window(mir_window->surface);

        mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);

        if (mir_window->egl_surface == EGL_NO_SURFACE) {
            return SDL_SetError("Failed to created a window surface %p",
                                _this->egl_data->egl_display);
        }
    }
    else {
        mir_window->egl_surface = EGL_NO_SURFACE;
    }

    MIR_mir_surface_set_event_handler(mir_window->surface, &delegate);

    return 0;
}

void
MIR_DestroyWindow(_THIS, SDL_Window* window)
{
    MIR_Data* mir_data = _this->driverdata;
    MIR_Window* mir_window = window->driverdata;

    if (mir_data) {
        SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
        MIR_mir_surface_release_sync(mir_window->surface);

        SDL_free(mir_window);
    }
    window->driverdata = NULL;
}
예제 #4
0
int
MIR_CreateWindow(_THIS, SDL_Window* window)
{
    MIR_Window* mir_window;
    MIR_Data* mir_data;
    MirPixelFormat pixel_format;
    MirBufferUsage buffer_usage;

    MirSurfaceSpec* spec;

    mir_window = SDL_calloc(1, sizeof(MIR_Window));
    if (!mir_window)
        return SDL_OutOfMemory();

    mir_data = _this->driverdata;
    window->driverdata = mir_window;

    if (window->x == SDL_WINDOWPOS_UNDEFINED)
        window->x = 0;

    if (window->y == SDL_WINDOWPOS_UNDEFINED)
        window->y = 0;

    mir_window->mir_data = mir_data;
    mir_window->sdl_window = window;

    if (window->flags & SDL_WINDOW_OPENGL) {
        pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
                                                               _this->egl_data->egl_display,
                                                               _this->egl_data->egl_config);
    }
    else {
        pixel_format = FindValidPixelFormat(mir_data);
    }

    mir_data->pixel_format = pixel_format;
    if (pixel_format == mir_pixel_format_invalid) {
        return SDL_SetError("Failed to find a valid pixel format.");
    }

    buffer_usage = mir_buffer_usage_hardware;
    if (mir_data->software)
        buffer_usage = mir_buffer_usage_software;

    spec = MIR_mir_connection_create_spec_for_normal_surface(mir_data->connection,
                                                             window->w,
                                                             window->h,
                                                             pixel_format);

    MIR_mir_surface_spec_set_buffer_usage(spec, buffer_usage);
    MIR_mir_surface_spec_set_name(spec, "Mir surface");

    if (window->flags & SDL_WINDOW_INPUT_FOCUS)
        SDL_SetKeyboardFocus(window);

    mir_window->surface = MIR_mir_surface_create_sync(spec);
    MIR_mir_surface_set_event_handler(mir_window->surface, MIR_HandleEvent, window);

    MIR_mir_surface_spec_release(spec);

    if (!MIR_mir_surface_is_valid(mir_window->surface)) {
        return SDL_SetError("Failed to created a mir surface: %s",
            MIR_mir_surface_get_error_message(mir_window->surface));
    }

    if (window->flags & SDL_WINDOW_OPENGL) {
        EGLNativeWindowType egl_native_window =
                        (EGLNativeWindowType)MIR_mir_buffer_stream_get_egl_native_window(
                                                       MIR_mir_surface_get_buffer_stream(mir_window->surface));

        mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);

        if (mir_window->egl_surface == EGL_NO_SURFACE) {
            return SDL_SetError("Failed to created a window surface %p",
                                _this->egl_data->egl_display);
        }
    }
    else {
        mir_window->egl_surface = EGL_NO_SURFACE;
    }

    mir_data->current_window = mir_window;

    return 0;
}