Hi Roman,
On Wed, 2006-06-14 at 15:51 +0200, Roman Kennke wrote:
> Here comes a slight optimization for CairoGraphics2D efficiency wrt JNI
> calls. It adds special methods for 3 common graphics operations
> (drawLine, drawRect and fillRect), so that unnecessary JNI calls and
> object creations are avoided.
Nice, but unfortunately that doesn't work for ComponentGraphics which
manipulate the X state. In that case we need locking before drawing. We
used to get that for free since ComponentGraphics overrides draw(Shape)
and fill(Shape). So we need to override these three new public methods
so we do correct locking again.
2006-06-14 Mark Wielaard <[EMAIL PROTECTED]>
* gnu/java/awt/peer/gtk/ComponentGraphics.java (drawLine): Lock and
call super.
(drawRect): Likewise.
(fillRect): Likewise.
Unfortunately I am unable to say how much speed loss this gives because
without this patch the benchmark program kept crashing on me. With this
it runs reliable though.
We might want to think a bit more about how we do this locking since the
current way means we do three separate JNI calls and a little extra
bookkeeping in ComponentGraphics to account for the gdk lock not being
reentrant. It is probably much more efficient if we had some
needs_drawing_lock flag inside CairoGraphics itself that subclasses
could set if needed.
For now I committed this quick-fix though.
Cheers,
Mark
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.16
diff -u -r1.16 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java 13 Jun 2006 12:59:22 -0000 1.16
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java 14 Jun 2006 17:22:33 -0000
@@ -359,5 +359,44 @@
return super.drawImage(bimg, x, y, width, height, observer);
}
+ public void drawLine(int x1, int y1, int x2, int y2)
+ {
+ lock();
+ try
+ {
+ super.drawLine(x1, y1, x2, y2);
+ }
+ finally
+ {
+ unlock();
+ }
+ }
+
+ public void drawRect(int x, int y, int width, int height)
+ {
+ lock();
+ try
+ {
+ super.drawRect(x, y, width, height);
+ }
+ finally
+ {
+ unlock();
+ }
+ }
+
+ public void fillRect(int x, int y, int width, int height)
+ {
+ lock();
+ try
+ {
+ super.fillRect(x, y, width, height);
+ }
+ finally
+ {
+ unlock();
+ }
+ }
+
}