Search in sources :

Example 6 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class OGLAnyCompositeBlit method complexClipBlit.

private synchronized void complexClipBlit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) {
    SurfaceData cachedSrc = null;
    if (srcTmp != null) {
        // use cached intermediate surface, if available
        cachedSrc = srcTmp.get();
    }
    // We can convert argb_pre data from OpenGL surface in two places:
    // - During OpenGL surface -> SW blit
    // - During SW -> SW blit
    // The first one is faster when we use opaque OGL surface, because in
    // this case we simply skip conversion and use color components as is.
    // Because of this we align intermediate buffer type with type of
    // destination not source.
    final int type = typeval == OGLSurfaceData.PF_INT_ARGB_PRE ? BufferedImage.TYPE_INT_ARGB_PRE : BufferedImage.TYPE_INT_ARGB;
    src = convertFrom(this, src, sx, sy, w, h, cachedSrc, type);
    // copy intermediate SW to destination SW using complex clip
    final Blit performop = Blit.getFromCache(src.getSurfaceType(), CompositeType.SrcNoEa, dst.getSurfaceType());
    performop.Blit(src, dst, comp, clip, 0, 0, dx, dy, w, h);
    if (src != cachedSrc) {
        // cache the intermediate surface
        srcTmp = new WeakReference<>(src);
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData) Blit(sun.java2d.loops.Blit) TransformBlit(sun.java2d.loops.TransformBlit) ScaledBlit(sun.java2d.loops.ScaledBlit)

Example 7 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class CGLVolatileSurfaceManager method initAcceleratedSurface.

/**
     * Create a pbuffer-based SurfaceData object (or init the backbuffer
     * of an existing window if this is a double buffered GraphicsConfig)
     */
protected SurfaceData initAcceleratedSurface() {
    SurfaceData sData = null;
    Component comp = vImg.getComponent();
    final ComponentPeer peer = (comp != null) ? comp.getPeer() : null;
    try {
        boolean createVSynced = false;
        boolean forceback = false;
        if (context instanceof Boolean) {
            forceback = ((Boolean) context).booleanValue();
            if (forceback && peer instanceof BackBufferCapsProvider) {
                BackBufferCapsProvider provider = (BackBufferCapsProvider) peer;
                BufferCapabilities caps = provider.getBackBufferCaps();
                if (caps instanceof ExtendedBufferCapabilities) {
                    ExtendedBufferCapabilities ebc = (ExtendedBufferCapabilities) caps;
                    if (ebc.getVSync() == VSYNC_ON && ebc.getFlipContents() == COPIED) {
                        createVSynced = true;
                        forceback = false;
                    }
                }
            }
        }
        if (forceback) {
        // peer must be non-null in this case
        // TODO: modify parameter to delegate
        //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
        } else {
            CGLGraphicsConfig gc = (CGLGraphicsConfig) vImg.getGraphicsConfig();
            ColorModel cm = gc.getColorModel(vImg.getTransparency());
            int type = vImg.getForcedAccelSurfaceType();
            // use the forced type, otherwise choose one based on caps
            if (type == OGLSurfaceData.UNDEFINED) {
                type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ? OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
            }
            if (createVSynced) {
            // TODO: modify parameter to delegate
            //                  sData = CGLSurfaceData.createData(peer, vImg, type);
            } else {
                sData = CGLSurfaceData.createData(gc, vImg.getWidth(), vImg.getHeight(), cm, vImg, type);
            }
        }
    } catch (NullPointerException ex) {
        sData = null;
    } catch (OutOfMemoryError er) {
        sData = null;
    }
    return sData;
}
Also used : ComponentPeer(java.awt.peer.ComponentPeer) ExtendedBufferCapabilities(sun.java2d.pipe.hw.ExtendedBufferCapabilities) SurfaceData(sun.java2d.SurfaceData) ExtendedBufferCapabilities(sun.java2d.pipe.hw.ExtendedBufferCapabilities) BufferCapabilities(java.awt.BufferCapabilities) ColorModel(java.awt.image.ColorModel) BackBufferCapsProvider(sun.java2d.BackBufferCapsProvider) Component(java.awt.Component)

Example 8 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class CWarningWindow method replaceSurface.

private void replaceSurface() {
    SurfaceData oldData = contentView.getSurfaceData();
    replaceSurfaceData();
    if (oldData != null && oldData != contentView.getSurfaceData()) {
        oldData.flush();
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData)

Example 9 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class AlphaPaintPipe method renderPathTile.

public void renderPathTile(Object ctx, byte[] atile, int offset, int tilesize, int x, int y, int w, int h) {
    TileContext context = (TileContext) ctx;
    PaintContext paintCtxt = context.paintCtxt;
    SunGraphics2D sg = context.sunG2D;
    SurfaceData dstData = context.dstData;
    SurfaceData srcData = null;
    Raster lastRas = null;
    if (context.lastData != null && context.lastRaster != null) {
        srcData = (SurfaceData) context.lastData.get();
        lastRas = (Raster) context.lastRaster.get();
        if (srcData == null || lastRas == null) {
            srcData = null;
            lastRas = null;
        }
    }
    ColorModel paintModel = context.paintModel;
    for (int rely = 0; rely < h; rely += TILE_SIZE) {
        int ty = y + rely;
        int th = Math.min(h - rely, TILE_SIZE);
        for (int relx = 0; relx < w; relx += TILE_SIZE) {
            int tx = x + relx;
            int tw = Math.min(w - relx, TILE_SIZE);
            Raster srcRaster = paintCtxt.getRaster(tx, ty, tw, th);
            if ((srcRaster.getMinX() != 0) || (srcRaster.getMinY() != 0)) {
                srcRaster = srcRaster.createTranslatedChild(0, 0);
            }
            if (lastRas != srcRaster) {
                lastRas = srcRaster;
                context.lastRaster = new WeakReference(lastRas);
                // REMIND: This will fail for a non-Writable raster!
                BufferedImage bImg = new BufferedImage(paintModel, (WritableRaster) srcRaster, paintModel.isAlphaPremultiplied(), null);
                srcData = BufImgSurfaceData.createData(bImg);
                context.lastData = new WeakReference(srcData);
                context.lastMask = null;
                context.lastBlit = null;
            }
            if (atile == null) {
                if (context.lastBlit == null) {
                    CompositeType comptype = sg.imageComp;
                    if (CompositeType.SrcOverNoEa.equals(comptype) && paintModel.getTransparency() == Transparency.OPAQUE) {
                        comptype = CompositeType.SrcNoEa;
                    }
                    context.lastBlit = Blit.getFromCache(srcData.getSurfaceType(), comptype, dstData.getSurfaceType());
                }
                context.lastBlit.Blit(srcData, dstData, sg.composite, null, 0, 0, tx, ty, tw, th);
            } else {
                if (context.lastMask == null) {
                    CompositeType comptype = sg.imageComp;
                    if (CompositeType.SrcOverNoEa.equals(comptype) && paintModel.getTransparency() == Transparency.OPAQUE) {
                        comptype = CompositeType.SrcNoEa;
                    }
                    context.lastMask = MaskBlit.getFromCache(srcData.getSurfaceType(), comptype, dstData.getSurfaceType());
                }
                int toff = offset + rely * tilesize + relx;
                context.lastMask.MaskBlit(srcData, dstData, sg.composite, null, 0, 0, tx, ty, tw, th, atile, toff, tilesize);
            }
        }
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData) BufImgSurfaceData(sun.awt.image.BufImgSurfaceData) ColorModel(java.awt.image.ColorModel) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) WeakReference(java.lang.ref.WeakReference) PaintContext(java.awt.PaintContext) SunGraphics2D(sun.java2d.SunGraphics2D) BufferedImage(java.awt.image.BufferedImage) CompositeType(sun.java2d.loops.CompositeType)

Example 10 with SurfaceData

use of sun.java2d.SurfaceData in project jdk8u_jdk by JetBrains.

the class BufferedPaints method setTexturePaint.

/************************** TexturePaint support ****************************/
/**
     * We use OpenGL's texture coordinate generator to automatically
     * map the TexturePaint image to the geometry being rendered.  The
     * generator uses two separate plane equations that take the (x,y)
     * location (in device space) of the fragment being rendered to
     * calculate (u,v) texture coordinates for that fragment:
     *     u = Ax + By + Cz + Dw
     *     v = Ex + Fy + Gz + Hw
     *
     * Since we use a 2D orthographic projection, we can assume that z=0
     * and w=1 for any fragment.  So we need to calculate appropriate
     * values for the plane equation constants (A,B,D) and (E,F,H) such
     * that {u,v}=0 for the top-left of the TexturePaint's anchor
     * rectangle and {u,v}=1 for the bottom-right of the anchor rectangle.
     * We can easily make the texture image repeat for {u,v} values
     * outside the range [0,1] by specifying the GL_REPEAT texture wrap
     * mode.
     *
     * Calculating the plane equation constants is surprisingly simple.
     * We can think of it as an inverse matrix operation that takes
     * device space coordinates and transforms them into user space
     * coordinates that correspond to a location relative to the anchor
     * rectangle.  First, we translate and scale the current user space
     * transform by applying the anchor rectangle bounds.  We then take
     * the inverse of this affine transform.  The rows of the resulting
     * inverse matrix correlate nicely to the plane equation constants
     * we were seeking.
     */
private static void setTexturePaint(RenderQueue rq, SunGraphics2D sg2d, TexturePaint paint, boolean useMask) {
    BufferedImage bi = paint.getImage();
    SurfaceData dstData = sg2d.surfaceData;
    SurfaceData srcData = dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
    boolean filter = (sg2d.interpolationType != AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    // calculate plane equation constants
    AffineTransform at = (AffineTransform) sg2d.transform.clone();
    Rectangle2D anchor = paint.getAnchorRect();
    at.translate(anchor.getX(), anchor.getY());
    at.scale(anchor.getWidth(), anchor.getHeight());
    double xp0, xp1, xp3, yp0, yp1, yp3;
    try {
        at.invert();
        xp0 = at.getScaleX();
        xp1 = at.getShearX();
        xp3 = at.getTranslateX();
        yp0 = at.getShearY();
        yp1 = at.getScaleY();
        yp3 = at.getTranslateY();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0;
    }
    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacityAndAlignment(68, 12);
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_TEXTURE_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(filter ? 1 : 0);
    buf.putLong(srcData.getNativeOps());
    buf.putDouble(xp0).putDouble(xp1).putDouble(xp3);
    buf.putDouble(yp0).putDouble(yp1).putDouble(yp3);
}
Also used : SurfaceData(sun.java2d.SurfaceData) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage)

Aggregations

SurfaceData (sun.java2d.SurfaceData)39 ColorModel (java.awt.image.ColorModel)9 SunGraphics2D (sun.java2d.SunGraphics2D)7 Blit (sun.java2d.loops.Blit)7 TransformBlit (sun.java2d.loops.TransformBlit)7 ScaledBlit (sun.java2d.loops.ScaledBlit)6 SurfaceType (sun.java2d.loops.SurfaceType)6 GDIWindowSurfaceData (sun.java2d.windows.GDIWindowSurfaceData)5 Component (java.awt.Component)4 BufferedImage (java.awt.image.BufferedImage)4 OGLSurfaceData (sun.java2d.opengl.OGLSurfaceData)4 BufferCapabilities (java.awt.BufferCapabilities)3 Graphics (java.awt.Graphics)3 Raster (java.awt.image.Raster)3 WeakReference (java.lang.ref.WeakReference)3 SurfaceManager (sun.awt.image.SurfaceManager)3 InvalidPipeException (sun.java2d.InvalidPipeException)3 D3DSurfaceData (sun.java2d.d3d.D3DSurfaceData)3 Graphics2D (java.awt.Graphics2D)2 PaintContext (java.awt.PaintContext)2