src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.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 <limits.h>
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    30
#include <math.h>
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    31
#include <jlong.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 "sun_java2d_metal_MTLTextRenderer.h"
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
#include "SurfaceData.h"
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    36
#include "MTLContext.h"
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    37
#include "MTLRenderQueue.h"
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    38
#include "MTLTextRenderer.h"
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    39
#include "MTLVertexCache.h"
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    40
#include "AccelGlyphCache.h"
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
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    43
 * The following constants define the inner and outer bounds of the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    44
 * accelerated glyph cache.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    45
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    46
#define MTLTR_CACHE_WIDTH       1024
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    47
#define MTLTR_CACHE_HEIGHT      1024
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
    48
#define MTLTR_CACHE_CELL_WIDTH  32
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
    49
#define MTLTR_CACHE_CELL_HEIGHT 32
57416
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
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    52
 * The current "glyph mode" state.  This variable is used to track the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    53
 * codepath used to render a particular glyph.  This variable is reset to
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    54
 * MODE_NOT_INITED at the beginning of every call to MTLTR_DrawGlyphList().
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    55
 * As each glyph is rendered, the glyphMode variable is updated to reflect
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    56
 * the current mode, so if the current mode is the same as the mode used
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    57
 * to render the previous glyph, we can avoid doing costly setup operations
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    58
 * each time.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    59
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    60
typedef enum {
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    61
    MODE_NOT_INITED,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    62
    MODE_USE_CACHE_GRAY,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    63
    MODE_USE_CACHE_LCD,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    64
    MODE_NO_CACHE_GRAY,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    65
    MODE_NO_CACHE_LCD,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    66
    MODE_NO_CACHE_COLOR
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    67
} GlyphMode;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    68
static GlyphMode glyphMode = MODE_NOT_INITED;
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
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    71
 * There are two separate glyph caches: for AA and for LCD.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    72
 * Once one of them is initialized as either GRAY or LCD, it
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    73
 * stays in that mode for the duration of the application.  It should
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    74
 * be safe to use this one glyph cache for all screens in a multimon
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    75
 * environment, since the glyph cache texture is shared between all contexts,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    76
 * and (in theory) OpenGL drivers should be smart enough to manage that
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    77
 * texture across all screens.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    78
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    79
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    80
static GlyphCacheInfo *glyphCacheLCD = NULL;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    81
static GlyphCacheInfo *glyphCacheAA = NULL;
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
 * The handle to the LCD text fragment program object.
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
static GLhandleARB lcdTextProgram = 0;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    87
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    88
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    89
 * This value tracks the previous LCD contrast setting, so if the contrast
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    90
 * value hasn't changed since the last time the gamma uniforms were
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    91
 * updated (not very common), then we can skip updating the unforms.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    92
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    93
static jint lastLCDContrast = -1;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    94
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    95
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    96
 * This value tracks the previous LCD rgbOrder setting, so if the rgbOrder
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    97
 * value has changed since the last time, it indicates that we need to
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    98
 * invalidate the cache, which may already store glyph images in the reverse
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
    99
 * order.  Note that in most real world applications this value will not
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   100
 * change over the course of the application, but tests like Font2DTest
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   101
 * allow for changing the ordering at runtime, so we need to handle that case.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   102
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   103
static jboolean lastRGBOrder = JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   104
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   105
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   106
 * This constant defines the size of the tile to use in the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   107
 * MTLTR_DrawLCDGlyphNoCache() method.  See below for more on why we
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   108
 * restrict this value to a particular size.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   109
 */
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   110
#define MTLTR_NOCACHE_TILE_SIZE 32
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   111
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
 * These constants define the size of the "cached destination" texture.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   114
 * This texture is only used when rendering LCD-optimized text, as that
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   115
 * codepath needs direct access to the destination.  There is no way to
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   116
 * access the framebuffer directly from an OpenGL shader, so we need to first
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   117
 * copy the destination region corresponding to a particular glyph into
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   118
 * this cached texture, and then that texture will be accessed inside the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   119
 * shader.  Copying the destination into this cached texture can be a very
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   120
 * expensive operation (accounting for about half the rendering time for
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   121
 * LCD text), so to mitigate this cost we try to bulk read a horizontal
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   122
 * region of the destination at a time.  (These values are empirically
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   123
 * derived for the common case where text runs horizontally.)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   124
 *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   125
 * Note: It is assumed in various calculations below that:
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   126
 *     (MTLTR_CACHED_DEST_WIDTH  >= MTLTR_CACHE_CELL_WIDTH)  &&
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   127
 *     (MTLTR_CACHED_DEST_WIDTH  >= MTLTR_NOCACHE_TILE_SIZE) &&
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   128
 *     (MTLTR_CACHED_DEST_HEIGHT >= MTLTR_CACHE_CELL_HEIGHT) &&
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   129
 *     (MTLTR_CACHED_DEST_HEIGHT >= MTLTR_NOCACHE_TILE_SIZE)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   130
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   131
#define MTLTR_CACHED_DEST_WIDTH  1024
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   132
#define MTLTR_CACHED_DEST_HEIGHT (MTLTR_CACHE_CELL_HEIGHT * 2)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   133
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   134
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   135
 * The handle to the "cached destination" texture object.
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
static GLuint cachedDestTextureID = 0;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   138
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
 * The current bounds of the "cached destination" texture, in destination
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   141
 * coordinate space.  The width/height of these bounds will not exceed the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   142
 * MTLTR_CACHED_DEST_WIDTH/HEIGHT values defined above.  These bounds are
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   143
 * only considered valid when the isCachedDestValid flag is JNI_TRUE.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   144
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   145
static SurfaceDataBounds cachedDestBounds;
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
 * This flag indicates whether the "cached destination" texture contains
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   149
 * valid data.  This flag is reset to JNI_FALSE at the beginning of every
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   150
 * call to MTLTR_DrawGlyphList().  Once we copy valid destination data
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   151
 * into the cached texture, this flag is set to JNI_TRUE.  This way, we can
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   152
 * limit the number of times we need to copy destination data, which is a
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   153
 * very costly operation.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   154
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   155
static jboolean isCachedDestValid = JNI_FALSE;
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
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   158
 * The bounds of the previously rendered LCD glyph, in destination
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   159
 * coordinate space.  We use these bounds to determine whether the glyph
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   160
 * currently being rendered overlaps the previously rendered glyph (i.e.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   161
 * its bounding box intersects that of the previously rendered glyph).  If
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   162
 * so, we need to re-read the destination area associated with that previous
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   163
 * glyph so that we can correctly blend with the actual destination data.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   164
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   165
static SurfaceDataBounds previousGlyphBounds;
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
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   168
 * Initializes the one glyph cache (texture and data structure).
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   169
 * If lcdCache is JNI_TRUE, the texture will contain RGB data,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   170
 * otherwise we will simply store the grayscale/monochrome glyph images
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   171
 * as intensity values (which work well with the GL_MODULATE function).
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   172
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   173
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   174
MTLTR_InitGlyphCache(jboolean lcdCache)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   175
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   176
    //TODO
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
    return JNI_TRUE;
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
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   181
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   182
 * Adds the given glyph to the glyph cache (texture and data structure)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   183
 * associated with the given MTLContext.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   184
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   185
static void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   186
MTLTR_AddTmTLyphCache(GlyphInfo *glyph, GLenum pixelFormat)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   187
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   188
    //TODO
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
    CacheCellInfo *ccinfo;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   191
    GlyphCacheInfo *gcinfo;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   192
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   193
    J2dTraceLn(J2D_TRACE_INFO, "MTLTR_AddTmTLyphCache");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   194
    //J2dTracePrimitive("MTLTR_InitGlyphCache");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   195
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   196
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   197
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   198
 * (Re)Initializes the gamma related uniforms.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   199
 *
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   200
 * The given contrast value is an int in the range [100, 250] which we will
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   201
 * then scale to fit in the range [1.0, 2.5].
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   202
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   203
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   204
MTLTR_UpdateLCDTextContrast(jint contrast)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   205
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   206
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   207
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   208
}
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
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   211
 * Updates the current gamma-adjusted source color ("src_adj") of the LCD
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   212
 * text shader program.  Note that we could calculate this value in the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   213
 * shader (e.g. just as we do for "dst_adj"), but would be unnecessary work
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   214
 * (and a measurable performance hit, maybe around 5%) since this value is
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   215
 * constant over the entire glyph list.  So instead we just calculate the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   216
 * gamma-adjusted value once and update the uniform parameter of the LCD
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   217
 * shader as needed.
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
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   220
MTLTR_UpdateLCDTextColor(jint contrast)
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
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   223
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   224
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   225
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   226
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   227
 * Enables the LCD text shader and updates any related state, such as the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   228
 * gamma lookup table textures.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   229
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   230
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   231
MTLTR_EnableLCDGlyphModeState(GLuint glyphTextureID,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   232
                              GLuint dstTextureID,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   233
                              jint contrast)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   234
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   235
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   236
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   237
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   238
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   239
void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   240
MTLTR_EnableGlyphVertexCache(MTLContext *mtlc)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   241
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   242
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   243
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   244
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   245
void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   246
MTLTR_DisableGlyphVertexCache(MTLContext *mtlc)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   247
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   248
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   249
    J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DisableGlyphVertexCache");
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   250
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   251
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   252
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   253
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   254
 * Disables any pending state associated with the current "glyph mode".
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   255
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   256
void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   257
MTLTR_DisableGlyphModeState()
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   258
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   259
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   260
    J2dTraceLn1(J2D_TRACE_VERBOSE,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   261
                "MTLTR_DisableGlyphModeState: mode=%d", glyphMode);
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   262
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   263
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   264
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   265
MTLTR_DrawGrayscaleGlyphViaCache(MTLContext *mtlc,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   266
                                 GlyphInfo *ginfo, jint x, jint y)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   267
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   268
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   269
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   270
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   271
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   272
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   273
 * Evaluates to true if the rectangle defined by gx1/gy1/gx2/gy2 is
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   274
 * inside outerBounds.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   275
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   276
#define INSIDE(gx1, gy1, gx2, gy2, outerBounds) \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   277
    (((gx1) >= outerBounds.x1) && ((gy1) >= outerBounds.y1) && \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   278
     ((gx2) <= outerBounds.x2) && ((gy2) <= outerBounds.y2))
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   279
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   280
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   281
 * Evaluates to true if the rectangle defined by gx1/gy1/gx2/gy2 intersects
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   282
 * the rectangle defined by bounds.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   283
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   284
#define INTERSECTS(gx1, gy1, gx2, gy2, bounds) \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   285
    ((bounds.x2 > (gx1)) && (bounds.y2 > (gy1)) && \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   286
     (bounds.x1 < (gx2)) && (bounds.y1 < (gy2)))
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   287
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   288
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   289
 * This method checks to see if the given LCD glyph bounds fall within the
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   290
 * cached destination texture bounds.  If so, this method can return
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   291
 * immediately.  If not, this method will copy a chunk of framebuffer data
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   292
 * into the cached destination texture and then update the current cached
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   293
 * destination bounds before returning.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   294
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   295
static void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   296
MTLTR_UpdateCachedDestination(MTLSDOps *dstOps, GlyphInfo *ginfo,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   297
                              jint gx1, jint gy1, jint gx2, jint gy2,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   298
                              jint glyphIndex, jint totalGlyphs)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   299
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   300
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   301
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   302
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   303
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   304
MTLTR_DrawLCDGlyphViaCache(MTLContext *mtlc, MTLSDOps *dstOps,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   305
                           GlyphInfo *ginfo, jint x, jint y,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   306
                           jint glyphIndex, jint totalGlyphs,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   307
                           jboolean rgbOrder, jint contrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   308
                           jint dstTextureID, jboolean * opened)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   309
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   310
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   311
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   312
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   313
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   314
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   315
MTLTR_DrawGrayscaleGlyphNoCache(MTLContext *mtlc,
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   316
                                GlyphInfo *ginfo, jint x, jint y, BMTLSDOps *dstOps)
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   317
{
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   318
    jfloat dx1, dy1, dx2, dy2;
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   319
    jint width = ginfo->width;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   320
    jint height = ginfo->height;
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   321
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   322
    J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DrawGrayscaleGlyphNoCache");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   323
    /*
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   324
     * TODO : Glyph caching is not used yet we need to
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   325
     * implement it.
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   326
     */
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   327
    if (glyphMode != MODE_NO_CACHE_GRAY) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   328
        glyphMode = MODE_NO_CACHE_GRAY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   329
    }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   330
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   331
    dx1 = (jfloat)x;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   332
    dy1 = (jfloat)y;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   333
    dx2 = x + width;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   334
    dy2 = y + height;
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   335
    J2dTraceLn4(J2D_TRACE_INFO,
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   336
        "Destination coordinates dx1 = %f dy1 = %f dx2 = %f dy2 = %f", dx1, dy1, dx2, dy2);
