Beispiel #1
0
JNIEXPORT void JNICALL
Java_sun_java2d_opengl_GLXGraphicsConfig_initConfig(JNIEnv *env,
                                                    jobject glxgc,
                                                    jlong configInfo)
{
#ifndef HEADLESS
    GLXGraphicsConfigInfo *glxinfo;
    AwtGraphicsConfigDataPtr configData = (AwtGraphicsConfigDataPtr)
	JNU_GetLongFieldAsPtr(env, glxgc, x11GraphicsConfigIDs.aData);

    J2dTraceLn(J2D_TRACE_INFO, "in GLXGraphicsConfig_initConfig");

    if (configData == NULL) {
	JNU_ThrowNullPointerException(env, "Native GraphicsConfig missing");
	return;
    }

    glxinfo = (GLXGraphicsConfigInfo *)jlong_to_ptr(configInfo);
    if (glxinfo == NULL) {
	JNU_ThrowNullPointerException(env,
                                      "GLXGraphicsConfigInfo data missing");
	return;
    }

    configData->glxInfo = glxinfo;
#endif /* !HEADLESS */
}
Beispiel #2
0
static pathData *
MakeSpanData(JNIEnv *env, jobject sr)
{
    pathData *pd = (pathData *) JNU_GetLongFieldAsPtr(env, sr, pSpanDataID);

    if (pd != NULL) {
	JNU_ThrowInternalError(env, "private data already initialized");
	return NULL;
    }

    pd = calloc(1, sizeof(pathData));

    if (pd == NULL) {
	JNU_ThrowOutOfMemoryError(env, "private data");
    } else {
	/* Initialize Ductus object header */
	pd->consumer = &dcShapeSpanIteratorClass;

	/* Initialize ShapeSpanIterator fields */
	pd->first = 1;

	(*env)->SetLongField(env, sr, pSpanDataID, ptr_to_jlong(pd));
    }

    return pd;
}
static AwtGraphicsConfigDataPtr
copyGraphicsConfigToMenuBarPeer(
JNIEnv *env, jobject frame, jobject thisMenuBar) {

    jobject gc_object;
    AwtGraphicsConfigDataPtr adata;

    /* GraphicsConfiguration object of Component */
    gc_object = (*env)->GetObjectField(env, frame,
                                       mComponentPeerIDs.graphicsConfig);

    if (gc_object != NULL) {
        /* Set graphicsConfig field of MComponentPeer */
        (*env)->SetObjectField (env, thisMenuBar,
                                mMenuBarPeerIDs.graphicsConfig,
                                gc_object);
        adata = (AwtGraphicsConfigDataPtr)
            JNU_GetLongFieldAsPtr(env, gc_object,
                                  x11GraphicsConfigIDs.aData);
    } else {
        /* Component was not constructed with a GraphicsConfiguration
           object */
        adata = getDefaultConfig(DefaultScreen(awt_display));
    }

    return adata;
}
Beispiel #4
0
/*
 * Class:     sun_awt_DefaultMouseInfoPeer
 * Method:    isWindowUnderMouse
 * Signature: (Ljava/awt/Window)Z
 */
JNIEXPORT jboolean JNICALL Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse
  (JNIEnv * env, jclass cls, jobject window)
{
    Window rootWindow, childWindow;
    int i;
    int32_t xr, yr, xw, yw;
    uint32_t keys;
    BOOL pointerFound;
    struct FrameData *wdata;
    jobject winPeer;

    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
        return JNI_FALSE;
    }
    winPeer = (*env)->GetObjectField(env, window, componentIDs.peer);
    if (JNU_IsNull(env, winPeer)) {
        return JNI_FALSE;
    }
    wdata = (struct FrameData *)
        JNU_GetLongFieldAsPtr(env, winPeer, mComponentPeerIDs.pData);
    (*env)->DeleteLocalRef(env, winPeer);
    if (wdata == NULL) {
        return JNI_FALSE;
    }

    AWT_LOCK();
    pointerFound = XQueryPointer(awt_display, XtWindow(wdata->winData.shell),
                                 &rootWindow, &childWindow,
                                 &xr, &yr, &xw, &yw, &keys);
    AWT_UNLOCK();
    return pointerFound ? JNI_TRUE : JNI_FALSE;
}
JNIEXPORT int32_t JNICALL
    awt_GetColor(JAWT_DrawingSurface* ds, int32_t r, int32_t g, int32_t b)
{
    JNIEnv* env;
    jobject target, peer;
    jclass componentClass;
    AwtGraphicsConfigDataPtr adata;
    int32_t result;
     jobject gc_object;
    if (ds == NULL) {
#ifdef DEBUG
        fprintf(stderr, "Drawing Surface is NULL\n");
#endif
        return (int32_t) 0;
    }

    env = ds->env;
    target = ds->target;

    /* Make sure the target is a java.awt.Component */
    componentClass = (*env)->FindClass(env, "java/awt/Component");
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
        fprintf(stderr, "DrawingSurface target must be a component\n");
#endif
        return (int32_t) 0;
    }

    if (!awtLockInited) {
        return (int32_t) 0;
    }

    AWT_LOCK();

    /* Get the peer of the target component */
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
    if (JNU_IsNull(env, peer)) {
#ifdef DEBUG
        fprintf(stderr, "Component peer is NULL\n");
#endif
        AWT_UNLOCK();
        return (int32_t) 0;
    }
     /* GraphicsConfiguration object of MComponentPeer */
    gc_object = (*env)->GetObjectField(env, peer, graphicsConfigID);

    if (gc_object != NULL) {
        adata = (AwtGraphicsConfigDataPtr)
            JNU_GetLongFieldAsPtr(env, gc_object,
                                  x11GraphicsConfigIDs.aData);
    } else {
        adata = getDefaultConfig(DefaultScreen(awt_display));
    }

    result = adata->AwtColorMatch(r, g, b, adata);
        AWT_UNLOCK();
        return result;
}
Beispiel #6
0
/*
 * Get the Motif text widget from the text component peer.  XmImGetXIC()
 * function should be issued on Motif text widgets.
 */
