Exemple #1
0
 public final synchronized void setRealized(boolean realizedArg) {
   if (realized != realizedArg) {
     if (DEBUG) {
       System.err.println(
           "setRealized: " + getClass().getName() + " " + realized + " -> " + realizedArg);
     }
     realized = realizedArg;
     AbstractGraphicsDevice aDevice = surface.getGraphicsConfiguration().getScreen().getDevice();
     if (realizedArg) {
       if (NativeSurface.LOCK_SURFACE_NOT_READY >= lockSurface()) {
         throw new GLException(
             "GLDrawableImpl.setRealized(true): already realized, but surface not ready (lockSurface)");
       }
     } else {
       aDevice.lock();
     }
     try {
       setRealizedImpl();
       if (realizedArg) {
         updateHandle();
       } else {
         destroyHandle();
       }
     } finally {
       if (realizedArg) {
         unlockSurface();
       } else {
         aDevice.unlock();
       }
     }
   } else if (DEBUG) {
     System.err.println(
         "setRealized: " + getClass().getName() + " " + this.realized + " == " + realizedArg);
   }
 }
 @Override
 protected final ProxySurface createMutableSurfaceImpl(
     AbstractGraphicsDevice deviceReq,
     boolean createNewDevice,
     GLCapabilitiesImmutable capsChosen,
     GLCapabilitiesImmutable capsRequested,
     GLCapabilitiesChooser chooser,
     UpstreamSurfaceHook upstreamHook) {
   final X11GraphicsDevice device;
   if (createNewDevice || !(deviceReq instanceof X11GraphicsDevice)) {
     device =
         new X11GraphicsDevice(
             X11Util.openDisplay(deviceReq.getConnection()),
             deviceReq.getUnitID(),
             true /* owner */);
   } else {
     device = (X11GraphicsDevice) deviceReq;
   }
   final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());
   final X11GLXGraphicsConfiguration config =
       X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
           capsChosen, capsRequested, chooser, screen, VisualIDHolder.VID_UNDEFINED);
   if (null == config) {
     throw new GLException(
         "Choosing GraphicsConfiguration failed w/ " + capsChosen + " on " + screen);
   }
   return new WrappedSurface(config, 0, upstreamHook, createNewDevice);
 }
