2370N/A/*
3909N/A * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
2370N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2370N/A *
2370N/A * This code is free software; you can redistribute it and/or modify it
2370N/A * under the terms of the GNU General Public License version 2 only, as
2685N/A * published by the Free Software Foundation. Oracle designates this
2370N/A * particular file as subject to the "Classpath" exception as provided
2685N/A * by Oracle in the LICENSE file that accompanied this code.
2370N/A *
2370N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2370N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2370N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2370N/A * version 2 for more details (a copy is included in the LICENSE file that
2370N/A * accompanied this code).
2370N/A *
2370N/A * You should have received a copy of the GNU General Public License version
2370N/A * 2 along with this work; if not, write to the Free Software Foundation,
2370N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2370N/A *
2685N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2685N/A * or visit www.oracle.com if you need additional information or have any
2685N/A * questions.
2370N/A */
2370N/A
2370N/Apackage sun.java2d.xr;
2370N/A
2370N/Aimport java.awt.*;
2370N/Aimport java.awt.geom.*;
2370N/Aimport java.awt.image.*;
2370N/Aimport sun.awt.*;
2370N/Aimport sun.java2d.InvalidPipeException;
2370N/Aimport sun.java2d.SunGraphics2D;
2370N/Aimport sun.java2d.SurfaceData;
2370N/Aimport sun.java2d.SurfaceDataProxy;
2370N/Aimport sun.java2d.jules.*;
2370N/Aimport sun.java2d.loops.*;
2370N/Aimport sun.java2d.pipe.*;
2370N/Aimport sun.java2d.x11.*;
2370N/Aimport sun.font.FontManagerNativeLibrary;
2370N/A
2370N/Apublic abstract class XRSurfaceData extends XSurfaceData {
2370N/A X11ComponentPeer peer;
2370N/A XRGraphicsConfig graphicsConfig;
2370N/A XRBackend renderQueue;
2370N/A
2370N/A private RenderLoops solidloops;
2370N/A
2370N/A protected int depth;
2370N/A
2370N/A private static native void initIDs();
2370N/A
2370N/A protected native void XRInitSurface(int depth, int width, int height,
2370N/A long drawable, int pictFormat);
2370N/A
2370N/A native void initXRPicture(long xsdo, int pictForm);
2370N/A
3610N/A native void freeXSDOPicture(long xsdo);
3610N/A
2370N/A public static final String DESC_BYTE_A8_X11 = "Byte A8 Pixmap";
2370N/A public static final String DESC_INT_RGB_X11 = "Integer RGB Pixmap";
2370N/A public static final String DESC_INT_ARGB_X11 = "Integer ARGB-Pre Pixmap";
2370N/A
2370N/A public static final SurfaceType
2370N/A ByteA8X11 = SurfaceType.ByteGray.deriveSubType(DESC_BYTE_A8_X11);
2370N/A public static final SurfaceType
2370N/A IntRgbX11 = SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_X11);
2370N/A public static final SurfaceType
2370N/A IntArgbPreX11 = SurfaceType.IntArgbPre.deriveSubType(DESC_INT_ARGB_X11);
2370N/A
2370N/A public Raster getRaster(int x, int y, int w, int h) {
2370N/A throw new InternalError("not implemented yet");
2370N/A }
2370N/A
2370N/A protected XRRenderer xrpipe;
2370N/A protected PixelToShapeConverter xrtxpipe;
2370N/A protected TextPipe xrtextpipe;
2370N/A protected XRDrawImage xrDrawImage;
2370N/A
2370N/A protected ShapeDrawPipe aaShapePipe;
2370N/A protected PixelToShapeConverter aaPixelToShapeConv;
2370N/A
2370N/A public static void initXRSurfaceData() {
2370N/A if (!isX11SurfaceDataInitialized()) {
2370N/A FontManagerNativeLibrary.load();
2370N/A initIDs();
2370N/A XRPMBlitLoops.register();
2370N/A XRMaskFill.register();
2370N/A XRMaskBlit.register();
2370N/A
2370N/A setX11SurfaceDataInitialized();
2370N/A }
2370N/A }
2370N/A
2370N/A /**
2370N/A * Synchronized accessor method for isDrawableValid.
2370N/A */
2370N/A protected boolean isXRDrawableValid() {
2370N/A try {
2370N/A SunToolkit.awtLock();
2370N/A return isDrawableValid();
2370N/A } finally {
2370N/A SunToolkit.awtUnlock();
2370N/A }
2370N/A }
2370N/A
2370N/A @Override
2370N/A public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
2370N/A return XRSurfaceDataProxy.createProxy(srcData, graphicsConfig);
2370N/A }
2370N/A
2370N/A public void validatePipe(SunGraphics2D sg2d) {
2370N/A TextPipe textpipe;
2370N/A boolean validated = false;
2370N/A
2370N/A /*
2370N/A * The textpipe for now can't handle TexturePaint when extra-alpha is
2370N/A * specified nore XOR mode
2370N/A */
2370N/A if (sg2d.compositeState < SunGraphics2D.COMP_XOR &&
2370N/A (sg2d.paintState < SunGraphics2D.PAINT_TEXTURE ||
2370N/A sg2d.composite == null ||
2370N/A !(sg2d.composite instanceof AlphaComposite) ||
2370N/A ((AlphaComposite) sg2d.composite).getAlpha() == 1.0f))
2370N/A {
2370N/A textpipe = xrtextpipe;
2370N/A } else {
2370N/A super.validatePipe(sg2d);
2370N/A textpipe = sg2d.textpipe;
2370N/A validated = true;
2370N/A }
2370N/A
2370N/A PixelToShapeConverter txPipe = null;
2370N/A XRRenderer nonTxPipe = null;
2370N/A
2370N/A /*
2370N/A * TODO: Can we rely on the GC for ARGB32 surfaces?
2370N/A */
2370N/A if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
2370N/A if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
2370N/A if (sg2d.compositeState <= SunGraphics2D.COMP_XOR) {
2370N/A txPipe = xrtxpipe;
2370N/A nonTxPipe = xrpipe;
2370N/A }
2370N/A } else if (sg2d.compositeState <= SunGraphics2D.COMP_ALPHA) {
2370N/A if (XRPaints.isValid(sg2d)) {
2370N/A txPipe = xrtxpipe;
2370N/A nonTxPipe = xrpipe;
2370N/A }
2370N/A // custom paints handled by super.validatePipe() below
2370N/A }
2370N/A }
2370N/A
2370N/A if (sg2d.antialiasHint == SunHints.INTVAL_ANTIALIAS_ON &&
2370N/A JulesPathBuf.isCairoAvailable())
2370N/A {
2370N/A sg2d.shapepipe = aaShapePipe;
2370N/A sg2d.drawpipe = aaPixelToShapeConv;
2370N/A sg2d.fillpipe = aaPixelToShapeConv;
2370N/A } else {
2370N/A if (txPipe != null) {
2370N/A if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
2370N/A sg2d.drawpipe = txPipe;
2370N/A sg2d.fillpipe = txPipe;
2370N/A } else if (sg2d.strokeState != SunGraphics2D.STROKE_THIN) {
2370N/A sg2d.drawpipe = txPipe;
2370N/A sg2d.fillpipe = nonTxPipe;
2370N/A } else {
2370N/A sg2d.drawpipe = nonTxPipe;
2370N/A sg2d.fillpipe = nonTxPipe;
2370N/A }
2370N/A sg2d.shapepipe = nonTxPipe;
2370N/A } else {
2370N/A if (!validated) {
2370N/A super.validatePipe(sg2d);
2370N/A }
2370N/A }
2370N/A }
2370N/A
2370N/A // install the text pipe based on our earlier decision
2370N/A sg2d.textpipe = textpipe;
2370N/A
2370N/A // always override the image pipe with the specialized XRender pipe
2370N/A sg2d.imagepipe = xrDrawImage;
2370N/A }
2370N/A
2370N/A protected MaskFill getMaskFill(SunGraphics2D sg2d) {
2370N/A if (sg2d.paintState > SunGraphics2D.PAINT_ALPHACOLOR &&
2370N/A !XRPaints.isValid(sg2d))
2370N/A {
2370N/A return null;
2370N/A }
2370N/A return super.getMaskFill(sg2d);
2370N/A }
2370N/A
2370N/A public RenderLoops getRenderLoops(SunGraphics2D sg2d) {
2370N/A if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
2370N/A sg2d.compositeState <= SunGraphics2D.COMP_ALPHA)
2370N/A {
2370N/A return solidloops;
2370N/A }
2370N/A
2370N/A return super.getRenderLoops(sg2d);
2370N/A }
2370N/A
2370N/A public GraphicsConfiguration getDeviceConfiguration() {
2370N/A return graphicsConfig;
2370N/A }
2370N/A
2370N/A /**
2370N/A * Method for instantiating a Window SurfaceData
2370N/A */
2370N/A public static XRWindowSurfaceData createData(X11ComponentPeer peer) {
2370N/A XRGraphicsConfig gc = getGC(peer);
2370N/A return new XRWindowSurfaceData(peer, gc, gc.getSurfaceType());
2370N/A }
2370N/A
2370N/A /**
2370N/A * Method for instantiating a Pixmap SurfaceData (offscreen).
2370N/A * If the surface * is opaque a 24-bit/RGB surface is chosen,
2370N/A * otherwise a 32-bit ARGB surface.
2370N/A */
2370N/A public static XRPixmapSurfaceData createData(XRGraphicsConfig gc,
2370N/A int width, int height,
2370N/A ColorModel cm, Image image,
2370N/A long drawable,
2370N/A int transparency) {
2370N/A int depth = transparency > Transparency.OPAQUE ? 32 : 24;
2370N/A if (depth == 24) {
2370N/A cm = new DirectColorModel(depth,
2370N/A 0x00FF0000, 0x0000FF00, 0x000000FF);
2370N/A } else {
2370N/A cm = new DirectColorModel(depth, 0x00FF0000, 0x0000FF00,
2370N/A 0x000000FF, 0xFF000000);
2370N/A }
2370N/A
2370N/A return new XRPixmapSurfaceData
2370N/A (gc, width, height, image, getSurfaceType(gc, transparency),
2370N/A cm, drawable, transparency,
2370N/A XRUtils.getPictureFormatForTransparency(transparency), depth);
2370N/A }
2370N/A
2370N/A protected XRSurfaceData(X11ComponentPeer peer, XRGraphicsConfig gc,
2370N/A SurfaceType sType, ColorModel cm, int depth, int transparency)
2370N/A {
2370N/A super(sType, cm);
2370N/A this.peer = peer;
2370N/A this.graphicsConfig = gc;
2370N/A this.solidloops = graphicsConfig.getSolidLoops(sType);
2370N/A this.depth = depth;
2370N/A initOps(peer, graphicsConfig, depth);
2370N/A
2370N/A setBlitProxyKey(gc.getProxyKey());
2370N/A }
2370N/A
2370N/A protected XRSurfaceData(XRBackend renderQueue) {
2370N/A super(XRSurfaceData.IntRgbX11,
2370N/A new DirectColorModel(24, 0x00FF0000, 0x0000FF00, 0x000000FF));
2370N/A this.renderQueue = renderQueue;
2370N/A }
2370N/A
2370N/A /**
2370N/A * Inits the XRender-data-structures which belong to the XRSurfaceData.
2370N/A *
2370N/A * @param pictureFormat
2370N/A */
2370N/A public void initXRender(int pictureFormat) {
2370N/A try {
2370N/A SunToolkit.awtLock();
2370N/A initXRPicture(getNativeOps(), pictureFormat);
2370N/A renderQueue = XRCompositeManager.getInstance(this).getBackend();
2370N/A maskBuffer = XRCompositeManager.getInstance(this);
2370N/A } catch (Throwable ex) {
2370N/A ex.printStackTrace();
2370N/A } finally {
2370N/A SunToolkit.awtUnlock();
2370N/A }
2370N/A }
2370N/A
2370N/A public static XRGraphicsConfig getGC(X11ComponentPeer peer) {
2370N/A if (peer != null) {
2370N/A return (XRGraphicsConfig) peer.getGraphicsConfiguration();
2370N/A } else {
2370N/A GraphicsEnvironment env =
2370N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
2370N/A GraphicsDevice gd = env.getDefaultScreenDevice();
2370N/A return (XRGraphicsConfig) gd.getDefaultConfiguration();
2370N/A }
2370N/A }
2370N/A
2370N/A /**
2370N/A * Returns a boolean indicating whether or not a copyArea from the given
2370N/A * rectangle source coordinates might be incomplete and result in X11
2370N/A * GraphicsExposure events being generated from XCopyArea. This method
2370N/A * allows the SurfaceData copyArea method to determine if it needs to set
2370N/A * the GraphicsExposures attribute of the X11 GC to True or False to receive
2370N/A * or avoid the events.
2370N/A *
2370N/A * @return true if there is any chance that an XCopyArea from the given
2370N/A * source coordinates could produce any X11 Exposure events.
2370N/A */
2370N/A public abstract boolean canSourceSendExposures(int x, int y, int w, int h);
2370N/A
2370N/A /**
2370N/A * CopyArea is implemented using the "old" X11 GC, therefor clip and
2370N/A * needExposures have to be validated against that GC. Pictures and GCs
2370N/A * don't share state.
2370N/A */
2370N/A public void validateCopyAreaGC(Region gcClip, boolean needExposures) {
2370N/A if (validatedGCClip != gcClip) {
2370N/A if (gcClip != null)
2370N/A renderQueue.setGCClipRectangles(xgc, gcClip);
2370N/A validatedGCClip = gcClip;
2370N/A }
2370N/A
2370N/A if (validatedExposures != needExposures) {
2370N/A validatedExposures = needExposures;
2370N/A renderQueue.setGCExposures(xgc, needExposures);
2370N/A }
2370N/A
2370N/A if (validatedXorComp != null) {
2370N/A renderQueue.setGCMode(xgc, true);
2370N/A renderQueue.setGCForeground(xgc, validatedGCForegroundPixel);
2370N/A validatedXorComp = null;
2370N/A }
2370N/A }
2370N/A
2370N/A public boolean copyArea(SunGraphics2D sg2d, int x, int y, int w, int h,
2370N/A int dx, int dy) {
2370N/A if (xrpipe == null) {
2370N/A if (!isXRDrawableValid()) {
2370N/A return true;
2370N/A }
2370N/A makePipes();
2370N/A }
2370N/A CompositeType comptype = sg2d.imageComp;
2370N/A if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&
2370N/A (CompositeType.SrcOverNoEa.equals(comptype) ||
2370N/A CompositeType.SrcNoEa.equals(comptype)))
2370N/A {
2370N/A x += sg2d.transX;
2370N/A y += sg2d.transY;
2370N/A try {
2370N/A SunToolkit.awtLock();
2370N/A boolean needExposures = canSourceSendExposures(x, y, w, h);
2370N/A validateCopyAreaGC(sg2d.getCompClip(), needExposures);
2370N/A renderQueue.copyArea(xid, xid, xgc, x, y, w, h, x + dx, y + dy);
2370N/A } finally {
2370N/A SunToolkit.awtUnlock();
2370N/A }
2370N/A return true;
2370N/A }
2370N/A return false;
2370N/A }
2370N/A
2370N/A /**
2370N/A * Returns the XRender SurfaceType which is able to fullfill the specified
2370N/A * transparency requirement.
2370N/A */
2370N/A public static SurfaceType getSurfaceType(XRGraphicsConfig gc,
2370N/A int transparency) {
2370N/A SurfaceType sType = null;
2370N/A
2370N/A switch (transparency) {
2370N/A case Transparency.OPAQUE:
2370N/A sType = XRSurfaceData.IntRgbX11;
2370N/A break;
2370N/A
2370N/A case Transparency.BITMASK:
2370N/A case Transparency.TRANSLUCENT:
2370N/A sType = XRSurfaceData.IntArgbPreX11;
2370N/A break;
2370N/A }
2370N/A
2370N/A return sType;
2370N/A }
2370N/A
2370N/A public void invalidate() {
2370N/A if (isValid()) {
2370N/A setInvalid();
2370N/A super.invalidate();
2370N/A }
2370N/A }
2370N/A
2370N/A private long xgc; // GC is still used for copyArea
2370N/A private int validatedGCForegroundPixel = 0;
2370N/A private XORComposite validatedXorComp;
2370N/A private int xid;
2370N/A public int picture;
2370N/A public XRCompositeManager maskBuffer;
2370N/A
2370N/A private Region validatedClip;
2370N/A private Region validatedGCClip;
2370N/A private boolean validatedExposures = true;
2370N/A
2370N/A boolean transformInUse = false;
2370N/A AffineTransform validatedSourceTransform = new AffineTransform();
2370N/A int validatedRepeat = XRUtils.RepeatNone;
2370N/A int validatedFilter = XRUtils.FAST;
2370N/A
2370N/A /**
2370N/A * Validates an XRSurfaceData when used as source. Note that the clip is
2370N/A * applied when used as source as well as destination.
2370N/A */
2370N/A void validateAsSource(AffineTransform sxForm, int repeat, int filter) {
2370N/A
2370N/A if (validatedClip != null) {
2370N/A validatedClip = null;
2370N/A renderQueue.setClipRectangles(picture, null);
2370N/A }
2370N/A
2370N/A if (validatedRepeat != repeat && repeat != -1) {
2370N/A validatedRepeat = repeat;
2370N/A renderQueue.setPictureRepeat(picture, repeat);
2370N/A }
2370N/A
2370N/A if (sxForm == null) {
2370N/A if (transformInUse) {
2370N/A validatedSourceTransform.setToIdentity();
2370N/A renderQueue.setPictureTransform(picture,
2370N/A validatedSourceTransform);
2370N/A transformInUse = false;
2370N/A }
2370N/A } else if (!transformInUse ||
2370N/A (transformInUse && !sxForm.equals(validatedSourceTransform))) {
2370N/A validatedSourceTransform.setTransform(sxForm.getScaleX(),
2370N/A sxForm.getShearY(),
2370N/A sxForm.getShearX(),
2370N/A sxForm.getScaleY(),
2370N/A sxForm.getTranslateX(),
2370N/A sxForm.getTranslateY());
2370N/A renderQueue.setPictureTransform(picture, validatedSourceTransform);
2370N/A transformInUse = true;
2370N/A }
2370N/A
2370N/A if (filter != validatedFilter && filter != -1) {
2370N/A renderQueue.setFilter(picture, filter);
2370N/A validatedFilter = filter;
2370N/A }
2370N/A }
2370N/A
2370N/A /**
2370N/A * Validates the Surface when used as destination.
2370N/A */
2370N/A public void validateAsDestination(SunGraphics2D sg2d, Region clip) {
2370N/A if (!isValid()) {
2370N/A throw new InvalidPipeException("bounds changed");
2370N/A }
2370N/A
2370N/A boolean updateGCClip = false;
2370N/A if (clip != validatedClip) {
2370N/A renderQueue.setClipRectangles(picture, clip);
2370N/A validatedClip = clip;
2370N/A updateGCClip = true;
2370N/A }
2370N/A
2370N/A if (sg2d != null && sg2d.compositeState == SunGraphics2D.COMP_XOR) {
2370N/A if (validatedXorComp != sg2d.getComposite()) {
2370N/A validatedXorComp = (XORComposite) sg2d.getComposite();
2370N/A int xorpixelmod = validatedXorComp.getXorPixel();
2370N/A renderQueue.setGCMode(xgc, false);
2370N/A
2370N/A // validate pixel
2370N/A int pixel = sg2d.pixel;
2370N/A if (validatedGCForegroundPixel != pixel) {
2370N/A renderQueue.setGCForeground(xgc, pixel ^ xorpixelmod);
2370N/A validatedGCForegroundPixel = pixel;
2370N/A }
2370N/A }
2370N/A
2370N/A if (updateGCClip) {
2370N/A renderQueue.setGCClipRectangles(xgc, clip);
2370N/A }
2370N/A }
2370N/A }
2370N/A
2370N/A public synchronized void makePipes() { /*
2370N/A * TODO: Why is this synchronized,
2370N/A * but access not?
2370N/A */
2370N/A if (xrpipe == null) {
2370N/A try {
2370N/A SunToolkit.awtLock();
3537N/A xgc = XCreateGC(getNativeOps());
2370N/A
2370N/A xrpipe = new XRRenderer(maskBuffer.getMaskBuffer());
2370N/A xrtxpipe = new PixelToShapeConverter(xrpipe);
2370N/A xrtextpipe = maskBuffer.getTextRenderer();
2370N/A xrDrawImage = new XRDrawImage();
2370N/A
2370N/A if (JulesPathBuf.isCairoAvailable()) {
2370N/A aaShapePipe =
2370N/A new JulesShapePipe(XRCompositeManager.getInstance(this));
2370N/A aaPixelToShapeConv = new PixelToShapeConverter(aaShapePipe);
2370N/A }
2370N/A } finally {
2370N/A SunToolkit.awtUnlock();
2370N/A }
2370N/A }
2370N/A }
2370N/A
2370N/A public static class XRWindowSurfaceData extends XRSurfaceData {
2370N/A public XRWindowSurfaceData(X11ComponentPeer peer,
2370N/A XRGraphicsConfig gc, SurfaceType sType) {
2370N/A super(peer, gc, sType, peer.getColorModel(),
2370N/A peer.getColorModel().getPixelSize(), Transparency.OPAQUE);
2370N/A
2370N/A if (isXRDrawableValid()) {
2370N/A initXRender(XRUtils.
2370N/A getPictureFormatForTransparency(Transparency.OPAQUE));
2370N/A makePipes();
2370N/A }
2370N/A }
2370N/A
2370N/A public SurfaceData getReplacement() {
2370N/A return peer.getSurfaceData();
2370N/A }
2370N/A
2370N/A public Rectangle getBounds() {
2370N/A Rectangle r = peer.getBounds();
2370N/A r.x = r.y = 0;
2370N/A return r;
2370N/A }
2370N/A
2370N/A @Override
2370N/A public boolean canSourceSendExposures(int x, int y, int w, int h) {
2370N/A return true;
2370N/A }
2370N/A
2370N/A /**
2370N/A * Returns destination Component associated with this SurfaceData.
2370N/A */
2370N/A public Object getDestination() {
2370N/A return peer.getTarget();
2370N/A }
3610N/A
3610N/A public void invalidate() {
3610N/A try {
3610N/A SunToolkit.awtLock();
3610N/A freeXSDOPicture(getNativeOps());
3610N/A }finally {
3610N/A SunToolkit.awtUnlock();
3610N/A }
3610N/A
3610N/A super.invalidate();
3610N/A }
2370N/A }
2370N/A
2370N/A public static class XRInternalSurfaceData extends XRSurfaceData {
2370N/A public XRInternalSurfaceData(XRBackend renderQueue, int pictXid,
2370N/A AffineTransform transform) {
2370N/A super(renderQueue);
2370N/A this.picture = pictXid;
2370N/A this.validatedSourceTransform = transform;
2370N/A
2370N/A if (validatedSourceTransform != null) {
2370N/A transformInUse = true;
2370N/A }
2370N/A }
2370N/A
2370N/A public boolean canSourceSendExposures(int x, int y, int w, int h) {
2370N/A return false;
2370N/A }
2370N/A
2370N/A public Rectangle getBounds() {
2370N/A return null;
2370N/A }
2370N/A
2370N/A public Object getDestination() {
2370N/A return null;
2370N/A }
2370N/A
2370N/A public SurfaceData getReplacement() {
2370N/A return null;
2370N/A }
2370N/A }
2370N/A
2370N/A public static class XRPixmapSurfaceData extends XRSurfaceData {
2370N/A Image offscreenImage;
2370N/A int width;
2370N/A int height;
2370N/A int transparency;
2370N/A
2370N/A public XRPixmapSurfaceData(XRGraphicsConfig gc, int width, int height,
2370N/A Image image, SurfaceType sType,
2370N/A ColorModel cm, long drawable,
2370N/A int transparency, int pictFormat,
2370N/A int depth) {
2370N/A super(null, gc, sType, cm, depth, transparency);
2370N/A this.width = width;
2370N/A this.height = height;
2370N/A offscreenImage = image;
2370N/A this.transparency = transparency;
2370N/A initSurface(depth, width, height, drawable, pictFormat);
2370N/A
2370N/A initXRender(pictFormat);
2370N/A makePipes();
2370N/A }
2370N/A
2370N/A public void initSurface(int depth, int width, int height,
2370N/A long drawable, int pictFormat) {
2370N/A try {
2370N/A SunToolkit.awtLock();
2370N/A XRInitSurface(depth, width, height, drawable, pictFormat);
2370N/A } finally {
2370N/A SunToolkit.awtUnlock();
2370N/A }
2370N/A }
2370N/A
2370N/A public SurfaceData getReplacement() {
2370N/A return restoreContents(offscreenImage);
2370N/A }
2370N/A
2370N/A /**
2370N/A * Need this since the surface data is created with the color model of
2370N/A * the target GC, which is always opaque. But in SunGraphics2D.blitSD we
2370N/A * choose loops based on the transparency on the source SD, so it could
2370N/A * choose wrong loop (blit instead of blitbg, for example).
2370N/A */
2370N/A public int getTransparency() {
2370N/A return transparency;
2370N/A }
2370N/A
2370N/A public Rectangle getBounds() {
2370N/A return new Rectangle(width, height);
2370N/A }
2370N/A
2370N/A @Override
2370N/A public boolean canSourceSendExposures(int x, int y, int w, int h) {
2370N/A return (x < 0 || y < 0 || (x + w) > width || (y + h) > height);
2370N/A }
2370N/A
2370N/A public void flush() {
2370N/A /*
2370N/A * We need to invalidate the surface before disposing the native
2370N/A * Drawable and Picture. This way if an application tries to render
2370N/A * to an already flushed XRSurfaceData, we will notice in the
2370N/A * validate() method above that it has been invalidated, and we will
2370N/A * avoid using those native resources that have already been
2370N/A * disposed.
2370N/A */
2370N/A invalidate();
2370N/A flushNativeSurface();
2370N/A }
2370N/A
2370N/A /**
2370N/A * Returns destination Image associated with this SurfaceData.
2370N/A */
2370N/A public Object getDestination() {
2370N/A return offscreenImage;
2370N/A }
2370N/A }
2370N/A
2370N/A public long getGC() {
2370N/A return xgc;
2370N/A }
2370N/A
2370N/A public static class LazyPipe extends ValidatePipe {
2370N/A public boolean validate(SunGraphics2D sg2d) {
2370N/A XRSurfaceData xsd = (XRSurfaceData) sg2d.surfaceData;
2370N/A if (!xsd.isXRDrawableValid()) {
2370N/A return false;
2370N/A }
2370N/A xsd.makePipes();
2370N/A return super.validate(sg2d);
2370N/A }
2370N/A }
2370N/A
2370N/A public int getPicture() {
2370N/A return picture;
2370N/A }
2370N/A
2370N/A public int getXid() {
2370N/A return xid;
2370N/A }
2370N/A
2370N/A public XRGraphicsConfig getGraphicsConfig() {
2370N/A return graphicsConfig;
2370N/A }
2370N/A}