Exemple #1
0
static cairo_t* _x11_backwin_begin_paint(struct _x11_backwin *self)
{
    Display *display;
    int screen, width, height;

    if (!self->managed)
        return NULL;

    display = mume_x11_backend_get_display(self->backend);
    screen = mume_x11_backend_get_screen(self->backend);
    _x11_backwin_get_geometry(self, NULL, NULL, &width, &height);

    if (NULL == self->surface) {
        self->surface = cairo_xlib_surface_create(
            display, self->window,
            DefaultVisual(display, screen),
            width, height);

        if (NULL == self->surface) {
            mume_error(("cairo_xlib_surface_create(%d, %d)\n",
                        width, height));

            return NULL;
        }
    }
    else {
        cairo_xlib_surface_set_size(self->surface, width, height);
    }

    return cairo_create(self->surface);
}
Exemple #2
0
/*! Open an X11 window and create a cairo surface base on that window. If x and
 * y are set to 0 the function opens a full screen window and stores to window
 * dimensions to x and y.
 * @param x Pointer to width of window.
 * @param y Pointer to height of window.
 * @return Returns a pointer to a valid Xlib cairo surface. The function does
 * not return on error (exit(3)).
 */
cairo_surface_t* 
cairo_create_x11_surface(int *x, int *y) {

   Display *dsp;
   Drawable da;
   Screen *scr;
   int screen;
   cairo_surface_t *sfc;

   if ((dsp = XOpenDisplay(NULL)) == NULL)
      exit(1);
   screen = DefaultScreen(dsp);
   scr = DefaultScreenOfDisplay(dsp);
   if (!*x || !*y)
   {
      *x = WidthOfScreen(scr), *y = HeightOfScreen(scr);
      da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, *x, *y, 0, 0, 0);
      fullscreen (dsp, da);
   }
   else
      da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, *x, *y, 0, 0, 0);
   XSelectInput(dsp, da, ButtonPressMask | KeyPressMask);
   XMapWindow(dsp, da);

   sfc = cairo_xlib_surface_create(dsp, da, DefaultVisual(dsp, screen), *x, *y);
   cairo_xlib_surface_set_size(sfc, *x, *y);

   return sfc;
}
static void init_X() {
    int screen;
    unsigned long foreground, background;
    XSizeHints hints;
    char **argv = NULL;
    XGCValues gcValues;
    Colormap colormap;
    XColor rgb_color, hw_color;
    Font font;
    //char *FNAME = "hanzigb24st";
    char *FNAME = "-misc-fixed-medium-r-normal--0-0-100-100-c-0-iso10646-1";

    display = XOpenDisplay(NULL);
    if (display == NULL) {
	fprintf(stderr, "Can't open dsplay\n");
	exit(1);
    }
    screen = DefaultScreen(display);
    foreground = BlackPixel(display, screen);
    background = WhitePixel(display, screen);

    window = XCreateSimpleWindow(display,
				 DefaultRootWindow(display),
				 0, 0, WIDTH, HEIGHT, 10,
				 foreground, background);
    hints.x = 0;
    hints.y = 0;
    hints.width = WIDTH;
    hints.height = HEIGHT;
    hints.flags = PPosition | PSize;

    XSetStandardProperties(display, window, 
			   "X", "X", 
			   None,
			   argv, 0,
			   &hints);

    XMapWindow(display, window);


    set_font();
    surface = cairo_xlib_surface_create(display, window,
					DefaultVisual(display, 0), WIDTH, HEIGHT);
    cairo_xlib_surface_set_size(surface, WIDTH, HEIGHT);

    paint_background();

    /*
    cr = cairo_create(surface);
    draw_text(g_array_index(lyric_lines.lines, GString *, 0)->str,
	      0.0, 0.0, 1.0, height_lyric_pixbufs[0]);
    draw_text(g_array_index(lyric_lines.lines, GString*, 1)->str,
	      0.0, 0.0, 1.0, height_lyric_pixbufs[0]);
    cairo_destroy(cr);
    */
    XFlush(display);
}
Exemple #4
0
/**
 * _gdk_x11_drawable_update_size:
 * @drawable: a #GdkDrawableImplX11.
 * 
 * Updates the state of the drawable (in particular the drawable's
 * cairo surface) when its size has changed.
 **/
