| version 1.2, 2004/07/15 14:24:33 | version 1.5, 2007/01/10 15:58:58 | 
| Line 12 | Line 12 | 
 | * 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | 
 | *    notice, this list of conditions and the following disclaimer in the | *    notice, this list of conditions and the following disclaimer in the | 
 | *    documentation and/or other materials provided with the distribution. | *    documentation and/or other materials provided with the distribution. | 
 | * 3. The name of the author may not be used to endorse or promote products |  | 
 | *    derived from this software without specific prior written permission. |  | 
 | * | * | 
 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
| Line 45  drawmng_create(void *parent, int width, | Line 43  drawmng_create(void *parent, int width, | 
 | GTKDRAWMNG_HDL hdl = NULL; | GTKDRAWMNG_HDL hdl = NULL; | 
 | GtkWidget *parent_window; | GtkWidget *parent_window; | 
 | GdkVisual *visual; | GdkVisual *visual; | 
| int bitcolor; | pixmap_format_t fmt; | 
 | int bytes_per_pixel; | int bytes_per_pixel; | 
 |  | int padding; | 
 |  |  | 
 | if (parent == NULL) | if (parent == NULL) | 
 | return NULL; | return NULL; | 
 | parent_window = GTK_WIDGET(parent); | parent_window = GTK_WIDGET(parent); | 
 |  | gtk_widget_realize(parent_window); | 
 |  |  | 
 | hdl = (GTKDRAWMNG_HDL)_MALLOC(sizeof(_GTKDRAWMNG_HDL), "drawmng hdl"); | hdl = (GTKDRAWMNG_HDL)_MALLOC(sizeof(_GTKDRAWMNG_HDL), "drawmng hdl"); | 
 | if (hdl == NULL) | if (hdl == NULL) | 
| Line 65  drawmng_create(void *parent, int width, | Line 65  drawmng_create(void *parent, int width, | 
 | gtk_widget_set_size_request(GTK_WIDGET(hdl->drawarea), width, height); | gtk_widget_set_size_request(GTK_WIDGET(hdl->drawarea), width, height); | 
 |  |  | 
 | visual = gtk_widget_get_visual(hdl->drawarea); | visual = gtk_widget_get_visual(hdl->drawarea); | 
| bitcolor = gtkdrawmng_getbpp(hdl->drawarea, parent_window); | if (!gtkdrawmng_getformat(hdl->drawarea, parent_window, &fmt)) | 
| if (bitcolor == 0) |  | 
 | goto destroy; | goto destroy; | 
 | bytes_per_pixel = bitcolor / 8; |  | 
 |  |  | 
| if (bitcolor == 16) { | switch (fmt.bits_per_pixel) { | 
|  | #if defined(SUPPORT_32BPP) | 
|  | case 32: | 
|  | break; | 
|  | #endif | 
|  | #if defined(SUPPORT_24BPP) | 
|  | case 24: | 
|  | break; | 
|  | #endif | 
|  | #if defined(SUPPORT_16BPP) | 
|  | case 16: | 
|  | case 15: | 
 | drawmng_make16mask(&hdl->d.pal16mask, visual->blue_mask, | drawmng_make16mask(&hdl->d.pal16mask, visual->blue_mask, | 
 | visual->red_mask, visual->green_mask); | visual->red_mask, visual->green_mask); | 
 |  | break; | 
 |  | #endif | 
 |  | #if defined(SUPPORT_8BPP) | 
 |  | case 8: | 
 |  | break; | 
 |  | #endif | 
 |  |  | 
 |  | default: | 
 |  | goto destroy; | 
 | } | } | 
 |  | bytes_per_pixel = fmt.bits_per_pixel / 8; | 
 |  |  | 
 | hdl->d.dest.x = hdl->d.dest.x = 0; | hdl->d.dest.x = hdl->d.dest.x = 0; | 
 | hdl->d.src.left = hdl->d.src.top = 0; | hdl->d.src.left = hdl->d.src.top = 0; | 
 | hdl->d.src.right = width; | hdl->d.src.right = width; | 
 | hdl->d.src.bottom = height; | hdl->d.src.bottom = height; | 
 | hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; | hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; | 
| if (hdl->d.lpitch % 4) { | padding = hdl->d.lpitch % (fmt.scanline_pad / 8); | 
| hdl->d.src.right += (hdl->d.lpitch % 4) / bytes_per_pixel; | if (padding > 0) { | 
|  | hdl->d.src.right += padding / bytes_per_pixel; | 
 | hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; | hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; | 
 | } | } | 
 |  |  | 
| Line 95  drawmng_create(void *parent, int width, | Line 115  drawmng_create(void *parent, int width, | 
 | hdl->d.vram.height = hdl->d.src.bottom; | hdl->d.vram.height = hdl->d.src.bottom; | 
 | hdl->d.vram.xalign = bytes_per_pixel; | hdl->d.vram.xalign = bytes_per_pixel; | 
 | hdl->d.vram.yalign = hdl->d.lpitch; | hdl->d.vram.yalign = hdl->d.lpitch; | 
| hdl->d.vram.bpp = bitcolor; | hdl->d.vram.bpp = fmt.bits_per_pixel; | 
 |  |  | 
 | /* pixmap */ | /* pixmap */ | 
 | hdl->backsurf = gdk_pixmap_new(parent_window->window, | hdl->backsurf = gdk_pixmap_new(parent_window->window, | 
| Line 107  drawmng_create(void *parent, int width, | Line 127  drawmng_create(void *parent, int width, | 
 |  |  | 
 | destroy: | destroy: | 
 | if (hdl) { | if (hdl) { | 
 |  | GtkWidget *da = hdl->drawarea; | 
 | drawmng_release((DRAWMNG_HDL)hdl); | drawmng_release((DRAWMNG_HDL)hdl); | 
| if (hdl->drawarea) { | if (da) { | 
| gtk_widget_unref(hdl->drawarea); | gtk_widget_unref(da); | 
 | } | } | 
 | } | } | 
 | return NULL; | return NULL; | 
| Line 124  drawmng_release(DRAWMNG_HDL dhdl) | Line 145  drawmng_release(DRAWMNG_HDL dhdl) | 
 | while (hdl->d.drawing) | while (hdl->d.drawing) | 
 | usleep(1); | usleep(1); | 
 | if (hdl->backsurf) { | if (hdl->backsurf) { | 
| gdk_pixmap_unref(hdl->backsurf); | g_object_unref(hdl->backsurf); | 
 | } | } | 
 | if (hdl->surface) { | if (hdl->surface) { | 
| gdk_image_destroy(hdl->surface); | g_object_unref(hdl->surface); | 
 | } | } | 
 | _MFREE(hdl); | _MFREE(hdl); | 
 | } | } | 
| Line 190  drawmng_blt(DRAWMNG_HDL dhdl, RECT_T *sr | Line 211  drawmng_blt(DRAWMNG_HDL dhdl, RECT_T *sr | 
 | width = r.right - p.x; | width = r.right - p.x; | 
 | height = r.bottom - p.y; | height = r.bottom - p.y; | 
 |  |  | 
| gdk_draw_pixmap(hdl->drawarea->window, gc, | gdk_draw_drawable(hdl->drawarea->window, gc, | 
 | hdl->backsurf, | hdl->backsurf, | 
 | r.left, r.top, p.x, p.y, width, height); | r.left, r.top, p.x, p.y, width, height); | 
 | } else { | } else { | 
| gdk_draw_pixmap(hdl->drawarea->window, gc, | gdk_draw_drawable(hdl->drawarea->window, gc, | 
 | hdl->backsurf, | hdl->backsurf, | 
 | 0, 0, 0, 0, hdl->d.width, hdl->d.height); | 0, 0, 0, 0, hdl->d.width, hdl->d.height); | 
 | } | } | 
| Line 236  drawmng_get_widget_handle(DRAWMNG_HDL dh | Line 257  drawmng_get_widget_handle(DRAWMNG_HDL dh | 
 | return hdl->drawarea; | return hdl->drawarea; | 
 | } | } | 
 |  |  | 
| int | BOOL | 
| gtkdrawmng_getbpp(GtkWidget *w, GtkWidget *parent_window) | gtkdrawmng_getformat(GtkWidget *w, GtkWidget *pw, pixmap_format_t *fmtp) | 
 | { | { | 
 | GdkVisual *visual; | GdkVisual *visual; | 
 | int bitcolor; |  | 
 |  |  | 
 | visual = gtk_widget_get_visual(w); | visual = gtk_widget_get_visual(w); | 
 | switch (visual->type) { | switch (visual->type) { | 
 | case GDK_VISUAL_TRUE_COLOR: | case GDK_VISUAL_TRUE_COLOR: | 
 | case GDK_VISUAL_PSEUDO_COLOR: | case GDK_VISUAL_PSEUDO_COLOR: | 
 | case GDK_VISUAL_DIRECT_COLOR: | case GDK_VISUAL_DIRECT_COLOR: | 
| if (visual->depth >= 8) { | break; | 
| break; |  | 
| } |  | 
| /* FALLTHROUGH */ |  | 
 | default: | default: | 
 | fprintf(stderr, "No support visual class.\n"); | fprintf(stderr, "No support visual class.\n"); | 
| return 0; | return FALSE; | 
 | } | } | 
 |  |  | 
| if (visual->depth == 32) { | switch (visual->depth) { | 
| bitcolor = 32; | #if defined(SUPPORT_32BPP) | 
| } else if (visual->depth == 24) { | case 32: | 
| if (is_32bpp(parent_window->window)) { | #endif | 
| bitcolor = 32; | #if defined(SUPPORT_24BPP) | 
| } else { | case 24: | 
| bitcolor = 24; | #endif | 
|  | #if defined(SUPPORT_16BPP) | 
|  | case 16: | 
|  | case 15: | 
|  | #endif | 
|  | #if defined(SUPPORT_8BPP) | 
|  | case 8: | 
|  | #endif | 
|  | break; | 
|  |  | 
|  | default: | 
|  | if (visual->depth < 8) { | 
|  | fprintf(stderr, "Too few allocable color.\n"); | 
 | } | } | 
 | } else if (visual->depth == 15 || visual->depth == 16) { |  | 
 | bitcolor = 16; |  | 
 | } else if (visual->depth == 8) { |  | 
 | bitcolor = 8; |  | 
 | } else if (visual->depth < 8) { |  | 
 | fprintf(stderr, "Too few allocable color.\n"); |  | 
 | return 0; |  | 
 | } else { |  | 
 | fprintf(stderr, "No support depth.\n"); | fprintf(stderr, "No support depth.\n"); | 
| return 0; | return FALSE; | 
 | } | } | 
 |  |  | 
| return bitcolor; | return gdk_window_get_pixmap_format(pw->window, visual, fmtp); | 
 | } | } |