简体   繁体   English

AWT.GetDrawingSurface做什么?

[英]What does AWT.GetDrawingSurface do?

I'm on a project where I need to use vtk with Java and JavaFX. 我在一个需要将vtk与Java和JavaFX结合使用的项目中。 And to give VTK the correct canvas where it can draw, I was wondering what does the function GetDrawingSurface() do in the code below. 为了给VTK提供可以绘制的正确画布,我想知道函数GetDrawingSurface()在下面的代码中做了什么。 awt is a JAWT object described in jawt.h from the jawt library. awt是一个来自jawt库的jawt.h中描述的JAWT对象。

It's in order to rewrite a Java class to give the C++ the correct canvas. 这是为了重写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;
}

Well, I figured out by myself that it was returning information on the window manager use on the system. 好吧,我自己弄清楚它正在返回有关系统上的窗口管理器使用的信息。

It uses the getPeer function of java to get the right information and give it to the C code. 它使用java的getPeer函数来获取正确的信息并将其提供给C代码。 So it is not possible to give where i want to draw because the javadoc tells clearly that it is computer specific and could not be rewritten. 因此,不可能给出我想绘制的位置,因为javadoc清楚地表明它是计算机特定的,无法重写。

Hopefully, the last VTK version (6.1.0) gives a new option to have VTK in JavaFX by using vtkJoGLPanelComponent . 希望最新的VTK版本(6.1.0)通过使用vtkJoGLPanelComponent提供了一个新选项,使JavaFX中具有VTK。 It's supposed to be lightweight I guess because the other option, vtkJoGLCanvasComponent is not working at all. 我猜这应该是轻量级的,因为另一个选项vtkJoGLCanvasComponent根本不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM