Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/sun/java2d/OSXOffScreenSurfaceData.java
38829 views
/*1* Copyright (c) 2011, 2017, 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;2627import java.awt.*;28import java.awt.color.*;29import java.awt.image.*;30import java.nio.*;3132import sun.awt.image.*;33import sun.java2d.loops.*;3435public class OSXOffScreenSurfaceData extends OSXSurfaceData // implements RasterListener36{37private static native void initIDs();3839static {40initIDs();41}4243// the image associated with this surface44BufferedImage bim;45// the image associated with this custom surface46BufferedImage bimBackup;47// <rdar://problem/4177639> nio based images use ARGB_PRE48static DirectColorModel dcmBackup = new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, true, DataBuffer.TYPE_INT);4950Object lock;5152// cached rasters for easy access53WritableRaster bufImgRaster;54SunWritableRaster bufImgSunRaster;5556// these are extra image types we can handle57private static final int TYPE_3BYTE_RGB = BufferedImage.TYPE_BYTE_INDEXED + 1;5859// these are for callbacks when pixes have been touched60protected ByteBuffer fImageInfo;61IntBuffer fImageInfoInt;62private static final int kNeedToSyncFromJavaPixelsIndex = 0;63private static final int kNativePixelsChangedIndex = 1;64private static final int kImageStolenIndex = 2;65private static final int kSizeOfParameters = kImageStolenIndex + 1;6667public static native SurfaceData getSurfaceData(BufferedImage bufImg);6869protected static native void setSurfaceData(BufferedImage bufImg, SurfaceData sData);7071public static SurfaceData createData(BufferedImage bufImg) {72/*73* if ((bufImg.getWidth() == 32) && (bufImg.getHeight() == 32)) { Thread.dumpStack(); }74*/75// This could be called from multiple threads. We need to synchronized on the image so that76// we can ensure that only one surface data is created per image. (<rdar://4564873>)77// Note: Eventually, we should switch to using the same mechanism (CachingSurfaceManager) that Sun uses78// <rdar://4563741>79synchronized (bufImg) {80SurfaceData sData = getSurfaceData(bufImg);81if (sData != null) { return sData; }8283OSXOffScreenSurfaceData osData = OSXOffScreenSurfaceData.createNewSurface(bufImg);8485OSXOffScreenSurfaceData.setSurfaceData(bufImg, osData);86osData.cacheRasters(bufImg);87// osData.setRasterListener();8889return osData;90}91}9293public static SurfaceData createData(Raster ras, ColorModel cm) {94throw new InternalError("SurfaceData not implemented for Raster/CM");95}9697static OSXOffScreenSurfaceData createNewSurface(BufferedImage bufImg) {98SurfaceData sData = null;99100ColorModel cm = bufImg.getColorModel();101int type = bufImg.getType();102// REMIND: Check the image type and pick an appropriate subclass103switch (type) {104case BufferedImage.TYPE_INT_BGR:105sData = createDataIC(bufImg, SurfaceType.IntBgr);106break;107case BufferedImage.TYPE_INT_RGB:108sData = createDataIC(bufImg, SurfaceType.IntRgb);109break;110case BufferedImage.TYPE_INT_ARGB:111sData = createDataIC(bufImg, SurfaceType.IntArgb);112break;113case BufferedImage.TYPE_INT_ARGB_PRE:114sData = createDataIC(bufImg, SurfaceType.IntArgbPre);115break;116case BufferedImage.TYPE_3BYTE_BGR:117sData = createDataBC(bufImg, SurfaceType.ThreeByteBgr, 2);118break;119case BufferedImage.TYPE_4BYTE_ABGR:120sData = createDataBC(bufImg, SurfaceType.FourByteAbgr, 3);121break;122case BufferedImage.TYPE_4BYTE_ABGR_PRE:123sData = createDataBC(bufImg, SurfaceType.FourByteAbgrPre, 3);124break;125case BufferedImage.TYPE_USHORT_565_RGB:126sData = createDataSC(bufImg, SurfaceType.Ushort565Rgb, null);127break;128case BufferedImage.TYPE_USHORT_555_RGB:129sData = createDataSC(bufImg, SurfaceType.Ushort555Rgb, null);130break;131case BufferedImage.TYPE_BYTE_INDEXED: {132SurfaceType sType;133switch (cm.getTransparency()) {134case OPAQUE:135if (isOpaqueGray((IndexColorModel) cm)) {136sType = SurfaceType.Index8Gray;137} else {138sType = SurfaceType.ByteIndexedOpaque;139}140break;141case BITMASK:142sType = SurfaceType.ByteIndexedBm;143break;144case TRANSLUCENT:145sType = SurfaceType.ByteIndexed;146break;147default:148throw new InternalError("Unrecognized transparency");149}150sData = createDataBC(bufImg, sType, 0);151}152break;153case BufferedImage.TYPE_BYTE_GRAY:154sData = createDataBC(bufImg, SurfaceType.ByteGray, 0);155break;156case BufferedImage.TYPE_USHORT_GRAY:157sData = createDataSC(bufImg, SurfaceType.UshortGray, null);158break;159case BufferedImage.TYPE_BYTE_BINARY:160case BufferedImage.TYPE_CUSTOM:161default: {162Raster raster = bufImg.getRaster();163164// we try to fit a custom image into one of the predefined BufferedImages (BufferedImage does that165// first, we further refine it here)166// we can do that because a pointer in C is a pointer (pixel pointer not dependent on DataBuffer type)167SampleModel sm = bufImg.getSampleModel();168SurfaceType sType = SurfaceType.Custom;169int transferType = cm.getTransferType();170int pixelSize = cm.getPixelSize();171int numOfComponents = cm.getNumColorComponents();172if ((numOfComponents == 3) && (cm instanceof ComponentColorModel) && (sm instanceof PixelInterleavedSampleModel)) {173int sizes[] = cm.getComponentSize();174boolean validsizes = (sizes[0] == 8) && (sizes[1] == 8) && (sizes[2] == 8);175int[] offs = ((ComponentSampleModel) sm).getBandOffsets();176int numBands = raster.getNumBands();177boolean bigendian = (offs[0] == numBands - 3) && (offs[1] == numBands - 2) && (offs[2] == numBands - 1);178boolean littleendian = (offs[0] == numBands - 1) && (offs[1] == numBands - 2) && (offs[2] == numBands - 3);179180if ((pixelSize == 32) && (transferType == DataBuffer.TYPE_INT)) {181if (validsizes && bigendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {182try {183sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB_PRE);184} catch (ClassCastException e) {185sData = null;186}187} else if (validsizes && bigendian && cm.hasAlpha() && sizes[3] == 8) {188try {189sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB);190} catch (ClassCastException e) {191sData = null;192}193} else if (validsizes && littleendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {194try {195sData = createDataIC(bufImg, sType, BufferedImage.TYPE_4BYTE_ABGR_PRE);196} catch (ClassCastException e) {197sData = null;198}199} else if (validsizes && littleendian && cm.hasAlpha() && sizes[3] == 8) {200try {201sData = createDataIC(bufImg, sType, BufferedImage.TYPE_4BYTE_ABGR);202} catch (ClassCastException e) {203sData = null;204}205} else if (validsizes && bigendian) {206try {207sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_RGB);208} catch (ClassCastException e) {209sData = null;210}211}212} else if ((pixelSize == 32) && (transferType == DataBuffer.TYPE_BYTE)) {213if (validsizes && bigendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {214try {215sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_ARGB_PRE);216} catch (ClassCastException e) {217sData = null;218}219}220if (validsizes && bigendian && cm.hasAlpha() && sizes[3] == 8) {221try {222sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_ARGB);223} catch (ClassCastException e) {224sData = null;225}226} else if (validsizes && littleendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {227try {228sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_4BYTE_ABGR_PRE);229} catch (ClassCastException e) {230sData = null;231}232} else if (validsizes && littleendian && cm.hasAlpha() && sizes[3] == 8) {233try {234sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_4BYTE_ABGR);235} catch (ClassCastException e) {236sData = null;237}238} else if (validsizes && littleendian) {239try {240sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_BGR);241} catch (ClassCastException e) {242sData = null;243}244} else if (validsizes && bigendian) {245try {246sData = createDataBC(bufImg, sType, 3, BufferedImage.TYPE_INT_RGB);247} catch (ClassCastException e) {248sData = null;249}250}251} else if ((pixelSize == 24) && (transferType == DataBuffer.TYPE_INT)) {252if (validsizes && bigendian) {253try {254sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_RGB);255} catch (ClassCastException e) {256sData = null;257}258} else if (validsizes && littleendian) {259try {260sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_BGR);261} catch (ClassCastException e) {262sData = null;263}264}265} else if ((pixelSize == 24) && (transferType == DataBuffer.TYPE_BYTE)) {266if (validsizes && bigendian) {267try {268sData = createDataBC(bufImg, sType, 0, TYPE_3BYTE_RGB);269} catch (ClassCastException e) {270sData = null;271}272} else if (validsizes && littleendian) {273try {274sData = createDataBC(bufImg, sType, 0, BufferedImage.TYPE_3BYTE_BGR);275} catch (ClassCastException e) {276sData = null;277}278}279} else if ((pixelSize == 16) && (transferType == DataBuffer.TYPE_USHORT)) {280validsizes = (sizes[0] == 5) && (sizes[1] == 6) && (sizes[2] == 5);281if (validsizes && bigendian) {282try {283sData = createDataSC(bufImg, sType, null, BufferedImage.TYPE_USHORT_565_RGB);284} catch (ClassCastException e) {285sData = null;286}287}288} else if ((pixelSize == 16) && (transferType == DataBuffer.TYPE_BYTE)) {289validsizes = (sizes[0] == 5) && (sizes[1] == 6) && (sizes[2] == 5);290if (validsizes && bigendian) {291try {292sData = createDataBC(bufImg, sType, 1, BufferedImage.TYPE_USHORT_565_RGB);293} catch (ClassCastException e) {294sData = null;295}296}297} else if ((pixelSize == 15) && (transferType == DataBuffer.TYPE_USHORT)) {298validsizes = (sizes[0] == 5) && (sizes[1] == 5) && (sizes[2] == 5);299if (validsizes && bigendian) {300try {301sData = createDataSC(bufImg, sType, null, BufferedImage.TYPE_USHORT_555_RGB);302} catch (ClassCastException e) {303sData = null;304}305}306} else if ((pixelSize == 15) && (transferType == DataBuffer.TYPE_BYTE)) {307validsizes = (sizes[0] == 5) && (sizes[1] == 5) && (sizes[2] == 5);308if (validsizes && bigendian) {309try {310sData = createDataBC(bufImg, sType, 1, BufferedImage.TYPE_USHORT_555_RGB);311} catch (ClassCastException e) {312sData = null;313}314}315}316}317}318break;319}320321// we failed to match322if (sData == null) {323sData = new OSXOffScreenSurfaceData(bufImg, SurfaceType.Custom);324OSXOffScreenSurfaceData offsd = (OSXOffScreenSurfaceData) sData;325326// 2004_03_26 cmc: We used to use createCompatibleImage here. Now that createCompatibleImage returns327// an INT_ARGB_PRE instead of an NIO-based image, we need to explicitly create an NIO-based image.328IntegerNIORaster backupRaster = (IntegerNIORaster) IntegerNIORaster.createNIORaster(bufImg.getWidth(), bufImg.getHeight(), dcmBackup.getMasks(), null);329offsd.bimBackup = new BufferedImage(dcmBackup, backupRaster, dcmBackup.isAlphaPremultiplied(), null);330331// the trick that makes it work - assign the raster from backup to the surface data of the original image332offsd.initCustomRaster(backupRaster.getBuffer(),333backupRaster.getWidth(),334backupRaster.getHeight(),335offsd.fGraphicsStates,336offsd.fGraphicsStatesObject,337offsd.fImageInfo);338339//offsd.checkIfLazyPixelConversionDisabled();340offsd.fImageInfoInt.put(kImageStolenIndex, 1);341}342343return (OSXOffScreenSurfaceData) sData;344}345346private static SurfaceData createDataIC(BufferedImage bImg, SurfaceType sType, int iType) {347OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);348349IntegerComponentRaster icRaster = (IntegerComponentRaster) bImg.getRaster();350offsd.initRaster(icRaster.getDataStorage(),351icRaster.getDataOffset(0) * 4,352icRaster.getWidth(),353icRaster.getHeight(),354icRaster.getPixelStride() * 4,355icRaster.getScanlineStride() * 4,356null,357iType,358offsd.fGraphicsStates,359offsd.fGraphicsStatesObject,360offsd.fImageInfo);361362// offsd.checkIfLazyPixelConversionDisabled();363offsd.fImageInfoInt.put(kImageStolenIndex, 1);364return offsd;365}366367public static SurfaceData createDataIC(BufferedImage bImg, SurfaceType sType) {368return createDataIC(bImg, sType, bImg.getType());369}370371private static SurfaceData createDataSC(BufferedImage bImg, SurfaceType sType, IndexColorModel icm, int iType) {372OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);373374ShortComponentRaster scRaster = (ShortComponentRaster) bImg.getRaster();375offsd.initRaster(scRaster.getDataStorage(),376scRaster.getDataOffset(0) * 2,377scRaster.getWidth(),378scRaster.getHeight(),379scRaster.getPixelStride() * 2,380scRaster.getScanlineStride() * 2,381icm,382iType,383offsd.fGraphicsStates,384offsd.fGraphicsStatesObject,385offsd.fImageInfo);386387//offsd.checkIfLazyPixelConversionDisabled();388offsd.fImageInfoInt.put(kImageStolenIndex, 1);389return offsd;390}391392public static SurfaceData createDataSC(BufferedImage bImg, SurfaceType sType, IndexColorModel icm) {393return createDataSC(bImg, sType, icm, bImg.getType());394}395396private static SurfaceData createDataBC(BufferedImage bImg, SurfaceType sType, int primaryBank, int iType) {397OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);398399ByteComponentRaster bcRaster = (ByteComponentRaster) bImg.getRaster();400ColorModel cm = bImg.getColorModel();401IndexColorModel icm = ((cm instanceof IndexColorModel) ? (IndexColorModel) cm : null);402offsd.initRaster(bcRaster.getDataStorage(),403bcRaster.getDataOffset(primaryBank),404bcRaster.getWidth(),405bcRaster.getHeight(),406bcRaster.getPixelStride(),407bcRaster.getScanlineStride(),408icm,409iType,410offsd.fGraphicsStates,411offsd.fGraphicsStatesObject,412offsd.fImageInfo);413414offsd.fImageInfoInt.put(kImageStolenIndex, 1);415416return offsd;417}418419public static SurfaceData createDataBC(BufferedImage bImg, SurfaceType sType, int primaryBank) {420return createDataBC(bImg, sType, primaryBank, bImg.getType());421}422423private static SurfaceData createDataBP(BufferedImage bImg, SurfaceType sType, int iType) {424OSXOffScreenSurfaceData offsd = new OSXOffScreenSurfaceData(bImg, sType);425426BytePackedRaster bpRaster = (BytePackedRaster) bImg.getRaster();427ColorModel cm = bImg.getColorModel();428IndexColorModel icm = ((cm instanceof IndexColorModel) ? (IndexColorModel) cm : null);429offsd.initRaster(bpRaster.getDataStorage(),430bpRaster.getDataBitOffset(), // in bits, NOT bytes! (needs special attention in native431// code!)432bpRaster.getWidth(),433bpRaster.getHeight(),434bpRaster.getPixelBitStride(),435bpRaster.getScanlineStride() * 8,436icm,437iType,438offsd.fGraphicsStates,439offsd.fGraphicsStatesObject,440offsd.fImageInfo);441442//offsd.checkIfLazyPixelConversionDisabled();443offsd.fImageInfoInt.put(kImageStolenIndex, 1);444return offsd;445}446447protected native void initRaster(Object theArray, int offset, int width, int height, int pixStr, int scanStr, IndexColorModel icm, int type, ByteBuffer graphicsStates, Object graphicsStatesObjects, ByteBuffer imageInfo);448449protected native void initCustomRaster(IntBuffer buffer, int width, int height, ByteBuffer graphicsStates, Object graphicsStatesObjects, ByteBuffer imageInfo);450451public Object getLockObject() {452return this.lock;453}454455// Makes the constructor package private instead of public.456OSXOffScreenSurfaceData(BufferedImage bufImg, SurfaceType sType) {457super(sType, bufImg.getColorModel());458setBounds(0, 0, bufImg.getWidth(), bufImg.getHeight());459460this.bim = bufImg;461462this.fImageInfo = ByteBuffer.allocateDirect(4 * kSizeOfParameters);463this.fImageInfo.order(ByteOrder.nativeOrder());464this.fImageInfoInt = this.fImageInfo.asIntBuffer();465466this.fImageInfoInt.put(kNeedToSyncFromJavaPixelsIndex, 1); // need to sync from Java the very first time467this.fImageInfoInt.put(kNativePixelsChangedIndex, 0);468this.fImageInfoInt.put(kImageStolenIndex, 0);469470this.lock = new Object();471}472473/**474* Performs a copyArea within this surface.475*/476public boolean copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy) {477// <rdar://problem/4488745> For the Sun2D renderer we should rely on the implementation of the super class.478// BufImageSurfaceData.java doesn't have an implementation of copyArea() and relies on the super class.479480int offsetX = 0;481int offsetY = 0;482if (sg2d.transformState == SunGraphics2D.TRANSFORM_ANY_TRANSLATE ||483sg2d.transformState == SunGraphics2D.TRANSFORM_INT_TRANSLATE) {484offsetX = (int) sg2d.transform.getTranslateX();485offsetY = (int) sg2d.transform.getTranslateY();486} else if (sg2d.transformState != SunGraphics2D.TRANSFORM_ISIDENT) { return false; }487488// reset the clip (this is how it works on windows)489// we actually can handle a case with any clips but windows ignores the light clip490Shape clip = sg2d.getClip();491sg2d.setClip(getBounds());492493// clip copyArea494Rectangle clippedCopyAreaRect = clipCopyArea(sg2d, x, y, w, h, dx, dy);495if (clippedCopyAreaRect == null) {496// clipped out497return true;498}499500// the rectangle returned from clipCopyArea() is in the coordinate space of the surface (image)501// we need to substract the offsetX and offsetY to move it to the coordinate space of the graphics2d.502// sg2d.drawImage expects the destination rect to be in the coord space of the graphics2d. <rdar://3746194>503// (vm)504x = clippedCopyAreaRect.x - offsetX;505y = clippedCopyAreaRect.y - offsetY;506w = clippedCopyAreaRect.width;507h = clippedCopyAreaRect.height;508509// copy (dst coordinates are in the coord space of the graphics2d, and src coordinates are510// in the coordinate space of the image)511sg2d.drawImage(this.bim, x + dx, y + dy, x + dx + w, y + dy + h, x + offsetX, y + offsetY, x + w + offsetX, y + h + offsetY, null);512513// restore the clip514sg2d.setClip(clip);515516return true;517}518519/**520* Performs a copyarea from this surface to a buffered image. If null is passed in for the image a new image will be521* created.522*523* Only used by compositor code (private API)524*/525public BufferedImage copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, BufferedImage dstImage) {526// create the destination image if needed527if (dstImage == null) {528dstImage = getDeviceConfiguration().createCompatibleImage(w, h);529}530531// copy532Graphics g = dstImage.createGraphics();533g.drawImage(this.bim, 0, 0, w, h, x, y, x + w, y + h, null);534g.dispose();535536return dstImage;537}538539public boolean xorSurfacePixels(SunGraphics2D sg2d, BufferedImage srcPixels, int x, int y, int w, int h, int colorXOR) {540541int type = this.bim.getType();542543if ((type == BufferedImage.TYPE_INT_ARGB_PRE) || (type == BufferedImage.TYPE_INT_ARGB) || (type == BufferedImage.TYPE_INT_RGB)) { return xorSurfacePixels(createData(srcPixels), colorXOR, x, y, w, h); }544545return false;546}547548native boolean xorSurfacePixels(SurfaceData src, int colorXOR, int x, int y, int w, int h);549550public void clearRect(BufferedImage bim, int w, int h) {551OSXOffScreenSurfaceData offsd = (OSXOffScreenSurfaceData) (OSXOffScreenSurfaceData.createData(bim));552// offsd.clear();553if (offsd.clearSurfacePixels(w, h) == false) {554Graphics2D g = bim.createGraphics();555g.setComposite(AlphaComposite.Clear);556g.fillRect(0, 0, w, h);557g.dispose();558}559}560561native boolean clearSurfacePixels(int w, int h);562563// 04/06/04 cmc: radr://3612381 Graphics.drawImage ignores bgcolor parameter.564// getCopyWithBgColor returns a new version of an image, drawn with a background565// color. Called by blitImage in OSXSurfaceData.java.566BufferedImage copyWithBgColor_cache = null;567568public SurfaceData getCopyWithBgColor(Color bgColor) {569int bimW = this.bim.getWidth();570int bimH = this.bim.getHeight();571572if ((this.copyWithBgColor_cache == null)573|| (this.copyWithBgColor_cache.getWidth() < bimW) || (this.copyWithBgColor_cache.getHeight() < bimH)) {574GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();575this.copyWithBgColor_cache = gc.createCompatibleImage(bimW, bimH);576}577578Graphics g2 = this.copyWithBgColor_cache.createGraphics();579g2.setColor(bgColor);580g2.fillRect(0, 0, bimW, bimH);581g2.drawImage(this.bim, 0, 0, bimW, bimH, null);582g2.dispose();583584return getSurfaceData(this.copyWithBgColor_cache);585}586587/**588* Invoked before the raster's contents are to be read (via one of the modifier methods in Raster such as589* getPixel())590*/591public void rasterRead() {592if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {593syncToJavaPixels();594}595}596597/**598* Invoked before the raster's contents are to be written to (via one of the modifier methods in Raster such as599* setPixel())600*/601public void rasterWrite() {602if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {603syncToJavaPixels();604}605606fImageInfoInt.put(kNeedToSyncFromJavaPixelsIndex, 1); // the pixels will change607}608609private void syncFromCustom() {610611}612613private void syncToCustom() {614615}616// /**617// * Invoked when the raster's contents will be taken (via the Raster.getDataBuffer() method)618// */619// public void rasterStolen() {620// fImageInfoInt.put(kImageStolenIndex, 1); // this means we must convert between Java and native pixels every621// // single primitive! (very expensive)622// if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {623// syncToJavaPixels();624// }625//626// // we know the pixels have been stolen, no need to listen for changes any more627//// if (this.bufImgSunRaster != null) {628//// this.bufImgSunRaster.setRasterListener(null);629//// }630// }631632private native void syncToJavaPixels();633634// we need to refer to rasters often, so cache them635void cacheRasters(BufferedImage bim) {636this.bufImgRaster = bim.getRaster();637if (this.bufImgRaster instanceof SunWritableRaster) {638this.bufImgSunRaster = (SunWritableRaster) this.bufImgRaster;639}640}641642// void setRasterListener() {643// if (this.bufImgSunRaster != null) {644// this.bufImgSunRaster.setRasterListener(this);645//646// Raster parentRaster = this.bufImgSunRaster.getParent();647// if (parentRaster != null) {648// if (parentRaster instanceof SunWritableRaster) {649// // mark subimages stolen to turn off lazy pixel conversion (gznote: can we do better here?)650// ((SunWritableRaster) parentRaster).notifyStolen();651// }652// rasterStolen();653// }654// } else {655// // it's a custom image (non-natively supported) and we can not set a raster listener656// // so mark the image as stolen - this will turn off LazyPixelConversion optimization (slow, but correct)657// rasterStolen();658// }659// }660}661662663