void
_gdk_x11_drawable_update_size (GdkDrawable *drawable)
{
  GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable);
  
  if (impl->cairo_surface)
    {
      int width, height;
      
      gdk_drawable_get_size (drawable, &width, &height);
      cairo_xlib_surface_set_size (impl->cairo_surface, width, height);
    }
}
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
    cairo_surface_t *surface;

    /* get the error surface */
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);

#if CAIRO_HAS_GL_SURFACE
    cairo_gl_surface_set_size (surface, 0, 0);
    cairo_gl_surface_swapbuffers (surface);
#endif

#if CAIRO_HAS_OS2_SURFACE
    cairo_os2_surface_set_hwnd (surface, 0);
    cairo_os2_surface_set_size (surface, 0, 0);
    cairo_os2_surface_set_manual_window_refresh (surface, FALSE);
#endif

#if CAIRO_HAS_PDF_SURFACE
    cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4);
    cairo_pdf_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_PS_SURFACE
    cairo_ps_surface_set_eps (surface, FALSE);
    cairo_ps_surface_set_size (surface, 0, 0);
    cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
    cairo_ps_surface_dsc_comment (surface, NULL);
    cairo_ps_surface_dsc_begin_setup (surface);
    cairo_ps_surface_dsc_begin_page_setup (surface);
#endif

#if CAIRO_HAS_XCB_SURFACE
    cairo_xcb_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_XLIB_SURFACE
    cairo_xlib_surface_set_size (surface, 0, 0);
    cairo_xlib_surface_set_drawable (surface, 0, 0, 0);
#endif

    cairo_surface_set_mime_data (surface, NULL, NULL, 0, NULL, 0);
    cairo_surface_set_device_offset (surface, 0, 0);
    cairo_surface_set_fallback_resolution (surface, 0, 0);

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
Exemple #6
0
    Surface(Scene& scene, int width = 0, int height = 0) : scene(scene), width(width), height(height), rendered(false) {
        Drawable da;
        Screen *scr;
        int screen;
        cairo_surface_t *sfc;

        if ((dsp = XOpenDisplay(NULL)) == NULL) {
            exit(1);
        }
        screen = DefaultScreen(dsp);
        scr = DefaultScreenOfDisplay(dsp);
        if (width == 0) {
            width = WidthOfScreen(scr), height = HeightOfScreen(scr);
        }
        da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, width, height, 0, 0, 0);
        XSelectInput(dsp, da, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask);
        XMapWindow(dsp, da);
        sfc = cairo_xlib_surface_create(dsp, da, DefaultVisual(dsp, screen), width, height);
        cairo_xlib_surface_set_size(sfc, width, height);

        cairo_surface = sfc;
        cr = cairo_create(sfc);
        render();
    }
