public void unlockSurface() {
   if (hdc == 0) {
     throw new GLException("Surface already unlocked");
   }
   long startTime = 0;
   if (PROFILING) {
     startTime = System.currentTimeMillis();
   }
   ds.FreeDrawingSurfaceInfo(dsi);
   ds.Unlock();
   JAWT.getJAWT().FreeDrawingSurface(ds);
   ds = null;
   dsi = null;
   win32dsi = null;
   hdc = 0;
   if (PROFILING) {
     long endTime = System.currentTimeMillis();
     profilingUnlockSurfaceTime += (endTime - startTime);
     int ticks = PROFILING_TICKS;
     if (++profilingUnlockSurfaceTicks == ticks) {
       System.err.println(
           "UnlockSurface calls: "
               + profilingUnlockSurfaceTime
               + " ms / "
               + ticks
               + " calls ("
               + ((float) profilingUnlockSurfaceTime / (float) ticks)
               + " ms/call)");
       profilingUnlockSurfaceTime = 0;
       profilingUnlockSurfaceTicks = 0;
     }
   }
 }
 public int lockSurface() throws GLException {
   if (!realized) {
     return LOCK_SURFACE_NOT_READY;
   }
   if (hdc != 0) {
     throw new GLException("Surface already locked");
   }
   long startTime = 0;
   if (PROFILING) {
     startTime = System.currentTimeMillis();
   }
   ds = JAWT.getJAWT().GetDrawingSurface(component);
   if (ds == null) {
     // Widget not yet realized
     return LOCK_SURFACE_NOT_READY;
   }
   int res = ds.Lock();
   if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) {
     throw new GLException("Unable to lock surface");
   }
   // See whether the surface changed and if so destroy the old
   // OpenGL context so it will be recreated (NOTE: removeNotify
   // should handle this case, but it may be possible that race
   // conditions can cause this code to be triggered -- should test
   // more)
   int ret = LOCK_SUCCESS;
   if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
     ret = LOCK_SURFACE_CHANGED;
   }
   dsi = ds.GetDrawingSurfaceInfo();
   if (dsi == null) {
     // Widget not yet realized
     ds.Unlock();
     JAWT.getJAWT().FreeDrawingSurface(ds);
     ds = null;
     return LOCK_SURFACE_NOT_READY;
   }
   win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo();
   hdc = win32dsi.hdc();
   if (hdc == 0) {
     // Widget not yet realized
     ds.FreeDrawingSurfaceInfo(dsi);
     ds.Unlock();
     JAWT.getJAWT().FreeDrawingSurface(ds);
     ds = null;
     dsi = null;
     win32dsi = null;
     return LOCK_SURFACE_NOT_READY;
   }
   if (!pixelFormatChosen) {
     try {
       choosePixelFormat(true);
       setPixelFormatFailCount = 0;
     } catch (RuntimeException e) {
       // Workaround for problems seen on Intel 82855 cards in particular
       // Make it look like the lockSurface() call didn't succeed
       unlockSurface();
       if (e instanceof GLException) {
         if (++setPixelFormatFailCount == MAX_SET_PIXEL_FORMAT_FAIL_COUNT) {
           setPixelFormatFailCount = 0;
           throw e;
         }
         return LOCK_SURFACE_NOT_READY;
       } else {
         // Probably a user error in the GLCapabilitiesChooser or similar.
         // Don't propagate non-GLExceptions out because calling code
         // expects to catch only that exception type
         throw new GLException(e);
       }
     }
   }
   if (PROFILING) {
     long endTime = System.currentTimeMillis();
     profilingLockSurfaceTime += (endTime - startTime);
     int ticks = PROFILING_TICKS;
     if (++profilingLockSurfaceTicks == ticks) {
       System.err.println(
           "LockSurface calls: "
               + profilingLockSurfaceTime
               + " ms / "
               + ticks
               + " calls ("
               + ((float) profilingLockSurfaceTime / (float) ticks)
               + " ms/call)");
       profilingLockSurfaceTime = 0;
       profilingLockSurfaceTicks = 0;
     }
   }
   return ret;
 }