Exemple #3
0
 protected void closeNativeImpl() {
   if (0 != windowHandleClose && null != getScreen()) {
     DisplayDriver display = (DisplayDriver) getScreen().getDisplay();
     final AbstractGraphicsDevice edtDevice = display.getGraphicsDevice();
     edtDevice.lock();
     try {
       CloseWindow0(
           edtDevice.getHandle(),
           windowHandleClose,
           display.getJavaObjectAtom(),
           display.getWindowDeleteAtom());
     } catch (Throwable t) {
       if (DEBUG_IMPLEMENTATION) {
         Exception e =
             new Exception(
                 "Warning: closeNativeImpl failed - " + Thread.currentThread().getName(), t);
         e.printStackTrace();
       }
     } finally {
       edtDevice.unlock();
       windowHandleClose = 0;
     }
   }
   if (null != renderDevice) {
     renderDevice.close(); // closes X11 display
     renderDevice = null;
   }
 }
  static List<GLCapabilitiesImmutable> getAvailableGLCapabilitiesXVisual(
      X11GraphicsScreen x11Screen, GLProfile glProfile, boolean isMultisampleAvailable) {
    AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    long display = absDevice.getHandle();

    int screen = x11Screen.getIndex();

    int[] count = new int[1];
    XVisualInfo template = XVisualInfo.create();
    template.setScreen(screen);
    XVisualInfo[] infos =
        X11Lib.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0);
    if (infos == null || infos.length < 1) {
      throw new GLException("Error while enumerating available XVisualInfos");
    }
    ArrayList<GLCapabilitiesImmutable> availableCaps = new ArrayList<GLCapabilitiesImmutable>();
    for (int i = 0; i < infos.length; i++) {
      if (!X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(
          availableCaps,
          glProfile,
          display,
          infos[i],
          GLGraphicsConfigurationUtil.ALL_BITS,
          isMultisampleAvailable)) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.getAvailableGLCapabilitiesXVisual: XVisual invalid: ("
                  + x11Screen
                  + "): fbcfg: "
                  + toHexString(infos[i].getVisualid()));
        }
      }
    }
    return availableCaps;
  }
 @Override
 protected ProxySurface createMutableSurfaceImpl(
     AbstractGraphicsDevice deviceReq,
     boolean createNewDevice,
     GLCapabilitiesImmutable capsChosen,
     GLCapabilitiesImmutable capsRequested,
     GLCapabilitiesChooser chooser,
     UpstreamSurfaceHook upstreamHook) {
   final boolean ownDevice;
   final EGLGraphicsDevice device;
   if (createNewDevice || !(deviceReq instanceof EGLGraphicsDevice)) {
     final long nativeDisplayID =
         (deviceReq instanceof EGLGraphicsDevice)
             ? ((EGLGraphicsDevice) deviceReq).getNativeDisplayID()
             : deviceReq.getHandle();
     device =
         EGLDisplayUtil.eglCreateEGLGraphicsDevice(
             nativeDisplayID, deviceReq.getConnection(), deviceReq.getUnitID());
     ownDevice = true;
   } else {
     device = (EGLGraphicsDevice) deviceReq;
     ownDevice = false;
   }
   final DefaultGraphicsScreen screen = new DefaultGraphicsScreen(device, 0);
   final EGLGraphicsConfiguration config =
       EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
           capsChosen, capsRequested, chooser, screen, VisualIDHolder.VID_UNDEFINED, false);
   if (null == config) {
     throw new GLException(
         "Choosing GraphicsConfiguration failed w/ " + capsChosen + " on " + screen);
   }
   return new WrappedSurface(config, 0, upstreamHook, ownDevice);
 }
  static X11GLXGraphicsConfiguration fetchGraphicsConfigurationFBConfig(
      X11GraphicsScreen x11Screen, int fbID, GLProfile glp) {
    final AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    final long display = absDevice.getHandle();
    final int screen = x11Screen.getIndex();

    final long fbcfg = X11GLXGraphicsConfiguration.glXFBConfigID2FBConfig(display, screen, fbID);
    if (0 == fbcfg || !X11GLXGraphicsConfiguration.GLXFBConfigValid(display, fbcfg)) {
      if (DEBUG) {
        System.err.println(
            "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("
                + x11Screen
                + ","
                + toHexString(fbID)
                + "): fbcfg: "
                + toHexString(fbcfg));
      }
      return null;
    }
    final X11GLXDrawableFactory factory =
        (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory();

    final X11GLCapabilities caps =
        X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(
            glp, display, fbcfg, true, true, true, factory.isGLXMultisampleAvailable(absDevice));
    return new X11GLXGraphicsConfiguration(
        x11Screen, caps, caps, new DefaultGLCapabilitiesChooser());
  }
 /**
  * @param capsRequested
  * @param absScreen
  * @param eglConfigID {@link EGL#EGL_CONFIG_ID} for which the config is being created for.
  * @return
  * @throws GLException if invalid EGL display.
  */
 public static EGLGraphicsConfiguration create(
     GLCapabilitiesImmutable capsRequested, AbstractGraphicsScreen absScreen, int eglConfigID) {
   final AbstractGraphicsDevice absDevice = absScreen.getDevice();
   if (null == absDevice || !(absDevice instanceof EGLGraphicsDevice)) {
     throw new GLException("GraphicsDevice must be a valid EGLGraphicsDevice");
   }
   final long dpy = absDevice.getHandle();
   if (dpy == EGL.EGL_NO_DISPLAY) {
     throw new GLException("Invalid EGL display: " + absDevice);
   }
   final long cfg = EGLConfigId2EGLConfig(dpy, eglConfigID);
   if (0 < cfg) {
     final GLRendererQuirks defaultQuirks =
         GLRendererQuirks.getStickyDeviceQuirks(
             GLDrawableFactory.getEGLFactory().getDefaultDevice());
     final int winattrmask =
         GLGraphicsConfigurationUtil.getExclusiveWinAttributeBits(capsRequested);
     final EGLGLCapabilities caps =
         EGLConfig2Capabilities(
             defaultQuirks,
             (EGLGraphicsDevice) absDevice,
             capsRequested.getGLProfile(),
             cfg,
             winattrmask,
             false);
     return new EGLGraphicsConfiguration(
         absScreen, caps, capsRequested, new DefaultGLCapabilitiesChooser());
   }
   return null;
 }
Exemple #8
0
 /**
  * Default implementation to destroys the drawable and context of this GLAutoDrawable:
  *
  * <ul>
  *   <li>issues the GLEventListener dispose call, if drawable and context are valid
  *   <li>destroys the GLContext, if valid
  *   <li>destroys the GLDrawable, if valid
  * </ul>
  *
  * <p>Method assumes the lock is being hold.
  *
  * <p>Override it to extend it to destroy your resources, i.e. the actual window. In such case
  * call <code>super.destroyImplInLock</code> first.
  */
 protected void destroyImplInLock() {
   if (preserveGLELSAtDestroy) {
     preserveGLStateAtDestroy(false);
     preserveGLEventListenerState();
   }
   if (null != context) {
     if (context.isCreated()) {
       // Catch dispose GLExceptions by GLEventListener, just 'print' them
       // so we can continue with the destruction.
       try {
         helper.disposeGL(this, context, true);
       } catch (GLException gle) {
         gle.printStackTrace();
       }
     }
     context = null;
   }
   if (null != drawable) {
     final AbstractGraphicsDevice device =
         drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
     drawable.setRealized(false);
     drawable = null;
     if (ownsDevice) {
       device.close();
     }
   }
 }
Exemple #9
0
  protected void createNativeImpl() {
    if (0 != getParentWindowHandle()) {
      throw new NativeWindowException("GDL Window does not support window parenting");
    }
    AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen();
    AbstractGraphicsDevice aDevice = getScreen().getDisplay().getGraphicsDevice();

    config =
        GraphicsConfigurationFactory.getFactory(aDevice)
            .chooseGraphicsConfiguration(
                capsRequested, capsRequested, capabilitiesChooser, aScreen);
    if (config == null) {
      throw new NativeWindowException(
          "Error choosing GraphicsConfiguration creating window: " + this);
    }

    synchronized (Window.class) {
      setWindowHandle(nextWindowHandle++); // just a marker

      surfaceHandle =
          CreateSurface(
              aDevice.getHandle(),
              getScreen().getWidth(),
              getScreen().getHeight(),
              x,
              y,
              width,
              height);
      if (surfaceHandle == 0) {
        throw new NativeWindowException("Error creating window");
      }
    }
  }
Exemple #10
0
 @Override
 public final synchronized void setRealized(boolean realizedArg) {
   if (realized != realizedArg) {
     if (DEBUG) {
       System.err.println(
           getThreadName()
               + ": setRealized: "
               + getClass().getSimpleName()
               + " "
               + realized
               + " -> "
               + realizedArg);
     }
     realized = realizedArg;
     AbstractGraphicsDevice aDevice = surface.getGraphicsConfiguration().getScreen().getDevice();
     if (realizedArg) {
       if (surface instanceof ProxySurface) {
         ((ProxySurface) surface).createNotify();
       }
       if (NativeSurface.LOCK_SURFACE_NOT_READY >= lockSurface()) {
         throw new GLException(
             "GLDrawableImpl.setRealized(true): Surface not ready (lockSurface)");
       }
     } else {
       aDevice.lock();
     }
     try {
       if (realizedArg) {
         setRealizedImpl();
         updateHandle();
       } else {
         destroyHandle();
         setRealizedImpl();
       }
     } finally {
       if (realizedArg) {
         unlockSurface();
       } else {
         aDevice.unlock();
         if (surface instanceof ProxySurface) {
           ((ProxySurface) surface).destroyNotify();
         }
       }
     }
   } else if (DEBUG) {
     System.err.println(
         getThreadName()
             + ": setRealized: "
             + getClass().getName()
             + " "
             + this.realized
             + " == "
             + realizedArg);
   }
 }
Exemple #11
0
 private void dispose() {
   if (null != awtConfig) {
     AbstractGraphicsDevice adevice =
         awtConfig.getNativeGraphicsConfiguration().getScreen().getDevice();
     String adeviceMsg = null;
     if (Window.DEBUG_IMPLEMENTATION) {
       adeviceMsg = adevice.toString();
     }
     boolean closed = adevice.close();
     if (Window.DEBUG_IMPLEMENTATION) {
       System.err.println(
           "AWTCanvas.dispose(): closed GraphicsDevice: " + adeviceMsg + ", result: " + closed);
     }
   }
 }
  static List<GLCapabilitiesImmutable> getAvailableGLCapabilitiesFBConfig(
      X11GraphicsScreen x11Screen, GLProfile glProfile, boolean isMultisampleAvailable) {
    PointerBuffer fbcfgsL = null;

    // Utilizing FBConfig
    //
    AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    long display = absDevice.getHandle();

    int screen = x11Screen.getIndex();
    int[] count = {-1};
    ArrayList<GLCapabilitiesImmutable> availableCaps = new ArrayList<GLCapabilitiesImmutable>();

    fbcfgsL = GLX.glXChooseFBConfig(display, screen, null, 0, count, 0);
    if (fbcfgsL == null || fbcfgsL.limit() <= 0) {
      if (DEBUG) {
        System.err.println(
            "X11GLXGraphicsConfiguration.getAvailableGLCapabilitiesFBConfig: Failed glXChooseFBConfig ("
                + x11Screen
                + "): "
                + fbcfgsL
                + ", "
                + count[0]);
      }
      return null;
    }
    for (int i = 0; i < fbcfgsL.limit(); i++) {
      if (!X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(
          availableCaps,
          glProfile,
          display,
          fbcfgsL.get(i),
          GLGraphicsConfigurationUtil.ALL_BITS,
          isMultisampleAvailable)) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.getAvailableGLCapabilitiesFBConfig: FBConfig invalid (2): ("
                  + x11Screen
                  + "): fbcfg: "
                  + toHexString(fbcfgsL.get(i)));
        }
      }
    }
    return availableCaps;
  }
 @Override
 protected ProxySurface createProxySurfaceImpl(
     AbstractGraphicsDevice deviceReq,
     int screenIdx,
     long windowHandle,
     GLCapabilitiesImmutable capsRequested,
     GLCapabilitiesChooser chooser,
     UpstreamSurfaceHook upstream) {
   final EGLGraphicsDevice eglDeviceReq = (EGLGraphicsDevice) deviceReq;
   final EGLGraphicsDevice device =
       EGLDisplayUtil.eglCreateEGLGraphicsDevice(
           eglDeviceReq.getNativeDisplayID(), deviceReq.getConnection(), deviceReq.getUnitID());
   final DefaultGraphicsScreen screen = new DefaultGraphicsScreen(device, screenIdx);
   final EGLGraphicsConfiguration cfg =
       EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
           capsRequested, capsRequested, chooser, screen, VisualIDHolder.VID_UNDEFINED, false);
   return new WrappedSurface(cfg, windowHandle, upstream, true);
 }