Exemple #7
0
static void
wireframeDrawCairo (WireFrame *wireframe, int width, int height)
{
    ScreenInfo *screen_info = wireframe->screen_info;

    XMoveResizeWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow,
                       wireframe->x, wireframe->y, width, height);
    if (!wireframe->mapped)
    {
        XMapWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
        wireframe->mapped = TRUE;
    }
    if ((width == wireframe->width) && (height == wireframe->height))
    {
        /* Moving only */
        return;
    }
    wireframe->width = width;
    wireframe->height = height;

    cairo_xlib_surface_set_size(wireframe->surface, wireframe->width, wireframe->height);
    XClearWindow (myScreenGetXDisplay (screen_info), wireframe->xwindow);
    cairo_set_source_rgba (wireframe->cr, wireframe->red, wireframe->green, wireframe->blue, wireframe->alpha);
    cairo_paint (wireframe->cr);

    cairo_set_source_rgba (wireframe->cr, wireframe->red, wireframe->green, wireframe->blue, 1.0);
    cairo_rectangle (wireframe->cr,
                     OUTLINE_WIDTH_CAIRO / 2, OUTLINE_WIDTH_CAIRO / 2,
                     wireframe->width - OUTLINE_WIDTH_CAIRO,
                     wireframe->height - OUTLINE_WIDTH_CAIRO);
    cairo_stroke (wireframe->cr);
    /* Force a resize of the compositor window to avoid flickering */
    compositorResizeWindow (screen_info->display_info, wireframe->xwindow,
                            wireframe->x, wireframe->y,
                            wireframe->width, wireframe->height);
}
static cairo_test_status_t
do_test (const cairo_test_context_t *ctx,
         Display        *dpy,
         unsigned char  *reference_data,
         unsigned char  *test_data,
         unsigned char  *diff_data,
         cairo_bool_t    use_pixmap,
         cairo_bool_t    set_size,
         cairo_bool_t    offscreen)
{
    cairo_surface_t *surface;
    cairo_surface_t *test_surface;
    cairo_t *test_cr;
    buffer_diff_result_t result;
    Drawable drawable;
    int screen = DefaultScreen (dpy);

    if (use_pixmap && offscreen)
        return CAIRO_TEST_SUCCESS;

    if (use_pixmap) {
        drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy),
                                  SIZE, SIZE, DefaultDepth (dpy, screen));
    } else {
        XSetWindowAttributes xwa;
        int x, y;

        xwa.override_redirect = True;

        if (offscreen) {
            x = - OFFSCREEN_OFFSET;
            y = - OFFSCREEN_OFFSET;
        } else {
            x = 0;
            y = 0;
        }

        drawable = XCreateWindow (dpy, DefaultRootWindow (dpy),
                                  x, y, SIZE, SIZE, 0,
                                  DefaultDepth (dpy, screen), InputOutput,
                                  DefaultVisual (dpy, screen),
                                  CWOverrideRedirect, &xwa);
        XMapWindow (dpy, drawable);
    }

    surface = cairo_xlib_surface_create (dpy,
                                         drawable,
                                         DefaultVisual (dpy, screen),
                                         SIZE, SIZE);

    if (! surface_compare_visual_and_format (surface))
        return CAIRO_TEST_FAILURE;

    if (set_size) {
        cairo_xlib_surface_set_size (surface, SIZE, SIZE);

        if (cairo_xlib_surface_get_width (surface) != SIZE ||
                cairo_xlib_surface_get_height (surface) != SIZE)
            return CAIRO_TEST_FAILURE;
    }

    if (! check_similar_visual_and_format (surface))
        return CAIRO_TEST_FAILURE;

    draw_pattern (surface);

    test_surface = cairo_image_surface_create_for_data (test_data,
                   CAIRO_FORMAT_RGB24,
                   SIZE, SIZE,
                   SIZE * 4);

    test_cr = cairo_create (test_surface);
    cairo_set_source_surface (test_cr, surface, 0, 0);
    cairo_paint (test_cr);

    cairo_destroy (test_cr);
    cairo_surface_destroy (test_surface);

    /* We erase the surface to black in case we get the same
     * memory back again for the pixmap case.
     */
    erase_pattern (surface);
    cairo_surface_destroy (surface);

    if (use_pixmap)
        XFreePixmap (dpy, drawable);
    else
        XDestroyWindow (dpy, drawable);

    if (offscreen) {
        size_t offset = 4 * (SIZE * OFFSCREEN_OFFSET + OFFSCREEN_OFFSET);

        buffer_diff_noalpha (reference_data + offset,
                             test_data + offset,
                             diff_data + offset,
                             SIZE - OFFSCREEN_OFFSET,
                             SIZE - OFFSCREEN_OFFSET,
                             4 * SIZE,
                             &result);
    } else {
        buffer_diff_noalpha (reference_data,
                             test_data,
                             diff_data,
                             SIZE,
                             SIZE,
                             4 * SIZE,
                             &result);
    }

    cairo_test_log (ctx, "xlib-surface: %s, %s, %s: %s\n",
                    set_size ? "   size" : "no-size",
                    use_pixmap ? "pixmap" : "window",
                    use_pixmap ?  "           " : (offscreen ? ", offscreen" : ",  onscreen"),
                    image_diff_is_failure (&result, 0) ? "FAIL" : "PASS");

    if (image_diff_is_failure (&result, 0))
        return CAIRO_TEST_FAILURE;
    else
        return CAIRO_TEST_SUCCESS;
}
EXPORT void slate_cairo_resize(cairo_surface_t* surface, int width, int height) {

  cairo_xlib_surface_set_size(surface, width, height);

}
Exemple #10
0
int main(int argc, char **argv)
{
  cairo_surface_t *surface;
  cairo_t *context;
  int x, y, i,
      width, height, depth,
      screen, pressed_key,
      png;
  double r, b, v;
  QTnode *tree;
  bool rendering;
  struct XWin **xwin;

  /* Get the arguments */
  if(argc != 3) {
    printf("Usage: nbody rendering resultsdir\n");
    exit(1);
  }
  if(*argv[1] == '0') {
    rendering = false;
  } else {
    rendering = true;
  }
  char buf[strlen(argv[2]) + 10];

  /* Set window size */
  width = 1024;
  height = 1024;
  depth = 32;

  tree = init_tree(10, NULL);
  for (i = 0; i < 100000; i++) {
    tree->insert(phys_gen_particle());
    if (i % 10000 == 0)
      printf("%d\n", i);
  }

  /* Create the drawing surface */
  if(rendering) {
    /* Create the X11 window */
    xwin = (struct XWin **)calloc(sizeof(struct XWin *), 1);
    xwindow_init(width, height, depth, xwin);
    surface = cairo_xlib_surface_create((*xwin)->dsp, (*xwin)->win, DefaultVisual((*xwin)->dsp, screen), width, height);
    cairo_xlib_surface_set_size(surface, width, height);
  } else {
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); 
  }
  context = cairo_create(surface);
  cairo_scale(context, width, height);

  png = 0;
  while(1) {
    if(rendering) {
      if((*xwin)->should_close) {
        break;
      }
      /* Wait on the input (also sync up to disable flickering) */
      if(input_ready(xwin)) {
        pressed_key = get_key(xwin);
      }
    }

    /* Clear the surface with black */
    cairo_set_source_rgb(context, 0.0, 0.0, 0.0);
    cairo_paint(context);

    std::queue <QTnode *> nodes;
    QTnode *t;

    nodes.push(tree);

    while (!nodes.empty()) {
      t = nodes.front();
      nodes.pop();

      if (!t->children.empty()) {
        for (i = 0; i < t->children.size(); i++) {
          nodes.push(t->children[i]);
        }
      } else {
        for (std::list <Particle>::iterator p = t->particles.begin(); p != t->particles.end(); p++) {

          v = f2_norm((*p).vel);
          if(v >= 0.4) {
            r = 1.0; b = 0.0;
          } else if(v < 0.5) {
            b = 1.0; r = 0.0;
          }
          cairo_set_source_rgba(context, (double)r, 0.0, (double)b, 1.0);
          cairo_rectangle(context, (*p).pos.x,
              (*p).pos.y, 2e-3, 2e-3);
          cairo_fill(context);
          cairo_set_source_rgba(context, (double)r, 0.0, (double)b, 0.2);
          cairo_rectangle(context, (*p).pos.x - 1e-3,
              (*p).pos.y - 1e-3, 4e-3, 4e-3);
          cairo_fill(context);
        }
      }
    }

    if(rendering) {
      /* Flush the X window */
      flush_input(xwin);
      update_screen(xwin);
    } else {
      mkdir(argv[2], S_IRWXU | S_IRWXG);
      sprintf(buf, "%s/%05d.png", argv[2], png++);
      printf("Making %s\n", buf);
      cairo_surface_write_to_png (surface, buf);
    }

    /* Get the new particles */
    timing(
        tree->calc_global_accel();
        tree->move_shit();
        );
  }
