OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [gtk-peer/] [gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c
2
   Copyright (C) 2006 Free Software Foundation, Inc.
3
 
4
   This file is part of GNU Classpath.
5
 
6
   GNU Classpath is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2, or (at your option)
9
   any later version.
10
 
11
   GNU Classpath is distributed in the hope that it will be useful, but
12
   WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
   General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with GNU Classpath; see the file COPYING.  If not, write to the
18
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
   02110-1301 USA.
20
 
21
   Linking this library statically or dynamically with other modules is
22
   making a combined work based on this library.  Thus, the terms and
23
   conditions of the GNU General Public License cover the whole
24
   combination.
25
 
26
   As a special exception, the copyright holders of this library give you
27
   permission to link this library with independent modules to produce an
28
   executable, regardless of the license terms of these independent
29
   modules, and to copy and distribute the resulting executable under
30
   terms of your choice, provided that you also meet, for each linked
31
   independent module, the terms and conditions of the license of that
32
   module.  An independent module is a module which is not derived from
33
   or based on this library.  If you modify this library, you may extend
34
   this exception to your version of the library, but you are not
35
   obligated to do so.  If you do not wish to do so, delete this
36
   exception statement from your version. */
37
 
38
#include <jcl.h>
39
 
40
#include <gdk/gdk.h>
41
#include <gdk/gdkx.h>
42
 
43
#ifdef HAVE_XRANDR
44
#include <X11/Xlib.h>
45
#include <X11/extensions/Xrandr.h>
46
#endif
47
 
48
#include "gdkdisplay.h"
49
 
50
#include "gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.h"
51
 
52
struct state_table *cp_gtk_native_screen_state_table;
53
 
54
jclass gdkScreenGraphicsDevice_class;
55
 
56
JNIEXPORT void JNICALL
57
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_initIDs
58
(JNIEnv *env, jclass klazz __attribute__((unused)))
59
{
60
  gtkpeer_init_screen_IDs(env);
61
}
62
 
63
JNIEXPORT jobject JNICALL
64
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetFixedDisplayMode
65
(JNIEnv *env, jobject obj, jobject gdkGraphicsEnv __attribute__((unused)))
66
{
67
        jclass displayMode_class;
68
        jmethodID displayMode_ctor;
69
        GdkScreen *screen;
70
        jobject fixedDisplayMode = NULL;
71
#ifdef HAVE_XRANDR
72
        int temp1, temp2;
73
        GdkDisplay *display;
74
 
75
    display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
76
 
77
        gdk_threads_enter();
78
 
79
        if (!XRRQueryExtension(GDK_DISPLAY_XDISPLAY(display), &temp1, &temp2))
80
          {
81
        displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode");
82
        displayMode_ctor = (*env)->GetMethodID(env,
83
                                               displayMode_class,
84
                                               "<init>",
85
                                               "(IIII)V");
86
 
87
        screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
88
 
89
                fixedDisplayMode = (*env)->NewObject(env,
90
                                                     displayMode_class,
91
                                                     displayMode_ctor,
92
                                                     gdk_screen_get_width(screen),
93
                                                     gdk_screen_get_height(screen),
94
                                                     -1,
95
                                                     0);
96
          }
97
 
98
        gdk_threads_leave();
99
 
100
#else
101
 
102
    displayMode_class = (*env)->FindClass(env, "java/awt/DisplayMode");
103
    displayMode_ctor = (*env)->GetMethodID(env,
104
                                           displayMode_class,
105
                                           "<init>",
106
                                           "(IIII)V");
107
 
108
    screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
109
 
110
    fixedDisplayMode = (*env)->NewObject(env,
111
                                             displayMode_class,
112
                                             displayMode_ctor,
113
                                             gdk_screen_get_width(screen),
114
                                             gdk_screen_get_height(screen),
115
                                             -1,
116
                                             0);
117
 
118
#endif    
119
        return fixedDisplayMode;
120
}
121
 
122
JNIEXPORT jstring JNICALL
123
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetIDString
124
(JNIEnv *env, jobject obj)
125
{
126
        GdkScreen *screen;
127
        gchar* displayName;
128
        jstring string;
129
 
130
    screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
131
 
132
        gdk_threads_enter();
133
 
134
        displayName = gdk_screen_make_display_name(screen);
135
 
136
        gdk_threads_leave();
137
 
138
    string = (*env)->NewStringUTF(env, displayName);
139
 
140
    g_free(displayName);
141
 
142
    return string;
143
}
144
 
145
JNIEXPORT jint JNICALL
146
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeRate
147
(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
148
{
149
#ifdef HAVE_XRANDR
150
 
151
        GdkDisplay *display;
152
        XRRScreenConfiguration *config;
153
        int rate;
154
 
155
        display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
156
 
157
        gdk_threads_enter();
158
 
159
        config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
160
 
161
        rate = (int) XRRConfigCurrentRate (config);
162
 
163
    XRRFreeScreenConfigInfo (config);
164
 
165
        gdk_threads_leave();
166
 
167
        return rate;
168
#else
169
    JCL_ThrowException(env,
170
                       "java/lang/InternalError",
171
                       "Method should not have been invoked.");
172
 
173
    return -1;
174
#endif    
175
}
176
 
177
JNIEXPORT jint JNICALL
178
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModeIndex
179
(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
180
{
181
#ifdef HAVE_XRANDR      
182
 
183
        GdkDisplay *display;
184
        XRRScreenConfiguration *config;
185
        SizeID index;
186
        Rotation rotation;
187
 
188
        display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
189
 
190
        gdk_threads_enter();
191
 
192
        config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
193
 
194
        index = XRRConfigCurrentConfiguration (config, &rotation);
195
 
196
    XRRFreeScreenConfigInfo (config);
197
 
198
        gdk_threads_leave();
199
 
200
        return (int) index;
201
 
202
#else
203
 
204
    JCL_ThrowException(env,
205
                       "java/lang/InternalError",
206
                       "Method should not have been invoked.");
207
 
208
    return -1;
209
 
210
#endif  
211
}
212
 
213
JNIEXPORT jobjectArray JNICALL
214
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModes
215
(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)))
216
{
217
#ifdef HAVE_XRANDR
218
        GdkDisplay *display;
219
        XRRScreenConfiguration *config;
220
        XRRScreenSize *screenSizes;
221
        int nsizes = 0, nrates = 0, i = 0;
222
        jclass x11DisplayMode_class;
223
        jmethodID x11DisplayMode_ctor;
224
        jobjectArray array;
225
        jobject instance;
226
        short *rates;
227
        jshortArray shortArray;
228
 
229
        display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
230
 
231
        gdk_threads_enter();
232
 
233
        config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
234
 
235
        screenSizes = XRRConfigSizes(config, &nsizes);
236
 
237
        x11DisplayMode_class = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice$X11DisplayMode");
238
 
239
        x11DisplayMode_ctor = (*env)->GetMethodID(env, x11DisplayMode_class, "<init>", "(II[S)V");
240
 
241
        array = (*env)->NewObjectArray(env, nsizes, x11DisplayMode_class, NULL);
242
 
243
        for (; i < nsizes ; i++)
244
          {
245
                /* Retrieves refresh rate information. */
246
                rates = XRRConfigRates(config, i, &nrates);
247
 
248
                /* Create a Java short array and put them in. */
249
                shortArray = (*env)->NewShortArray(env, nrates);
250
                (*env)->SetShortArrayRegion(env, shortArray, 0, nrates, (jshort *) rates);
251
 
252
                /* Create a GdkScreenGraphicsDevice.X11DisplayMode instance. */
253
        instance = (*env)->NewObject(env,
254
                                                                         x11DisplayMode_class,
255
                                                                         x11DisplayMode_ctor,
256
                                                                         screenSizes[i].width,
257
                                                                         screenSizes[i].height,
258
                                                                         shortArray);
259
 
260
                /* Put it into the result array. */
261
        (*env)->SetObjectArrayElement(env, array, i, instance);
262
          }
263
 
264
        /* Free everything acquired by xlib. */
265
        XRRFreeScreenConfigInfo (config);
266
 
267
        gdk_threads_leave();
268
 
269
        return array;
270
#else
271
    JCL_ThrowException(env,
272
                       "java/lang/InternalError",
273
                       "Method should not have been invoked.");
274
 
275
    return NULL;
276
 
277
#endif  
278
}
279
 
280
JNIEXPORT void JNICALL
281
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeSetDisplayMode
282
(JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused)), jint index __attribute__((unused)), jshort rate __attribute__((unused)))
283
{
284
#ifdef HAVE_XRANDR
285
        GdkDisplay *display;
286
        XRRScreenConfiguration *config;
287
        Rotation rotation;
288
 
289
        display = (GdkDisplay *) gtkpeer_get_display(env, gdkGraphicsEnv);
290
 
291
        gdk_threads_enter();
292
 
293
        config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW());
