src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLVertexCache.m
author jdv
Wed, 26 Jun 2019 14:28:47 +0530
branchmetal-prototype-branch
changeset 57431 d5ab3442e44f
parent 57426 68ec5c5ae381
child 57441 ee34e24af607
permissions -rw-r--r--
Re-create encoder when we hit texture pool threshold
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
#ifndef HEADLESS
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
#include <stdlib.h>
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    29
#include <string.h>
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    30
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    31
#include "sun_java2d_SunGraphics2D.h"
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
#include "MTLPaints.h"
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    34
#include "MTLVertexCache.h"
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    35
#include "common.h"
57416
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
typedef struct _J2DVertex {
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    38
    float position[3];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    39
    float txtpos[2];
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    40
} J2DVertex;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    41
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    42
static J2DVertex *vertexCache = NULL;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    43
static jint vertexCacheIndex = 0;
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
static jint maskCacheTexID = 0;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    46
static jint maskCacheIndex = 0;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    47
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    48
id<MTLRenderCommandEncoder> encoder;
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    49
id<MTLTexture> texturePool[MTLVC_MAX_TEX_INDEX];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    50
static jint texturePoolIndex = 0;
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    51
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    52
#define MTLVC_ADD_VERTEX(TX, TY, DX, DY, DZ) \
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    53
    do { \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    54
        J2DVertex *v = &vertexCache[vertexCacheIndex++]; \
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    55
        v->txtpos[0] = TX; \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    56
        v->txtpos[1] = TY; \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    57
        v->position[0]= DX; \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    58
        v->position[1] = DY; \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    59
        v->position[2] = DZ; \
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    60
    } while (0)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    61
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    62
#define MTLVC_ADD_TRIANGLES(DX1, DY1, DX2, DY2) \
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    63
    do { \
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    64
        MTLVC_ADD_VERTEX(0, 0, DX1, DY1, 0); \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    65
        MTLVC_ADD_VERTEX(1, 0, DX2, DY1, 0); \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    66
        MTLVC_ADD_VERTEX(1, 1, DX2, DY2, 0); \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    67
        MTLVC_ADD_VERTEX(1, 1, DX2, DY2, 0); \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    68
        MTLVC_ADD_VERTEX(0, 1, DX1, DY2, 0); \
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    69
        MTLVC_ADD_VERTEX(0, 0, DX1, DY1, 0); \
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    70
    } while (0)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    71
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    72
jboolean
57431
d5ab3442e44f Re-create encoder when we hit texture pool threshold
jdv
parents: 57426
diff changeset
    73
