feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2007, 2008, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
/**
* An interface for receiving notifications about imminent accelerated device's
* events. Upon receiving such event appropriate actions can be taken (for
* example, resources associated with the device can be freed).
*/
public interface AccelDeviceEventListener {
/**
* Called when the device is about to be reset.
*
* One must release all native resources associated with the device which
* prevent the device from being reset (such as Default Pool resources for
* the D3D pipeline).
*
* It is safe to remove the listener while in the call back.
*
* Note: this method is called on the rendering thread,
* do not call into user code, do not take RQ lock!
*/
public void onDeviceReset();
/**
* Called when the device is about to be disposed of.
*
* One must release all native resources associated with the device.
*
* It is safe to remove the listener while in the call back.
*
* Note: this method is called on the rendering thread,
* do not call into user code, do not take RQ lock!
*/
public void onDeviceDispose();
}

View File

@@ -0,0 +1,169 @@
/*
* Copyright (c) 2007, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.lang.annotation.Native;
/**
* This class is used to notify listeners about accelerated device's
* events such as device reset or dispose that are about to occur.
*/
public class AccelDeviceEventNotifier {
private static AccelDeviceEventNotifier theInstance;
/**
* A device is about to be reset. The listeners have to release all
* resources associated with the device which are required for the device
* to be reset.
*/
@Native public static final int DEVICE_RESET = 0;
/**
* A device is about to be disposed. The listeners have to release all
* resources associated with the device.
*/
@Native public static final int DEVICE_DISPOSED = 1;
private final Map<AccelDeviceEventListener, Integer> listeners;
private AccelDeviceEventNotifier() {
listeners = Collections.synchronizedMap(
new HashMap<AccelDeviceEventListener, Integer>(1));
}
/**
* Returns a singleton of AccelDeviceEventNotifier if it exists. If the
* passed boolean is false and singleton doesn't exist yet, null is
* returned. If the passed boolean is {@code true} and singleton doesn't
* exist it will be created and returned.
*
* @param create whether to create a singleton instance if doesn't yet
* exist
* @return a singleton instance or null
*/
private static synchronized
AccelDeviceEventNotifier getInstance(boolean create)
{
if (theInstance == null && create) {
theInstance = new AccelDeviceEventNotifier();
}
return theInstance;
}
/**
* Called to indicate that a device event had occurred.
* If a singleton exists, the listeners (those associated with
* the device) will be notified.
*
* @param screen a screen number of the device which is a source of
* the event
* @param eventType a type of the event
* @see #DEVICE_DISPOSED
* @see #DEVICE_RESET
*/
public static final void eventOccured(int screen, int eventType) {
AccelDeviceEventNotifier notifier = getInstance(false);
if (notifier != null) {
notifier.notifyListeners(eventType, screen);
}
}
/**
* Adds the listener associated with a device on particular screen.
*
* Note: the listener must be removed as otherwise it will forever
* be referenced by the notifier.
*
* @param l the listener
* @param screen the screen number indicating which device the listener is
* interested in.
*/
public static final void addListener(AccelDeviceEventListener l,int screen){
getInstance(true).add(l, screen);
}
/**
* Removes the listener.
*
* @param l the listener
*/
public static final void removeListener(AccelDeviceEventListener l) {
getInstance(true).remove(l);
}
private final void add(AccelDeviceEventListener theListener, int screen) {
listeners.put(theListener, screen);
}
private final void remove(AccelDeviceEventListener theListener) {
listeners.remove(theListener);
}
/**
* Notifies the listeners associated with the screen's device about the
* event.
*
* Implementation note: the current list of listeners is first duplicated
* which allows the listeners to remove themselves during the iteration.
*
* @param screen a screen number with which the device which is a source of
* the event is associated with
* @param eventType a type of the event
* @see #DEVICE_DISPOSED
* @see #DEVICE_RESET
*/
private final void notifyListeners(int deviceEventType, int screen) {
HashMap<AccelDeviceEventListener, Integer> listClone;
Set<AccelDeviceEventListener> cloneSet;
synchronized(listeners) {
listClone =
new HashMap<AccelDeviceEventListener, Integer>(listeners);
}
cloneSet = listClone.keySet();
Iterator<AccelDeviceEventListener> itr = cloneSet.iterator();
while (itr.hasNext()) {
AccelDeviceEventListener current = itr.next();
Integer i = listClone.get(current);
// only notify listeners which are interested in this device
if (i != null && i.intValue() != screen) {
continue;
}
if (deviceEventType == DEVICE_RESET) {
current.onDeviceReset();
} else if (deviceEventType == DEVICE_DISPOSED) {
current.onDeviceDispose();
}
}
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 2007, 2008, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
import java.awt.image.VolatileImage;
/**
* Implementors of this interface provida a way to create a
* {@code VolatileImage} whose destination surface is an
* {@link AccelSurface} of specified type.
*
* @see AccelSurface
*/
public interface AccelGraphicsConfig extends BufferedContextProvider {
/**
* Returns a VolatileImage with specified width, height, transparency
* and guaranteed accelerated surface type. If such image can not be created
* (out of vram error, specific surface type is not supported) null
* is returned.
*
* Note: if {@link AccelSurface#TEXTURE} type is requested, rendering
* to the image will be denied by throwing
* {@code UnsupportedOperationException }
* from {@link java.awt.image.VolatileImage#getGraphics} and
* {@link java.awt.image.VolatileImage#createGraphics}
*
* @param width the width of the returned {@code VolatileImage}
* @param height the height of the returned {@code VolatileImage}
* @param transparency the specified transparency mode
* @param type requested accelerated surface type as specified by constants
* in AccelSurface interface
* @return a {@code VolatileImage} backed up by requested accelerated
* surface type or null
* @throws IllegalArgumentException if the transparency is not a valid value
* @see AccelSurface#TEXTURE
* @see AccelSurface#RT_PLAIN
* @see AccelSurface#RT_TEXTURE
*/
public VolatileImage createCompatibleVolatileImage(int width, int height,
int transparency,
int type);
/**
* Returns object representing capabilities of the context associated
* with this {@code AccelGraphicsConfig}.
*
* @return ContextCapabilities object representing caps
* @see ContextCapabilities
*/
public ContextCapabilities getContextCapabilities();
/**
* Adds an {@code AccelDeviceEventListener} to listen to accelerated
* device's (which is associated with this {@code AccelGraphicsConfig})
* events.
*
* Note: a hard link to the listener may be kept so it must be explicitly
* removed via {@link #removeDeviceEventListener()}.
*
* @param l the listener
* @see AccelDeviceEventListener
*/
public void addDeviceEventListener(AccelDeviceEventListener l);
/**
* Removes an {@code AccelDeviceEventListener} from the list of listeners
* for this device's events.
*
* @param l the listener
* @see AccelDeviceEventListener
*/
public void removeDeviceEventListener(AccelDeviceEventListener l);
}

View File

@@ -0,0 +1,137 @@
/*
* Copyright (c) 2007, 2015, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
import java.awt.Rectangle;
import sun.java2d.Surface;
import java.lang.annotation.Native;
/**
* Abstraction for a hardware accelerated surface.
*/
public interface AccelSurface extends BufferedContextProvider, Surface {
/**
* Undefined
*/
@Native public static final int UNDEFINED = 0;
/**
* Window (or window substitute) surface
*/
@Native public static final int WINDOW = 1;
/**
* Render-To Plain surface (Render Target surface for Direct3D)
*/
@Native public static final int RT_PLAIN = 2;
/**
* Texture surface
*/
@Native public static final int TEXTURE = 3;
/**
* A back-buffer surface (SwapChain surface for Direct3D, backbuffer for
* OpenGL)
*/
@Native public static final int FLIP_BACKBUFFER = 4;
/**
* Render-To Texture surface (fbobject for OpenGL, texture with render-to
* attribute for Direct3D)
*/
@Native public static final int RT_TEXTURE = 5;
/**
* Returns {@code int} representing surface's type as defined by constants
* in this interface.
*
* @return an integer representing this surface's type
* @see AccelSurface#UNDEFINED
* @see AccelSurface#WINDOW
* @see AccelSurface#RT_PLAIN
* @see AccelSurface#TEXTURE
* @see AccelSurface#FLIP_BACKBUFFER
* @see AccelSurface#RT_TEXTURE
*/
public int getType();
/**
* Returns a pointer to the native surface data associated with this
* surface.
* Note: this pointer is only valid on the rendering thread.
*
* @return pointer to the native surface's data
*/
public long getNativeOps();
/**
* Returns a pointer to the real native resource
* of the specified type associated with this AccelSurface.
* Note: this pointer is only valid on the rendering thread.
*
* @param resType the type of the requested resource
* @return a long containing a pointer to the native resource of the
* specified type or 0L if such resource doesn't exist for this surface
*/
public long getNativeResource(int resType);
/**
* Marks this surface dirty.
*/
public void markDirty();
/**
* Returns whether the pipeline considers this surface valid. A surface
* may become invalid if it is disposed of, or resized.
*
* @return true if valid, false otherwise
*/
public boolean isValid();
/**
* Returns whether this surface is lost. The return value is only valid
* on the render thread, meaning that even if this method returns
* {@code true} it could be lost in the next moment unless it is called
* on the rendering thread.
*
* @return true if the surface is known to be lost, false otherwise
*/
public boolean isSurfaceLost();
/**
* Returns the requested bounds of the destination surface. The real bounds
* of the native accelerated surface may differ. Use
* {@link #getNativeBounds} to get the bounds of the native surface.
*
* @return Rectangle representing java surface's bounds
*/
public Rectangle getBounds();
/**
* Returns real bounds of the native surface, which may differ from those
* returned by {@link #getBounds}.
*
* @return Rectangle representing native surface's bounds
*/
public Rectangle getNativeBounds();
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2007, 2008, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import sun.awt.image.SunVolatileImage;
import static sun.java2d.pipe.hw.AccelSurface.*;
/**
* This is an image with forced type of the accelerated surface.
*/
public class AccelTypedVolatileImage extends SunVolatileImage {
/**
* Creates a volatile image with specified type of accelerated surface.
*
* @param graphicsConfig a GraphicsConfiguration for which this image should
* be created.
* @param width width
* @param height width
* @param transparency type of {@link java.awt.Transparency transparency}
* requested for the image
* @param accType type of the desired accelerated surface as defined in
* AccelSurface interface
* @see sun.java2d.pipe.hw.AccelSurface
*/
public AccelTypedVolatileImage(GraphicsConfiguration graphicsConfig,
int width, int height, int transparency,
int accType)
{
super(null, graphicsConfig, width, height, null, transparency,
null, accType);
}
/**
* {@inheritDoc}
*
* This method will throw {@code UnsupportedOperationException} if it this
* image's destination surface can not be rendered to.
*/
@Override
public Graphics2D createGraphics() {
if (getForcedAccelSurfaceType() == TEXTURE) {
throw new UnsupportedOperationException("Can't render " +
"to a non-RT Texture");
}
return super.createGraphics();
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2007, 2008, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
import sun.java2d.pipe.BufferedContext;
/**
* Classes implementing this interface can provide the {@code BufferedContext}
* associated with or used by them.
*
* @see sun.java2d.pipe.BufferedContext
*/
public interface BufferedContextProvider {
/**
* Retrieves a context associated with object implementing this
* interface.
*
* @return associated context
* @see sun.java2d.pipe.BufferedContext
*/
public BufferedContext getContext();
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2007, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
/**
* Represents a set of capabilities of a BufferedContext and associated
* AccelGraphicsConfig.
*
* @see AccelGraphicsConfig
*/
public class ContextCapabilities {
/** Indicates that the context has no capabilities. */
public static final int CAPS_EMPTY = (0 << 0);
/** Indicates that the context supports RT surfaces with alpha channel. */
public static final int CAPS_RT_PLAIN_ALPHA = (1 << 1);
/** Indicates that the context supports RT textures with alpha channel. */
public static final int CAPS_RT_TEXTURE_ALPHA = (1 << 2);
/** Indicates that the context supports opaque RT textures. */
public static final int CAPS_RT_TEXTURE_OPAQUE = (1 << 3);
/** Indicates that the context supports multitexturing. */
public static final int CAPS_MULTITEXTURE = (1 << 4);
/** Indicates that the context supports non-pow2 texture dimensions. */
public static final int CAPS_TEXNONPOW2 = (1 << 5);
/** Indicates that the context supports non-square textures. */
public static final int CAPS_TEXNONSQUARE = (1 << 6);
/** Indicates that the context supports pixel shader 2.0 or better. */
public static final int CAPS_PS20 = (1 << 7);
/** Indicates that the context supports pixel shader 3.0 or better. */
public static final int CAPS_PS30 = (1 << 8);
/*
* Pipeline contexts should use this for defining pipeline-specific
* capabilities, for example:
* int CAPS_D3D_1 = (FIRST_PRIVATE_CAP << 0);
* int CAPS_D3D_2 = (FIRST_PRIVATE_CAP << 1);
*/
protected static final int FIRST_PRIVATE_CAP = (1 << 16);
protected final int caps;
protected final String adapterId;
/**
* Constructs a {@code ContextCapabilities} object.
* @param caps an {@code int} representing the capabilities
* @param a {@code String} representing the name of the adapter, or null,
* in which case the adapterId will be set to "unknown adapter".
*/
protected ContextCapabilities(int caps, String adapterId) {
this.caps = caps;
this.adapterId = adapterId != null ? adapterId : "unknown adapter";
}
/**
* Returns a string representing the name of the graphics adapter if such
* could be determined. It is guaranteed to never return {@code null}.
* @return string representing adapter id
*/
public String getAdapterId() {
return adapterId;
}
/**
* Returns an {@code int} with capabilities (OR-ed constants defined in
* this class and its pipeline-specific subclasses).
* @return capabilities as {@code int}
*/
public int getCaps() {
return caps;
}
@Override
public String toString() {
StringBuffer buf =
new StringBuffer("ContextCapabilities: adapter=" +
adapterId+", caps=");
if (caps == CAPS_EMPTY) {
buf.append("CAPS_EMPTY");
} else {
if ((caps & CAPS_RT_PLAIN_ALPHA) != 0) {
buf.append("CAPS_RT_PLAIN_ALPHA|");
}
if ((caps & CAPS_RT_TEXTURE_ALPHA) != 0) {
buf.append("CAPS_RT_TEXTURE_ALPHA|");
}
if ((caps & CAPS_RT_TEXTURE_OPAQUE) != 0) {
buf.append("CAPS_RT_TEXTURE_OPAQUE|");
}
if ((caps & CAPS_MULTITEXTURE) != 0) {
buf.append("CAPS_MULTITEXTURE|");
}
if ((caps & CAPS_TEXNONPOW2) != 0) {
buf.append("CAPS_TEXNONPOW2|");
}
if ((caps & CAPS_TEXNONSQUARE) != 0) {
buf.append("CAPS_TEXNONSQUARE|");
}
if ((caps & CAPS_PS20) != 0) {
buf.append("CAPS_PS20|");
}
if ((caps & CAPS_PS30) != 0) {
buf.append("CAPS_PS30|");
}
}
return buf.toString();
}
}

View File

@@ -0,0 +1,154 @@
/*
* Copyright (c) 2007, 2008, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.java2d.pipe.hw;
import java.awt.BufferCapabilities;
import java.awt.ImageCapabilities;
/**
* Provides extended BufferStrategy capabilities, allowing to specify
* the type of vertical refresh synchronization for a buffer strategy.
*
* This BS capability is always page flipping because v-sync is only relevant
* to flipping buffer strategies.
*
* Note that asking for a v-synced BS doesn't necessarily guarantee that it will
* be v-synced since the vsync capability may be disabled in the driver, or
* there may be other restriction (like a number of v-synced buffer strategies
* allowed per vm). Because of this {@code createBufferStrategy} doesn't
* throw {@code AWTException} when a v-synced BS could not be created when
* requested.
*
* @see java.awt.Canvas#createBufferStrategy(int, BufferCapabilities)
* @see java.awt.Window#createBufferStrategy(int, BufferCapabilities)
*/
public class ExtendedBufferCapabilities extends BufferCapabilities {
/**
* Type of synchronization on vertical retrace.
*/
public static enum VSyncType {
/**
* Use the default v-sync mode appropriate for given BufferStrategy
* and situation.
*/
VSYNC_DEFAULT(0),
/**
* Synchronize flip on vertical retrace.
*/
VSYNC_ON(1),
/**
* Do not synchronize flip on vertical retrace.
*/
VSYNC_OFF(2);
/**
* Used to identify the v-sync type (independent of the constants
* order as opposed to {@code ordinal()}).
*/
public int id() {
return id;
}
private VSyncType(int id) {
this.id = id;
}
private int id;
}
private VSyncType vsync;
/**
* Creates an ExtendedBufferCapabilities object with front/back/flip caps
* from the passed cap, and VSYNC_DEFAULT v-sync mode.
*/
public ExtendedBufferCapabilities(BufferCapabilities caps) {
super(caps.getFrontBufferCapabilities(),
caps.getBackBufferCapabilities(),
caps.getFlipContents());
this.vsync = VSyncType.VSYNC_DEFAULT;
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the passed caps, and VSYNC_DEFAULT v-sync mode.
*/
public ExtendedBufferCapabilities(ImageCapabilities front,
ImageCapabilities back, FlipContents flip)
{
super(front, back, flip);
this.vsync = VSyncType.VSYNC_DEFAULT;
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the passed image/flip caps, and the v-sync type.
*/
public ExtendedBufferCapabilities(ImageCapabilities front,
ImageCapabilities back, FlipContents flip,
VSyncType t)
{
super(front, back, flip);
this.vsync = t;
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the passed cap, and the passed v-sync mode.
*/
public ExtendedBufferCapabilities(BufferCapabilities caps, VSyncType t) {
super(caps.getFrontBufferCapabilities(),
caps.getBackBufferCapabilities(),
caps.getFlipContents());
this.vsync = t;
}
/**
* Creates an ExtendedBufferCapabilities instance with front/back/flip caps
* from the object, and passed v-sync mode.
*/
public ExtendedBufferCapabilities derive(VSyncType t) {
return new ExtendedBufferCapabilities(this, t);
}
/**
* Returns the type of v-sync requested by this capabilities instance.
*/
public VSyncType getVSync() {
return vsync;
}
@Override
public final boolean isPageFlipping() {
return true;
}
}