Exemple #14
0
  @Override
  protected final void updateGLXProcAddressTable() {
    final AbstractGraphicsConfiguration aconfig =
        drawable.getNativeSurface().getGraphicsConfiguration();
    final AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice();
    final String key = "EGL-" + adevice.getUniqueID();
    if (DEBUG) {
      System.err.println(getThreadName() + ": Initializing EGLextension address table: " + key);
    }
    eglQueryStringInitialized = false;
    eglQueryStringAvailable = false;

    ProcAddressTable table = null;
    synchronized (mappedContextTypeObjectLock) {
      table = mappedGLXProcAddress.get(key);
    }
    if (null != table) {
      eglExtProcAddressTable = (EGLExtProcAddressTable) table;
      if (DEBUG) {
        System.err.println(
            getThreadName()
                + ": GLContext EGL ProcAddressTable reusing key("
                + key
                + ") -> "
                + toHexString(table.hashCode()));
      }
    } else {
      eglExtProcAddressTable = new EGLExtProcAddressTable(new GLProcAddressResolver());
      resetProcAddressTable(getEGLExtProcAddressTable());
      synchronized (mappedContextTypeObjectLock) {
        mappedGLXProcAddress.put(key, getEGLExtProcAddressTable());
        if (DEBUG) {
          System.err.println(
              getThreadName()
                  + ": GLContext EGL ProcAddressTable mapping key("
                  + key
                  + ") -> "
                  + toHexString(getEGLExtProcAddressTable().hashCode()));
        }
      }
    }
  }
 @Override
 protected final ProxySurface createProxySurfaceImpl(
     AbstractGraphicsDevice deviceReq,
     int screenIdx,
     long windowHandle,
     GLCapabilitiesImmutable capsRequested,
     GLCapabilitiesChooser chooser,
     UpstreamSurfaceHook upstream) {
   final X11GraphicsDevice device =
       new X11GraphicsDevice(
           X11Util.openDisplay(deviceReq.getConnection()),
           deviceReq.getUnitID(),
           true /* owner */);
   final X11GraphicsScreen screen = new X11GraphicsScreen(device, screenIdx);
   final int xvisualID = X11Lib.GetVisualIDFromWindow(device.getHandle(), windowHandle);
   if (VisualIDHolder.VID_UNDEFINED == xvisualID) {
     throw new GLException(
         "Undefined VisualID of window 0x"
             + Long.toHexString(windowHandle)
             + ", window probably invalid");
   }
   if (DEBUG) {
     System.err.println(
         "X11GLXDrawableFactory.createProxySurfaceImpl 0x"
             + Long.toHexString(windowHandle)
             + ": visualID 0x"
             + Integer.toHexString(xvisualID));
   }
   final X11GLXGraphicsConfiguration cfg =
       X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
           capsRequested, capsRequested, chooser, screen, xvisualID);
   if (DEBUG) {
     System.err.println(
         "X11GLXDrawableFactory.createProxySurfaceImpl 0x"
             + Long.toHexString(windowHandle)
             + ": "
             + cfg);
   }
   return new WrappedSurface(cfg, windowHandle, upstream, true);
 }
  @Override
  protected final SharedResource getOrCreateSharedResourceImpl(AbstractGraphicsDevice adevice) {
    if (null
        == sharedMap) { // null == eglES1DynamicLookupHelper && null == eglES2DynamicLookupHelper
      return null;
    }

    if (needsToCreateSharedResource(defaultDevice.getUniqueID(), null)) {
      if (DEBUG) {
        System.err.println(
            "EGLDrawableFactory.createShared: (defaultDevice): req. device: "
                + adevice
                + ", defaultDevice "
                + defaultDevice);
        Thread.dumpStack();
      }
      if (null != defaultSharedResource) {
        dumpMap();
        throw new InternalError("defaultSharedResource already exist: " + defaultSharedResource);
      }
      defaultSharedResource = createEGLSharedResourceImpl(defaultDevice);
    }

    final String key = adevice.getUniqueID();
    if (defaultDevice.getUniqueID().equals(key)) {
      return defaultSharedResource;
    } else {
      if (null == defaultSharedResource) { // defaultDevice must be initialized before host-device
        dumpMap();
        throw new InternalError("defaultSharedResource does not exist");
      }
      final SharedResource[] existing = new SharedResource[] {null};
      if (!needsToCreateSharedResource(key, existing)) {
        return existing[0];
      }
      return createEGLSharedResourceImpl(adevice);
    }
  }
  private static X11GLXGraphicsConfiguration chooseGraphicsConfigurationXVisual(
      GLCapabilitiesImmutable capsChosen,
      GLCapabilitiesImmutable capsReq,
      GLCapabilitiesChooser chooser,
      X11GraphicsScreen x11Screen) {
    if (chooser == null) {
      chooser = new DefaultGLCapabilitiesChooser();
    }

    GLProfile glProfile = capsChosen.getGLProfile();
    final int winattrmask =
        GLGraphicsConfigurationUtil.getWinAttributeBits(
            capsChosen.isOnscreen(), false /* pbuffer */);
    ArrayList availableCaps = new ArrayList();
    int recommendedIndex = -1;

    AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    long display = absDevice.getHandle();
    int screen = x11Screen.getIndex();

    final X11GLXDrawableFactory factory =
        (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory();
    final boolean isMultisampleAvailable = factory.isGLXMultisampleAvailable(absDevice);
    int[] attribs =
        X11GLXGraphicsConfiguration.GLCapabilities2AttribList(
            capsChosen, false, isMultisampleAvailable, display, screen);

    // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as
    // preferred choice
    XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0);
    if (DEBUG) {
      System.err.print("glXChooseVisual recommended ");
      if (recommendedVis == null) {
        System.err.println("null visual");
      } else {
        System.err.println("visual id " + toHexString(recommendedVis.getVisualid()));
      }
    }

    // 2nd choice: get all GLCapabilities available, preferred recommendedIndex might be available
    // if 1st choice was successful
    int[] count = new int[1];
    XVisualInfo template = XVisualInfo.create();
    template.setScreen(screen);
    XVisualInfo[] infos =
        X11Lib.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0);
    if (infos == null || infos.length < 1) {
      throw new GLException("Error while enumerating available XVisualInfos");
    }

    for (int i = 0; i < infos.length; i++) {
      if (!X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(
          availableCaps, glProfile, display, infos[i], winattrmask, isMultisampleAvailable)) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual: XVisual invalid: ("
                  + x11Screen
                  + "): fbcfg: "
                  + toHexString(infos[i].getVisualid()));
        }
      } else {
        // Attempt to find the visual chosenIndex by glXChooseVisual, if not translucent
        if (capsChosen.isBackgroundOpaque()
            && recommendedVis != null
            && recommendedVis.getVisualid() == infos[i].getVisualid()) {
          recommendedIndex = availableCaps.size() - 1;
        }
      }
    }

    int chosenIndex = chooseCapabilities(chooser, capsChosen, availableCaps, recommendedIndex);
    if (0 > chosenIndex) {
      if (DEBUG) {
        System.err.println(
            "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual: failed, return null");
        Thread.dumpStack();
      }
      return null;
    }
    X11GLCapabilities chosenCaps = (X11GLCapabilities) availableCaps.get(chosenIndex);

    return new X11GLXGraphicsConfiguration(x11Screen, chosenCaps, capsReq, chooser);
  }
  private static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(
      GLCapabilitiesImmutable capsChosen,
      GLCapabilitiesImmutable capsReq,
      GLCapabilitiesChooser chooser,
      X11GraphicsScreen x11Screen) {
    int recommendedIndex = -1;
    PointerBuffer fbcfgsL = null;
    GLProfile glProfile = capsChosen.getGLProfile();
    boolean onscreen = capsChosen.isOnscreen();
    boolean usePBuffer = capsChosen.isPBuffer();

    // Utilizing FBConfig
    //
    AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    long display = absDevice.getHandle();
    int screen = x11Screen.getIndex();

    final X11GLXDrawableFactory factory =
        (X11GLXDrawableFactory) GLDrawableFactory.getDesktopFactory();
    final boolean isMultisampleAvailable = factory.isGLXMultisampleAvailable(absDevice);
    int[] attribs =
        X11GLXGraphicsConfiguration.GLCapabilities2AttribList(
            capsChosen, true, isMultisampleAvailable, display, screen);
    int[] count = {-1};
    ArrayList /*<X11GLCapabilities>*/ availableCaps = new ArrayList();
    final int winattrmask = GLGraphicsConfigurationUtil.getWinAttributeBits(onscreen, usePBuffer);

    // 1st choice: get GLCapabilities based on users GLCapabilities setting recommendedIndex as
    // preferred choice
    fbcfgsL = GLX.glXChooseFBConfig(display, screen, attribs, 0, count, 0);
    if (fbcfgsL != null && fbcfgsL.limit() > 0) {
      for (int i = 0; i < fbcfgsL.limit(); i++) {
        if (!X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(
            availableCaps,
            glProfile,
            display,
            fbcfgsL.get(i),
            winattrmask,
            isMultisampleAvailable)) {
          if (DEBUG) {
            System.err.println(
                "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: FBConfig invalid (1): ("
                    + x11Screen
                    + ","
                    + capsChosen
                    + "): fbcfg: "
                    + toHexString(fbcfgsL.get(i)));
          }
        }
      }
      if (availableCaps.size() > 0) {
        recommendedIndex =
            capsChosen.isBackgroundOpaque() ? 0 : -1; // only use recommended idx if not translucent
        if (DEBUG) {
          System.err.println(
              "glXChooseFBConfig recommended fbcfg "
                  + toHexString(fbcfgsL.get(0))
                  + ", idx "
                  + recommendedIndex);
          System.err.println("user  caps " + capsChosen);
          System.err.println("fbcfg caps " + availableCaps.get(0));
        }
      } else if (DEBUG) {
        System.err.println(
            "glXChooseFBConfig no caps for recommended fbcfg " + toHexString(fbcfgsL.get(0)));
        System.err.println("user  caps " + capsChosen);
      }
    }

    // 2nd choice: get all GLCapabilities available, no preferred recommendedIndex available
    if (0 == availableCaps.size()) {
      // reset ..
      recommendedIndex = -1;

      fbcfgsL = GLX.glXChooseFBConfig(display, screen, null, 0, count, 0);
      if (fbcfgsL == null || fbcfgsL.limit() <= 0) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("
                  + x11Screen
                  + ","
                  + capsChosen
                  + "): "
                  + fbcfgsL
                  + ", "
                  + count[0]);
        }
        return null;
      }

      for (int i = 0; i < fbcfgsL.limit(); i++) {
        if (!X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(
            availableCaps,
            glProfile,
            display,
            fbcfgsL.get(i),
            winattrmask,
            isMultisampleAvailable)) {
          if (DEBUG) {
            System.err.println(
                "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: FBConfig invalid (2): ("
                    + x11Screen
                    + "): fbcfg: "
                    + toHexString(fbcfgsL.get(i)));
          }
        }
      }
    }
    int chosenIndex = chooseCapabilities(chooser, capsChosen, availableCaps, recommendedIndex);
    if (0 > chosenIndex) {
      if (DEBUG) {
        System.err.println(
            "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: failed, return null");
        Thread.dumpStack();
      }
      return null;
    }
    X11GLCapabilities chosenCaps = (X11GLCapabilities) availableCaps.get(chosenIndex);

    return new X11GLXGraphicsConfiguration(x11Screen, chosenCaps, capsReq, chooser);
  }
  private SharedResource createEGLSharedResourceImpl(AbstractGraphicsDevice adevice) {
    final boolean madeCurrentES1;
    final boolean madeCurrentES2;
    final boolean madeCurrentES3;
    boolean[] hasPBufferES1 = new boolean[] {false};
    boolean[] hasPBufferES3ES2 = new boolean[] {false};
    // EGLContext[] eglCtxES1 = new EGLContext[] { null };
    // EGLContext[] eglCtxES2 = new EGLContext[] { null };
    GLRendererQuirks[] rendererQuirksES1 = new GLRendererQuirks[] {null};
    GLRendererQuirks[] rendererQuirksES3ES2 = new GLRendererQuirks[] {null};
    int[] ctpES1 = new int[] {-1};
    int[] ctpES3ES2 = new int[] {-1};

    if (DEBUG) {
      System.err.println("EGLDrawableFactory.createShared(): device " + adevice);
    }

    if (null != eglES1DynamicLookupHelper) {
      madeCurrentES1 =
          mapAvailableEGLESConfig(adevice, 1, hasPBufferES1, rendererQuirksES1, ctpES1);
    } else {
      madeCurrentES1 = false;
    }
    if (null != eglES2DynamicLookupHelper) {
      madeCurrentES3 =
          mapAvailableEGLESConfig(adevice, 3, hasPBufferES3ES2, rendererQuirksES3ES2, ctpES3ES2);
      if (madeCurrentES3) {
        // Only support highest - FIXME: Proper ES2/ES3 profile selection
        madeCurrentES2 = false;
      } else {
        madeCurrentES2 =
            mapAvailableEGLESConfig(adevice, 2, hasPBufferES3ES2, rendererQuirksES3ES2, ctpES3ES2);
      }
    } else {
      madeCurrentES2 = false;
      madeCurrentES3 = false;
    }

    if (!EGLContext.getAvailableGLVersionsSet(adevice)) {
      // Even though we override the non EGL native mapping intentionally,
      // avoid exception due to double 'set' - carefull exception of the rule.
      EGLContext.setAvailableGLVersionsSet(adevice);
    }
    if (hasX11) {
      handleDontCloseX11DisplayQuirk(rendererQuirksES1[0]);
      handleDontCloseX11DisplayQuirk(rendererQuirksES3ES2[0]);
    }
    final SharedResource sr =
        new SharedResource(
            defaultDevice,
            madeCurrentES1,
            hasPBufferES1[0],
            rendererQuirksES1[0],
            ctpES1[0],
            madeCurrentES2,
            madeCurrentES3,
            hasPBufferES3ES2[0],
            rendererQuirksES3ES2[0],
            ctpES3ES2[0]);

    synchronized (sharedMap) {
      sharedMap.put(adevice.getUniqueID(), sr);
    }
    if (DEBUG) {
      System.err.println(
          "EGLDrawableFactory.createShared: devices: queried nativeTK "
              + QUERY_EGL_ES_NATIVE_TK
              + ", adevice "
              + adevice
              + ", defaultDevice "
              + defaultDevice);
      System.err.println(
          "EGLDrawableFactory.createShared: context ES1: "
              + madeCurrentES1
              + ", hasPBuffer "
              + hasPBufferES1[0]);
      System.err.println(
          "EGLDrawableFactory.createShared: context ES2: "
              + madeCurrentES2
              + ", hasPBuffer "
              + hasPBufferES3ES2[0]);
      System.err.println(
          "EGLDrawableFactory.createShared: context ES3: "
              + madeCurrentES3
              + ", hasPBuffer "
              + hasPBufferES3ES2[0]);
      dumpMap();
    }
    return sr;
  }
