Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2006:
[Freeciv-Dev] (PR#16431) [PATCH] cairo conversion of gtk2 client
Home

[Freeciv-Dev] (PR#16431) [PATCH] cairo conversion of gtk2 client

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: patg@xxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#16431) [PATCH] cairo conversion of gtk2 client
From: "Christian Prochaska" <cp.ml.freeciv.dev@xxxxxxxxxxxxxx>
Date: Thu, 27 Apr 2006 15:28:16 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=16431 >

struct sprite *load_gfxfile(const char *filename)
{
  cairo_surface_t *img, *surface;
  cairo_t *cr;
  int w, h;

  img = cairo_image_surface_create_from_png(filename);

  if (cairo_surface_status(img) != CAIRO_STATUS_SUCCESS) {
    freelog(LOG_FATAL, "Failed reading graphics file: %s", filename);
    freelog(LOG_FATAL, "  %s", cairo_status_to_string(
                                cairo_surface_status(img)));
    exit(EXIT_FAILURE);
  }

  w = cairo_image_surface_get_width(img);
  h = cairo_image_surface_get_height(img);

  /* Creating server-side pixel buffer
   * This groups everything server-side, reducing memory use/round trips */
  surface = cairo_surface_create_similar(ref_pbuffer,
                                         CAIRO_CONTENT_COLOR_ALPHA, w, h);
  assert(cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS);
  cr = cairo_create(surface);

  /* Cleaning that surface and getting a copy of the image */
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_rectangle(cr, 0.0, 0.0, w, h);
  cairo_fill(cr);

  cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
  cairo_set_source_surface(cr, img, 0.0, 0.0);
  cairo_paint(cr);
  cairo_destroy(cr);
  cairo_surface_destroy(img);

  /* write surface to PNG */
  char *filename2 = fc_malloc(strlen(filename) + 10);
  mystrlcpy(filename2, filename, strlen(filename) + 1);
  mystrlcat(filename2, ".new.png", strlen(filename) + 10);
  freelog(LOG_NORMAL, "writing %s", filename2);
  
  cairo_surface_write_to_png(surface, filename2);
 
  free(filename2);


  return surface_to_sprite(surface, w, h);
}


This writes the created surface back to a PNG file and in my test with
amplio and trident tilesets and the "nv" driver it created some "empty"
files (sample file attached):

misc/citybar.png
misc/colors.png

amplio/fog.png
amplio/grid.png
amplio/terrain1.png
amplio/terrain2.png

trident/fog.png
trident/roads.png
trident/tiles.png

Do these images have something in common what the other images don't have?

And for some reason they were drawn correctly when I replaced
CAIRO_OPERATOR_SOURCE with CAIRO_OPERATOR_OVER, but this still didn't
solve the "high CPU load" problem (which makes the game really
unplayable, because every move needs seconds). I tracked this down to
canvas_put() where CPU usage comes to a normal level when I outcomment
the cairo_set_source_surface() call, but of course nothing useful is
visible then.

PNG image


[Prev in Thread] Current Thread [Next in Thread]