static Widget getTextWidget(jobject tc) {
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    if (mTextAreaClass == NULL) {
        jclass localClass = (*env)->FindClass(env, MTEXTAREAPEER_CLASS_NAME);
        mTextAreaClass = (jclass)(*env)->NewGlobalRef(env, localClass);
        (*env)->DeleteLocalRef(env, localClass);
    }

    if ((*env)->IsInstanceOf(env, tc, mTextAreaClass)) {
        struct TextAreaData * tdata = (struct TextAreaData *)
        JNU_GetLongFieldAsPtr(env, tc, mComponentPeerIDs.pData);
        return tdata->txt;
    } else {
        struct ComponentData * tdata = (struct ComponentData *)
        JNU_GetLongFieldAsPtr(env, tc, mComponentPeerIDs.pData);
        return tdata->widget;
    }
}
JNIEXPORT NativePrimitive * JNICALL
GetNativePrim(JNIEnv *env, jobject gp)
{
    NativePrimitive *pPrim;

    pPrim = (NativePrimitive *) JNU_GetLongFieldAsPtr(env, gp, pNativePrimID);
    if (pPrim == NULL) {
        JNU_ThrowInternalError(env, "Non-native Primitive invoked natively");
    }

    return pPrim;
}
Beispiel #8
0
JNIEXPORT void JNICALL
SurfaceData_SetOps(JNIEnv *env, jobject sData, SurfaceDataOps *ops)
{
    if (JNU_GetLongFieldAsPtr(env, sData, pDataID) == NULL) {
        JNU_SetLongFieldFromPtr(env, sData, pDataID, ops);
        /* Register the data for disposal */
        Disposer_AddRecord(env, sData,
                           SurfaceData_DisposeOps,
                           ptr_to_jlong(ops));
    } else {
        JNU_ThrowInternalError(env, "Attempting to set SurfaceData ops twice");
    }
}
Beispiel #9
0
static pathData *
GetSpanData(JNIEnv *env, jobject sr, int minState, int maxState)
{
    pathData *pd = (pathData *) JNU_GetLongFieldAsPtr(env, sr, pSpanDataID);

    if (pd == NULL) {
	JNU_ThrowNullPointerException(env, "private data");
    } else if (pd->state < minState || pd->state > maxState) {
	JNU_ThrowInternalError(env, "bad path delivery sequence");
	pd = NULL;
    }

    return pd;
}
Beispiel #10
0
static void geometry_hook(Widget wid, Widget hooked_widget, XtGeometryHookData call_data) {
    XtWidgetGeometry *request;
    JNIEnv *env;
    struct ChoiceData *cdata;
    struct WidgetInfo *winfo = NULL;

    jobject target;
    jobject parent;
    jint y, height;

    if ((call_data->widget == hooked_widget) &&
        (call_data->type == XtHpostGeometry) &&
        (call_data->result == XtGeometryYes)) {

        request = call_data->request;

        env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
        DASSERT(env != NULL);

        winfo=findWidgetInfo(hooked_widget);

        if (winfo != NULL && XmIsRowColumn(hooked_widget)) {
            target = (*env)->GetObjectField(env, (jobject)winfo->peer, mComponentPeerIDs.target);
            cdata = (struct ChoiceData *) JNU_GetLongFieldAsPtr(env, (jobject)winfo->peer, mComponentPeerIDs.pData);
            DASSERT(target != NULL);
            DASSERT(cdata != NULL && cdata->comp.widget != NULL)
            if (request->request_mode & CWHeight) {
                height = (*env)->GetIntField(env, target, componentIDs.height);
                if (request->height > 0 && request->height != height) {
                  parent = (*env)->CallObjectMethod(env, target, componentIDs.getParent);
                  if ((parent != NULL) && ((*env)->GetObjectField(env, parent, containerIDs.layoutMgr) != NULL)) {
                      y = cdata->bounds_y;
                      if (request->height < cdata->bounds_height) {
                          y += (cdata->bounds_height - request->height) / 2;
                      }
                      XtVaSetValues(hooked_widget, XmNy, y, NULL);
                      (*env)->SetIntField(env, target, componentIDs.y, y);
                  }
                  if (parent != NULL) {
                      (*env)->DeleteLocalRef(env, parent);
                  }
                }
                (*env)->SetIntField(env, target, componentIDs.height, request->height);
            }
            if (request->request_mode & CWWidth) {
                (*env)->SetIntField(env, target, componentIDs.width, request->width);
            }
            (*env)->DeleteLocalRef(env, target);
        }
JNIEXPORT void JNICALL
Java_java_awt_AWTEvent_nativeSetSource(JNIEnv *env, jobject self,
				       jobject newSource)
{
    jbyteArray bdata;

    AWT_LOCK();

    bdata = (jbyteArray)(*env)->GetObjectField(env, self, awtEventIDs.bdata);

    if (bdata != NULL) {
	XEvent *xev;
	Window w;
	jboolean dummy;

	/* get the widget out of the peer newSource */
	struct ComponentData *cdata = (struct ComponentData *)
	    JNU_GetLongFieldAsPtr(env, newSource, mComponentPeerIDs.pData);
	if (JNU_IsNull(env, cdata) || (cdata == NULL) ||
	    ((cdata->widget != NULL) && (XtIsObject(cdata->widget)) &&
	     (cdata->widget->core.being_destroyed))) {
	    JNU_ThrowNullPointerException(env, "null widget");
	    AWT_UNLOCK();
	    return;
	}
	
	/* get the Window out of the widget */
	w = XtWindow(cdata->widget);

	if (w == None) {
	    JNU_ThrowNullPointerException(env, "null window");
	    AWT_UNLOCK();
	    return;
	}

	/* reset the filed in the event */
	xev = (XEvent *)(*env)->GetPrimitiveArrayCritical(env, bdata, &dummy);
	if (xev == NULL) {
	    JNU_ThrowNullPointerException(env, "null data");
	    AWT_UNLOCK();
	    return;
	}
	xev->xany.window = w;
	(*env)->ReleasePrimitiveArrayCritical(env, bdata, (void *)xev, 0);
    }

    AWT_UNLOCK();
}
Beispiel #12
0
/*
 * Class:     sun_awt_DefaultMouseInfoPeer
 * Method:    isWindowUnderMouse
 * Signature: (Ljava/awt/Window)Z
 */
JNIEXPORT jboolean JNICALL Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse
  (JNIEnv * env, jclass cls, jobject window)
{
    Window rootWindow = None, parentWindow = None, siblingWindow = None;
    Window * children = NULL;
    int i = 0;
    int is_the_same_screen = 0;
    int32_t xr = 0, yr = 0, xw = 0, yw = 0;
    uint32_t keys = 0;
    uint32_t nchildren = 0;
    Bool pointerFound = 0;
    struct FrameData *wdata = NULL;
    jobject winPeer = NULL;

    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
        return JNI_FALSE;
    }
    winPeer = (*env)->GetObjectField(env, window, componentIDs.peer);
    if (JNU_IsNull(env, winPeer)) {
        return JNI_FALSE;
    }

    wdata = (struct FrameData *)
        JNU_GetLongFieldAsPtr(env, winPeer, mComponentPeerIDs.pData);
    (*env)->DeleteLocalRef(env, winPeer);

    if (wdata == NULL) {
        return JNI_FALSE;
    }

    AWT_LOCK();

    XQueryTree(awt_display, XtWindow(wdata->winData.comp.widget),
                    &rootWindow, &parentWindow, &children, &nchildren);

    is_the_same_screen = XQueryPointer(awt_display, parentWindow,
            &rootWindow, &siblingWindow, &xr, &yr, &xw, &yw, &keys);

    if (siblingWindow == XtWindow(wdata->winData.comp.widget) && is_the_same_screen) {
        AWT_UNLOCK();
        return JNI_TRUE;
    }

    AWT_UNLOCK();
    return JNI_FALSE ;

}
/*
 * client_data is MFileDialogPeer instance pointer
 */
static void
FileDialog_CANCEL(Widget w,
                  void *client_data,
                  XmFileSelectionBoxCallbackStruct * call_data)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    jobject this = (jobject) client_data;
    struct FrameData *fdata;

    fdata = (struct FrameData *) JNU_GetLongFieldAsPtr(env,this,mComponentPeerIDs.pData);

    JNU_CallMethodByName(env, NULL, (jobject) client_data, "handleCancel", "()V");
    if ((*env)->ExceptionOccurred(env)) {
        (*env)->ExceptionDescribe(env);
        (*env)->ExceptionClear(env);
    }
}
/*
 * client_data is MFileDialogPeer instance pointer
 */
