0N/A/*
2362N/A * Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.opengl;
0N/A
0N/Aimport java.awt.Component;
0N/Aimport java.awt.GraphicsConfiguration;
0N/Aimport java.awt.GraphicsDevice;
0N/Aimport java.awt.GraphicsEnvironment;
0N/Aimport java.awt.Image;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.image.ColorModel;
430N/Aimport sun.awt.SunToolkit;
0N/Aimport sun.awt.windows.WComponentPeer;
0N/Aimport sun.java2d.SurfaceData;
0N/A
0N/Apublic abstract class WGLSurfaceData extends OGLSurfaceData {
0N/A
0N/A protected WComponentPeer peer;
0N/A private WGLGraphicsConfig graphicsConfig;
0N/A
430N/A private native void initOps(long pConfigInfo, WComponentPeer peer,
430N/A long hwnd);
0N/A protected native boolean initPbuffer(long pData, long pConfigInfo,
0N/A boolean isOpaque,
0N/A int width, int height);
0N/A
0N/A protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,
0N/A ColorModel cm, int type)
0N/A {
0N/A super(gc, cm, type);
0N/A this.peer = peer;
0N/A this.graphicsConfig = gc;
0N/A
0N/A long pConfigInfo = gc.getNativeConfigInfo();
430N/A long hwnd = peer != null ? peer.getHWnd() : 0L;
0N/A
430N/A initOps(pConfigInfo, peer, hwnd);
0N/A }
0N/A
0N/A public GraphicsConfiguration getDeviceConfiguration() {
0N/A return graphicsConfig;
0N/A }
0N/A
0N/A /**
0N/A * Creates a SurfaceData object representing the primary (front) buffer
0N/A * of an on-screen Window.
0N/A */
0N/A public static WGLWindowSurfaceData createData(WComponentPeer peer) {
430N/A // the OGL pipeline can render directly to the screen and interfere
430N/A // with layered windows, which is why we don't allow accelerated
430N/A // surfaces in this case
1045N/A if (!peer.isAccelCapable() ||
1045N/A !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
430N/A {
430N/A return null;
430N/A }
0N/A WGLGraphicsConfig gc = getGC(peer);
0N/A return new WGLWindowSurfaceData(peer, gc);
0N/A }
0N/A
0N/A /**
0N/A * Creates a SurfaceData object representing the back buffer of a
0N/A * double-buffered on-screen Window.
0N/A */
0N/A public static WGLOffScreenSurfaceData createData(WComponentPeer peer,
430N/A Image image,
430N/A int type)
0N/A {
430N/A // the OGL pipeline can render directly to the screen and interfere
430N/A // with layered windows, which is why we don't allow accelerated
430N/A // surfaces in this case
1045N/A if (!peer.isAccelCapable() ||
1045N/A !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
430N/A {
430N/A return null;
430N/A }
0N/A WGLGraphicsConfig gc = getGC(peer);
0N/A Rectangle r = peer.getBounds();
430N/A if (type == FLIP_BACKBUFFER) {
430N/A return new WGLOffScreenSurfaceData(peer, gc, r.width, r.height,
430N/A image, peer.getColorModel(),
430N/A type);
430N/A } else {
430N/A return new WGLVSyncOffScreenSurfaceData(peer, gc, r.width, r.height,
430N/A image, peer.getColorModel(),
430N/A type);
430N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a SurfaceData object representing an off-screen buffer (either
0N/A * a Pbuffer or Texture).
0N/A */
0N/A public static WGLOffScreenSurfaceData createData(WGLGraphicsConfig gc,
0N/A int width, int height,
0N/A ColorModel cm,
0N/A Image image, int type)
0N/A {
0N/A return new WGLOffScreenSurfaceData(null, gc, width, height,
0N/A image, cm, type);
0N/A }
0N/A
0N/A public static WGLGraphicsConfig getGC(WComponentPeer peer) {
0N/A if (peer != null) {
0N/A return (WGLGraphicsConfig)peer.getGraphicsConfiguration();
0N/A } else {
0N/A // REMIND: this should rarely (never?) happen, but what if
0N/A // default config is not WGL?
0N/A GraphicsEnvironment env =
0N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
0N/A GraphicsDevice gd = env.getDefaultScreenDevice();
0N/A return (WGLGraphicsConfig)gd.getDefaultConfiguration();
0N/A }
0N/A }
0N/A
0N/A public static class WGLWindowSurfaceData extends WGLSurfaceData {
0N/A
0N/A public WGLWindowSurfaceData(WComponentPeer peer,
0N/A WGLGraphicsConfig gc)
0N/A {
0N/A super(peer, gc, peer.getColorModel(), WINDOW);
0N/A }
0N/A
0N/A public SurfaceData getReplacement() {
0N/A return peer.getSurfaceData();
0N/A }
0N/A
0N/A public Rectangle getBounds() {
0N/A Rectangle r = peer.getBounds();
0N/A r.x = r.y = 0;
0N/A return r;
0N/A }
0N/A
0N/A /**
0N/A * Returns destination Component associated with this SurfaceData.
0N/A */
0N/A public Object getDestination() {
0N/A return peer.getTarget();
0N/A }
0N/A }
0N/A
430N/A /**
430N/A * A surface which implements a v-synced flip back-buffer with COPIED
430N/A * FlipContents.
430N/A *
430N/A * This surface serves as a back-buffer to the outside world, while
430N/A * it is actually an offscreen surface. When the BufferStrategy this surface
430N/A * belongs to is showed, it is first copied to the real private
430N/A * FLIP_BACKBUFFER, which is then flipped.
430N/A */
430N/A public static class WGLVSyncOffScreenSurfaceData extends
430N/A WGLOffScreenSurfaceData
430N/A {
430N/A private WGLOffScreenSurfaceData flipSurface;
430N/A
430N/A public WGLVSyncOffScreenSurfaceData(WComponentPeer peer,
430N/A WGLGraphicsConfig gc,
430N/A int width, int height,
430N/A Image image, ColorModel cm,
430N/A int type)
430N/A {
430N/A super(peer, gc, width, height, image, cm, type);
430N/A flipSurface = WGLSurfaceData.createData(peer, image, FLIP_BACKBUFFER);
430N/A }
430N/A
430N/A public SurfaceData getFlipSurface() {
430N/A return flipSurface;
430N/A }
430N/A
430N/A @Override
430N/A public void flush() {
430N/A flipSurface.flush();
430N/A super.flush();
430N/A }
430N/A
430N/A }
430N/A
0N/A public static class WGLOffScreenSurfaceData extends WGLSurfaceData {
0N/A
0N/A private Image offscreenImage;
0N/A private int width, height;
0N/A
0N/A public WGLOffScreenSurfaceData(WComponentPeer peer,
0N/A WGLGraphicsConfig gc,
0N/A int width, int height,
0N/A Image image, ColorModel cm,
0N/A int type)
0N/A {
0N/A super(peer, gc, cm, type);
0N/A
0N/A this.width = width;
0N/A this.height = height;
0N/A offscreenImage = image;
0N/A
0N/A initSurface(width, height);
0N/A }
0N/A
0N/A public SurfaceData getReplacement() {
0N/A return restoreContents(offscreenImage);
0N/A }
0N/A
0N/A public Rectangle getBounds() {
0N/A if (type == FLIP_BACKBUFFER) {
0N/A Rectangle r = peer.getBounds();
0N/A r.x = r.y = 0;
0N/A return r;
0N/A } else {
0N/A return new Rectangle(width, height);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns destination Image associated with this SurfaceData.
0N/A */
0N/A public Object getDestination() {
0N/A return offscreenImage;
0N/A }
0N/A }
430N/A
430N/A /**
430N/A * Updates the layered window with the contents of the surface.
430N/A *
430N/A * @param psdops pointer to the native ogl sd structure
430N/A * @param pData pointer to the AwtWindow peer data
430N/A * @param w width of the window
430N/A * @param h height of the window
430N/A * @see sun.awt.windows.TranslucentWindowPainter
430N/A */
430N/A public static native boolean updateWindowAccelImpl(long psdops,
430N/A WComponentPeer peer,
430N/A int w, int h);
0N/A}