Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/sun/java2d/opengl/CGLLayer.java
38918 views
/*1* Copyright (c) 2011, 2013, 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 sun.lwawt.macosx.CFRetainedResource;28import sun.lwawt.LWWindowPeer;2930import sun.java2d.SurfaceData;31import sun.java2d.NullSurfaceData;3233import sun.awt.CGraphicsConfig;3435import java.awt.Rectangle;36import java.awt.GraphicsConfiguration;37import java.awt.Transparency;3839public class CGLLayer extends CFRetainedResource {4041private native long nativeCreateLayer();42private static native void nativeSetScale(long layerPtr, double scale);43private static native void validate(long layerPtr, CGLSurfaceData cglsd);44private static native void blitTexture(long layerPtr);4546private LWWindowPeer peer;47private int scale = 1;4849private SurfaceData surfaceData; // represents intermediate buffer (texture)5051public CGLLayer(LWWindowPeer peer) {52super(0, true);5354setPtr(nativeCreateLayer());55this.peer = peer;56}5758public long getPointer() {59return ptr;60}6162public Rectangle getBounds() {63return peer.getBounds();64}6566public GraphicsConfiguration getGraphicsConfiguration() {67return peer.getGraphicsConfiguration();68}6970public boolean isOpaque() {71return !peer.isTranslucent();72}7374public int getTransparency() {75return isOpaque() ? Transparency.OPAQUE : Transparency.TRANSLUCENT;76}7778public Object getDestination() {79return peer;80}8182public SurfaceData replaceSurfaceData() {83if (getBounds().isEmpty()) {84surfaceData = NullSurfaceData.theInstance;85return surfaceData;86}8788// the layer redirects all painting to the buffer's graphics89// and blits the buffer to the layer surface (in drawInCGLContext callback)90CGraphicsConfig gc = (CGraphicsConfig)getGraphicsConfiguration();91surfaceData = gc.createSurfaceData(this);92setScale(gc.getDevice().getScaleFactor());93// the layer holds a reference to the buffer, which in94// turn has a reference back to this layer95if (surfaceData instanceof CGLSurfaceData) {96validate((CGLSurfaceData)surfaceData);97}9899return surfaceData;100}101102public SurfaceData getSurfaceData() {103return surfaceData;104}105106public void validate(final CGLSurfaceData cglsd) {107OGLRenderQueue rq = OGLRenderQueue.getInstance();108rq.lock();109try {110execute(ptr -> validate(ptr, cglsd));111} finally {112rq.unlock();113}114}115116@Override117public void dispose() {118// break the connection between the layer and the buffer119validate(null);120super.dispose();121}122123private void setScale(final int _scale) {124if (scale != _scale) {125scale = _scale;126execute(ptr -> nativeSetScale(ptr, scale));127}128}129130// ----------------------------------------------------------------------131// NATIVE CALLBACKS132// ----------------------------------------------------------------------133134private void drawInCGLContext() {135// tell the flusher thread not to update the intermediate buffer136// until we are done blitting from it137OGLRenderQueue rq = OGLRenderQueue.getInstance();138rq.lock();139try {140execute(ptr -> blitTexture(ptr));141} finally {142rq.unlock();143}144}145}146147148