📄 cairo-xlib-surface.c
字号:
surface->screen_info = screen_info; surface->gc = NULL; surface->drawable = drawable; surface->screen = screen; surface->owns_pixmap = FALSE; surface->use_pixmap = 0; surface->width = width; surface->height = height; surface->buggy_repeat = FALSE; if (strstr (ServerVendor (dpy), "X.Org") != NULL) { if (VendorRelease (dpy) <= 60802000) surface->buggy_repeat = TRUE; } else if (strstr (ServerVendor (dpy), "XFree86") != NULL) { if (VendorRelease (dpy) <= 40500000) surface->buggy_repeat = TRUE; } else if (strstr (ServerVendor (dpy), "Sun Microsystems, Inc.") != NULL) { if (VendorRelease (dpy) <= 60800000) surface->buggy_repeat = TRUE; } surface->dst_picture = None; surface->src_picture = None; surface->visual = visual; surface->xrender_format = xrender_format; surface->depth = depth; surface->have_clip_rects = FALSE; surface->clip_rects = NULL; surface->num_clip_rects = 0; return (cairo_surface_t *) surface;}static Screen *_cairo_xlib_screen_from_visual (Display *dpy, Visual *visual){ int s; int d; int v; Screen *screen; Depth *depth; for (s = 0; s < ScreenCount (dpy); s++) { screen = ScreenOfDisplay (dpy, s); if (visual == DefaultVisualOfScreen (screen)) return screen; for (d = 0; d < screen->ndepths; d++) { depth = &screen->depths[d]; for (v = 0; v < depth->nvisuals; v++) if (visual == &depth->visuals[v]) return screen; } } return NULL;}/** * cairo_xlib_surface_create: * @dpy: an X Display * @drawable: an X Drawable, (a Pixmap or a Window) * @visual: the visual to use for drawing to @drawable. The depth * of the visual must match the depth of the drawable. * Currently, only TrueColor visuals are fully supported. * @width: the current width of @drawable. * @height: the current height of @drawable. * * Creates an Xlib surface that draws to the given drawable. * The way that colors are represented in the drawable is specified * by the provided visual. * * NOTE: If @drawable is a Window, then the function * cairo_xlib_surface_set_size must be called whenever the size of the * window changes. * * Return value: the newly created surface **/cairo_surface_t *cairo_xlib_surface_create (Display *dpy, Drawable drawable, Visual *visual, int width, int height){ Screen *screen = _cairo_xlib_screen_from_visual (dpy, visual); if (screen == NULL) { _cairo_error (CAIRO_STATUS_INVALID_VISUAL); return (cairo_surface_t*) &_cairo_surface_nil; } return _cairo_xlib_surface_create_internal (dpy, drawable, screen, visual, NULL, width, height, 0);}/** * cairo_xlib_surface_create_for_bitmap: * @dpy: an X Display * @bitmap: an X Drawable, (a depth-1 Pixmap) * @screen: the X Screen associated with @bitmap * @width: the current width of @bitmap. * @height: the current height of @bitmap. * * Creates an Xlib surface that draws to the given bitmap. * This will be drawn to as a CAIRO_FORMAT_A1 object. * * Return value: the newly created surface **/cairo_surface_t *cairo_xlib_surface_create_for_bitmap (Display *dpy, Pixmap bitmap, Screen *screen, int width, int height){ return _cairo_xlib_surface_create_internal (dpy, bitmap, screen, NULL, NULL, width, height, 1);}/** * cairo_xlib_surface_create_with_xrender_format: * @dpy: an X Display * @drawable: an X Drawable, (a Pixmap or a Window) * @screen: the X Screen associated with @drawable * @format: the picture format to use for drawing to @drawable. The depth * of @format must match the depth of the drawable. * @width: the current width of @drawable. * @height: the current height of @drawable. * * Creates an Xlib surface that draws to the given drawable. * The way that colors are represented in the drawable is specified * by the provided picture format. * * NOTE: If @drawable is a Window, then the function * cairo_xlib_surface_set_size must be called whenever the size of the * window changes. * * Return value: the newly created surface **/cairo_surface_t *cairo_xlib_surface_create_with_xrender_format (Display *dpy, Drawable drawable, Screen *screen, XRenderPictFormat *format, int width, int height){ return _cairo_xlib_surface_create_internal (dpy, drawable, screen, NULL, format, width, height, 0);}/** * cairo_xlib_surface_set_size: * @surface: a #cairo_surface_t for the XLib backend * @width: the new width of the surface * @height: the new height of the surface * * Informs cairo of the new size of the X Drawable underlying the * surface. For a surface created for a Window (rather than a Pixmap), * this function must be called each time the size of the window * changes. (For a subwindow, you are normally resizing the window * yourself, but for a toplevel window, it is necessary to listen for * ConfigureNotify events.) * * A Pixmap can never change size, so it is never necessary to call * this function on a surface created for a Pixmap. **/voidcairo_xlib_surface_set_size (cairo_surface_t *abstract_surface, int width, int height){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_surface_set_error (abstract_surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return; } surface->width = width; surface->height = height;}/** * cairo_xlib_surface_set_drawable: * @surface: a #cairo_surface_t for the XLib backend * @drawable: the new drawable for the surface * @width: the width of the new drawable * @height: the height of the new drawable * * Informs cairo of a new X Drawable underlying the * surface. The drawable must match the display, screen * and format of the existing drawable or the application * will get X protocol errors and will probably terminate. * No checks are done by this function to ensure this * compatibility. **/voidcairo_xlib_surface_set_drawable (cairo_surface_t *abstract_surface, Drawable drawable, int width, int height){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *)abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_surface_set_error (abstract_surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return; } /* XXX: and what about this case? */ if (surface->owns_pixmap) return; if (surface->drawable != drawable) { if (surface->dst_picture) XRenderFreePicture (surface->dpy, surface->dst_picture); if (surface->src_picture) XRenderFreePicture (surface->dpy, surface->src_picture); surface->dst_picture = None; surface->src_picture = None; surface->drawable = drawable; } surface->width = width; surface->height = height;}/** * cairo_xlib_surface_get_display: * @surface: a #cairo_xlib_surface_t * * Get the X Display for the underlying X Drawable. * * Return value: the display. * * Since: 1.2 **/Display *cairo_xlib_surface_get_display (cairo_surface_t *abstract_surface){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return NULL; } return surface->dpy;}/** * cairo_xlib_surface_get_drawable: * @surface: a #cairo_xlib_surface_t * * Get the underlying X Drawable used for the surface. * * Return value: the drawable. * * Since: 1.2 **/Drawablecairo_xlib_surface_get_drawable (cairo_surface_t *abstract_surface){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return 0; } return surface->drawable;}/** * cairo_xlib_surface_get_screen: * @surface: a #cairo_xlib_surface_t * * Get the X Screen for the underlying X Drawable. * * Return value: the screen. * * Since: 1.2 **/Screen *cairo_xlib_surface_get_screen (cairo_surface_t *abstract_surface){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return NULL; } return surface->screen;}/** * cairo_xlib_surface_get_visual: * @surface: a #cairo_xlib_surface_t * * Get the X Visual used for underlying X Drawable. * * Return value: the visual. * * Since: 1.2 **/Visual *cairo_xlib_surface_get_visual (cairo_surface_t *abstract_surface){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return NULL; } return surface->visual;}/** * cairo_xlib_surface_get_depth: * @surface: a #cairo_xlib_surface_t * * Get the number of bits used to represent each pixel value. * * Return value: the depth of the surface in bits. * * Since: 1.2 **/intcairo_xlib_surface_get_depth (cairo_surface_t *abstract_surface){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return 0; } return surface->depth;}/** * cairo_xlib_surface_get_width: * @surface: a #cairo_xlib_surface_t * * Get the width of the X Drawable underlying the surface in pixels. * * Return value: the width of the surface in pixels. * * Since: 1.2 **/intcairo_xlib_surface_get_width (cairo_surface_t *abstract_surface){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return -1; } return surface->width;}/** * cairo_xlib_surface_get_height: * @surface: a #cairo_xlib_surface_t * * Get the height of the X Drawable underlying the surface in pixels. * * Return value: the height of the surface in pixels. * * Since: 1.2 **/intcairo_xlib_surface_get_height (cairo_surface_t *abstract_surface){ cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface; if (! _cairo_surface_is_xlib (abstract_surface)) { _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH); return -1; } return surface->height;}typedef struct _cairo_xlib_surface_font_private { Display *dpy; GlyphSet glyphset; cairo_format_t format; XRenderPictFormat *xrender_format;} cairo_xlib_surface_font_private_t;static cairo_status_t_cairo_xlib_surface_font_init (Display *dpy, cairo_scaled_font_t *scaled_font, cairo_format_t format){ cairo_xlib_surface_font_private_t *font_private; font_private = malloc (sizeof (cairo_xlib_surface_font_private_t)); if (!font_private) return CAIRO_STATUS_NO_MEMORY; font_private->dpy = dpy; font_private->format = format; font_private->xrender_format = _CAIRO_FORMAT_TO_XRENDER_FORMAT(dpy, format); font_private->glyphset = XRenderCreateGlyphSet (dpy, font_private->xrender_format); scaled_font->surface_private = font_private; scaled_font->surface_backend = &cairo_xlib_surface_backend; return CAIRO_STATUS_SUCCESS;}static void_cairo_xlib_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font){ cairo_xlib_surface_font_private_t *font_private = scaled_font->surface_private; if (font_private) { XRenderFreeGlyphSet (font_private->dpy, font_private->glyphset); free (font_private); }}static void_cairo_xlib_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph, cairo_scaled_font_t *scaled_font){ cairo_xlib_surface_font_private_t *font_private = scaled_font->surface_private; if (font_private != NULL && scaled_glyph->surface_private != NULL) { unsigned long glyph_index = _cairo_scaled_glyph_index(scaled_glyph); XRenderFreeGlyphs (font_private->dpy, font_private->glyphset, &glyph_index, 1); }}static cairo_bool_t_native_byte_order_lsb (void){ int x = 1; return *((char *) &x) == 1;}static cairo_status_t_cairo_xlib_surface_add_glyph (Display *dpy, cairo_scaled_font_t *scaled_font, cairo_scaled_glyph_t *scaled_glyph){ XGlyphInfo glyph_inf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -