public AbstractGraphicsConfiguration chooseGraphicsConfiguration(
      Capabilities capabilities, CapabilitiesChooser chooser, AbstractGraphicsScreen absScreen) {
    GraphicsDevice device = null;
    if (absScreen != null && !(absScreen instanceof AWTGraphicsScreen)) {
      throw new IllegalArgumentException(
          "This GraphicsConfigurationFactory accepts only AWTGraphicsScreen objects");
    }

    if (null == absScreen) {
      absScreen = AWTGraphicsScreen.createScreenDevice(-1);
    }
    AWTGraphicsScreen awtScreen = (AWTGraphicsScreen) absScreen;
    device = ((AWTGraphicsDevice) awtScreen.getDevice()).getGraphicsDevice();

    if (capabilities != null && !(capabilities instanceof GLCapabilities)) {
      throw new IllegalArgumentException(
          "This GraphicsConfigurationFactory accepts only GLCapabilities objects");
    }

    if (chooser != null && !(chooser instanceof GLCapabilitiesChooser)) {
      throw new IllegalArgumentException(
          "This GraphicsConfigurationFactory accepts only GLCapabilitiesChooser objects");
    }

    if (DEBUG) {
      System.err.println("MacOSXAWTCGLGraphicsConfigurationFactory: got " + absScreen);
    }

    long displayHandle = 0;

    MacOSXGraphicsDevice macDevice = new MacOSXGraphicsDevice();
    DefaultGraphicsScreen macScreen = new DefaultGraphicsScreen(macDevice, awtScreen.getIndex());
    if (DEBUG) {
      System.err.println("MacOSXAWTCGLGraphicsConfigurationFactory: made " + macScreen);
    }

    GraphicsConfiguration gc = device.getDefaultConfiguration();
    AWTGraphicsConfiguration.setupCapabilitiesRGBABits(capabilities, gc);
    if (DEBUG) {
      System.err.println("AWT Colormodel compatible: " + capabilities);
    }

    MacOSXCGLGraphicsConfiguration macConfig =
        (MacOSXCGLGraphicsConfiguration)
            GraphicsConfigurationFactory.getFactory(macDevice)
                .chooseGraphicsConfiguration(capabilities, chooser, macScreen);

    if (macConfig == null) {
      throw new GLException(
          "Unable to choose a GraphicsConfiguration: "
              + capabilities
              + ",\n\t"
              + chooser
              + "\n\t"
              + macScreen);
    }

    // FIXME: we have nothing to match .. so choose the default
    return new AWTGraphicsConfiguration(
        awtScreen,
        macConfig.getChosenCapabilities(),
        macConfig.getRequestedCapabilities(),
        gc,
        macConfig);
  }
  /**
   * Creates and initializes an appropriate OpenGl Context (NS). Should only be called by {@link
   * makeCurrentImpl()}.
   */
  protected boolean create(boolean pbuffer, boolean floatingPoint) {
    MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this);
    long share = 0;
    if (other != null) {
      if (!other.isNSContext()) {
        throw new GLException("GLContextShareSet is not a NS Context");
      }
      share = other.getHandle();
      if (share == 0) {
        throw new GLException("GLContextShareSet returned a NULL OpenGL context");
      }
    }
    MacOSXCGLGraphicsConfiguration config =
        (MacOSXCGLGraphicsConfiguration)
            drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
    GLCapabilitiesImmutable capabilitiesRequested =
        (GLCapabilitiesImmutable) config.getRequestedCapabilities();
    GLProfile glProfile = capabilitiesRequested.getGLProfile();
    if (glProfile.isGL3()) {
      throw new GLException(
          "GL3 profile currently not supported on MacOSX, due to the lack of a OpenGL 3.1 implementation");
    }
    // HACK .. bring in OnScreen/PBuffer selection to the DrawableFactory !!
    GLCapabilities capabilities = (GLCapabilities) capabilitiesRequested.cloneMutable();
    capabilities.setPBuffer(pbuffer);
    capabilities.setPbufferFloatingPointBuffers(floatingPoint);

    long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(capabilities);
    if (pixelFormat == 0) {
      throw new GLException("Unable to allocate pixel format with requested GLCapabilities");
    }
    config.setChosenPixelFormat(pixelFormat);
    try {
      int[] viewNotReady = new int[1];
      // Try to allocate a context with this
      contextHandle = CGL.createContext(share, drawable.getHandle(), pixelFormat, viewNotReady, 0);
      if (contextHandle == 0) {
        if (viewNotReady[0] == 1) {
          if (DEBUG) {
            System.err.println("!!! View not ready for " + getClass().getName());
          }
          // View not ready at the window system level -- this is OK
          return false;
        }
        throw new GLException("Error creating NSOpenGLContext with requested pixel format");
      }

      if (!pbuffer && !capabilities.isBackgroundOpaque()) {
        // Set the context opacity
        CGL.setContextOpacity(contextHandle, 0);
      }

      GLCapabilitiesImmutable caps =
          MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(glProfile, pixelFormat);
      config.setChosenCapabilities(caps);
    } finally {
      CGL.deletePixelFormat(pixelFormat);
    }
    if (!CGL.makeCurrentContext(contextHandle)) {
      throw new GLException("Error making Context (NS) current");
    }
    isNSContext = true;
    setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT | CTX_OPTION_ANY);
    GLContextShareSet.contextCreated(this);
    return true;
  }