Diff for /np2/x11/gtk2/gtk_drawmng.c between versions 1.1 and 1.10

version 1.1, 2004/07/14 16:01:40 version 1.10, 2011/12/21 18:16:25
Line 1 Line 1
 /*      $Id$    */  
   
 /*  /*
  * Copyright (c) 2003 NONAKA Kimihiro   * Copyright (c) 2003 NONAKA Kimihiro
  * All rights reserved.   * All rights reserved.
Line 12 Line 10
  * 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 41  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 63  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.y = 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 113  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 125  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);                          g_object_unref(da);
                 }                  }
         }          }
         return NULL;          return NULL;
Line 124  drawmng_release(DRAWMNG_HDL dhdl) Line 143  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 139  drawmng_surflock(DRAWMNG_HDL dhdl) Line 158  drawmng_surflock(DRAWMNG_HDL dhdl)
         GTKDRAWMNG_HDL hdl = (GTKDRAWMNG_HDL)dhdl;          GTKDRAWMNG_HDL hdl = (GTKDRAWMNG_HDL)dhdl;
   
         if (hdl) {          if (hdl) {
                 hdl->d.vram.ptr = (BYTE *)hdl->surface->mem;                  hdl->d.vram.ptr = (UINT8 *)hdl->surface->mem;
                 if (hdl->d.vram.ptr) {                  if (hdl->d.vram.ptr) {
                         hdl->d.drawing = TRUE;                          hdl->d.drawing = TRUE;
                         return &hdl->d.vram;                          return &hdl->d.vram;
Line 155  drawmng_surfunlock(DRAWMNG_HDL dhdl) Line 174  drawmng_surfunlock(DRAWMNG_HDL dhdl)
         GdkGC *gc;          GdkGC *gc;
   
         if (hdl) {          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,                  gdk_draw_image(hdl->backsurf, gc, hdl->surface,
                     0, 0, 0, 0, hdl->d.width, hdl->d.height);                      0, 0, 0, 0, hdl->d.width, hdl->d.height);
                 hdl->d.drawing = FALSE;                  hdl->d.drawing = FALSE;
Line 172  drawmng_blt(DRAWMNG_HDL dhdl, RECT_T *sr Line 191  drawmng_blt(DRAWMNG_HDL dhdl, RECT_T *sr
         int width, height;          int width, height;
   
         if (hdl) {          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 || dp) {
   
                         if (sr) {                          if (sr) {
Line 190  drawmng_blt(DRAWMNG_HDL dhdl, RECT_T *sr Line 209  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 255  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");                  g_printerr("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) {
                           g_printerr("Too few allocable color.\n");
                 }                  }
         } else if (visual->depth == 15 || visual->depth == 16) {                  g_printerr("No support depth.\n");
                 bitcolor = 16;                  return FALSE;
         } 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;  
         }          }
   
         return bitcolor;          return gdk_window_get_pixmap_format(pw->window, visual, fmtp);
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.10


RetroPC.NET-CVS <cvs@retropc.net>