src/java.desktop/macosx/classes/sun/java2d/metal/MTLContext.java
author jdv
Fri, 21 Jun 2019 12:08:37 +0530
branchmetal-prototype-branch
changeset 57416 e153174dba06
permissions -rw-r--r--
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch Reviewed-by: avu, prr, kcr Contributed-by: avu(Jetbrains), aghaisas, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     1
/*
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     4
 *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    10
 *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    15
 * accompanied this code).
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    16
 *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    20
 *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    23
 * questions.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    24
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    25
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    26
package sun.java2d.metal;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    27
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    28
import sun.java2d.pipe.BufferedContext;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    29
import sun.java2d.pipe.RenderBuffer;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    30
import sun.java2d.pipe.RenderQueue;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    31
import sun.java2d.pipe.hw.ContextCapabilities;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    32
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    33
import java.lang.annotation.Native;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    34
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    35
import static sun.java2d.pipe.BufferedOpCodes.*;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    36
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    37
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    38
 * Note that the RenderQueue lock must be acquired before calling any of
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    39
 * the methods in this class.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    40
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    41
public class MTLContext extends BufferedContext {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    42
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    43
    private final MTLGraphicsConfig config;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    44
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    45
    public MTLContext(RenderQueue rq, MTLGraphicsConfig config) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    46
        super(rq);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    47
        this.config = config;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    48
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    49
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    50
    /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    51
     * Convenience method that delegates to setScratchSurface() below.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    52
     */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    53
    static void setScratchSurface(MTLGraphicsConfig gc) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    54
        setScratchSurface(gc.getNativeConfigInfo());
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    55
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    56
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    57
    /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    58
     * Makes the given GraphicsConfig's context current to its associated
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    59
     * "scratch surface".  Each GraphicsConfig maintains a native context
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    60
     * (MTLDevice) as well as a native pbuffer
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    61
     * known as the "scratch surface".  By making the context current to the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    62
     * scratch surface, we are assured that we have a current context for
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    63
     * the relevant GraphicsConfig, and can therefore perform operations
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    64
     * depending on the capabilities of that GraphicsConfig.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    65
     * This method should be used for operations with an MTL texture
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    66
     * as the destination surface (e.g. a sw->texture blit loop), or in those
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    67
     * situations where we may not otherwise have a current context (e.g.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    68
     * when disposing a texture-based surface).
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    69
     */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    70
    public static void setScratchSurface(long pConfigInfo) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    71
        // assert MTLRenderQueue.getInstance().lock.isHeldByCurrentThread();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    72
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    73
        // invalidate the current context
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    74
        currentContext = null;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    75
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    76
        // set the scratch context
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    77
        MTLRenderQueue rq = MTLRenderQueue.getInstance();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    78
        RenderBuffer buf = rq.getBuffer();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    79
        rq.ensureCapacityAndAlignment(12, 4);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    80
        buf.putInt(SET_SCRATCH_SURFACE);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    81
        buf.putLong(pConfigInfo);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    82
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    83
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    84
    /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    85
     * Invalidates the currentContext field to ensure that we properly
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    86
     * revalidate the MTLContext (make it current, etc.) next time through
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    87
     * the validate() method.  This is typically invoked from methods
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    88
     * that affect the current context state (e.g. disposing a context or
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    89
     * surface).
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    90
     */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    91
    public static void invalidateCurrentContext() {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    92
        // assert MTLRenderQueue.getInstance().lock.isHeldByCurrentThread();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    93
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    94
        // invalidate the current Java-level context so that we
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    95
        // revalidate everything the next time around
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    96
        if (currentContext != null) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    97
            currentContext.invalidateContext();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    98
            currentContext = null;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    99
        }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   100
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   101
        // invalidate the context reference at the native level, and
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   102
        // then flush the queue so that we have no pending operations
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   103
        // dependent on the current context
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   104
        MTLRenderQueue rq = MTLRenderQueue.getInstance();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   105
        rq.ensureCapacity(4);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   106
        rq.getBuffer().putInt(INVALIDATE_CONTEXT);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   107
        rq.flushNow();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   108
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   109
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   110
    public RenderQueue getRenderQueue() {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   111
        return MTLRenderQueue.getInstance();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   112
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   113
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   114
    /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   115
     * Returns a string representing adapter id (vendor, renderer, version).
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   116
     * Must be called on the rendering thread.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   117
     *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   118
     * @return an id string for the adapter
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   119
     */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   120
    public static final native String getMTLIdString();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   121
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   122
    @Override
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   123
    public void saveState() {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   124
        // assert rq.lock.isHeldByCurrentThread();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   125
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   126
        // reset all attributes of this and current contexts
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   127
        invalidateContext();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   128
        invalidateCurrentContext();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   129
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   130
        setScratchSurface(config);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   131
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   132
        // save the state on the native level
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   133
        rq.ensureCapacity(4);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   134
        buf.putInt(SAVE_STATE);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   135
        rq.flushNow();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   136
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   137
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   138
    @Override
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   139
    public void restoreState() {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   140
        // assert rq.lock.isHeldByCurrentThread();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   141
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   142
        // reset all attributes of this and current contexts
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   143
        invalidateContext();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   144
        invalidateCurrentContext();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   145
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   146
        setScratchSurface(config);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   147
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   148
        // restore the state on the native level
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   149
        rq.ensureCapacity(4);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   150
        buf.putInt(RESTORE_STATE);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   151
        rq.flushNow();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   152
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   153
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   154
    public static class MTLContextCaps extends ContextCapabilities {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   155
        /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   156
         * This cap will only be set if the fbobject system property has been
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   157
         * enabled and we are able to create an FBO with depth buffer.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   158
         */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   159
        @Native
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   160
        public static final int CAPS_EXT_FBOBJECT     =
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   161
                (CAPS_RT_TEXTURE_ALPHA | CAPS_RT_TEXTURE_OPAQUE);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   162
        /** Indicates that the context is doublebuffered. */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   163
        @Native
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   164
        public static final int CAPS_DOUBLEBUFFERED   = (FIRST_PRIVATE_CAP << 0);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   165
        /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   166
         * This cap will only be set if the lcdshader system property has been
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   167
         * enabled and the hardware supports the minimum number of texture units
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   168
         */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   169
        @Native
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   170
        static final int CAPS_EXT_LCD_SHADER   = (FIRST_PRIVATE_CAP << 1);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   171
        /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   172
         * This cap will only be set if the biopshader system property has been
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   173
         * enabled and the hardware meets our minimum requirements.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   174
         */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   175
        @Native
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   176
        static final int CAPS_EXT_BIOP_SHADER  = (FIRST_PRIVATE_CAP << 2);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   177
        /**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   178
         * This cap will only be set if the gradshader system property has been
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   179
         * enabled and the hardware meets our minimum requirements.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   180
         */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   181
        @Native
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   182
        static final int CAPS_EXT_GRAD_SHADER  = (FIRST_PRIVATE_CAP << 3);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   183
        /** Indicates the presence of the GL_ARB_texture_rectangle extension. */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   184
        @Native
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   185
        static final int CAPS_EXT_TEXRECT      = (FIRST_PRIVATE_CAP << 4);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   186
        /** Indicates the presence of the GL_NV_texture_barrier extension. */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   187
        @Native
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   188
        static final int CAPS_EXT_TEXBARRIER = (FIRST_PRIVATE_CAP << 5);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   189
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   190
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   191
        public MTLContextCaps(int caps, String adapterId) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   192
            super(caps, adapterId);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   193
        }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   194
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   195
        @Override
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   196
        public String toString() {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   197
            StringBuilder sb = new StringBuilder(super.toString());
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   198
            if ((caps & CAPS_EXT_FBOBJECT) != 0) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   199
                sb.append("CAPS_EXT_FBOBJECT|");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   200
            }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   201
            if ((caps & CAPS_DOUBLEBUFFERED) != 0) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   202
                sb.append("CAPS_DOUBLEBUFFERED|");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   203
            }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   204
            if ((caps & CAPS_EXT_LCD_SHADER) != 0) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   205
                sb.append("CAPS_EXT_LCD_SHADER|");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   206
            }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   207
            if ((caps & CAPS_EXT_BIOP_SHADER) != 0) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   208
                sb.append("CAPS_BIOP_SHADER|");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   209
            }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   210
            if ((caps & CAPS_EXT_GRAD_SHADER) != 0) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   211
                sb.append("CAPS_EXT_GRAD_SHADER|");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   212
            }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   213
            if ((caps & CAPS_EXT_TEXRECT) != 0) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   214
                sb.append("CAPS_EXT_TEXRECT|");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   215
            }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   216
            if ((caps & CAPS_EXT_TEXBARRIER) != 0) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   217
                sb.append("CAPS_EXT_TEXBARRIER|");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   218
            }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   219
            return sb.toString();
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   220
        }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   221
    }
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   222
}