Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/opengl/WGLSurfaceData.java
32288 views
/*1* Copyright (c) 2004, 2009, 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.Component;28import java.awt.GraphicsConfiguration;29import java.awt.GraphicsDevice;30import java.awt.GraphicsEnvironment;31import java.awt.Image;32import java.awt.Rectangle;33import java.awt.image.ColorModel;34import sun.awt.SunToolkit;35import sun.awt.windows.WComponentPeer;36import sun.java2d.SurfaceData;3738public abstract class WGLSurfaceData extends OGLSurfaceData {3940protected WComponentPeer peer;41private WGLGraphicsConfig graphicsConfig;4243private native void initOps(OGLGraphicsConfig gc, long pConfigInfo,44WComponentPeer peer, long hwnd);45protected native boolean initPbuffer(long pData, long pConfigInfo,46boolean isOpaque,47int width, int height);4849protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,50ColorModel cm, int type)51{52super(gc, cm, type);53this.peer = peer;54this.graphicsConfig = gc;5556long pConfigInfo = gc.getNativeConfigInfo();57long hwnd = peer != null ? peer.getHWnd() : 0L;5859initOps(gc, pConfigInfo, peer, hwnd);60}6162public GraphicsConfiguration getDeviceConfiguration() {63return graphicsConfig;64}6566/**67* Creates a SurfaceData object representing the primary (front) buffer68* of an on-screen Window.69*/70public static WGLWindowSurfaceData createData(WComponentPeer peer) {71// the OGL pipeline can render directly to the screen and interfere72// with layered windows, which is why we don't allow accelerated73// surfaces in this case74if (!peer.isAccelCapable() ||75!SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))76{77return null;78}79WGLGraphicsConfig gc = getGC(peer);80return new WGLWindowSurfaceData(peer, gc);81}8283/**84* Creates a SurfaceData object representing the back buffer of a85* double-buffered on-screen Window.86*/87public static WGLOffScreenSurfaceData createData(WComponentPeer peer,88Image image,89int type)90{91// the OGL pipeline can render directly to the screen and interfere92// with layered windows, which is why we don't allow accelerated93// surfaces in this case94if (!peer.isAccelCapable() ||95!SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))96{97return null;98}99WGLGraphicsConfig gc = getGC(peer);100Rectangle r = peer.getBounds();101if (type == FLIP_BACKBUFFER) {102return new WGLOffScreenSurfaceData(peer, gc, r.width, r.height,103image, peer.getColorModel(),104type);105} else {106return new WGLVSyncOffScreenSurfaceData(peer, gc, r.width, r.height,107image, peer.getColorModel(),108type);109}110}111112/**113* Creates a SurfaceData object representing an off-screen buffer (either114* a Pbuffer or Texture).115*/116public static WGLOffScreenSurfaceData createData(WGLGraphicsConfig gc,117int width, int height,118ColorModel cm,119Image image, int type)120{121return new WGLOffScreenSurfaceData(null, gc, width, height,122image, cm, type);123}124125public static WGLGraphicsConfig getGC(WComponentPeer peer) {126if (peer != null) {127return (WGLGraphicsConfig)peer.getGraphicsConfiguration();128} else {129// REMIND: this should rarely (never?) happen, but what if130// default config is not WGL?131GraphicsEnvironment env =132GraphicsEnvironment.getLocalGraphicsEnvironment();133GraphicsDevice gd = env.getDefaultScreenDevice();134return (WGLGraphicsConfig)gd.getDefaultConfiguration();135}136}137138public static class WGLWindowSurfaceData extends WGLSurfaceData {139140public WGLWindowSurfaceData(WComponentPeer peer,141WGLGraphicsConfig gc)142{143super(peer, gc, peer.getColorModel(), WINDOW);144}145146public SurfaceData getReplacement() {147return peer.getSurfaceData();148}149150public Rectangle getBounds() {151Rectangle r = peer.getBounds();152r.x = r.y = 0;153return r;154}155156/**157* Returns destination Component associated with this SurfaceData.158*/159public Object getDestination() {160return peer.getTarget();161}162}163164/**165* A surface which implements a v-synced flip back-buffer with COPIED166* FlipContents.167*168* This surface serves as a back-buffer to the outside world, while169* it is actually an offscreen surface. When the BufferStrategy this surface170* belongs to is showed, it is first copied to the real private171* FLIP_BACKBUFFER, which is then flipped.172*/173public static class WGLVSyncOffScreenSurfaceData extends174WGLOffScreenSurfaceData175{176private WGLOffScreenSurfaceData flipSurface;177178public WGLVSyncOffScreenSurfaceData(WComponentPeer peer,179WGLGraphicsConfig gc,180int width, int height,181Image image, ColorModel cm,182int type)183{184super(peer, gc, width, height, image, cm, type);185flipSurface = WGLSurfaceData.createData(peer, image, FLIP_BACKBUFFER);186}187188public SurfaceData getFlipSurface() {189return flipSurface;190}191192@Override193public void flush() {194flipSurface.flush();195super.flush();196}197198}199200public static class WGLOffScreenSurfaceData extends WGLSurfaceData {201202private Image offscreenImage;203private int width, height;204205public WGLOffScreenSurfaceData(WComponentPeer peer,206WGLGraphicsConfig gc,207int width, int height,208Image image, ColorModel cm,209int type)210{211super(peer, gc, cm, type);212213this.width = width;214this.height = height;215offscreenImage = image;216217initSurface(width, height);218}219220public SurfaceData getReplacement() {221return restoreContents(offscreenImage);222}223224public Rectangle getBounds() {225if (type == FLIP_BACKBUFFER) {226Rectangle r = peer.getBounds();227r.x = r.y = 0;228return r;229} else {230return new Rectangle(width, height);231}232}233234/**235* Returns destination Image associated with this SurfaceData.236*/237public Object getDestination() {238return offscreenImage;239}240}241242/**243* Updates the layered window with the contents of the surface.244*245* @param psdops pointer to the native ogl sd structure246* @param pData pointer to the AwtWindow peer data247* @param w width of the window248* @param h height of the window249* @see sun.awt.windows.TranslucentWindowPainter250*/251public static native boolean updateWindowAccelImpl(long psdops,252WComponentPeer peer,253int w, int h);254}255256257