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);
}
}
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;
}
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();
}
}
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);
}
}
}
}
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);
}
Aggregations