Exemplo n.º 1
0
  public static int getFormat(CapabilitiesImmutable rCaps) {
    int fmt = PixelFormat.UNKNOWN;

    if (!rCaps.isBackgroundOpaque()) {
      fmt = PixelFormat.TRANSLUCENT;
    } else if (rCaps.getRedBits() <= 5
        && rCaps.getGreenBits() <= 6
        && rCaps.getBlueBits() <= 5
        && rCaps.getAlphaBits() == 0) {
      fmt = PixelFormat.RGB_565;
    }
    /* else if(rCaps.getRedBits()<=5 &&
       rCaps.getGreenBits()<=5 &&
       rCaps.getBlueBits()<=5 &&
       rCaps.getAlphaBits()==1) {
        fmt = PixelFormat.RGBA_5551; // FIXME: Supported ?
    } */
    else {
      fmt = PixelFormat.RGBA_8888;
    }
    Log.d(MD.TAG, "getFormat: requested: " + rCaps);
    Log.d(MD.TAG, "getFormat:  returned: " + fmt);

    return fmt;
  }
Exemplo n.º 2
0
  private static AWTGraphicsConfiguration chooseGraphicsConfiguration(
      CapabilitiesImmutable capsChosen,
      CapabilitiesImmutable capsRequested,
      CapabilitiesChooser chooser,
      GraphicsDevice device) {
    final AbstractGraphicsScreen aScreen =
        null != device
            ? AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT)
            : AWTGraphicsScreen.createDefault();
    AWTGraphicsConfiguration config =
        (AWTGraphicsConfiguration)
            GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class, capsChosen.getClass())
                .chooseGraphicsConfiguration(
                    capsChosen, capsRequested, chooser, aScreen, VisualIDHolder.VID_UNDEFINED);
    if (config == null) {
      throw new NativeWindowException("Error: Couldn't fetch AWTGraphicsConfiguration");
    }

    return config;
  }