Exemple #20
0
  protected void createNativeImpl() {
    final ScreenDriver screen = (ScreenDriver) getScreen();
    final DisplayDriver display = (DisplayDriver) screen.getDisplay();
    final AbstractGraphicsDevice edtDevice = display.getGraphicsDevice();

    // Decoupled X11 Device/Screen allowing X11 display lock-free off-thread rendering
    final long renderDeviceHandle = X11Util.openDisplay(edtDevice.getConnection());
    if (0 == renderDeviceHandle) {
      throw new RuntimeException("Error creating display(EDT): " + edtDevice.getConnection());
    }
    renderDevice =
        new X11GraphicsDevice(
            renderDeviceHandle, AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */);
    final AbstractGraphicsScreen renderScreen =
        new X11GraphicsScreen(renderDevice, screen.getIndex());

    final GraphicsConfigurationFactory factory =
        GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice(), capsRequested);
    final AbstractGraphicsConfiguration cfg =
        factory.chooseGraphicsConfiguration(
            capsRequested,
            capsRequested,
            capabilitiesChooser,
            renderScreen,
            VisualIDHolder.VID_UNDEFINED);
    if (DEBUG_IMPLEMENTATION) {
      System.err.println(
          "X11Window.createNativeImpl() factory: " + factory + ", chosen config: " + cfg);
    }
    if (null == cfg) {
      throw new NativeWindowException(
          "Error choosing GraphicsConfiguration creating window: " + this);
    }
    final int visualID = cfg.getVisualID(VIDType.NATIVE);
    if (VisualIDHolder.VID_UNDEFINED == visualID) {
      throw new NativeWindowException("Chosen Configuration w/o native visual ID: " + cfg);
    }
    setGraphicsConfiguration(cfg);
    final int flags = getReconfigureFlags(0, true) & (FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED);
    edtDevice.lock();
    try {
      setWindowHandle(
          CreateWindow0(
              getParentWindowHandle(),
              edtDevice.getHandle(),
              screen.getIndex(),
              visualID,
              display.getJavaObjectAtom(),
              display.getWindowDeleteAtom(),
              getX(),
              getY(),
              getWidth(),
              getHeight(),
              autoPosition(),
              flags));
    } finally {
      edtDevice.unlock();
    }
    windowHandleClose = getWindowHandle();
    if (0 == windowHandleClose) {
      throw new NativeWindowException("Error creating window");
    }
  }
  protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationXVisual(
      GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) {
    if (chooser == null) {
      chooser = new DefaultGLCapabilitiesChooser();
    }

    // Until we have a rock-solid visual selection algorithm written
    // in pure Java, we're going to provide the underlying window
    // system's selection to the chooser as a hint

    GLProfile glProfile = capabilities.getGLProfile();
    boolean onscreen = capabilities.isOnscreen();
    GLCapabilities[] caps = null;
    int recommendedIndex = -1;
    XVisualInfo retXVisualInfo = null;
    int chosen = -1;

    AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    long display = absDevice.getHandle();
    try {
      NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
      X11Lib.XLockDisplay(display);
      int screen = x11Screen.getIndex();
      boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display);
      int[] attribs =
          X11GLXGraphicsConfiguration.GLCapabilities2AttribList(
              capabilities, false, isMultisampleAvailable, display, screen);
      XVisualInfo[] infos = null;

      XVisualInfo recommendedVis = GLX.glXChooseVisualCopied(display, screen, attribs, 0);
      if (DEBUG) {
        System.err.print("!!! glXChooseVisual recommended ");
        if (recommendedVis == null) {
          System.err.println("null visual");
        } else {
          System.err.println("visual id 0x" + Long.toHexString(recommendedVis.getVisualid()));
        }
      }
      int[] count = new int[1];
      XVisualInfo template = XVisualInfo.create();
      template.setScreen(screen);
      infos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, template, count, 0);
      if (infos == null || infos.length < 1) {
        throw new GLException("Error while enumerating available XVisualInfos");
      }
      caps = new GLCapabilities[infos.length];
      for (int i = 0; i < infos.length; i++) {
        caps[i] =
            X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(
                glProfile, display, infos[i], onscreen, false, isMultisampleAvailable);
        // Attempt to find the visual chosen by glXChooseVisual
        if (recommendedVis != null && recommendedVis.getVisualid() == infos[i].getVisualid()) {
          recommendedIndex = i;
        }
      }
      try {
        chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex);
      } catch (NativeWindowException e) {
        if (DEBUG) {
          e.printStackTrace();
        }
        chosen = -1;
      }
      if (chosen < 0) {
        // keep on going ..
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual Failed .. unable to choose config, using first");
        }
        chosen = 0; // default ..
      } else if (chosen >= caps.length) {
        throw new GLException(
            "GLCapabilitiesChooser specified invalid index (expected 0.."
                + (caps.length - 1)
                + ")");
      }
      if (infos[chosen] == null) {
        throw new GLException("GLCapabilitiesChooser chose an invalid visual");
      }
      retXVisualInfo = XVisualInfo.create(infos[chosen]);
    } finally {
      X11Lib.XUnlockDisplay(display);
      NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
    }
    return new X11GLXGraphicsConfiguration(
        x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, 0, -1);
  }
  protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig(
      GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) {
    int recommendedIndex = -1;
    GLCapabilities[] caps = null;
    PointerBuffer fbcfgsL = null;
    int chosen = -1;
    int retFBID = -1;
    XVisualInfo retXVisualInfo = null;
    GLProfile glProfile = capabilities.getGLProfile();
    boolean onscreen = capabilities.isOnscreen();
    boolean usePBuffer = capabilities.isPBuffer();

    // Utilizing FBConfig
    //
    AbstractGraphicsDevice absDevice = x11Screen.getDevice();
    long display = absDevice.getHandle();
    try {
      NativeWindowFactory.getDefaultFactory().getToolkitLock().lock();
      X11Lib.XLockDisplay(display);
      int screen = x11Screen.getIndex();
      boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display);
      int[] attribs =
          X11GLXGraphicsConfiguration.GLCapabilities2AttribList(
              capabilities, true, isMultisampleAvailable, display, screen);
      int[] count = {-1};

      fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0);
      if (fbcfgsL == null || fbcfgsL.limit() < 1) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig ("
                  + x11Screen
                  + ","
                  + capabilities
                  + "): "
                  + fbcfgsL
                  + ", "
                  + count[0]);
        }
        return null;
      }
      if (!X11GLXGraphicsConfiguration.GLXFBConfigValid(display, fbcfgsL.get(0))) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: ("
                  + x11Screen
                  + ","
                  + capabilities
                  + "): "
                  + fbcfgsL
                  + ", fbcfg: 0x"
                  + Long.toHexString(fbcfgsL.get(0)));
        }
        return null;
      }
      recommendedIndex = 0; // 1st match is always recommended ..
      caps = new GLCapabilities[fbcfgsL.limit()];
      for (int i = 0; i < fbcfgsL.limit(); i++) {
        caps[i] =
            X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(
                glProfile,
                display,
                fbcfgsL.get(i),
                false,
                onscreen,
                usePBuffer,
                isMultisampleAvailable);
      }

      if (null == chooser) {
        chosen = recommendedIndex;
      } else {
        try {
          chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex);
        } catch (NativeWindowException e) {
          if (DEBUG) {
            e.printStackTrace();
          }
          chosen = -1;
        }
      }
      if (chosen < 0) {
        // keep on going ..
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first");
        }
        chosen = 0; // default ..
      } else if (chosen >= caps.length) {
        throw new GLException(
            "GLCapabilitiesChooser specified invalid index (expected 0.."
                + (caps.length - 1)
                + ")");
      }

      retFBID = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfgsL.get(chosen));

      retXVisualInfo = GLX.glXGetVisualFromFBConfigCopied(display, fbcfgsL.get(chosen));
      if (retXVisualInfo == null) {
        if (DEBUG) {
          System.err.println(
              "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig ("
                  + x11Screen
                  + ", "
                  + fbcfgsL.get(chosen)
                  + " (Continue: "
                  + (false == caps[chosen].isOnscreen())
                  + "):\n\t"
                  + caps[chosen]);
        }
        if (caps[chosen].isOnscreen()) {
          // Onscreen drawables shall have a XVisual ..
          return null;
        }
      }
    } finally {
      X11Lib.XUnlockDisplay(display);
      NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock();
    }

    return new X11GLXGraphicsConfiguration(
        x11Screen,
        caps[chosen],
        capabilities,
        chooser,
        retXVisualInfo,
        fbcfgsL.get(chosen),
        retFBID);
  }
  private final void evalUpstreamSurface(String dbgPrefix, ProxySurface surface) {
    //
    // evaluate nature of upstreamSurface, may create EGL instances if required
    //

    boolean isEGLSurfaceValid = true; // assume yes

    final EGLGraphicsDevice eglDevice;
    final AbstractGraphicsConfiguration aConfig;
    {
      final AbstractGraphicsConfiguration surfaceConfig = surface.getGraphicsConfiguration();
      final AbstractGraphicsDevice surfaceDevice =
          null != surfaceConfig ? surfaceConfig.getScreen().getDevice() : null;
      if (DEBUG) {
        System.err.println(
            dbgPrefix
                + "SurfaceDevice: "
                + surfaceDevice.getClass().getSimpleName()
                + ", hash 0x"
                + Integer.toHexString(surfaceDevice.hashCode())
                + ", "
                + surfaceDevice);
        System.err.println(
            dbgPrefix
                + "SurfaceConfig: "
                + surfaceConfig.getClass().getSimpleName()
                + ", hash 0x"
                + Integer.toHexString(surfaceConfig.hashCode())
                + ", "
                + surfaceConfig);
      }

      final AbstractGraphicsConfiguration upstreamConfig =
          upstreamSurface.getGraphicsConfiguration();
      final AbstractGraphicsDevice upstreamDevice = upstreamConfig.getScreen().getDevice();
      if (DEBUG) {
        System.err.println(
            dbgPrefix
                + "UpstreamDevice: "
                + upstreamDevice.getClass().getSimpleName()
                + ", hash 0x"
                + Integer.toHexString(upstreamDevice.hashCode())
                + ", "
                + upstreamDevice);
        System.err.println(
            dbgPrefix
                + "UpstreamConfig: "
                + upstreamConfig.getClass().getSimpleName()
                + ", hash 0x"
                + Integer.toHexString(upstreamConfig.hashCode())
                + ", "
                + upstreamConfig);
      }

      if (surfaceDevice instanceof EGLGraphicsDevice) {
        eglDevice = (EGLGraphicsDevice) surfaceDevice;
        aConfig = surfaceConfig;
        if (DEBUG) {
          System.err.println(
              dbgPrefix
                  + "Reusing this eglDevice: "
                  + eglDevice
                  + ", using this config "
                  + aConfig.getClass().getSimpleName()
                  + " "
                  + aConfig);
        }
        if (EGL.EGL_NO_DISPLAY == eglDevice.getHandle()) {
          eglDevice.open();
          isEGLSurfaceValid = false;
          surface.addUpstreamOptionBits(ProxySurface.OPT_PROXY_OWNS_UPSTREAM_DEVICE);
        }
      } else if (upstreamDevice instanceof EGLGraphicsDevice) {
        eglDevice = (EGLGraphicsDevice) upstreamDevice;
        aConfig = upstreamConfig;
        if (DEBUG) {
          System.err.println(
              dbgPrefix
                  + "Reusing upstream eglDevice: "
                  + eglDevice
                  + ", using upstream config "
                  + aConfig.getClass().getSimpleName()
                  + " "
                  + aConfig);
        }
        if (EGL.EGL_NO_DISPLAY == eglDevice.getHandle()) {
          eglDevice.open();
          isEGLSurfaceValid = false;
          surface.addUpstreamOptionBits(ProxySurface.OPT_PROXY_OWNS_UPSTREAM_DEVICE);
        }
      } else {
        eglDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(upstreamSurface);
        eglDevice.open();
        aConfig = upstreamConfig;
        isEGLSurfaceValid = false;
        surface.addUpstreamOptionBits(ProxySurface.OPT_PROXY_OWNS_UPSTREAM_DEVICE);
      }
    }

    final GLCapabilitiesImmutable capsRequested =
        (GLCapabilitiesImmutable) aConfig.getRequestedCapabilities();
    final EGLGraphicsConfiguration eglConfig;
    if (aConfig instanceof EGLGraphicsConfiguration) {
      // Config is already in EGL type - reuse ..
      final EGLGLCapabilities capsChosen = (EGLGLCapabilities) aConfig.getChosenCapabilities();
      if (!isEGLSurfaceValid
          || !EGLGraphicsConfiguration.isEGLConfigValid(
              eglDevice.getHandle(), capsChosen.getEGLConfig())) {
        // 'refresh' the native EGLConfig handle
        capsChosen.setEGLConfig(
            EGLGraphicsConfiguration.EGLConfigId2EGLConfig(
                eglDevice.getHandle(), capsChosen.getEGLConfigID()));
        if (0 == capsChosen.getEGLConfig()) {
          throw new GLException(
              "Refreshing native EGLConfig handle failed with error "
                  + EGLContext.toHexString(EGL.eglGetError())
                  + ": "
                  + eglDevice
                  + ", "
                  + capsChosen
                  + " of "
                  + aConfig);
        }
        final AbstractGraphicsScreen eglScreen =
            new DefaultGraphicsScreen(eglDevice, aConfig.getScreen().getIndex());
        eglConfig = new EGLGraphicsConfiguration(eglScreen, capsChosen, capsRequested, null);
        if (DEBUG) {
          System.err.println(dbgPrefix + "Refreshing eglConfig: " + eglConfig);
        }
        isEGLSurfaceValid = false;
      } else {
        eglConfig = (EGLGraphicsConfiguration) aConfig;
        if (DEBUG) {
          System.err.println(dbgPrefix + "Reusing eglConfig: " + eglConfig);
        }
      }
    } else {
      final AbstractGraphicsScreen eglScreen =
          new DefaultGraphicsScreen(eglDevice, aConfig.getScreen().getIndex());
      eglConfig =
          EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
              capsRequested,
              capsRequested,
              null,
              eglScreen,
              aConfig.getVisualID(VIDType.NATIVE),
              false /* forceTransparencyFlag */);

      if (null == eglConfig) {
        throw new GLException("Couldn't create EGLGraphicsConfiguration from " + eglScreen);
      } else if (DEBUG) {
        System.err.println(dbgPrefix + "Chosen eglConfig: " + eglConfig);
      }
      isEGLSurfaceValid = false;
    }
    surface.setGraphicsConfiguration(eglConfig);

    if (isEGLSurfaceValid) {
      isEGLSurfaceValid =
          EGLDrawable.isValidEGLSurface(eglDevice.getHandle(), upstreamSurface.getSurfaceHandle());
    }
    if (isEGLSurfaceValid) {
      surface.setSurfaceHandle(upstreamSurface.getSurfaceHandle());
      surface.clearUpstreamOptionBits(ProxySurface.OPT_PROXY_OWNS_UPSTREAM_SURFACE);
      if (DEBUG) {
        System.err.println(
            dbgPrefix + "Fin: Already valid EGL surface - use as-is: " + upstreamSurface);
      }
    } else {
      surface.setSurfaceHandle(EGL.EGL_NO_SURFACE);
      surface.addUpstreamOptionBits(
          ProxySurface.OPT_PROXY_OWNS_UPSTREAM_SURFACE); // create/destroy in EGLDrawable
      if (DEBUG) {
        System.err.println(dbgPrefix + "Fin: EGL surface n/a - TBD: " + upstreamSurface);
      }
    }
  }