Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/java.desktop/macosx/classes/sun/awt/CGraphicsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public abstract class CGraphicsConfig extends GraphicsConfiguration

private final CGraphicsDevice device;
private ColorModel colorModel;
private final SurfaceManager.ProxyCache surfaceDataProxyCache = new SurfaceManager.ProxyCache();
private final SurfaceManager.ProxyCache surfaceDataProxyCache =
new SurfaceManager.ProxyCache();

protected CGraphicsConfig(CGraphicsDevice device) {
this.device = device;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import java.util.ListIterator;
import java.util.Map;

import sun.java2d.MacosxSurfaceManagerFactory;
import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.SurfaceManagerFactory;

/**
* This is an implementation of a GraphicsEnvironment object for the default
Expand Down Expand Up @@ -70,8 +68,6 @@ public static void init() { }
static {
// Load libraries and initialize the Toolkit.
Toolkit.getDefaultToolkit();
// Install the correct surface manager factory.
SurfaceManagerFactory.setInstance(new MacosxSurfaceManagerFactory());
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import sun.awt.CGraphicsDevice;
import sun.awt.image.OffScreenImage;
import sun.awt.image.SunVolatileImage;
import sun.awt.image.SurfaceManager;
import sun.awt.image.VolatileSurfaceManager;
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;
import sun.java2d.Surface;
Expand Down Expand Up @@ -67,7 +69,7 @@
import static sun.java2d.metal.MTLContext.MTLContextCaps.CAPS_EXT_BIOP_SHADER;

public final class MTLGraphicsConfig extends CGraphicsConfig
implements AccelGraphicsConfig
implements AccelGraphicsConfig, SurfaceManager.Factory
{
private static ImageCapabilities imageCaps = new MTLImageCaps();

Expand Down Expand Up @@ -372,4 +374,10 @@ public int getMaxTextureHeight() {
return Math.max(maxTextureSize / getDevice().getScaleFactor(),
getBounds().height);
}

@Override
public VolatileSurfaceManager createVolatileManager(SunVolatileImage image,
Object context) {
return new MTLVolatileSurfaceManager(image, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import sun.awt.CGraphicsDevice;
import sun.awt.image.OffScreenImage;
import sun.awt.image.SunVolatileImage;
import sun.awt.image.SurfaceManager;
import sun.awt.image.VolatileSurfaceManager;
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;
import sun.java2d.Surface;
Expand Down Expand Up @@ -386,4 +388,10 @@ public int getMaxTextureHeight() {
return Math.max(maxTextureSize / getDevice().getScaleFactor(),
getBounds().height);
}

@Override
public VolatileSurfaceManager createVolatileManager(SunVolatileImage image,
Object context) {
return new CGLVolatileSurfaceManager(image, context);
}
}
33 changes: 11 additions & 22 deletions src/java.desktop/share/classes/sun/awt/image/SunVolatileImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.awt.image.ImageObserver;
import java.awt.image.VolatileImage;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceManagerFactory;
import sun.java2d.DestSurfaceProvider;
import sun.java2d.Surface;
import sun.java2d.pipe.Region;
Expand Down Expand Up @@ -158,29 +157,19 @@ public int getForcedAccelSurfaceType() {
return forcedAccelSurfaceType;
}

protected VolatileSurfaceManager createSurfaceManager(Object context,
ImageCapabilities caps)
{
/**
* Platform-specific SurfaceManagerFactories will return a
* manager suited to acceleration on each platform. But if
* the user is asking for a VolatileImage from a BufferedImageGC,
* then we need to return the appropriate unaccelerated manager.
* Note: this could change in the future; if some platform would
* like to accelerate BIGC volatile images, then this special-casing
* of the BIGC graphicsConfig should live in platform-specific
* code instead.
* We do the same for a Printer Device, and if user requested an
* unaccelerated VolatileImage by passing the capabilities object.
*/
if (graphicsConfig instanceof BufferedImageGraphicsConfig ||
graphicsConfig instanceof sun.print.PrinterGraphicsConfig ||
(caps != null && !caps.isAccelerated()))
{
private VolatileSurfaceManager createSurfaceManager(
Object context, ImageCapabilities caps) {
// GraphicsConfig may provide some specific surface manager
// implementation.
// In case it doesn't, or we were specifically requested to use
// an unaccelerated surface, fall back to the buffered image
// surface manager.
if ((caps == null || caps.isAccelerated()) &&
graphicsConfig instanceof SurfaceManager.Factory factory) {
return factory.createVolatileManager(this, context);
} else {
return new BufImgVolatileSurfaceManager(this, context);
}
SurfaceManagerFactory smf = SurfaceManagerFactory.getInstance();
return smf.createVolatileManager(this, context);
}

private Color getForeground() {
Expand Down
23 changes: 21 additions & 2 deletions src/java.desktop/share/classes/sun/awt/image/SurfaceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ public boolean isAccelerated() {
}
}

/**
* An interface for GraphicsConfiguration objects to implement if
* they create their own VolatileSurfaceManager implementations.
*/
public interface Factory {

/**
* Creates a new instance of a VolatileSurfaceManager given a
* compatible SunVolatileImage.
* An optional context Object can be supplied as a way for the caller
* to pass pipeline-specific context data to the VolatileSurfaceManager
* (such as a backbuffer handle, for example).
*/
VolatileSurfaceManager createVolatileManager(SunVolatileImage image,
Object context);
}

/**
* An interface for GraphicsConfiguration objects to implement if
* their surfaces accelerate images using SurfaceDataProxy objects.
Expand All @@ -201,7 +218,8 @@ public interface ProxiedGraphicsConfig {
}

public static class ProxyCache {
private final Map<SurfaceManager, SurfaceDataProxy> map = Collections.synchronizedMap(new WeakHashMap<>());
private final Map<SurfaceManager, SurfaceDataProxy> map =
Collections.synchronizedMap(new WeakHashMap<>());

/**
* Return a cached SurfaceDataProxy object for a given SurfaceManager.
Expand Down Expand Up @@ -252,7 +270,8 @@ public synchronized void flush() {

void flush(boolean deaccelerate) {
synchronized (weakCache) {
Iterator<WeakReference<SurfaceDataProxy>> i = weakCache.values().iterator();
Iterator<WeakReference<SurfaceDataProxy>> i =
weakCache.values().iterator();
while (i.hasNext()) {
SurfaceDataProxy sdp = i.next().get();
if (sdp == null || sdp.flush(deaccelerate)) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* methods directly from OGLSurfaceData.
*/
interface OGLGraphicsConfig extends
AccelGraphicsConfig, SurfaceManager.ProxiedGraphicsConfig
AccelGraphicsConfig, SurfaceManager.ProxiedGraphicsConfig, SurfaceManager.Factory
{
OGLContext getContext();
long getNativeConfigInfo();
Expand Down
10 changes: 9 additions & 1 deletion src/java.desktop/unix/classes/sun/awt/X11GraphicsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import sun.awt.image.OffScreenImage;
import sun.awt.image.SunVolatileImage;
import sun.awt.image.SurfaceManager;
import sun.awt.image.VolatileSurfaceManager;
import sun.java2d.Disposer;
import sun.java2d.DisposerRecord;
import sun.java2d.SurfaceData;
Expand All @@ -55,6 +56,7 @@
import sun.java2d.loops.SurfaceType;
import sun.java2d.pipe.Region;
import sun.java2d.x11.X11SurfaceData;
import sun.java2d.x11.X11VolatileSurfaceManager;

/**
* This is an implementation of a GraphicsConfiguration object for a
Expand All @@ -64,7 +66,7 @@
* @see GraphicsDevice
*/
public class X11GraphicsConfig extends GraphicsConfiguration
implements SurfaceManager.ProxiedGraphicsConfig
implements SurfaceManager.ProxiedGraphicsConfig, SurfaceManager.Factory
{
private final X11GraphicsDevice device;
protected int visual;
Expand Down Expand Up @@ -500,4 +502,10 @@ public boolean isTranslucencyCapable() {
}

private native boolean isTranslucencyCapable(long x11ConfigData);

@Override
public VolatileSurfaceManager createVolatileManager(SunVolatileImage image,
Object context) {
return new X11VolatileSurfaceManager(image, context);
}
}
6 changes: 4 additions & 2 deletions src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public final class X11GraphicsDevice extends GraphicsDevice
* therefore methods, which is using this id should be ready to it.
*/
private volatile int screen;
Map<SurfaceType, SurfaceManager.ProxyCache> x11ProxyCacheMap = Collections.synchronizedMap(new HashMap<>());
Map<SurfaceType, SurfaceManager.ProxyCache> x11ProxyCacheMap =
Collections.synchronizedMap(new HashMap<>());

private static Boolean xrandrExtSupported;
private SunDisplayChanger topLevels = new SunDisplayChanger();
Expand Down Expand Up @@ -95,7 +96,8 @@ public int getScreen() {
}

public SurfaceManager.ProxyCache getProxyCacheFor(SurfaceType st) {
return x11ProxyCacheMap.computeIfAbsent(st, unused -> new SurfaceManager.ProxyCache());
return x11ProxyCacheMap.computeIfAbsent(st,
unused -> new SurfaceManager.ProxyCache());
}

/**
Expand Down
Loading