Mercurial > sdl-ios-xcode
view src/video/ps3/SDL_ps3yuv.c @ 4384:6800e2560310 SDL-1.2
Fixed bugs #882 and 865, re-opening bug #634
Ronald Lamprecht to SDL
Hi,
Sam Lantinga wrote:
The problem with that fix is that it breaks IME events again. Maybe
we can handle keyboard events differently to prevent this issue?
Spending an hour reading MSDN, analysing SDL and another hour testing the reality on XP I am really wondering how patch r4990 could have ever worked in any situation. It's main effect is to break the unicode translation and causing spurious activation events!
Why does TranslateMessage(&msg) nothing useful? Simply because it does not affect "msg" at all! All keyboard events are dispatched without the slightest change (see MSDN). TranslateMessage() just appends additional WM_CHAR, WM_DEADCHAR, WM_SYSCHAR, WM_SYSDEADCHAR event messages to the queue. But I could not find any SDL event handling routine that catches these events and transforms them to proper SDL keyevents while eliminating the corresponding WM_KEYDOWN, etc. events. Thus any IME input like the '@' generated by "Alt + 6(Numpad) + 4(Numpad)" is simply lost.
But the situation is even worse! Up to r4990 the TranslateKey()/ToUnicode() calls did evaluate dead keys and did deliver proper key events for subsequent key strokes like '´' + 'e' resulting in 'é'. ToUnicode() needs proper key state informations to be able to handle these substitutions. But unfortunatly TranslateMessage() needs the same state information and eats it up while generating the WM_CHAR messages :-( Thus the current 1.2.14 breakes the partial IME support of previous releases, too.
The key state race condition between ToUnicode() and TranslateMessage() requires to avoid any ToUnicode() usage for receiving proper WM_CHAR, etc. messages generated by TranslateMessage(). (Yes - the '@' and 'é' appear as WM_CHAR messages when unicode is switched off).
The spurious SDL activation events are *not* caused by additional WM_ACTIVATE Windows messages! Besides DIB_HandleMessage() SDL_PrivateAppActive() is called by another source which I am not yet aware of - any hints?
Thus I do strongly recommend the deletion of the TranslateMessage(&msg) call as a quick fix.
A proper support of unicode and IME requires a clean SDL keyboard input concept first. Which SDL keyboards events should be transmitted to the app when the user presses '´' + 'e' ? Within the current unicode handling the first key stroke is hidden. Even though ToUnicode() delivers the proper key SDL does ignore it in TranslateKey(). Just the composed key event is transmitted to the app. That is what you expect for text input, but the app can no longer use keys like '^' as a key button because it will never receive a key event for it!
With a given concept it seems to be necessary to regenerate SDL key events out of the WM_CHAR, etc. events and to drop all related direct WM_KEYDOWN, etc. events while the remaining basic WM_KEYDOWN, etc. events would still have to result in SDL key events.
Anyway the source of the spurious WM_ACTIVATE should be located to avoid future trouble.
Greets,
Ronald
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 17 Nov 2009 04:59:13 +0000 |
parents | 3b8ac3d311a2 |
children |
line wrap: on
line source
/* * SDL - Simple DirectMedia Layer * CELL BE Support for PS3 Framebuffer * Copyright (C) 2008, 2009 International Business Machines Corporation * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 * USA * * Martin Lowinski <lowinski [at] de [dot] ibm [ibm] com> * Dirk Herrendoerfer <d.herrendoerfer [at] de [dot] ibm [dot] com> * SPE code based on research by: * Rene Becker * Thimo Emmerich */ #include "SDL_config.h" #include "SDL_video.h" #include "SDL_ps3video.h" #include "SDL_ps3yuv_c.h" #include "../SDL_yuvfuncs.h" #include "spulibs/spu_common.h" /* Stores the executable name */ extern spe_program_handle_t yuv2rgb_spu; extern spe_program_handle_t bilin_scaler_spu; int SPE_Start(_THIS, spu_data_t * spe_data); int SPE_Stop(_THIS, spu_data_t * spe_data); int SPE_Boot(_THIS, spu_data_t * spe_data); int SPE_Shutdown(_THIS, spu_data_t * spe_data); int SPE_SendMsg(_THIS, spu_data_t * spe_data, unsigned int msg); int SPE_WaitForMsg(_THIS, spu_data_t * spe_data, unsigned int msg); void SPE_RunContext(void *thread_argp); /* The functions used to manipulate software video overlays */ static struct private_yuvhwfuncs ps3_yuvfuncs = { PS3_LockYUVOverlay, PS3_UnlockYUVOverlay, PS3_DisplayYUVOverlay, PS3_FreeYUVOverlay }; struct private_yuvhwdata { SDL_Surface *display; SDL_Surface *stretch; volatile void * pixels __attribute__((aligned(128))); /* These are just so we don't have to allocate them separately */ Uint16 pitches[3]; Uint8 * planes[3]; unsigned int scale; /* Scaled YUV picture */ Uint8 * scaler_out __attribute__((aligned(128))); /* YUV2RGB converter data */ volatile struct yuv2rgb_parms_t * converter_parms __attribute__((aligned(128))); /* Scaler data */ volatile struct scale_parms_t * scaler_parms __attribute__((aligned(128))); Uint8 locked; }; SDL_Overlay *PS3_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) { /* Only RGB packed pixel conversion supported */ if ((display->format->BytesPerPixel != 2) && (display->format->BytesPerPixel != 3) && (display->format->BytesPerPixel != 4)) { SDL_SetError ("Can't use YUV data on non 16/24/32 bit surfaces"); return NULL; } /* Double-check the requested format. We'll only support YV12 */ switch (format) { case SDL_IYUV_OVERLAY: case SDL_YV12_OVERLAY: /* Supported YUV format */ break; default: SDL_SetError("Unsupported YUV format"); return NULL; } SDL_Overlay* overlay; struct private_yuvhwdata* hwdata; /* Create the overlay structure */ overlay = (SDL_Overlay *) SDL_calloc(1, sizeof(SDL_Overlay)); if (overlay == NULL) { SDL_OutOfMemory(); return NULL; } SDL_memset(overlay, 0, (sizeof *overlay)); /* Set the basic attributes */ overlay->format = format; overlay->w = width; overlay->h = height; overlay->hwdata = NULL; /* Set up the PS3 YUV surface function structure */ overlay->hwfuncs = &ps3_yuvfuncs; /* Create the pixel data and lookup tables */ hwdata = (struct private_yuvhwdata *) SDL_calloc(1, sizeof(struct private_yuvhwdata)); if (hwdata == NULL) { SDL_OutOfMemory(); SDL_FreeYUVOverlay(overlay); return NULL; } overlay->hwdata = hwdata; hwdata->stretch = NULL; hwdata->display = display; /* Create SPU parms structure */ hwdata->converter_parms = (struct yuv2rgb_parms_t *) memalign(16, sizeof(struct yuv2rgb_parms_t)); hwdata->scaler_parms = (struct scale_parms_t *) memalign(16, sizeof(struct scale_parms_t)); if (hwdata->converter_parms == NULL || hwdata->scaler_parms == NULL) { SDL_FreeYUVOverlay(overlay); SDL_OutOfMemory(); return(NULL); } /* Set up the SPEs */ scaler_thread_data = (spu_data_t *) malloc(sizeof(spu_data_t)); converter_thread_data = (spu_data_t *) malloc(sizeof(spu_data_t)); if (converter_thread_data == NULL || scaler_thread_data == NULL) { SDL_FreeYUVOverlay(overlay); SDL_OutOfMemory(); return(NULL); } scaler_thread_data->program = bilin_scaler_spu; scaler_thread_data->program_name = "bilin_scaler_spu"; scaler_thread_data->keepalive = 0; scaler_thread_data->booted = 0; converter_thread_data->program = yuv2rgb_spu; converter_thread_data->program_name = "yuv2rgb_spu"; converter_thread_data->keepalive = 1; converter_thread_data->booted = 0; SPE_Start(this, converter_thread_data); hwdata->pixels = (Uint8 *) memalign(16, width * height + ((width * height) >> 1)); if (hwdata->pixels == NULL) { SDL_FreeYUVOverlay(overlay); SDL_OutOfMemory(); return(NULL); } /* Find the pitch and offset values for the overlay */ overlay->pitches = hwdata->pitches; overlay->pixels = hwdata->planes; switch (format) { case SDL_YV12_OVERLAY: case SDL_IYUV_OVERLAY: overlay->pitches[0] = overlay->w; overlay->pitches[1] = overlay->pitches[0] / 2; overlay->pitches[2] = overlay->pitches[0] / 2; overlay->pixels[0] = (Uint8 *)hwdata->pixels; overlay->pixels[1] = overlay->pixels[0] + overlay->pitches[0] * overlay->h; overlay->pixels[2] = overlay->pixels[1] + overlay->pitches[1] * overlay->h / 2; overlay->planes = 3; break; default: /* We should never get here (caught above) */ break; } /* We're all done.. */ return overlay; } int PS3_LockYUVOverlay(_THIS, SDL_Overlay *overlay) { if (overlay == NULL) { return -1; } overlay->hwdata->locked = 1; return 0; } void PS3_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) { if (overlay == NULL) { return; } overlay->hwdata->locked = 0; return; } int PS3_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *src, SDL_Rect *dst) { if ((overlay == NULL) || (overlay->hwdata == NULL)) { return -1; } Uint8 *lum, *Cr, *Cb; struct private_yuvhwdata *hwdata; SDL_Surface *display; hwdata = overlay->hwdata; display = hwdata->display; /* Do we have to scale? */ if ((src->w != dst->w) || (src->h != dst->h) ) { hwdata->scale = 1; deprintf(1, "[PS3] We need to scale\n"); } else { hwdata->scale = 0; deprintf(1, "[PS3] No scaling\n"); } /* Find out where the various portions of the image are */ switch (overlay->format) { case SDL_YV12_OVERLAY: lum = (Uint8 *)overlay->pixels[0]; Cr = (Uint8 *)overlay->pixels[1]; Cb = (Uint8 *)overlay->pixels[2]; break; case SDL_IYUV_OVERLAY: lum = (Uint8 *)overlay->pixels[0]; Cr = (Uint8 *)overlay->pixels[2]; Cb = (Uint8 *)overlay->pixels[1]; break; default: SDL_SetError("Unsupported YUV format in blit"); return -1; } if (hwdata->scale) { /* Alloc mem for scaled YUV picture */ hwdata->scaler_out = (Uint8 *) memalign(16, dst->w * dst->h + ((dst->w * dst->h) >> 1)); if (hwdata->scaler_out == NULL) { SDL_FreeYUVOverlay(overlay); SDL_OutOfMemory(); return -1; } /* Set parms for scaling */ hwdata->scaler_parms->src_pixel_width = src->w; hwdata->scaler_parms->src_pixel_height = src->h; hwdata->scaler_parms->dst_pixel_width = dst->w; hwdata->scaler_parms->dst_pixel_height = dst->h; hwdata->scaler_parms->y_plane = lum; hwdata->scaler_parms->v_plane = Cr; hwdata->scaler_parms->u_plane = Cb; hwdata->scaler_parms->dstBuffer = hwdata->scaler_out; scaler_thread_data->argp = (void *)hwdata->scaler_parms; /* Scale the YUV overlay to given size */ SPE_Start(this, scaler_thread_data); SPE_Stop(this, scaler_thread_data); /* Set parms for converting after scaling */ hwdata->converter_parms->y_plane = hwdata->scaler_out; hwdata->converter_parms->v_plane = hwdata->scaler_out + dst->w * dst->h; hwdata->converter_parms->u_plane = hwdata->scaler_out + dst->w * dst->h + ((dst->w * dst->h) >> 2); } else { /* Set parms for converting */ hwdata->converter_parms->y_plane = lum; hwdata->converter_parms->v_plane = Cr; hwdata->converter_parms->u_plane = Cb; } hwdata->converter_parms->src_pixel_width = dst->w; hwdata->converter_parms->src_pixel_height = dst->h; hwdata->converter_parms->dstBuffer = (Uint8 *) s_pixels; converter_thread_data->argp = (void *)hwdata->converter_parms; /* Convert YUV overlay to RGB */ SPE_SendMsg(this, converter_thread_data, SPU_START); SPE_SendMsg(this, converter_thread_data, (unsigned int)converter_thread_data->argp); /* Centering */ s_bounded_input_width = dst->w; s_bounded_input_height = dst->h; /* UpdateRects() will do the rest.. */ SDL_UpdateRects(display, 1, dst); if (hwdata->scale) SDL_free((void *)hwdata->scaler_out); return 0; } void PS3_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) { if (overlay == NULL) { return; } if (overlay->hwdata == NULL) { return; } struct private_yuvhwdata * hwdata; hwdata = overlay->hwdata; if (scaler_thread_data) SDL_free(scaler_thread_data); if (converter_thread_data) { SPE_Shutdown(this, converter_thread_data); SDL_free(converter_thread_data); } if (hwdata) { if (hwdata->pixels) SDL_free((void *)hwdata->pixels); SDL_free(hwdata); } return; }