MTLVertexCache_InitVertexCache()
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    74
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    75
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_InitVertexCache");
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    76
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    77
    if (vertexCache == NULL) {
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    78
        vertexCache = (J2DVertex *)malloc(MTLVC_MAX_INDEX * sizeof(J2DVertex));
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    79
        if (vertexCache == NULL) {
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    80
            return JNI_FALSE;
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    81
        }
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    82
    }
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    83
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    84
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    85
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    86
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    87
void
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    88
MTLVertexCache_FlushVertexCache(MTLContext *mtlc)
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    89
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    90
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_FlushVertexCache");
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    91
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    92
    if (vertexCacheIndex > 0 ||
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    93
        texturePoolIndex > 0) {
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    94
        id<MTLBuffer>vertexBuffer = [mtlc.device newBufferWithBytes:vertexCache
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    95
                                                 length:vertexCacheIndex * sizeof(J2DVertex)
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    96
                                                 options:MTLResourceOptionCPUCacheModeDefault];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    97
        [encoder setVertexBuffer:vertexBuffer offset:0 atIndex:MeshVertexBuffer];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    98
        for (int i = 0; i < texturePoolIndex; i++) {
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
    99
            J2dTraceLn1(J2D_TRACE_INFO, "MTLVertexCache_FlushVertexCache : draw texture at index %d", i);
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   100
            [encoder setFragmentTexture:texturePool[i] atIndex: 0];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   101
            [encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:i*6 vertexCount:6];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   102
        }
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   103
        [encoder endEncoding];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   104
    }
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   105
    vertexCacheIndex = 0;
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   106
    texturePoolIndex = 0;
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   107
}
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
 * This method is somewhat hacky, but necessary for the foreseeable future.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   111
 * The problem is the way OpenGL handles color values in vertex arrays.  When
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   112
 * a vertex in a vertex array contains a color, and then the vertex array
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   113
 * is rendered via glDrawArrays(), the global OpenGL color state is actually
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   114
 * modified each time a vertex is rendered.  This means that after all
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   115
 * vertices have been flushed, the global OpenGL color state will be set to
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   116
 * the color of the most recently rendered element in the vertex array.
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
 * The reason this is a problem for us is that we do not want to flush the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   119
 * vertex array (in the case of mask/glyph operations) or issue a glEnd()
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   120
 * (in the case of non-antialiased primitives) everytime the current color
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   121
 * changes, which would defeat any benefit from batching in the first place.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   122
 * We handle this in practice by not calling CHECK/RESET_PREVIOUS_OP() when
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   123
 * the simple color state is changing in MTLPaints_SetColor().  This is
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   124
 * problematic for vertex caching because we may end up with the following
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   125
 * situation, for example:
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   126
 *   SET_COLOR (orange)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   127
 *   MASK_FILL
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   128
 *   MASK_FILL
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   129
 *   SET_COLOR (blue; remember, this won't cause a flush)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   130
 *   FILL_RECT (this will cause the vertex array to be flushed)
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
 * In this case, we would actually end up rendering an orange FILL_RECT,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   133
 * not a blue one as intended, because flushing the vertex cache flush would
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   134
 * override the color state from the most recent SET_COLOR call.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   135
 *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   136
 * Long story short, the easiest way to resolve this problem is to call
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   137
 * this method just after disabling the mask/glyph cache, which will ensure
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   138
 * that the appropriate color state is restored.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   139
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   140
void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   141
MTLVertexCache_RestoreColorState(MTLContext *mtlc)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   142
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   143
    // TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   144
    if (mtlc.paintState == sun_java2d_SunGraphics2D_PAINT_ALPHACOLOR) {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   145
        [mtlc setColor:mtlc.pixel];
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   146
    }
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
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   149
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   150
MTLVertexCache_InitMaskCache()
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   151
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   152
    // TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   153
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_InitMaskCache");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   154
    return JNI_TRUE;
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
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   157
void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   158
MTLVertexCache_EnableMaskCache(MTLContext *mtlc)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   159
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   160
    // TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   161
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_EnableMaskCache");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   162
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   163
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   164
void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   165
MTLVertexCache_DisableMaskCache(MTLContext *mtlc)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   166
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   167
    // TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   168
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_DisableMaskCache");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   169
    maskCacheIndex = 0;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   170
}
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
void
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   173
MTLVertexCache_AddVertexTriangles(jfloat dx1, jfloat dy1,
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   174
                                  jfloat dx2, jfloat dy2)
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   175
{
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   176
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_AddVertexTriangles");
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   177
    MTLVC_ADD_TRIANGLES(dx1, dy1, dx2, dy2);
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   178
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   179
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   180
void
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   181
MTLVertexCache_AddGlyphTexture(MTLContext *mtlc,
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   182
                               jint width, jint height,
57431
d5ab3442e44f Re-create encoder when we hit texture pool threshold
jdv
parents: 57426
diff changeset
   183
                               GlyphInfo *ginfo,
d5ab3442e44f Re-create encoder when we hit texture pool threshold
jdv
parents: 57426
diff changeset
   184
                               BMTLSDOps *dstOps)
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   185
{
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   186
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_AddGlyphTexture");
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   187
    if (texturePoolIndex >= MTLVC_MAX_TEX_INDEX ||
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   188
        vertexCacheIndex >= MTLVC_MAX_INDEX)
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   189
    {
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   190
        MTLVertexCache_FlushVertexCache(mtlc);
57431
d5ab3442e44f Re-create encoder when we hit texture pool threshold
jdv
parents: 57426
diff changeset
   191
        MTLVertexCache_CreateSamplingEncoder(mtlc, dstOps);
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   192
    }
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   193
    id<MTLTexture> texture = [mtlc.texturePool getTexture:width height:height format:MTLPixelFormatA8Unorm];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   194
    NSUInteger bytesPerRow = 1 * width;
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   195
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   196
    MTLRegion region = {
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   197
        { 0, 0, 0 },
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   198
        {width, height, 1}
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   199
    };
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   200
    [texture replaceRegion:region
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   201
             mipmapLevel:0
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   202
             withBytes:ginfo->image
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   203
             bytesPerRow:bytesPerRow];
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   204
    texturePool[texturePoolIndex] = texture;
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   205
    texturePoolIndex++;
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   206
}
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   207
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   208
void
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   209
MTLVertexCache_CreateSamplingEncoder(MTLContext *mtlc, BMTLSDOps *dstOps) {
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   210
    J2dTraceLn(J2D_TRACE_INFO, "MTLVertexCache_CreateSamplingEncoder");
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57416
diff changeset
   211
    encoder = [mtlc createSamplingEncoderForDest:dstOps->pTexture];
57416
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
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   214
#endif /* !HEADLESS */