]> git.sesse.net Git - vlc/blob - bindings/java/vlc-graphics-jni.cc
FSF address change.
[vlc] / bindings / java / vlc-graphics-jni.cc
1 /*****************************************************************************
2  * JVLC.java: JNI interface for vlc Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2005 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 /* These are a must*/
24 #include <jni.h>
25 #include <vlc/vlc.h>
26 #include <jawt.h>
27 #include <jawt_md.h>
28
29 #include <X11/Xlib.h> // for Xlibs graphics functions
30
31 /* JVLC internal imports, generated by gcjh */
32 #include "org_videolan_jvlc_JVLCCanvas.h"
33
34 /*
35  * This will only work on X11 at the moment
36  */
37
38 JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLCCanvas_paint (JNIEnv *env, jobject canvas, jobject graphics) {
39
40   JAWT awt;
41   JAWT_DrawingSurface* ds;
42   JAWT_DrawingSurfaceInfo* dsi;
43   JAWT_X11DrawingSurfaceInfo* dsi_x11;
44   jboolean result;
45   jint lock;
46   GC gc;
47     
48   vlc_value_t value;
49   short i;
50
51   /* Get the AWT */
52   awt.version = JAWT_VERSION_1_3;
53   if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
54     printf("AWT Not found\n");
55     return;
56   }
57
58   /* Get the drawing surface */
59   ds = awt.GetDrawingSurface(env, canvas);
60   if (ds == NULL) {
61     printf("NULL drawing surface\n");
62     return;
63   }
64
65   /* Lock the drawing surface */
66   lock = ds->Lock(ds);
67   if((lock & JAWT_LOCK_ERROR) != 0) {
68     printf("Error locking surface\n");
69     awt.FreeDrawingSurface(ds);
70     return;
71   }
72
73   /* Get the drawing surface info */
74   dsi = ds->GetDrawingSurfaceInfo(ds);
75   if (dsi == NULL) {
76     printf("Error getting surface info\n");
77     ds->Unlock(ds);
78     awt.FreeDrawingSurface(ds);
79     return;
80   }
81
82   /* Get the platform-specific drawing info */
83   dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
84
85
86   /* Now paint */
87   gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
88   XSetBackground(dsi_x11->display, gc, 0);
89
90   value.i_int = dsi_x11->drawable;
91   VLC_VariableSet( 0, "drawable", value );
92
93   XFreeGC(dsi_x11->display, gc);
94
95   /* Free the drawing surface info */
96   ds->FreeDrawingSurfaceInfo(dsi);
97
98   /* Unlock the drawing surface */
99   ds->Unlock(ds);
100
101   /* Free the drawing surface */
102   awt.FreeDrawingSurface(ds);
103 }