Skip to content

Commit ead83e6

Browse files
committed
8239124: Minimize the usage of AwtGraphicsConfigDataPtr in native
Reviewed-by: pbansal
1 parent 5a5e4bb commit ead83e6

4 files changed

Lines changed: 33 additions & 146 deletions

File tree

src/java.desktop/unix/classes/sun/awt/X11/XWindow.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,22 +25,42 @@
2525

2626
package sun.awt.X11;
2727

28-
import java.awt.*;
29-
import java.awt.event.*;
30-
import java.awt.peer.ComponentPeer;
28+
import java.awt.AWTEvent;
29+
import java.awt.AWTKeyStroke;
30+
import java.awt.Color;
31+
import java.awt.Component;
32+
import java.awt.Container;
33+
import java.awt.Cursor;
34+
import java.awt.Font;
35+
import java.awt.FontMetrics;
36+
import java.awt.Graphics;
37+
import java.awt.GraphicsConfiguration;
38+
import java.awt.Point;
39+
import java.awt.Rectangle;
40+
import java.awt.SystemColor;
41+
import java.awt.Toolkit;
42+
import java.awt.Window;
43+
import java.awt.event.ComponentEvent;
44+
import java.awt.event.FocusEvent;
45+
import java.awt.event.InputEvent;
46+
import java.awt.event.KeyEvent;
47+
import java.awt.event.MouseEvent;
48+
import java.awt.event.MouseWheelEvent;
49+
import java.awt.event.PaintEvent;
3150
import java.awt.image.ColorModel;
32-
51+
import java.awt.peer.ComponentPeer;
3352
import java.lang.ref.WeakReference;
3453

54+
import sun.awt.AWTAccessor;
3555
import sun.awt.AWTAccessor.ComponentAccessor;
36-
import sun.util.logging.PlatformLogger;
37-
38-
import sun.awt.*;
39-
40-
import sun.awt.image.PixelConverter;
41-
56+
import sun.awt.PaintEventDispatcher;
57+
import sun.awt.PeerEvent;
58+
import sun.awt.SunToolkit;
59+
import sun.awt.X11ComponentPeer;
60+
import sun.awt.X11GraphicsConfig;
4261
import sun.java2d.SunGraphics2D;
4362
import sun.java2d.SurfaceData;
63+
import sun.util.logging.PlatformLogger;
4464

