提交 d854411c 编写于 作者: B bae

7146550: [macosx] DnD test failure in createCompatibleWritableRaster()

Reviewed-by: kizune, serb
上级 cd7322ee
...@@ -132,44 +132,31 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer { ...@@ -132,44 +132,31 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
this.setDefaultDragImage(component); this.setDefaultDragImage(component);
// Get drag image (if any) as BufferedImage and convert that to CImage: // Get drag image (if any) as BufferedImage and convert that to CImage:
long dragImage;
Point dragImageOffset; Point dragImageOffset;
if (fDragImage != null) { if (fDragImage != null) {
BufferedImage bi = (fDragImage instanceof BufferedImage ? (BufferedImage) fDragImage : null); try {
fDragCImage = CImage.getCreator().createFromImageImmediately(fDragImage);
if (bi == null) { } catch(Exception e) {
// Create a new buffered image: // image creation may fail for any reason
int width = fDragImage.getWidth(null); throw new InvalidDnDOperationException("Drag image can not be created.");
int height = fDragImage.getHeight(null);
bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
// Draw drag image into the buffered image:
Graphics g = bi.getGraphics();
g.drawImage(fDragImage, 0, 0, null);
g.dispose();
} }
/* TODO:BG if (fDragCImage == null) {
fDragCImage = CImage.getCreator().createImage(bi); throw new InvalidDnDOperationException("Drag image is not ready.");
dragImage = fDragCImage.getNSImage(); */ }
fDragCImage = null;
dragImage = 0L;
dragImageOffset = fDragImageOffset; dragImageOffset = fDragImageOffset;
} else { } else {
fDragCImage = null; fDragCImage = null;
dragImage = 0L;
dragImageOffset = new Point(0, 0); dragImageOffset = new Point(0, 0);
} }
// Get NS drag image instance if we have a drag image:
long nsDragImage = 0L; //TODO:BG (fDragCImage != null ? fDragCImage.getNSImage() : 0L);
try { try {
// Create native dragging source: // Create native dragging source:
final long nativeDragSource = createNativeDragSource(component, peer, nativeWindowPtr, transferable, triggerEvent, final long nativeDragSource = createNativeDragSource(component, peer, nativeWindowPtr, transferable, triggerEvent,
(int) (dragOrigin.getX() + componentOffset.x), (int) (dragOrigin.getY() + componentOffset.y), extModifiers, (int) (dragOrigin.getX() + componentOffset.x), (int) (dragOrigin.getY() + componentOffset.y), extModifiers,
clickCount, timestamp, cursor, dragImage, dragImageOffset.x, dragImageOffset.y, clickCount, timestamp, cursor, fDragCImage, dragImageOffset.x, dragImageOffset.y,
getDragSourceContext().getSourceActions(), formats, formatMap); getDragSourceContext().getSourceActions(), formats, formatMap);
if (nativeDragSource == 0) if (nativeDragSource == 0)
...@@ -495,7 +482,7 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer { ...@@ -495,7 +482,7 @@ public final class CDragSourceContextPeer extends SunDragSourceContextPeer {
// Native support: // Native support:
private native long createNativeDragSource(Component component, ComponentPeer peer, long nativePeer, Transferable transferable, private native long createNativeDragSource(Component component, ComponentPeer peer, long nativePeer, Transferable transferable,
InputEvent triggerEvent, int dragPosX, int dragPosY, int extModifiers, int clickCount, long timestamp, InputEvent triggerEvent, int dragPosX, int dragPosY, int extModifiers, int clickCount, long timestamp,
Cursor cursor, long nsDragImage, int dragImageOffsetX, int dragImageOffsetY, Cursor cursor, CImage nsDragImage, int dragImageOffsetX, int dragImageOffsetY,
int sourceActions, long[] formats, Map formatMap); int sourceActions, long[] formats, Map formatMap);
private native void doDragging(long nativeDragSource); private native void doDragging(long nativeDragSource);
......
...@@ -97,35 +97,55 @@ public class CImage extends CFRetainedResource { ...@@ -97,35 +97,55 @@ public class CImage extends CFRetainedResource {
return createImageUsingNativeSize(nativeCreateNSImageFromImageName(name)); return createImageUsingNativeSize(nativeCreateNSImageFromImageName(name));
} }
private static int[] imageToArray(Image image) { private static int[] imageToArray(Image image, boolean prepareImage) {
if (image == null) return null; if (image == null) return null;
MediaTracker mt = new MediaTracker(new Label()); if (prepareImage && !(image instanceof BufferedImage)) {
final int id = 0; final MediaTracker mt = new MediaTracker(new Label());
mt.addImage(image, id); final int id = 0;
mt.addImage(image, id);
try { try {
mt.waitForID(id); mt.waitForID(id);
} catch (InterruptedException e) { } catch (InterruptedException e) {
} return null;
}
if (mt.isErrorID(id)) { if (mt.isErrorID(id)) {
return null; return null;
}
} }
int w = image.getWidth(null); int w = image.getWidth(null);
int h = image.getHeight(null); int h = image.getHeight(null);
if (w < 0 || h < 0) {
return null;
}
BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
Graphics2D g2 = bimg.createGraphics(); Graphics2D g2 = bimg.createGraphics();
g2.setComposite(AlphaComposite.Src); g2.setComposite(AlphaComposite.Src);
g2.drawImage(image, 0, 0, null); g2.drawImage(image, 0, 0, null);
g2.dispose(); g2.dispose();
return ((DataBufferInt)bimg.getRaster().getDataBuffer()).getData(); return ((DataBufferInt)bimg.getRaster().getDataBuffer()).getData();
} }
public CImage createFromImageImmediately(final Image image) {
int[] buffer = imageToArray(image, false);
if (buffer == null) {
return null;
}
return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null),
image.getHeight(null)));
}
// This is used to create a CImage from a Image // This is used to create a CImage from a Image
public CImage createFromImage(final Image image) { public CImage createFromImage(final Image image) {
int[] buffer = imageToArray(image); int[] buffer = imageToArray(image, true);
if (buffer == null) { if (buffer == null) {
return null; return null;
} }
...@@ -146,7 +166,7 @@ public class CImage extends CFRetainedResource { ...@@ -146,7 +166,7 @@ public class CImage extends CFRetainedResource {
num = 0; num = 0;
for (Image img : images) { for (Image img : images) {
buffers[num] = imageToArray(img); buffers[num] = imageToArray(img, true);
if (buffers[num] == null) { if (buffers[num] == null) {
// Unable to process the image // Unable to process the image
continue; continue;
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
transferable:(jobject)jtransferable triggerEvent:(jobject)jtrigger transferable:(jobject)jtransferable triggerEvent:(jobject)jtrigger
dragPosX:(jint)dragPosX dragPosY:(jint)dragPosY modifiers:(jint)extModifiers clickCount:(jint)clickCount timeStamp:(jlong)timeStamp dragPosX:(jint)dragPosX dragPosY:(jint)dragPosY modifiers:(jint)extModifiers clickCount:(jint)clickCount timeStamp:(jlong)timeStamp
cursor:(jobject)jcursor cursor:(jobject)jcursor
dragImage:(jlong)jnsdragimage dragImageOffsetX:(jint)jdragimageoffsetx dragImageOffsetY:(jint)jdragimageoffsety dragImage:(jobject)jnsdragimage dragImageOffsetX:(jint)jdragimageoffsetx dragImageOffsetY:(jint)jdragimageoffsety
sourceActions:(jint)jsourceactions formats:(jlongArray)jformats formatMap:(jobject)jformatmap; sourceActions:(jint)jsourceactions formats:(jlongArray)jformats formatMap:(jobject)jformatmap;
- (void)removeFromView:(JNIEnv *)env; - (void)removeFromView:(JNIEnv *)env;
......
...@@ -70,6 +70,7 @@ static BOOL sIsJavaDragging; ...@@ -70,6 +70,7 @@ static BOOL sIsJavaDragging;
JNF_CLASS_CACHE(DataTransfererClass, "sun/awt/datatransfer/DataTransferer"); JNF_CLASS_CACHE(DataTransfererClass, "sun/awt/datatransfer/DataTransferer");
JNF_CLASS_CACHE(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer"); JNF_CLASS_CACHE(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer");
JNF_CLASS_CACHE(CImageClass, "sun/lwawt/macosx/CImage");
static NSDragOperation sDragOperation; static NSDragOperation sDragOperation;
static NSPoint sDraggingLocation; static NSPoint sDraggingLocation;
...@@ -87,7 +88,7 @@ static BOOL sNeedsEnter; ...@@ -87,7 +88,7 @@ static BOOL sNeedsEnter;
transferable:(jobject)jtransferable triggerEvent:(jobject)jtrigger transferable:(jobject)jtransferable triggerEvent:(jobject)jtrigger
dragPosX:(jint)dragPosX dragPosY:(jint)dragPosY modifiers:(jint)extModifiers clickCount:(jint)clickCount dragPosX:(jint)dragPosX dragPosY:(jint)dragPosY modifiers:(jint)extModifiers clickCount:(jint)clickCount
timeStamp:(jlong)timeStamp cursor:(jobject)jcursor timeStamp:(jlong)timeStamp cursor:(jobject)jcursor
dragImage:(jlong)jnsdragimage dragImageOffsetX:(jint)jdragimageoffsetx dragImageOffsetY:(jint)jdragimageoffsety dragImage:(jobject)jnsdragimage dragImageOffsetX:(jint)jdragimageoffsetx dragImageOffsetY:(jint)jdragimageoffsety
sourceActions:(jint)jsourceactions formats:(jlongArray)jformats formatMap:(jobject)jformatmap sourceActions:(jint)jsourceactions formats:(jlongArray)jformats formatMap:(jobject)jformatmap
{ {
self = [super init]; self = [super init];
...@@ -107,8 +108,14 @@ static BOOL sNeedsEnter; ...@@ -107,8 +108,14 @@ static BOOL sNeedsEnter;
fTriggerEvent = JNFNewGlobalRef(env, jtrigger); fTriggerEvent = JNFNewGlobalRef(env, jtrigger);
fCursor = JNFNewGlobalRef(env, jcursor); fCursor = JNFNewGlobalRef(env, jcursor);
fDragImage = (NSImage*) jlong_to_ptr(jnsdragimage); // Double-casting prevents compiler 'different size' warning. if (jnsdragimage) {
[fDragImage retain]; JNF_MEMBER_CACHE(nsImagePtr, CImageClass, "ptr", "J");
jlong imgPtr = JNFGetLongField(env, jnsdragimage, nsImagePtr);
fDragImage = (NSImage*) jlong_to_ptr(imgPtr); // Double-casting prevents compiler 'd$|//
[fDragImage retain];
}
fDragImageOffset = NSMakePoint(jdragimageoffsetx, jdragimageoffsety); fDragImageOffset = NSMakePoint(jdragimageoffsetx, jdragimageoffsety);
fSourceActions = jsourceactions; fSourceActions = jsourceactions;
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_createNativeDragSource JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDragSourceContextPeer_createNativeDragSource
(JNIEnv *env, jobject jthis, jobject jcomponent, jobject jpeer, jlong jnativepeer, jobject jtransferable, (JNIEnv *env, jobject jthis, jobject jcomponent, jobject jpeer, jlong jnativepeer, jobject jtransferable,
jobject jtrigger, jint jdragposx, jint jdragposy, jint jextmodifiers, jint jclickcount, jlong jtimestamp, jobject jtrigger, jint jdragposx, jint jdragposy, jint jextmodifiers, jint jclickcount, jlong jtimestamp,
jobject jcursor, jlong jnsdragimage, jint jdragimageoffsetx, jint jdragimageoffsety, jobject jcursor, jobject jnsdragimage, jint jdragimageoffsetx, jint jdragimageoffsety,
jint jsourceactions, jlongArray jformats, jobject jformatmap) jint jsourceactions, jlongArray jformats, jobject jformatmap)
{ {
id controlObj = (id) jlong_to_ptr(jnativepeer); id controlObj = (id) jlong_to_ptr(jnativepeer);
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
/* /*
test %W% %E% test %W% %E%
@bug 4874070 @bug 4874070 7146550
@summary Tests basic DnD functionality @summary Tests basic DnD functionality
@author Your Name: Alexey Utkin area=dnd @author Your Name: Alexey Utkin area=dnd
@run applet ImageDecoratedDnDNegative.html @run applet ImageDecoratedDnDNegative.html
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册