Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/opengl/GLXSurfaceData.java
32288 views
/*1* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.opengl;2627import java.awt.GraphicsConfiguration;28import java.awt.GraphicsDevice;29import java.awt.GraphicsEnvironment;30import java.awt.Image;31import java.awt.Rectangle;32import java.awt.Transparency;33import java.awt.image.ColorModel;34import sun.awt.X11ComponentPeer;35import sun.java2d.SurfaceData;36import sun.java2d.loops.SurfaceType;3738public abstract class GLXSurfaceData extends OGLSurfaceData {3940protected X11ComponentPeer peer;41private GLXGraphicsConfig graphicsConfig;4243private native void initOps(OGLGraphicsConfig gc, X11ComponentPeer peer,44long aData);45protected native boolean initPbuffer(long pData, long pConfigInfo,46boolean isOpaque,47int width, int height);4849protected GLXSurfaceData(X11ComponentPeer peer, GLXGraphicsConfig gc,50ColorModel cm, int type)51{52super(gc, cm, type);53this.peer = peer;54this.graphicsConfig = gc;55initOps(gc, peer, graphicsConfig.getAData());56}5758public GraphicsConfiguration getDeviceConfiguration() {59return graphicsConfig;60}6162/**63* Creates a SurfaceData object representing the primary (front) buffer64* of an on-screen Window.65*/66public static GLXWindowSurfaceData createData(X11ComponentPeer peer) {67GLXGraphicsConfig gc = getGC(peer);68return new GLXWindowSurfaceData(peer, gc);69}7071/**72* Creates a SurfaceData object representing the back buffer of a73* double-buffered on-screen Window.74*/75public static GLXOffScreenSurfaceData createData(X11ComponentPeer peer,76Image image,77int type)78{79GLXGraphicsConfig gc = getGC(peer);80Rectangle r = peer.getBounds();81if (type == FLIP_BACKBUFFER) {82return new GLXOffScreenSurfaceData(peer, gc, r.width, r.height,83image, peer.getColorModel(),84FLIP_BACKBUFFER);85} else {86return new GLXVSyncOffScreenSurfaceData(peer, gc, r.width, r.height,87image, peer.getColorModel(),88type);89}90}9192/**93* Creates a SurfaceData object representing an off-screen buffer (either94* a Pbuffer or Texture).95*/96public static GLXOffScreenSurfaceData createData(GLXGraphicsConfig gc,97int width, int height,98ColorModel cm,99Image image, int type)100{101return new GLXOffScreenSurfaceData(null, gc, width, height,102image, cm, type);103}104105public static GLXGraphicsConfig getGC(X11ComponentPeer peer) {106if (peer != null) {107return (GLXGraphicsConfig)peer.getGraphicsConfiguration();108} else {109// REMIND: this should rarely (never?) happen, but what if110// default config is not GLX?111GraphicsEnvironment env =112GraphicsEnvironment.getLocalGraphicsEnvironment();113GraphicsDevice gd = env.getDefaultScreenDevice();114return (GLXGraphicsConfig)gd.getDefaultConfiguration();115}116}117118public static class GLXWindowSurfaceData extends GLXSurfaceData {119120public GLXWindowSurfaceData(X11ComponentPeer peer,121GLXGraphicsConfig gc)122{123super(peer, gc, peer.getColorModel(), WINDOW);124}125126public SurfaceData getReplacement() {127return peer.getSurfaceData();128}129130public Rectangle getBounds() {131Rectangle r = peer.getBounds();132r.x = r.y = 0;133return r;134}135136/**137* Returns destination Component associated with this SurfaceData.138*/139public Object getDestination() {140return peer.getTarget();141}142}143144/**145* A surface which implements a v-synced flip back-buffer with COPIED146* FlipContents.147*148* This surface serves as a back-buffer to the outside world, while149* it is actually an offscreen surface. When the BufferStrategy this surface150* belongs to is showed, it is first copied to the real private151* FLIP_BACKBUFFER, which is then flipped.152*/153public static class GLXVSyncOffScreenSurfaceData extends154GLXOffScreenSurfaceData155{156private GLXOffScreenSurfaceData flipSurface;157158public GLXVSyncOffScreenSurfaceData(X11ComponentPeer peer,159GLXGraphicsConfig gc,160int width, int height,161Image image, ColorModel cm,162int type)163{164super(peer, gc, width, height, image, cm, type);165flipSurface = GLXSurfaceData.createData(peer, image, FLIP_BACKBUFFER);166}167168public SurfaceData getFlipSurface() {169return flipSurface;170}171172@Override173public void flush() {174flipSurface.flush();175super.flush();176}177178}179180public static class GLXOffScreenSurfaceData extends GLXSurfaceData {181182private Image offscreenImage;183private int width, height;184185public GLXOffScreenSurfaceData(X11ComponentPeer peer,186GLXGraphicsConfig gc,187int width, int height,188Image image, ColorModel cm,189int type)190{191super(peer, gc, cm, type);192193this.width = width;194this.height = height;195offscreenImage = image;196197initSurface(width, height);198}199200public SurfaceData getReplacement() {201return restoreContents(offscreenImage);202}203204public Rectangle getBounds() {205if (type == FLIP_BACKBUFFER) {206Rectangle r = peer.getBounds();207r.x = r.y = 0;208return r;209} else {210return new Rectangle(width, height);211}212}213214/**215* Returns destination Image associated with this SurfaceData.216*/217public Object getDestination() {218return offscreenImage;219}220}221}222223224