jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c
author azvegint
Mon, 07 Apr 2014 17:41:16 +0100
changeset 24165 fb4f67872b27
parent 24130 db72fc72f87b
permissions -rw-r--r--
8031087: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/xawt Reviewed-by: anthony, pchelko, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
     2
 * Copyright (c) 1996, 2014, 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: 1175
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: 1175
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: 1175
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1175
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    #error This file should not be included in headless library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "java_awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <jawt_md.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
extern struct ComponentIDs componentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "awt_GraphicsEnv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
extern jfieldID windowID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
extern jfieldID targetID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
extern jfieldID graphicsConfigID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
extern jfieldID drawStateID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Lock the surface of the target component for native rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * When finished drawing, the surface must be unlocked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Unlock().  This function returns a bitmask with one or more of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * JAWT_LOCK_ERROR - When an error has occurred and the surface could not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * be locked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
JNIEXPORT jint JNICALL awt_DrawingSurface_Lock(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    jobject target, peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    jint drawState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    target = ds->target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /* Make sure the target is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    componentClass = (*env)->FindClass(env, "java/awt/Component");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
    81
    CHECK_NULL_RETURN(componentClass, (jint)JAWT_LOCK_ERROR);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
    82
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            fprintf(stderr, "Target is not a component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    if (!awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /* Get the peer of the target component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    if (JNU_IsNull(env, peer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        fprintf(stderr, "Component peer is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                AWT_FLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   drawState = (*env)->GetIntField(env, peer, drawStateID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    (*env)->SetIntField(env, peer, drawStateID, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    return drawState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
JNIEXPORT int32_t JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    awt_GetColor(JAWT_DrawingSurface* ds, int32_t r, int32_t g, int32_t b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    jobject target, peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    int32_t result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     jobject gc_object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return (int32_t) 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    target = ds->target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /* Make sure the target is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    componentClass = (*env)->FindClass(env, "java/awt/Component");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   131
    CHECK_NULL_RETURN(componentClass, (int32_t) 0);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   132
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        fprintf(stderr, "DrawingSurface target must be a component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return (int32_t) 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    if (!awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return (int32_t) 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /* Get the peer of the target component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    if (JNU_IsNull(env, peer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        fprintf(stderr, "Component peer is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return (int32_t) 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     /* GraphicsConfiguration object of MComponentPeer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    gc_object = (*env)->GetObjectField(env, peer, graphicsConfigID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    if (gc_object != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        adata = (AwtGraphicsConfigDataPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            JNU_GetLongFieldAsPtr(env, gc_object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                  x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        adata = getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    result = adata->AwtColorMatch(r, g, b, adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * Get the drawing surface info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * The value returned may be cached, but the values may change if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * additional calls to Lock() or Unlock() are made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * Lock() must be called before this can return a valid value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * Returns NULL if an error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * When finished with the returned value, FreeDrawingSurfaceInfo must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
awt_DrawingSurface_GetDrawingSurfaceInfo(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    jobject target, peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    JAWT_X11DrawingSurfaceInfo* px;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    JAWT_DrawingSurfaceInfo* p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    XWindowAttributes attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    target = ds->target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /* Make sure the target is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    componentClass = (*env)->FindClass(env, "java/awt/Component");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   202
    CHECK_NULL_RETURN(componentClass, NULL);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   203
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        fprintf(stderr, "DrawingSurface target must be a component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    if (!awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /* Get the peer of the target component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    if (JNU_IsNull(env, peer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        fprintf(stderr, "Component peer is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
11093
e753252dc8a9 6996291: command line selection of MToolkit by -Dawt.toolkit=sun.awt.motif.MToolkit fails from jdk7 b21 on
serb
parents: 9035
diff changeset
   227
    AWT_UNLOCK();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /* Allocate platform-specific data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    px = (JAWT_X11DrawingSurfaceInfo*)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        malloc(sizeof(JAWT_X11DrawingSurfaceInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /* Set drawable and display */
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   234
    px->drawable = (*env)->GetLongField(env, peer, windowID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    px->display = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /* Get window attributes to set other values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    XGetWindowAttributes(awt_display, (Window)(px->drawable), &attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /* Set the other values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    px->visualID = XVisualIDFromVisual(attrs.visual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    px->colormapID = attrs.colormap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    px->depth = attrs.depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    px->GetAWTColor = awt_GetColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /* Allocate and initialize platform-independent data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    p = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    p->platformInfo = px;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    p->ds = ds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    p->bounds.x = (*env)->GetIntField(env, target, componentIDs.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    p->bounds.y = (*env)->GetIntField(env, target, componentIDs.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    p->bounds.width = (*env)->GetIntField(env, target, componentIDs.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    p->bounds.height = (*env)->GetIntField(env, target, componentIDs.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    p->clipSize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    p->clip = &(p->bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /* Return our new structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * Free the drawing surface info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
awt_DrawingSurface_FreeDrawingSurfaceInfo(JAWT_DrawingSurfaceInfo* dsi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    if (dsi == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        fprintf(stderr, "Drawing Surface Info is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
#endif
8754
0c97cc803f5b 7016131: JDK 7 b127: 8 crashes in native frame:awt_DrawingSurface_FreeDrawingSurfaceInfo+0xc on linux amd64
dav
parents: 7668
diff changeset
   271
        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    free(dsi->platformInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    free(dsi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * Unlock the drawing surface of the target component for native rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
JNIEXPORT void JNICALL awt_DrawingSurface_Unlock(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    AWT_FLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
JNIEXPORT JAWT_DrawingSurface* JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    awt_GetDrawingSurface(JNIEnv* env, jobject target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    JAWT_DrawingSurface* p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /* Make sure the target component is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    componentClass = (*env)->FindClass(env, "java/awt/Component");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   301
    CHECK_NULL_RETURN(componentClass, NULL);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   302
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        fprintf(stderr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            "GetDrawingSurface target must be a java.awt.Component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    p = (JAWT_DrawingSurface*)malloc(sizeof(JAWT_DrawingSurface));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    p->env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    p->target = (*env)->NewGlobalRef(env, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    p->Lock = awt_DrawingSurface_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    p->GetDrawingSurfaceInfo = awt_DrawingSurface_GetDrawingSurfaceInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    p->FreeDrawingSurfaceInfo = awt_DrawingSurface_FreeDrawingSurfaceInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    p->Unlock = awt_DrawingSurface_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    awt_FreeDrawingSurface(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    if (ds == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    (*env)->DeleteGlobalRef(env, ds->target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    free(ds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    awt_Lock(JNIEnv* env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    if (awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    awt_Unlock(JNIEnv* env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    if (awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        AWT_FLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    awt_GetComponent(JNIEnv* env, void* platformInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    Window window = (Window)platformInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    jobject target = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
19366
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   362
    if (window != None) {
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   363
        peer = JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit",
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   364
            "windowToXWindow", "(J)Lsun/awt/X11/XBaseWindow;", (jlong)window).l;
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   365
        if ((*env)->ExceptionCheck(env)) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   366
            AWT_UNLOCK();
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   367
            return (jobject)NULL;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   368
        }
19366
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   369
    }
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   370
    if ((peer != NULL) &&
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   371
        (JNU_IsInstanceOfByName(env, peer, "sun/awt/X11/XWindow") == 1)) {
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   372
        target = (*env)->GetObjectField(env, peer, targetID);
5286ad9a6ff2 7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5
alitvinov
parents: 11093
diff changeset
   373
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (target == NULL) {
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 19366
diff changeset
   376
        (*env)->ExceptionClear(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        JNU_ThrowNullPointerException(env, "NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return (jobject)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    return target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}