下面列出了java.awt.image.ShortLookupTable#sun.java2d.SurfaceData 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void fillSpans(SunGraphics2D sg2d, SpanIterator si) {
// REMIND: Eventually, the plan is that it will not be possible for
// fs to be null since the FillSpans loop will be the fundamental
// loop implemented for any destination type...
if (sg2d.clipState == SunGraphics2D.CLIP_SHAPE) {
si = sg2d.clipRegion.filter(si);
// REMIND: Region.filter produces a Java-only iterator
// with no native counterpart...
} else {
sun.java2d.loops.FillSpans fs = sg2d.loops.fillSpansLoop;
if (fs != null) {
fs.FillSpans(sg2d, sg2d.getSurfaceData(), si);
return;
}
}
int spanbox[] = new int[4];
SurfaceData sd = sg2d.getSurfaceData();
while (si.nextSpan(spanbox)) {
int x = spanbox[0];
int y = spanbox[1];
int w = spanbox[2] - x;
int h = spanbox[3] - y;
sg2d.loops.fillRectLoop.FillRect(sg2d, sd, x, y, w, h);
}
}
public void DrawPolygons(SunGraphics2D sg2d, SurfaceData sData,
int xPoints[], int yPoints[],
int nPoints[], int numPolys,
int transx, int transy,
boolean close)
{
PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);
int off = 0;
Region clip = sg2d.getCompClip();
for (int i = 0; i < numPolys; i++) {
int numpts = nPoints[i];
GeneralRenderer.doDrawPoly(sData, pw,
xPoints, yPoints, off, numpts,
clip, transx, transy, close);
off += numpts;
}
}
private static void fillSpans(SunGraphics2D sg2d, SpanIterator si) {
// REMIND: Eventually, the plan is that it will not be possible for
// fs to be null since the FillSpans loop will be the fundamental
// loop implemented for any destination type...
if (sg2d.clipState == SunGraphics2D.CLIP_SHAPE) {
si = sg2d.clipRegion.filter(si);
// REMIND: Region.filter produces a Java-only iterator
// with no native counterpart...
} else {
sun.java2d.loops.FillSpans fs = sg2d.loops.fillSpansLoop;
if (fs != null) {
fs.FillSpans(sg2d, sg2d.getSurfaceData(), si);
return;
}
}
int spanbox[] = new int[4];
SurfaceData sd = sg2d.getSurfaceData();
while (si.nextSpan(spanbox)) {
int x = spanbox[0];
int y = spanbox[1];
int w = spanbox[2] - x;
int h = spanbox[3] - y;
sg2d.loops.fillRectLoop.FillRect(sg2d, sd, x, y, w, h);
}
}
public static SurfaceData createDataBC(BufferedImage bImg,
SurfaceType sType,
int primaryBank,
double scaleX, double scaleY)
{
ByteComponentRaster bcRaster =
(ByteComponentRaster)bImg.getRaster();
BufImgSurfaceData bisd =
new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType,
scaleX, scaleY);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel)
? (IndexColorModel) cm
: null);
bisd.initRaster(bcRaster.getDataStorage(),
bcRaster.getDataOffset(primaryBank), 0,
bcRaster.getWidth(),
bcRaster.getHeight(),
bcRaster.getPixelStride(),
bcRaster.getScanlineStride(),
icm);
return bisd;
}
@Override
public void BlitBg(SurfaceData src, SurfaceData dst,
Composite comp, Region clip, int bgColor,
int sx, int sy,
int dx, int dy,
int w, int h)
{
SunToolkit.awtLock();
try {
int pixel = dst.pixelFor(bgColor);
X11SurfaceData x11sd = (X11SurfaceData)dst;
// use false for needExposures since we clip to the pixmap
long xgc = x11sd.getBlitGC(clip, false);
nativeBlitBg(src.getNativeOps(), dst.getNativeOps(),
xgc, pixel,
sx, sy, dx, dy, w, h);
} finally {
SunToolkit.awtUnlock();
}
}
@Override
public synchronized void Transform(SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
AffineTransform at, int hint, int srcx,
int srcy, int dstx, int dsty, int width,
int height){
Blit convertsrc = Blit.getFromCache(src.getSurfaceType(),
CompositeType.SrcNoEa,
SurfaceType.IntArgbPre);
// use cached intermediate surface, if available
final SurfaceData cachedSrc = srcTmp != null ? srcTmp.get() : null;
// convert source to IntArgbPre
src = convertFrom(convertsrc, src, srcx, srcy, width, height, cachedSrc,
BufferedImage.TYPE_INT_ARGB_PRE);
// transform IntArgbPre intermediate surface to D3D surface
performop.Transform(src, dst, comp, clip, at, hint, 0, 0, dstx, dsty,
width, height);
if (src != cachedSrc) {
// cache the intermediate surface
srcTmp = new WeakReference<>(src);
}
}
public void DrawPolygons(SunGraphics2D sg2d, SurfaceData sData,
int xPoints[], int yPoints[],
int nPoints[], int numPolys,
int transx, int transy,
boolean close)
{
PixelWriter pw = GeneralRenderer.createXorPixelWriter(sg2d, sData);
int off = 0;
Region clip = sg2d.getCompClip();
for (int i = 0; i < numPolys; i++) {
int numpts = nPoints[i];
GeneralRenderer.doDrawPoly(sData, pw,
xPoints, yPoints, off, numpts,
clip, transx, transy, close);
off += numpts;
}
}
/**
* Creates a software-based surface (of type BufImgSurfaceData).
* The software representation is only created when needed, which
* is only during some situation in which the hardware surface
* cannot be allocated. This allows apps to at least run,
* albeit more slowly than they would otherwise.
*/
protected SurfaceData getBackupSurface() {
if (sdBackup == null) {
GraphicsConfiguration gc = vImg.getGraphicsConfig();
AffineTransform tx = gc.getDefaultTransform();
double scaleX = tx.getScaleX();
double scaleY = tx.getScaleY();
BufferedImage bImg = vImg.getBackupImage(scaleX, scaleY);
// Sabotage the acceleration capabilities of the BufImg surface
SunWritableRaster.stealTrackable(bImg
.getRaster()
.getDataBuffer()).setUntrackable();
sdBackup = BufImgSurfaceData.createData(bImg, scaleX, scaleY);
}
return sdBackup;
}
public static SurfaceData createDataBC(BufferedImage bImg,
SurfaceType sType,
int primaryBank) {
ByteComponentRaster bcRaster =
(ByteComponentRaster)bImg.getRaster();
BufImgSurfaceData bisd =
new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel)
? (IndexColorModel) cm
: null);
bisd.initRaster(bcRaster.getDataStorage(),
bcRaster.getDataOffset(primaryBank), 0,
bcRaster.getWidth(),
bcRaster.getHeight(),
bcRaster.getPixelStride(),
bcRaster.getScanlineStride(),
icm);
return bisd;
}
public void Transform(MaskBlit output,
SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
AffineTransform itx, int txtype,
int sx1, int sy1, int sx2, int sy2,
int dx1, int dy1, int dx2, int dy2,
int edges[], int dxoff, int dyoff)
{
if ((traceflags & TRACEPTIME) == 0) {
tracePrimitive(target);
}
long time = System.nanoTime();
target.Transform(output, src, dst, comp, clip, itx, txtype,
sx1, sy1, sx2, sy2,
dx1, dy1, dx2, dy2,
edges, dxoff, dyoff);
tracePrimitiveTime(target, System.nanoTime() - time);
}
public void drawString(SunGraphics2D sg2d, String s,
double x, double y)
{
FontInfo info = sg2d.getFontInfo();
if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
SurfaceData.outlineTextRenderer.drawString(sg2d, s, x, y);
return;
}
float devx, devy;
if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
double origin[] = {x + info.originX, y + info.originY};
sg2d.transform.transform(origin, 0, origin, 0, 1);
devx = (float)origin[0];
devy = (float)origin[1];
} else {
devx = (float)(x + info.originX + sg2d.transX);
devy = (float)(y + info.originY + sg2d.transY);
}
/* setFromString returns false if shaping is needed, and we then back
* off to a TextLayout. Such text may benefit slightly from a lower
* overhead in this approach over the approach in previous releases.
*/
GlyphList gl = GlyphList.getInstance();
if (gl.setFromString(info, s, devx, devy)) {
drawGlyphList(sg2d, gl);
gl.dispose();
} else {
gl.dispose(); // release this asap.
TextLayout tl = new TextLayout(s, sg2d.getFont(),
sg2d.getFontRenderContext());
tl.draw(sg2d, (float)x, (float)y);
}
}
@Override
public SurfaceData validateSurfaceData(SurfaceData srcData,
SurfaceData cachedData,
int w, int h)
{
if (cachedData == null) {
try {
cachedData = oglgc.createManagedSurface(w, h, transparency);
} catch (OutOfMemoryError er) {
return null;
}
}
return cachedData;
}
public void FillRect(SunGraphics2D sg2d, SurfaceData sData,
int x, int y, int w, int h)
{
PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);
Region r = sg2d.getCompClip().getBoundsIntersectionXYWH(x, y, w, h);
GeneralRenderer.doSetRect(sData, pw,
r.getLoX(), r.getLoY(),
r.getHiX(), r.getHiY());
}
public SurfaceData replaceSurfaceData() {
if (!LWCToolkit.getSunAwtDisableCALayers()) {
surfaceData = windowLayer.replaceSurfaceData();
} else {
if (surfaceData == null) {
CGraphicsConfig graphicsConfig = (CGraphicsConfig)getGraphicsConfiguration();
surfaceData = graphicsConfig.createSurfaceData(this);
} else {
validateSurface();
}
}
return surfaceData;
}
public void MaskBlit(SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
int srcx, int srcy, int dstx, int dsty,
int width, int height,
byte[] mask, int maskoff, int maskscan)
{
tracePrimitive(target);
target.MaskBlit(src, dst, comp, clip,
srcx, srcy, dstx, dsty, width, height,
mask, maskoff, maskscan);
}
static PixelWriter createSolidPixelWriter(SunGraphics2D sg2d,
SurfaceData sData)
{
ColorModel dstCM = sData.getColorModel();
Object srcPixel = dstCM.getDataElements(sg2d.eargb, null);
return new SolidPixelWriter(srcPixel);
}
/**
* Creates a new SurfaceData that will be associated with the given
* WComponentPeer.
*/
@Override
public SurfaceData createSurfaceData(WComponentPeer peer,
int numBackBuffers)
{
SurfaceData sd = WGLSurfaceData.createData(peer);
if (sd == null) {
sd = GDIWindowSurfaceData.createData(peer);
}
return sd;
}
public void FillSpans(SunGraphics2D sg2d, SurfaceData sData,
SpanIterator si)
{
PixelWriter pw = GeneralRenderer.createXorPixelWriter(sg2d, sData);
int span[] = new int[4];
while (si.nextSpan(span)) {
GeneralRenderer.doSetRect(sData, pw,
span[0], span[1], span[2], span[3]);
}
}
public void FillAAPgram(SunGraphics2D sg2d, SurfaceData sData,
Composite comp,
double x, double y,
double dx1, double dy1,
double dx2, double dy2)
{
tracePrimitive(fillPgramTarget);
target.FillAAPgram(sg2d, sData, comp,
x, y, dx1, dy1, dx2, dy2);
}
public void Blit(SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
int sx, int sy, int dx, int dy, int w, int h)
{
D3DBlitLoops.IsoBlit(src, dst,
null, null,
comp, clip, null,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
sx, sy, sx+w, sy+h,
dx, dy, dx+w, dy+h,
true);
}
@Override
protected void validateContext(SurfaceData dstData,
Composite comp, Region clip)
{
OGLSurfaceData oglDst = (OGLSurfaceData)dstData;
OGLContext.validateContext(oglDst, oglDst,
clip, comp, null, null, null,
OGLContext.NO_CONTEXT_FLAGS);
}
/**
* Adds a surface to the list of tracked surfaces.
*
* @param d3dw the surface to be added
*/
private void trackScreenSurface(SurfaceData sd) {
if (!done && sd instanceof D3DWindowSurfaceData) {
synchronized (this) {
if (d3dwSurfaces == null) {
d3dwSurfaces = new ArrayList<D3DWindowSurfaceData>();
}
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData)sd;
if (!d3dwSurfaces.contains(d3dw)) {
d3dwSurfaces.add(d3dw);
}
}
startUpdateThread();
}
}
/**
* Adds a surface to the list of tracked surfaces.
*
* @param d3dw the surface to be added
*/
private void trackScreenSurface(SurfaceData sd) {
if (!done && sd instanceof D3DWindowSurfaceData) {
synchronized (this) {
if (d3dwSurfaces == null) {
d3dwSurfaces = new ArrayList<D3DWindowSurfaceData>();
}
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData)sd;
if (!d3dwSurfaces.contains(d3dw)) {
d3dwSurfaces.add(d3dw);
}
}
startUpdateThread();
}
}
public void Blit(SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
int sx, int sy, int dx, int dy, int w, int h)
{
D3DBlitLoops.IsoBlit(src, dst,
null, null,
comp, clip, null,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
sx, sy, sx+w, sy+h,
dx, dy, dx+w, dy+h,
true);
}
public void MaskFill(SunGraphics2D sg2d, SurfaceData sData,
Composite comp,
int x, int y, int w, int h,
byte[] mask, int maskoff, int maskscan)
{
tracePrimitive(target);
target.MaskFill(sg2d, sData, comp, x, y, w, h,
mask, maskoff, maskscan);
}
@Override
public boolean isSupportedOperation(SurfaceData srcData,
int txtype,
CompositeType comp,
Color bgColor)
{
// These could probably be combined into a single
// nested if, but the logic is easier to follow this way.
// we don't have X11 scale loops, so always use
// software surface in case of scaling
if (txtype >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
return false;
}
if (bgColor != null &&
bgColor.getTransparency() != Transparency.OPAQUE)
{
return false;
}
// for transparent images SrcNoEa+bgColor has the
// same effect as SrcOverNoEa+bgColor, so we allow
// copying from pixmap SD using accelerated blitbg loops:
// SrcOver will be changed to SrcNoEa in DrawImage.blitSD
if (CompositeType.SrcOverNoEa.equals(comp) ||
(CompositeType.SrcNoEa.equals(comp) &&
bgColor != null))
{
return true;
}
return false;
}
@Override
protected void disposeImpl() {
SurfaceData oldData = surfaceData;
surfaceData = null;
ScreenUpdateManager.getInstance().dropScreenSurface(oldData);
oldData.invalidate();
// remove from updater before calling targetDisposedPeer
WToolkit.targetDisposedPeer(target, this);
_dispose();
}
public void Blit(SurfaceData src, SurfaceData dst,
Composite comp, Region clip,
int sx, int sy, int dx, int dy, int w, int h)
{
D3DBlitLoops.IsoBlit(src, dst,
null, null,
comp, clip, null,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
sx, sy, sx+w, sy+h,
dx, dy, dx+w, dy+h,
true);
}
public void DrawLine(SunGraphics2D sg2d, SurfaceData sData,
int x1, int y1, int x2, int y2)
{
PixelWriter pw = GeneralRenderer.createSolidPixelWriter(sg2d, sData);
if (y1 >= y2) {
GeneralRenderer.doDrawLine(sData, pw, null,
sg2d.getCompClip(),
x2, y2, x1, y1);
} else {
GeneralRenderer.doDrawLine(sData, pw, null,
sg2d.getCompClip(),
x1, y1, x2, y2);
}
}
@Override
public boolean isSupportedOperation(SurfaceData srcData,
int txtype,
CompositeType comp,
Color bgColor)
{
// These could probably be combined into a single
// nested if, but the logic is easier to follow this way.
// we don't have X11 scale loops, so always use
// software surface in case of scaling
if (txtype >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
return false;
}
if (bgColor != null &&
bgColor.getTransparency() != Transparency.OPAQUE)
{
return false;
}
// for transparent images SrcNoEa+bgColor has the
// same effect as SrcOverNoEa+bgColor, so we allow
// copying from pixmap SD using accelerated blitbg loops:
// SrcOver will be changed to SrcNoEa in DrawImage.blitSD
if (CompositeType.SrcOverNoEa.equals(comp) ||
(CompositeType.SrcNoEa.equals(comp) &&
bgColor != null))
{
return true;
}
return false;
}