Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/xr/XRBackendNative.java
32288 views
/*1* Copyright (c) 2010, 2013, 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.xr;2627import java.awt.geom.*;28import java.util.*;2930import sun.font.*;31import sun.java2d.jules.*;32import sun.java2d.pipe.*;3334import static sun.java2d.xr.XRUtils.XDoubleToFixed;3536/**37* Native implementation of XRBackend.38* Almost direct 1:1 binding to libX11.39*40* @author Clemens Eisserer41*/4243public class XRBackendNative implements XRBackend {4445static {46initIDs();47}4849private static long FMTPTR_A8;50private static long FMTPTR_ARGB32;51private static long MASK_XIMG;5253private static native void initIDs();5455public native long createGC(int drawable);5657public native void freeGC(long gc);5859public native int createPixmap(int drawable, int depth,60int width, int height);6162private native int createPictureNative(int drawable, long formatID);6364public native void freePicture(int picture);6566public native void freePixmap(int pixmap);6768public native void setGCExposures(long gc, boolean exposure);6970public native void setGCForeground(long gc, int pixel);7172public native void setPictureRepeat(int picture, int repeat);7374public native void copyArea(int src, int dst, long gc,75int srcx, int srcy, int width, int height,76int dstx, int dsty);7778public native void setGCMode(long gc, boolean copy);7980private static native void GCRectanglesNative(int drawable, long gc,81int[] rectArray, int rectCnt);8283public native void renderComposite(byte op, int src, int mask,84int dst, int srcX, int srcY,85int maskX, int maskY, int dstX, int dstY,86int width, int height);8788private native void renderRectangle(int dst, byte op,89short red, short green,90short blue, short alpha,91int x, int y, int width, int height);9293private static native void94XRenderRectanglesNative(int dst, byte op,95short red, short green,96short blue, short alpha,97int[] rects, int rectCnt);9899private native void XRSetTransformNative(int pic,100int m00, int m01, int m02,101int m10, int m11, int m12);102103private static native int104XRCreateLinearGradientPaintNative(float[] fractionsArray,105short[] pixelsArray,106int x1, int y1, int x2, int y2,107int numStops, int repeat);108109private native static int110XRCreateRadialGradientPaintNative(float[] fractionsArray,111short[] pixelsArray, int numStops,112int centerX, int centerY,113int innerRadius, int outerRadius,114int repeat);115116public native void setFilter(int picture, int filter);117118private static native void XRSetClipNative(long dst,119int x1, int y1, int x2, int y2,120Region clip, boolean isGC);121122public void GCRectangles(int drawable, long gc, GrowableRectArray rects) {123GCRectanglesNative(drawable, gc, rects.getArray(), rects.getSize());124}125126public int createPicture(int drawable, int formatID) {127return createPictureNative(drawable, getFormatPtr(formatID));128}129130public void setPictureTransform(int picture, AffineTransform transform) {131XRSetTransformNative(picture,132XDoubleToFixed(transform.getScaleX()),133XDoubleToFixed(transform.getShearX()),134XDoubleToFixed(transform.getTranslateX()),135XDoubleToFixed(transform.getShearY()),136XDoubleToFixed(transform.getScaleY()),137XDoubleToFixed(transform.getTranslateY()));138}139140public void renderRectangle(int dst, byte op, XRColor color,141int x, int y, int width, int height) {142renderRectangle(dst, op, (short)color.red, (short)color.green,143(short)color.blue, (short)color.alpha,144x, y, width, height);145}146147private short[] getRenderColors(int[] pixels) {148short[] renderColors = new short[pixels.length * 4];149150XRColor c = new XRColor();151for (int i = 0; i < pixels.length; i++) {152c.setColorValues(pixels[i], true);153renderColors[i * 4 + 0] = (short) c.alpha;154renderColors[i * 4 + 1] = (short) c.red;155renderColors[i * 4 + 2] = (short) c.green;156renderColors[i * 4 + 3] = (short) c.blue;157}158159return renderColors;160}161162private static long getFormatPtr(int formatID) {163switch (formatID) {164case XRUtils.PictStandardA8:165return FMTPTR_A8;166case XRUtils.PictStandardARGB32:167return FMTPTR_ARGB32;168}169170return 0L;171}172173public int createLinearGradient(Point2D p1, Point2D p2, float[] fractions,174int[] pixels, int repeat) {175176short[] colorValues = getRenderColors(pixels);177int gradient =178XRCreateLinearGradientPaintNative(fractions, colorValues,179XDoubleToFixed(p1.getX()), XDoubleToFixed(p1.getY()),180XDoubleToFixed(p2.getX()), XDoubleToFixed(p2.getY()),181fractions.length, repeat);182return gradient;183}184185public int createRadialGradient(float centerX, float centerY,186float innerRadius, float outerRadius,187float[] fractions, int[] pixels, int repeat) {188189short[] colorValues = getRenderColors(pixels);190return XRCreateRadialGradientPaintNative191(fractions, colorValues, fractions.length,192XDoubleToFixed(centerX),193XDoubleToFixed(centerY),194XDoubleToFixed(innerRadius),195XDoubleToFixed(outerRadius),196repeat);197}198199public void setGCClipRectangles(long gc, Region clip) {200XRSetClipNative(gc, clip.getLoX(), clip.getLoY(),201clip.getHiX(), clip.getHiY(),202clip.isRectangular() ? null : clip, true);203}204205public void setClipRectangles(int picture, Region clip) {206if (clip != null) {207XRSetClipNative(picture, clip.getLoX(), clip.getLoY(),208clip.getHiX(), clip.getHiY(),209clip.isRectangular() ? null : clip, false);210} else {211XRSetClipNative(picture, 0, 0, 32767, 32767, null, false);212}213}214215public void renderRectangles(int dst, byte op, XRColor color,216GrowableRectArray rects) {217XRenderRectanglesNative(dst, op,218(short) color.red, (short) color.green,219(short) color.blue, (short) color.alpha,220rects.getArray(), rects221.getSize());222}223224private static long[] getGlyphInfoPtrs(List<XRGlyphCacheEntry> cacheEntries) {225long[] glyphInfoPtrs = new long[cacheEntries.size()];226for (int i = 0; i < cacheEntries.size(); i++) {227glyphInfoPtrs[i] = cacheEntries.get(i).getGlyphInfoPtr();228}229return glyphInfoPtrs;230}231232public void XRenderAddGlyphs(int glyphSet, GlyphList gl,233List<XRGlyphCacheEntry> cacheEntries,234byte[] pixelData) {235long[] glyphInfoPtrs = getGlyphInfoPtrs(cacheEntries);236XRAddGlyphsNative(glyphSet, glyphInfoPtrs,237glyphInfoPtrs.length, pixelData, pixelData.length);238}239240public void XRenderFreeGlyphs(int glyphSet, int[] gids) {241XRFreeGlyphsNative(glyphSet, gids, gids.length);242}243244private static native void XRAddGlyphsNative(int glyphSet,245long[] glyphInfoPtrs,246int glyphCnt,247byte[] pixelData,248int pixelDataLength);249250private static native void XRFreeGlyphsNative(int glyphSet,251int[] gids, int idCnt);252253private static native void254XRenderCompositeTextNative(int op, int src, int dst,255int srcX, int srcY, long maskFormat,256int[] eltArray, int[] glyphIDs, int eltCnt,257int glyphCnt);258259public int XRenderCreateGlyphSet(int formatID) {260return XRenderCreateGlyphSetNative(getFormatPtr(formatID));261}262263private static native int XRenderCreateGlyphSetNative(long format);264265public void XRenderCompositeText(byte op, int src, int dst,266int maskFormatID,267int sx, int sy, int dx, int dy,268int glyphset, GrowableEltArray elts) {269270GrowableIntArray glyphs = elts.getGlyphs();271XRenderCompositeTextNative(op, src, dst, sx, sy, 0, elts.getArray(),272glyphs.getArray(), elts.getSize(),273glyphs.getSize());274}275276public void putMaskImage(int drawable, long gc, byte[] imageData,277int sx, int sy, int dx, int dy,278int width, int height, int maskOff,279int maskScan, float ea) {280putMaskNative(drawable, gc, imageData, sx, sy, dx, dy,281width, height, maskOff, maskScan, ea, MASK_XIMG);282}283284private static native void putMaskNative(int drawable, long gc,285byte[] imageData,286int sx, int sy, int dx, int dy,287int width, int height,288int maskOff, int maskScan,289float ea, long xImg);290291public void padBlit(byte op, int srcPict, int maskPict, int dstPict,292AffineTransform maskTrx, int maskWidth, int maskHeight,293int lastMaskWidth, int lastMaskHeight,294int sx, int sy, int dx, int dy, int w, int h) {295296padBlitNative(op, srcPict, maskPict, dstPict,297XDoubleToFixed(maskTrx.getScaleX()),298XDoubleToFixed(maskTrx.getShearX()),299XDoubleToFixed(maskTrx.getTranslateX()),300XDoubleToFixed(maskTrx.getShearY()),301XDoubleToFixed(maskTrx.getScaleY()),302XDoubleToFixed(maskTrx.getTranslateY()),303maskWidth, maskHeight, lastMaskWidth, lastMaskHeight,304sx, sy, dx, dy, w, h);305}306307private static native void padBlitNative(byte op, int srcPict,308int maskPict, int dstPict,309int m00, int m01, int m02,310int m10, int m11, int m12,311int maskWidth, int maskHeight,312int lastMaskWidth,313int lastMaskHeight,314int sx, int sy, int dx, int dy,315int w, int h);316317public void renderCompositeTrapezoids(byte op, int src, int maskFormat,318int dst, int srcX, int srcY,319TrapezoidList trapList) {320renderCompositeTrapezoidsNative(op, src, getFormatPtr(maskFormat),321dst, srcX, srcY,322trapList.getTrapArray());323}324325private static native void326renderCompositeTrapezoidsNative(byte op, int src, long maskFormat,327int dst, int srcX, int srcY,328int[] trapezoids);329}330331332