Hi Michele,
I didn't work much with JAWT, so I'm not sure what's going wrong
with it, unfortunately.
But some of the things you'll need to make sure:
- the awt and 2d is initialized
- you'll need a realized canvas in order to work with jawt
So your library should accept a realized (that is, added to a
realized/visible hierarchy) Canvas so that you can
get access to the ddraw surface.
So, in your case you'd have something like
public class VideoUtils {
static {
System.loadLibrary("videoutils");
}
public static native void waitForVSync(Canvas c);
}
You might want to make sure that the Canvas is realized/visible in
this method before going to native.
Then on the native level:
JNIEXPORT void JNICALL Java_VideoUtils_waitForVSync
(JNIEnv* env, jclass utils, jobject canvas)
{
JAWT awt;
awt.version = JAWT_VERSION_1_4;
if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
printf("AWT Not found\n");
return;
}
JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, canvas);
// wait for the vertical retrace
}
I don't see why this won't work.
You might want to check out www.javagaming.org, I believe someone
there was doing something similar.
Also, the good news is that we're considering adding vsync
functionality for mustang:
6378181: 2D needs a way to synchronize onscreen rendering with vertical
retrace
We'll provide the necessary API in the BufferStrategy class.
Your library will still be useful for pre-6.0 jdks, though.
Thanks,
Dmitri
On Fri, Jan 27, 2006 at 10:09:29AM +0100, Michele Puccini wrote:
> Thanks Dmitri,
>
> taking a look of some other jawt-dependent implementations (JOGL,LWJGL) I've
> discovered that JAWT must be pre-loaded before any other JAWT-dependent DLL
> (at least on Win32).
>
> Infact the pre-loding solved all the "unsatisfied link error: jawt.ll not
> found..." problems I had in all my jawt-dependent dlls.
>
> About JAWT initialization I think I'm doing quite well with a little useful
> class I've found somewhere. Find it attached. Usage is strightforward:
>
> /*
> * Class: it_classx_video_VideoUtils
> * Method: createDDraw
> * Signature: (Ljava/awt/Component;)I
> */
> JNIEXPORT jint JNICALL Java_it_classx_video_VideoUtils_createDDraw(JNIEnv *
> env , jobject obj, jobject canvas)
> {
> __int64 ddraw = 0;
> JAWT_Info info(env, canvas);
> HWND hWnd = (HWND)info.getHWND();
> if (hWnd != NULL)
> {
> ...
> }
> }
>
>
> But some problems still remain:
>
> - If the VideoUtils class extends Canvas
> - JAWT is not loaded. -> CRASH
> - JAWT is loaded in the static{} initializer. -> WORKS
> - JAWT is loaded in the class constructor. -> WORKS
>
> - If the VideoUtils class does not extend Canvas
> - JAWT is not loaded. -> CRASH
> - JAWT is loaded in the static{} initializer. -> "JAWT.DLL not loaded"
> - JAWT is loaded in the class constructor. -> WORKS
>
>
> Of course VideoUtils must not extend a Canvas as it's not a Canvas in my
> design.
>
>
> Thanks,
>
> Mik
> ============================================================================
> >ClassX Development Italy Via Francesca, 368/I I-56030 S.M. a Monte (PI) <
> >Tel.(+39)-0587-705153 Fax.(+39)-0587-705153 WEB: http://www.classx.it <
> ============================================================================
>
>
>
>
>
>
> From: "Dmitri Trembovetski" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, January 26, 2006 10:17 PM
> Subject: Re: [JAVA2D] FullScreen, BufferStrategy, Vertical Blanking
>
>
> > Hi Michele,
> >
> > sorry for late response.
> >
> >On Mon, Jan 23, 2006 at 01:04:47PM +0100, Michele Puccini wrote:
> >> Dmitri,
> >>
> >> I've managed to create a simple class (VideoUtils) that implements
> >> Vertical
> >> Blanking synchronization with multimonitor support through directdraw
> >> calls
> >> in a separate jni dll. Note: the jawt.dll is delayloaded from my jni
> >> implementation.
> >
> > Wow, nice.
> >
> >> Anyway I have a strange runtime problem with JAWT:
> >>
> >> - if the class extends java.awt.Canvas then it can load and initialize
> >> JAWT
> >> and everything works.
> >>
> >> - if it doesn't, JAWT will not be loaded I get an error
> >> "java.lang.UnsatisfiedLinkError:
> >> C:\Programmi\Java\jdk1.5.0_06\jre\bin\jawt.dll: Can't find dependent
> >> libraries" at <clinit>.
> >
> > Well, it's hard to tell exactly why this happens w/o seeing the
> > code.
> >
> >> The class is an helper class and should not be Canvas.
> >
> > I'm not sure why do you need to load jawt.dll yourself.
> >
> > Can't you use something like this in your native lib:
> > JAWT awt;
> > awt.version = JAWT_VERSION_1_4;
> > if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
> > // error
> > }
> >
> > Then later:
> > JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, canvas);
> > // do stuff with the drawing surface
> >
> > where 'canvas' is the canvas that you need to pass from java
> > level. You'll need to get one (either create it yourself or traverse
> > the hierarchy to find the one already there).
> >
> > And in your java class just load your native lib.
> >
> > Thanks,
> > Dmitri
> >
> >>
> >> Thanks,
> >>
> >> Mik
> >>
> >============================================================================
> >> >ClassX Development Italy Via Francesca, 368/I I-56030 S.M. a Monte
> >> >(PI) <
> >> >Tel.(+39)-0587-705153 Fax.(+39)-0587-705153 WEB: http://www.classx.it
> >> ><
> >>
> >============================================================================
> >>
> >>
> >>
> >> From: "Dmitri Trembovetski" <[EMAIL PROTECTED]>
> >> To: <[EMAIL PROTECTED]>
> >> Sent: Wednesday, January 18, 2006 5:52 PM
> >> Subject: Re: [JAVA2D] FullScreen, BufferStrategy, Vertical Blanking
> >>
> >>
> >>
> >> > I realize that. What I'm saying is that since a Vsynched windowed
> >> > buffer strategy would be implemented in the same way the
> >> > FlipBufferStrategy is, there won't be a problem with the cpu usage.
> >>
> >>
> >
> >===========================================================================
> >To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> >body
> >of the message "signoff JAVA2D-INTEREST". For general help, send email to
> >[EMAIL PROTECTED] and include in the body of the message "help".
> >
> #ifndef JAWT_INFO_H
> #define JAWT_INFO_H
>
> // Helper class for accessing JAWT Information.
> class JAWT_Info
> {
> private:
> JAWT awt;
> JAWT_DrawingSurface* ds;
> JAWT_DrawingSurfaceInfo* dsi;
> JAWT_Win32DrawingSurfaceInfo* dsi_win;
>
> public:
> JAWT_Info(JNIEnv *env, jobject panel)
> {
> jboolean result;
> jint lock;
>
> // Get the AWT
> awt.version = JAWT_VERSION_1_4;
> result = JAWT_GetAWT(env, &awt);
> assert(result != JNI_FALSE);
> // Get the drawing surface
> ds = awt.GetDrawingSurface(env, panel);
> if(ds == NULL)
> return;
> // Lock the drawing surface
> lock = ds->Lock(ds);
> assert((lock & JAWT_LOCK_ERROR) == 0);
>
> // Get the drawing surface info
> dsi = ds->GetDrawingSurfaceInfo(ds);
>
> // Get the platform-specific drawing info
> dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
> }
>
> HWND getHWND()
> {
> if(dsi_win == NULL)
> return NULL;
> return dsi_win->hwnd;
> }
>
> HDC getHDC()
> {
> if(dsi_win == NULL)
> return NULL;
> return dsi_win->hdc;
> }
>
> virtual ~JAWT_Info()
> {
> if(ds != NULL)
> {
> // Free the drawing surface info
> ds->FreeDrawingSurfaceInfo(dsi);
> // Unlock the drawing surface
> ds->Unlock(ds);
> // Free the drawing surface
> awt.FreeDrawingSurface(ds);
> }
> }
> };
>
> #endif
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".