2014-06-20 39 views
0

我在一個項目中需要使用Java和JavaFX的vtk。爲了給VTK提供正確的畫布,我想知道GetDrawingSurface()函數在下面的代碼中做了什麼。 awt是jawt庫中jawt.h中描述的JAWT對象。AWT.GetDrawingSurface是做什麼的?

這是爲了重寫一個Java類,爲C++提供正確的畫布。

extern "C" JNIEXPORT jint JNICALL 
Java_vtk_vtkPanel_RenderCreate(JNIEnv *env, jobject canvas, jobject id0) 
{ 
#if defined(WIN32_JAWT_LOCK_HACK) 
    int hash; 
    WJLH_HASH_FUNC(env, canvas, hash); 
    WJLH_lock_map[hash] = 0; 
#endif 

    JAWT awt; 
    JAWT_DrawingSurface* ds; 
    JAWT_DrawingSurfaceInfo* dsi; 
    jint lock; 

    // get the render window pointer 
    vtkRenderWindow *temp0; 
    temp0 = (vtkRenderWindow *)(vtkJavaGetPointerFromObject(env,id0)); 

    /* Get the AWT */ 
    awt.version = JAWT_VERSION_1_3; 
    if (JAWT_GetAWT(env, &awt) == JNI_FALSE) 
    { 
#ifndef VTK_JAVA_DEBUG 
    printf("AWT Not found\n"); 
#endif 
    return 1; 
    } 

    /* Get the drawing surface */ 
    ds = awt.GetDrawingSurface(env, canvas); 
    if (ds == NULL) 
    { 
#ifndef VTK_JAVA_DEBUG 
    printf("NULL drawing surface\n"); 
#endif 
    return 1; 
    } 

    /* Lock the drawing surface */ 
    lock = ds->Lock(ds); 
    if((lock & JAWT_LOCK_ERROR) != 0) 
    { 
#ifndef VTK_JAVA_DEBUG 
    printf("Error locking surface\n"); 
#endif 
    awt.FreeDrawingSurface(ds); 
    return 1; 
    } 

    /* Get the drawing surface info */ 
    dsi = ds->GetDrawingSurfaceInfo(ds); 
    if (dsi == NULL) 
    { 
    printf("Error getting surface info\n"); 
    ds->Unlock(ds); 
    awt.FreeDrawingSurface(ds); 
    return 1; 
    } 

// Here is the win32 drawing code 
#if defined(_WIN32) || defined(WIN32) 
    temp0->Finalize(); 
    JAWT_Win32DrawingSurfaceInfo* dsi_win; 
    dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; 
    temp0->SetWindowId((void *)dsi_win->hwnd); 
    temp0->SetDisplayId((void *)dsi_win->hdc); 
    // also set parent id to avoid border sizes being added 
    temp0->SetParentId((void *)dsi_win->hdc); 
// use mac code 
#elif defined(__APPLE__) 
    JAWT_MacOSXDrawingSurfaceInfo* dsi_mac; 
    dsi_mac = (JAWT_MacOSXDrawingSurfaceInfo*)dsi->platformInfo; 
    temp0->SetWindowId(dsi_mac->cocoaViewRef); 
// otherwise use X11 code 
#else 
    JAWT_X11DrawingSurfaceInfo* dsi_x11; 
    dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; 
    temp0->SetDisplayId((void *)dsi_x11->display); 
    temp0->SetWindowId((void *)dsi_x11->drawable); 
    temp0->SetParentId((void *)dsi_x11->display); 
#endif 

    /* Free the drawing surface info */ 
    ds->FreeDrawingSurfaceInfo(dsi); 

    /* Unlock the drawing surface */ 
    ds->Unlock(ds); 

    /* Free the drawing surface */ 
    awt.FreeDrawingSurface(ds); 

#if defined(WIN32_JAWT_LOCK_HACK) 
    if (WJLH_init_check == 0) 
    { 
    WJLH_init_check = 1; 
    } 
    WJLH_lock_map[hash] = 1; 
#endif 
    return 0; 
} 

回答

0

那麼,我自己發現它是返回窗口管理器在系統上使用的信息。

它使用java的getPeer函數來獲取正確的信息並將其提供給C代碼。所以不可能給我想要繪製的地方,因爲javadoc清楚地說明它是計算機專用的並且不能被重寫。

希望最後一個VTK版本(6.1.0)通過使用vtkJoGLPanelComponent給出了一個新的選項,讓JavaFX中的VTK有效。它應該是輕量級的,我想是因爲其他選項vtkJoGLCanvasComponent根本沒有工作。