57431
d5ab3442e44f Re-create encoder when we hit texture pool threshold
jdv
parents: 57426
diff changeset
   337
    MTLVertexCache_AddGlyphTexture(mtlc, width, height, ginfo, dstOps);
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   338
    MTLVertexCache_AddVertexTriangles(dx1, dy1, dx2, dy2);
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   339
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   340
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   341
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   342
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   343
MTLTR_DrawLCDGlyphNoCache(MTLContext *mtlc, MTLSDOps *dstOps,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   344
                          GlyphInfo *ginfo, jint x, jint y,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   345
                          jint rowBytesOffset,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   346
                          jboolean rgbOrder, jint contrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   347
                          jint dstTextureID)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   348
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   349
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   350
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   351
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   352
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   353
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   354
MTLTR_DrawColorGlyphNoCache(MTLContext *mtlc, GlyphInfo *ginfo, jint x, jint y)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   355
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   356
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   357
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   358
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   359
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   360
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   361
// see DrawGlyphList.c for more on this macro...
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   362
#define FLOOR_ASSIGN(l, r) \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   363
    if ((r)<0) (l) = ((int)floor(r)); else (l) = ((int)(r))
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   364
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   365
void
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   366
MTLTR_DrawGlyphList(JNIEnv *env, MTLContext *mtlc, BMTLSDOps *dstOps,
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   367
                    jint totalGlyphs, jboolean usePositions,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   368
                    jboolean subPixPos, jboolean rgbOrder, jint lcdContrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   369
                    jfloat glyphListOrigX, jfloat glyphListOrigY,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   370
                    unsigned char *images, unsigned char *positions)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   371
{
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   372
    int glyphCounter;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   373
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   374
    J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DrawGlyphList");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   375
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   376
    RETURN_IF_NULL(mtlc);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   377
    RETURN_IF_NULL(dstOps);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   378
    RETURN_IF_NULL(images);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   379
    if (usePositions) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   380
        RETURN_IF_NULL(positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   381
    }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   382
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   383
    glyphMode = MODE_NOT_INITED;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   384
    isCachedDestValid = JNI_FALSE;
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   385
    J2dTraceLn1(J2D_TRACE_INFO, "totalGlyphs = %d", totalGlyphs);
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   386
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   387
    MTLVertexCache_CreateSamplingEncoder(mtlc, dstOps);
57431
d5ab3442e44f Re-create encoder when we hit texture pool threshold
jdv
parents: 57426
diff changeset
   388
    MTLVertexCache_InitVertexCache();
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   389
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   390
    for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   391
        J2dTraceLn(J2D_TRACE_INFO, "Entered for loop for glyph list");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   392
        jint x, y;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   393
        jfloat glyphx, glyphy;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   394
        jboolean grayscale, ok;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   395
        GlyphInfo *ginfo = (GlyphInfo *)jlong_to_ptr(NEXT_LONG(images));
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   396
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   397
        if (ginfo == NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   398
            // this shouldn't happen, but if it does we'll just break out...
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   399
            J2dRlsTraceLn(J2D_TRACE_ERROR,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   400
                          "MTLTR_DrawGlyphList: glyph info is null");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   401
            break;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   402
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   403
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   404
        grayscale = (ginfo->rowBytes == ginfo->width);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   405
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   406
        if (usePositions) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   407
            jfloat posx = NEXT_FLOAT(positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   408
            jfloat posy = NEXT_FLOAT(positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   409
            glyphx = glyphListOrigX + posx + ginfo->topLeftX;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   410
            glyphy = glyphListOrigY + posy + ginfo->topLeftY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   411
            FLOOR_ASSIGN(x, glyphx);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   412
            FLOOR_ASSIGN(y, glyphy);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   413
        } else {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   414
            glyphx = glyphListOrigX + ginfo->topLeftX;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   415
            glyphy = glyphListOrigY + ginfo->topLeftY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   416
            FLOOR_ASSIGN(x, glyphx);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   417
            FLOOR_ASSIGN(y, glyphy);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   418
            glyphListOrigX += ginfo->advanceX;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   419
            glyphListOrigY += ginfo->advanceY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   420
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   421
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   422
        if (ginfo->image == NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   423
            continue;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   424
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   425
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   426
        //TODO : Right now we have initial texture mapping logic
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   427
        // as we implement LCD, cache usage add new selection condition.
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   428
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   429
        if (grayscale) {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   430
            // grayscale or monochrome glyph data
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   431
            if (ginfo->width <= MTLTR_CACHE_CELL_WIDTH &&
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   432
                ginfo->height <= MTLTR_CACHE_CELL_HEIGHT)
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   433
            {
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   434
                J2dTraceLn(J2D_TRACE_INFO, "Forced Grayscale no cache");
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   435
                //ok = MTLTR_DrawGrayscaleGlyphViaCache(oglc, ginfo, x, y);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   436
                // TODO: Replace no cache with cache rendering
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   437
                ok = MTLTR_DrawGrayscaleGlyphNoCache(mtlc, ginfo, x, y, dstOps);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   438
            } else {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   439
                J2dTraceLn(J2D_TRACE_INFO, "Grayscale no cache");
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   440
                ok = MTLTR_DrawGrayscaleGlyphNoCache(mtlc, ginfo, x, y, dstOps);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   441
            }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   442
        } else {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   443
            // LCD-optimized glyph data
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   444
            jint rowBytesOffset = 0;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   445
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   446
            if (subPixPos) {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   447
                jint frac = (jint)((glyphx - x) * 3);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   448
                if (frac != 0) {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   449
                    rowBytesOffset = 3 - frac;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   450
                    x += 1;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   451
                }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   452
            }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   453
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   454
            // TODO: Implement LCD text rendering
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   455
            if (rowBytesOffset == 0 &&
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   456
                ginfo->width <= MTLTR_CACHE_CELL_WIDTH &&
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   457
                ginfo->height <= MTLTR_CACHE_CELL_HEIGHT)
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   458
            {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   459
                J2dTraceLn(J2D_TRACE_INFO, "LCD cache");
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   460
                /*ok = MTLTR_DrawLCDGlyphViaCache(oglc, dstOps,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   461
                                                ginfo, x, y,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   462
                                                glyphCounter, totalGlyphs,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   463
                                                rgbOrder, lcdContrast,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   464
                                                dstTextureID);*/
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   465
                ok = JNI_FALSE;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   466
            } else {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   467
                J2dTraceLn(J2D_TRACE_INFO, "LCD no cache");
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   468
                /*ok = MTLTR_DrawLCDGlyphNoCache(oglc, dstOps,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   469
                                               ginfo, x, y,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   470
                                               rowBytesOffset,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   471
                                               rgbOrder, lcdContrast,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   472
                                               dstTextureID);*/
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   473
                ok = JNI_FALSE;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   474
            }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   475
        }
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   476
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   477
        if (!ok) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   478
            break;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   479
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   480
    }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   481
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   482
    MTLVertexCache_FlushVertexCache(mtlc);
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   483
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   484
    // TODO : Disable glyph state.
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   485
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   486
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   487
JNIEXPORT void JNICALL
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   488
Java_sun_java2d_metal_MTLTextRenderer_drawGlyphList
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   489
    (JNIEnv *env, jobject self,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   490
     jint numGlyphs, jboolean usePositions,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   491
     jboolean subPixPos, jboolean rgbOrder, jint lcdContrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   492
     jfloat glyphListOrigX, jfloat glyphListOrigY,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   493
     jlongArray imgArray, jfloatArray posArray)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   494
{
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   495
    unsigned char *images;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   496
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   497
    J2dTraceLn(J2D_TRACE_INFO, "MTLTextRenderer_drawGlyphList");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   498
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   499
    images = (unsigned char *)
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   500
        (*env)->GetPrimitiveArrayCritical(env, imgArray, NULL);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   501
    if (images != NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   502
        MTLContext *mtlc = MTLRenderQueue_GetCurrentContext();
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   503
        BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   504
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   505
        if (usePositions) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   506
            unsigned char *positions = (unsigned char *)
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   507
                (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   508
            if (positions != NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   509
                MTLTR_DrawGlyphList(env, mtlc, dstOps,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   510
                                    numGlyphs, usePositions,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   511
                                    subPixPos, rgbOrder, lcdContrast,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   512
                                    glyphListOrigX, glyphListOrigY,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   513
                                    images, positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   514
                (*env)->ReleasePrimitiveArrayCritical(env, posArray,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   515
                                                      positions, JNI_ABORT);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   516
            }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   517
        } else {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   518
            MTLTR_DrawGlyphList(env, mtlc, dstOps,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   519
                                numGlyphs, usePositions,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   520
                                subPixPos, rgbOrder, lcdContrast,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   521
                                glyphListOrigX, glyphListOrigY,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   522
                                images, NULL);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   523
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   524
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   525
        // TODO : We are flushing serially as of now
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   526
        // no need for below logic.
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   527
        //if (mtlc != NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   528
            //RESET_PREVIOUS_OP();
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   529
            //j2d_glFlush();
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   530
        //}
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   531
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   532
        (*env)->ReleasePrimitiveArrayCritical(env, imgArray,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   533
                                              images, JNI_ABORT);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   534
    }
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   535
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   536
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   537
#endif /* !HEADLESS */