4565
class XWindow extends XBaseWindow implements X11ComponentPeer {
4666
private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindow");
@@ -117,10 +137,6 @@ static synchronized Font getDefaultFont() {
117137
*/
118138
private int mouseButtonClickAllowed = 0;
119139

120-
native int getNativeColor(Color clr, GraphicsConfiguration gc);
121-
native void getWMInsets(long window, long left, long top, long right, long bottom, long border);
122-
native long getTopWindow(long window, long rootWin);
123-
native void getWindowBounds(long window, long x, long y, long width, long height);
124140
private static native void initIDs();
125141

126142
static {

src/java.desktop/unix/native/common/awt/X11Color.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1263,43 +1263,6 @@ jobject awtJNI_GetColorModel(JNIEnv *env, AwtGraphicsConfigDataPtr aData)
12631263
extern jfieldID colorValueID;
12641264

12651265
#ifndef HEADLESS
1266-
int awtJNI_GetColorForVis (JNIEnv *env,jobject this, AwtGraphicsConfigDataPtr awt_data)
1267-
{
1268-
int col;
1269-
jclass SYSCLR_class;
1270-
1271-
if (!JNU_IsNull(env,this))
1272-
{
1273-
SYSCLR_class = (*env)->FindClass(env, "java/awt/SystemColor");
1274-
CHECK_NULL_RETURN(SYSCLR_class, 0);
1275-
1276-
if ((*env)->IsInstanceOf(env, this, SYSCLR_class)) {
1277-
/* SECURITY: This is safe, because there is no way
1278-
* for client code to insert an object
1279-
* that is a subclass of SystemColor
1280-
*/
1281-
col = (int) JNU_CallMethodByName(env
1282-
,NULL
1283-
,this
1284-
,"getRGB"
1285-
,"()I").i;
1286-
JNU_CHECK_EXCEPTION_RETURN(env, 0);
1287-
} else {
1288-
col = (int)(*env)->GetIntField(env,this,colorValueID);
1289-
}
1290-
1291-
if (awt_data->awt_cmap == (Colormap) NULL) {
1292-
awtJNI_CreateColorData (env, awt_data, 1);
1293-
}
1294-
1295-
col = awt_data->AwtColorMatch(red(col), green(col), blue(col),
1296-
awt_data);
1297-
return col;
1298-
}
1299-
1300-
return 0;
1301-
}
1302-
13031266
void
13041267
awt_allocate_systemrgbcolors (jint *rgbColors, int num_colors,
13051268
AwtGraphicsConfigDataPtr awtData) {

src/java.desktop/unix/native/common/awt/awt_p.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ extern AwtGraphicsConfigDataPtr getDefaultConfig(int screen);
104104
extern int awt_allocate_colors(AwtGraphicsConfigDataPtr);
105105
extern void awt_allocate_systemrgbcolors(jint *, int, AwtGraphicsConfigDataPtr);
106106

107-
extern int awtJNI_GetColorForVis (JNIEnv *, jobject, AwtGraphicsConfigDataPtr);
108107
extern jobject awtJNI_GetColorModel(JNIEnv *, AwtGraphicsConfigDataPtr);
109108
extern void awtJNI_CreateColorData (JNIEnv *, AwtGraphicsConfigDataPtr, int lock);
110109

src/java.desktop/unix/native/libawt_xawt/xawt/XWindow.c

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1124,19 +1124,6 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XWindow_x11inputMethodLookupString
11241124

11251125
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
11261126

1127-
/*
1128-
* Class: Java_sun_awt_X11_XWindow_getNativeColor
1129-
* Method: getNativeColor
1130-
* Signature (Ljava/awt/Color;Ljava/awt/GraphicsConfiguration;)I
1131-
*/
1132-
JNIEXPORT jint JNICALL Java_sun_awt_X11_XWindow_getNativeColor
1133-
(JNIEnv *env, jobject this, jobject color, jobject gc_object) {
1134-
AwtGraphicsConfigDataPtr adata;
1135-
/* fire warning because JNU_GetLongFieldAsPtr casts jlong to (void *) */
1136-
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, gc_object, x11GraphicsConfigIDs.aData);
1137-
return awtJNI_GetColorForVis(env, color, adata);
1138-
}
1139-
11401127
/* syncTopLevelPos() is necessary to insure that the window manager has in
11411128
* fact moved us to our final position relative to the reParented WM window.
11421129
* We have noted a timing window which our shell has not been moved so we
@@ -1164,84 +1151,6 @@ void syncTopLevelPos( Display *d, Window w, XWindowAttributes *winAttr ) {
11641151
} while (i++ < 50);
11651152
}
11661153

1167-
static Window getTopWindow(Window win, Window *rootWin)
1168-
{
1169-
Window root=None, current_window=win, parent=None, *ignore_children=NULL;
1170-
Window prev_window=None;
1171-
unsigned int ignore_uint=0;
1172-
Status status = 0;
1173-
1174-
if (win == None) return None;
1175-
do {
1176-
status = XQueryTree(awt_display,
1177-
current_window,
1178-
&root,
1179-
&parent,
1180-
&ignore_children,
1181-
&ignore_uint);
1182-
XFree(ignore_children);
1183-
if (status == 0) return None;
1184-
prev_window = current_window;
1185-
current_window = parent;
1186-
} while (parent != root);
1187-
*rootWin = root;
1188-
return prev_window;
1189-
}
1190-
1191-
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XWindow_getTopWindow
1192-
(JNIEnv *env, jclass clazz, jlong win, jlong rootWin) {
1193-
return getTopWindow((Window) win, (Window*) jlong_to_ptr(rootWin));
1194-
}
1195-
1196-
static void
1197-
getWMInsets
1198-
(Window window, int *left, int *top, int *right, int *bottom, int *border) {
1199-
// window is event->xreparent.window
1200-
Window topWin = None, rootWin = None, containerWindow = None;
1201-
XWindowAttributes winAttr, topAttr;
1202-
int screenX, screenY;
1203-
topWin = getTopWindow(window, &rootWin);
1204-
syncTopLevelPos(awt_display, topWin, &topAttr);
1205-
// (screenX, screenY) is (0,0) of the reparented window
1206-
// converted to screen coordinates.
1207-
XTranslateCoordinates(awt_display, window, rootWin,
1208-
0,0, &screenX, &screenY, &containerWindow);
1209-
*left = screenX - topAttr.x - topAttr.border_width;
1210-
*top = screenY - topAttr.y - topAttr.border_width;
1211-
XGetWindowAttributes(awt_display, window, &winAttr);
1212-
*right = topAttr.width - ((winAttr.width) + *left);
1213-
*bottom = topAttr.height - ((winAttr.height) + *top);
1214-
*border = topAttr.border_width;
1215-
}
1216-
1217-
JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWMInsets
1218-
(JNIEnv *env, jclass clazz, jlong window, jlong left, jlong top, jlong right, jlong bottom, jlong border) {
1219-
getWMInsets((Window) window,
1220-
(int*) jlong_to_ptr(left),
1221-
(int*) jlong_to_ptr(top),
1222-
(int*) jlong_to_ptr(right),
1223-
(int*) jlong_to_ptr(bottom),
1224-
(int*) jlong_to_ptr(border));
1225-
}
1226-
1227-
static void
1228-
getWindowBounds
1229-
(Window window, int *x, int *y, int *width, int *height) {
1230-
XWindowAttributes winAttr;
1231-
XSync(awt_display, False);
1232-
XGetWindowAttributes(awt_display, window, &winAttr);
1233-
*x = winAttr.x;
1234-
*y = winAttr.y;
1235-
*width = winAttr.width;
1236-
*height = winAttr.height;
1237-
}
1238-
1239-
JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWindowBounds
1240-
(JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) {
1241-
getWindowBounds((Window) window, (int*) jlong_to_ptr(x), (int*) jlong_to_ptr(y),
1242-
(int*) jlong_to_ptr(width), (int*) jlong_to_ptr(height));
1243-
}
1244-
12451154
JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_setSizeHints
12461155
(JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) {
12471156
XSizeHints *size_hints = XAllocSizeHints();

0 commit comments

Comments
 (0)