Commit de0dbff2 authored by Sam Lantinga's avatar Sam Lantinga

Adam Strzelecki to SDL

Since current DirectFB implementation is incomplete for YUV surfaces (actually causes segmentation faults when trying Lock and use YUV planar textures) I decided to fix it a bit.
Here's a patch that should make DirectFB properly support YUV both packed and planar (3 planes).

(1) Removed SDL_BYTESPERPIXEL at all in favor of DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(fmt)) which does return always proper BPP for YUVs too, coz SDL_BYTESPERPIXEL returns incorrect values for FOURCCs
(2) Fixed data->pixels allocation for planar YUVs in CreateTexture, it should allocate 150% more space
(3) Copy other planes for planar YUVs in UpdateTexture
(4) Moved checking if format is supported at all with DirectFB on CreateTexture at the beginning of the code

Waiting for comments,
--
Adam Strzelecki | nanoant.com

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403959
parent 361d31ae
...@@ -499,12 +499,20 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -499,12 +499,20 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
DirectFB_TextureData *data; DirectFB_TextureData *data;
DFBResult ret; DFBResult ret;
DFBSurfaceDescription dsc; DFBSurfaceDescription dsc;
DFBSurfacePixelFormat pixelformat;
SDL_DFB_CALLOC(data, 1, sizeof(*data)); SDL_DFB_CALLOC(data, 1, sizeof(*data));
texture->driverdata = data; texture->driverdata = data;
/* find the right pixelformat */
pixelformat = SDLToDFBPixelFormat(texture->format);
if (pixelformat == DSPF_UNKNOWN) {
SDL_SetError("Unknown pixel format %d\n", data->format);
goto error;
}
data->format = texture->format; data->format = texture->format;
data->pitch = (texture->w * SDL_BYTESPERPIXEL(data->format)); data->pitch = texture->w * DFB_BYTES_PER_PIXEL(pixelformat);
if (DirectFB_AcquireVidLayer(renderer, texture) != 0) { if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
/* fill surface description */ /* fill surface description */
...@@ -525,14 +533,7 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -525,14 +533,7 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
dsc.caps |= DSCAPS_VIDEOONLY; dsc.caps |= DSCAPS_VIDEOONLY;
#endif #endif
/* find the right pixelformat */ dsc.pixelformat = pixelformat;
dsc.pixelformat = SDLToDFBPixelFormat(data->format);
if (dsc.pixelformat == DSPF_UNKNOWN) {
SDL_SetError("Unknown pixel format %d\n", data->format);
goto error;
}
data->pixels = NULL; data->pixels = NULL;
/* Create the surface */ /* Create the surface */
...@@ -550,8 +551,13 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -550,8 +551,13 @@ DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
#endif #endif
if (texture->access == SDL_TEXTUREACCESS_STREAMING) { if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); /* 3 plane YUVs return 1 bpp, but we need more space for other planes */
SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch); if(texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
SDL_DFB_CALLOC(data->pixels, 1, (texture->h * data->pitch * 3 + texture->h * data->pitch * 3 % 2) / 2);
} else {
SDL_DFB_CALLOC(data->pixels, 1, texture->h * data->pitch);
}
} }
return 0; return 0;
...@@ -726,6 +732,24 @@ DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -726,6 +732,24 @@ DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
src += pitch; src += pitch;
dst += dpitch; dst += dpitch;
} }
/* copy other planes for 3 plane formats */
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
src = (Uint8 *) pixels + texture->h * pitch;
dst = (Uint8 *) dpixels + texture->h * dpitch + rect->y * dpitch / 4 + rect->x * bpp / 2;
for (row = 0; row < rect->h / 2; ++row) {
SDL_memcpy(dst, src, length / 2);
src += pitch / 2;
dst += dpitch / 2;
}
src = (Uint8 *) pixels + texture->h * pitch + texture->h * pitch / 4;
dst = (Uint8 *) dpixels + texture->h * dpitch + texture->h * dpitch / 4 + rect->y * dpitch / 4 + rect->x * bpp / 2;
for (row = 0; row < rect->h / 2; ++row) {
SDL_memcpy(dst, src, length / 2);
src += pitch / 2;
dst += dpitch / 2;
}
}
SDL_DFB_CHECKERR(data->surface->Unlock(data->surface)); SDL_DFB_CHECKERR(data->surface->Unlock(data->surface));
return 0; return 0;
error: error:
...@@ -759,7 +783,7 @@ DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -759,7 +783,7 @@ DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
*pixels = *pixels =
(void *) ((Uint8 *) texturedata->pixels + (void *) ((Uint8 *) texturedata->pixels +
rect->y * texturedata->pitch + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format)); rect->x * DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format)));
*pitch = texturedata->pitch; *pitch = texturedata->pitch;
} }
return 0; return 0;
...@@ -916,7 +940,7 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -916,7 +940,7 @@ DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
if (texturedata->dirty.list) { if (texturedata->dirty.list) {
SDL_DirtyRect *dirty; SDL_DirtyRect *dirty;
void *pixels; void *pixels;
int bpp = SDL_BYTESPERPIXEL(texture->format); int bpp = DFB_BYTES_PER_PIXEL(SDLToDFBPixelFormat(texture->format));
int pitch = texturedata->pitch; int pitch = texturedata->pitch;
for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) { for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment