Enlightenment CVS committal Author : doursse Project : e17 Module : libs/evas
Dir : e17/libs/evas/src/modules/engines/software_ddraw Modified Files: evas_ddraw_buffer.c evas_ddraw_main.c evas_engine.h evas_outbuf.c Log Message: resize the directdraw surface when the evas is resized. move directdraw code to its own file =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_ddraw/evas_ddraw_buffer.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- evas_ddraw_buffer.c 5 Aug 2007 06:37:44 -0000 1.2 +++ evas_ddraw_buffer.c 8 Sep 2007 10:42:30 -0000 1.3 @@ -42,32 +42,36 @@ void evas_software_ddraw_output_buffer_paste(DDraw_Output_Buffer *ddob, - DDSURFACEDESC2 *surface_desc, - int x, - int y) + void *ddraw_data, + int ddraw_width, + int ddraw_height, + int ddraw_pitch, + int ddraw_depth, + int x, + int y) { - DATA8 *dd_data; - DATA8 *evas_data; - int width; - int height; - int pitch; - int j; + DATA8 *dd_data; + DATA8 *evas_data; + int width; + int height; + int pitch; + int j; - if ((x >= surface_desc->dwWidth) || (y >= surface_desc->dwHeight)) + if ((x >= ddraw_width) || (y >= ddraw_height)) return; /* compute the size of the data to copy on the back surface */ - width = ((x + ddob->width) > surface_desc->dwWidth) - ? surface_desc->dwWidth - x + width = ((x + ddob->width) > ddraw_width) + ? ddraw_width - x : ddob->width; - height = ((y + ddob->height) > surface_desc->dwHeight) - ? surface_desc->dwHeight - y + height = ((y + ddob->height) > ddraw_height) + ? ddraw_height - y : ddob->height; pitch = width * ddob->depth / 8; - dd_data = (DATA8 *)surface_desc->lpSurface + y * surface_desc->lPitch + x * surface_desc->ddpfPixelFormat.dwRGBBitCount / 8; + dd_data = (DATA8 *)ddraw_data + y * ddraw_pitch + x * ddraw_depth; evas_data = (unsigned char *)ddob->image; - for (j = 0; j < height; j++, evas_data += ddob->pitch, dd_data += surface_desc->lPitch) + for (j = 0; j < height; j++, evas_data += ddob->pitch, dd_data += ddraw_pitch) memcpy(dd_data, evas_data, pitch); } =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_ddraw/evas_ddraw_main.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- evas_ddraw_main.c 5 Aug 2007 06:37:44 -0000 1.2 +++ evas_ddraw_main.c 8 Sep 2007 10:42:30 -0000 1.3 @@ -1,5 +1,96 @@ +#include "evas_engine.h" + + +int +evas_software_ddraw_masks_get(Outbuf *buf) +{ + DDPIXELFORMAT pixel_format; + + ZeroMemory(&pixel_format, sizeof(pixel_format)); + pixel_format.dwSize = sizeof(pixel_format); + + if (FAILED(IDirectDrawSurface7_GetPixelFormat(buf->priv.dd.surface_primary, + &pixel_format))) + return 0; + + buf->priv.mask.r = pixel_format.dwRBitMask; + buf->priv.mask.g = pixel_format.dwGBitMask; + buf->priv.mask.b = pixel_format.dwBBitMask; + + return 1; +} + +void * +evas_software_ddraw_lock(Outbuf *buf, int *ddraw_width, int *ddraw_height, int *ddraw_pitch, int *ddraw_depth) +{ + DDSURFACEDESC2 surface_desc; + + ZeroMemory(&surface_desc, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + + if (FAILED(IDirectDrawSurface7_Lock(buf->priv.dd.surface_back, NULL, + &surface_desc, + DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, + NULL))) + return NULL; + + *ddraw_width = surface_desc.dwWidth; + *ddraw_height = surface_desc.dwHeight; + *ddraw_pitch = surface_desc.lPitch; + *ddraw_depth = surface_desc.ddpfPixelFormat.dwRGBBitCount >> 3; + + return surface_desc.lpSurface; +} + +void +evas_software_ddraw_unlock_and_flip(Outbuf *buf) +{ + RECT dst_rect; + RECT src_rect; + POINT p; + + if (FAILED(IDirectDrawSurface7_Unlock(buf->priv.dd.surface_back, NULL))) + return; + + /* we figure out where on the primary surface our window lives */ + p.x = 0; + p.y = 0; + ClientToScreen(buf->priv.dd.window, &p); + GetClientRect(buf->priv.dd.window, &dst_rect); + OffsetRect(&dst_rect, p.x, p.y); + SetRect(&src_rect, 0, 0, buf->width, buf->height); + + /* nothing to do if the function fails, so we don't check the result */ + IDirectDrawSurface7_Blt(buf->priv.dd.surface_primary, &dst_rect, + buf->priv.dd.surface_back, &src_rect, + DDBLT_WAIT, NULL); +} void -evas_software_ddraw_init(void) +evas_software_ddraw_surface_resize(Outbuf *buf) { + DDSURFACEDESC2 surface_desc; + DDSURFACEDESC2 *sd; + + IDirectDrawSurface7_Release(buf->priv.dd.surface_back); + memset (&surface_desc, 0, sizeof (surface_desc)); + surface_desc.dwSize = sizeof (surface_desc); + /* FIXME: that code does not compile. Must know why */ +#if 0 + surface_desc.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; + surface_desc.dwWidth = width; + surface_desc.dwHeight = height; + IDirectDrawSurface7_SetSurfaceDesc(buf->priv.dd.surface_back, &surface_desc, NULL); +#else + surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; + surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + surface_desc.dwWidth = buf->width; + surface_desc.dwHeight = buf->height; + /* Hack to cleanly remove a warning */ + sd = &surface_desc; + IDirectDraw7_CreateSurface(buf->priv.dd.object, + (DDSURFACEDESC *)sd, + &buf->priv.dd.surface_back, + NULL); +#endif } =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_ddraw/evas_engine.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- evas_engine.h 5 Aug 2007 06:37:44 -0000 1.3 +++ evas_engine.h 8 Sep 2007 10:42:30 -0000 1.4 @@ -109,12 +109,21 @@ void *data); void evas_software_ddraw_output_buffer_free(DDraw_Output_Buffer *ddob); void evas_software_ddraw_output_buffer_paste(DDraw_Output_Buffer *ddob, - DDSURFACEDESC2 *surface_desc, + void *ddraw_data, + int ddraw_width, + int ddraw_height, + int ddraw_pitch, + int ddraw_depth, int x, int y); DATA8 *evas_software_ddraw_output_buffer_data(DDraw_Output_Buffer *ddob, int *bytes_per_line_ret); int evas_software_ddraw_output_buffer_depth(DDraw_Output_Buffer *ddob); + +int evas_software_ddraw_masks_get(Outbuf *buf); +void *evas_software_ddraw_lock(Outbuf *buf, int *ddraw_width, int *ddraw_height, int *ddraw_pitch, int *ddraw_depth); +void evas_software_ddraw_unlock_and_flip(Outbuf *buf); +void evas_software_ddraw_surface_resize(Outbuf *buf); #endif /* __EVAS_ENGINE_H__ */ =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_ddraw/evas_outbuf.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- evas_outbuf.c 5 Aug 2007 06:37:44 -0000 1.3 +++ evas_outbuf.c 8 Sep 2007 10:42:30 -0000 1.4 @@ -1,34 +1,6 @@ #include "evas_engine.h" -static void -_ddraw_surface_flip(HWND window, - LPDIRECTDRAWSURFACE surface_primary, - LPDIRECTDRAWSURFACE surface_back, - int width, - int height) -{ - HRESULT res; - RECT dst_rect; - RECT src_rect; - POINT p; - - /* we figure out where on the primary surface our window lives */ - p.x = 0; - p.y = 0; - ClientToScreen (window, &p); - GetClientRect (window, &dst_rect); - OffsetRect (&dst_rect, p.x, p.y); - SetRect (&src_rect, 0, 0, width, height); - res = IDirectDrawSurface7_Blt (surface_primary, &dst_rect, - surface_back, &src_rect, - DDBLT_WAIT, NULL); - if (FAILED(res)) - { - } -} - - void evas_software_ddraw_outbuf_init(void) { @@ -77,35 +49,29 @@ conv_func = NULL; if (ddob) { - DDPIXELFORMAT pixel_format; - - ZeroMemory(&pixel_format, sizeof(pixel_format)); - pixel_format.dwSize = sizeof(pixel_format); - IDirectDrawSurface7_GetPixelFormat(surface_primary, &pixel_format); - buf->priv.mask.r = pixel_format.dwRBitMask; - buf->priv.mask.g = pixel_format.dwGBitMask; - buf->priv.mask.b = pixel_format.dwBBitMask; - - if ((rotation == 0) || (rotation == 180)) - conv_func = evas_common_convert_func_get(0, - width, - height, - evas_software_ddraw_output_buffer_depth (ddob), - buf->priv.mask.r, - buf->priv.mask.g, - buf->priv.mask.b, - PAL_MODE_NONE, - rotation); - else if ((rotation == 90) || (rotation == 270)) - conv_func = evas_common_convert_func_get(0, - height, - width, - evas_software_ddraw_output_buffer_depth (ddob), - buf->priv.mask.r, - buf->priv.mask.g, - buf->priv.mask.b, - PAL_MODE_NONE, - rotation); + if (evas_software_ddraw_masks_get(buf)) + { + if ((rotation == 0) || (rotation == 180)) + conv_func = evas_common_convert_func_get(0, + width, + height, + evas_software_ddraw_output_buffer_depth (ddob), + buf->priv.mask.r, + buf->priv.mask.g, + buf->priv.mask.b, + PAL_MODE_NONE, + rotation); + else if ((rotation == 90) || (rotation == 270)) + conv_func = evas_common_convert_func_get(0, + height, + width, + evas_software_ddraw_output_buffer_depth (ddob), + buf->priv.mask.r, + buf->priv.mask.g, + buf->priv.mask.b, + PAL_MODE_NONE, + rotation); + } evas_software_ddraw_output_buffer_free(ddob); if (!conv_func) { @@ -198,17 +164,20 @@ void evas_software_ddraw_outbuf_flush(Outbuf *buf) { - DDSURFACEDESC2 surface_desc; - HRESULT res; - Evas_List *l; - - ZeroMemory(&surface_desc, sizeof(surface_desc)); - surface_desc.dwSize = sizeof(surface_desc); + Evas_List *l; + void *ddraw_data; + int ddraw_width; + int ddraw_height; + int ddraw_pitch; + int ddraw_depth; /* lock the back surface */ - res = IDirectDrawSurface7_Lock (buf->priv.dd.surface_back, NULL, &surface_desc, - DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); - if (FAILED(res)) goto free_images; + if (!(ddraw_data = evas_software_ddraw_lock(buf, + &ddraw_width, + &ddraw_height, + &ddraw_pitch, + &ddraw_depth))) + goto free_images; /* copy safely the images that need to be drawn onto the back surface */ for (l = buf->priv.pending_writes; l; l = l->next) @@ -220,21 +189,17 @@ ddob = im->extended_info; /* paste now */ evas_software_ddraw_output_buffer_paste(ddob, - &surface_desc, + ddraw_data, + ddraw_width, + ddraw_height, + ddraw_pitch, + ddraw_depth, ddob->x, ddob->y); } - /* unlock the back surface */ - res = IDirectDrawSurface7_Unlock (buf->priv.dd.surface_back, NULL); - if (FAILED(res)) goto free_images; - - /* flip the surfaces */ - _ddraw_surface_flip(buf->priv.dd.window, - buf->priv.dd.surface_primary, - buf->priv.dd.surface_back, - buf->width, - buf->height); + /* unlock the back surface and flip the surface */ + evas_software_ddraw_unlock_and_flip(buf); free_images: while (buf->priv.pending_writes) @@ -346,6 +311,7 @@ buf->width = width; buf->height = height; buf->rot = rotation; + evas_software_ddraw_surface_resize(buf); } int ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs