]> git.sesse.net Git - vlc/blob - bindings/java/src/graphics-jni.cc
Java bindings update: various enhancements; paint system changed; reparenting works...
[vlc] / bindings / java / src / 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /* These are a must*/
24 #include <jni.h>
25 #include <vlc/vlc.h>
26 #include <vlc/libvlc.h>
27 #include <jawt.h>
28 #include <jawt_md.h>
29
30 #ifndef WIN32
31 #include <X11/Xlib.h> // for Xlibs graphics functions
32 #endif
33
34 #include <stdio.h>    // for printf
35 #include <stdlib.h>   // for malloc
36
37 /* JVLC internal imports, generated by gcjh */
38 #include "../includes/JVLCCanvas.h"
39
40 jlong getJVLCInstance (JNIEnv *env, jobject _this);
41
42 // JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLCCanvas_paint (JNIEnv *env, jobject canvas, jobject graphics) {
43
44 //   JAWT awt;
45 //   JAWT_DrawingSurface* ds;
46 //   JAWT_DrawingSurfaceInfo* dsi;
47 // #ifdef WIN32
48 //   JAWT_Win32DrawingSurfaceInfo* dsi_win;
49 // #else
50 //   JAWT_X11DrawingSurfaceInfo* dsi_x11;
51 //   GC gc;
52 // #endif
53   
54 //   jint lock;
55     
56 //   libvlc_drawable_t drawable;
57 //   libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ));
58 //   libvlc_exception_init( exception );
59
60 //   /* Get the AWT */
61 //   awt.version = JAWT_VERSION_1_3;
62 //   if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
63 //     printf("AWT Not found\n");
64 //     return;
65 //   }
66
67 //   /* Get the drawing surface */
68 //   ds = awt.GetDrawingSurface(env, canvas);
69 //   if (ds == NULL) {
70 //     printf("NULL drawing surface\n");
71 //     return;
72 //   }
73
74 //   /* Lock the drawing surface */
75 //   lock = ds->Lock(ds);
76 //   if((lock & JAWT_LOCK_ERROR) != 0) {
77 //     printf("Error locking surface\n");
78 //     awt.FreeDrawingSurface(ds);
79 //     return;
80 //   }
81
82 //   /* Get the drawing surface info */
83 //   dsi = ds->GetDrawingSurfaceInfo(ds);
84 //   if (dsi == NULL) {
85 //     printf("Error getting surface info\n");
86 //     ds->Unlock(ds);
87 //     awt.FreeDrawingSurface(ds);
88 //     return;
89 //   }
90
91
92 // #ifdef WIN32
93 //   /* Get the platform-specific drawing info */
94 //   dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
95
96 //   /* Now paint */
97
98 //   drawable = reinterpret_cast<int>(dsi_win->hwnd);
99 //   long vlcInstance = getJVLCInstance( env, canvas );
100 //   libvlc_video_set_parent( (libvlc_instance_t *) vlcInstance, drawable, exception );
101
102 // #else // UNIX
103 //   /* Get the platform-specific drawing info */
104 //   dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
105
106 //   /* Now paint */
107 //   gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
108 //   XSetBackground(dsi_x11->display, gc, 0);
109   
110 //   drawable = dsi_x11->drawable;
111 //   long vlcInstance = getJVLCInstance( env, canvas );
112 //   libvlc_video_set_parent( (libvlc_instance_t *)vlcInstance, drawable, exception );
113
114 //   XFreeGC(dsi_x11->display, gc);
115
116 // #endif
117
118 //   /* Free the drawing surface info */
119 //   ds->FreeDrawingSurfaceInfo(dsi);
120
121 //   /* Unlock the drawing surface */
122 //   ds->Unlock(ds);
123
124 //   /* Free the drawing surface */
125 //   awt.FreeDrawingSurface(ds);
126 // }
127
128 /*
129  * Utility functions
130  */
131 jlong getJVLCInstance (JNIEnv *env, jobject _this) {
132     /* get the id field of object */
133     jclass    canvascls   = env->GetObjectClass(_this);
134     jmethodID canvasmid   = env->GetMethodID(canvascls, "getJVLC", "()Lorg/videolan/jvlc/JVLC;");
135     jobject   canvasjvlc  = env->CallObjectMethod(_this, canvasmid);
136     jclass    cls   = env->GetObjectClass(canvasjvlc);
137     jmethodID mid   = env->GetMethodID(cls, "getInstance", "()J");
138     jlong     field = env->CallLongMethod(canvasjvlc, mid);
139     return field;
140 }