294
 
295
        /* The rotation is not exposed to the Java API. So we retrieve its current
296
         * value and set it to the same when switching resolution.
297
         */
298
        XRRConfigCurrentConfiguration (config, &rotation);
299
 
300
        XRRSetScreenConfigAndRate (GDK_DISPLAY_XDISPLAY(display),
301
                                           config,
302
                               GDK_ROOT_WINDOW(),
303
                               index,
304
                               rotation,
305
                               rate,
306
                               CurrentTime);
307
 
308
        XRRFreeScreenConfigInfo(config);
309
 
310
        gdk_threads_leave();
311
 
312
#else
313
    JCL_ThrowException(env,
314
                       "java/lang/InternalError",
315
                       "Method should not have been invoked.");
316
#endif  
317
}
318
 
319
JNIEXPORT jobject JNICALL
320
Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetBounds
321
(JNIEnv *env, jobject obj)
322
{
323
        jclass rectangle_class;
324
        jmethodID rectangle_ctor;
325
        GdkScreen *screen;
326
        GdkWindow *window;
327
        int x, y, w, h;
328
        jobject instance;
329
 
330
        rectangle_class = (*env)->FindClass(env, "java/awt/Rectangle");
331
 
332
    rectangle_ctor = (*env)->GetMethodID
333
    (env, rectangle_class, "<init>", "(IIII)V");
334
 
335
    screen = (GdkScreen *) gtkpeer_get_screen(env, obj);
336
 
337
        gdk_threads_enter();
338
 
339
        window = gdk_screen_get_root_window(screen);
340
 
341
        gdk_window_get_geometry(window, &x, &y, &w, &h, NULL);
342
 
343
        gdk_threads_leave();
344
 
345
    instance = (*env)->NewObject(env,
346
                                                                 rectangle_class,
347
                                                                 rectangle_ctor,
348
                                                                 x, y, w, h);
349
 
350
        return instance;
351
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.