use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class Test8004859 method test.
private static void test(final Graphics2D g) {
for (final Shape clip : clips) {
g.setClip(clip);
if (!g.getClip().equals(clip)) {
System.err.println("Expected clip: " + clip);
System.err.println("Actual clip: " + g.getClip());
System.err.println("bounds=" + g.getClip().getBounds2D());
System.err.println("bounds=" + g.getClip().getBounds());
status = false;
}
final Rectangle bounds = g.getClipBounds();
if (!clip.equals(bounds)) {
System.err.println("Expected getClipBounds(): " + clip);
System.err.println("Actual getClipBounds(): " + bounds);
status = false;
}
g.getClipBounds(bounds);
if (!clip.equals(bounds)) {
System.err.println("Expected getClipBounds(r): " + clip);
System.err.println("Actual getClipBounds(r): " + bounds);
status = false;
}
if (!clip.getBounds2D().isEmpty() && ((SunGraphics2D) g).clipRegion.isEmpty()) {
System.err.println("clipRegion should not be empty");
status = false;
}
}
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class MultiResolutionDrawImageWithTransformTest method getImageColor.
private static Color getImageColor(Image image, double configScale, double transformScale) {
TestSurfaceData surface = new TestSurfaceData(SCREEN_SIZE, SCREEN_SIZE, configScale);
SunGraphics2D g2d = new SunGraphics2D(surface, Color.BLACK, Color.BLACK, null);
g2d.setRenderingHint(KEY_RESOLUTION_VARIANT, VALUE_RESOLUTION_VARIANT_SIZE_FIT);
AffineTransform tx = AffineTransform.getScaleInstance(transformScale, transformScale);
g2d.drawImage(image, tx, null);
g2d.dispose();
int backgroundX = (int) (1.5 * image.getWidth(null) * transformScale);
int backgroundY = (int) (1.5 * image.getHeight(null) * transformScale);
Color backgroundColor = surface.getColor(backgroundX, backgroundY);
//surface.show(String.format("Config: %f, transform: %f", configScale, transformScale));
if (!BACKGROUND_COLOR.equals(backgroundColor)) {
throw new RuntimeException("Wrong background color!");
}
return surface.getColor(IMAGE_SIZE / 4, IMAGE_SIZE / 4);
}
use of sun.java2d.SunGraphics2D in project jdk8u_jdk by JetBrains.
the class OGLUtilities method invokeWithOGLContextCurrent.
/**
* Invokes the given Runnable on the OGL QueueFlusher thread with the
* OpenGL context corresponding to the given Graphics object made
* current. It is legal for OpenGL code executed in the given
* Runnable to change the current OpenGL context; it will be reset
* once the Runnable completes. No guarantees are made as to the
* state of the OpenGL context of the Graphics object; for
* example, calling code must set the scissor box using the return
* value from {@link #getOGLScissorBox} to avoid drawing
* over other Swing components, and must typically set the OpenGL
* viewport using the return value from {@link #getOGLViewport} to
* make the client's OpenGL rendering appear in the correct place
* relative to the scissor region.
*
* 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 g the Graphics object for the corresponding destination surface;
* if null, the step making a context current to the destination surface
* will be skipped
* @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 a context current to the surface
* associated with the given Graphics object
*/
public static boolean invokeWithOGLContextCurrent(Graphics g, Runnable r) {
OGLRenderQueue rq = OGLRenderQueue.getInstance();
rq.lock();
try {
if (g != null) {
if (!(g instanceof SunGraphics2D)) {
return false;
}
SurfaceData sData = ((SunGraphics2D) g).surfaceData;
if (!(sData instanceof OGLSurfaceData)) {
return false;
}
// make a context current to the destination surface
OGLContext.validateContext((OGLSurfaceData) sData);
}
// 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;
}
Aggregations