Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java
32288 views
/*1* Copyright (c) 1999, 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.GraphicsDevice;28import java.awt.GraphicsEnvironment;29import java.awt.Color;30import java.awt.Composite;31import java.awt.Rectangle;32import java.awt.GraphicsConfiguration;33import java.awt.Image;34import java.awt.color.ColorSpace;35import java.awt.Transparency;36import java.awt.image.BufferedImage;37import java.awt.image.ColorModel;38import java.awt.image.ComponentColorModel;39import java.awt.image.DirectColorModel;40import java.awt.image.IndexColorModel;41import java.awt.image.Raster;42import java.awt.peer.ComponentPeer;4344import sun.awt.SunHints;45import sun.awt.SunToolkit;46import sun.awt.X11ComponentPeer;47import sun.awt.X11GraphicsConfig;48import sun.awt.X11GraphicsEnvironment;49import sun.awt.image.PixelConverter;50import sun.font.X11TextRenderer;51import sun.java2d.InvalidPipeException;52import sun.java2d.SunGraphics2D;53import sun.java2d.SunGraphicsEnvironment;54import sun.java2d.SurfaceData;55import sun.java2d.SurfaceDataProxy;56import sun.java2d.loops.SurfaceType;57import sun.java2d.loops.CompositeType;58import sun.java2d.loops.RenderLoops;59import sun.java2d.loops.GraphicsPrimitive;60import sun.java2d.loops.XORComposite;61import sun.java2d.loops.Blit;62import sun.java2d.pipe.ValidatePipe;63import sun.java2d.pipe.PixelToShapeConverter;64import sun.java2d.pipe.TextPipe;65import sun.java2d.pipe.Region;6667public abstract class X11SurfaceData extends XSurfaceData {68X11ComponentPeer peer;69X11GraphicsConfig graphicsConfig;70private RenderLoops solidloops;7172protected int depth;7374private static native void initIDs(Class xorComp, boolean tryDGA);75protected native void initSurface(int depth, int width, int height,76long drawable);7778public static final String79DESC_INT_BGR_X11 = "Integer BGR Pixmap";80public static final String81DESC_INT_RGB_X11 = "Integer RGB Pixmap";8283public static final String84DESC_4BYTE_ABGR_PRE_X11 = "4 byte ABGR Pixmap with pre-multplied alpha";85public static final String86DESC_INT_ARGB_PRE_X11 = "Integer ARGB Pixmap with pre-multiplied " +87"alpha";8889public static final String90DESC_BYTE_IND_OPQ_X11 = "Byte Indexed Opaque Pixmap";9192public static final String93DESC_INT_BGR_X11_BM = "Integer BGR Pixmap with 1-bit transp";94public static final String95DESC_INT_RGB_X11_BM = "Integer RGB Pixmap with 1-bit transp";96public static final String97DESC_BYTE_IND_X11_BM = "Byte Indexed Pixmap with 1-bit transp";9899public static final String100DESC_BYTE_GRAY_X11 = "Byte Gray Opaque Pixmap";101public static final String102DESC_INDEX8_GRAY_X11 = "Index8 Gray Opaque Pixmap";103104public static final String105DESC_BYTE_GRAY_X11_BM = "Byte Gray Opaque Pixmap with 1-bit transp";106public static final String107DESC_INDEX8_GRAY_X11_BM = "Index8 Gray Opaque Pixmap with 1-bit transp";108109public static final String110DESC_3BYTE_RGB_X11 = "3 Byte RGB Pixmap";111public static final String112DESC_3BYTE_BGR_X11 = "3 Byte BGR Pixmap";113114public static final String115DESC_3BYTE_RGB_X11_BM = "3 Byte RGB Pixmap with 1-bit transp";116public static final String117DESC_3BYTE_BGR_X11_BM = "3 Byte BGR Pixmap with 1-bit transp";118119public static final String120DESC_USHORT_555_RGB_X11 = "Ushort 555 RGB Pixmap";121public static final String122DESC_USHORT_565_RGB_X11 = "Ushort 565 RGB Pixmap";123124public static final String125DESC_USHORT_555_RGB_X11_BM126= "Ushort 555 RGB Pixmap with 1-bit transp";127public static final String128DESC_USHORT_565_RGB_X11_BM129= "Ushort 565 RGB Pixmap with 1-bit transp";130public static final String131DESC_USHORT_INDEXED_X11 = "Ushort Indexed Pixmap";132133public static final String134DESC_USHORT_INDEXED_X11_BM = "Ushort Indexed Pixmap with 1-bit transp";135136public static final SurfaceType IntBgrX11 =137SurfaceType.IntBgr.deriveSubType(DESC_INT_BGR_X11);138public static final SurfaceType IntRgbX11 =139SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_X11);140141public static final SurfaceType FourByteAbgrPreX11 =142SurfaceType.FourByteAbgrPre.deriveSubType(DESC_4BYTE_ABGR_PRE_X11);143public static final SurfaceType IntArgbPreX11 =144SurfaceType.IntArgbPre.deriveSubType(DESC_INT_ARGB_PRE_X11);145146public static final SurfaceType ThreeByteRgbX11 =147SurfaceType.ThreeByteRgb.deriveSubType(DESC_3BYTE_RGB_X11);148public static final SurfaceType ThreeByteBgrX11 =149SurfaceType.ThreeByteBgr.deriveSubType(DESC_3BYTE_BGR_X11);150151public static final SurfaceType UShort555RgbX11 =152SurfaceType.Ushort555Rgb.deriveSubType(DESC_USHORT_555_RGB_X11);153public static final SurfaceType UShort565RgbX11 =154SurfaceType.Ushort565Rgb.deriveSubType(DESC_USHORT_565_RGB_X11);155156public static final SurfaceType UShortIndexedX11 =157SurfaceType.UshortIndexed.deriveSubType(DESC_USHORT_INDEXED_X11);158159public static final SurfaceType ByteIndexedOpaqueX11 =160SurfaceType.ByteIndexedOpaque.deriveSubType(DESC_BYTE_IND_OPQ_X11);161162public static final SurfaceType ByteGrayX11 =163SurfaceType.ByteGray.deriveSubType(DESC_BYTE_GRAY_X11);164public static final SurfaceType Index8GrayX11 =165SurfaceType.Index8Gray.deriveSubType(DESC_INDEX8_GRAY_X11);166167// Bitmap surface types168public static final SurfaceType IntBgrX11_BM =169SurfaceType.Custom.deriveSubType(DESC_INT_BGR_X11_BM,170PixelConverter.Xbgr.instance);171public static final SurfaceType IntRgbX11_BM =172SurfaceType.Custom.deriveSubType(DESC_INT_RGB_X11_BM,173PixelConverter.Xrgb.instance);174175public static final SurfaceType ThreeByteRgbX11_BM =176SurfaceType.Custom.deriveSubType(DESC_3BYTE_RGB_X11_BM,177PixelConverter.Xbgr.instance);178public static final SurfaceType ThreeByteBgrX11_BM =179SurfaceType.Custom.deriveSubType(DESC_3BYTE_BGR_X11_BM,180PixelConverter.Xrgb.instance);181182public static final SurfaceType UShort555RgbX11_BM =183SurfaceType.Custom.deriveSubType(DESC_USHORT_555_RGB_X11_BM,184PixelConverter.Ushort555Rgb.instance);185public static final SurfaceType UShort565RgbX11_BM =186SurfaceType.Custom.deriveSubType(DESC_USHORT_565_RGB_X11_BM,187PixelConverter.Ushort565Rgb.instance);188189public static final SurfaceType UShortIndexedX11_BM =190SurfaceType.Custom.deriveSubType(DESC_USHORT_INDEXED_X11_BM);191192public static final SurfaceType ByteIndexedX11_BM =193SurfaceType.Custom.deriveSubType(DESC_BYTE_IND_X11_BM);194195public static final SurfaceType ByteGrayX11_BM =196SurfaceType.Custom.deriveSubType(DESC_BYTE_GRAY_X11_BM);197public static final SurfaceType Index8GrayX11_BM =198SurfaceType.Custom.deriveSubType(DESC_INDEX8_GRAY_X11_BM);199200201private static Boolean accelerationEnabled = null;202203public Raster getRaster(int x, int y, int w, int h) {204throw new InternalError("not implemented yet");205}206207protected X11Renderer x11pipe;208protected PixelToShapeConverter x11txpipe;209protected static TextPipe x11textpipe;210protected static boolean dgaAvailable;211212static {213if (!isX11SurfaceDataInitialized() &&214!GraphicsEnvironment.isHeadless()) {215// If a screen magnifier is present, don't attempt to use DGA216String magPresent = (String) java.security.AccessController.doPrivileged217(new sun.security.action.GetPropertyAction("javax.accessibility.screen_magnifier_present"));218boolean tryDGA = magPresent == null || !"true".equals(magPresent);219220initIDs(XORComposite.class, tryDGA);221222String xtextpipe = (String) java.security.AccessController.doPrivileged223(new sun.security.action.GetPropertyAction("sun.java2d.xtextpipe"));224if (xtextpipe == null || "true".startsWith(xtextpipe)) {225if ("true".equals(xtextpipe)) {226// Only verbose if they use the full string "true"227System.out.println("using X11 text renderer");228}229x11textpipe = new X11TextRenderer();230if (GraphicsPrimitive.tracingEnabled()) {231x11textpipe = ((X11TextRenderer) x11textpipe).traceWrap();232}233} else {234if ("false".equals(xtextpipe)) {235// Only verbose if they use the full string "false"236System.out.println("using DGA text renderer");237}238x11textpipe = solidTextRenderer;239}240241dgaAvailable = isDgaAvailable();242243if (isAccelerationEnabled()) {244X11PMBlitLoops.register();245X11PMBlitBgLoops.register();246}247}248}249250/**251* Returns true if we can use DGA on any of the screens252*/253public static native boolean isDgaAvailable();254255/**256* Returns true if shared memory pixmaps are available257*/258private static native boolean isShmPMAvailable();259260public static boolean isAccelerationEnabled() {261if (accelerationEnabled == null) {262263if (GraphicsEnvironment.isHeadless()) {264accelerationEnabled = Boolean.FALSE;265} else {266String prop =267(String) java.security.AccessController.doPrivileged(268new sun.security.action.GetPropertyAction("sun.java2d.pmoffscreen"));269if (prop != null) {270// true iff prop==true, false otherwise271accelerationEnabled = Boolean.valueOf(prop);272} else {273boolean isDisplayLocal = false;274GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();275if (ge instanceof SunGraphicsEnvironment) {276isDisplayLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal();277}278279// EXA based drivers tend to place pixmaps in VRAM, slowing down readbacks.280// Don't use pixmaps if dga is available,281// or we are local and shared memory Pixmaps are not available.282accelerationEnabled =283!(isDgaAvailable() || (isDisplayLocal && !isShmPMAvailable()));284}285}286}287return accelerationEnabled.booleanValue();288}289290@Override291public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {292return X11SurfaceDataProxy.createProxy(srcData, graphicsConfig);293}294295public void validatePipe(SunGraphics2D sg2d) {296if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON &&297sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&298(sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY ||299sg2d.compositeState == SunGraphics2D.COMP_XOR))300{301if (x11txpipe == null) {302/*303* Note: this is thread-safe since x11txpipe is the304* second of the two pipes constructed in makePipes().305* In the rare case we are racing against another306* thread making new pipes, setting lazypipe is a307* safe alternative to waiting for the other thread.308*/309sg2d.drawpipe = lazypipe;310sg2d.fillpipe = lazypipe;311sg2d.shapepipe = lazypipe;312sg2d.imagepipe = lazypipe;313sg2d.textpipe = lazypipe;314return;315}316317if (sg2d.clipState == SunGraphics2D.CLIP_SHAPE) {318// Do this to init textpipe correctly; we will override the319// other non-text pipes below320// REMIND: we should clean this up eventually instead of321// having this work duplicated.322super.validatePipe(sg2d);323} else {324switch (sg2d.textAntialiasHint) {325326case SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT:327/* equating to OFF which it is for us */328case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:329// Use X11 pipe even if DGA is available since DGA330// text slows everything down when mixed with X11 calls331if (sg2d.compositeState == SunGraphics2D.COMP_ISCOPY) {332sg2d.textpipe = x11textpipe;333} else {334sg2d.textpipe = solidTextRenderer;335}336break;337338case SunHints.INTVAL_TEXT_ANTIALIAS_ON:339// Remind: may use Xrender for these when composite is340// copy as above, or if remote X11.341sg2d.textpipe = aaTextRenderer;342break;343344default:345switch (sg2d.getFontInfo().aaHint) {346347case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:348case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:349sg2d.textpipe = lcdTextRenderer;350break;351352case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:353// Use X11 pipe even if DGA is available since DGA354// text slows everything down when mixed with X11 calls355if (sg2d.compositeState == SunGraphics2D.COMP_ISCOPY) {356sg2d.textpipe = x11textpipe;357} else {358sg2d.textpipe = solidTextRenderer;359}360break;361362case SunHints.INTVAL_TEXT_ANTIALIAS_ON:363sg2d.textpipe = aaTextRenderer;364break;365366default:367sg2d.textpipe = solidTextRenderer;368}369}370}371372if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {373sg2d.drawpipe = x11txpipe;374sg2d.fillpipe = x11txpipe;375} else if (sg2d.strokeState != SunGraphics2D.STROKE_THIN){376sg2d.drawpipe = x11txpipe;377sg2d.fillpipe = x11pipe;378} else {379sg2d.drawpipe = x11pipe;380sg2d.fillpipe = x11pipe;381}382sg2d.shapepipe = x11pipe;383sg2d.imagepipe = imagepipe;384385// This is needed for AA text.386// Note that even an X11TextRenderer can dispatch AA text387// if a GlyphVector overrides the AA setting.388// We use getRenderLoops() rather than setting solidloops389// directly so that we get the appropriate loops in XOR mode.390if (sg2d.loops == null) {391// assert(some pipe will always be a LoopBasedPipe)392sg2d.loops = getRenderLoops(sg2d);393}394} else {395super.validatePipe(sg2d);396}397}398399public RenderLoops getRenderLoops(SunGraphics2D sg2d) {400if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&401sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY)402{403return solidloops;404}405return super.getRenderLoops(sg2d);406}407408public GraphicsConfiguration getDeviceConfiguration() {409return graphicsConfig;410}411412/**413* Method for instantiating a Window SurfaceData414*/415public static X11WindowSurfaceData createData(X11ComponentPeer peer) {416X11GraphicsConfig gc = getGC(peer);417return new X11WindowSurfaceData(peer, gc, gc.getSurfaceType());418}419420/**421* Method for instantiating a Pixmap SurfaceData (offscreen)422*/423public static X11PixmapSurfaceData createData(X11GraphicsConfig gc,424int width, int height,425ColorModel cm, Image image,426long drawable,427int transparency)428{429return new X11PixmapSurfaceData(gc, width, height, image,430getSurfaceType(gc, transparency, true),431cm, drawable, transparency);432}433434// /**435// * Initializes the native Ops pointer.436// */437// private native void initOps(X11ComponentPeer peer,438// X11GraphicsConfig gc, int depth);439440protected X11SurfaceData(X11ComponentPeer peer,441X11GraphicsConfig gc,442SurfaceType sType,443ColorModel cm) {444super(sType, cm);445this.peer = peer;446this.graphicsConfig = gc;447this.solidloops = graphicsConfig.getSolidLoops(sType);448this.depth = cm.getPixelSize();449initOps(peer, graphicsConfig, depth);450if (isAccelerationEnabled()) {451setBlitProxyKey(gc.getProxyKey());452}453}454455public static X11GraphicsConfig getGC(X11ComponentPeer peer) {456if (peer != null) {457return (X11GraphicsConfig) peer.getGraphicsConfiguration();458} else {459GraphicsEnvironment env =460GraphicsEnvironment.getLocalGraphicsEnvironment();461GraphicsDevice gd = env.getDefaultScreenDevice();462return (X11GraphicsConfig)gd.getDefaultConfiguration();463}464}465466/**467* Returns a boolean indicating whether or not a copyArea from468* the given rectangle source coordinates might be incomplete469* and result in X11 GraphicsExposure events being generated470* from XCopyArea.471* This method allows the SurfaceData copyArea method to determine472* if it needs to set the GraphicsExposures attribute of the X11 GC473* to True or False to receive or avoid the events.474* @return true if there is any chance that an XCopyArea from the475* given source coordinates could produce any X11476* Exposure events.477*/478public abstract boolean canSourceSendExposures(int x, int y, int w, int h);479480public boolean copyArea(SunGraphics2D sg2d,481int x, int y, int w, int h, int dx, int dy)482{483if (x11pipe == null) {484if (!isDrawableValid()) {485return true;486}487makePipes();488}489CompositeType comptype = sg2d.imageComp;490if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&491(CompositeType.SrcOverNoEa.equals(comptype) ||492CompositeType.SrcNoEa.equals(comptype)))493{494x += sg2d.transX;495y += sg2d.transY;496SunToolkit.awtLock();497try {498boolean needExposures = canSourceSendExposures(x, y, w, h);499long xgc = getBlitGC(sg2d.getCompClip(), needExposures);500x11pipe.devCopyArea(getNativeOps(), xgc,501x, y,502x + dx, y + dy,503w, h);504} finally {505SunToolkit.awtUnlock();506}507return true;508}509return false;510}511512public static SurfaceType getSurfaceType(X11GraphicsConfig gc,513int transparency)514{515return getSurfaceType(gc, transparency, false);516}517518public static SurfaceType getSurfaceType(X11GraphicsConfig gc,519int transparency,520boolean pixmapSurface)521{522boolean transparent = (transparency == Transparency.BITMASK);523SurfaceType sType;524ColorModel cm = gc.getColorModel();525switch (cm.getPixelSize()) {526case 24:527if (gc.getBitsPerPixel() == 24) {528if (cm instanceof DirectColorModel) {529// 4517321: We will always use ThreeByteBgr for 24 bpp530// surfaces, regardless of the pixel masks reported by531// X11. Despite ambiguity in the X11 spec in how 24 bpp532// surfaces are treated, it appears that the best533// SurfaceType for these configurations (including534// some Matrox Millenium and ATI Radeon boards) is535// ThreeByteBgr.536sType = transparent ? X11SurfaceData.ThreeByteBgrX11_BM : X11SurfaceData.ThreeByteBgrX11;537} else {538throw new sun.java2d.InvalidPipeException("Unsupported bit " +539"depth/cm combo: " +540cm.getPixelSize() +541", " + cm);542}543break;544}545// Fall through for 32 bit case546case 32:547if (cm instanceof DirectColorModel) {548if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit()549).isTranslucencyCapable(gc) && !pixmapSurface)550{551sType = X11SurfaceData.IntArgbPreX11;552} else {553if (((DirectColorModel)cm).getRedMask() == 0xff0000) {554sType = transparent ? X11SurfaceData.IntRgbX11_BM :555X11SurfaceData.IntRgbX11;556} else {557sType = transparent ? X11SurfaceData.IntBgrX11_BM :558X11SurfaceData.IntBgrX11;559}560}561} else if (cm instanceof ComponentColorModel) {562sType = X11SurfaceData.FourByteAbgrPreX11;563} else {564565throw new sun.java2d.InvalidPipeException("Unsupported bit " +566"depth/cm combo: " +567cm.getPixelSize() +568", " + cm);569}570break;571case 15:572sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;573break;574case 16:575if ((cm instanceof DirectColorModel) &&576(((DirectColorModel)cm).getGreenMask() == 0x3e0))577{578// fix for 4352984: Riva128 on Linux579sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;580} else {581sType = transparent ? X11SurfaceData.UShort565RgbX11_BM : X11SurfaceData.UShort565RgbX11;582}583break;584case 12:585if (cm instanceof IndexColorModel) {586sType = transparent ?587X11SurfaceData.UShortIndexedX11_BM :588X11SurfaceData.UShortIndexedX11;589} else {590throw new sun.java2d.InvalidPipeException("Unsupported bit " +591"depth: " +592cm.getPixelSize() +593" cm="+cm);594}595break;596case 8:597if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&598cm instanceof ComponentColorModel) {599sType = transparent ? X11SurfaceData.ByteGrayX11_BM : X11SurfaceData.ByteGrayX11;600} else if (cm instanceof IndexColorModel &&601isOpaqueGray((IndexColorModel)cm)) {602sType = transparent ? X11SurfaceData.Index8GrayX11_BM : X11SurfaceData.Index8GrayX11;603} else {604sType = transparent ? X11SurfaceData.ByteIndexedX11_BM : X11SurfaceData.ByteIndexedOpaqueX11;605}606break;607default:608throw new sun.java2d.InvalidPipeException("Unsupported bit " +609"depth: " +610cm.getPixelSize());611}612return sType;613}614615public void invalidate() {616if (isValid()) {617setInvalid();618super.invalidate();619}620}621622/**623* The following methods and variables are used to keep the Java-level624* context state in sync with the native X11 GC associated with this625* X11SurfaceData object.626*/627628private static native void XSetCopyMode(long xgc);629private static native void XSetXorMode(long xgc);630private static native void XSetForeground(long xgc, int pixel);631632private long xgc;633private Region validatedClip;634private XORComposite validatedXorComp;635private int xorpixelmod;636private int validatedPixel;637private boolean validatedExposures = true;638639public final long getRenderGC(Region clip,640int compState, Composite comp,641int pixel)642{643return getGC(clip, compState, comp, pixel, validatedExposures);644}645646public final long getBlitGC(Region clip, boolean needExposures) {647return getGC(clip, SunGraphics2D.COMP_ISCOPY, null,648validatedPixel, needExposures);649}650651final long getGC(Region clip,652int compState, Composite comp,653int pixel, boolean needExposures)654{655// assert SunToolkit.isAWTLockHeldByCurrentThread();656657if (!isValid()) {658throw new InvalidPipeException("bounds changed");659}660661// validate clip662if (clip != validatedClip) {663validatedClip = clip;664if (clip != null) {665XSetClip(xgc,666clip.getLoX(), clip.getLoY(),667clip.getHiX(), clip.getHiY(),668(clip.isRectangular() ? null : clip));669} else {670XResetClip(xgc);671}672}673674// validate composite675if (compState == SunGraphics2D.COMP_ISCOPY) {676if (validatedXorComp != null) {677validatedXorComp = null;678xorpixelmod = 0;679XSetCopyMode(xgc);680}681} else {682if (validatedXorComp != comp) {683validatedXorComp = (XORComposite)comp;684xorpixelmod = validatedXorComp.getXorPixel();685XSetXorMode(xgc);686}687}688689// validate pixel690pixel ^= xorpixelmod;691if (pixel != validatedPixel) {692validatedPixel = pixel;693XSetForeground(xgc, pixel);694}695696if (validatedExposures != needExposures) {697validatedExposures = needExposures;698XSetGraphicsExposures(xgc, needExposures);699}700701return xgc;702}703704public synchronized void makePipes() {705if (x11pipe == null) {706SunToolkit.awtLock();707try {708xgc = XCreateGC(getNativeOps());709} finally {710SunToolkit.awtUnlock();711}712x11pipe = X11Renderer.getInstance();713x11txpipe = new PixelToShapeConverter(x11pipe);714}715}716717public static class X11WindowSurfaceData extends X11SurfaceData {718public X11WindowSurfaceData(X11ComponentPeer peer,719X11GraphicsConfig gc,720SurfaceType sType) {721super(peer, gc, sType, peer.getColorModel());722if (isDrawableValid()) {723makePipes();724}725}726727public SurfaceData getReplacement() {728return peer.getSurfaceData();729}730731public Rectangle getBounds() {732Rectangle r = peer.getBounds();733r.x = r.y = 0;734return r;735}736737@Override738public boolean canSourceSendExposures(int x, int y, int w, int h) {739return true;740}741742/**743* Returns destination Component associated with this SurfaceData.744*/745public Object getDestination() {746return peer.getTarget();747}748}749750public static class X11PixmapSurfaceData extends X11SurfaceData {751752Image offscreenImage;753int width;754int height;755int transparency;756757public X11PixmapSurfaceData(X11GraphicsConfig gc,758int width, int height,759Image image,760SurfaceType sType, ColorModel cm,761long drawable, int transparency)762{763super(null, gc, sType, cm);764this.width = width;765this.height = height;766offscreenImage = image;767this.transparency = transparency;768initSurface(depth, width, height, drawable);769makePipes();770}771772public SurfaceData getReplacement() {773return restoreContents(offscreenImage);774}775776/**777* Need this since the surface data is created with778* the color model of the target GC, which is always779* opaque. But in SunGraphics2D.blitSD we choose loops780* based on the transparency on the source SD, so781* it could choose wrong loop (blit instead of blitbg,782* for example).783*/784public int getTransparency() {785return transparency;786}787788public Rectangle getBounds() {789return new Rectangle(width, height);790}791792@Override793public boolean canSourceSendExposures(int x, int y, int w, int h) {794return (x < 0 || y < 0 || (x+w) > width || (y+h) > height);795}796797public void flush() {798/*799* We need to invalidate the surface before disposing the800* native Drawable and GC. This way if an application tries801* to render to an already flushed X11SurfaceData, we will notice802* in the validate() method above that it has been invalidated,803* and we will avoid using those native resources that have804* already been disposed.805*/806invalidate();807flushNativeSurface();808}809810/**811* Returns destination Image associated with this SurfaceData.812*/813public Object getDestination() {814return offscreenImage;815}816}817818private static LazyPipe lazypipe = new LazyPipe();819820public static class LazyPipe extends ValidatePipe {821public boolean validate(SunGraphics2D sg2d) {822X11SurfaceData xsd = (X11SurfaceData) sg2d.surfaceData;823if (!xsd.isDrawableValid()) {824return false;825}826xsd.makePipes();827return super.validate(sg2d);828}829}830}831832833