static void
FileDialog_OK(Widget w,
              void *client_data,
              XmFileSelectionBoxCallbackStruct * call_data)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    jobject this = (jobject) client_data;
    struct FrameData *fdata;
    char *file;
    jstring jstr;
    XmStringContext   stringContext;
    XmStringDirection direction;
    XmStringCharSet   charset;
    Boolean           separator;

    fdata = (struct FrameData *)JNU_GetLongFieldAsPtr(env,this,mComponentPeerIDs.pData);

    if ((*env)->EnsureLocalCapacity(env, 1) < 0)
        return;

    if (!XmStringInitContext(&stringContext, call_data->value))
	return;

    if (!XmStringGetNextSegment(stringContext, &file, &charset,
				&direction, &separator))
	file = NULL;

    if (file == NULL)
	jstr = NULL;
    else
	jstr = JNU_NewStringPlatform(env, (const char *) file);

    if (jstr != 0) {
	JNU_CallMethodByName(env, NULL, this, "handleSelected",
			     "(Ljava/lang/String;)V", jstr);
	(*env)->DeleteLocalRef(env, jstr);
    }
    if ((*env)->ExceptionOccurred(env)) {
        (*env)->ExceptionDescribe(env);
        (*env)->ExceptionClear(env);
    }

    XmStringFreeContext(stringContext);
    if (file != NULL)
	XtFree(file);
}
static pxembed_server_data
addData(jobject server) {
    JNIEnv      *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    struct ComponentData *cdata;
    xembed_server_data * data = malloc(sizeof(xembed_server_data));
    DASSERT(server != NULL);
    memset(data, 0, sizeof(xembed_server_data));
    data->server = server;
    cdata = (struct ComponentData *)
        JNU_GetLongFieldAsPtr(env, server, mComponentPeerIDs.pData);
    DASSERT(cdata != NULL);
    data->serverHandle = XtWindow(cdata->widget);
    data->serverWidget = cdata->widget;
    data->next = xembed_list;
    xembed_list = data;
    return data;
}
Beispiel #16
0
static X11InputMethodData * getX11InputMethodData(JNIEnv * env, jobject imInstance) {
    X11InputMethodData *pX11IMData = 
        (X11InputMethodData *)JNU_GetLongFieldAsPtr(env, imInstance, x11InputMethodIDs.pData);

    /*
     * In case the XIM server was killed somehow, reset X11InputMethodData
     */
    if (pX11IMData != NULL && X11im == NULL) {
        JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod,
			 "flushText",
			 "()V");
	freeX11InputMethodData(env, pX11IMData);
	setX11InputMethodData(env, imInstance, NULL);
	pX11IMData = NULL;
    }

    return pX11IMData;
}
AwtGraphicsConfigDataPtr
getGraphicsConfigFromMenuBarPeer(JNIEnv *env, jobject menubarPeer) {

    jobject gc_object;
    AwtGraphicsConfigDataPtr adata;

    /* GraphicsConfiguration object of Component */
    gc_object = (*env)->GetObjectField(env, menubarPeer,
                                       mMenuBarPeerIDs.graphicsConfig);

    if (gc_object != NULL) {
        adata = (AwtGraphicsConfigDataPtr)
            JNU_GetLongFieldAsPtr(env, gc_object,
                                  x11GraphicsConfigIDs.aData);
    } else {
        adata = getDefaultConfig(DefaultScreen(awt_display));
    }

    return adata;
}
Beispiel #18
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_mouseMoveImpl (JNIEnv *env,
                          jclass cls,
                          jobject xgc,
                          jint root_x,
                          jint root_y) {

    AwtGraphicsConfigDataPtr adata;

    AWT_LOCK();

    DTRACE_PRINTLN3("RobotPeer: mouseMoveImpl(%lx, %i, %i)", xgc, root_x, root_y);

    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
    DASSERT(adata != NULL);

    XWarpPointer(awt_display, None, XRootWindow(awt_display, adata->awt_visInfo.screen), 0, 0, 0, 0, root_x, root_y);
    XSync(awt_display, False);

    AWT_UNLOCK();
}
/*
 *  client_data is MMenuItemPeer instance pointer
 */