Exemplo n.º 3
0
  public static CapabilitiesImmutable fixCaps(
      boolean matchFormatPrecise, int format, CapabilitiesImmutable rCaps) {
    PixelFormat pf = new PixelFormat();
    PixelFormat.getPixelFormatInfo(format, pf);
    final CapabilitiesImmutable res;
    int r, g, b, a;

    switch (format) {
      case PixelFormat.RGBA_8888:
        r = 8;
        g = 8;
        b = 8;
        a = 8;
        break;
      case PixelFormat.RGBX_8888:
        r = 8;
        g = 8;
        b = 8;
        a = 0;
        break;
      case PixelFormat.RGB_888:
        r = 8;
        g = 8;
        b = 8;
        a = 0;
        break;
      case PixelFormat.RGB_565:
        r = 5;
        g = 6;
        b = 5;
        a = 0;
        break;
      case PixelFormat.RGBA_5551:
        r = 5;
        g = 5;
        b = 5;
        a = 1;
        break;
      case PixelFormat.RGBA_4444:
        r = 4;
        g = 4;
        b = 4;
        a = 4;
        break;
      case PixelFormat.RGB_332:
        r = 3;
        g = 3;
        b = 2;
        a = 0;
        break;
      default:
        throw new InternalError("Unhandled pixelformat: " + format);
    }
    final boolean change =
        matchFormatPrecise
            || rCaps.getRedBits() > r
                && rCaps.getGreenBits() > g
                && rCaps.getBlueBits() > b
                && rCaps.getAlphaBits() > a;

    if (change) {
      Capabilities nCaps = (Capabilities) rCaps.cloneMutable();
      nCaps.setRedBits(r);
      nCaps.setGreenBits(g);
      nCaps.setBlueBits(b);
      nCaps.setAlphaBits(a);
      res = nCaps;
    } else {
      res = rCaps;
    }
    Log.d(MD.TAG, "fixCaps:    format: " + format);
    Log.d(MD.TAG, "fixCaps: requested: " + rCaps);
    Log.d(MD.TAG, "fixCaps:    chosen: " + res);

    return res;
  }
  void doTest(final GLCapabilitiesImmutable reqGLCaps, final GLEventListener demo)
      throws InterruptedException {
    System.out.println("Requested  GL Caps: " + reqGLCaps);
    final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile());
    final GLCapabilitiesImmutable expGLCaps =
        GLGraphicsConfigurationUtil.fixGLCapabilities(reqGLCaps, factory, null);
    System.out.println("Expected   GL Caps: " + expGLCaps);

    //
    // Create native OpenGL resources .. XGL/WGL/CGL ..
    // equivalent to GLAutoDrawable methods: setVisible(true)
    //
    final GLOffscreenAutoDrawable glad =
        factory.createOffscreenAutoDrawable(
            null, reqGLCaps, null, widthStep * szStep, heightStep * szStep);

    Assert.assertNotNull(glad);
    System.out.println(
        "Drawable    Pre-GL(0): "
            + glad.getClass().getName()
            + ", "
            + glad.getNativeSurface().getClass().getName());
    Assert.assertTrue(glad.isRealized());

    // Check caps of NativeWindow config w/o GL
    final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities();
    System.out.println("Drawable Caps Pre_GL : " + chosenCaps);
    Assert.assertNotNull(chosenCaps);
    Assert.assertTrue(chosenCaps.getGreenBits() > 4);
    Assert.assertTrue(chosenCaps.getBlueBits() > 4);
    Assert.assertTrue(chosenCaps.getRedBits() > 4);

    glad.display(); // force native context creation

    // Check caps of GLDrawable after realization
    final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities();
    System.out.println("Chosen     GL CTX (1): " + glad.getContext().getGLVersion());
    System.out.println("Chosen     GL Caps(1): " + chosenGLCaps);
    System.out.println(
        "Chosen     GL Caps(2): "
            + glad.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities());

    Assert.assertNotNull(chosenGLCaps);
    Assert.assertTrue(chosenGLCaps.getGreenBits() > 4);
    Assert.assertTrue(chosenGLCaps.getBlueBits() > 4);
    Assert.assertTrue(chosenGLCaps.getRedBits() > 4);
    Assert.assertTrue(chosenGLCaps.getDepthBits() > 4);
    Assert.assertEquals(expGLCaps.isOnscreen(), chosenGLCaps.isOnscreen());
    Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO());
    Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer());
    Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap());
    /**
     * Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen()
     * || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap
     * Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); }
     */
    glad.addGLEventListener(demo);

    final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener();
    glad.addGLEventListener(snapshotGLEventListener);

    glad.display(); // initial resize/display

    // 1 - szStep = 2
    Assert.assertTrue(
        "Size not reached: Expected "
            + (widthStep * szStep)
            + "x"
            + (heightStep * szStep)
            + ", Is "
            + glad.getSurfaceWidth()
            + "x"
            + glad.getSurfaceHeight(),
        AWTRobotUtil.waitForSize(glad, widthStep * szStep, heightStep * szStep));
    snapshotGLEventListener.setMakeSnapshot();
    glad.display();

    // 2, 3 (resize + display)
    szStep = 1;
    glad.setSurfaceSize(widthStep * szStep, heightStep * szStep);
    Assert.assertTrue(
        "Size not reached: Expected "
            + (widthStep * szStep)
            + "x"
            + (heightStep * szStep)
            + ", Is "
            + glad.getSurfaceWidth()
            + "x"
            + glad.getSurfaceHeight(),
        AWTRobotUtil.waitForSize(glad, widthStep * szStep, heightStep * szStep));
    snapshotGLEventListener.setMakeSnapshot();
    glad.display();

    // 4, 5 (resize + display)
    szStep = 4;
    glad.setSurfaceSize(widthStep * szStep, heightStep * szStep);
    Assert.assertTrue(
        "Size not reached: Expected "
            + (widthStep * szStep)
            + "x"
            + (heightStep * szStep)
            + ", Is "
            + glad.getSurfaceWidth()
            + "x"
            + glad.getSurfaceHeight(),
        AWTRobotUtil.waitForSize(glad, widthStep * szStep, heightStep * szStep));
    snapshotGLEventListener.setMakeSnapshot();
    glad.display();

    Thread.sleep(50);

    glad.destroy();
    System.out.println("Fin Drawable: " + glad);
  }