static cairo_test_status_t
test_cairo_xlib_surface_set_size (cairo_surface_t *surface)
{
    cairo_xlib_surface_set_size (surface, 5, 5);
    return CAIRO_TEST_SUCCESS;
}
Exemple #12
0
static int handle_event(XEvent e)
{
	KeySym k;
	int x, y, b;

	switch(e.type) {

		case ConfigureNotify: 
			win_w = e.xconfigure.width;
			win_h = e.xconfigure.height;
			cairo_xlib_surface_set_size(cs, win_w, win_h);
			redraw = 1;
			break;
			

		case Expose:
			if(e.xexpose.count < 1) redraw = 1;
			break;

		case KeyPress: 

			k = XLookupKeysym(&e.xkey, 0);

			if(k == XK_minus) opt_levels--;
			if(k == XK_equal) opt_levels++;
			if(k == XK_0) opt_levels = 4;
			if(k == XK_Escape) return 1;
			if(k == XK_q) return 1;
			if(k == XK_a) opt_apparent = !opt_apparent;
			if(k == XK_b) opt_bytes = !opt_bytes;
			if(k == XK_f) fuzz = (fuzz == 0) ? opt_fuzz : 0;
			if(k == XK_comma) if(opt_ring_gap > 0) opt_ring_gap --;
			if(k == XK_period) opt_ring_gap ++;
			if(k == XK_p) {
				palette = (palette + 1) % 4;
			}
			if(k == XK_BackSpace) {
				duc_dir *dir2 = duc_dir_openat(dir, "..");
				if(dir2) {
					duc_dir_close(dir);
					dir = dir2;
				}
			}

			redraw = 1;
			break;

		case ButtonPress: 

			x = e.xbutton.x;
			y = e.xbutton.y;
			b = e.xbutton.button;

			if(b == 1) {
				duc_dir *dir2 = duc_graph_find_spot(graph, dir, x, y, NULL);
				if(dir2) {
					duc_dir_close(dir);
					dir = dir2;
				}
			}
			if(b == 3) {
				duc_dir *dir2 = duc_dir_openat(dir, "..");
				if(dir2) {
					duc_dir_close(dir);
					dir = dir2;
				}
			}

			if(b == 4) opt_levels --;
			if(b == 5) opt_levels ++;

			redraw = 1;
			break;

		case MotionNotify: 

			tooltip_x = e.xmotion.x;
			tooltip_y = e.xmotion.y;
			tooltip_moved = 1;
			break;

		default:
			break;
	}

	return 0;
}
Exemple #13
0
void 
croActivateX11(CROddp *psa, cairo_surface_t* surface)
{
  static int initBack = 1;

    /* code for this function was heavily barrowed from the original X11 driver --RLB */
    XWindowAttributes       xwa;    /* Get window attributes        */
    CoordSpace              square_screen;

    Display *dpy = cairo_xlib_surface_get_display(surface);
    Window   win = cairo_xlib_surface_get_drawable(surface);

    if (initBack) {
       /* We want to set the window's background/border to the 
	* workstation's background color, but can't do it at window
	* creation time because the workstation color map is not 
	* available then. We do it once here, on the first activation.
	*/
        cairo_surface_flush(surface);
        XSetWindowBackground(dpy, win, psa->ctable[0]);
        XSetWindowBorder(dpy, win, psa->ctable[0]);
        initBack = 0;
    }

    XSync(dpy, False);
    
    /*
     *      Find out how big the window is; calculate the
     *      coordinate translation macros.
     */
    if (XGetWindowAttributes(dpy, win, &xwa) == 0) {
        ESprintf(ERR_WIN_ATTRIB, "XGetWindowAttributes(,,)");
        return;
    }

    square_screen = ComputeLargestSquare(
        (double) 0.0, (double) (xwa.height - 1),
	(double) (xwa.width - 1), (double) 0.0
    );

    psa->image_width = xwa.width; /*square_screen.urx; */
    psa->image_height = xwa.height; /*square_screen.lly;*/

    psa->dspace.llx = square_screen.llx;
    psa->dspace.urx = square_screen.urx;
    psa->dspace.lly = square_screen.ury;   /* note flip of y-axis */
    psa->dspace.ury = square_screen.lly;   /*         "           */

    psa->dspace.xspan = ((psa->dspace.urx) - (psa->dspace.llx));
    psa->dspace.yspan = ((psa->dspace.ury) - (psa->dspace.lly));

    if (psa->cro_clip.null == FALSE) {
      psa->cro_clip.llx = psa->dspace.llx;
      psa->cro_clip.lly = psa->dspace.lly;
      psa->cro_clip.urx = psa->dspace.urx;
      psa->cro_clip.ury = psa->dspace.ury;
    }

    cairo_xlib_surface_set_size(surface, xwa.width, xwa.height);

    return;
}