static void
MenuItem_selected(Widget w, XtPointer client_data, XmAnyCallbackStruct * s)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    jobject this = (jobject) client_data;
    ConvertEventTimeAndModifiers converted;

    awt_util_convertEventTimeAndModifiers(s->event, &converted);

    if ((*env)->GetBooleanField(env, this, mMenuItemPeerIDs.isCheckbox)) {
        jboolean state;
        struct MenuItemData *mdata;

        mdata = (struct MenuItemData *)
	  JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);

        if (mdata != NULL) {
            XtVaGetValues(mdata->comp.widget, XmNset, &state, NULL);

            JNU_CallMethodByName(env, NULL, this
				 ,"action"
				 ,"(J*Z)V"
				 ,converted.when, converted.modifiers,
                                 state);
            if ((*env)->ExceptionOccurred(env)) {
                (*env)->ExceptionDescribe(env);
                (*env)->ExceptionClear(env);
            }
        }
    } else {
        JNU_CallMethodByName(env, NULL, this, "action", "(JI)V",
			     converted.when, converted.modifiers);
        if ((*env)->ExceptionOccurred(env)) {
            (*env)->ExceptionDescribe(env);
            (*env)->ExceptionClear(env);
        }
    }
}
Beispiel #20
0
static SurfaceDataOps *
GetSDOps(JNIEnv *env, jobject sData, jboolean callSetup)
{
    SurfaceDataOps *ops;
    if (JNU_IsNull(env, sData)) {
        JNU_ThrowNullPointerException(env, "surfaceData");
        return NULL;
    }
    ops = (SurfaceDataOps *)JNU_GetLongFieldAsPtr(env, sData, pDataID);
    if (ops == NULL) {
        if (!(*env)->ExceptionOccurred(env) &&
            !(*env)->IsInstanceOf(env, sData, pNullSurfaceDataClass))
        {
            if (!(*env)->GetBooleanField(env, sData, validID)) {
                SurfaceData_ThrowInvalidPipeException(env, "invalid data");
            } else {
                JNU_ThrowNullPointerException(env, "native ops missing");
            }
        }
    } else if (callSetup) {
        SurfaceData_InvokeSetup(env, ops);
    }
    return ops;
}
JNIEXPORT void JNICALL
Java_sun_java2d_opengl_GLXSurfaceData_initOps(JNIEnv *env, jobject glxsd,
                                              jobject peer, jlong aData)
{
#ifndef HEADLESS
    OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
                                                       sizeof(OGLSDOps));
    GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));

    J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");

    if (glxsdo == NULL) {
        JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
        return;
    }

    oglsdo->privOps = glxsdo;

    oglsdo->sdOps.Lock       = OGLSD_Lock;
    oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo;
    oglsdo->sdOps.Unlock     = OGLSD_Unlock;
    oglsdo->sdOps.Dispose    = OGLSD_Dispose;

    oglsdo->drawableType = OGLSD_UNDEFINED;
    oglsdo->activeBuffer = GL_FRONT;
    oglsdo->needsInit = JNI_TRUE;

#ifdef XAWT
    if (peer != NULL) {
        glxsdo->window = JNU_CallMethodByName(env, NULL, peer,
                                              "getContentWindow", "()J").j;
    } else {
        glxsdo->window = 0;
    }
