Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JAWT on Java 1.3.1



Hello all,

I'd like to use JAWT in Java 1.3.1 on Jaguar to draw in a
java.awt.Canvas using C code that calls QuickDraw. (My hope is that
drawing will be fast enough in 1.4.1 that I won't need to resort to C
code, but in the meantime, I'd like my app to be fast on 1.3.1. I
don't want to have to convert my AWT app to Swing in order to get the
benefit of hwaccel, and I don't want to use JDirect, because I don't
want to pay the cost of crossing the Java/C bridge once per native
QuickDraw call.)

I'm wondering if anyone has done this successfully and would be
willing to share their code with me or look at my code and tell me
what I'm doing wrong.

I was able to get something sort of working by taking Sun's sample
Windows code in jawt.h, replacing "win32" with "mac", and then drawing
to the GrafPort that I get out of the JAWT_MacDrawingSurfaceInfo
struct that's declared in jawt_md.h.

In Java, I do:

public native void paint(Graphics g);

The meat of my C code that implements paint(), the part that goes
where the example code in jawt.h says "!!! DO PAINTING HERE !!!", is:

SetPort( dsi_mac->fQDPort ) ;
RGBColor c ;
c.red = Random() ; c.green = Random() ; c.blue = Random() ;
RGBForeColor( & c ) ;
Rect rt ;
SetRect( &rt , 0 , 0 , 400 , 400 ) ;
PaintRect( &rt ) ;

Then in Java I wrote a loop that calls paint() over and over again,
and does Toolkit.sync() after each call, just in case. So I should
see a rectangle that constantly changes color. It works -- sort of!
The rectangle only changes color as I move the mouse -- mouse stops,
painting stops. I know from adding debugging output that my native
code is still being called, it just doesn't paint anything onscreen
until I move the mouse.

My guess is that there's some QuickDraw boilerplate I need, that
calling SetPort at the top isn't enough, that I need to call something
more at the beginning, or call something at the end to tell it I'm
done. Hopefully someone out there has done this, or at least has some
suggestions...?

Stuff I've tried:

- Always calling paint() from the AWT Event Queue thread not the main
thread. No difference.
- Triggering painting indirectly by calling repaint() over and over,
instead of directly calling paint(). No difference.
- Saving and restoring the current port using GetPort and SetPort.
This doesn't help.
- Using SetGWorld instead of SetPort, like this:
SetGWorld( dsi_mac->fQDPort , & dsi_mac->fQDDevice ) ;
but this just makes my app crash when I call RGBForeColor().

==
Seth Tisue / email@hidden / (847) 467-2814
lead developer, NetLogo http://ccl.northwestern.edu/netlogo/
Center for Connected Learning and Computer-Based Modeling
School of Education and Social Policy / Department of Computer Science
Northwestern University
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.