src/macosx/classes/sun/awt/CGraphicsEnvironment.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2011, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2011, 2013, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 24,46 ****
*/
package sun.awt;
import java.awt.*;
- import java.awt.print.*;
import java.util.*;
import sun.java2d.*;
/**
! * This is an implementation of a GraphicsEnvironment object for the default local GraphicsEnvironment used by the Java
! * Runtime Environment for Mac OS X GUI environments.
*
* @see GraphicsDevice
* @see GraphicsConfiguration
*/
! public class CGraphicsEnvironment extends SunGraphicsEnvironment {
// Global initialization of the Cocoa runtime.
private static native void initCocoa();
/**
* Fetch an array of all valid CoreGraphics display identifiers.
--- 24,47 ----
*/
package sun.awt;
import java.awt.*;
import java.util.*;
import sun.java2d.*;
/**
! * This is an implementation of a GraphicsEnvironment object for the default
! * local GraphicsEnvironment used by the Java Runtime Environment for Mac OS X
! * GUI environments.
*
* @see GraphicsDevice
* @see GraphicsConfiguration
*/
! public final class CGraphicsEnvironment extends SunGraphicsEnvironment {
!
// Global initialization of the Cocoa runtime.
private static native void initCocoa();
/**
* Fetch an array of all valid CoreGraphics display identifiers.
*** 51,61 ****
* Fetch the CoreGraphics display ID for the 'main' display.
*/
private static native int getMainDisplayID();
/**
! * Noop function that just acts as an entry point for someone to force a static initialization of this class.
*/
public static void init() { }
static {
java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
--- 52,63 ----
* Fetch the CoreGraphics display ID for the 'main' display.
*/
private static native int getMainDisplayID();
/**
! * Noop function that just acts as an entry point for someone to force a
! * static initialization of this class.
*/
public static void init() { }
static {
java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
*** 76,87 ****
// Install the correct surface manager factory.
SurfaceManagerFactory.setInstance(new MacosxSurfaceManagerFactory());
}
/**
! * Register the instance with CGDisplayRegisterReconfigurationCallback()
! * The registration uses a weak global reference -- if our instance is garbage collected, the reference will be dropped.
*
* @return Return the registration context (a pointer).
*/
private native long registerDisplayReconfiguration();
--- 78,90 ----
// Install the correct surface manager factory.
SurfaceManagerFactory.setInstance(new MacosxSurfaceManagerFactory());
}
/**
! * Register the instance with CGDisplayRegisterReconfigurationCallback().
! * The registration uses a weak global reference -- if our instance is
! * garbage collected, the reference will be dropped.
*
* @return Return the registration context (a pointer).
*/
private native long registerDisplayReconfiguration();
*** 89,99 ****
* Remove the instance's registration with CGDisplayRemoveReconfigurationCallback()
*/
private native void deregisterDisplayReconfiguration(long context);
/** Available CoreGraphics displays. */
! private final Map<Integer, CGraphicsDevice> devices = new HashMap<Integer, CGraphicsDevice>();
/** Reference to the display reconfiguration callback context. */
private final long displayReconfigContext;
/**
--- 92,102 ----
* Remove the instance's registration with CGDisplayRemoveReconfigurationCallback()
*/
private native void deregisterDisplayReconfiguration(long context);
/** Available CoreGraphics displays. */
! private final Map<Integer, CGraphicsDevice> devices = new HashMap<>(5);
/** Reference to the display reconfiguration callback context. */
private final long displayReconfigContext;
/**
*** 116,130 ****
}
/**
* Called by the CoreGraphics Display Reconfiguration Callback.
*
! * @param displayId
! * CoreGraphics displayId
*/
! void _displayReconfiguration(long displayId) {
! displayChanged();
}
@Override
protected void finalize() throws Throwable {
try {
--- 119,140 ----
}
/**
* Called by the CoreGraphics Display Reconfiguration Callback.
*
! * @param displayId CoreGraphics displayId
! * @param removed true if displayId was removed, false otherwise.
*/
! void _displayReconfiguration(final int displayId, final boolean removed) {
! synchronized (this) {
! if (removed && devices.containsKey(displayId)) {
! final CGraphicsDevice gd = devices.remove(displayId);
! gd.invalidate(getMainDisplayID());
! gd.displayChanged();
! }
! }
! initDevices();
}
@Override
protected void finalize() throws Throwable {
try {
*** 133,175 ****
deregisterDisplayReconfiguration(displayReconfigContext);
}
}
/**
! * (Re)create all CGraphicsDevices
! *
! * @return
*/
! private synchronized void initDevices() {
devices.clear();
int mainID = getMainDisplayID();
// initialization of the graphics device may change
// list of displays on hybrid systems via an activation
// of discrete video.
// So, we initialize the main display first, and then
// retrieve actual list of displays.
! CGraphicsDevice mainDevice = new CGraphicsDevice(mainID);
!
! final int[] displayIDs = getDisplayIDs();
! for (int displayID : displayIDs) {
! if (displayID != mainID) {
! devices.put(displayID, new CGraphicsDevice(displayID));
! } else {
! devices.put(mainID, mainDevice);
}
}
}
@Override
public synchronized GraphicsDevice getDefaultScreenDevice() throws HeadlessException {
final int mainDisplayID = getMainDisplayID();
CGraphicsDevice d = devices.get(mainDisplayID);
if (d == null) {
! // we do not exepct that this may happen, the only responce
// is to re-initialize the list of devices
initDevices();
d = devices.get(mainDisplayID);
}
--- 143,184 ----
deregisterDisplayReconfiguration(displayReconfigContext);
}
}
/**
! * (Re)create all CGraphicsDevices, reuses a devices if it is possible.
*/
! private void initDevices() {
! synchronized (this) {
! final Map<Integer, CGraphicsDevice> old = new HashMap<>(devices);
devices.clear();
int mainID = getMainDisplayID();
// initialization of the graphics device may change
// list of displays on hybrid systems via an activation
// of discrete video.
// So, we initialize the main display first, and then
// retrieve actual list of displays.
! if (!old.containsKey(mainID)) {
! old.put(mainID, new CGraphicsDevice(mainID));
! }
! for (final int id : getDisplayIDs()) {
! devices.put(id, old.containsKey(id) ? old.get(id)
! : new CGraphicsDevice(id));
}
}
+ displayChanged();
}
@Override
public synchronized GraphicsDevice getDefaultScreenDevice() throws HeadlessException {
final int mainDisplayID = getMainDisplayID();
CGraphicsDevice d = devices.get(mainDisplayID);
if (d == null) {
! // we do not expect that this may happen, the only response
// is to re-initialize the list of devices
initDevices();
d = devices.get(mainDisplayID);
}