1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "evas_engine.h"
4 #include "Evas_Engine_XRender_Xcb.h"
6 static Evas_Hash *_xr_fg_pool = NULL;
9 _xre_font_surface_new(Xcb_Image_Info *xcbinf, RGBA_Font_Glyph *fg)
16 Xcb_Image_Image *xcim;
21 data = fg->glyph_out->bitmap.buffer;
22 w = fg->glyph_out->bitmap.width;
23 h = fg->glyph_out->bitmap.rows;
24 j = fg->glyph_out->bitmap.pitch;
26 if ((w <= 0) || (h <= 0)) return NULL;
31 if ((fs->xcbinf->conn == xcbinf->conn) &&
32 (fs->xcbinf->root == xcbinf->root))
34 snprintf(buf, sizeof(buf), "@%p@/@%x@", fs->xcbinf->conn, fs->xcbinf->root);
35 pool = evas_hash_find(_xr_fg_pool, buf);
38 snprintf(buf, sizeof(buf), "%p", fg);
39 fs = evas_hash_find(pool, buf);
44 fs = calloc(1, sizeof(XR_Font_Surface));
49 fs->xcbinf->references++;
53 snprintf(buf, sizeof(buf), "@%p@/@%x@", fs->xcbinf->conn, fs->xcbinf->root);
54 pool = evas_hash_find(_xr_fg_pool, buf);
55 snprintf(buf2, sizeof(buf2), "%p", fg);
56 pool = evas_hash_add(pool, buf2, fs);
57 _xr_fg_pool = evas_hash_add(_xr_fg_pool, buf, pool);
59 fs->draw = xcb_generate_id(xcbinf->conn);
60 xcb_create_pixmap(xcbinf->conn, xcbinf->fmt8->depth, fs->draw, xcbinf->root, w, h);
62 mask = XCB_RENDER_CP_REPEAT | XCB_RENDER_CP_DITHER | XCB_RENDER_CP_COMPONENT_ALPHA;
66 fs->pic = xcb_generate_id(xcbinf->conn);
67 xcb_render_create_picture(xcbinf->conn, fs->pic, fs->draw, xcbinf->fmt8->id, mask, values);
69 xcim = _xr_image_new(fs->xcbinf, w, h, xcbinf->fmt8->depth);
70 if ((fg->glyph_out->bitmap.num_grays == 256) &&
71 (fg->glyph_out->bitmap.pixel_mode == ft_pixel_mode_grays))
76 for (y = 0; y < h; y++)
79 p2 = ((DATA8 *)xcim->data) + (xcim->line_bytes * y);
80 for (x = 0; x < w; x++)
91 DATA8 *tmpbuf = NULL, *dp, *tp, bits;
93 const DATA8 bitrepl[2] = {0x0, 0xff};
100 for (y = 0; y < h; y++)
103 p2 = ((DATA8 *)xcim->data) + (xcim->line_bytes * y);
105 dp = data + (y * fg->glyph_out->bitmap.pitch);
106 for (bi = 0; bi < w; bi += 8)
109 if ((w - bi) < 8) end = w - bi;
111 for (bj = 0; bj < end; bj++)
113 *tp = bitrepl[(bits >> (7 - bj)) & 0x1];
118 for (x = 0; x < w; x++)
127 _xr_image_put(xcim, fs->draw, 0, 0, w, h);
132 _xre_font_pool_cb(const Evas_Hash *hash, const char *key, void *data, void *fdata)
140 snprintf(buf, sizeof(buf), "@%p@/@%x@", fs->xcbinf->conn, fs->xcbinf->root);
141 pool = evas_hash_del(pool, buf, fs);
142 hash = evas_hash_modify(hash, key, pool);
147 _xre_font_surface_free(XR_Font_Surface *fs)
150 evas_hash_foreach(_xr_fg_pool, _xre_font_pool_cb, fs);
151 xcb_free_pixmap(fs->xcbinf->conn, fs->draw);
152 xcb_render_free_picture(fs->xcbinf->conn, fs->pic);
153 _xr_image_info_free(fs->xcbinf);
158 _xre_font_surface_draw(Xcb_Image_Info *xcbinf, RGBA_Image *surface, RGBA_Draw_Context *dc, RGBA_Font_Glyph *fg, int x, int y)
161 Xcb_Render_Surface *target_surface;
162 xcb_rectangle_t rect;
170 target_surface = (Xcb_Render_Surface *)(surface->image.data);
171 a = (dc->col.col >> 24) & 0xff;
172 r = (dc->col.col >> 16) & 0xff;
173 g = (dc->col.col >> 8 ) & 0xff;
174 b = (dc->col.col ) & 0xff;
175 if ((fs->xcbinf->mul_r != r) || (fs->xcbinf->mul_g != g) ||
176 (fs->xcbinf->mul_b != b) || (fs->xcbinf->mul_a != a))
178 fs->xcbinf->mul_r = r;
179 fs->xcbinf->mul_g = g;
180 fs->xcbinf->mul_b = b;
181 fs->xcbinf->mul_a = a;
182 _xr_render_surface_solid_rectangle_set(fs->xcbinf->mul, r, g, b, a, 0, 0, 1, 1);
188 if ((dc) && (dc->clip.use))
190 RECTS_CLIP_TO_RECT(rect.x, rect.y, rect.width, rect.height,
191 dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
193 xcb_render_set_picture_clip_rectangles(target_surface->xcbinf->conn,
194 target_surface->pic, 0, 0, 1, &rect);
195 xcb_render_composite(fs->xcbinf->conn, XCB_RENDER_PICT_OP_OVER,
196 fs->xcbinf->mul->pic,