Skip to content

Commit

Permalink
8237049: Rollback the workaround for JDK-4533057
Browse files Browse the repository at this point in the history
Reviewed-by: dmarkov
  • Loading branch information
mrserb committed Jan 24, 2020
1 parent 7fa7536 commit 05b98dd
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 99 deletions.
144 changes: 97 additions & 47 deletions src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,60 +25,125 @@


package sun.awt.windows; package sun.awt.windows;


import java.awt.peer.TaskbarPeer; import java.awt.AWTEvent;
import java.awt.*; import java.awt.AWTException;
import java.awt.im.InputMethodHighlight; import java.awt.Button;
import java.awt.im.spi.InputMethodDescriptor; import java.awt.Canvas;
import java.awt.image.*; import java.awt.Checkbox;
import java.awt.peer.*; import java.awt.CheckboxMenuItem;
import java.awt.Choice;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Insets;
import java.awt.JobAttributes;
import java.awt.Label;
import java.awt.List;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.PageAttributes;
import java.awt.Panel;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.PrintJob;
import java.awt.RenderingHints;
import java.awt.Robot;
import java.awt.ScrollPane;
import java.awt.Scrollbar;
import java.awt.SystemTray;
import java.awt.Taskbar;
import java.awt.TextArea;
import java.awt.TextComponent;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.Window;
import java.awt.datatransfer.Clipboard;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.MouseDragGestureRecognizer;
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.datatransfer.Clipboard; import java.awt.im.InputMethodHighlight;
import java.awt.TextComponent; import java.awt.im.spi.InputMethodDescriptor;
import java.awt.TrayIcon; import java.awt.image.ColorModel;
import java.awt.peer.ButtonPeer;
import java.awt.peer.CanvasPeer;
import java.awt.peer.CheckboxMenuItemPeer;
import java.awt.peer.CheckboxPeer;
import java.awt.peer.ChoicePeer;
import java.awt.peer.DesktopPeer;
import java.awt.peer.DialogPeer;
import java.awt.peer.FileDialogPeer;
import java.awt.peer.FontPeer;
import java.awt.peer.FramePeer;
import java.awt.peer.KeyboardFocusManagerPeer;
import java.awt.peer.LabelPeer;
import java.awt.peer.ListPeer;
import java.awt.peer.MenuBarPeer;
import java.awt.peer.MenuItemPeer;
import java.awt.peer.MenuPeer;
import java.awt.peer.MouseInfoPeer;
import java.awt.peer.PanelPeer;
import java.awt.peer.PopupMenuPeer;
import java.awt.peer.RobotPeer;
import java.awt.peer.ScrollPanePeer;
import java.awt.peer.ScrollbarPeer;
import java.awt.peer.SystemTrayPeer;
import java.awt.peer.TaskbarPeer;
import java.awt.peer.TextAreaPeer;
import java.awt.peer.TextFieldPeer;
import java.awt.peer.TrayIconPeer;
import java.awt.peer.WindowPeer;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;


import sun.awt.AWTAccessor; import sun.awt.AWTAccessor;
import sun.awt.AppContext;
import sun.awt.AWTAutoShutdown; import sun.awt.AWTAutoShutdown;
import sun.awt.AWTPermissions; import sun.awt.AWTPermissions;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.awt.DisplayChangedListener; import sun.awt.DisplayChangedListener;
import sun.awt.LightweightFrame; import sun.awt.LightweightFrame;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.awt.util.ThreadGroupUtils;
import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsDevice;
import sun.awt.Win32GraphicsEnvironment; import sun.awt.Win32GraphicsEnvironment;
import sun.awt.datatransfer.DataTransferer; import sun.awt.datatransfer.DataTransferer;
import sun.java2d.d3d.D3DRenderQueue;
import sun.java2d.opengl.OGLRenderQueue;

import sun.print.PrintJob2D;

import java.awt.dnd.DragSource;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.MouseDragGestureRecognizer;
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.dnd.peer.DragSourceContextPeer;

