Esempio n. 1
0
  private void initDraw() {
    if (TOOLKIT == AWT) {
      awtCanvas.setVisible(true);
      // Force the realization
      awtCanvas.display();
      if (awtCanvas.getDelegatedDrawable().isRealized()) {
        // Request the focus here as it cannot work when the window is not visible
        awtCanvas.requestFocus();
        context = awtCanvas.getContext();
      }
    } else if (TOOLKIT == NEWT) {
      newtCanvas.setVisible(true);
      // Force the realization
      newtWindow.display();
      if (newtWindow.isRealized()) {
        // Request the focus here as it cannot work when the window is not visible
        newtCanvas.requestFocus();
        context = newtWindow.getContext();
      }
    }

    drawRunnable = new DrawRunnable();

    doneInit = true;
  }
  static {
    long lastTime = Calendar.getInstance().getTimeInMillis();

    Debug.DEBUG("SwingScilabCanvasImpl", "=======================================");
    String OS_NAME = System.getProperty("os.name");
    Debug.DEBUG("SwingScilabCanvasImpl", "os.name=" + OS_NAME);
    String OS_ARCH = System.getProperty("os.arch");
    Debug.DEBUG("SwingScilabCanvasImpl", "os.arch=" + OS_ARCH);
    Debug.DEBUG("SwingScilabCanvasImpl", "=======================================");

    /*
     * Bug #7526: moved out of the try/catch block since it contains
     * no OpenGL calls.
     */
    if (OS_NAME.contains("Windows") && OS_ARCH.equals("amd64")) {
      // bug 3919 : JOGL x64 doesn't like x64 remote desktop on Windows
      // @TODO : bug report to JOGL
      String REMOTEDESKTOP = System.getenv("SCILAB_MSTS_SESSION");
      if (REMOTEDESKTOP != null) {
        if (REMOTEDESKTOP.equals("OK")) {
          noGLJPanel = true;
        }
      }

      if (noGLJPanel) {
        /** Inform the users */
        InterpreterManagement.requestScilabExec(
            String.format(
                "disp(\"%s\"), disp(\"%s\")",
                String.format(
                    Messages.gettext(
                        "WARNING: Due to your configuration limitations, Scilab switched in a mode where mixing uicontrols and graphics is not available. Type %s for more information."),
                    "\"\"help usecanvas\"\""),
                String.format(
                    Messages.gettext("In some cases, %s fixes the issue"),
                    "\"\"system_setproperty(''jogl.gljpanel.nohw'','''');\"\"")));
      }
    }

    /*
     * Bug #7526: this code block causes a crash on Windows and Intel Graphic HD cards
     * with graphics drivers older than 8.15.10.2279 and is therefore not executed if
     * Windows is the OS (the tests on driver and OpenGL versions are Linux-specific).
     * Consequently, updateMaxCanvasSize, which determines the canvas size, is not called
     * any more on Windows. However, it is still called when an actual graphics window is created
     * (by the renderer module's SciRenderer init method), which still allows getting the maximum
     * canvas dimensions, so this should not be an issue.
     */
    if (!OS_NAME.contains("Windows")) {

      try {
        GLCanvas tmpCanvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()));
        Frame tmpFrame = new Frame();
        tmpFrame.add(tmpCanvas);
        tmpFrame.setVisible(true);

        tmpCanvas.getContext().makeCurrent();
        GL gl = tmpCanvas.getGL();

        String GL_VENDOR = gl.glGetString(GL.GL_VENDOR);
        Debug.DEBUG("SwingScilabCanvasImpl", "GL_VENDOR=" + GL_VENDOR);
        String GL_RENDERER = gl.glGetString(GL.GL_RENDERER);
        Debug.DEBUG("SwingScilabCanvasImpl", "GL_RENDERER=" + GL_RENDERER);
        String GL_VERSION = gl.glGetString(GL.GL_VERSION);
        Debug.DEBUG("SwingScilabCanvasImpl", "GL_VERSION=" + GL_VERSION);
        // Debug.DEBUG("SwingScilabCanvasImpl", "GL_EXTENSIONS="+gl.glGetString(GL.GL_EXTENSIONS));
        Debug.DEBUG("SwingScilabCanvasImpl", "=======================================");
        // System.getProperties().list(System.err);

        // get maximum axes size
        // RenderingCapabilities.updateMaxCanvasSize(gl);

        tmpCanvas.getContext().release();
        tmpFrame.remove(tmpCanvas);
        tmpFrame.setVisible(false);
        tmpFrame.dispose();
        Debug.DEBUG(
            "SwingScilabCanvasImpl",
            "Testing time = " + (Calendar.getInstance().getTimeInMillis() - lastTime) + "ms");

        noGLJPanel = false;

        // By default disable GLJPanel on Linux
        if (OS_NAME.contains("Linux")) {
          noGLJPanel = true;
          // Linux && NVIDIA
          if (GL_VENDOR.contains("NVIDIA")) {
            noGLJPanel = false;
          }
          // Linux && ATI
          if (GL_VENDOR.contains("ATI")) {
            StringTokenizer stSpace = new StringTokenizer(GL_VERSION, " ");
            StringTokenizer stDot = new StringTokenizer(stSpace.nextToken(), ".");
            int majorVersion = Integer.parseInt(stDot.nextToken());
            int minorVersion = Integer.parseInt(stDot.nextToken());
            int releaseVersion = Integer.parseInt(stDot.nextToken());
            // Only OpenGL version newer than 2.1.7873 works
            // available through ATI 8.8 installer
            // and driver newer than 8.52.3
            Debug.DEBUG(
                "SwingScilabCanvasImpl",
                "majorVersion = "
                    + majorVersion
                    + " minorVersion = "
                    + minorVersion
                    + " releaseVersion = "
                    + releaseVersion);
            if (majorVersion > 2
                || majorVersion == 2 && minorVersion > 1
                || majorVersion == 2 && minorVersion == 1 && releaseVersion >= 7873) {
              noGLJPanel = false;
            }
          }
        }

        if (noGLJPanel) {
          /** Inform the users */
          InterpreterManagement.requestScilabExec(
              String.format(
                  "disp(\"%s\"), disp(\"%s\")",
                  String.format(
                      Messages.gettext(
                          "WARNING: Due to your configuration limitations, Scilab switched in a mode where mixing uicontrols and graphics is not available. Type %s for more information."),
                      "\"\"help usecanvas\"\""),
                  String.format(
                      Messages.gettext("In some cases, %s fixes the issue"),
                      "\"\"system_setproperty(''jogl.gljpanel.nohw'','''');\"\"")));
        }
      } catch (GLException e) {
        noGLJPanel = true;
        /** Inform the users */
        InterpreterManagement.requestScilabExec(
            String.format(
                "disp(\"%s\"), disp(\"%s\")",
                Messages.gettext(
                    "Due to your video card drivers limitations, that are not able to manage OpenGL, Scilab will not be able to draw any graphics. Please update your driver."),
                String.format(
                    Messages.gettext("In some cases, %s fixes the issue"),
                    "\"\"system_setproperty(''jogl.gljpanel.nohw'','''');\"\"")));
      } catch (HeadlessException e) {
        // do not print anything on a CLI only environment
        noGLJPanel = true;
      }
    }
  }