src/java.desktop/share/native/libawt/awt/image/DataBufferNative.c
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
42455
a66ed8458668 8170525: Fix minor issues in AWT/ECC/PKCS11 coding
goetz
parents: 26751
diff changeset
     2
 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    26
#include <stdlib.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "SurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sun_awt_image_DataBufferNative.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "debug_trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
unsigned char *DBN_GetPixelPointer(JNIEnv *env, jint x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
                                   SurfaceDataRasInfo *lockInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                                   SurfaceDataOps *ops, int lockFlag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    if (ops == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    lockInfo->bounds.x1 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    lockInfo->bounds.y1 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    lockInfo->bounds.x2 = x + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    lockInfo->bounds.y2 = y + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    if (ops->Lock(env, ops, lockInfo, lockFlag) != SD_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    ops->GetRasInfo(env, ops, lockInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    if (lockInfo->rasBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        unsigned char *pixelPtr = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            (unsigned char*)lockInfo->rasBase +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            (x * lockInfo->pixelStride + y * lockInfo->scanStride));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return pixelPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    SurfaceData_InvokeRelease(env, ops, lockInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    SurfaceData_InvokeUnlock(env, ops, lockInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Class:     sun_awt_image_DataBufferNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Method:    getElem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
Java_sun_awt_image_DataBufferNative_getElem(JNIEnv *env, jobject dbn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                            jint x, jint y, jobject sd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    jint returnVal = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    unsigned char *pixelPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    SurfaceDataRasInfo lockInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    SurfaceDataOps *ops;
42455
a66ed8458668 8170525: Fix minor issues in AWT/ECC/PKCS11 coding
goetz
parents: 26751
diff changeset
    75
    lockInfo.rasBase = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    ops = SurfaceData_GetOps(env, sd);
23644
0cdb97daeef5 8030787: [Parfait] JNI-related warnings from b119 for jdk/src/share/native/sun/awt/image
pchelko
parents: 23010
diff changeset
    78
    JNU_CHECK_EXCEPTION_RETURN(env, -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                         ops, SD_LOCK_READ)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return returnVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    switch (lockInfo.pixelStride) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        returnVal = *(int *)pixelPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /* REMIND: do we need a 3-byte case (for 24-bit) here? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        returnVal = *(unsigned short *)pixelPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        returnVal = *pixelPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    SurfaceData_InvokeRelease(env, ops, &lockInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    SurfaceData_InvokeUnlock(env, ops, &lockInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    return returnVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * Class:     sun_awt_image_DataBufferNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * Method:    setElem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
Java_sun_awt_image_DataBufferNative_setElem(JNIEnv *env, jobject dbn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                            jint x, jint y, jint val, jobject sd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    SurfaceDataRasInfo lockInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    SurfaceDataOps *ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    unsigned char *pixelPtr;
42455
a66ed8458668 8170525: Fix minor issues in AWT/ECC/PKCS11 coding
goetz
parents: 26751
diff changeset
   117
    lockInfo.rasBase = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    ops = SurfaceData_GetOps(env, sd);
23644
0cdb97daeef5 8030787: [Parfait] JNI-related warnings from b119 for jdk/src/share/native/sun/awt/image
pchelko
parents: 23010
diff changeset
   120
    JNU_CHECK_EXCEPTION(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                         ops, SD_LOCK_WRITE)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    switch (lockInfo.pixelStride) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        *(int *)pixelPtr = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /* REMIND: do we need a 3-byte case (for 24-bit) here? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        *(unsigned short *)pixelPtr = (unsigned short)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        *pixelPtr = (unsigned char)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    SurfaceData_InvokeRelease(env, ops, &lockInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    SurfaceData_InvokeUnlock(env, ops, &lockInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}