Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/opengl/CGLSurfaceData.java
41159 views
/*1* Copyright (c) 2011, 2019, 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.Image;29import java.awt.Rectangle;30import java.awt.image.ColorModel;3132import sun.java2d.SurfaceData;3334public abstract class CGLSurfaceData extends OGLSurfaceData {3536private final int scale;37final int width;38final int height;39private final CGLGraphicsConfig graphicsConfig;4041private native void initOps(OGLGraphicsConfig gc, long pConfigInfo,42long pPeerData, long layerPtr, int xoff,43int yoff, boolean isOpaque);4445private CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,46ColorModel cm, int type, int width, int height) {47super(gc, cm, type);48// TEXTURE shouldn't be scaled, it is used for managed BufferedImages.49scale = type == TEXTURE ? 1 : gc.getDevice().getScaleFactor();50this.width = width * scale;51this.height = height * scale;52this.graphicsConfig = gc;5354long layerPtr = 0L;55boolean isOpaque = true;56if (layer != null) {57layerPtr = layer.getPointer();58isOpaque = layer.isOpaque();59}60// TODO delete the native code: pPeerData, xoff, yoff are always zero61initOps(gc, gc.getNativeConfigInfo(), 0, layerPtr, 0, 0, isOpaque);62}6364@Override //SurfaceData65public GraphicsConfiguration getDeviceConfiguration() {66return graphicsConfig;67}6869/**70* Creates a SurfaceData object representing the intermediate buffer71* between the Java2D flusher thread and the AppKit thread.72*/73public static CGLLayerSurfaceData createData(CGLLayer layer) {74CGLGraphicsConfig gc = (CGLGraphicsConfig) layer.getGraphicsConfiguration();75Rectangle r = layer.getBounds();76return new CGLLayerSurfaceData(layer, gc, r.width, r.height);77}7879/**80* Creates a SurfaceData object representing an off-screen buffer (either a81* FBO or Texture).82*/83public static CGLOffScreenSurfaceData createData(CGLGraphicsConfig gc,84int width, int height, ColorModel cm, Image image, int type) {85return new CGLOffScreenSurfaceData(gc, width, height, image, cm, type);86}8788@Override89public double getDefaultScaleX() {90return scale;91}9293@Override94public double getDefaultScaleY() {95return scale;96}9798@Override99public Rectangle getBounds() {100return new Rectangle(width, height);101}102103protected native void clearWindow();104105/**106* A surface which implements an intermediate buffer between107* the Java2D flusher thread and the AppKit thread.108*109* This surface serves as a buffer attached to a CGLLayer and110* the layer redirects all painting to the buffer's graphics.111*/112public static class CGLLayerSurfaceData extends CGLSurfaceData {113114private final CGLLayer layer;115116private CGLLayerSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,117int width, int height) {118super(layer, gc, gc.getColorModel(), FBOBJECT, width, height);119this.layer = layer;120initSurface(this.width, this.height);121}122123@Override124public SurfaceData getReplacement() {125return layer.getSurfaceData();126}127128@Override129boolean isOnScreen() {130return true;131}132133@Override134public Object getDestination() {135return layer.getDestination();136}137138@Override139public int getTransparency() {140return layer.getTransparency();141}142143@Override144public void invalidate() {145super.invalidate();146clearWindow();147}148}149150/**151* SurfaceData object representing an off-screen buffer (either a FBO or152* Texture).153*/154public static class CGLOffScreenSurfaceData extends CGLSurfaceData {155156private final Image offscreenImage;157158private CGLOffScreenSurfaceData(CGLGraphicsConfig gc, int width,159int height, Image image,160ColorModel cm, int type) {161super(null, gc, cm, type, width, height);162offscreenImage = image;163initSurface(this.width, this.height);164}165166@Override167public SurfaceData getReplacement() {168return restoreContents(offscreenImage);169}170171/**172* Returns destination Image associated with this SurfaceData.173*/174@Override175public Object getDestination() {176return offscreenImage;177}178}179}180181182