Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed pitch alignment problem causing MITSHM error on 16-bit displays
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 25, 2008
1 parent f8225c8 commit 434123d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/video/x11/SDL_x11modes.c
Expand Up @@ -136,6 +136,8 @@ X11_InitModes(_THIS)
SDL_VideoDisplay display;
SDL_DisplayData *displaydata;
SDL_DisplayMode mode;
XPixmapFormatValues *pixmapFormats;
int i, n;

if (get_visualinfo(data->display, screen, &vinfo) < 0) {
continue;
Expand All @@ -155,6 +157,18 @@ X11_InitModes(_THIS)
displaydata->visual = vinfo.visual;
displaydata->depth = vinfo.depth;

displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format)*8;
pixmapFormats = XListPixmapFormats(data->display, &n);
if (pixmapFormats) {
for (i = 0; i < n; ++i) {
if (pixmapFormats[i].depth == displaydata->depth) {
displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
break;
}
}
XFree(pixmapFormats);
}

SDL_zero(display);
display.desktop_mode = mode;
display.current_mode = mode;
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11modes.h
Expand Up @@ -29,6 +29,7 @@ typedef struct
int screen;
Visual *visual;
int depth;
int scanline_pad;

int use_xinerama;
int use_xrandr;
Expand Down
4 changes: 4 additions & 0 deletions src/video/x11/SDL_x11render.c
Expand Up @@ -83,6 +83,7 @@ typedef struct
int screen;
Visual *visual;
int depth;
int scanline_pad;
Window window;
Pixmap pixmaps[3];
int current_pixmap;
Expand Down Expand Up @@ -185,6 +186,7 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
data->screen = displaydata->screen;
data->visual = displaydata->visual;
data->depth = displaydata->depth;
data->scanline_pad = displaydata->scanline_pad;
data->window = windowdata->window;

renderer->DisplayModeChanged = X11_DisplayModeChanged;
Expand Down Expand Up @@ -316,6 +318,7 @@ X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
X11_TextureData *data;
int pitch_alignmask = ((renderdata->scanline_pad / 8) - 1);

data = (X11_TextureData *) SDL_calloc(1, sizeof(*data));
if (!data) {
Expand Down Expand Up @@ -343,6 +346,7 @@ X11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
data->format = texture->format;
}
data->pitch = texture->w * SDL_BYTESPERPIXEL(data->format);
data->pitch = (data->pitch + pitch_alignmask) & ~pitch_alignmask;

if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
#ifndef NO_SHARED_MEMORY
Expand Down

0 comments on commit 434123d

Please sign in to comment.