src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTextRenderer.m
author jdv
Tue, 13 Aug 2019 11:02:18 +0530
branchmetal-prototype-branch
changeset 57719 328d81bbff39
parent 57682 6b0febcd7b43
permissions -rw-r--r--
TODO logs for text rendering
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
{
57476
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   259
    // TODO : This is similar to OpenGL implementation
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   260
    // When LCD implementation is done weshould make
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   261
    // more changes.
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   262
    J2dTraceLn1(J2D_TRACE_VERBOSE,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   263
                "MTLTR_DisableGlyphModeState: mode=%d", glyphMode);
57476
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   264
    switch (glyphMode) {
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   265
    case MODE_NO_CACHE_LCD:
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   266
        // TODO : Along with LCD implementation
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   267
        // changes needs to be made
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   268
    case MODE_USE_CACHE_LCD:
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   269
        // TODO : Along with LCD implementation
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   270
        // changes needs to be made
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   271
        break;
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   272
    case MODE_NO_CACHE_GRAY:
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   273
    case MODE_USE_CACHE_GRAY:
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   274
    case MODE_NOT_INITED:
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   275
    default:
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   276
        break;
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   277
    }
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   278
}
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
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   281
MTLTR_DrawGrayscaleGlyphViaCache(MTLContext *mtlc,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   282
                                 GlyphInfo *ginfo, jint x, jint y)
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
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   285
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   286
}
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
 * 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
   290
 * inside outerBounds.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   291
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   292
#define INSIDE(gx1, gy1, gx2, gy2, outerBounds) \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   293
    (((gx1) >= outerBounds.x1) && ((gy1) >= outerBounds.y1) && \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   294
     ((gx2) <= outerBounds.x2) && ((gy2) <= outerBounds.y2))
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   295
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   296
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   297
 * 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
   298
 * the rectangle defined by bounds.
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
#define INTERSECTS(gx1, gy1, gx2, gy2, bounds) \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   301
    ((bounds.x2 > (gx1)) && (bounds.y2 > (gy1)) && \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   302
     (bounds.x1 < (gx2)) && (bounds.y1 < (gy2)))
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   303
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   304
/**
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   305
 * 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
   306
 * 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
   307
 * 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
   308
 * 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
   309
 * destination bounds before returning.
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   310
 */
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   311
static void
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   312
MTLTR_UpdateCachedDestination(MTLSDOps *dstOps, GlyphInfo *ginfo,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   313
                              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
   314
                              jint glyphIndex, jint totalGlyphs)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   315
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   316
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   317
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   318
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   319
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   320
MTLTR_DrawLCDGlyphViaCache(MTLContext *mtlc, MTLSDOps *dstOps,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   321
                           GlyphInfo *ginfo, jint x, jint y,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   322
                           jint glyphIndex, jint totalGlyphs,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   323
                           jboolean rgbOrder, jint contrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   324
                           jint dstTextureID, jboolean * opened)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   325
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   326
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   327
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   328
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   329
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   330
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   331
MTLTR_DrawGrayscaleGlyphNoCache(MTLContext *mtlc,
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   332
                                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
   333
{
57462
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   334
    jint tw, th;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   335
    jint sx, sy, sw, sh;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   336
    jint x0;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   337
    jint w = ginfo->width;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   338
    jint h = ginfo->height;
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   339
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   340
    J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DrawGrayscaleGlyphNoCache");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   341
    if (glyphMode != MODE_NO_CACHE_GRAY) {
57682
6b0febcd7b43 Disable usage of check_previous_op for text rendering
jdv
parents: 57476
diff changeset
   342
        //MTLTR_DisableGlyphModeState();
6b0febcd7b43 Disable usage of check_previous_op for text rendering
jdv
parents: 57476
diff changeset
   343
        //CHECK_PREVIOUS_OP(MTL_STATE_MASK_OP);
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   344
        glyphMode = MODE_NO_CACHE_GRAY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   345
    }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   346
57462
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   347
    x0 = x;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   348
    tw = MTLVC_MASK_CACHE_TILE_WIDTH;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   349
    th = MTLVC_MASK_CACHE_TILE_HEIGHT;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   350
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   351
    for (sy = 0; sy < h; sy += th, y += th) {
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   352
        x = x0;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   353
        sh = ((sy + th) > h) ? (h - sy) : th;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   354
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   355
        for (sx = 0; sx < w; sx += tw, x += tw) {
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   356
            sw = ((sx + tw) > w) ? (w - sx) : tw;
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   357
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   358
            J2dTraceLn7(J2D_TRACE_INFO, "sx = %d sy = %d x = %d y = %d sw = %d sh = %d w = %d", sx, sy, x, y, sw, sh, w);
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   359
            MTLVertexCache_AddMaskQuad(mtlc,
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   360
                                       sx, sy, x, y, sw, sh,
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   361
                                       w, ginfo->image,
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   362
                                       dstOps,
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   363
                                       ginfo->width);
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   364
        }
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   365
    }
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   366
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   367
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   368
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   369
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   370
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   371
MTLTR_DrawLCDGlyphNoCache(MTLContext *mtlc, MTLSDOps *dstOps,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   372
                          GlyphInfo *ginfo, jint x, jint y,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   373
                          jint rowBytesOffset,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   374
                          jboolean rgbOrder, jint contrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   375
                          jint dstTextureID)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   376
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   377
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   378
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   379
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   380
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   381
static jboolean
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   382
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
   383
{
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   384
    //TODO
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   385
    return JNI_TRUE;
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   386
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   387
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   388
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   389
// 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
   390
#define FLOOR_ASSIGN(l, r) \
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   391
    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
   392
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   393
void
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   394
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
   395
                    jint totalGlyphs, jboolean usePositions,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   396
                    jboolean subPixPos, jboolean rgbOrder, jint lcdContrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   397
                    jfloat glyphListOrigX, jfloat glyphListOrigY,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   398
                    unsigned char *images, unsigned char *positions)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   399
{
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   400
    int glyphCounter;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   401
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   402
    J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DrawGlyphList");
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
    RETURN_IF_NULL(mtlc);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   405
    RETURN_IF_NULL(dstOps);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   406
    RETURN_IF_NULL(images);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   407
    if (usePositions) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   408
        RETURN_IF_NULL(positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   409
    }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   410
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   411
    glyphMode = MODE_NOT_INITED;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   412
    isCachedDestValid = JNI_FALSE;
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   413
    J2dTraceLn1(J2D_TRACE_INFO, "totalGlyphs = %d", totalGlyphs);
57682
6b0febcd7b43 Disable usage of check_previous_op for text rendering
jdv
parents: 57476
diff changeset
   414
    MTLVertexCache_EnableMaskCache(mtlc, dstOps);
57426
68ec5c5ae381 Initial implementation of vertex cache for text rendering
jdv
parents: 57423
diff changeset
   415
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   416
    for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   417
        J2dTraceLn(J2D_TRACE_INFO, "Entered for loop for glyph list");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   418
        jint x, y;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   419
        jfloat glyphx, glyphy;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   420
        jboolean grayscale, ok;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   421
        GlyphInfo *ginfo = (GlyphInfo *)jlong_to_ptr(NEXT_LONG(images));
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   423
        if (ginfo == NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   424
            // 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
   425
            J2dRlsTraceLn(J2D_TRACE_ERROR,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   426
                          "MTLTR_DrawGlyphList: glyph info is null");
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   427
            break;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   428
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   429
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   430
        grayscale = (ginfo->rowBytes == ginfo->width);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   431
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   432
        if (usePositions) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   433
            jfloat posx = NEXT_FLOAT(positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   434
            jfloat posy = NEXT_FLOAT(positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   435
            glyphx = glyphListOrigX + posx + ginfo->topLeftX;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   436
            glyphy = glyphListOrigY + posy + ginfo->topLeftY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   437
            FLOOR_ASSIGN(x, glyphx);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   438
            FLOOR_ASSIGN(y, glyphy);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   439
        } else {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   440
            glyphx = glyphListOrigX + ginfo->topLeftX;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   441
            glyphy = glyphListOrigY + ginfo->topLeftY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   442
            FLOOR_ASSIGN(x, glyphx);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   443
            FLOOR_ASSIGN(y, glyphy);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   444
            glyphListOrigX += ginfo->advanceX;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   445
            glyphListOrigY += ginfo->advanceY;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   446
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   447
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   448
        if (ginfo->image == NULL) {
57441
ee34e24af607 Remove usage of texture pool
jdv
parents: 57431
diff changeset
   449
            J2dTraceLn(J2D_TRACE_INFO, "Glyph image is null");
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   450
            continue;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   451
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   452
57462
db2be8544d10 Initial implementation of mask cache for Text rendering
jdv
parents: 57441
diff changeset
   453
        J2dTraceLn2(J2D_TRACE_INFO, "Glyph width = %d height = %d", ginfo->width, ginfo->height);
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   454
        //TODO : Right now we have initial texture mapping logic
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   455
        // 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
   456
        if (grayscale) {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   457
            // grayscale or monochrome glyph data
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   458
            if (ginfo->width <= MTLTR_CACHE_CELL_WIDTH &&
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   459
                ginfo->height <= MTLTR_CACHE_CELL_HEIGHT)
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   460
            {
57719
328d81bbff39 TODO logs for text rendering
jdv
parents: 57682
diff changeset
   461
                J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DrawGlyphList Grayscale cache -- :TODO");
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   462
                //ok = MTLTR_DrawGrayscaleGlyphViaCache(oglc, ginfo, x, y);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   463
                // TODO: Replace no cache with cache rendering
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   464
                ok = MTLTR_DrawGrayscaleGlyphNoCache(mtlc, ginfo, x, y, dstOps);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   465
            } else {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   466
                J2dTraceLn(J2D_TRACE_INFO, "Grayscale no cache");
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   467
                ok = MTLTR_DrawGrayscaleGlyphNoCache(mtlc, ginfo, x, y, dstOps);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   468
            }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   469
        } else {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   470
            // LCD-optimized glyph data
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   471
            jint rowBytesOffset = 0;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   472
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   473
            if (subPixPos) {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   474
                jint frac = (jint)((glyphx - x) * 3);
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   475
                if (frac != 0) {
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   476
                    rowBytesOffset = 3 - frac;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   477
                    x += 1;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   478
                }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   479
            }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   480
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   481
            // TODO: Implement LCD text rendering
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   482
            if (rowBytesOffset == 0 &&
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   483
                ginfo->width <= MTLTR_CACHE_CELL_WIDTH &&
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   484
                ginfo->height <= MTLTR_CACHE_CELL_HEIGHT)
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   485
            {
57719
328d81bbff39 TODO logs for text rendering
jdv
parents: 57682
diff changeset
   486
                J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DrawGlyphList LCD cache -- :TODO");
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   487
                /*ok = MTLTR_DrawLCDGlyphViaCache(oglc, dstOps,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   488
                                                ginfo, x, y,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   489
                                                glyphCounter, totalGlyphs,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   490
                                                rgbOrder, lcdContrast,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   491
                                                dstTextureID);*/
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   492
                ok = JNI_FALSE;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   493
            } else {
57719
328d81bbff39 TODO logs for text rendering
jdv
parents: 57682
diff changeset
   494
                J2dTraceLn(J2D_TRACE_INFO, "MTLTR_DrawGlyphList LCD no cache -- :TODO");
57423
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   495
                /*ok = MTLTR_DrawLCDGlyphNoCache(oglc, dstOps,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   496
                                               ginfo, x, y,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   497
                                               rowBytesOffset,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   498
                                               rgbOrder, lcdContrast,
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   499
                                               dstTextureID);*/
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   500
                ok = JNI_FALSE;
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   501
            }
539748673056 Remove faulty tile coordinate logic for text rendering
jdv
parents: 57422
diff changeset
   502
        }
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   503
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   504
        if (!ok) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   505
            break;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   506
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   507
    }
57682
6b0febcd7b43 Disable usage of check_previous_op for text rendering
jdv
parents: 57476
diff changeset
   508
    MTLVertexCache_FlushVertexCache(mtlc);
57476
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   509
    MTLTR_DisableGlyphModeState();
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   510
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   511
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   512
JNIEXPORT void JNICALL
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   513
Java_sun_java2d_metal_MTLTextRenderer_drawGlyphList
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   514
    (JNIEnv *env, jobject self,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   515
     jint numGlyphs, jboolean usePositions,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   516
     jboolean subPixPos, jboolean rgbOrder, jint lcdContrast,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   517
     jfloat glyphListOrigX, jfloat glyphListOrigY,
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   518
     jlongArray imgArray, jfloatArray posArray)
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   519
{
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   520
    unsigned char *images;
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   521
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   522
    J2dTraceLn(J2D_TRACE_INFO, "MTLTextRenderer_drawGlyphList");
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
    images = (unsigned char *)
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   525
        (*env)->GetPrimitiveArrayCritical(env, imgArray, NULL);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   526
    if (images != NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   527
        MTLContext *mtlc = MTLRenderQueue_GetCurrentContext();
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   528
        BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   529
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   530
        if (usePositions) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   531
            unsigned char *positions = (unsigned char *)
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   532
                (*env)->GetPrimitiveArrayCritical(env, posArray, NULL);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   533
            if (positions != NULL) {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   534
                MTLTR_DrawGlyphList(env, mtlc, dstOps,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   535
                                    numGlyphs, usePositions,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   536
                                    subPixPos, rgbOrder, lcdContrast,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   537
                                    glyphListOrigX, glyphListOrigY,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   538
                                    images, positions);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   539
                (*env)->ReleasePrimitiveArrayCritical(env, posArray,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   540
                                                      positions, JNI_ABORT);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   541
            }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   542
        } else {
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   543
            MTLTR_DrawGlyphList(env, mtlc, dstOps,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   544
                                numGlyphs, usePositions,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   545
                                subPixPos, rgbOrder, lcdContrast,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   546
                                glyphListOrigX, glyphListOrigY,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   547
                                images, NULL);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   548
        }
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   549
57476
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   550
        // TODO : We can't flush draw calls here
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   551
        // as it is done while blitting. It needs to
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   552
        // be updated if start flushing right after
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   553
        // rendering
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   554
        if (mtlc != NULL) {
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   555
            RESET_PREVIOUS_OP();
64365a5764cd Initial state management for Mask Cache with some cleanup
jdv
parents: 57462
diff changeset
   556
        }
57422
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   557
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   558
        (*env)->ReleasePrimitiveArrayCritical(env, imgArray,
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   559
                                              images, JNI_ABORT);
08d15ddd72c9 Initial texture mapping logic for text rendering
jdv
parents: 57416
diff changeset
   560
    }
57416
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   561
}
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   562
e153174dba06 Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff changeset
   563
#endif /* !HEADLESS */