1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "evas_engine.h"
4 #include "Evas_Engine_XRender_X11.h"
6 static Evas_Hash *_xr_fg_pool = NULL;
9 _xre_font_surface_new(Ximage_Info *xinf, RGBA_Font_Glyph *fg)
14 XRenderPictureAttributes att;
15 XRenderPictFormat *fmt;
18 char buf[256], buf2[256];
20 data = fg->glyph_out->bitmap.buffer;
21 w = fg->glyph_out->bitmap.width;
22 h = fg->glyph_out->bitmap.rows;
23 j = fg->glyph_out->bitmap.pitch;
25 if ((w <= 0) || (h <= 0)) return NULL;
30 if ((fs->xinf->disp == xinf->disp) && (fs->xinf->root == xinf->root))
32 snprintf(buf, sizeof(buf), "@%p@/@%lx@", fs->xinf->disp, fs->xinf->root);
33 pool = evas_hash_find(_xr_fg_pool, buf);
36 snprintf(buf, sizeof(buf), "%p", fg);
37 fs = evas_hash_find(pool, buf);
42 fs = calloc(1, sizeof(XR_Font_Surface));
47 fs->xinf->references++;
51 snprintf(buf, sizeof(buf), "@%p@/@%lx@", fs->xinf->disp, fs->xinf->root);
52 pool = evas_hash_find(_xr_fg_pool, buf);
53 snprintf(buf2, sizeof(buf2), "%p", fg);
54 pool = evas_hash_add(pool, buf2, fs);
55 _xr_fg_pool = evas_hash_add(_xr_fg_pool, buf, pool);
57 /* FIXME: maybe use fmt4? */
59 fs->draw = XCreatePixmap(xinf->disp, xinf->root, w, h,fmt->depth);
61 att.component_alpha = 0;
63 fs->pic = XRenderCreatePicture(xinf->disp, fs->draw,fmt,
64 CPRepeat | CPDither | CPComponentAlpha, &att);
66 /* FIXME: handle if fmt->depth != 8 */
67 xim = _xr_image_new(fs->xinf, w, h,fmt->depth);
68 if ((fg->glyph_out->bitmap.num_grays == 256) &&
69 (fg->glyph_out->bitmap.pixel_mode == ft_pixel_mode_grays))
74 for (y = 0; y < h; y++)
77 p2 = ((DATA8 *)xim->data) + (xim->line_bytes * y);
78 for (x = 0; x < w; x++)
89 DATA8 *tmpbuf = NULL, *dp, *tp, bits;
91 const DATA8 bitrepl[2] = {0x0, 0xff};
98 for (y = 0; y < h; y++)
101 p2 = ((DATA8 *)xim->data) + (xim->line_bytes * y);
103 dp = data + (y * fg->glyph_out->bitmap.pitch);
104 for (bi = 0; bi < w; bi += 8)
107 if ((w - bi) < 8) end = w - bi;
109 for (bj = 0; bj < end; bj++)
111 *tp = bitrepl[(bits >> (7 - bj)) & 0x1];
116 for (x = 0; x < w; x++)
125 _xr_image_put(xim, fs->draw, 0, 0, w, h);
130 _xre_font_pool_cb(const Evas_Hash *hash, const char *key, void *data, void *fdata)
138 snprintf(buf, sizeof(buf), "@%p@/@%lx@", fs->xinf->disp, fs->xinf->root);
139 pool = evas_hash_del(pool, buf, fs);
140 hash = evas_hash_modify(hash, key, pool);
145 _xre_font_surface_free(XR_Font_Surface *fs)
148 evas_hash_foreach(_xr_fg_pool, _xre_font_pool_cb, fs);
149 XFreePixmap(fs->xinf->disp, fs->draw);
150 XRenderFreePicture(fs->xinf->disp, fs->pic);
151 _xr_image_info_free(fs->xinf);
156 _xre_font_surface_draw(Ximage_Info *xinf, RGBA_Image *surface, RGBA_Draw_Context *dc, RGBA_Font_Glyph *fg, int x, int y)
159 Xrender_Surface *target_surface;
164 if (!fs || !fs->xinf || !dc || !dc->col.col) return;
165 if (!surface || !surface->image.data) return;
166 target_surface = (Xrender_Surface *)(surface->image.data);
167 a = (dc->col.col >> 24) & 0xff;
168 r = (dc->col.col >> 16) & 0xff;
169 g = (dc->col.col >> 8 ) & 0xff;
170 b = (dc->col.col ) & 0xff;
171 if ((fs->xinf->mul_r != r) || (fs->xinf->mul_g != g) ||
172 (fs->xinf->mul_b != b) || (fs->xinf->mul_a != a))
178 _xr_render_surface_solid_rectangle_set(fs->xinf->mul, r, g, b, a, 0, 0, 1, 1);
180 rect.x = x; rect.y = y; rect.width = fs->w; rect.height = fs->h;
183 RECTS_CLIP_TO_RECT(rect.x, rect.y, rect.width, rect.height,
184 dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h);
186 XRenderSetPictureClipRectangles(target_surface->xinf->disp,
187 target_surface->pic, 0, 0, &rect, 1);
188 XRenderComposite(fs->xinf->disp, PictOpOver, fs->xinf->mul->pic,
189 fs->pic, target_surface->pic,
190 0, 0, 0, 0, x, y, fs->w, fs->h);