summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt.opengl/gtk/library/structs.c
blob: f11d22d342fbd3e027baa50db2a8fc48570a4bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
#include <X11/X.h>
#include <X11/Xlib.h>
#include "swt.h"
#include "structs.h"

typedef struct XVisualInfo_FID_CACHE {
	int cached;
	jclass clazz;
	jfieldID visual, visualid, screen, depth, cclass, red_mask, green_mask, blue_mask, colormap_size, bits_per_rgb;
} XVisualInfo_FID_CACHE;
typedef XVisualInfo_FID_CACHE *PXVisualInfo_FID_CACHE;

XVisualInfo_FID_CACHE XVisualInfoFc;

void cacheXVisualInfoFids(JNIEnv *env, jobject lpObject, PXVisualInfo_FID_CACHE lpCache)
{
	if (lpCache->cached) return;
	lpCache->clazz = (*env)->GetObjectClass(env, lpObject);
	lpCache->visual = (*env)->GetFieldID(env, lpCache->clazz, "visual", "I");
	lpCache->visualid = (*env)->GetFieldID(env, lpCache->clazz, "visualid", "I");
	lpCache->screen = (*env)->GetFieldID(env, lpCache->clazz, "screen", "I");
	lpCache->depth = (*env)->GetFieldID(env, lpCache->clazz, "depth", "I");
	lpCache->cclass = (*env)->GetFieldID(env, lpCache->clazz, "cclass", "I");
	lpCache->red_mask = (*env)->GetFieldID(env, lpCache->clazz, "red_mask", "I");
	lpCache->green_mask = (*env)->GetFieldID(env, lpCache->clazz, "green_mask", "I");
	lpCache->blue_mask = (*env)->GetFieldID(env, lpCache->clazz, "blue_mask", "I");
	lpCache->colormap_size = (*env)->GetFieldID(env, lpCache->clazz, "colormap_size", "I");
	lpCache->bits_per_rgb = (*env)->GetFieldID(env, lpCache->clazz, "bits_per_rgb", "I");
	lpCache->cached = 1;
}

XVisualInfo *getXVisualInfoFields(JNIEnv *env, jobject lpObject, XVisualInfo *lpStruct)
{
	PXVisualInfo_FID_CACHE lpCache = &XVisualInfoFc;
	if (!lpCache->cached) cacheXVisualInfoFids(env, lpObject, lpCache);
	lpStruct->visual = (Visual *)(*env)->GetIntField(env, lpObject, lpCache->visual);
	lpStruct->visualid = (*env)->GetIntField(env, lpObject, lpCache->visualid);
	lpStruct->screen = (*env)->GetIntField(env, lpObject, lpCache->screen);
	lpStruct->depth = (*env)->GetIntField(env, lpObject, lpCache->depth);
	lpStruct->class = (*env)->GetIntField(env, lpObject, lpCache->cclass);
	lpStruct->red_mask = (*env)->GetIntField(env, lpObject, lpCache->red_mask);
	lpStruct->green_mask = (*env)->GetIntField(env, lpObject, lpCache->green_mask);
	lpStruct->blue_mask = (*env)->GetIntField(env, lpObject, lpCache->blue_mask);
	lpStruct->colormap_size = (*env)->GetIntField(env, lpObject, lpCache->colormap_size);
	lpStruct->bits_per_rgb = (*env)->GetIntField(env, lpObject, lpCache->bits_per_rgb);
	return lpStruct;
}

void setXVisualInfoFields(JNIEnv *env, jobject lpObject, XVisualInfo *lpStruct)
{
	PXVisualInfo_FID_CACHE lpCache = &XVisualInfoFc;
	if (!lpCache->cached) cacheXVisualInfoFids(env, lpObject, lpCache);
	(*env)->SetIntField(env, lpObject, lpCache->visual, (jint)lpStruct->visual);
	(*env)->SetIntField(env, lpObject, lpCache->visualid, (jint)lpStruct->visualid);
	(*env)->SetIntField(env, lpObject, lpCache->screen, (jint)lpStruct->screen);
	(*env)->SetIntField(env, lpObject, lpCache->depth, (jint)lpStruct->depth);
	(*env)->SetIntField(env, lpObject, lpCache->cclass, (jint)lpStruct->class);
	(*env)->SetIntField(env, lpObject, lpCache->red_mask, (jint)lpStruct->red_mask);
	(*env)->SetIntField(env, lpObject, lpCache->green_mask, (jint)lpStruct->green_mask);
	(*env)->SetIntField(env, lpObject, lpCache->blue_mask, (jint)lpStruct->blue_mask);
	(*env)->SetIntField(env, lpObject, lpCache->colormap_size, (jint)lpStruct->colormap_size);
	(*env)->SetIntField(env, lpObject, lpCache->bits_per_rgb, (jint)lpStruct->bits_per_rgb);
}