8239124: Minimize the usage of AwtGraphicsConfigDataPtr in native
Reviewed-by: pbansal
This commit is contained in:
parent
5a5e4bbfee
commit
ead83e6b63
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 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
|
||||
@ -25,22 +25,42 @@
|
||||
|
||||
package sun.awt.X11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.AWTKeyStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
import sun.awt.AWTAccessor.ComponentAccessor;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
import sun.awt.*;
|
||||
|
||||
import sun.awt.image.PixelConverter;
|
||||
|
||||
import sun.awt.PaintEventDispatcher;
|
||||
import sun.awt.PeerEvent;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.X11ComponentPeer;
|
||||
import sun.awt.X11GraphicsConfig;
|
||||
import sun.java2d.SunGraphics2D;
|
||||
import sun.java2d.SurfaceData;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
|
||||
class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XWindow");
|
||||
@ -117,10 +137,6 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
|
||||
*/
|
||||
private int mouseButtonClickAllowed = 0;
|
||||
|
||||
native int getNativeColor(Color clr, GraphicsConfiguration gc);
|
||||
native void getWMInsets(long window, long left, long top, long right, long bottom, long border);
|
||||
native long getTopWindow(long window, long rootWin);
|
||||
native void getWindowBounds(long window, long x, long y, long width, long height);
|
||||
private static native void initIDs();
|
||||
|
||||
static {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 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
|
||||
@ -1263,43 +1263,6 @@ jobject awtJNI_GetColorModel(JNIEnv *env, AwtGraphicsConfigDataPtr aData)
|
||||
extern jfieldID colorValueID;
|
||||
|
||||
#ifndef HEADLESS
|
||||
int awtJNI_GetColorForVis (JNIEnv *env,jobject this, AwtGraphicsConfigDataPtr awt_data)
|
||||
{
|
||||
int col;
|
||||
jclass SYSCLR_class;
|
||||
|
||||
if (!JNU_IsNull(env,this))
|
||||
{
|
||||
SYSCLR_class = (*env)->FindClass(env, "java/awt/SystemColor");
|
||||
CHECK_NULL_RETURN(SYSCLR_class, 0);
|
||||
|
||||
if ((*env)->IsInstanceOf(env, this, SYSCLR_class)) {
|
||||
/* SECURITY: This is safe, because there is no way
|
||||
* for client code to insert an object
|
||||
* that is a subclass of SystemColor
|
||||
*/
|
||||
col = (int) JNU_CallMethodByName(env
|
||||
,NULL
|
||||
,this
|
||||
,"getRGB"
|
||||
,"()I").i;
|
||||
JNU_CHECK_EXCEPTION_RETURN(env, 0);
|
||||
} else {
|
||||
col = (int)(*env)->GetIntField(env,this,colorValueID);
|
||||
}
|
||||
|
||||
if (awt_data->awt_cmap == (Colormap) NULL) {
|
||||
awtJNI_CreateColorData (env, awt_data, 1);
|
||||
}
|
||||
|
||||
col = awt_data->AwtColorMatch(red(col), green(col), blue(col),
|
||||
awt_data);
|
||||
return col;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
awt_allocate_systemrgbcolors (jint *rgbColors, int num_colors,
|
||||
AwtGraphicsConfigDataPtr awtData) {
|
||||
|
@ -104,7 +104,6 @@ extern AwtGraphicsConfigDataPtr getDefaultConfig(int screen);
|
||||
extern int awt_allocate_colors(AwtGraphicsConfigDataPtr);
|
||||
extern void awt_allocate_systemrgbcolors(jint *, int, AwtGraphicsConfigDataPtr);
|
||||
|
||||
extern int awtJNI_GetColorForVis (JNIEnv *, jobject, AwtGraphicsConfigDataPtr);
|
||||
extern jobject awtJNI_GetColorModel(JNIEnv *, AwtGraphicsConfigDataPtr);
|
||||
extern void awtJNI_CreateColorData (JNIEnv *, AwtGraphicsConfigDataPtr, int lock);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 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
|
||||
@ -1124,19 +1124,6 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XWindow_x11inputMethodLookupString
|
||||
|
||||
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
|
||||
|
||||
/*
|
||||
* Class: Java_sun_awt_X11_XWindow_getNativeColor
|
||||
* Method: getNativeColor
|
||||
* Signature (Ljava/awt/Color;Ljava/awt/GraphicsConfiguration;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_sun_awt_X11_XWindow_getNativeColor
|
||||
(JNIEnv *env, jobject this, jobject color, jobject gc_object) {
|
||||
AwtGraphicsConfigDataPtr adata;
|
||||
/* fire warning because JNU_GetLongFieldAsPtr casts jlong to (void *) */
|
||||
adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, gc_object, x11GraphicsConfigIDs.aData);
|
||||
return awtJNI_GetColorForVis(env, color, adata);
|
||||
}
|
||||
|
||||
/* syncTopLevelPos() is necessary to insure that the window manager has in
|
||||
* fact moved us to our final position relative to the reParented WM window.
|
||||
* 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 ) {
|
||||
} while (i++ < 50);
|
||||
}
|
||||
|
||||
static Window getTopWindow(Window win, Window *rootWin)
|
||||
{
|
||||
Window root=None, current_window=win, parent=None, *ignore_children=NULL;
|
||||
Window prev_window=None;
|
||||
unsigned int ignore_uint=0;
|
||||
Status status = 0;
|
||||
|
||||
if (win == None) return None;
|
||||
do {
|
||||
status = XQueryTree(awt_display,
|
||||
current_window,
|
||||
&root,
|
||||
&parent,
|
||||
&ignore_children,
|
||||
&ignore_uint);
|
||||
XFree(ignore_children);
|
||||
if (status == 0) return None;
|
||||
prev_window = current_window;
|
||||
current_window = parent;
|
||||
} while (parent != root);
|
||||
*rootWin = root;
|
||||
return prev_window;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_sun_awt_X11_XWindow_getTopWindow
|
||||
(JNIEnv *env, jclass clazz, jlong win, jlong rootWin) {
|
||||
return getTopWindow((Window) win, (Window*) jlong_to_ptr(rootWin));
|
||||
}
|
||||
|
||||
static void
|
||||
getWMInsets
|
||||
(Window window, int *left, int *top, int *right, int *bottom, int *border) {
|
||||
// window is event->xreparent.window
|
||||
Window topWin = None, rootWin = None, containerWindow = None;
|
||||
XWindowAttributes winAttr, topAttr;
|
||||
int screenX, screenY;
|
||||
topWin = getTopWindow(window, &rootWin);
|
||||
syncTopLevelPos(awt_display, topWin, &topAttr);
|
||||
// (screenX, screenY) is (0,0) of the reparented window
|
||||
// converted to screen coordinates.
|
||||
XTranslateCoordinates(awt_display, window, rootWin,
|
||||
0,0, &screenX, &screenY, &containerWindow);
|
||||
*left = screenX - topAttr.x - topAttr.border_width;
|
||||
*top = screenY - topAttr.y - topAttr.border_width;
|
||||
XGetWindowAttributes(awt_display, window, &winAttr);
|
||||
*right = topAttr.width - ((winAttr.width) + *left);
|
||||
*bottom = topAttr.height - ((winAttr.height) + *top);
|
||||
*border = topAttr.border_width;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWMInsets
|
||||
(JNIEnv *env, jclass clazz, jlong window, jlong left, jlong top, jlong right, jlong bottom, jlong border) {
|
||||
getWMInsets((Window) window,
|
||||
(int*) jlong_to_ptr(left),
|
||||
(int*) jlong_to_ptr(top),
|
||||
(int*) jlong_to_ptr(right),
|
||||
(int*) jlong_to_ptr(bottom),
|
||||
(int*) jlong_to_ptr(border));
|
||||
}
|
||||
|
||||
static void
|
||||
getWindowBounds
|
||||
(Window window, int *x, int *y, int *width, int *height) {
|
||||
XWindowAttributes winAttr;
|
||||
XSync(awt_display, False);
|
||||
XGetWindowAttributes(awt_display, window, &winAttr);
|
||||
*x = winAttr.x;
|
||||
*y = winAttr.y;
|
||||
*width = winAttr.width;
|
||||
*height = winAttr.height;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_getWindowBounds
|
||||
(JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) {
|
||||
getWindowBounds((Window) window, (int*) jlong_to_ptr(x), (int*) jlong_to_ptr(y),
|
||||
(int*) jlong_to_ptr(width), (int*) jlong_to_ptr(height));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_sun_awt_X11_XWindow_setSizeHints
|
||||
(JNIEnv *env, jclass clazz, jlong window, jlong x, jlong y, jlong width, jlong height) {
|
||||
XSizeHints *size_hints = XAllocSizeHints();
|
||||
|
Loading…
x
Reference in New Issue
Block a user