0N/A/*
3909N/A * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifdef HEADLESS
0N/A #error This file should not be included in headless library
0N/A#endif
0N/A
0N/A#include "awt_p.h"
0N/A#include "java_awt_Component.h"
547N/A//#include "sun_awt_motif_MComponentPeer.h"
0N/A
0N/A#include "awt_Component.h"
0N/A
0N/A
0N/A#include <jni.h>
0N/A#include <jni_util.h>
0N/A#include <jawt_md.h>
0N/A
0N/Aextern struct MComponentPeerIDs mComponentPeerIDs;
0N/Aextern struct ComponentIDs componentIDs;
0N/A#ifndef XAWT
0N/Aextern AwtGraphicsConfigDataPtr
0N/AgetGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
0N/A#endif
0N/A
0N/A#ifdef XAWT
0N/A#include "awt_GraphicsEnv.h"
0N/Aextern jfieldID windowID;
0N/Aextern jfieldID targetID;
0N/Aextern jfieldID graphicsConfigID;
0N/Aextern jfieldID drawStateID;
0N/Aextern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
0N/A#endif
0N/A
0N/A/*
0N/A * Lock the surface of the target component for native rendering.
0N/A * When finished drawing, the surface must be unlocked with
0N/A * Unlock(). This function returns a bitmask with one or more of the
0N/A * following values:
0N/A *
0N/A * JAWT_LOCK_ERROR - When an error has occurred and the surface could not
0N/A * be locked.
0N/A *
0N/A * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
0N/A *
0N/A * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
0N/A *
0N/A * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
0N/A */
0N/AJNIEXPORT jint JNICALL awt_DrawingSurface_Lock(JAWT_DrawingSurface* ds)
0N/A{
0N/A JNIEnv* env;
0N/A jobject target, peer;
0N/A jclass componentClass;
0N/A jint drawState;
0N/A
0N/A if (ds == NULL) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Drawing Surface is NULL\n");
0N/A#endif
0N/A return (jint)JAWT_LOCK_ERROR;
0N/A }
0N/A env = ds->env;
0N/A target = ds->target;
0N/A
0N/A /* Make sure the target is a java.awt.Component */
0N/A componentClass = (*env)->FindClass(env, "java/awt/Component");
0N/A if (!(*env)->IsInstanceOf(env, target, componentClass)) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Target is not a component\n");
0N/A#endif
0N/A return (jint)JAWT_LOCK_ERROR;
0N/A }
0N/A
0N/A if (!awtLockInited) {
0N/A return (jint)JAWT_LOCK_ERROR;
0N/A }
0N/A AWT_LOCK();
0N/A
0N/A /* Get the peer of the target component */
0N/A peer = (*env)->GetObjectField(env, target, componentIDs.peer);
0N/A if (JNU_IsNull(env, peer)) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Component peer is NULL\n");
0N/A#endif
0N/A AWT_FLUSH_UNLOCK();
0N/A return (jint)JAWT_LOCK_ERROR;
0N/A }
0N/A
0N/A#ifndef XAWT
0N/A drawState = (*env)->GetIntField(env, peer, mComponentPeerIDs.drawState);
0N/A (*env)->SetIntField(env, peer, mComponentPeerIDs.drawState, 0);
0N/A#else
0N/A drawState = (*env)->GetIntField(env, peer, drawStateID);
0N/A (*env)->SetIntField(env, peer, drawStateID, 0);
0N/A#endif
0N/A return drawState;
0N/A}
0N/A
0N/AJNIEXPORT int32_t JNICALL
0N/A awt_GetColor(JAWT_DrawingSurface* ds, int32_t r, int32_t g, int32_t b)
0N/A{
0N/A JNIEnv* env;
0N/A jobject target, peer;
0N/A jclass componentClass;
0N/A AwtGraphicsConfigDataPtr adata;
0N/A int32_t result;
0N/A#ifdef XAWT
0N/A jobject gc_object;
0N/A#endif
0N/A if (ds == NULL) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Drawing Surface is NULL\n");
0N/A#endif
0N/A return (int32_t) 0;
0N/A }
0N/A
0N/A env = ds->env;
0N/A target = ds->target;
0N/A
0N/A /* Make sure the target is a java.awt.Component */
0N/A componentClass = (*env)->FindClass(env, "java/awt/Component");
0N/A if (!(*env)->IsInstanceOf(env, target, componentClass)) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "DrawingSurface target must be a component\n");
0N/A#endif
0N/A return (int32_t) 0;
0N/A }
0N/A
0N/A if (!awtLockInited) {
0N/A return (int32_t) 0;
0N/A }
0N/A
0N/A AWT_LOCK();
0N/A
0N/A /* Get the peer of the target component */
0N/A peer = (*env)->GetObjectField(env, target, componentIDs.peer);
0N/A if (JNU_IsNull(env, peer)) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Component peer is NULL\n");
0N/A#endif
0N/A AWT_UNLOCK();
0N/A return (int32_t) 0;
0N/A }
0N/A#ifndef XAWT
0N/A adata = getGraphicsConfigFromComponentPeer(env, peer);
0N/A#else
0N/A /* GraphicsConfiguration object of MComponentPeer */
0N/A gc_object = (*env)->GetObjectField(env, peer, graphicsConfigID);
0N/A
0N/A if (gc_object != NULL) {
0N/A adata = (AwtGraphicsConfigDataPtr)
0N/A JNU_GetLongFieldAsPtr(env, gc_object,
0N/A x11GraphicsConfigIDs.aData);
0N/A } else {
0N/A adata = getDefaultConfig(DefaultScreen(awt_display));
0N/A }
0N/A#endif
0N/A
0N/A result = adata->AwtColorMatch(r, g, b, adata);
0N/A AWT_UNLOCK();
0N/A return result;
0N/A}
0N/A
0N/A/*
0N/A * Get the drawing surface info.
0N/A * The value returned may be cached, but the values may change if
0N/A * additional calls to Lock() or Unlock() are made.
0N/A * Lock() must be called before this can return a valid value.
0N/A * Returns NULL if an error has occurred.
0N/A * When finished with the returned value, FreeDrawingSurfaceInfo must be
0N/A * called.
0N/A */
0N/AJNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL
0N/Aawt_DrawingSurface_GetDrawingSurfaceInfo(JAWT_DrawingSurface* ds)
0N/A{
0N/A JNIEnv* env;
0N/A jobject target, peer;
0N/A jclass componentClass;
0N/A JAWT_X11DrawingSurfaceInfo* px;
0N/A JAWT_DrawingSurfaceInfo* p;
0N/A#ifndef XAWT
0N/A struct ComponentData *cdata;
0N/A#endif
0N/A XWindowAttributes attrs;
0N/A
0N/A if (ds == NULL) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Drawing Surface is NULL\n");
0N/A#endif
0N/A return NULL;
0N/A }
0N/A
0N/A env = ds->env;
0N/A target = ds->target;
0N/A
0N/A /* Make sure the target is a java.awt.Component */
0N/A componentClass = (*env)->FindClass(env, "java/awt/Component");
0N/A if (!(*env)->IsInstanceOf(env, target, componentClass)) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "DrawingSurface target must be a component\n");
0N/A#endif
0N/A return NULL;
0N/A }
0N/A
0N/A if (!awtLockInited) {
0N/A return NULL;
0N/A }
0N/A
0N/A AWT_LOCK();
0N/A
0N/A /* Get the peer of the target component */
0N/A peer = (*env)->GetObjectField(env, target, componentIDs.peer);
0N/A if (JNU_IsNull(env, peer)) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Component peer is NULL\n");
0N/A#endif
0N/A AWT_UNLOCK();
0N/A return NULL;
0N/A }
0N/A
0N/A#ifndef XAWT
0N/A /* Get the component data from the peer */
0N/A cdata = (struct ComponentData *)
0N/A JNU_GetLongFieldAsPtr(env, peer, mComponentPeerIDs.pData);
0N/A if (cdata == NULL) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Component data is NULL\n");
0N/A#endif
0N/A AWT_UNLOCK();
0N/A return NULL;
0N/A }
0N/A#endif
0N/A
0N/A AWT_UNLOCK();
0N/A
0N/A /* Allocate platform-specific data */
0N/A px = (JAWT_X11DrawingSurfaceInfo*)
0N/A malloc(sizeof(JAWT_X11DrawingSurfaceInfo));
0N/A
0N/A /* Set drawable and display */
0N/A#ifndef XAWT
0N/A px->drawable = XtWindow(cdata->widget);
0N/A#else
2859N/A px->drawable = (*env)->GetLongField(env, peer, windowID);
0N/A#endif
0N/A px->display = awt_display;
0N/A
0N/A /* Get window attributes to set other values */
0N/A XGetWindowAttributes(awt_display, (Window)(px->drawable), &attrs);
0N/A
0N/A /* Set the other values */
0N/A px->visualID = XVisualIDFromVisual(attrs.visual);
0N/A px->colormapID = attrs.colormap;
0N/A px->depth = attrs.depth;
0N/A px->GetAWTColor = awt_GetColor;
0N/A
0N/A /* Allocate and initialize platform-independent data */
0N/A p = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo));
0N/A p->platformInfo = px;
0N/A p->ds = ds;
0N/A p->bounds.x = (*env)->GetIntField(env, target, componentIDs.x);
0N/A p->bounds.y = (*env)->GetIntField(env, target, componentIDs.y);
0N/A p->bounds.width = (*env)->GetIntField(env, target, componentIDs.width);
0N/A p->bounds.height = (*env)->GetIntField(env, target, componentIDs.height);
0N/A p->clipSize = 1;
0N/A p->clip = &(p->bounds);
0N/A
0N/A /* Return our new structure */
0N/A return p;
0N/A}
0N/A
0N/A/*
0N/A * Free the drawing surface info.
0N/A */
0N/AJNIEXPORT void JNICALL
0N/Aawt_DrawingSurface_FreeDrawingSurfaceInfo(JAWT_DrawingSurfaceInfo* dsi)
0N/A{
0N/A if (dsi == NULL ) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Drawing Surface Info is NULL\n");
0N/A#endif
3725N/A return;
0N/A }
0N/A free(dsi->platformInfo);
0N/A free(dsi);
0N/A}
0N/A
0N/A/*
0N/A * Unlock the drawing surface of the target component for native rendering.
0N/A */
0N/AJNIEXPORT void JNICALL awt_DrawingSurface_Unlock(JAWT_DrawingSurface* ds)
0N/A{
0N/A JNIEnv* env;
0N/A if (ds == NULL) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Drawing Surface is NULL\n");
0N/A#endif
0N/A return;
0N/A }
0N/A env = ds->env;
0N/A AWT_FLUSH_UNLOCK();
0N/A}
0N/A
0N/AJNIEXPORT JAWT_DrawingSurface* JNICALL
0N/A awt_GetDrawingSurface(JNIEnv* env, jobject target)
0N/A{
0N/A jclass componentClass;
0N/A JAWT_DrawingSurface* p;
0N/A
0N/A /* Make sure the target component is a java.awt.Component */
0N/A componentClass = (*env)->FindClass(env, "java/awt/Component");
0N/A if (!(*env)->IsInstanceOf(env, target, componentClass)) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr,
0N/A "GetDrawingSurface target must be a java.awt.Component\n");
0N/A#endif
0N/A return NULL;
0N/A }
0N/A
0N/A p = (JAWT_DrawingSurface*)malloc(sizeof(JAWT_DrawingSurface));
0N/A p->env = env;
0N/A p->target = (*env)->NewGlobalRef(env, target);
0N/A p->Lock = awt_DrawingSurface_Lock;
0N/A p->GetDrawingSurfaceInfo = awt_DrawingSurface_GetDrawingSurfaceInfo;
0N/A p->FreeDrawingSurfaceInfo = awt_DrawingSurface_FreeDrawingSurfaceInfo;
0N/A p->Unlock = awt_DrawingSurface_Unlock;
0N/A return p;
0N/A}
0N/A
0N/AJNIEXPORT void JNICALL
0N/A awt_FreeDrawingSurface(JAWT_DrawingSurface* ds)
0N/A{
0N/A JNIEnv* env;
0N/A
0N/A if (ds == NULL ) {
0N/A#ifdef DEBUG
0N/A fprintf(stderr, "Drawing Surface is NULL\n");
0N/A#endif
0N/A return;
0N/A }
0N/A env = ds->env;
0N/A (*env)->DeleteGlobalRef(env, ds->target);
0N/A free(ds);
0N/A}
0N/A
0N/AJNIEXPORT void JNICALL
0N/A awt_Lock(JNIEnv* env)
0N/A{
0N/A if (awtLockInited) {
0N/A AWT_LOCK();
0N/A }
0N/A}
0N/A
0N/AJNIEXPORT void JNICALL
0N/A awt_Unlock(JNIEnv* env)
0N/A{
0N/A if (awtLockInited) {
0N/A AWT_FLUSH_UNLOCK();
0N/A }
0N/A}
0N/A
0N/AJNIEXPORT jobject JNICALL
0N/A awt_GetComponent(JNIEnv* env, void* platformInfo)
0N/A{
0N/A Window window = (Window)platformInfo;
0N/A Widget widget = NULL;
0N/A jobject peer = NULL;
0N/A jobject target = NULL;
0N/A
0N/A AWT_LOCK();
0N/A
0N/A#ifndef XAWT
0N/A if (window != None) {
0N/A widget = XtWindowToWidget(awt_display, window);
0N/A }
0N/A
0N/A if (widget != NULL) {
0N/A XtVaGetValues (widget, XmNuserData, &peer, NULL);
0N/A }
0N/A
0N/A if (peer != NULL) {
0N/A target = (*env)->GetObjectField(env, peer, mComponentPeerIDs.target);
0N/A }
0N/A#else
0N/A target = (*env)->GetObjectField(env, peer, targetID);
0N/A#endif
0N/A
0N/A if (target == NULL) {
0N/A JNU_ThrowNullPointerException(env, "NullPointerException");
0N/A AWT_UNLOCK();
0N/A return (jobject)NULL;
0N/A }
0N/A
0N/A
0N/A AWT_UNLOCK();
0N/A
0N/A return target;
0N/A}