Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLSurfaceDataProxy.java
41159 views
/*1* Copyright (c) 2019, 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.java2d.SurfaceData;28import sun.java2d.SurfaceDataProxy;29import sun.java2d.loops.CompositeType;3031import java.awt.Color;32import java.awt.Transparency;3334/**35* The proxy class contains the logic for when to replace a36* SurfaceData with a cached MTL Texture and the code to create37* the accelerated surfaces.38*/39public class MTLSurfaceDataProxy extends SurfaceDataProxy {40public static SurfaceDataProxy createProxy(SurfaceData srcData,41MTLGraphicsConfig dstConfig)42{43if (srcData instanceof MTLSurfaceData) {44// srcData must be a VolatileImage which either matches45// our pixel format or not - either way we do not cache it...46return UNCACHED;47}4849return new MTLSurfaceDataProxy(dstConfig, srcData.getTransparency());50}5152MTLGraphicsConfig mtlgc;53int transparency;5455public MTLSurfaceDataProxy(MTLGraphicsConfig mtlgc, int transparency) {56this.mtlgc = mtlgc;57this.transparency = transparency;58}5960@Override61public SurfaceData validateSurfaceData(SurfaceData srcData,62SurfaceData cachedData,63int w, int h)64{65if (cachedData == null) {66try {67cachedData = mtlgc.createManagedSurface(w, h, transparency);68} catch (OutOfMemoryError er) {69return null;70}71}72return cachedData;73}7475@Override76public boolean isSupportedOperation(SurfaceData srcData,77int txtype,78CompositeType comp,79Color bgColor)80{81return comp.isDerivedFrom(CompositeType.AnyAlpha) &&82(bgColor == null || transparency == Transparency.OPAQUE);83}84}858687