src/video/mir/SDL_mirframebuffer.c
changeset 10089 25fda20d0173
parent 9998 f67cf37e9cd4
child 10094 fdfdae3f6039
equal deleted inserted replaced
10088:33bee97dbcbb 10089:25fda20d0173
    37     SDL_PIXELFORMAT_UNKNOWN,  /* mir_pixel_format_invalid   */
    37     SDL_PIXELFORMAT_UNKNOWN,  /* mir_pixel_format_invalid   */
    38     SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
    38     SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
    39     SDL_PIXELFORMAT_BGR888,   /* mir_pixel_format_xbgr_8888 */
    39     SDL_PIXELFORMAT_BGR888,   /* mir_pixel_format_xbgr_8888 */
    40     SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
    40     SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
    41     SDL_PIXELFORMAT_RGB888,   /* mir_pixel_format_xrgb_8888 */
    41     SDL_PIXELFORMAT_RGB888,   /* mir_pixel_format_xrgb_8888 */
    42     SDL_PIXELFORMAT_BGR24     /* mir_pixel_format_bgr_888   */
    42     SDL_PIXELFORMAT_BGR24,    /* mir_pixel_format_bgr_888   */
       
    43     SDL_PIXELFORMAT_RGB24,    /* mir_pixel_format_rgb_888   */
       
    44     SDL_PIXELFORMAT_RGB565,   /* mir_pixel_format_rgb_565   */
       
    45     SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */
       
    46     SDL_PIXELFORMAT_RGBA4444  /* mir_pixel_format_rgba_4444 */
    43 };
    47 };
    44 
    48 
    45 Uint32
    49 Uint32
    46 MIR_GetSDLPixelFormat(MirPixelFormat format)
    50 MIR_GetSDLPixelFormat(MirPixelFormat format)
    47 {
    51 {
    51 int
    55 int
    52 MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
    56 MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
    53                             void** pixels, int* pitch)
    57                             void** pixels, int* pitch)
    54 {
    58 {
    55     MIR_Data* mir_data = _this->driverdata;
    59     MIR_Data* mir_data = _this->driverdata;
    56     MIR_Window* mir_window;
       
    57     MirSurfaceParameters surfaceparm;
       
    58 
    60 
    59     mir_data->software = SDL_TRUE;
    61     mir_data->software = SDL_TRUE;
    60 
    62 
    61     if (MIR_CreateWindow(_this, window) < 0)
    63     if (MIR_CreateWindow(_this, window) < 0)
    62         return SDL_SetError("Failed to created a mir window.");
    64         return SDL_SetError("Failed to created a mir window.");
    63 
    65 
    64     mir_window = window->driverdata;
    66     *format = MIR_GetSDLPixelFormat(mir_data->pixel_format);
    65 
       
    66     MIR_mir_surface_get_parameters(mir_window->surface, &surfaceparm);
       
    67 
       
    68     *format = MIR_GetSDLPixelFormat(surfaceparm.pixel_format);
       
    69     if (*format == SDL_PIXELFORMAT_UNKNOWN)
    67     if (*format == SDL_PIXELFORMAT_UNKNOWN)
    70         return SDL_SetError("Unknown pixel format");
    68         return SDL_SetError("Unknown pixel format");
    71 
    69 
    72     *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
    70     *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
    73 
    71 
    74     *pixels = SDL_malloc(window->h*(*pitch));
    72     *pixels = SDL_malloc(window->h*(*pitch));
    75     if (*pixels == NULL)
    73     if (*pixels == NULL)
    76         return SDL_OutOfMemory();
    74         return SDL_OutOfMemory();
    77 
       
    78     mir_window->surface = MIR_mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
       
    79     if (!MIR_mir_surface_is_valid(mir_window->surface)) {
       
    80         const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
       
    81         return SDL_SetError("Failed to created a mir surface: %s", error);
       
    82     }
       
    83 
    75 
    84     return 0;
    76     return 0;
    85 }
    77 }
    86 
    78 
    87 int
    79 int
    89                             const SDL_Rect* rects, int numrects)
    81                             const SDL_Rect* rects, int numrects)
    90 {
    82 {
    91     MIR_Window* mir_window = window->driverdata;
    83     MIR_Window* mir_window = window->driverdata;
    92 
    84 
    93     MirGraphicsRegion region;
    85     MirGraphicsRegion region;
       
    86     MirBufferStream* bs;
    94     int i, j, x, y, w, h, start;
    87     int i, j, x, y, w, h, start;
    95     int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
    88     int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
    96     char* s_dest;
    89     char* s_dest;
    97     char* pixels;
    90     char* pixels;
    98 
    91 
    99     MIR_mir_surface_get_graphics_region(mir_window->surface, &region);
    92     bs = MIR_mir_surface_get_buffer_stream(mir_window->surface);
       
    93     MIR_mir_buffer_stream_get_graphics_region(bs, &region);
   100 
    94 
   101     s_dest = region.vaddr;
    95     s_dest = region.vaddr;
   102     pixels = (char*)window->surface->pixels;
    96     pixels = (char*)window->surface->pixels;
   103 
    97 
   104     s_stride = window->surface->pitch;
    98     s_stride = window->surface->pitch;
   142             pixels += s_stride;
   136             pixels += s_stride;
   143             s_dest += d_stride;
   137             s_dest += d_stride;
   144         }
   138         }
   145     }
   139     }
   146 
   140 
   147     MIR_mir_surface_swap_buffers_sync(mir_window->surface);
   141     MIR_mir_buffer_stream_swap_buffers_sync(bs);
   148 
   142 
   149     return 0;
   143     return 0;
   150 }
   144 }
   151 
   145 
   152 void
   146 void