首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWT.GetDrawingSurface是做什么的?

AWT.GetDrawingSurface是做什么的?
EN

Stack Overflow用户
提问于 2014-06-20 10:56:00
回答 1查看 514关注 0票数 0

我在一个项目中需要使用vtk与Java和JavaFX。为了给VTK正确的画布,它可以在哪里绘制,我想知道函数GetDrawingSurface()在下面的代码中做了什么。awt是jawt.h中从JAWT库中描述的jawt对象。

它是为了重写一个Java类来给C++提供正确的画布。

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-11 14:00:12

嗯,我自己发现它正在返回系统上窗口管理器使用的信息。

它使用java的getPeer函数获取正确的信息,并将其交给C代码。因此,不可能给出我想要绘制的位置,因为javadoc清楚地表明它是特定于计算机的,不能重写。

希望上一个VTK版本(6.1.0)提供了一个新的选项,通过使用JavaFX在vtkJoGLPanelComponent中使用VTK。它应该是轻量级的,我猜是因为另一种选择,vtkJoGLCanvasComponent根本不起作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24325676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档