Summary: | Add getters for cairo_scaled_font_t | ||
---|---|---|---|
Product: | cairo | Reporter: | Behdad Esfahbod <freedesktop> |
Component: | general | Assignee: | Carl Worth <cworth> |
Status: | RESOLVED FIXED | QA Contact: | cairo-bugs mailing list <cairo-bugs> |
Severity: | enhancement | ||
Priority: | high | CC: | mlists |
Version: | 1.1.1 | ||
Hardware: | x86 (IA32) | ||
OS: | All | ||
Whiteboard: | |||
i915 platform: | i915 features: | ||
Attachments: | Add 4 getter functions |
Description
Behdad Esfahbod
2006-01-04 18:11:17 UTC
Created attachment 4253 [details] [review] Add 4 getter functions I don't much like the idea of having a function named cairo_set_scaled_font that would also muck with the CTM, nor would a function so-named likely make sense without setting the CTM. So let's not add that one. Instead, here's a patch to add the suggested 4 getter functions. That way any mucking with the CTM for the sake of using a particular scaled font will be explicit. Without actually looking at the code (my laptop died, using public terminals), shouldn't get_font_face reference the font before returning? Of course it should be documented whichever way. Looks good otherwise. The _get_ functions in cairo are non-referencing by convention. If you want a referencing version it is simple enough to get it with: font_face = cairo_font_face_reference (cairo_scaled_font_get_font_face (scaled_font)); -Carl Fine. I'm just thinking that ref(get()) is inherently not thread safe even when cairo becomes thread safe itself... When "cairo becomes thread-safe" ? As a library, cairo should be thread-safe already[*]. That is, it is safe to use cairo from multiple simultaneous threads. What we don't currently have is per-object locking that allows an individual cairo object to be safely used from multiple threads. I don't think that would even make sense to do, and there are no plans to do that at any point. [*] Modulo some win32 brain-damage that results in a broken library when doing static linking on win32. Well, it does make sense to use a cairo_scaled_font from multiple threads IMO. And having to _ref after _get makes room for dangling pointers in the application that cannot be fixed in cairo later... Anyway, please apply the patch then. Umm, and do not forget to add them to doc/public/cairo-sections.txt cairo_scaled_font_t is immutable, so there is no thread safety problem with ref-after-get. Another thread can't change these fields while this thread is using the font. Thread 1 get. Thread 2 destroy the last reference. Thread 1 ref the dangling pointer. Thread 1 can't access the scaled font without holding a reference to it. After thread 1 gets, it must copy or ref the getted resource before dropping the reference it holds to the scaled font. So, as long as the scaled font is immutable (and it is) then there is no issue... the scaled font will reference the resource at least until after the thread establishes a reference. Right, what I said doesn't exactly hold here. Basically you are saying that the obeject passed to the getter always has a reference to what the getter returns, so it cannot be destroyed before ref(). Guess that's the case in cairo. This is committed now to cairo 1.1.1 (in CVS): 2006-01-20 Carl Worth <cworth@cworth.org> * src/cairo.h: * src/cairo-scaled-font.c: (cairo_scaled_font_get_font_face), (cairo_scaled_font_get_font_matrix), (cairo_scaled_font_get_ctm), (cairo_scaled_font_get_font_options): Add getter functions for cairo_scaled_font_t. I added some documentation as well. -Carl |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.