#else
    if (peer != NULL) {
        struct ComponentData *cdata;
        cdata = (struct ComponentData *)
            JNU_GetLongFieldAsPtr(env, peer, mComponentPeerIDs.pData);
        if (cdata == NULL) {
            free(glxsdo);
            JNU_ThrowNullPointerException(env, "Component data missing");
            return;
        }
        if (cdata->widget == NULL) {
            free(glxsdo);
            JNU_ThrowInternalError(env, "Widget is NULL in initOps");
            return;
        }
        glxsdo->widget = cdata->widget;
    } else {
        glxsdo->widget = NULL;
    }
#endif

    glxsdo->configData = (AwtGraphicsConfigDataPtr)jlong_to_ptr(aData);
    if (glxsdo->configData == NULL) {
        free(glxsdo);
        JNU_ThrowNullPointerException(env,
                                 "Native GraphicsConfig data block missing");
        return;
    }

    if (glxsdo->configData->glxInfo == NULL) {
        free(glxsdo);
        JNU_ThrowNullPointerException(env, "GLXGraphicsConfigInfo missing");
        return;
    }
#endif /* HEADLESS */
}
Beispiel #22
0
JNIEXPORT void JNICALL Java_sun_awt_motif_MRobotPeer_getRGBPixelsImpl(
		             JNIEnv *env,
		             jclass cls,
		             jobject xgc,
		             jint x,
		             jint y,
		             jint width,
		             jint height,
		             jintArray pixelArray) {
    RCmdGetPixels cmd;
    RResultPixelHeader result;
    int row;
    int col;
    unsigned int *ary;
    AwtGraphicsConfigDataPtr adata;

    DTRACE_PRINTLN7("%lx: MRobotPeer.getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", cls, xgc, x, y, width, height, pixelArray);
    /* avoid a lot of work for empty rectangles */
    if ( (width * height) == 0 ) {
	return;
    }
    DASSERT(width * height > 0); /* only allow positive size */

    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
    DASSERT(adata != NULL);

    cmd.code = RCMD_GETPIXELS;
    cmd.screen = adata->awt_visInfo.screen;
    cmd.x = x;
    cmd.y = y;
    cmd.width = width;
    cmd.height = height;

    robot_writeChildCommand((RCmdBase *)&cmd);

    /*
     * For getPixels, there is data to receive
     * from the child process.    The following sequence
     * must match the sequence in the getPixels method.
     *
     * The robot_readBytes function automatically provides
     * synchronization with the sending of data
     * back to us.
     */

    DTRACE_PRINTLN("PARENT: Waiting for pixels ...");

    robot_getChildResult((char *)&result, sizeof(result));

    DTRACE_PRINTLN2("PARENT: Got pixels header %d x %d", result.nRows, result.nCols);

    if (result.code == RES_OUTOFMEMORY) {
	JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
	return;
    }

    ary = (unsigned int *)XtMalloc(height * width * sizeof(jint));
    if (ary == NULL) {
	JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
	/* eat up the data in the pipe so things remain in sync */
	robot_flushChildResult();
	return;
    }

    DASSERT(result.nRows == height && result.nCols == width);
    robot_getChildResult((char *)ary, (jint) (height * width * sizeof (jint)));

    (*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, (jint *)ary);

    XtFree((char *)ary);
}
Beispiel #23
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
                             jclass cls,
                             jobject xgc,
                             jint x,
                             jint y,
                             jint width,
                             jint height,
                             jintArray pixelArray) {

    XImage *image;
    jint *ary;               /* Array of jints for sending pixel values back
                              * to parent process.
                              */
    Window rootWindow;
    AwtGraphicsConfigDataPtr adata;

    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray);

    AWT_LOCK();

    /* avoid a lot of work for empty rectangles */
    if ((width * height) == 0) {
        AWT_UNLOCK();
        return;
    }
    DASSERT(width * height > 0); /* only allow positive size */

    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
    DASSERT(adata != NULL);

    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
    image = getWindowImage(awt_display, rootWindow, x, y, width, height);

    /* Array to use to crunch around the pixel values */
    ary = (jint *) malloc(width * height * sizeof (jint));
    if (ary == NULL) {
        JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
        XDestroyImage(image);
        AWT_UNLOCK();
        return;
    }
    /* convert to Java ARGB pixels */
    for (y = 0; y < height; y++) {
        for (x = 0; x < width; x++) {
            jint pixel = (jint) XGetPixel(image, x, y); /* Note ignore upper
                                                         * 32-bits on 64-bit
                                                         * OSes.
                                                         */

            pixel |= 0xff000000; /* alpha - full opacity */

            ary[(y * width) + x] = pixel;
        }
    }
    (*env)->SetIntArrayRegion(env, pixelArray, 0, height * width, ary);
    free(ary);

    XDestroyImage(image);

    AWT_UNLOCK();
}
Beispiel #24
0
/*
 * Get the drawing surface info.
 * The value returned may be cached, but the values may change if
 * additional calls to Lock() or Unlock() are made.
 * Lock() must be called before this can return a valid value.
 * Returns NULL if an error has occurred.
 * When finished with the returned value, FreeDrawingSurfaceInfo must be
 * called.
 */
JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL
awt_DrawingSurface_GetDrawingSurfaceInfo(JAWT_DrawingSurface* ds)
{
    JNIEnv* env;
    jobject target, peer;
    jclass componentClass;
    JAWT_X11DrawingSurfaceInfo* px;
    JAWT_DrawingSurfaceInfo* p;
#ifndef XAWT    
    struct ComponentData *cdata;
#endif
    XWindowAttributes attrs;

    if (ds == NULL) {
#ifdef DEBUG
        fprintf(stderr, "Drawing Surface is NULL\n");
#endif
        return NULL;
    }

    env = ds->env;
    target = ds->target;

    /* Make sure the target is a java.awt.Component */
    componentClass = (*env)->FindClass(env, "java/awt/Component");
    if (!(*env)->IsInstanceOf(env, target, componentClass)) {
#ifdef DEBUG
        fprintf(stderr, "DrawingSurface target must be a component\n");
#endif
        return NULL;
	}

    if (!awtLockInited) {
        return NULL;
    }

    AWT_LOCK();

    /* Get the peer of the target component */
    peer = (*env)->GetObjectField(env, target, componentIDs.peer);
    if (JNU_IsNull(env, peer)) {
#ifdef DEBUG
        fprintf(stderr, "Component peer is NULL\n");
#endif
		AWT_UNLOCK();
        return NULL;
    }

#ifndef XAWT
    /* Get the component data from the peer */
    cdata = (struct ComponentData *)
        JNU_GetLongFieldAsPtr(env, peer, mComponentPeerIDs.pData);
    if (cdata == NULL) {
#ifdef DEBUG
        fprintf(stderr, "Component data is NULL\n");
#endif
		AWT_UNLOCK();
        return NULL;
    }
#endif

	AWT_UNLOCK();

    /* Allocate platform-specific data */
    px = (JAWT_X11DrawingSurfaceInfo*)
        malloc(sizeof(JAWT_X11DrawingSurfaceInfo));

    /* Set drawable and display */
#ifndef XAWT    
    px->drawable = XtWindow(cdata->widget);
#else
    px->drawable = JNU_GetLongFieldAsPtr(env, peer, windowID);
#endif    
    px->display = awt_display;

    /* Get window attributes to set other values */
    XGetWindowAttributes(awt_display, (Window)(px->drawable), &attrs);

    /* Set the other values */
    px->visualID = XVisualIDFromVisual(attrs.visual);
    px->colormapID = attrs.colormap;
    px->depth = attrs.depth;
    px->GetAWTColor = awt_GetColor;

    /* Allocate and initialize platform-independent data */
    p = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo));
    p->platformInfo = px;
    p->ds = ds;
    p->bounds.x = (*env)->GetIntField(env, target, componentIDs.x);
    p->bounds.y = (*env)->GetIntField(env, target, componentIDs.y);
    p->bounds.width = (*env)->GetIntField(env, target, componentIDs.width);
    p->bounds.height = (*env)->GetIntField(env, target, componentIDs.height);
    p->clipSize = 1;
    p->clip = &(p->bounds);

    /* Return our new structure */
    return p;
}
Beispiel #25
0
/*
 * A utility to retrieve cursor from java.awt.Cursor
 * Create and save the cursor first if it is not yet 
 */
Cursor getCursor(JNIEnv *env, jobject jCur)
{
    int32_t cursorType = 0;
    Cursor  xcursor;
    
    xcursor = (Cursor)JNU_GetLongFieldAsPtr(env, jCur, cursorIDs.pData);
    
    if (xcursor != NULL) {
	return xcursor;
    }
    
    cursorType = (*env)->GetIntField(env, jCur, cursorIDs.type);
    
    DASSERT(cursorType != java_awt_Cursor_CUSTOM_CURSOR);
    
    switch (cursorType) {
    case java_awt_Cursor_DEFAULT_CURSOR:
	cursorType = XC_left_ptr;
        break;
    case java_awt_Cursor_CROSSHAIR_CURSOR:
	cursorType = XC_crosshair;
        break;
    case java_awt_Cursor_TEXT_CURSOR:
	cursorType = XC_xterm;
        break;
    case java_awt_Cursor_WAIT_CURSOR:
	cursorType = XC_watch;
        break;
    case java_awt_Cursor_SW_RESIZE_CURSOR:
	cursorType = XC_bottom_left_corner;
        break;
    case java_awt_Cursor_NW_RESIZE_CURSOR:
	cursorType = XC_top_left_corner;
        break;
    case java_awt_Cursor_SE_RESIZE_CURSOR:
	cursorType = XC_bottom_right_corner;
        break;
    case java_awt_Cursor_NE_RESIZE_CURSOR:
	cursorType = XC_top_right_corner;
        break;
    case java_awt_Cursor_S_RESIZE_CURSOR:
	cursorType = XC_bottom_side;
        break;
    case java_awt_Cursor_N_RESIZE_CURSOR:
	cursorType = XC_top_side;
        break;
    case java_awt_Cursor_W_RESIZE_CURSOR:
	cursorType = XC_left_side;
        break;
    case java_awt_Cursor_E_RESIZE_CURSOR:
	cursorType = XC_right_side;
        break;
    case java_awt_Cursor_HAND_CURSOR:
	cursorType = XC_hand2;
        break;
    case java_awt_Cursor_MOVE_CURSOR:
	cursorType = XC_fleur;
        break;
    }
    xcursor = XCreateFontCursor(awt_display, cursorType);
    
    JNU_SetLongFieldFromPtr(env, jCur, cursorIDs.pData, xcursor);
    return xcursor;
}
Beispiel #26
0
    
    JNU_SetLongFieldFromPtr(env, jCur, cursorIDs.pData, xcursor);
    return xcursor;
}

