Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLContext.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.pipe.BufferedContext;28import sun.java2d.pipe.RenderBuffer;29import sun.java2d.pipe.RenderQueue;30import sun.java2d.pipe.hw.ContextCapabilities;3132import java.lang.annotation.Native;3334import static sun.java2d.pipe.BufferedOpCodes.SET_SCRATCH_SURFACE;3536/**37* Note that the RenderQueue lock must be acquired before calling any of38* the methods in this class.39*/40final class MTLContext extends BufferedContext {4142public MTLContext(RenderQueue rq) {43super(rq);44}4546/**47* Convenience method that delegates to setScratchSurface() below.48*/49static void setScratchSurface(MTLGraphicsConfig gc) {50setScratchSurface(gc.getNativeConfigInfo());51}5253/**54* Makes the given GraphicsConfig's context current to its associated55* "scratch surface". Each GraphicsConfig maintains a native context56* (MTLDevice) as well as a native MTLTexture57* known as the "scratch surface". By making the context current to the58* scratch surface, we are assured that we have a current context for59* the relevant GraphicsConfig, and can therefore perform operations60* depending on the capabilities of that GraphicsConfig.61* This method should be used for operations with an MTL texture62* as the destination surface (e.g. a sw->texture blit loop), or in those63* situations where we may not otherwise have a current context (e.g.64* when disposing a texture-based surface).65*/66public static void setScratchSurface(long pConfigInfo) {67// assert MTLRenderQueue.getInstance().lock.isHeldByCurrentThread();6869// invalidate the current context70currentContext = null;7172// set the scratch context73MTLRenderQueue rq = MTLRenderQueue.getInstance();74RenderBuffer buf = rq.getBuffer();75rq.ensureCapacityAndAlignment(12, 4);76buf.putInt(SET_SCRATCH_SURFACE);77buf.putLong(pConfigInfo);78}7980public static class MTLContextCaps extends ContextCapabilities {8182/** Indicates that the context is doublebuffered. */83@Native84public static final int CAPS_DOUBLEBUFFERED = (FIRST_PRIVATE_CAP << 0);85/**86* This cap will only be set if the lcdshader system property has been87* enabled and the hardware supports the minimum number of texture units88*/89@Native90static final int CAPS_EXT_LCD_SHADER = (FIRST_PRIVATE_CAP << 1);91/**92* This cap will only be set if the biopshader system property has been93* enabled and the hardware meets our minimum requirements.94*/95@Native96public static final int CAPS_EXT_BIOP_SHADER = (FIRST_PRIVATE_CAP << 2);97/**98* This cap will only be set if the gradshader system property has been99* enabled and the hardware meets our minimum requirements.100*/101@Native102static final int CAPS_EXT_GRAD_SHADER = (FIRST_PRIVATE_CAP << 3);103104public MTLContextCaps(int caps, String adapterId) {105super(caps, adapterId);106}107108@Override109public String toString() {110StringBuilder sb = new StringBuilder(super.toString());111if ((caps & CAPS_DOUBLEBUFFERED) != 0) {112sb.append("CAPS_DOUBLEBUFFERED|");113}114if ((caps & CAPS_EXT_LCD_SHADER) != 0) {115sb.append("CAPS_EXT_LCD_SHADER|");116}117if ((caps & CAPS_EXT_BIOP_SHADER) != 0) {118sb.append("CAPS_BIOP_SHADER|");119}120if ((caps & CAPS_EXT_GRAD_SHADER) != 0) {121sb.append("CAPS_EXT_GRAD_SHADER|");122}123return sb.toString();124}125}126}127128129