Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/OSXOffScreenSurfaceData.java
41152 views
/*1* Copyright (c) 2011, 2018, 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.479480if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {481return false;482}483484// reset the clip (this is how it works on windows)485// we actually can handle a case with any clips but windows ignores the light clip486Shape clip = sg2d.getClip();487sg2d.setClip(getBounds());488489// clip copyArea490Rectangle clippedCopyAreaRect = clipCopyArea(sg2d, x, y, w, h, dx, dy);491if (clippedCopyAreaRect == null) {492// clipped out493return true;494}495496// the rectangle returned from clipCopyArea() is in the coordinate space497// of the surface (image)498x = clippedCopyAreaRect.x;499y = clippedCopyAreaRect.y;500w = clippedCopyAreaRect.width;501h = clippedCopyAreaRect.height;502503// copy (dst coordinates are in the coord space of the graphics2d, and504// src coordinates are in the coordinate space of the image)505// sg2d.drawImage expects the destination rect to be in the coord space506// of the graphics2d. <rdar://3746194> (vm)507// we need to substract the transX and transY to move it508// to the coordinate space of the graphics2d.509int dstX = x + dx - sg2d.transX;510int dstY = y + dy - sg2d.transY;511sg2d.drawImage(this.bim, dstX, dstY, dstX + w, dstY + h,512x, y, x + w, y + h, null);513514// restore the clip515sg2d.setClip(clip);516517return true;518}519520/**521* Performs a copyarea from this surface to a buffered image. If null is passed in for the image a new image will be522* created.523*524* Only used by compositor code (private API)525*/526public BufferedImage copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, BufferedImage dstImage) {527// create the destination image if needed528if (dstImage == null) {529dstImage = getDeviceConfiguration().createCompatibleImage(w, h);530}531532// copy533Graphics g = dstImage.createGraphics();534g.drawImage(this.bim, 0, 0, w, h, x, y, x + w, y + h, null);535g.dispose();536537return dstImage;538}539540public boolean xorSurfacePixels(SunGraphics2D sg2d, BufferedImage srcPixels, int x, int y, int w, int h, int colorXOR) {541542int type = this.bim.getType();543544if ((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); }545546return false;547}548549native boolean xorSurfacePixels(SurfaceData src, int colorXOR, int x, int y, int w, int h);550551public void clearRect(BufferedImage bim, int w, int h) {552OSXOffScreenSurfaceData offsd = (OSXOffScreenSurfaceData) (OSXOffScreenSurfaceData.createData(bim));553// offsd.clear();554if (offsd.clearSurfacePixels(w, h) == false) {555Graphics2D g = bim.createGraphics();556g.setComposite(AlphaComposite.Clear);557g.fillRect(0, 0, w, h);558g.dispose();559}560}561562native boolean clearSurfacePixels(int w, int h);563564// 04/06/04 cmc: radr://3612381 Graphics.drawImage ignores bgcolor parameter.565// getCopyWithBgColor returns a new version of an image, drawn with a background566// color. Called by blitImage in OSXSurfaceData.java.567BufferedImage copyWithBgColor_cache = null;568569public SurfaceData getCopyWithBgColor(Color bgColor) {570int bimW = this.bim.getWidth();571int bimH = this.bim.getHeight();572573if ((this.copyWithBgColor_cache == null)574|| (this.copyWithBgColor_cache.getWidth() < bimW) || (this.copyWithBgColor_cache.getHeight() < bimH)) {575GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();576this.copyWithBgColor_cache = gc.createCompatibleImage(bimW, bimH);577}578579Graphics g2 = this.copyWithBgColor_cache.createGraphics();580g2.setColor(bgColor);581g2.fillRect(0, 0, bimW, bimH);582g2.drawImage(this.bim, 0, 0, bimW, bimH, null);583g2.dispose();584585return getSurfaceData(this.copyWithBgColor_cache);586}587588/**589* Invoked before the raster's contents are to be read (via one of the modifier methods in Raster such as590* getPixel())591*/592public void rasterRead() {593if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {594syncToJavaPixels();595}596}597598/**599* Invoked before the raster's contents are to be written to (via one of the modifier methods in Raster such as600* setPixel())601*/602public void rasterWrite() {603if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {604syncToJavaPixels();605}606607fImageInfoInt.put(kNeedToSyncFromJavaPixelsIndex, 1); // the pixels will change608}609610private void syncFromCustom() {611612}613614private void syncToCustom() {615616}617// /**618// * Invoked when the raster's contents will be taken (via the Raster.getDataBuffer() method)619// */620// public void rasterStolen() {621// fImageInfoInt.put(kImageStolenIndex, 1); // this means we must convert between Java and native pixels every622// // single primitive! (very expensive)623// if (fImageInfoInt.get(kNativePixelsChangedIndex) == 1) {624// syncToJavaPixels();625// }626//627// // we know the pixels have been stolen, no need to listen for changes any more628//// if (this.bufImgSunRaster != null) {629//// this.bufImgSunRaster.setRasterListener(null);630//// }631// }632633private native void syncToJavaPixels();634635// we need to refer to rasters often, so cache them636void cacheRasters(BufferedImage bim) {637this.bufImgRaster = bim.getRaster();638if (this.bufImgRaster instanceof SunWritableRaster) {639this.bufImgSunRaster = (SunWritableRaster) this.bufImgRaster;640}641}642643// void setRasterListener() {644// if (this.bufImgSunRaster != null) {645// this.bufImgSunRaster.setRasterListener(this);646//647// Raster parentRaster = this.bufImgSunRaster.getParent();648// if (parentRaster != null) {649// if (parentRaster instanceof SunWritableRaster) {650// // mark subimages stolen to turn off lazy pixel conversion (gznote: can we do better here?)651// ((SunWritableRaster) parentRaster).notifyStolen();652// }653// rasterStolen();654// }655// } else {656// // it's a custom image (non-natively supported) and we can not set a raster listener657// // so mark the image as stolen - this will turn off LazyPixelConversion optimization (slow, but correct)658// rasterStolen();659// }660// }661}662663664