java.awt.GraphicsConfiguration Java Examples
The following examples show how to use
java.awt.GraphicsConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageCombiner.java From Spark with Apache License 2.0 | 9 votes |
/** * Creates an Image from the specified Icon * * @param icon * that should be converted to an image * @return the new image */ public static Image iconToImage(Icon icon) { if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); } else { int w = icon.getIconWidth(); int h = icon.getIconHeight(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(w, h); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose(); return image; } }
Example #2
Source File: IncorrectAlphaConversionBicubic.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc, int type) { BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type); Graphics2D g2d = img.createGraphics(); g2d.setColor(RGB); g2d.fillRect(0, 0, SIZE, SIZE); g2d.dispose(); final DataBuffer db = img.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { ((DataBufferInt) db).getData(); } else if (db instanceof DataBufferShort) { ((DataBufferShort) db).getData(); } else if (db instanceof DataBufferByte) { ((DataBufferByte) db).getData(); } else { try { img.setAccelerationPriority(0.0f); } catch (final Throwable ignored) { } } return img; }
Example #3
Source File: VolatileSurfaceManager.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Creates a software-based surface (of type BufImgSurfaceData). * The software representation is only created when needed, which * is only during some situation in which the hardware surface * cannot be allocated. This allows apps to at least run, * albeit more slowly than they would otherwise. */ protected SurfaceData getBackupSurface() { if (sdBackup == null) { GraphicsConfiguration gc = vImg.getGraphicsConfig(); AffineTransform tx = gc.getDefaultTransform(); double scaleX = tx.getScaleX(); double scaleY = tx.getScaleY(); BufferedImage bImg = vImg.getBackupImage(scaleX, scaleY); // Sabotage the acceleration capabilities of the BufImg surface SunWritableRaster.stealTrackable(bImg .getRaster() .getDataBuffer()).setUntrackable(); sdBackup = BufImgSurfaceData.createData(bImg, scaleX, scaleY); } return sdBackup; }
Example #4
Source File: VolatileImageBug.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { boolean iaeThrown = false; GraphicsEnvironment ge = GraphicsEnvironment. getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice(). getDefaultConfiguration(); try { VolatileImage volatileImage = gc.createCompatibleVolatileImage(0, 0); } catch (IllegalArgumentException iae) { iaeThrown = true; } if (!iaeThrown) { throw new RuntimeException ("IllegalArgumentException not thrown " + "for createCompatibleVolatileImage(0,0)"); } }
Example #5
Source File: TranslucentWindowPainter.java From hottub with GNU General Public License v2.0 | 6 votes |
@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; }
Example #6
Source File: TransformedPaintTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private void runTest() { GraphicsConfiguration gc = GraphicsEnvironment. getLocalGraphicsEnvironment().getDefaultScreenDevice(). getDefaultConfiguration(); if (gc.getColorModel().getPixelSize() < 16) { System.out.println("8-bit desktop depth found, test passed"); return; } VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT); BufferedImage bi = null; do { vi.validate(gc); Graphics2D g = vi.createGraphics(); render(g, vi.getWidth(), vi.getHeight()); bi = vi.getSnapshot(); } while (vi.contentsLost()); checkBI(bi); System.out.println("Test PASSED."); }
Example #7
Source File: XComponentPeer.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public boolean updateGraphicsData(GraphicsConfiguration gc) { int oldVisual = -1, newVisual = -1; if (graphicsConfig != null) { oldVisual = graphicsConfig.getVisual(); } if (gc != null && gc instanceof X11GraphicsConfig) { newVisual = ((X11GraphicsConfig)gc).getVisual(); } // If the new visual differs from the old one, the peer must be // recreated because X11 does not allow changing the visual on the fly. // So we even skip the initGraphicsConfiguration() call. // The initial assignment should happen though, hence the != -1 thing. if (oldVisual != -1 && oldVisual != newVisual) { return true; } initGraphicsConfiguration(); doValidateSurface(); return false; }
Example #8
Source File: RSLAPITest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); testGC(gc); if (failed) { throw new RuntimeException("Test FAILED. See err output for more"); } System.out.println("Test PASSED."); }
Example #9
Source File: XRVolatileSurfaceManager.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Need to override the default behavior because Pixmaps-based * images are accelerated but not volatile. */ @Override public ImageCapabilities getCapabilities(GraphicsConfiguration gc) { if (isConfigValid(gc) && isAccelerationEnabled()) { return new ImageCapabilities(true); } return new ImageCapabilities(false); }
Example #10
Source File: X11GraphicsDevice.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private DisplayMode getDefaultDisplayMode() { GraphicsConfiguration gc = getDefaultConfiguration(); Rectangle r = gc.getBounds(); return new DisplayMode(r.width, r.height, DisplayMode.BIT_DEPTH_MULTI, DisplayMode.REFRESH_RATE_UNKNOWN); }
Example #11
Source File: IncorrectAlphaConversionBicubic.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) { final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); final GraphicsConfiguration gc = gd.getDefaultConfiguration(); final VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT); final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT); final int expected = bi.getRGB(2, 2); int attempt = 0; BufferedImage snapshot; while (true) { if (++attempt > 10) { throw new RuntimeException("Too many attempts: " + attempt); } vi.validate(gc); final Graphics2D g2d = vi.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.scale(2, 2); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.drawImage(bi, 0, 0, null); g2d.dispose(); snapshot = vi.getSnapshot(); if (vi.contentsLost()) { continue; } break; } final int actual = snapshot.getRGB(2, 2); if (actual != expected) { System.err.println("Actual: " + Integer.toHexString(actual)); System.err.println("Expected: " + Integer.toHexString(expected)); throw new RuntimeException("Test failed"); } }
Example #12
Source File: ServiceDialog.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Constructor for the solitary "page setup" dialog */ public ServiceDialog(GraphicsConfiguration gc, int x, int y, PrintService ps, DocFlavor flavor, PrintRequestAttributeSet attributes, Dialog dialog) { super(dialog, getMsg("dialog.pstitle"), true, gc); initPageDialog(x, y, ps, flavor, attributes); }
Example #13
Source File: SourceClippingBlitTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static Image getBufferedImage(GraphicsConfiguration gc, int w, int h, int type, boolean acceleratable) { BufferedImage image = new BufferedImage(w, h, type); if (!acceleratable) { image.setAccelerationPriority(0.0f); } initImage(gc, image); return image; }
Example #14
Source File: DrawCachedImageAndTransform.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); VolatileImage vi = gc.createCompatibleVolatileImage(100, 100); Graphics2D g2d = vi.createGraphics(); g2d.scale(2, 2); BufferedImage img = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); g2d.drawImage(img, 10, 25, Color.blue, null); g2d.dispose(); }
Example #15
Source File: XRVolatileSurfaceManager.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Need to override the default behavior because Pixmaps-based * images are accelerated but not volatile. */ @Override public ImageCapabilities getCapabilities(GraphicsConfiguration gc) { if (isConfigValid(gc) && isAccelerationEnabled()) { return new ImageCapabilities(true); } return new ImageCapabilities(false); }
Example #16
Source File: OpaqueImageToSurfaceBlitTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); VolatileImage vi = gc.createCompatibleVolatileImage(16, 16); vi.validate(gc); BufferedImage bi = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB); int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); data[0] = 0x0000007f; data[1] = 0x0000007f; data[2] = 0xff00007f; data[3] = 0xff00007f; Graphics2D g = vi.createGraphics(); g.setComposite(AlphaComposite.SrcOver.derive(0.999f)); g.drawImage(bi, 0, 0, null); bi = vi.getSnapshot(); if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) { throw new RuntimeException("Test FAILED: color at 0x0 ="+ Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+ Integer.toHexString(bi.getRGB(1,1))); } System.out.println("Test PASSED."); }
Example #17
Source File: UnmanagedDrawImagePerformance.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static VolatileImage makeVI(final int type) { final GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); final GraphicsConfiguration gc = gd.getDefaultConfiguration(); return gc.createCompatibleVolatileImage(SIZE, SIZE, type); }
Example #18
Source File: IncorrectClipSurface2SW.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) throws IOException { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); AffineTransform at; for (final int size : SIZES) { for (final int scale : SCALES) { final int sw = size * scale; at = AffineTransform.getScaleInstance(sw, sw); for (Shape clip : SHAPES) { clip = at.createTransformedShape(clip); for (Shape to : SHAPES) { to = at.createTransformedShape(to); // Prepare test images VolatileImage vi = getVolatileImage(gc, size); BufferedImage bi = getBufferedImage(sw); // Prepare gold images BufferedImage goldvi = getCompatibleImage(gc, size); BufferedImage goldbi = getBufferedImage(sw); draw(clip, to, vi, bi, scale); draw(clip, to, goldvi, goldbi, scale); validate(bi, goldbi); } } } } }
Example #19
Source File: OGLUtilities.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Invokes the given Runnable on the OGL QueueFlusher thread with the * "shared" OpenGL context (corresponding to the given * GraphicsConfiguration object) made current. This method is typically * used when the Runnable needs a current context to complete its * operation, but does not require that the context be made current to * a particular surface. For example, an application may call this * method so that the given Runnable can query the OpenGL capabilities * of the given GraphicsConfiguration, without making a context current * to a dummy surface (or similar hacky techniques). * * In order to avoid deadlock, it is important that the given Runnable * does not attempt to acquire the AWT lock, as that will be handled * automatically as part of the <code>rq.flushAndInvokeNow()</code> step. * * @param config the GraphicsConfiguration object whose "shared" * context will be made current during this operation; if this value is * null or if OpenGL is not enabled for the GraphicsConfiguration, this * method will return false * @param r the action to be performed on the QFT; cannot be null * @return true if the operation completed successfully, or false if * there was any problem making the shared context current */ public static boolean invokeWithOGLSharedContextCurrent(GraphicsConfiguration config, Runnable r) { if (!(config instanceof OGLGraphicsConfig)) { return false; } OGLRenderQueue rq = OGLRenderQueue.getInstance(); rq.lock(); try { // make the "shared" context current for the given GraphicsConfig OGLContext.setScratchSurface((OGLGraphicsConfig)config); // invoke the given runnable on the QFT rq.flushAndInvokeNow(r); // invalidate the current context so that the next time we render // with Java 2D, the context state will be completely revalidated OGLContext.invalidateCurrentContext(); } finally { rq.unlock(); } return true; }
Example #20
Source File: RSLAPITest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); testGC(gc); if (failed) { throw new RuntimeException("Test FAILED. See err output for more"); } System.out.println("Test PASSED."); }
Example #21
Source File: SourceClippingBlitTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
static Image getBMImage(GraphicsConfiguration gc, int w, int h) { Image image = gc.createCompatibleImage(w, h, Transparency.BITMASK); initImage(gc, image); return image; }
Example #22
Source File: ScreenshotUtil.java From haxademic with MIT License | 5 votes |
public static Rectangle2D getFullScreenBounds() { // NOTE! main monitor must be top left, otherwise, override x+y position Rectangle2D result = new Rectangle2D.Double(); GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (GraphicsDevice gd : localGE.getScreenDevices()) { for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) { Rectangle2D.union(result, graphicsConfiguration.getBounds(), result); } } return result; }
Example #23
Source File: X11VolatileSurfaceManager.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Need to override the default behavior because Pixmaps-based * images are accelerated but not volatile. */ @Override public ImageCapabilities getCapabilities(GraphicsConfiguration gc) { if (isConfigValid(gc) && isAccelerationEnabled()) { // accelerated but not volatile return new ImageCapabilities(true); } // neither accelerated nor volatile return new ImageCapabilities(false); }
Example #24
Source File: CustomCompositeTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static void testVolatileImage(GraphicsConfiguration cfg, boolean accelerated) { VolatileImage dst = null; try { dst = cfg.createCompatibleVolatileImage(640, 480, new ImageCapabilities(accelerated)); } catch (AWTException e) { System.out.println("Unable to create volatile image, skip the test."); return; } renderToVolatileImage(dst); }
Example #25
Source File: IncorrectAlphaConversionBicubic.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) { final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); final GraphicsConfiguration gc = gd.getDefaultConfiguration(); final VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT); final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT); final int expected = bi.getRGB(2, 2); int attempt = 0; BufferedImage snapshot; while (true) { if (++attempt > 10) { throw new RuntimeException("Too many attempts: " + attempt); } vi.validate(gc); final Graphics2D g2d = vi.createGraphics(); g2d.setComposite(AlphaComposite.Src); g2d.scale(2, 2); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.drawImage(bi, 0, 0, null); g2d.dispose(); snapshot = vi.getSnapshot(); if (vi.contentsLost()) { continue; } break; } final int actual = snapshot.getRGB(2, 2); if (actual != expected) { System.err.println("Actual: " + Integer.toHexString(actual)); System.err.println("Expected: " + Integer.toHexString(expected)); throw new RuntimeException("Test failed"); } }
Example #26
Source File: FontStyleIcon.java From RipplePower with Apache License 2.0 | 5 votes |
private void calcImageBufferSize() { GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); BufferedImage buff = config.createCompatibleImage(1, 1, Transparency.TRANSLUCENT); Graphics2D g2 = buff.createGraphics(); g2.setFont(font); LineMetrics lm = font.getLineMetrics(String.valueOf(icon), g2.getFontRenderContext()); iconWidth = g2.getFontMetrics().charWidth(icon.getChar()); iconHeight = (int) lm.getHeight(); iconBaseline = (int) (lm.getHeight() - lm.getLeading() - lm.getDescent()); g2.dispose(); }
Example #27
Source File: ServiceDialog.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Constructor for the solitary "page setup" dialog */ public ServiceDialog(GraphicsConfiguration gc, int x, int y, PrintService ps, DocFlavor flavor, PrintRequestAttributeSet attributes, Frame frame) { super(frame, getMsg("dialog.pstitle"), true, gc); initPageDialog(x, y, ps, flavor, attributes); }
Example #28
Source File: IncorrectClipSurface2SW.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static VolatileImage getVolatileImage(GraphicsConfiguration gc, int size) { VolatileImage vi = gc.createCompatibleVolatileImage(size, size); Graphics2D g2d = vi.createGraphics(); g2d.setColor(Color.GREEN); g2d.fillRect(0, 0, size, size); return vi; }
Example #29
Source File: InfiniteValidationLoopTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void runTest(Graphics g) { int status = IMAGE_OK; int count1 = 0; do { GraphicsConfiguration gc = getGraphicsConfiguration(); int count2 = 0; while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) { if (++count2 > LOOP_THRESHOLD) { System.err.println("Infinite loop detected: count2="+count2); failed = true; return; } if (vi == null || status == IMAGE_INCOMPATIBLE) { if (vi != null) { vi.flush(); vi = null; } vi = gc.createCompatibleVolatileImage(100, 100); continue; } if (status == IMAGE_RESTORED) { Graphics gg = vi.getGraphics(); gg.setColor(Color.green); gg.fillRect(0, 0, vi.getWidth(), vi.getHeight()); break; } } g.drawImage(vi, getInsets().left, getInsets().top, null); if (++count1 > LOOP_THRESHOLD) { System.err.println("Infinite loop detected: count1="+count1); failed = true; return; } } while (vi.contentsLost()); }
Example #30
Source File: SunVolatileImage.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private SunVolatileImage(Component comp, GraphicsConfiguration graphicsConfig, int width, int height, Object context, ImageCapabilities caps) { this(comp, graphicsConfig, width, height, context, Transparency.OPAQUE, caps, UNDEFINED); }