Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/x11/X11Renderer.java
32288 views
/*1* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.x11;2627import java.awt.Polygon;28import java.awt.Shape;29import java.awt.geom.AffineTransform;30import java.awt.geom.PathIterator;31import java.awt.geom.Path2D;32import java.awt.geom.IllegalPathStateException;33import sun.awt.SunToolkit;34import sun.java2d.SunGraphics2D;35import sun.java2d.SurfaceData;36import sun.java2d.loops.GraphicsPrimitive;37import sun.java2d.pipe.Region;38import sun.java2d.pipe.PixelDrawPipe;39import sun.java2d.pipe.PixelFillPipe;40import sun.java2d.pipe.ShapeDrawPipe;41import sun.java2d.pipe.SpanIterator;42import sun.java2d.pipe.ShapeSpanIterator;43import sun.java2d.pipe.LoopPipe;4445public class X11Renderer implements46PixelDrawPipe,47PixelFillPipe,48ShapeDrawPipe49{50public static X11Renderer getInstance() {51return (GraphicsPrimitive.tracingEnabled()52? new X11TracingRenderer()53: new X11Renderer());54}5556private final long validate(SunGraphics2D sg2d) {57// NOTE: getCompClip() will revalidateAll() if the58// surfaceData is invalid. This should ensure that59// the clip and pixel that we are validating against60// are the most current.61//62// The assumption is that the pipeline after that63// revalidation will either be another X11 pipe64// (because the drawable format never changes on X11)65// or a null pipeline if the surface is disposed.66//67// Since we do not get the ops structure of the SurfaceData68// until the actual call down to the native level we will69// pick up the most recently validated copy.70// Note that if the surface is disposed, a NullSurfaceData71// (with null native data structure) will be set in72// sg2d, so we have to protect against it in native code.7374X11SurfaceData x11sd = (X11SurfaceData)sg2d.surfaceData;75return x11sd.getRenderGC(sg2d.getCompClip(),76sg2d.compositeState, sg2d.composite,77sg2d.pixel);78}7980native void XDrawLine(long pXSData, long xgc,81int x1, int y1, int x2, int y2);8283public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {84SunToolkit.awtLock();85try {86long xgc = validate(sg2d);87int transx = sg2d.transX;88int transy = sg2d.transY;89XDrawLine(sg2d.surfaceData.getNativeOps(), xgc,90x1+transx, y1+transy, x2+transx, y2+transy);91} finally {92SunToolkit.awtUnlock();93}94}9596native void XDrawRect(long pXSData, long xgc,97int x, int y, int w, int h);9899public void drawRect(SunGraphics2D sg2d,100int x, int y, int width, int height)101{102SunToolkit.awtLock();103try {104long xgc = validate(sg2d);105XDrawRect(sg2d.surfaceData.getNativeOps(), xgc,106x+sg2d.transX, y+sg2d.transY, width, height);107} finally {108SunToolkit.awtUnlock();109}110}111112native void XDrawRoundRect(long pXSData, long xgc,113int x, int y, int w, int h,114int arcW, int arcH);115116public void drawRoundRect(SunGraphics2D sg2d,117int x, int y, int width, int height,118int arcWidth, int arcHeight)119{120SunToolkit.awtLock();121try {122long xgc = validate(sg2d);123XDrawRoundRect(sg2d.surfaceData.getNativeOps(), xgc,124x+sg2d.transX, y+sg2d.transY, width, height,125arcWidth, arcHeight);126} finally {127SunToolkit.awtUnlock();128}129}130131native void XDrawOval(long pXSData, long xgc,132int x, int y, int w, int h);133134public void drawOval(SunGraphics2D sg2d,135int x, int y, int width, int height)136{137SunToolkit.awtLock();138try {139long xgc = validate(sg2d);140XDrawOval(sg2d.surfaceData.getNativeOps(), xgc,141x+sg2d.transX, y+sg2d.transY, width, height);142} finally {143SunToolkit.awtUnlock();144}145}146147native void XDrawArc(long pXSData, long xgc,148int x, int y, int w, int h,149int angleStart, int angleExtent);150151public void drawArc(SunGraphics2D sg2d,152int x, int y, int width, int height,153int startAngle, int arcAngle)154{155SunToolkit.awtLock();156try {157long xgc = validate(sg2d);158XDrawArc(sg2d.surfaceData.getNativeOps(), xgc,159x+sg2d.transX, y+sg2d.transY, width, height,160startAngle, arcAngle);161} finally {162SunToolkit.awtUnlock();163}164}165166native void XDrawPoly(long pXSData, long xgc,167int transx, int transy,168int[] xpoints, int[] ypoints,169int npoints, boolean isclosed);170171public void drawPolyline(SunGraphics2D sg2d,172int xpoints[], int ypoints[],173int npoints)174{175SunToolkit.awtLock();176try {177long xgc = validate(sg2d);178XDrawPoly(sg2d.surfaceData.getNativeOps(), xgc,179sg2d.transX, sg2d.transY,180xpoints, ypoints, npoints, false);181} finally {182SunToolkit.awtUnlock();183}184}185186public void drawPolygon(SunGraphics2D sg2d,187int xpoints[], int ypoints[],188int npoints)189{190SunToolkit.awtLock();191try {192long xgc = validate(sg2d);193XDrawPoly(sg2d.surfaceData.getNativeOps(), xgc,194sg2d.transX, sg2d.transY,195xpoints, ypoints, npoints, true);196} finally {197SunToolkit.awtUnlock();198}199}200201native void XFillRect(long pXSData, long xgc,202int x, int y, int w, int h);203204public void fillRect(SunGraphics2D sg2d,205int x, int y, int width, int height)206{207SunToolkit.awtLock();208try {209long xgc = validate(sg2d);210XFillRect(sg2d.surfaceData.getNativeOps(), xgc,211x+sg2d.transX, y+sg2d.transY, width, height);212} finally {213SunToolkit.awtUnlock();214}215}216217native void XFillRoundRect(long pXSData, long xgc,218int x, int y, int w, int h,219int arcW, int arcH);220221public void fillRoundRect(SunGraphics2D sg2d,222int x, int y, int width, int height,223int arcWidth, int arcHeight)224{225SunToolkit.awtLock();226try {227long xgc = validate(sg2d);228XFillRoundRect(sg2d.surfaceData.getNativeOps(), xgc,229x+sg2d.transX, y+sg2d.transY, width, height,230arcWidth, arcHeight);231} finally {232SunToolkit.awtUnlock();233}234}235236native void XFillOval(long pXSData, long xgc,237int x, int y, int w, int h);238239public void fillOval(SunGraphics2D sg2d,240int x, int y, int width, int height)241{242SunToolkit.awtLock();243try {244long xgc = validate(sg2d);245XFillOval(sg2d.surfaceData.getNativeOps(), xgc,246x+sg2d.transX, y+sg2d.transY, width, height);247} finally {248SunToolkit.awtUnlock();249}250}251252native void XFillArc(long pXSData, long xgc,253int x, int y, int w, int h,254int angleStart, int angleExtent);255256public void fillArc(SunGraphics2D sg2d,257int x, int y, int width, int height,258int startAngle, int arcAngle)259{260SunToolkit.awtLock();261try {262long xgc = validate(sg2d);263XFillArc(sg2d.surfaceData.getNativeOps(), xgc,264x+sg2d.transX, y+sg2d.transY, width, height,265startAngle, arcAngle);266} finally {267SunToolkit.awtUnlock();268}269}270271native void XFillPoly(long pXSData, long xgc,272int transx, int transy,273int[] xpoints, int[] ypoints,274int npoints);275276public void fillPolygon(SunGraphics2D sg2d,277int xpoints[], int ypoints[],278int npoints)279{280SunToolkit.awtLock();281try {282long xgc = validate(sg2d);283XFillPoly(sg2d.surfaceData.getNativeOps(), xgc,284sg2d.transX, sg2d.transY, xpoints, ypoints, npoints);285} finally {286SunToolkit.awtUnlock();287}288}289290native void XFillSpans(long pXSData, long xgc,291SpanIterator si, long iterator,292int transx, int transy);293294native void XDoPath(SunGraphics2D sg2d, long pXSData, long xgc,295int transX, int transY, Path2D.Float p2df,296boolean isFill);297298private void doPath(SunGraphics2D sg2d, Shape s, boolean isFill) {299Path2D.Float p2df;300int transx, transy;301if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {302if (s instanceof Path2D.Float) {303p2df = (Path2D.Float)s;304} else {305p2df = new Path2D.Float(s);306}307transx = sg2d.transX;308transy = sg2d.transY;309} else {310p2df = new Path2D.Float(s, sg2d.transform);311transx = 0;312transy = 0;313}314SunToolkit.awtLock();315try {316long xgc = validate(sg2d);317XDoPath(sg2d, sg2d.surfaceData.getNativeOps(), xgc,318transx, transy, p2df, isFill);319} finally {320SunToolkit.awtUnlock();321}322}323324public void draw(SunGraphics2D sg2d, Shape s) {325if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {326// Delegate to drawPolygon() if possible...327if (s instanceof Polygon &&328sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE)329{330Polygon p = (Polygon) s;331drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);332return;333}334335// Otherwise we will use drawPath() for336// high-quality thin paths.337doPath(sg2d, s, false);338} else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {339// REMIND: X11 can handle uniform scaled wide lines340// and dashed lines itself if we set the appropriate341// XGC attributes (TBD).342ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);343try {344SunToolkit.awtLock();345try {346long xgc = validate(sg2d);347XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,348si, si.getNativeIterator(),3490, 0);350} finally {351SunToolkit.awtUnlock();352}353} finally {354si.dispose();355}356} else {357fill(sg2d, sg2d.stroke.createStrokedShape(s));358}359}360361public void fill(SunGraphics2D sg2d, Shape s) {362if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {363// Delegate to fillPolygon() if possible...364if (s instanceof Polygon &&365sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE)366{367Polygon p = (Polygon) s;368fillPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);369return;370}371372// Otherwise we will use fillPath() for373// high-quality fills.374doPath(sg2d, s, true);375return;376}377378AffineTransform at;379int transx, transy;380if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE) {381// Transform (translation) will be done by XFillSpans382at = null;383transx = sg2d.transX;384transy = sg2d.transY;385} else {386// Transform will be done by the PathIterator387at = sg2d.transform;388transx = transy = 0;389}390391ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);392try {393// Subtract transx/y from the SSI clip to match the394// (potentially untranslated) geometry fed to it395Region clip = sg2d.getCompClip();396ssi.setOutputAreaXYXY(clip.getLoX() - transx,397clip.getLoY() - transy,398clip.getHiX() - transx,399clip.getHiY() - transy);400ssi.appendPath(s.getPathIterator(at));401SunToolkit.awtLock();402try {403long xgc = validate(sg2d);404XFillSpans(sg2d.surfaceData.getNativeOps(), xgc,405ssi, ssi.getNativeIterator(),406transx, transy);407} finally {408SunToolkit.awtUnlock();409}410} finally {411ssi.dispose();412}413}414415native void devCopyArea(long sdOps, long xgc,416int srcx, int srcy,417int dstx, int dsty,418int w, int h);419420public static class X11TracingRenderer extends X11Renderer {421void XDrawLine(long pXSData, long xgc,422int x1, int y1, int x2, int y2)423{424GraphicsPrimitive.tracePrimitive("X11DrawLine");425super.XDrawLine(pXSData, xgc, x1, y1, x2, y2);426}427void XDrawRect(long pXSData, long xgc,428int x, int y, int w, int h)429{430GraphicsPrimitive.tracePrimitive("X11DrawRect");431super.XDrawRect(pXSData, xgc, x, y, w, h);432}433void XDrawRoundRect(long pXSData, long xgc,434int x, int y, int w, int h,435int arcW, int arcH)436{437GraphicsPrimitive.tracePrimitive("X11DrawRoundRect");438super.XDrawRoundRect(pXSData, xgc, x, y, w, h, arcW, arcH);439}440void XDrawOval(long pXSData, long xgc,441int x, int y, int w, int h)442{443GraphicsPrimitive.tracePrimitive("X11DrawOval");444super.XDrawOval(pXSData, xgc, x, y, w, h);445}446void XDrawArc(long pXSData, long xgc,447int x, int y, int w, int h,448int angleStart, int angleExtent)449{450GraphicsPrimitive.tracePrimitive("X11DrawArc");451super.XDrawArc(pXSData, xgc,452x, y, w, h, angleStart, angleExtent);453}454void XDrawPoly(long pXSData, long xgc,455int transx, int transy,456int[] xpoints, int[] ypoints,457int npoints, boolean isclosed)458{459GraphicsPrimitive.tracePrimitive("X11DrawPoly");460super.XDrawPoly(pXSData, xgc, transx, transy,461xpoints, ypoints, npoints, isclosed);462}463void XDoPath(SunGraphics2D sg2d, long pXSData, long xgc,464int transX, int transY, Path2D.Float p2df,465boolean isFill)466{467GraphicsPrimitive.tracePrimitive(isFill ?468"X11FillPath" :469"X11DrawPath");470super.XDoPath(sg2d, pXSData, xgc, transX, transY, p2df, isFill);471}472void XFillRect(long pXSData, long xgc,473int x, int y, int w, int h)474{475GraphicsPrimitive.tracePrimitive("X11FillRect");476super.XFillRect(pXSData, xgc, x, y, w, h);477}478void XFillRoundRect(long pXSData, long xgc,479int x, int y, int w, int h,480int arcW, int arcH)481{482GraphicsPrimitive.tracePrimitive("X11FillRoundRect");483super.XFillRoundRect(pXSData, xgc, x, y, w, h, arcW, arcH);484}485void XFillOval(long pXSData, long xgc,486int x, int y, int w, int h)487{488GraphicsPrimitive.tracePrimitive("X11FillOval");489super.XFillOval(pXSData, xgc, x, y, w, h);490}491void XFillArc(long pXSData, long xgc,492int x, int y, int w, int h,493int angleStart, int angleExtent)494{495GraphicsPrimitive.tracePrimitive("X11FillArc");496super.XFillArc(pXSData, xgc,497x, y, w, h, angleStart, angleExtent);498}499void XFillPoly(long pXSData, long xgc,500int transx, int transy,501int[] xpoints, int[] ypoints,502int npoints)503{504GraphicsPrimitive.tracePrimitive("X11FillPoly");505super.XFillPoly(pXSData, xgc,506transx, transy, xpoints, ypoints, npoints);507}508void XFillSpans(long pXSData, long xgc,509SpanIterator si, long iterator, int transx, int transy)510{511GraphicsPrimitive.tracePrimitive("X11FillSpans");512super.XFillSpans(pXSData, xgc,513si, iterator, transx, transy);514}515void devCopyArea(long sdOps, long xgc,516int srcx, int srcy,517int dstx, int dsty,518int w, int h)519{520GraphicsPrimitive.tracePrimitive("X11CopyArea");521super.devCopyArea(sdOps, xgc, srcx, srcy, dstx, dsty, w, h);522}523}524}525526527