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