Re: [cp-patches] RFC: Rotated characters problem

2006-10-23 Thread Francis Kung
Hi Tom,

> > It seems that when we cache the cairo_font_face_t in CairoGraphics2D
> > (well, the native peer), we lose the transform that was originally
> > applied to it.  In the patch, I've simply removed this caching
> > behaviour, and the jfig tests work.  Of course, that results in reduced
> > performance and isn't the ideal solution.
> 
> Can you quantify the reduction in performance?  If it's not major, then I 
> think 
> this patch should go in and we can try different optimization strategies 
> later.

I haven't done anything quantitative, but without caching we would be
creating and disposing a new cairo_font_face_t on each and every
drawGlyphVector call.

Now that I look at it again, I wonder why we can't just create the
cairo_font_face_t when we setFont(), and keep it around until the font
is changed.  I'll give that a try first... if it doesn't work, I'll try
to quantify the performance of this patch and commit if it's not too
bad.

> > I tried playing around with cairo_get/set_font_matrix as well, caching
> > and restoring it, but that didn't seem to have any effect; I'm not sure
> > what else could be reset and lost in the caching process which would
> > affect the transform...
> 
> Have you tried debugging cairo itself to see how it manages the transforms 
> that 
> CairoGraphics2D passes to it?

No, I didn't look that far... I wasn't too sure whether this was
relevant, since we never use cairo_get/set_font_matrix anywhere else in
our code, so I gave up after a quick test.

Francis





Re: [cp-patches] RFC: Rotated characters problem

2006-10-23 Thread Thomas Fitzsimmons

Hi,

Francis Kung wrote:

Hi,

In response to PR 27947
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27947) I've attached a
possible patch.  I'm not entirely convinced that it's the best solution,
though, so I'm posting it in the hope that someone may be able to
improve on it =)

It seems that when we cache the cairo_font_face_t in CairoGraphics2D
(well, the native peer), we lose the transform that was originally
applied to it.  In the patch, I've simply removed this caching
behaviour, and the jfig tests work.  Of course, that results in reduced
performance and isn't the ideal solution.


Can you quantify the reduction in performance?  If it's not major, then I think 
this patch should go in and we can try different optimization strategies later.




I tried playing around with cairo_get/set_font_matrix as well, caching
and restoring it, but that didn't seem to have any effect; I'm not sure
what else could be reset and lost in the caching process which would
affect the transform...


Have you tried debugging cairo itself to see how it manages the transforms that 
CairoGraphics2D passes to it?


Tom



[cp-patches] RFC: Rotated characters problem

2006-10-20 Thread Francis Kung
Hi,

In response to PR 27947
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27947) I've attached a
possible patch.  I'm not entirely convinced that it's the best solution,
though, so I'm posting it in the hope that someone may be able to
improve on it =)

It seems that when we cache the cairo_font_face_t in CairoGraphics2D
(well, the native peer), we lose the transform that was originally
applied to it.  In the patch, I've simply removed this caching
behaviour, and the jfig tests work.  Of course, that results in reduced
performance and isn't the ideal solution.

I tried playing around with cairo_get/set_font_matrix as well, caching
and restoring it, but that didn't seem to have any effect; I'm not sure
what else could be reset and lost in the caching process which would
affect the transform...

Does anyone with more experience in this area have any ideas?

Thanks,
Francis

Index: include/gnu_java_awt_peer_gtk_GdkFontPeer.h
===
RCS file: /cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_GdkFontPeer.h,v
retrieving revision 1.9
diff -u -r1.9 gnu_java_awt_peer_gtk_GdkFontPeer.h
--- include/gnu_java_awt_peer_gtk_GdkFontPeer.h	7 Jun 2006 13:54:32 -	1.9
+++ include/gnu_java_awt_peer_gtk_GdkFontPeer.h	20 Oct 2006 20:33:17 -
@@ -16,7 +16,6 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_setFont (JNIEnv *env, jobject, jstring, jint, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics (JNIEnv *env, jobject, jdoubleArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTextMetrics (JNIEnv *env, jobject, jstring, jdoubleArray);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_releasePeerGraphicsResource (JNIEnv *env, jobject);
 JNIEXPORT jbyteArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTrueTypeTable (JNIEnv *env, jobject, jbyte, jbyte, jbyte, jbyte);
 
 #ifdef __cplusplus
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
===
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c,v
retrieving revision 1.17
diff -u -r1.17 gnu_java_awt_peer_gtk_CairoGraphics2D.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	14 Sep 2006 20:43:18 -	1.17
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	20 Oct 2006 20:33:17 -
@@ -760,31 +760,19 @@
   g_assert(cr != NULL);
   g_assert(pfont != NULL);
 
-  if (pfont->graphics_resource == NULL)
-{
-  face = pango_fc_font_lock_face( (PangoFcFont *)pfont->font );
-  g_assert (face != NULL);
-
-  ft = cairo_ft_font_face_create_for_ft_face (face, 0);
-  g_assert (ft != NULL);
-
-  cairo_set_font_face (cr, ft);
-  /*  cairo_font_face_destroy (ft);*/
-  cairo_set_font_size (cr,
-   (pango_font_description_get_size (pfont->desc) /
-(double)PANGO_SCALE));
-  ft = cairo_get_font_face (cr);
-  pango_fc_font_unlock_face( (PangoFcFont *)pfont->font );
-  pfont->graphics_resource = ft;
-}
-  else
-{
-  ft = (cairo_font_face_t *) pfont->graphics_resource;
-  cairo_set_font_face (cr, ft);
-  cairo_set_font_size (cr,
-   (pango_font_description_get_size (pfont->desc) /
-(double)PANGO_SCALE));
-}
+  face = pango_fc_font_lock_face( (PangoFcFont *)pfont->font );
+  g_assert (face != NULL);
+
+  ft = cairo_ft_font_face_create_for_ft_face (face, 0);
+  g_assert (ft != NULL);
+
+  cairo_set_font_face (cr, ft);
+  cairo_set_font_size (cr,
+   (pango_font_description_get_size (pfont->desc) /
+(double)PANGO_SCALE));
+  
+  cairo_font_face_destroy (ft);
+  pango_fc_font_unlock_face( (PangoFcFont *)pfont->font );
 }
 
 static void 
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
===
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c,v
retrieving revision 1.20
diff -u -r1.20 gnu_java_awt_peer_gtk_GdkFontPeer.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	8 Jun 2006 11:02:10 -	1.20
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	20 Oct 2006 20:33:17 -
@@ -108,26 +108,6 @@
 
 
 JNIEXPORT void JNICALL
-Java_gnu_java_awt_peer_gtk_GdkFontPeer_releasePeerGraphicsResource
-   (JNIEnv *env, jobject java_font)
-{
-  struct peerfont *pfont = NULL;
-
-  gdk_threads_enter();
-
-  pfont = (struct peerfont *) NSA_GET_FONT_PTR (env, java_font);
-  g_assert (pfont != NULL);
-  if (pfont->graphics_resource != NULL)
-{
-  cairo_font_face_destroy ((cairo_font_face_t *) pfont->graphics_resource);
-  pfont->graphics_resource = NULL;
-}
-
-  gdk_threads_leave();
-}
-
-
-JNIEXPORT void JNICALL
 Java_gnu_java_awt_peer_gtk_Gd