/*
 * Class:     java_awt_Cursor
 * Method:    finalizeImpl
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_java_awt_Cursor_finalizeImpl(JNIEnv *env, jobject this)
{
    Cursor xcursor;
    
    xcursor = (Cursor)JNU_GetLongFieldAsPtr(env, this, cursorIDs.pData);
    if (xcursor != NULL) {
        AWT_LOCK();
	JNU_SetLongFieldFromPtr(env, this, cursorIDs.pData, 0);
	XFreeCursor(awt_display, xcursor);
        AWT_UNLOCK();
    }
}

/*
 *  normal replace : CACHE_UDPATE  => update curComp and updateCursor
 *  not replace    : UPDATE_ONLY   => intact curComp but updateCursor
 *  only replace   : CACHE_ONLY    => update curComp only, not updateCursor 
 *
 *  This function should only be called under AWT_LOCK(). Otherwise
 *  multithreaded access can corrupt the value of curComp variable.
Beispiel #27
0
JNIEXPORT void JNICALL
Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
                             jclass cls,
                             jobject xgc,
                             jint jx,
                             jint jy,
                             jint jwidth,
                             jint jheight,
                             jint scale,
                             jintArray pixelArray,
                             jboolean useGtk) {
    XImage *image;
    jint *ary;               /* Array of jints for sending pixel values back
                              * to parent process.
                              */
    Window rootWindow;
    XWindowAttributes attr;
    AwtGraphicsConfigDataPtr adata;

    DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray);

    if (jwidth <= 0 || jheight <= 0) {
        return;
    }

    adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
    DASSERT(adata != NULL);

    AWT_LOCK();

    jint sx = jx * scale;
    jint sy = jy * scale;
    jint swidth = jwidth * scale;
    jint sheight = jheight * scale;

    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);

    if (!useGtk) {
        if (hasXCompositeOverlayExtension(awt_display) &&
            isXCompositeDisplay(awt_display, adata->awt_visInfo.screen))
        {
            rootWindow = compositeGetOverlayWindow(awt_display, rootWindow);
        }
    }

    if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
            || sx + swidth <= attr.x
            || attr.x + attr.width <= sx
            || sy + sheight <= attr.y
            || attr.y + attr.height <= sy) {

        AWT_UNLOCK();
        return; // Does not intersect with root window
    }

    gboolean gtk_failed = TRUE;
    jint _x, _y;

    jint x = MAX(sx, attr.x);
    jint y = MAX(sy, attr.y);
    jint width = MIN(sx + swidth, attr.x + attr.width) - x;
    jint height = MIN(sy + sheight, attr.y + attr.height) - y;


    int dx = attr.x > sx ? attr.x - sx : 0;
    int dy = attr.y > sy ? attr.y - sy : 0;

    int index;

    if (useGtk) {
        gtk->gdk_threads_enter();
        gtk_failed = gtk->get_drawable_data(env, pixelArray, x, y, width,
                                            height, jwidth, dx, dy, scale);
        gtk->gdk_threads_leave();
    }

    if (gtk_failed) {
        image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight);

        ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);

        if (!ary) {
            XDestroyImage(image);
            AWT_UNLOCK();
            return;
        }

        dx /= scale;
        dy /= scale;
        width /= scale;
        height /= scale;

        /* convert to Java ARGB pixels */
        for (_y = 0; _y < height; _y++) {
            for (_x = 0; _x < width; _x++) {
                jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale);
                                                              /* Note ignore upper
                                                               * 32-bits on 64-bit
                                                               * OSes.
                                                               */
                pixel |= 0xff000000; /* alpha - full opacity */

                index = (_y + dy) * jwidth + (_x + dx);
                ary[index] = pixel;
            }
        }

        XDestroyImage(image);
        (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
    }
    AWT_UNLOCK();
}
Beispiel #28
0
struct FontData *
awtJNI_GetFontData(JNIEnv * env, jobject font, char **errmsg)
{
    /* We are going to create at most 4 outstanding local refs in this
     * function. */
    if ((*env)->EnsureLocalCapacity(env, 4) < 0) {
        return NULL;
    }

    if (!JNU_IsNull(env, font) && awtJNI_IsMultiFont(env, font)) {
        struct FontData *fdata = NULL;
        int32_t i, size;
        char *fontsetname = NULL;
        char *nativename = NULL;
        jobjectArray componentFonts = NULL;
        jobject peer = NULL;
        jobject fontDescriptor = NULL;
        jstring fontDescriptorName = NULL;
        jstring charsetName = NULL;

        fdata = (struct FontData *) JNU_GetLongFieldAsPtr(env,font,
                                                         fontIDs.pData);

        if (fdata != NULL && fdata->flist != NULL) {
            return fdata;
        }
        size = (*env)->GetIntField(env, font, fontIDs.size);
        fdata = (struct FontData *) malloc(sizeof(struct FontData));

        peer = (*env)->CallObjectMethod(env, font, fontIDs.getPeer);

        componentFonts =
          (*env)->GetObjectField(env, peer, platformFontIDs.componentFonts);
        /* We no longer need peer */
        (*env)->DeleteLocalRef(env, peer);

        fdata->charset_num = (*env)->GetArrayLength(env, componentFonts);

        fdata->flist = (awtFontList *) malloc(sizeof(awtFontList)
                                              * fdata->charset_num);
        fdata->xfont = NULL;
        for (i = 0; i < fdata->charset_num; i++) {
            /*
             * set xlfd name
             */

            fontDescriptor = (*env)->GetObjectArrayElement(env, componentFonts, i);
            fontDescriptorName =
              (*env)->GetObjectField(env, fontDescriptor,
                                     fontDescriptorIDs.nativeName);

            if (!JNU_IsNull(env, fontDescriptorName)) {
                nativename = (char *) JNU_GetStringPlatformChars(env, fontDescriptorName, NULL);
            } else {
                nativename = "";
            }

            fdata->flist[i].xlfd = malloc(strlen(nativename)
                                          + strlen(defaultXLFD));
            jio_snprintf(fdata->flist[i].xlfd, strlen(nativename) + 10,
                         nativename, size * 10);

            if (nativename != NULL && nativename != "")
                JNU_ReleaseStringPlatformChars(env, fontDescriptorName, (const char *) nativename);

            /*
             * set charset_name
             */

            charsetName =
              (*env)->GetObjectField(env, fontDescriptor,
                                     fontDescriptorIDs.charsetName);

            fdata->flist[i].charset_name = (char *)
                JNU_GetStringPlatformChars(env, charsetName, NULL);

            /* We are done with the objects. */
            (*env)->DeleteLocalRef(env, fontDescriptor);
            (*env)->DeleteLocalRef(env, fontDescriptorName);
            (*env)->DeleteLocalRef(env, charsetName);

            /*
             * set load & XFontStruct
             */
            fdata->flist[i].load = 0;

            /*
             * This appears to be a bogus check.  The actual intent appears
             * to be to find out whether this is the "base" font in a set,
             * rather than iso8859_1 explicitly.  Note that iso8859_15 will
             * and must also pass this test.
             */

            if (fdata->xfont == NULL &&
                strstr(fdata->flist[i].charset_name, "8859_1")) {
                fdata->flist[i].xfont =
                    loadFont(awt_display, fdata->flist[i].xlfd, size * 10);
                if (fdata->flist[i].xfont != NULL) {
                    fdata->flist[i].load = 1;
                    fdata->xfont = fdata->flist[i].xfont;
                    fdata->flist[i].index_length = 1;
                } else {
                    if (errmsg != NULL) {
                        *errmsg = "java/lang" "NullPointerException";
                    }
                    (*env)->DeleteLocalRef(env, componentFonts);
                    return NULL;
                }
            }
        }
        (*env)->DeleteLocalRef(env, componentFonts);
        /*
         * XFontSet will create if the peer of TextField/TextArea
         * are used.
         */
        fdata->xfs = NULL;

        JNU_SetLongFieldFromPtr(env,font,fontIDs.pData,fdata);
        Disposer_AddRecord(env, font, pDataDisposeMethod, ptr_to_jlong(fdata));
        return fdata;
    } else {
        Display *display = NULL;
        struct FontData *fdata = NULL;
        char fontSpec[1024];
        int32_t height;
        int32_t oheight;
        int32_t above = 0;              /* tries above height */
        int32_t below = 0;              /* tries below height */
        char *foundry = NULL;
        char *name = NULL;
        char *encoding = NULL;
        char *style = NULL;
        XFontStruct *xfont = NULL;
        jstring family = NULL;

        if (JNU_IsNull(env, font)) {
            if (errmsg != NULL) {
                *errmsg = "java/lang" "NullPointerException";
            }
            return (struct FontData *) NULL;
        }
        display = XDISPLAY;

        fdata = (struct FontData *) JNU_GetLongFieldAsPtr(env,font,fontIDs.pData);
        if (fdata != NULL && fdata->xfont != NULL) {
            return fdata;
        }

        family = (*env)->CallObjectMethod(env, font, fontIDs.getFamily);

        if (!awtJNI_FontName(env, family, &foundry, &name, &encoding)) {
            if (errmsg != NULL) {
                *errmsg = "java/lang" "NullPointerException";
            }
            (*env)->DeleteLocalRef(env, family);
            return (struct FontData *) NULL;
        }
        style = Style((*env)->GetIntField(env, font, fontIDs.style));
        oheight = height = (*env)->GetIntField(env, font, fontIDs.size);

        while (1) {
            jio_snprintf(fontSpec, sizeof(fontSpec), "-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
                         foundry,
                         name,
                         style,
                         height,
                         encoding);

            /*fprintf(stderr,"LoadFont: %s\n", fontSpec); */
            xfont = XLoadQueryFont(display, fontSpec);

            /* XXX: sometimes XLoadQueryFont returns a bogus font structure */
            /* with negative ascent. */
            if (xfont == (Font) NULL || xfont->ascent < 0) {
                if (xfont != NULL) {
                    XFreeFont(display, xfont);
                }
                if (foundry != anyfoundry) {  /* Use ptr comparison here, not strcmp */
                    /* Try any other foundry before messing with the sizes */
                    foundry = anyfoundry;
                    continue;
                }
                /* We couldn't find the font. We'll try to find an */
                /* alternate by searching for heights above and below our */
                /* preferred height. We try for 4 heights above and below. */
                /* If we still can't find a font we repeat the algorithm */
                /* using misc-fixed as the font. If we then fail, then we */
                /* give up and signal an error. */
                if (above == below) {
                    above++;
                    height = oheight + above;
                } else {
                    below++;
                    if (below > 4) {
                        if (name != defaultfontname || style != anystyle) {
                            name = defaultfontname;
                            foundry = defaultfoundry;
                            height = oheight;
                            style = anystyle;
                            encoding = isolatin1;
                            above = below = 0;
                            continue;
                        } else {
                            if (errmsg != NULL) {
                                *errmsg = "java/io/" "FileNotFoundException";
                            }
                            (*env)->DeleteLocalRef(env, family);
                            return (struct FontData *) NULL;
                        }
                    }
                    height = oheight - below;
                }
                continue;
            } else {
                fdata = ZALLOC(FontData);

                if (fdata == NULL) {
                    if (errmsg != NULL) {
                        *errmsg = "java/lang" "OutOfMemoryError";
                    }
                } else {
                    fdata->xfont = xfont;
                    JNU_SetLongFieldFromPtr(env,font,fontIDs.pData,fdata);
                    Disposer_AddRecord(env, font, pDataDisposeMethod,
                                       ptr_to_jlong(fdata));
                }
                (*env)->DeleteLocalRef(env, family);
                return fdata;
            }
        }
        /* not reached */
    }
}