Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLVolatileSurfaceManager.java
41159 views
/*1* Copyright (c) 2021, 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.metal;2627import sun.awt.image.SunVolatileImage;28import sun.awt.image.VolatileSurfaceManager;29import sun.java2d.SurfaceData;3031import java.awt.GraphicsConfiguration;32import java.awt.Transparency;33import java.awt.image.ColorModel;34import sun.java2d.pipe.hw.AccelSurface;3536public class MTLVolatileSurfaceManager extends VolatileSurfaceManager {3738private final boolean accelerationEnabled;3940public MTLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {41super(vImg, context);4243/*44* We will attempt to accelerate this image only45* if the image is not bitmask46*/47int transparency = vImg.getTransparency();48accelerationEnabled = transparency != Transparency.BITMASK;49}5051protected boolean isAccelerationEnabled() {52return accelerationEnabled;53}5455/**56* Create a SurfaceData object (or init the backbuffer57* of an existing window if this is a double buffered GraphicsConfig)58*/59protected SurfaceData initAcceleratedSurface() {60try {61MTLGraphicsConfig gc =62(MTLGraphicsConfig)vImg.getGraphicsConfig();63ColorModel cm = gc.getColorModel(vImg.getTransparency());64int type = vImg.getForcedAccelSurfaceType();65// if acceleration type is forced (type != UNDEFINED) then66// use the forced type, otherwise choose RT_TEXTURE67if (type == AccelSurface.UNDEFINED) {68type = AccelSurface.RT_TEXTURE;69}70return MTLSurfaceData.createData(gc,71vImg.getWidth(),72vImg.getHeight(),73cm, vImg, type);74} catch (NullPointerException | OutOfMemoryError ignored) {75return null;76}77}7879@Override80protected boolean isConfigValid(GraphicsConfiguration gc) {81return ((gc == null) || (gc == vImg.getGraphicsConfig()));82}8384@Override85public void initContents() {86if (vImg.getForcedAccelSurfaceType() != AccelSurface.TEXTURE) {87super.initContents();88}89}90}919293