Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
Automatic merge of client:master into master
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Apr 27, 2020
2 parents e544463 + 14b7dd4 commit 9d847b5
Show file tree
Hide file tree
Showing 33 changed files with 644 additions and 264 deletions.
Expand Up @@ -107,6 +107,7 @@
import sun.awt.PlatformGraphicsInfo;
import sun.awt.SunToolkit;
import sun.awt.datatransfer.DataTransferer;
import sun.awt.dnd.SunDragSourceContextPeer;
import sun.awt.util.ThreadGroupUtils;
import sun.java2d.macos.MacOSFlags;
import sun.java2d.metal.MTLRenderQueue;
Expand Down Expand Up @@ -465,6 +466,13 @@ protected void initializeDesktopProperties() {

@Override
protected boolean syncNativeQueue(long timeout) {
if (SunDragSourceContextPeer.isDragDropInProgress()
|| EventQueue.isDispatchThread()) {
// The java code started the DnD, but the native drag may still not
// start, the last attempt to flush the native events,
// also do not block EDT for a long time
timeout = 50;
}
return nativeSyncQueue(timeout);
}

Expand Down
11 changes: 7 additions & 4 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m
Expand Up @@ -37,6 +37,7 @@
#import "CDragSource.h"
#import "DnDUtilities.h"
#import "ThreadUtilities.h"
#import "LWCToolkit.h"


// When sIsJavaDragging is true Java drag gesture has been recognized and a drag is/has been initialized.
Expand Down Expand Up @@ -511,9 +512,9 @@ - (void)doDrag
fDragKeyModifiers = [DnDUtilities extractJavaExtKeyModifiersFromJavaExtModifiers:fModifiers];
fDragMouseModifiers = [DnDUtilities extractJavaExtMouseModifiersFromJavaExtModifiers:fModifiers];

sNeedsEnter = YES;

@try {
sNeedsEnter = YES;
AWTToolkit.inDoDragDropLoop = YES;
// Data dragging:
if (isFileDrag == FALSE) {
[view dragImage:dragImage at:dragOrigin offset:dragOffset event:dragEvent pasteboard:pb source:view slideBack:YES];
Expand Down Expand Up @@ -561,6 +562,7 @@ - (void)doDrag
JNFCallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable
} @finally {
sNeedsEnter = NO;
AWTToolkit.inDoDragDropLoop = NO;
}

// We have to do this, otherwise AppKit doesn't know we're finished dragging. Yup, it's that bad.
Expand Down Expand Up @@ -607,15 +609,15 @@ - (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination {

- (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint {
DLog4(@"[CDragSource draggedImage beganAt]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);

[AWTToolkit eventCountPlusPlus];
// Initialize static variables:
sDragOperation = NSDragOperationNone;
sDraggingLocation = screenPoint;
}

- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation {
DLog4(@"[CDragSource draggedImage endedAt:]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);

[AWTToolkit eventCountPlusPlus];
sDraggingLocation = screenPoint;
sDragOperation = operation;
}
Expand All @@ -625,6 +627,7 @@ - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint {
JNIEnv* env = [ThreadUtilities getJNIEnv];

JNF_COCOA_ENTER(env);
[AWTToolkit eventCountPlusPlus];
// There are two things we would be interested in:
// a) mouse pointer has moved
// b) drag actions (key modifiers) have changed
Expand Down
2 changes: 2 additions & 0 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.h
Expand Up @@ -39,6 +39,8 @@ extern int gNumberOfButtons;
extern jint* gButtonDownMasks;

@interface AWTToolkit : NSObject { }
+ (BOOL) inDoDragDropLoop;
+ (void) setInDoDragDropLoop:(BOOL)val;
+ (long) getEventCount;
+ (void) eventCountPlusPlus;
+ (jint) scrollStateWithEvent: (NSEvent*) event;
Expand Down
33 changes: 28 additions & 5 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -70,13 +70,30 @@
@implementation AWTToolkit

static long eventCount;
static BOOL inDoDragDropLoop;

+ (BOOL) inDoDragDropLoop {
@synchronized(self) {
return inDoDragDropLoop;
}
}

+ (void) setInDoDragDropLoop:(BOOL)val {
@synchronized(self) {
inDoDragDropLoop = val;
}
}

+ (long) getEventCount{
@synchronized(self) {
return eventCount;
}
}

+ (void) eventCountPlusPlus{
@synchronized(self) {
eventCount++;
}
}

+ (jint) scrollStateWithEvent: (NSEvent*) event {
Expand Down Expand Up @@ -420,10 +437,16 @@ + (void)starter:(BOOL)wasOnMainThread headless:(BOOL)headless {
// immediately after this we will post the second event via
// [NSApp postEvent] then sometimes the second event will be handled
// first. The opposite isn't proved, but we use both here to be safer.
[theApp postDummyEvent:false];
[theApp waitForDummyEvent:timeout / 2.0];
[theApp postDummyEvent:true];
[theApp waitForDummyEvent:timeout / 2.0];

// If the native drag is in progress, skip native sync.
if (!AWTToolkit.inDoDragDropLoop) {
[theApp postDummyEvent:false];
[theApp waitForDummyEvent:timeout / 2.0];
}
if (!AWTToolkit.inDoDragDropLoop) {
[theApp postDummyEvent:true];
[theApp waitForDummyEvent:timeout / 2.0];
}

} else {
// could happen if we are embedded inside SWT application,
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -350,9 +350,9 @@ public final String getVersion() {
}

/**
* Provides a string representation of the device information.
* Returns a string representation of the info object.
*
* @return a description of the info object
* @return a string representation of the info object
*/
@Override
public final String toString() {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -720,14 +720,13 @@ public final int hashCode() {
}

/**
* Provides this synchronization mode's name as the string
* representation of the mode.
* Returns mode's name as the string representation of the
* synchronization mode.
*
* @return the name of this synchronization mode
* @return a string representation of the synchronization mode
*/
@Override
public final String toString() {

return name;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -262,33 +262,25 @@ public Object getProperty(String key) {
}

/**
* Provides a string representation of the file format.
* Returns a string representation of the audio file format.
*
* @return the file format as a string
* @return a string representation of the audio file format
*/
@Override
public String toString() {

StringBuffer buf = new StringBuffer();

String str = "Unknown file format";
//$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException
if (type != null) {
buf.append(type.toString() + " (." + type.getExtension() + ") file");
} else {
buf.append("unknown file format");
if (getType() != null) {
str = getType() + " (." + getType().getExtension() + ") file";
}

if (byteLength != AudioSystem.NOT_SPECIFIED) {
buf.append(", byte length: " + byteLength);
if (getByteLength() != AudioSystem.NOT_SPECIFIED) {
str += ", byte length: " + getByteLength();
}

buf.append(", data format: " + format);

if (frameLength != AudioSystem.NOT_SPECIFIED) {
buf.append(", frame length: " + frameLength);
str += ", data format: " + getFormat();
if (getFrameLength() != AudioSystem.NOT_SPECIFIED) {
str += ", frame length: " + getFrameLength();
}

return new String(buf);
return str;
}

/**
Expand Down Expand Up @@ -376,10 +368,9 @@ public final int hashCode() {
}

/**
* Provides the file type's name as the {@code String} representation of
* the file type.
* Returns type's name as the string representation of the file type.
*
* @return the file type's name
* @return a string representation of the file type
*/
@Override
public final String toString() {
Expand Down
91 changes: 27 additions & 64 deletions src/java.desktop/share/classes/javax/sound/sampled/AudioFormat.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -448,83 +448,47 @@ public boolean matches(AudioFormat format) {
}

/**
* Returns a string that describes the format, such as: "PCM SIGNED 22050 Hz
* 16 bit mono big-endian". The contents of the string may vary between
* implementations of Java Sound.
* Returns a string that describes the audio format, such as: "PCM SIGNED
* 22050 Hz 16 bit mono big-endian". The contents of the string may vary
* between implementations of Java Sound.
*
* @return a string that describes the format parameters
* @return a string representation of the audio format
*/
@Override
public String toString() {
String sEncoding = "";
if (getEncoding() != null) {
sEncoding = getEncoding().toString() + " ";
}

String sSampleRate;
if (getSampleRate() == (float) AudioSystem.NOT_SPECIFIED) {
sSampleRate = "unknown sample rate, ";
} else {
sSampleRate = "" + getSampleRate() + " Hz, ";
}
String sampleRate = getSampleRate() == AudioSystem.NOT_SPECIFIED ?
"unknown sample rate" : getSampleRate() + " Hz";

String sSampleSizeInBits;
if (getSampleSizeInBits() == (float) AudioSystem.NOT_SPECIFIED) {
sSampleSizeInBits = "unknown bits per sample, ";
} else {
sSampleSizeInBits = "" + getSampleSizeInBits() + " bit, ";
}
String sampleSize = getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED ?
"unknown bits per sample" : getSampleSizeInBits() + " bit";

String sChannels;
if (getChannels() == 1) {
sChannels = "mono, ";
} else
if (getChannels() == 2) {
sChannels = "stereo, ";
} else {
if (getChannels() == AudioSystem.NOT_SPECIFIED) {
sChannels = " unknown number of channels, ";
} else {
sChannels = ""+getChannels()+" channels, ";
}
}
String channels = switch (getChannels()) {
case 1 -> "mono";
case 2 -> "stereo";
case AudioSystem.NOT_SPECIFIED -> "unknown number of channels";
default -> getChannels() + " channels";
};

String sFrameSize;
if (getFrameSize() == (float) AudioSystem.NOT_SPECIFIED) {
sFrameSize = "unknown frame size, ";
} else {
sFrameSize = "" + getFrameSize()+ " bytes/frame, ";
}
String frameSize = getFrameSize() == AudioSystem.NOT_SPECIFIED ?
"unknown frame size" : getFrameSize() + " bytes/frame";

String sFrameRate = "";
String frameRate = "";
if (Math.abs(getSampleRate() - getFrameRate()) > 0.00001) {
if (getFrameRate() == (float) AudioSystem.NOT_SPECIFIED) {
sFrameRate = "unknown frame rate, ";
} else {
sFrameRate = getFrameRate() + " frames/second, ";
}
frameRate = getFrameRate() == AudioSystem.NOT_SPECIFIED ?
", unknown frame rate":", " + getFrameRate() + " frames/second";
}

String sEndian = "";
String bigEndian = "";
if ((getEncoding().equals(Encoding.PCM_SIGNED)
|| getEncoding().equals(Encoding.PCM_UNSIGNED))
&& ((getSampleSizeInBits() > 8)
|| (getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED))) {
if (isBigEndian()) {
sEndian = "big-endian";
} else {
sEndian = "little-endian";
}
bigEndian = isBigEndian() ? ", big-endian" : ", little-endian";
}

return sEncoding
+ sSampleRate
+ sSampleSizeInBits
+ sChannels
+ sFrameSize
+ sFrameRate
+ sEndian;

return String.format("%s %s, %s, %s, %s%s%s", getEncoding(),
sampleRate, sampleSize, channels, frameSize,
frameRate, bigEndian);
}

/**
Expand Down Expand Up @@ -630,13 +594,12 @@ public final int hashCode() {
}

/**
* Provides the {@code String} representation of the encoding. This
* {@code String} is the same name that was passed to the constructor.
* Returns encoding's name as the string representation of the encoding.
* For the predefined encodings, the name is similar to the encoding's
* variable (field) name. For example, {@code PCM_SIGNED.toString()}
* returns the name "PCM_SIGNED".
*
* @return the encoding name
* @return a string representation of the encoding
*/
@Override
public final String toString() {
Expand Down

0 comments on commit 9d847b5

Please sign in to comment.