diff --git a/legacy/evas/src/modules/engines/software_ddraw/Evas_Engine_Software_DDraw.h b/legacy/evas/src/modules/engines/software_ddraw/Evas_Engine_Software_DDraw.h index 82ae47d820..f0628d62e8 100644 --- a/legacy/evas/src/modules/engines/software_ddraw/Evas_Engine_Software_DDraw.h +++ b/legacy/evas/src/modules/engines/software_ddraw/Evas_Engine_Software_DDraw.h @@ -2,8 +2,10 @@ #define __EVAS_ENGINE_SOFTWARE_DDRAW_H__ +#define WIN32_LEAN_AND_MEAN #include -#include +#undef WIN32_LEAN_AND_MEAN + typedef struct _Evas_Engine_Info_Software_DDraw Evas_Engine_Info_Software_DDraw; @@ -15,9 +17,6 @@ struct _Evas_Engine_Info_Software_DDraw struct { HWND window; - LPDIRECTDRAW object; - LPDIRECTDRAWSURFACE surface_primary; - LPDIRECTDRAWSURFACE surface_back; int depth; int rotation; } info; diff --git a/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_buffer.c b/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_buffer.c index c0b209d289..870bcb2d2c 100644 --- a/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_buffer.c +++ b/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_buffer.c @@ -1,29 +1,30 @@ #include +#include "evas_common.h" #include "evas_engine.h" -DDraw_Output_Buffer * +DD_Output_Buffer * evas_software_ddraw_output_buffer_new(int depth, int width, int height, void *data) { - DDraw_Output_Buffer *ddob; + DD_Output_Buffer *ddob; - ddob = calloc(1, sizeof(DDraw_Output_Buffer)); + ddob = calloc(1, sizeof(DD_Output_Buffer)); if (!ddob) return NULL; - ddob->image = data; + ddob->data = data; ddob->depth = depth; ddob->width = width; ddob->height = height; ddob->pitch = width * depth / 8; - if (!ddob->image) + if (!ddob->data) { - ddob->image = malloc(ddob->pitch * height); - if (!ddob->image) + ddob->data = malloc(ddob->pitch * height); + if (!ddob->data) { free(ddob); return NULL; @@ -34,21 +35,21 @@ evas_software_ddraw_output_buffer_new(int depth, } void -evas_software_ddraw_output_buffer_free(DDraw_Output_Buffer *ddob) +evas_software_ddraw_output_buffer_free(DD_Output_Buffer *ddob) { - if (ddob->image) free(ddob->image); + if (ddob->data) free(ddob->data); free(ddob); } void -evas_software_ddraw_output_buffer_paste(DDraw_Output_Buffer *ddob, - void *ddraw_data, - int ddraw_width, - int ddraw_height, - int ddraw_pitch, - int ddraw_depth, - int x, - int y) +evas_software_ddraw_output_buffer_paste(DD_Output_Buffer *ddob, + 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; @@ -70,21 +71,21 @@ evas_software_ddraw_output_buffer_paste(DDraw_Output_Buffer *ddob, pitch = width * ddob->depth / 8; dd_data = (DATA8 *)ddraw_data + y * ddraw_pitch + x * ddraw_depth; - evas_data = (unsigned char *)ddob->image; + evas_data = (unsigned char *)ddob->data; for (j = 0; j < height; j++, evas_data += ddob->pitch, dd_data += ddraw_pitch) memcpy(dd_data, evas_data, pitch); } DATA8 * -evas_software_ddraw_output_buffer_data(DDraw_Output_Buffer *ddob, - int *bytes_per_line_ret) +evas_software_ddraw_output_buffer_data(DD_Output_Buffer *ddob, + int *bytes_per_line_ret) { if (bytes_per_line_ret) *bytes_per_line_ret = ddob->pitch; - return ddob->image; + return ddob->data; } int -evas_software_ddraw_output_buffer_depth(DDraw_Output_Buffer *ddob) +evas_software_ddraw_output_buffer_depth(DD_Output_Buffer *ddob) { return ddob->depth; } diff --git a/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_main.cpp b/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_main.cpp index 87fa9cfcaf..ec5c606992 100644 --- a/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_main.cpp +++ b/legacy/evas/src/modules/engines/software_ddraw/evas_ddraw_main.cpp @@ -1,5 +1,104 @@ +#include "evas_common.h" #include "evas_engine.h" +int +evas_software_ddraw_init (HWND window, + int depth, + Outbuf *buf) +{ + DDSURFACEDESC surface_desc; + DDPIXELFORMAT pixel_format; + RECT rect; + LPDIRECTDRAW o; + HRESULT res; + int width; + int height; + + if (!buf) + return 0; + + if (!GetClientRect(window, &rect)) + return 0; + + width = rect.right - rect.left; + height = rect.bottom - rect.top; + + buf->priv.dd.window = window; + + res = DirectDrawCreate(NULL, &buf->priv.dd.object, NULL); + if (FAILED(res)) + return 0; + + res = buf->priv.dd.object->SetCooperativeLevel(window, DDSCL_NORMAL); + if (FAILED(res)) + goto release_object; + + res = buf->priv.dd.object->CreateClipper (0, &buf->priv.dd.clipper, NULL); + if (FAILED(res)) + goto release_object; + + res = buf->priv.dd.clipper->SetHWnd (0, window); + if (FAILED(res)) + goto release_clipper; + + memset(&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS; + surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + + res = buf->priv.dd.object->CreateSurface (&surface_desc, &buf->priv.dd.surface_primary, NULL); + if (FAILED(res)) + goto release_clipper; + + res = buf->priv.dd.surface_primary->SetClipper (buf->priv.dd.clipper); + if (FAILED(res)) + goto release_surface_primary; + + memset (&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; + surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + surface_desc.dwWidth = width; + surface_desc.dwHeight = height; + + res = buf->priv.dd.object->CreateSurface (&surface_desc, &buf->priv.dd.surface_back, NULL); + if (FAILED(res)) + goto release_surface_primary; + + ZeroMemory(&pixel_format, sizeof(pixel_format)); + pixel_format.dwSize = sizeof(pixel_format); + buf->priv.dd.surface_primary->GetPixelFormat(&pixel_format); + + if (pixel_format.dwRGBBitCount != depth) + goto release_surface_back; + + buf->priv.dd.depth = depth; + + return 1; + + release_surface_back: + buf->priv.dd.surface_back->Release(); + release_surface_primary: + buf->priv.dd.surface_primary->Release(); + release_clipper: + buf->priv.dd.clipper->Release(); + release_object: + buf->priv.dd.object->Release(); + + return 0; +} + +void +evas_software_ddraw_shutdown(Outbuf *buf) +{ + if (!buf) + return; + + buf->priv.dd.surface_back->Release(); + buf->priv.dd.surface_primary->Release(); + buf->priv.dd.clipper->Release(); + buf->priv.dd.object->Release(); +} int evas_software_ddraw_masks_get(Outbuf *buf) @@ -20,7 +119,11 @@ 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) +evas_software_ddraw_lock(Outbuf *buf, + int *ddraw_width, + int *ddraw_height, + int *ddraw_pitch, + int *ddraw_depth) { DDSURFACEDESC surface_desc; diff --git a/legacy/evas/src/modules/engines/software_ddraw/evas_engine.c b/legacy/evas/src/modules/engines/software_ddraw/evas_engine.c index 91b1742563..0772021bfe 100644 --- a/legacy/evas/src/modules/engines/software_ddraw/evas_engine.c +++ b/legacy/evas/src/modules/engines/software_ddraw/evas_engine.c @@ -1,7 +1,11 @@ -#include "evas_engine.h" +#include "evas_common.h" #include "evas_private.h" +#include "evas_engine.h" #include "Evas_Engine_Software_DDraw.h" +/* function tables - filled in later (func and parent func) */ +static Evas_Func func, pfunc; + /* engine struct data */ typedef struct _Render_Engine Render_Engine; @@ -15,58 +19,18 @@ struct _Render_Engine }; -/* function tables - filled in later (func and parent func) */ -static Evas_Func func, pfunc; - -/* prototypes we will use here */ -static void *_output_setup(int width, - int height, - int rotation, - HWND window, - LPDIRECTDRAW lpDD, - LPDIRECTDRAWSURFACE surface_primary, - LPDIRECTDRAWSURFACE surface_back, - int w_depth); - -static void *eng_info(Evas *e); -static void eng_info_free(Evas *e, - void *info); -static void eng_setup(Evas *e, - void *info); -static void eng_output_free(void *data); -static void eng_output_resize(void *data, - int width, - int height); -static void eng_output_tile_size_set(void *data, - int width, - int height); -static void eng_output_redraws_rect_add(void *data, - int x, - int y, - int width, - int height); -static void eng_output_redraws_rect_del(void *data, - int x, - int y, - int width, - int height); -static void eng_output_redraws_clear(void *data); - -/* internal engine routines */ static void * -_output_setup(int width, - int height, - int rotation, - HWND window, - LPDIRECTDRAW object, - LPDIRECTDRAWSURFACE surface_primary, - LPDIRECTDRAWSURFACE surface_back, - int w_depth) +_output_setup(int width, + int height, + int rot, + HWND window, + int depth) { Render_Engine *re; - re = (Render_Engine *)calloc(1, sizeof(Render_Engine)); - if (!re) return NULL; + re = calloc(1, sizeof(Render_Engine)); + if (!re) + return NULL; /* if we haven't initialized - init (automatic abort if already done) */ evas_common_cpu_init(); @@ -85,14 +49,24 @@ _output_setup(int width, evas_software_ddraw_outbuf_init(); - /* get any stored performance metrics from device */ - re->ob = evas_software_ddraw_outbuf_setup_dd(width, height, rotation, OUTBUF_DEPTH_INHERIT, window, object, surface_primary, surface_back, w_depth); + re->ob = evas_software_ddraw_outbuf_setup(width, height, rot, + OUTBUF_DEPTH_INHERIT, + window, depth); if (!re->ob) { free(re); return NULL; } + /* for updates return 1 big buffer, but only use portions of it, also cache + it and keepit around until an idle_flush */ + /* disable for now - i am hunting down why some expedite tests are slower, + * as well as shaped stuff is broken and probable non-32bpp is broken as + * convert funcs dont do the right thing + * + re->ob->onebuf = 1; + */ + re->tb = evas_common_tilebuf_new(width, height); if (!re->tb) { @@ -100,21 +74,21 @@ _output_setup(int width, free(re); return NULL; } - - /* FIXME: that comment :) */ /* in preliminary tests 16x16 gave highest framerates */ evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); return re; } + /* engine api this module provides */ + static void * eng_info(Evas *e) { Evas_Engine_Info_Software_DDraw *info; - info = (Evas_Engine_Info_Software_DDraw *)calloc(1, sizeof(Evas_Engine_Info_Software_DDraw)); + info = calloc(1, sizeof(Evas_Engine_Info_Software_DDraw)); if (!info) return NULL; info->magic.magic = rand(); return info; @@ -122,8 +96,7 @@ eng_info(Evas *e) } static void -eng_info_free(Evas *e, - void *info) +eng_info_free(Evas *e, void *info) { Evas_Engine_Info_Software_DDraw *in; @@ -132,29 +105,38 @@ eng_info_free(Evas *e, } static void -eng_setup(Evas *e, - void *info) +eng_setup(Evas *e, void *in) { Render_Engine *re; - Evas_Engine_Info_Software_DDraw *in; + Evas_Engine_Info_Software_DDraw *info; - in = (Evas_Engine_Info_Software_DDraw *)info; + info = (Evas_Engine_Info_Software_DDraw *)in; if (!e->engine.data.output) - e->engine.data.output = - _output_setup(e->output.w, - e->output.h, - in->info.rotation, - in->info.window, - in->info.object, - in->info.surface_primary, - in->info.surface_back, - in->info.depth); - if (!e->engine.data.output) return; - if (!e->engine.data.context) - e->engine.data.context = - e->engine.func->context_new(e->engine.data.output); + e->engine.data.output = _output_setup(e->output.w, + e->output.h, + info->info.rotation, + info->info.window, + info->info.depth); + else + { + int ponebuf = 0; - re = (Render_Engine *)e->engine.data.output; + re = e->engine.data.output; + ponebuf = re->ob->onebuf; + evas_software_ddraw_outbuf_free(re->ob); + re->ob = evas_software_ddraw_outbuf_setup(e->output.w, + e->output.h, + info->info.rotation, + OUTBUF_DEPTH_INHERIT, + info->info.window, + info->info.depth); + re->ob->onebuf = ponebuf; + } + if (!e->engine.data.output) return; + if (!e->engine.data.context) + e->engine.data.context = e->engine.func->context_new(e->engine.data.output); + + re = e->engine.data.output; } static void @@ -162,6 +144,8 @@ eng_output_free(void *data) { Render_Engine *re; + if (!data) return; + re = (Render_Engine *)data; evas_software_ddraw_outbuf_free(re->ob); evas_common_tilebuf_free(re->tb); @@ -173,9 +157,7 @@ eng_output_free(void *data) } static void -eng_output_resize(void *data, - int width, - int height) +eng_output_resize(void *data, int width, int height) { Render_Engine *re; @@ -183,8 +165,8 @@ eng_output_resize(void *data, evas_software_ddraw_outbuf_reconfigure(re->ob, width, height, - evas_software_ddraw_outbuf_rot_get(re->ob), - OUTBUF_DEPTH_INHERIT); + evas_software_ddraw_outbuf_rot_get(re->ob), + OUTBUF_DEPTH_INHERIT); evas_common_tilebuf_free(re->tb); re->tb = evas_common_tilebuf_new(width, height); if (re->tb) @@ -192,40 +174,30 @@ eng_output_resize(void *data, } static void -eng_output_tile_size_set(void *data, - int width, - int height) +eng_output_tile_size_set(void *data, int w, int h) { Render_Engine *re; re = (Render_Engine *)data; - evas_common_tilebuf_set_tile_size(re->tb, width, height); + evas_common_tilebuf_set_tile_size(re->tb, w, h); } static void -eng_output_redraws_rect_add(void *data, - int x, - int y, - int width, - int height) +eng_output_redraws_rect_add(void *data, int x, int y, int w, int h) { Render_Engine *re; re = (Render_Engine *)data; - evas_common_tilebuf_add_redraw(re->tb, x, y, width, height); + evas_common_tilebuf_add_redraw(re->tb, x, y, w, h); } static void -eng_output_redraws_rect_del(void *data, - int x, - int y, - int width, - int height) +eng_output_redraws_rect_del(void *data, int x, int y, int w, int h) { Render_Engine *re; re = (Render_Engine *)data; - evas_common_tilebuf_del_redraw(re->tb, x, y, width, height); + evas_common_tilebuf_del_redraw(re->tb, x, y, w, h); } static void @@ -239,14 +211,14 @@ eng_output_redraws_clear(void *data) static void * eng_output_redraws_next_update_get(void *data, - int *x, - int *y, - int *w, - int *h, - int *cx, - int *cy, - int *cw, - int *ch) + int *x, + int *y, + int *w, + int *h, + int *cx, + int *cy, + int *cw, + int *ch) { Render_Engine *re; RGBA_Image *surface; @@ -269,7 +241,10 @@ eng_output_redraws_next_update_get(void *data, } if (!re->cur_rect) return NULL; rect = (Tilebuf_Rect *)re->cur_rect; - ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h; + ux = rect->x; + uy = rect->y; + uw = rect->w; + uh = rect->h; re->cur_rect = re->cur_rect->next; if (!re->cur_rect) { @@ -279,30 +254,33 @@ eng_output_redraws_next_update_get(void *data, } surface = evas_software_ddraw_outbuf_new_region_for_update(re->ob, - ux, uy, - uw, uh, - cx, cy, - cw, ch); - *x = ux; *y = uy; *w = uw; *h = uh; + ux, + uy, + uw, + uh, + cx, + cy, + cw, + ch); + + *x = ux; + *y = uy; + *w = uw; + *h = uh; return surface; } static void -eng_output_redraws_next_update_push(void *data, - void *surface, - int x, - int y, - int w, - int h) +eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h) { Render_Engine *re; re = (Render_Engine *)data; - evas_common_pipe_begin((RGBA_Image *)surface); - evas_common_pipe_flush((RGBA_Image *)surface); - evas_software_ddraw_outbuf_push_updated_region(re->ob, (RGBA_Image *)surface, x, y, w, h); - evas_software_ddraw_outbuf_free_region_for_update(re->ob, (RGBA_Image *)surface); + evas_common_pipe_begin(surface); + evas_common_pipe_flush(surface); + evas_software_ddraw_outbuf_push_updated_region(re->ob, surface, x, y, w, h); + evas_software_ddraw_outbuf_free_region_for_update(re->ob, surface); evas_common_cpu_end_opt(); } @@ -321,8 +299,10 @@ eng_output_idle_flush(void *data) Render_Engine *re; re = (Render_Engine *)data; + evas_software_ddraw_outbuf_idle_flush(re->ob); } + /* module advertising code */ EAPI int module_open(Evas_Module *em) @@ -360,8 +340,7 @@ module_close(void) EAPI Evas_Module_Api evas_modapi = { EVAS_MODULE_API_VERSION, - EVAS_MODULE_TYPE_ENGINE, - "software_ddraw", - "none" + EVAS_MODULE_TYPE_ENGINE, + "software_ddraw", + "none" }; - diff --git a/legacy/evas/src/modules/engines/software_ddraw/evas_engine.h b/legacy/evas/src/modules/engines/software_ddraw/evas_engine.h index 2cd2a6990f..b880b2542d 100644 --- a/legacy/evas/src/modules/engines/software_ddraw/evas_engine.h +++ b/legacy/evas/src/modules/engines/software_ddraw/evas_engine.h @@ -2,14 +2,14 @@ #define __EVAS_ENGINE_H__ +#define WIN32_LEAN_AND_MEAN #include +#undef WIN32_LEAN_AND_MEAN #include -#include "evas_common.h" - typedef struct _Outbuf Outbuf; -typedef struct _DDraw_Output_Buffer DDraw_Output_Buffer; - +typedef struct _Outbuf_Region Outbuf_Region; +typedef struct _DD_Output_Buffer DD_Output_Buffer; enum _Outbuf_Depth { @@ -25,112 +25,164 @@ enum _Outbuf_Depth typedef enum _Outbuf_Depth Outbuf_Depth; - struct _Outbuf { - int width; - int height; - int rot; - Outbuf_Depth depth; + Outbuf_Depth depth; + int width; + int height; + int rot; + int onebuf; struct { + Convert_Pal *pal; struct { HWND window; LPDIRECTDRAW object; LPDIRECTDRAWSURFACE surface_primary; LPDIRECTDRAWSURFACE surface_back; - int depth; + LPDIRECTDRAWCLIPPER clipper; + int depth; + unsigned char swap : 1; + unsigned char bit_swap : 1; } dd; struct { - DATA32 r, g, b; + DATA32 r, g, b; } mask; + /* 1 big buffer for updates - flush on idle_flush */ + RGBA_Image *onebuf; + Evas_List *onebuf_regions; + /* a list of pending regions to write to the target */ - Evas_List *pending_writes; + Evas_List *pending_writes; + /* a list of previous frame pending regions to write to the target */ + Evas_List *prev_pending_writes; + + unsigned char mask_dither : 1; + unsigned char destination_alpha : 1; + unsigned char debug : 1; + unsigned char synced : 1; } priv; }; -struct _DDraw_Output_Buffer +struct _Outbuf_Region { - void *image; - int x; - int y; + DD_Output_Buffer *ddob; + int x; + int y; + int width; + int height; +}; + +struct _DD_Output_Buffer +{ + void *data; int width; int height; int depth; int pitch; +/* int w, h, bpl; */ + int psize; }; -/* Outbuf functions */ -void evas_software_ddraw_outbuf_init(void); -void evas_software_ddraw_outbuf_free(Outbuf *buf); -Outbuf *evas_software_ddraw_outbuf_setup_dd(int width, - int height, - int rotation, - Outbuf_Depth depth, - HWND window, - LPDIRECTDRAW object, - LPDIRECTDRAWSURFACE surface_primary, - LPDIRECTDRAWSURFACE surface_back, - int w_depth); -RGBA_Image *evas_software_ddraw_outbuf_new_region_for_update(Outbuf *buf, - int x, - int y, - int width, - int height, - int *cx, - int *cy, - int *cw, - int *ch); -void evas_software_ddraw_outbuf_free_region_for_update(Outbuf *buf, - RGBA_Image *update); -void evas_software_ddraw_outbuf_flush(Outbuf *buf); -void evas_software_ddraw_outbuf_push_updated_region(Outbuf *buf, - RGBA_Image *update, - int x, - int y, - int width, - int height); -void evas_software_ddraw_outbuf_reconfigure(Outbuf *buf, - int width, - int height, - int rotation, - Outbuf_Depth depth); -int evas_software_ddraw_outbuf_width_get(Outbuf *buf); -int evas_software_ddraw_outbuf_height_get(Outbuf *buf); +/* evas_outbuf.c */ + +void evas_software_ddraw_outbuf_init(void); + +void evas_software_ddraw_outbuf_free(Outbuf *buf); + +Outbuf *evas_software_ddraw_outbuf_setup(int width, + int height, + int rotation, + Outbuf_Depth depth, + HWND window, + int w_depth); + +void evas_software_ddraw_outbuf_reconfigure(Outbuf *buf, + int width, + int height, + int rotation, + Outbuf_Depth depth); + +RGBA_Image *evas_software_ddraw_outbuf_new_region_for_update(Outbuf *buf, + int x, + int y, + int w, + int h, + int *cx, + int *cy, + int *cw, + int *ch); + +void evas_software_ddraw_outbuf_push_updated_region(Outbuf *buf, + RGBA_Image *update, + int x, + int y, + int w, + int h); + +void evas_software_ddraw_outbuf_free_region_for_update(Outbuf *buf, + RGBA_Image *update); + +void evas_software_ddraw_outbuf_flush(Outbuf *buf); + +void evas_software_ddraw_outbuf_idle_flush(Outbuf *buf); + +int evas_software_ddraw_outbuf_width_get(Outbuf *buf); + +int evas_software_ddraw_outbuf_height_get(Outbuf *buf); + Outbuf_Depth evas_software_ddraw_outbuf_depth_get(Outbuf *buf); -int evas_software_ddraw_outbuf_rot_get(Outbuf *buf); -/* Output Buffer functions */ -DDraw_Output_Buffer *evas_software_ddraw_output_buffer_new(int depth, - int width, - int height, - void *data); -void evas_software_ddraw_output_buffer_free(DDraw_Output_Buffer *ddob); -void evas_software_ddraw_output_buffer_paste(DDraw_Output_Buffer *ddob, - 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_outbuf_rot_get(Outbuf *buf); +/* evas_ddraw_buffer.c */ + +DD_Output_Buffer *evas_software_ddraw_output_buffer_new(int depth, + int width, + int height, + void *data); + +void evas_software_ddraw_output_buffer_free(DD_Output_Buffer *ddob); + +void evas_software_ddraw_output_buffer_paste(DD_Output_Buffer *ddob, + 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(DD_Output_Buffer *ddob, + int *bytes_per_line_ret); + +int evas_software_ddraw_output_buffer_depth(DD_Output_Buffer *ddob); + +/* evas_ddraw_main.cpp */ #ifdef __cplusplus extern "C" { #endif +int evas_software_ddraw_init (HWND window, + int depth, + Outbuf *buf); -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); +void evas_software_ddraw_shutdown(Outbuf *buf); +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); #ifdef __cplusplus } diff --git a/legacy/evas/src/modules/engines/software_ddraw/evas_outbuf.c b/legacy/evas/src/modules/engines/software_ddraw/evas_outbuf.c index 3035e947a4..5a6f78336f 100644 --- a/legacy/evas/src/modules/engines/software_ddraw/evas_outbuf.c +++ b/legacy/evas/src/modules/engines/software_ddraw/evas_outbuf.c @@ -1,6 +1,89 @@ +#include "evas_common.h" #include "evas_engine.h" +static Evas_List *ddpool = NULL; +static int ddsize = 0; +static int ddmemlimit = 10 * 1024 * 1024; +static int ddcountlimit = 32; + +static DD_Output_Buffer * +_find_ddob(int depth, int w, int h, void *data) +{ + Evas_List *l; + Evas_List *ddl; + DD_Output_Buffer *ddob = NULL; + int sz; + int lbytes; + int bpp; + + bpp = depth / 8; + if (bpp == 3) bpp = 4; + lbytes = (((w * bpp) + 3) / 4) * 4; + sz = lbytes * h; + for (l = ddpool; l; l = l->next) + { + DD_Output_Buffer *ddob2; + + ddob2 = l->data; + if (ddob2->depth != depth) + continue; + if (ddob2->psize == sz) + { + ddob = ddob2; + ddl = l; + goto have_ddob; + } + } + if (!ddob) + return evas_software_ddraw_output_buffer_new(depth, w, h, data); + + have_ddob: + ddpool = evas_list_remove_list(ddpool, ddl); + ddob->width = w; + ddob->height = h; + ddob->pitch = lbytes; + ddsize -= ddob->psize * (ddob->depth / 8); + + return ddob; +} + +static void +_unfind_ddob(DD_Output_Buffer *ddob) +{ + ddpool = evas_list_prepend(ddpool, ddob); + ddsize += ddob->psize * ddob->depth / 8; + while ((ddsize > (ddmemlimit)) || + (evas_list_count(ddpool) > ddcountlimit)) + { + Evas_List *xl; + + xl = evas_list_last(ddpool); + if (!xl) + { + ddsize = 0; + break; + } + ddob = xl->data; + ddpool = evas_list_remove_list(ddpool, xl); + evas_software_ddraw_output_buffer_free(ddob); + } +} + +static void +_clear_ddob(int sync) +{ + while (ddpool) + { + DD_Output_Buffer *ddob; + + ddob = ddpool->data; + ddpool = evas_list_remove_list(ddpool, ddpool); + evas_software_ddraw_output_buffer_free(ddob); + } + ddsize = 0; +} + void evas_software_ddraw_outbuf_init(void) { @@ -9,19 +92,20 @@ evas_software_ddraw_outbuf_init(void) void evas_software_ddraw_outbuf_free(Outbuf *buf) { + if (!buf) + return; + + evas_software_ddraw_shutdown(buf); free(buf); } Outbuf * -evas_software_ddraw_outbuf_setup_dd(int width, - int height, - int rotation, - Outbuf_Depth depth, - HWND window, - LPDIRECTDRAW object, - LPDIRECTDRAWSURFACE surface_primary, - LPDIRECTDRAWSURFACE surface_back, - int w_depth) +evas_software_ddraw_outbuf_setup(int width, + int height, + int rotation, + Outbuf_Depth depth, + HWND window, + int w_depth) { Outbuf *buf; @@ -34,15 +118,15 @@ evas_software_ddraw_outbuf_setup_dd(int width, buf->depth = depth; buf->rot = rotation; - buf->priv.dd.window = window; - buf->priv.dd.object = object; - buf->priv.dd.surface_primary = surface_primary; - buf->priv.dd.surface_back = surface_back; - buf->priv.dd.depth = w_depth; + if (!evas_software_ddraw_init(window, w_depth, buf)) + { + free(buf); + return NULL; + } { - Gfx_Func_Convert conv_func; - DDraw_Output_Buffer *ddob; + Gfx_Func_Convert conv_func; + DD_Output_Buffer *ddob; ddob = evas_software_ddraw_output_buffer_new(w_depth, 1, 1, NULL); @@ -72,19 +156,21 @@ evas_software_ddraw_outbuf_setup_dd(int width, PAL_MODE_NONE, rotation); } + evas_software_ddraw_output_buffer_free(ddob); + if (!conv_func) { - printf(".[ Evas Error ].\n" - " {\n" - " At depth %i:\n" - " RGB format mask: %08x, %08x, %08x\n" - " Not supported by and compiled in converters!\n" - " }\n", - buf->priv.dd.depth, - buf->priv.mask.r, - buf->priv.mask.g, - buf->priv.mask.b); + fprintf(stderr, ".[ Evas Error ].\n" + " {\n" + " At depth %i:\n" + " RGB format mask: %08x, %08x, %08x\n" + " Not supported by and compiled in converters!\n" + " }\n", + buf->priv.dd.depth, + buf->priv.mask.r, + buf->priv.mask.g, + buf->priv.mask.b); } } } @@ -92,70 +178,179 @@ evas_software_ddraw_outbuf_setup_dd(int width, return buf; } +void +evas_software_ddraw_outbuf_reconfigure(Outbuf *buf, + int width, + int height, + int rotation, + Outbuf_Depth depth) +{ + if ((width == buf->width) && (height == buf->height) && + (rotation == buf->rot) && (depth == buf->depth)) + return; + buf->width = width; + buf->height = height; + buf->rot = rotation; + evas_software_ddraw_surface_resize(buf); +} + RGBA_Image * evas_software_ddraw_outbuf_new_region_for_update(Outbuf *buf, - int x, - int y, - int width, - int height, - int *cx, - int *cy, - int *cw, - int *ch) + int x, + int y, + int w, + int h, + int *cx, + int *cy, + int *cw, + int *ch) { - RGBA_Image *im; - DDraw_Output_Buffer *ddob = NULL; - int bpl = 0; + RGBA_Image *im; + Outbuf_Region *obr; + int bpl = 0; + int alpha = 0; + obr = calloc(1, sizeof(Outbuf_Region)); + obr->x = x; + obr->y = y; + obr->width = w; + obr->height = h; *cx = 0; *cy = 0; - *cw = width; - *ch = height; + *cw = w; + *ch = h; if ((buf->rot == 0) && (buf->priv.mask.r == 0xff0000) && (buf->priv.mask.g == 0x00ff00) && (buf->priv.mask.b == 0x0000ff)) { - im = (RGBA_Image*) evas_cache_image_empty(evas_common_image_cache_get()); - if (!im) return NULL; - im = (RGBA_Image*) evas_cache_image_size_set(&im->cache_entry, width, height); - if (!im) return NULL; - im->image.no_free = 1; - ddob = evas_software_ddraw_output_buffer_new(buf->priv.dd.depth, - width, - height, - NULL); - im->extended_info = ddob; - im->image.data = (DATA32 *)evas_software_ddraw_output_buffer_data(ddob, &bpl); + obr->ddob = _find_ddob(buf->priv.dd.depth, w, h, NULL); +/* obr->ddob = evas_software_x11_x_output_buffer_new(buf->priv.dd.disp, */ +/* buf->priv.dd.vis, */ +/* buf->priv.dd.depth, */ +/* w, h, */ +/* use_shm, */ +/* NULL); */ + im = (RGBA_Image *)evas_cache_image_data(evas_common_image_cache_get(), + w, h, + (DATA32 *) evas_software_ddraw_output_buffer_data(obr->ddob, &bpl), + alpha, EVAS_COLORSPACE_ARGB8888); + im->extended_info = obr; } else { - im = evas_cache_image_empty(evas_common_image_cache_get()); - if (!im) return NULL; - evas_cache_image_surface_alloc(&im->cache_entry, width, height); - im->extended_info = ddob; + im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get()); + im->cache_entry.flags.alpha |= alpha ? 1 : 0; + evas_cache_image_surface_alloc(&im->cache_entry, w, h); + im->extended_info = obr; if ((buf->rot == 0) || (buf->rot == 180)) - ddob = evas_software_ddraw_output_buffer_new(buf->priv.dd.depth, - width, - height, - NULL); + obr->ddob = _find_ddob(buf->priv.dd.depth, w, h, NULL); +/* + obr->ddob = evas_software_x11_x_output_buffer_new(buf->priv.dd.disp, + buf->priv.dd.vis, + buf->priv.dd.depth, + w, h, + use_shm, + NULL); + */ else if ((buf->rot == 90) || (buf->rot == 270)) - ddob = evas_software_ddraw_output_buffer_new(buf->priv.dd.depth, - width, - height, - NULL); - im->extended_info = ddob; + obr->ddob = _find_ddob(buf->priv.dd.depth, h, w, NULL); +/* + obr->ddob = evas_software_x11_x_output_buffer_new(buf->priv.dd.disp, + buf->priv.dd.vis, + buf->priv.dd.depth, + h, w, + use_shm, + NULL); + */ } buf->priv.pending_writes = evas_list_append(buf->priv.pending_writes, im); - return im; } +void +evas_software_ddraw_outbuf_push_updated_region(Outbuf *buf, + RGBA_Image *update, + int x, + int y, + int w, + int h) +{ + Gfx_Func_Convert conv_func; + Outbuf_Region *obr; + DATA32 *src_data; + void *data; + int bpl = 0, yy; + + conv_func = NULL; + obr = update->extended_info; + + if ((buf->rot == 0) || (buf->rot == 180)) + conv_func = evas_common_convert_func_get(0, w, h, + evas_software_ddraw_output_buffer_depth(obr->ddob), + buf->priv.mask.r, + buf->priv.mask.g, + buf->priv.mask.b, + PAL_MODE_NONE, + buf->rot); + else if ((buf->rot == 90) || (buf->rot == 270)) + conv_func = evas_common_convert_func_get(0, h, w, + evas_software_ddraw_output_buffer_depth(obr->ddob), + buf->priv.mask.r, + buf->priv.mask.g, + buf->priv.mask.b, + PAL_MODE_NONE, buf->rot); + if (!conv_func) return; + + data = evas_software_ddraw_output_buffer_data(obr->ddob, &bpl); + src_data = update->image.data; + if (buf->rot == 0) + { + obr->x = x; + obr->y = y; + } + else if (buf->rot == 90) + { + obr->x = y; + obr->y = buf->width - x - w; + } + else if (buf->rot == 180) + { + obr->x = buf->width - x - w; + obr->y = buf->height - y - h; + } + else if (buf->rot == 270) + { + obr->x = buf->height - y - h; + obr->y = x; + } + if ((buf->rot == 0) || (buf->rot == 180)) + { + obr->width = w; + obr->height = h; + } + else if ((buf->rot == 90) || (buf->rot == 270)) + { + obr->width = h; + obr->height = w; + } + + if (data != src_data) + conv_func(src_data, data, + 0, + bpl / ((evas_software_ddraw_output_buffer_depth(obr->ddob) / 8)) - obr->width, + obr->width, + obr->height, + x, + y, + NULL); +} + void evas_software_ddraw_outbuf_free_region_for_update(Outbuf *buf, - RGBA_Image *update) + RGBA_Image *update) { /* no need to do anything - they are cleaned up on flush */ } @@ -181,136 +376,68 @@ evas_software_ddraw_outbuf_flush(Outbuf *buf) /* copy safely the images that need to be drawn onto the back surface */ for (l = buf->priv.pending_writes; l; l = l->next) { - RGBA_Image *im; - DDraw_Output_Buffer *ddob; + RGBA_Image *im; + Outbuf_Region *obr; + DD_Output_Buffer *ddob; - im = l->data; - ddob = im->extended_info; - /* paste now */ - evas_software_ddraw_output_buffer_paste(ddob, + im = l->data; + obr = im->extended_info; + ddob = obr->ddob; + evas_software_ddraw_output_buffer_paste(ddob, ddraw_data, ddraw_width, ddraw_height, ddraw_pitch, ddraw_depth, - ddob->x, - ddob->y); + obr->x, + obr->y); } /* unlock the back surface and flip the surface */ evas_software_ddraw_unlock_and_flip(buf); free_images: - while (buf->priv.pending_writes) + while (buf->priv.prev_pending_writes) { - RGBA_Image *im; - DDraw_Output_Buffer *ddob; + RGBA_Image *im; + Outbuf_Region *obr; - im = buf->priv.pending_writes->data; - buf->priv.pending_writes = evas_list_remove_list(buf->priv.pending_writes, - buf->priv.pending_writes); - ddob = im->extended_info; - evas_cache_image_drop(im); - if (ddob) evas_software_ddraw_output_buffer_free(ddob); + im = buf->priv.prev_pending_writes->data; + buf->priv.prev_pending_writes = + evas_list_remove_list(buf->priv.prev_pending_writes, + buf->priv.prev_pending_writes); + obr = im->extended_info; + evas_cache_image_drop((Image_Entry *)im); + if (obr->ddob) _unfind_ddob(obr->ddob); +/* + if (obr->ddob) evas_software_x11_x_output_buffer_free(obr->ddob); + */ + free(obr); } + buf->priv.prev_pending_writes = buf->priv.pending_writes; + buf->priv.pending_writes = NULL; + evas_common_cpu_end_opt(); } void -evas_software_ddraw_outbuf_push_updated_region(Outbuf *buf, - RGBA_Image *update, - int x, - int y, - int width, - int height) +evas_software_ddraw_outbuf_idle_flush(Outbuf *buf) { - Gfx_Func_Convert conv_func; - DDraw_Output_Buffer *ddob; - DATA32 *src_data; - void *data; - int bpl = 0; - - conv_func = NULL; - ddob = update->extended_info; - - if ((buf->rot == 0) || (buf->rot == 180)) - conv_func = evas_common_convert_func_get(NULL, - width, - height, - evas_software_ddraw_output_buffer_depth(ddob), - buf->priv.mask.r, - buf->priv.mask.g, - buf->priv.mask.b, - PAL_MODE_NONE, - buf->rot); - else if ((buf->rot == 90) || (buf->rot == 270)) - conv_func = evas_common_convert_func_get(NULL, - height, - width, - evas_software_ddraw_output_buffer_depth(ddob), - buf->priv.mask.r, - buf->priv.mask.g, - buf->priv.mask.b, - PAL_MODE_NONE, - buf->rot); - - if (!conv_func) return; - - data = evas_software_ddraw_output_buffer_data(ddob, &bpl); - src_data = update->image->data; - if (buf->rot == 0) + while (buf->priv.prev_pending_writes) { - ddob->x = x; - ddob->y = y; - } - else if (buf->rot == 90) - { - ddob->x = y; - ddob->y = buf->width - x - width; - } - else if (buf->rot == 180) - { - ddob->x = buf->width - x - width; - ddob->y = buf->height - y - height; - } - else if (buf->rot == 270) - { - ddob->x = buf->height - y - height; - ddob->y = x; - } - if ((buf->rot == 0) || (buf->rot == 180)) - { - ddob->width = width; - ddob->height = height; - } - else if ((buf->rot == 90) || (buf->rot == 270)) - { - ddob->width = height; - ddob->height = width; - } + RGBA_Image *im; + Outbuf_Region *obr; - if (data != src_data) - conv_func(src_data, data, - 0, - bpl / - ((evas_software_ddraw_output_buffer_depth(ddob))) - ddob->width, - ddob->width, ddob->height, x, y, NULL); -} - -void -evas_software_ddraw_outbuf_reconfigure(Outbuf *buf, - int width, - int height, - int rotation, - Outbuf_Depth depth) -{ - if ((width == buf->width) && (height == buf->height) && - (rotation == buf->rot) && (depth == buf->depth)) - return; - buf->width = width; - buf->height = height; - buf->rot = rotation; - evas_software_ddraw_surface_resize(buf); + im = buf->priv.prev_pending_writes->data; + buf->priv.prev_pending_writes = + evas_list_remove_list(buf->priv.prev_pending_writes, + buf->priv.prev_pending_writes); + obr = im->extended_info; + evas_cache_image_drop((Image_Entry *)im); + if (obr->ddob) _unfind_ddob(obr->ddob); + free(obr); + } + _clear_ddob(0); } int