jdk/src/solaris/native/sun/awt/awt_DrawingSurface.c
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8754 0c97cc803f5b
child 11093 e753252dc8a9
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8754
diff changeset
     2
 * Copyright (c) 1996, 2011, 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"
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
    32
//#include "sun_awt_motif_MComponentPeer.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <jawt_md.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
extern struct MComponentPeerIDs mComponentPeerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
extern struct ComponentIDs componentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
extern AwtGraphicsConfigDataPtr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#ifdef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include "awt_GraphicsEnv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
extern jfieldID windowID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
extern jfieldID targetID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
extern jfieldID graphicsConfigID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
extern jfieldID drawStateID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Lock the surface of the target component for native rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * When finished drawing, the surface must be unlocked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Unlock().  This function returns a bitmask with one or more of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * JAWT_LOCK_ERROR - When an error has occurred and the surface could not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * be locked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
JNIEXPORT jint JNICALL awt_DrawingSurface_Lock(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    jobject target, peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jint drawState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    target = ds->target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /* Make sure the target is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    componentClass = (*env)->FindClass(env, "java/awt/Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            fprintf(stderr, "Target is not a component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    if (!awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /* Get the peer of the target component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    if (JNU_IsNull(env, peer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        fprintf(stderr, "Component peer is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                AWT_FLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return (jint)JAWT_LOCK_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    drawState = (*env)->GetIntField(env, peer, mComponentPeerIDs.drawState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    (*env)->SetIntField(env, peer, mComponentPeerIDs.drawState, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
   drawState = (*env)->GetIntField(env, peer, drawStateID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    (*env)->SetIntField(env, peer, drawStateID, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    return drawState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
JNIEXPORT int32_t JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    awt_GetColor(JAWT_DrawingSurface* ds, int32_t r, int32_t g, int32_t b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jobject target, peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    int32_t result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#ifdef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     jobject gc_object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        fprintf(stderr, "Drawing Surface is NULL\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
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    target = ds->target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /* Make sure the target is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    componentClass = (*env)->FindClass(env, "java/awt/Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        fprintf(stderr, "DrawingSurface target must be a component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return (int32_t) 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    if (!awtLockInited) {
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /* Get the peer of the target component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    if (JNU_IsNull(env, peer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        fprintf(stderr, "Component peer is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return (int32_t) 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    adata = getGraphicsConfigFromComponentPeer(env, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     /* GraphicsConfiguration object of MComponentPeer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    gc_object = (*env)->GetObjectField(env, peer, graphicsConfigID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    if (gc_object != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        adata = (AwtGraphicsConfigDataPtr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            JNU_GetLongFieldAsPtr(env, gc_object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                  x11GraphicsConfigIDs.aData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        adata = getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    result = adata->AwtColorMatch(r, g, b, adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * Get the drawing surface info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * The value returned may be cached, but the values may change if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * additional calls to Lock() or Unlock() are made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * Lock() must be called before this can return a valid value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * Returns NULL if an error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * When finished with the returned value, FreeDrawingSurfaceInfo must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
awt_DrawingSurface_GetDrawingSurfaceInfo(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    jobject target, peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    JAWT_X11DrawingSurfaceInfo* px;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    JAWT_DrawingSurfaceInfo* p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    struct ComponentData *cdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    XWindowAttributes attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    target = ds->target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* Make sure the target is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    componentClass = (*env)->FindClass(env, "java/awt/Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        fprintf(stderr, "DrawingSurface target must be a component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    if (!awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /* Get the peer of the target component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    if (JNU_IsNull(env, peer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        fprintf(stderr, "Component peer is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /* Get the component data from the peer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    cdata = (struct ComponentData *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        JNU_GetLongFieldAsPtr(env, peer, mComponentPeerIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    if (cdata == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        fprintf(stderr, "Component data is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /* Allocate platform-specific data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    px = (JAWT_X11DrawingSurfaceInfo*)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        malloc(sizeof(JAWT_X11DrawingSurfaceInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /* Set drawable and display */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    px->drawable = XtWindow(cdata->widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
#else
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   267
    px->drawable = (*env)->GetLongField(env, peer, windowID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    px->display = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /* Get window attributes to set other values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    XGetWindowAttributes(awt_display, (Window)(px->drawable), &attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /* Set the other values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    px->visualID = XVisualIDFromVisual(attrs.visual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    px->colormapID = attrs.colormap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    px->depth = attrs.depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    px->GetAWTColor = awt_GetColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /* Allocate and initialize platform-independent data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    p = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    p->platformInfo = px;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    p->ds = ds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    p->bounds.x = (*env)->GetIntField(env, target, componentIDs.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    p->bounds.y = (*env)->GetIntField(env, target, componentIDs.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    p->bounds.width = (*env)->GetIntField(env, target, componentIDs.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    p->bounds.height = (*env)->GetIntField(env, target, componentIDs.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    p->clipSize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    p->clip = &(p->bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /* Return our new structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * Free the drawing surface info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
awt_DrawingSurface_FreeDrawingSurfaceInfo(JAWT_DrawingSurfaceInfo* dsi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if (dsi == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        fprintf(stderr, "Drawing Surface Info is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
#endif
8754
0c97cc803f5b 7016131: JDK 7 b127: 8 crashes in native frame:awt_DrawingSurface_FreeDrawingSurfaceInfo+0xc on linux amd64
dav
parents: 7668
diff changeset
   305
        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    free(dsi->platformInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    free(dsi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * Unlock the drawing surface of the target component for native rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
JNIEXPORT void JNICALL awt_DrawingSurface_Unlock(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    if (ds == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    AWT_FLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
JNIEXPORT JAWT_DrawingSurface* JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    awt_GetDrawingSurface(JNIEnv* env, jobject target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    jclass componentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    JAWT_DrawingSurface* p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /* Make sure the target component is a java.awt.Component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    componentClass = (*env)->FindClass(env, "java/awt/Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        fprintf(stderr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            "GetDrawingSurface target must be a java.awt.Component\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    p = (JAWT_DrawingSurface*)malloc(sizeof(JAWT_DrawingSurface));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    p->env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    p->target = (*env)->NewGlobalRef(env, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    p->Lock = awt_DrawingSurface_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    p->GetDrawingSurfaceInfo = awt_DrawingSurface_GetDrawingSurfaceInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    p->FreeDrawingSurfaceInfo = awt_DrawingSurface_FreeDrawingSurfaceInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    p->Unlock = awt_DrawingSurface_Unlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    return p;
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 void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    awt_FreeDrawingSurface(JAWT_DrawingSurface* ds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    JNIEnv* env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    if (ds == NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        fprintf(stderr, "Drawing Surface is NULL\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    env = ds->env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    (*env)->DeleteGlobalRef(env, ds->target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    free(ds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    awt_Lock(JNIEnv* env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    if (awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    awt_Unlock(JNIEnv* env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    if (awtLockInited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        AWT_FLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    awt_GetComponent(JNIEnv* env, void* platformInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    Window window = (Window)platformInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    Widget widget = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    jobject peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    jobject target = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
#ifndef XAWT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if (window != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        widget = XtWindowToWidget(awt_display, window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    if (widget != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        XtVaGetValues (widget, XmNuserData, &peer, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    if (peer != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        target = (*env)->GetObjectField(env, peer, mComponentPeerIDs.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    target =  (*env)->GetObjectField(env, peer, targetID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    if (target == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        JNU_ThrowNullPointerException(env, "NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return (jobject)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    return target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
}