import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import sun.awt.util.PerformanceLogger; import sun.awt.util.PerformanceLogger;
import sun.awt.util.ThreadGroupUtils;
import sun.font.FontManager; import sun.font.FontManager;
import sun.font.FontManagerFactory; import sun.font.FontManagerFactory;
import sun.font.SunFontManager; import sun.font.SunFontManager;
import sun.java2d.d3d.D3DRenderQueue;
import sun.java2d.opengl.OGLRenderQueue;
import sun.print.PrintJob2D;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;


public final class WToolkit extends SunToolkit implements Runnable { public final class WToolkit extends SunToolkit implements Runnable {
Expand Down Expand Up @@ -133,23 +198,8 @@ public Void run() {
if (log.isLoggable(PlatformLogger.Level.FINE)) { if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("Win version: " + getWindowsVersion()); log.fine("Win version: " + getWindowsVersion());
} }

AccessController.doPrivileged(
new PrivilegedAction <Void> ()
{
@Override
public Void run() {
String browserProp = System.getProperty("browser");
if (browserProp != null && browserProp.equals("sun.plugin")) {
disableCustomPalette();
}
return null;
}
});
} }


private static native void disableCustomPalette();

/* /*
* NOTE: The following embedded*() methods are non-public API intended * NOTE: The following embedded*() methods are non-public API intended
* for internal use only. The methods are unsupported and could go * for internal use only. The methods are unsupported and could go
Expand Down
36 changes: 5 additions & 31 deletions src/java.desktop/windows/native/libawt/windows/awt_Palette.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,8 +30,6 @@
#include "awt_CustomPaletteDef.h" #include "awt_CustomPaletteDef.h"
#include "Trace.h" #include "Trace.h"


BOOL AwtPalette::m_useCustomPalette = TRUE;

#define ERROR_GRAY (-1) #define ERROR_GRAY (-1)
#define NON_GRAY 0 #define NON_GRAY 0
#define LINEAR_STATIC_GRAY 1 #define LINEAR_STATIC_GRAY 1
Expand All @@ -46,8 +44,7 @@ HPALETTE AwtPalette::Select(HDC hDC)
{ {
HPALETTE prevPalette = NULL; HPALETTE prevPalette = NULL;
if (logicalPalette) { if (logicalPalette) {
BOOL background = !(m_useCustomPalette); prevPalette = ::SelectPalette(hDC, logicalPalette, FALSE);
prevPalette = ::SelectPalette(hDC, logicalPalette, background);
} }
return prevPalette; return prevPalette;
} }
Expand All @@ -60,8 +57,7 @@ HPALETTE AwtPalette::Select(HDC hDC)
void AwtPalette::Realize(HDC hDC) void AwtPalette::Realize(HDC hDC)
{ {
if (logicalPalette) { if (logicalPalette) {
if (!m_useCustomPalette || if (AwtComponent::QueryNewPaletteCalled() ||
AwtComponent::QueryNewPaletteCalled() ||
AwtToolkit::GetInstance().HasDisplayChanged()) { AwtToolkit::GetInstance().HasDisplayChanged()) {
// Fix for bug 4178909, workaround for Windows bug. Shouldn't // Fix for bug 4178909, workaround for Windows bug. Shouldn't
// do a RealizePalette until the first QueryNewPalette message // do a RealizePalette until the first QueryNewPalette message
Expand All @@ -79,28 +75,6 @@ void AwtPalette::Realize(HDC hDC)
} }
} }


/**
* Disable the use of our custom palette. This method is called
* during initialization if we detect that we are running inside
* the plugin; we do not want to clobber our parent application's
* palette with our own in that situation.
*/
void AwtPalette::DisableCustomPalette()
{
m_useCustomPalette = FALSE;
}

/**
* Returns whether we are currently using a custom palette. Used
* by AwtWin32GraphicsDevice when creating the colorModel of the
* device.
*/
BOOL AwtPalette::UseCustomPalette()
{
return m_useCustomPalette;
}


