0N/A/*
2362N/A * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.x11;
0N/A
0N/Aimport java.awt.Polygon;
0N/Aimport java.awt.Shape;
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.geom.PathIterator;
0N/Aimport java.awt.geom.Path2D;
0N/Aimport java.awt.geom.IllegalPathStateException;
0N/Aimport sun.awt.SunToolkit;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.java2d.SurfaceData;
0N/Aimport sun.java2d.loops.GraphicsPrimitive;
0N/Aimport sun.java2d.pipe.Region;
0N/Aimport sun.java2d.pipe.PixelDrawPipe;
0N/Aimport sun.java2d.pipe.PixelFillPipe;
0N/Aimport sun.java2d.pipe.ShapeDrawPipe;
0N/Aimport sun.java2d.pipe.SpanIterator;
0N/Aimport sun.java2d.pipe.ShapeSpanIterator;
0N/Aimport sun.java2d.pipe.LoopPipe;
0N/A
0N/Apublic class X11Renderer implements
0N/A PixelDrawPipe,
0N/A PixelFillPipe,
0N/A ShapeDrawPipe
0N/A{
0N/A public static X11Renderer getInstance() {
0N/A return (GraphicsPrimitive.tracingEnabled()
0N/A ? new X11TracingRenderer()
0N/A : new X11Renderer());
0N/A }
0N/A
0N/A private final long validate(SunGraphics2D sg2d) {
0N/A // NOTE: getCompClip() will revalidateAll() if the
0N/A // surfaceData is invalid. This should ensure that
0N/A // the clip and pixel that we are validating against
0N/A // are the most current.
0N/A //
0N/A // The assumption is that the pipeline after that
0N/A // revalidation will either be another X11 pipe
0N/A // (because the drawable format never changes on X11)
0N/A // or a null pipeline if the surface is disposed.
0N/A //
0N/A // Since we do not get the ops structure of the SurfaceData
0N/A // until the actual call down to the native level we will
0N/A // pick up the most recently validated copy.
0N/A // Note that if the surface is disposed, a NullSurfaceData
0N/A // (with null native data structure) will be set in
0N/A // sg2d, so we have to protect against it in native code.
0N/A
0N/A X11SurfaceData x11sd = (X11SurfaceData)sg2d.surfaceData;
0N/A return x11sd.getRenderGC(sg2d.getCompClip(),
0N/A sg2d.compositeState, sg2d.composite,
0N/A sg2d.pixel);
0N/A }
0N/A
0N/A native void XDrawLine(long pXSData, long xgc,
0N/A int x1, int y1, int x2, int y2);
0N/A
0N/A public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A int transx = sg2d.transX;
0N/A int transy = sg2d.transY;
0N/A XDrawLine(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x1+transx, y1+transy, x2+transx, y2+transy);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XDrawRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h);
0N/A
0N/A public void drawRect(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XDrawRect(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XDrawRoundRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int arcW, int arcH);
0N/A
0N/A public void drawRoundRect(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height,
0N/A int arcWidth, int arcHeight)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XDrawRoundRect(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height,
0N/A arcWidth, arcHeight);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XDrawOval(long pXSData, long xgc,
0N/A int x, int y, int w, int h);
0N/A
0N/A public void drawOval(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XDrawOval(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XDrawArc(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int angleStart, int angleExtent);
0N/A
0N/A public void drawArc(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height,
0N/A int startAngle, int arcAngle)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XDrawArc(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height,
0N/A startAngle, arcAngle);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XDrawPoly(long pXSData, long xgc,
0N/A int transx, int transy,
0N/A int[] xpoints, int[] ypoints,
0N/A int npoints, boolean isclosed);
0N/A
0N/A public void drawPolyline(SunGraphics2D sg2d,
0N/A int xpoints[], int ypoints[],
0N/A int npoints)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XDrawPoly(sg2d.surfaceData.getNativeOps(), xgc,
0N/A sg2d.transX, sg2d.transY,
0N/A xpoints, ypoints, npoints, false);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A public void drawPolygon(SunGraphics2D sg2d,
0N/A int xpoints[], int ypoints[],
0N/A int npoints)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XDrawPoly(sg2d.surfaceData.getNativeOps(), xgc,
0N/A sg2d.transX, sg2d.transY,
0N/A xpoints, ypoints, npoints, true);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XFillRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h);
0N/A
0N/A public void fillRect(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XFillRect(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XFillRoundRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int arcW, int arcH);
0N/A
0N/A public void fillRoundRect(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height,
0N/A int arcWidth, int arcHeight)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XFillRoundRect(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height,
0N/A arcWidth, arcHeight);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XFillOval(long pXSData, long xgc,
0N/A int x, int y, int w, int h);
0N/A
0N/A public void fillOval(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XFillOval(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XFillArc(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int angleStart, int angleExtent);
0N/A
0N/A public void fillArc(SunGraphics2D sg2d,
0N/A int x, int y, int width, int height,
0N/A int startAngle, int arcAngle)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XFillArc(sg2d.surfaceData.getNativeOps(), xgc,
0N/A x+sg2d.transX, y+sg2d.transY, width, height,
0N/A startAngle, arcAngle);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XFillPoly(long pXSData, long xgc,
0N/A int transx, int transy,
0N/A int[] xpoints, int[] ypoints,
0N/A int npoints);
0N/A
0N/A public void fillPolygon(SunGraphics2D sg2d,
0N/A int xpoints[], int ypoints[],
0N/A int npoints)
0N/A {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XFillPoly(sg2d.surfaceData.getNativeOps(), xgc,
0N/A sg2d.transX, sg2d.transY, xpoints, ypoints, npoints);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A native void XFillSpans(long pXSData, long xgc,
0N/A SpanIterator si, long iterator,
0N/A int transx, int transy);
0N/A
0N/A native void XDoPath(SunGraphics2D sg2d, long pXSData, long xgc,
0N/A int transX, int transY, Path2D.Float p2df,
0N/A boolean isFill);
0N/A
0N/A private void doPath(SunGraphics2D sg2d, Shape s, boolean isFill) {
0N/A Path2D.Float p2df;
0N/A int transx, transy;
0N/A if (sg2d.transformState <= sg2d.TRANSFORM_INT_TRANSLATE) {
0N/A if (s instanceof Path2D.Float) {
0N/A p2df = (Path2D.Float)s;
0N/A } else {
0N/A p2df = new Path2D.Float(s);
0N/A }
0N/A transx = sg2d.transX;
0N/A transy = sg2d.transY;
0N/A } else {
0N/A p2df = new Path2D.Float(s, sg2d.transform);
0N/A transx = 0;
0N/A transy = 0;
0N/A }
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XDoPath(sg2d, sg2d.surfaceData.getNativeOps(), xgc,
0N/A transx, transy, p2df, isFill);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A public void draw(SunGraphics2D sg2d, Shape s) {
0N/A if (sg2d.strokeState == sg2d.STROKE_THIN) {
0N/A // Delegate to drawPolygon() if possible...
0N/A if (s instanceof Polygon &&
0N/A sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE)
0N/A {
0N/A Polygon p = (Polygon) s;
0N/A drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
0N/A return;
0N/A }
0N/A
0N/A // Otherwise we will use drawPath() for
0N/A // high-quality thin paths.
0N/A doPath(sg2d, s, false);
0N/A } else if (sg2d.strokeState < sg2d.STROKE_CUSTOM) {
0N/A // REMIND: X11 can handle uniform scaled wide lines
0N/A // and dashed lines itself if we set the appropriate
0N/A // XGC attributes (TBD).
0N/A ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);
0N/A try {
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,
0N/A si, si.getNativeIterator(),
0N/A 0, 0);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A } finally {
0N/A si.dispose();
0N/A }
0N/A } else {
0N/A fill(sg2d, sg2d.stroke.createStrokedShape(s));
0N/A }
0N/A }
0N/A
0N/A public void fill(SunGraphics2D sg2d, Shape s) {
0N/A if (sg2d.strokeState == sg2d.STROKE_THIN) {
0N/A // Delegate to fillPolygon() if possible...
0N/A if (s instanceof Polygon &&
0N/A sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE)
0N/A {
0N/A Polygon p = (Polygon) s;
0N/A fillPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
0N/A return;
0N/A }
0N/A
0N/A // Otherwise we will use fillPath() for
0N/A // high-quality fills.
0N/A doPath(sg2d, s, true);
0N/A return;
0N/A }
0N/A
0N/A AffineTransform at;
0N/A int transx, transy;
0N/A if (sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE) {
0N/A // Transform (translation) will be done by XFillSpans
0N/A at = null;
0N/A transx = sg2d.transX;
0N/A transy = sg2d.transY;
0N/A } else {
0N/A // Transform will be done by the PathIterator
0N/A at = sg2d.transform;
0N/A transx = transy = 0;
0N/A }
0N/A
0N/A ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
0N/A try {
0N/A // Subtract transx/y from the SSI clip to match the
0N/A // (potentially untranslated) geometry fed to it
0N/A Region clip = sg2d.getCompClip();
0N/A ssi.setOutputAreaXYXY(clip.getLoX() - transx,
0N/A clip.getLoY() - transy,
0N/A clip.getHiX() - transx,
0N/A clip.getHiY() - transy);
0N/A ssi.appendPath(s.getPathIterator(at));
0N/A SunToolkit.awtLock();
0N/A try {
0N/A long xgc = validate(sg2d);
0N/A XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,
0N/A ssi, ssi.getNativeIterator(),
0N/A transx, transy);
0N/A } finally {
0N/A SunToolkit.awtUnlock();
0N/A }
0N/A } finally {
0N/A ssi.dispose();
0N/A }
0N/A }
0N/A
0N/A native void devCopyArea(long sdOps, long xgc,
0N/A int srcx, int srcy,
0N/A int dstx, int dsty,
0N/A int w, int h);
0N/A
0N/A public static class X11TracingRenderer extends X11Renderer {
0N/A void XDrawLine(long pXSData, long xgc,
0N/A int x1, int y1, int x2, int y2)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11DrawLine");
0N/A super.XDrawLine(pXSData, xgc, x1, y1, x2, y2);
0N/A }
0N/A void XDrawRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11DrawRect");
0N/A super.XDrawRect(pXSData, xgc, x, y, w, h);
0N/A }
0N/A void XDrawRoundRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int arcW, int arcH)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11DrawRoundRect");
0N/A super.XDrawRoundRect(pXSData, xgc, x, y, w, h, arcW, arcH);
0N/A }
0N/A void XDrawOval(long pXSData, long xgc,
0N/A int x, int y, int w, int h)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11DrawOval");
0N/A super.XDrawOval(pXSData, xgc, x, y, w, h);
0N/A }
0N/A void XDrawArc(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int angleStart, int angleExtent)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11DrawArc");
0N/A super.XDrawArc(pXSData, xgc,
0N/A x, y, w, h, angleStart, angleExtent);
0N/A }
0N/A void XDrawPoly(long pXSData, long xgc,
0N/A int transx, int transy,
0N/A int[] xpoints, int[] ypoints,
0N/A int npoints, boolean isclosed)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11DrawPoly");
0N/A super.XDrawPoly(pXSData, xgc, transx, transy,
0N/A xpoints, ypoints, npoints, isclosed);
0N/A }
0N/A void XDoPath(SunGraphics2D sg2d, long pXSData, long xgc,
0N/A int transX, int transY, Path2D.Float p2df,
0N/A boolean isFill)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive(isFill ?
0N/A "X11FillPath" :
0N/A "X11DrawPath");
0N/A super.XDoPath(sg2d, pXSData, xgc, transX, transY, p2df, isFill);
0N/A }
0N/A void XFillRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11FillRect");
0N/A super.XFillRect(pXSData, xgc, x, y, w, h);
0N/A }
0N/A void XFillRoundRect(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int arcW, int arcH)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11FillRoundRect");
0N/A super.XFillRoundRect(pXSData, xgc, x, y, w, h, arcW, arcH);
0N/A }
0N/A void XFillOval(long pXSData, long xgc,
0N/A int x, int y, int w, int h)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11FillOval");
0N/A super.XFillOval(pXSData, xgc, x, y, w, h);
0N/A }
0N/A void XFillArc(long pXSData, long xgc,
0N/A int x, int y, int w, int h,
0N/A int angleStart, int angleExtent)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11FillArc");
0N/A super.XFillArc(pXSData, xgc,
0N/A x, y, w, h, angleStart, angleExtent);
0N/A }
0N/A void XFillPoly(long pXSData, long xgc,
0N/A int transx, int transy,
0N/A int[] xpoints, int[] ypoints,
0N/A int npoints)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11FillPoly");
0N/A super.XFillPoly(pXSData, xgc,
0N/A transx, transy, xpoints, ypoints, npoints);
0N/A }
0N/A void XFillSpans(long pXSData, long xgc,
0N/A SpanIterator si, long iterator, int transx, int transy)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11FillSpans");
0N/A super.XFillSpans(pXSData, xgc,
0N/A si, iterator, transx, transy);
0N/A }
0N/A void devCopyArea(long sdOps, long xgc,
0N/A int srcx, int srcy,
0N/A int dstx, int dsty,
0N/A int w, int h)
0N/A {
0N/A GraphicsPrimitive.tracePrimitive("X11CopyArea");
0N/A super.devCopyArea(sdOps, xgc, srcx, srcy, dstx, dsty, w, h);
0N/A }
0N/A }
0N/A}