/** * Creates an instance of the painter for particular peer. */ public static TranslucentWindowPainter createInstance(WWindowPeer peer) { GraphicsConfiguration gc = peer.getGraphicsConfiguration(); if (!forceSW && gc instanceof AccelGraphicsConfig) { String gcName = gc.getClass().getSimpleName(); AccelGraphicsConfig agc = (AccelGraphicsConfig)gc; // this is a heuristic to check that we have a pcix board // (those have higher transfer rate from gpu to cpu) if ((agc.getContextCapabilities().getCaps() & CAPS_PS30) != 0 || forceOpt) { // we check for name to avoid loading classes unnecessarily if // a pipeline isn't enabled if (gcName.startsWith("D3D")) { return new VIOptD3DWindowPainter(peer); } else if (forceOpt && gcName.startsWith("WGL")) { // on some boards (namely, ATI, even on pcix bus) ogl is // very slow reading pixels back so for now it is disabled // unless forced return new VIOptWGLWindowPainter(peer); } } } return new BIWindowPainter(peer); }
@Override protected Image getBackBuffer(boolean clear) { int w = window.getWidth(); int h = window.getHeight(); GraphicsConfiguration gc = peer.getGraphicsConfiguration(); if (viBB == null || viBB.getWidth() != w || viBB.getHeight() != h || viBB.validate(gc) == IMAGE_INCOMPATIBLE) { flush(); if (gc instanceof AccelGraphicsConfig) { AccelGraphicsConfig agc = ((AccelGraphicsConfig)gc); viBB = agc.createCompatibleVolatileImage(w, h, TRANSLUCENT, RT_PLAIN); } if (viBB == null) { viBB = gc.createCompatibleVolatileImage(w, h, TRANSLUCENT); } viBB.validate(gc); } return clear ? clearImage(viBB) : viBB; }
private static void testContext(final AccelGraphicsConfig agc) { BufferedContext c = agc.getContext(); final AccelDeviceEventListener l = new AccelDeviceEventListener() { public void onDeviceDispose() { System.out.println("onDeviceDispose invoked"); agc.removeDeviceEventListener(this); } public void onDeviceReset() { System.out.println("onDeviceReset invoked"); } }; agc.addDeviceEventListener(l); RenderQueue rq = c.getRenderQueue(); rq.lock(); try { c.saveState(); rq.flushNow(); c.restoreState(); rq.flushNow(); System.out.println("Passed: Save/Restore"); } finally { rq.unlock(); } }
private static void printAGC(AccelGraphicsConfig agc) { System.out.println("Accelerated Graphics Config: " + agc); System.out.println("Capabilities:"); System.out.printf("AGC caps: 0x%x\n", agc.getContextCapabilities().getCaps()); System.out.println(agc.getContextCapabilities()); }
private static void testGC(GraphicsConfiguration gc) { if (!(gc instanceof AccelGraphicsConfig)) { System.out.println("Test passed: no hw accelerated configs found."); return; } System.out.println("AccelGraphicsConfig exists, testing."); AccelGraphicsConfig agc = (AccelGraphicsConfig) gc; printAGC(agc); testContext(agc); VolatileImage vi = gc.createCompatibleVolatileImage(10, 10); vi.validate(gc); if (vi instanceof DestSurfaceProvider) { System.out.println("Passed: VI is DestSurfaceProvider"); Surface s = ((DestSurfaceProvider) vi).getDestSurface(); if (s instanceof AccelSurface) { System.out.println("Passed: Obtained Accel Surface"); printSurface((AccelSurface) s); } Graphics g = vi.getGraphics(); if (g instanceof DestSurfaceProvider) { System.out.println("Passed: VI graphics is " + "DestSurfaceProvider"); printSurface(((DestSurfaceProvider) g).getDestSurface()); } } else { System.out.println("VI is not DestSurfaceProvider"); } testVICreation(agc, CAPS_RT_TEXTURE_ALPHA, TRANSLUCENT, RT_TEXTURE); testVICreation(agc, CAPS_RT_TEXTURE_OPAQUE, OPAQUE, RT_TEXTURE); testVICreation(agc, CAPS_RT_PLAIN_ALPHA, TRANSLUCENT, RT_PLAIN); testVICreation(agc, agc.getContextCapabilities().getCaps(), OPAQUE, TEXTURE); testForNPEDuringCreation(agc); }