3 // means that A is not "uniform"
14 cairo_gpu_surface_t
*surface
;
15 cairo_gpu_texture_t
* texture
;
16 unsigned char owns_texture
;
17 unsigned char owns_surface
;
18 unsigned char unpremultiplied
: 1;
19 unsigned char gradient_discontinuous
: 1;
20 unsigned char has_coords
: 1;
21 cairo_surface_attributes_t attributes
;
22 unsigned gradient_denominator
;
23 unsigned gradient_width
;
24 } cairo_gpu_composite_operand_t
;
26 #define BLEND_COLOR_C_DIV_A 1
27 #define BLEND_COLOR_A 2
28 #define BLEND_COLOR_1_MINUS_A 3
34 cairo_gpu_blend_t blend
;
35 unsigned char blend_color
;
37 unsigned char component
;
38 unsigned char unpremultiplied
: 1;
39 unsigned char unpremultiplied_one_alpha
: 1;
40 unsigned char draw_geometry
: 1;
41 char operands
[MAX_OPERANDS
];
42 } cairo_gpu_composite_pass_t
;
48 cairo_gpu_surface_t
*dst
;
61 unsigned char blend_dst
;
62 unsigned char blend_src
;
64 unsigned char saturate
: 1;
65 unsigned char dst_alpha_mask
: 1;
66 unsigned char unpremultiplied
: 1;
72 cairo_gpu_composite_operand_t operands
[MAX_OPERANDS
];
73 char cur_operands
[MAX_OPERANDS
];
76 cairo_gpu_composite_pass_t passes
[4];
77 } cairo_gpu_composite_setup_t
;
81 #define CURRENT_THREAD() ((void*)1)
83 #define CURRENT_THREAD() ((void*)pthread_self())
84 #elif defined(HAVE_WINDOWS_H) || defined(_MSC_VER)
85 #define CURRENT_THREAD() ((void*)GetCurrentThreadId())
87 #error Implement CURRENT_THREAD for OS/2
88 #elif CAIRO_HAS_BEOS_SURFACE
89 #define CURRENT_THREAD() ((void*)find_thread(0))
91 #error Implement CURRENT_THREAD for your platform
95 _cairo_gpu_context__lock(cairo_gpu_context_t
* ctx
)
97 if(ctx
->owner_thread
!= CURRENT_THREAD())
99 CAIRO_MUTEX_LOCK(ctx
->mutex
);
100 ctx
->owner_thread
= CURRENT_THREAD();
106 _cairo_gpu_context__unlock(cairo_gpu_context_t
* ctx
)
108 if(!--ctx
->lock_depth
)
110 ctx
->owner_thread
= 0;
111 CAIRO_MUTEX_UNLOCK(ctx
->mutex
);
116 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
119 int_as_float(uint32_t val
)
131 /* Some loss of precision possible */
133 _cairo_fixed_to_float(cairo_fixed_t f
)
135 return ((float)f
) * (1.0f
/ (float)(1 << CAIRO_FIXED_FRAC_BITS
));
140 parse_boolean (const char *v
)
145 if (c0
== 't' || c0
== 'T' || c0
== 'y' || c0
== 'Y' || c0
== '1')
147 if (c0
== 'f' || c0
== 'F' || c0
== 'n' || c0
== 'N' || c0
== '0')
152 if (c1
== 'n' || c1
== 'N')
154 if (c1
== 'f' || c1
== 'F')
162 get_boolean_default (Display
*dpy
,
169 v
= XGetDefault (dpy
, "Xft", option
);
171 i
= parse_boolean (v
);
181 #if CAIRO_HAS_FT_FONT
182 int __attribute__((weak
)) FcNameConstant (unsigned char* string
, int *result
);
186 get_integer_default (Display
*dpy
,
192 v
= XGetDefault (dpy
, "Xft", option
);
194 #if CAIRO_HAS_FT_FONT
195 if (FcNameConstant ((unsigned char*) v
, value
))
199 *value
= strtol (v
, &e
, 0);
207 #ifndef FC_RGBA_UNKNOWN
208 #define FC_RGBA_UNKNOWN 0
209 #define FC_RGBA_RGB 1
210 #define FC_RGBA_BGR 2
211 #define FC_RGBA_VRGB 3
212 #define FC_RGBA_VBGR 4
213 #define FC_RGBA_NONE 5
216 /* Old versions of fontconfig didn't have these options */
218 #define FC_HINT_NONE 0
219 #define FC_HINT_SLIGHT 1
220 #define FC_HINT_MEDIUM 2
221 #define FC_HINT_FULL 3
224 /* Fontconfig version older than 2.6 didn't have these options */
225 #ifndef FC_LCD_FILTER
226 #define FC_LCD_FILTER "lcdfilter"
228 /* Some Ubuntu versions defined FC_LCD_FILTER without defining the following */
230 #define FC_LCD_NONE 0
231 #define FC_LCD_DEFAULT 1
232 #define FC_LCD_LIGHT 2
233 #define FC_LCD_LEGACY 3
237 _cairo_gpu_init_font_options_for_display (cairo_font_options_t
* font_options
, Display
* dpy
)
239 cairo_bool_t xft_hinting
;
240 cairo_bool_t xft_antialias
;
243 cairo_antialias_t antialias
;
244 cairo_subpixel_order_t subpixel_order
;
245 cairo_hint_style_t hint_style
;
247 if (!get_boolean_default (dpy
, "antialias", &xft_antialias
))
248 xft_antialias
= TRUE
;
250 if (!get_boolean_default (dpy
, "hinting", &xft_hinting
))
253 if (!get_integer_default (dpy
, "hintstyle", &xft_hintstyle
))
254 xft_hintstyle
= FC_HINT_FULL
;
256 if (!get_integer_default (dpy
, "rgba", &xft_rgba
))
258 int event_base
, error_base
, has_render
;
259 xft_rgba
= FC_RGBA_UNKNOWN
;
263 has_render
= (XRenderQueryExtension (dpy
, &event_base
, &error_base
) &&
264 (XRenderFindVisualFormat (dpy
, DefaultVisual (dpy
, DefaultScreen (dpy
))) != 0));
266 #if RENDER_MAJOR > 0 || RENDER_MINOR >= 6
269 int render_order
= XRenderQuerySubpixelOrder (dpy
, DefaultScreen(dpy
));
271 switch (render_order
)
274 case SubPixelUnknown
:
275 xft_rgba
= FC_RGBA_UNKNOWN
;
277 case SubPixelHorizontalRGB
:
278 xft_rgba
= FC_RGBA_RGB
;
280 case SubPixelHorizontalBGR
:
281 xft_rgba
= FC_RGBA_BGR
;
283 case SubPixelVerticalRGB
:
284 xft_rgba
= FC_RGBA_VRGB
;
286 case SubPixelVerticalBGR
:
287 xft_rgba
= FC_RGBA_VBGR
;
290 xft_rgba
= FC_RGBA_NONE
;
298 switch (xft_hintstyle
) {
300 hint_style
= CAIRO_HINT_STYLE_NONE
;
303 hint_style
= CAIRO_HINT_STYLE_SLIGHT
;
306 hint_style
= CAIRO_HINT_STYLE_MEDIUM
;
309 hint_style
= CAIRO_HINT_STYLE_FULL
;
312 hint_style
= CAIRO_HINT_STYLE_DEFAULT
;
315 hint_style
= CAIRO_HINT_STYLE_NONE
;
320 subpixel_order
= CAIRO_SUBPIXEL_ORDER_RGB
;
323 subpixel_order
= CAIRO_SUBPIXEL_ORDER_BGR
;
326 subpixel_order
= CAIRO_SUBPIXEL_ORDER_VRGB
;
329 subpixel_order
= CAIRO_SUBPIXEL_ORDER_VBGR
;
331 case FC_RGBA_UNKNOWN
:
334 subpixel_order
= CAIRO_SUBPIXEL_ORDER_DEFAULT
;
338 if (subpixel_order
== CAIRO_SUBPIXEL_ORDER_DEFAULT
)
339 antialias
= CAIRO_ANTIALIAS_GRAY
;
341 antialias
= CAIRO_ANTIALIAS_SUBPIXEL
;
343 antialias
= CAIRO_ANTIALIAS_NONE
;
346 cairo_font_options_set_hint_style (font_options
, hint_style
);
347 cairo_font_options_set_antialias (font_options
, antialias
);
348 cairo_font_options_set_subpixel_order (font_options
, subpixel_order
);
349 cairo_font_options_set_hint_metrics (font_options
, CAIRO_HINT_METRICS_ON
);
353 static inline cairo_gpu_space_tls_t
*
354 _cairo_gpu_space_alloc_tls(cairo_gpu_space_t
* space
);
356 static cairo_gpu_space_tls_t
*
357 _cairo_gpu_space_create_tls(cairo_gpu_space_t
* space
)
359 cairo_gpu_space_tls_t
* tls
= _cairo_gpu_space_alloc_tls(space
);
362 CAIRO_MUTEX_LOCK(space
->mutex
);
363 insert_after(&space
->tls_list
, &tls
->node
);
364 CAIRO_MUTEX_UNLOCK(space
->mutex
);
366 pthread_setspecific(space
->tls
, tls
);
370 static cairo_gpu_space_tls_t
*
371 _cairo_gpu_space_get_tls(cairo_gpu_space_t
* space
)
373 cairo_gpu_space_tls_t
* tls
= pthread_getspecific(space
->tls
);
377 return _cairo_gpu_space_create_tls(space
);
380 static inline cairo_gpu_context_t
*
381 _cairo_gpu_space_tls_lookup_context(cairo_gpu_space_tls_t
* gpu_tls
);
384 _cairo_gpu_context_bind(cairo_gpu_context_t
* ctx
);
386 static inline cairo_gpu_context_t
*
387 _cairo_gpu_space_bind(cairo_gpu_space_t
* space
)
389 cairo_gpu_context_t
* ctx
= _cairo_gpu_space_tls_lookup_context(_cairo_gpu_space_get_tls(space
));
390 _cairo_gpu_context_bind(ctx
);
395 _cairo_gpu_space_tls_destroy_contexts(cairo_gpu_space_tls_t
* gpu_tls
);
398 _cairo_gpu_space_tls_destroy(cairo_gpu_space_tls_t
* tls
)
401 cairo_gpu_context_t
* ctx
= _cairo_gpu_space_tls_lookup_context(tls
);
402 _cairo_gpu_context_bind(ctx
);
404 for(i
= 0; i
< MAX_OPERANDS
; ++i
)
407 for(j
= 0; j
< MAX_SMALL_WIDTH
; ++j
)
409 if(tls
->small_texture_pools
[i
].texture
[j
])
411 _cairo_gpu_texture_fini(ctx
, tls
->small_texture_pools
[i
].texture
[j
]);
412 free(tls
->small_texture_pools
[i
].texture
[j
]);
413 tls
->small_texture_pools
[i
].texture
[j
] = 0;
418 _cairo_gpu_space_tls_destroy_contexts(tls
);
424 _cairo_gpu_space_tls_dtor(void* abstract
)
426 cairo_gpu_space_tls_t
* tls
= abstract
;
430 CAIRO_MUTEX_LOCK(tls
->space
->mutex
);
431 unlink_node(&tls
->node
);
432 CAIRO_MUTEX_UNLOCK(tls
->space
->mutex
);
434 _cairo_gpu_space_tls_destroy(tls
);
438 #define _cairo_gpu_context_geometry(ctx, unused) _cairo_gpu_geometry_init((cairo_gpu_geometry_t*)alloca(sizeof(cairo_gpu_geometry_t)))
439 #define _cairo_gpu_geometry_put(ctx, geometry) _cairo_gpu_geometry_fini(ctx, geometry)
441 #define _cairo_gpu_context_geometry_long(ctx, unused) _cairo_gpu_geometry_init((cairo_gpu_geometry_t*)malloc(sizeof(cairo_gpu_geometry_t)))
442 #define _cairo_gpu_geometry_put_long(ctx, geometry) free(_cairo_gpu_geometry_fini(ctx, geometry))