/** /**
* Constructor. Initialize the system and logical palettes. * Constructor. Initialize the system and logical palettes.
* used by this object. * used by this object.
Expand Down Expand Up @@ -153,7 +127,7 @@ int AwtPalette::FetchPaletteEntries(HDC hDC, PALETTEENTRY* pPalEntries)
return 0; return 0;
} }


hPalOld = ::SelectPalette(hDC, hPal, 1); hPalOld = ::SelectPalette(hDC, hPal, TRUE);
if (hPalOld == 0) { if (hPalOld == 0) {
::DeleteObject(hPal); ::DeleteObject(hPal);
return 0; return 0;
Expand All @@ -168,7 +142,7 @@ int AwtPalette::FetchPaletteEntries(HDC hDC, PALETTEENTRY* pPalEntries)
pPalEntries[iEntry].peBlue = GetBValue(rgb); pPalEntries[iEntry].peBlue = GetBValue(rgb);
} }


::SelectPalette(hDC, hPalOld, 0 ); ::SelectPalette(hDC, hPalOld, FALSE);
::DeleteObject(hPal); ::DeleteObject(hPal);
::RealizePalette(hDC); ::RealizePalette(hDC);


Expand Down
8 changes: 1 addition & 7 deletions src/java.desktop/windows/native/libawt/windows/awt_Palette.h
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -49,10 +49,6 @@ class AwtPalette {


HPALETTE GetPalette() { return logicalPalette; } HPALETTE GetPalette() { return logicalPalette; }


static void DisableCustomPalette();

static BOOL UseCustomPalette();

AwtPalette(AwtWin32GraphicsDevice *device); AwtPalette(AwtWin32GraphicsDevice *device);


static int FetchPaletteEntries(HDC hDC, PALETTEENTRY* pPalEntries); static int FetchPaletteEntries(HDC hDC, PALETTEENTRY* pPalEntries);
Expand All @@ -66,8 +62,6 @@ class AwtPalette {
unsigned char *GetSystemInverseLUT() { return systemInverseLUT; } unsigned char *GetSystemInverseLUT() { return systemInverseLUT; }


private: private:
static BOOL m_useCustomPalette;

unsigned int logicalEntries[256]; unsigned int logicalEntries[256];
unsigned int systemEntries[256]; unsigned int systemEntries[256];
PALETTEENTRY systemEntriesWin32[256]; // cached to eliminate PALETTEENTRY systemEntriesWin32[256]; // cached to eliminate
Expand Down
13 changes: 1 addition & 12 deletions src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -2465,17 +2465,6 @@ Java_sun_awt_windows_WToolkit_initIDs(JNIEnv *env, jclass cls)
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }



/*
* Class: sun_awt_windows_Toolkit
* Method: disableCustomPalette
* Signature: ()V
*/
JNIEXPORT void JNICALL
Java_sun_awt_windows_WToolkit_disableCustomPalette(JNIEnv *env, jclass cls) {
AwtPalette::DisableCustomPalette();
}

/* /*
* Class: sun_awt_windows_WToolkit * Class: sun_awt_windows_WToolkit
* Method: embeddedInit * Method: embeddedInit
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2011, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -405,7 +405,7 @@ jobject AwtWin32GraphicsDevice::GetColorModel(JNIEnv *env, jboolean dynamic)
vbits[sizeof(vbits)-1] = 0; vbits[sizeof(vbits)-1] = 0;
allvalid = JNI_FALSE; allvalid = JNI_FALSE;
} else { } else {
if (AwtPalette::UseCustomPalette() && !dynamic) { if (!dynamic) {
// If we plan to use our custom palette (i.e., we are // If we plan to use our custom palette (i.e., we are
// not running inside another app and we are not creating // not running inside another app and we are not creating
// a dynamic colorModel object), then setup ICM with // a dynamic colorModel object), then setup ICM with
Expand Down

0 comments on commit 05b98dd

Please sign in to comment.