--- np2/x11/gtk2/gtk_drawmng.c 2004/07/14 16:01:40 1.1 +++ np2/x11/gtk2/gtk_drawmng.c 2011/01/15 18:43:13 1.9 @@ -1,5 +1,3 @@ -/* $Id: gtk_drawmng.c,v 1.1 2004/07/14 16:01:40 monaka Exp $ */ - /* * Copyright (c) 2003 NONAKA Kimihiro * All rights reserved. @@ -12,8 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * 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 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -45,12 +41,14 @@ drawmng_create(void *parent, int width, GTKDRAWMNG_HDL hdl = NULL; GtkWidget *parent_window; GdkVisual *visual; - int bitcolor; + pixmap_format_t fmt; int bytes_per_pixel; + int padding; if (parent == NULL) return NULL; parent_window = GTK_WIDGET(parent); + gtk_widget_realize(parent_window); hdl = (GTKDRAWMNG_HDL)_MALLOC(sizeof(_GTKDRAWMNG_HDL), "drawmng hdl"); if (hdl == NULL) @@ -65,23 +63,43 @@ drawmng_create(void *parent, int width, gtk_widget_set_size_request(GTK_WIDGET(hdl->drawarea), width, height); visual = gtk_widget_get_visual(hdl->drawarea); - bitcolor = gtkdrawmng_getbpp(hdl->drawarea, parent_window); - if (bitcolor == 0) + if (!gtkdrawmng_getformat(hdl->drawarea, parent_window, &fmt)) 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, 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.src.left = hdl->d.src.top = 0; hdl->d.src.right = width; hdl->d.src.bottom = height; hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; - if (hdl->d.lpitch % 4) { - hdl->d.src.right += (hdl->d.lpitch % 4) / bytes_per_pixel; + padding = hdl->d.lpitch % (fmt.scanline_pad / 8); + if (padding > 0) { + hdl->d.src.right += padding / bytes_per_pixel; hdl->d.lpitch = hdl->d.src.right * bytes_per_pixel; } @@ -95,7 +113,7 @@ drawmng_create(void *parent, int width, hdl->d.vram.height = hdl->d.src.bottom; hdl->d.vram.xalign = bytes_per_pixel; hdl->d.vram.yalign = hdl->d.lpitch; - hdl->d.vram.bpp = bitcolor; + hdl->d.vram.bpp = fmt.bits_per_pixel; /* pixmap */ hdl->backsurf = gdk_pixmap_new(parent_window->window, @@ -107,9 +125,10 @@ drawmng_create(void *parent, int width, destroy: if (hdl) { + GtkWidget *da = hdl->drawarea; drawmng_release((DRAWMNG_HDL)hdl); - if (hdl->drawarea) { - gtk_widget_unref(hdl->drawarea); + if (da) { + g_object_unref(da); } } return NULL; @@ -124,10 +143,10 @@ drawmng_release(DRAWMNG_HDL dhdl) while (hdl->d.drawing) usleep(1); if (hdl->backsurf) { - gdk_pixmap_unref(hdl->backsurf); + g_object_unref(hdl->backsurf); } if (hdl->surface) { - gdk_image_destroy(hdl->surface); + g_object_unref(hdl->surface); } _MFREE(hdl); } @@ -139,7 +158,7 @@ drawmng_surflock(DRAWMNG_HDL dhdl) GTKDRAWMNG_HDL hdl = (GTKDRAWMNG_HDL)dhdl; if (hdl) { - hdl->d.vram.ptr = (BYTE *)hdl->surface->mem; + hdl->d.vram.ptr = (UINT8 *)hdl->surface->mem; if (hdl->d.vram.ptr) { hdl->d.drawing = TRUE; return &hdl->d.vram; @@ -155,7 +174,7 @@ drawmng_surfunlock(DRAWMNG_HDL dhdl) GdkGC *gc; if (hdl) { - gc = hdl->drawarea->style->fg_gc[GTK_WIDGET_STATE(hdl->drawarea)]; + gc = hdl->drawarea->style->fg_gc[gtk_widget_get_state(hdl->drawarea)]; gdk_draw_image(hdl->backsurf, gc, hdl->surface, 0, 0, 0, 0, hdl->d.width, hdl->d.height); hdl->d.drawing = FALSE; @@ -172,7 +191,7 @@ drawmng_blt(DRAWMNG_HDL dhdl, RECT_T *sr int width, height; if (hdl) { - gc = hdl->drawarea->style->fg_gc[GTK_WIDGET_STATE(hdl->drawarea)]; + gc = hdl->drawarea->style->fg_gc[gtk_widget_get_state(hdl->drawarea)]; if (sr || dp) { if (sr) { @@ -190,11 +209,11 @@ drawmng_blt(DRAWMNG_HDL dhdl, RECT_T *sr width = r.right - p.x; height = r.bottom - p.y; - gdk_draw_pixmap(hdl->drawarea->window, gc, + gdk_draw_drawable(hdl->drawarea->window, gc, hdl->backsurf, r.left, r.top, p.x, p.y, width, height); } else { - gdk_draw_pixmap(hdl->drawarea->window, gc, + gdk_draw_drawable(hdl->drawarea->window, gc, hdl->backsurf, 0, 0, 0, 0, hdl->d.width, hdl->d.height); } @@ -236,45 +255,46 @@ drawmng_get_widget_handle(DRAWMNG_HDL dh return hdl->drawarea; } -int -gtkdrawmng_getbpp(GtkWidget *w, GtkWidget *parent_window) +BOOL +gtkdrawmng_getformat(GtkWidget *w, GtkWidget *pw, pixmap_format_t *fmtp) { GdkVisual *visual; - int bitcolor; visual = gtk_widget_get_visual(w); switch (visual->type) { case GDK_VISUAL_TRUE_COLOR: case GDK_VISUAL_PSEUDO_COLOR: case GDK_VISUAL_DIRECT_COLOR: - if (visual->depth >= 8) { - break; - } - /* FALLTHROUGH */ + break; + default: - fprintf(stderr, "No support visual class.\n"); - return 0; + g_printerr("No support visual class.\n"); + return FALSE; } - if (visual->depth == 32) { - bitcolor = 32; - } else if (visual->depth == 24) { - if (is_32bpp(parent_window->window)) { - bitcolor = 32; - } else { - bitcolor = 24; + switch (visual->depth) { +#if defined(SUPPORT_32BPP) + case 32: +#endif +#if defined(SUPPORT_24BPP) + case 24: +#endif +#if defined(SUPPORT_16BPP) + case 16: + case 15: +#endif +#if defined(SUPPORT_8BPP) + case 8: +#endif + break; + + default: + if (visual->depth < 8) { + g_printerr("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"); - return 0; + g_printerr("No support depth.\n"); + return FALSE; } - return bitcolor; + return gdk_window_get_pixmap_format(pw->window, visual, fmtp); }