use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class TransformSetGet method main.
public static void main(final String[] args) {
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
final VolatileImage vi = gc.createCompatibleVolatileImage(200, 200);
final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();
sg2d.constrain(0, 61, 100, 100);
final AffineTransform expected = sg2d.cloneTransform();
sg2d.setTransform(sg2d.getTransform());
final AffineTransform actual = sg2d.cloneTransform();
sg2d.dispose();
vi.flush();
if (!expected.equals(actual)) {
System.out.println("Expected = " + expected);
System.out.println("Actual = " + actual);
throw new RuntimeException("Wrong transform");
}
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class MultiResolutionSplashTest method getScaleFactor.
static float getScaleFactor() {
final Dialog dialog = new Dialog((Window) null);
dialog.setSize(100, 100);
dialog.setModal(true);
final float[] scaleFactors = new float[1];
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
float scaleFactor = 1;
if (g instanceof SunGraphics2D) {
scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
}
scaleFactors[0] = scaleFactor;
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
dialog.dispose();
return scaleFactors[0];
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class WGLGraphicsConfig method flip.
/**
* Performs the native WGL flip operation for the given target Component.
*/
@Override
public void flip(WComponentPeer peer, Component target, VolatileImage backBuffer, int x1, int y1, int x2, int y2, BufferCapabilities.FlipContents flipAction) {
if (flipAction == BufferCapabilities.FlipContents.COPIED) {
SurfaceManager vsm = SurfaceManager.getManager(backBuffer);
SurfaceData sd = vsm.getPrimarySurfaceData();
if (sd instanceof WGLVSyncOffScreenSurfaceData) {
WGLVSyncOffScreenSurfaceData vsd = (WGLVSyncOffScreenSurfaceData) sd;
SurfaceData bbsd = vsd.getFlipSurface();
Graphics2D bbg = new SunGraphics2D(bbsd, Color.black, Color.white, null);
try {
bbg.drawImage(backBuffer, 0, 0, null);
} finally {
bbg.dispose();
}
} else {
Graphics g = peer.getGraphics();
try {
g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
} finally {
g.dispose();
}
return;
}
} else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
// not supported by WGL...
return;
}
OGLSurfaceData.swapBuffers(peer.getData());
if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
Graphics g = backBuffer.getGraphics();
try {
g.setColor(target.getBackground());
g.fillRect(0, 0, backBuffer.getWidth(), backBuffer.getHeight());
} finally {
g.dispose();
}
}
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class D3DScreenUpdateManager method createGraphics.
/**
* Creates a graphics object for the passed in surface data. If
* the surface is lost, it is restored.
* If the surface wasn't lost or the restoration was successful
* the surface is added to the list of maintained surfaces
* (if it hasn't been already).
*
* If the updater thread hasn't been created yet , it will be created and
* started.
*
* @param sd surface data for which to create SunGraphics2D
* @param peer peer associated with the surface data
* @param fgColor fg color to be used in graphics
* @param bgColor bg color to be used in graphics
* @param font font to be used in graphics
* @return a SunGraphics2D object for the surface (or for temp GDI
* surface data)
*/
@Override
public Graphics2D createGraphics(SurfaceData sd, WComponentPeer peer, Color fgColor, Color bgColor, Font font) {
if (!done && sd instanceof D3DWindowSurfaceData) {
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData) sd;
if (!d3dw.isSurfaceLost() || validate(d3dw)) {
trackScreenSurface(d3dw);
return new SunGraphics2D(sd, fgColor, bgColor, font);
}
// could not restore the d3dw surface, use the cached gdi surface
// instead for this graphics object; note that we do not track
// this new gdi surface, it is only used for this graphics
// object
sd = getGdiSurface(d3dw);
}
return super.createGraphics(sd, peer, fgColor, bgColor, font);
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class D3DScreenUpdateManager method validate.
/**
* Restores the passed surface if it was lost, resets the lost status.
* @param sd surface to be validated
* @return true if surface wasn't lost or if restoration was successful,
* false otherwise
*/
private boolean validate(D3DWindowSurfaceData sd) {
if (sd.isSurfaceLost()) {
try {
sd.restoreSurface();
// if succeeded, first fill the surface with bg color
// note: use the non-synch method to avoid incorrect lock order
Color bg = sd.getPeer().getBackgroundNoSync();
SunGraphics2D sg2d = new SunGraphics2D(sd, bg, bg, null);
sg2d.fillRect(0, 0, sd.getBounds().width, sd.getBounds().height);
sg2d.dispose();
// now clean the dirty status so that we don't flip it
// next time before it gets repainted; it is safe
// to do without the lock because we will issue a
// repaint anyway so we will not lose any rendering
sd.markClean();
// since the surface was successfully restored we need to
// repaint whole window to repopulate the back-buffer
repaintPeerTarget(sd.getPeer());
} catch (InvalidPipeException ipe) {
return false;
}
}
return true;
}
Aggregations