Mercurial > mplayer.hg
annotate libvo/vo_macosx.m @ 28008:a0d376b63a6a
Fix compilation after FFmpeg r15940
author | reimar |
---|---|
date | Wed, 26 Nov 2008 18:17:55 +0000 |
parents | 8f31ea9bca98 |
children | 0a0f63090e60 |
rev | line source |
---|---|
15289 | 1 /* |
2 vo_macosx.m | |
3 by Nicolas Plourde <nicolasplourde@gmail.com> | |
4 | |
5 MPlayer Mac OSX video out module. | |
6 Copyright (c) Nicolas Plourde - 2005 | |
7 */ | |
8 | |
9 #import "vo_macosx.h" | |
16385 | 10 #include <sys/types.h> |
11 #include <sys/ipc.h> | |
12 #include <sys/shm.h> | |
27988 | 13 #include <CoreServices/CoreServices.h> |
14 //special workaround for Apple bug #6267445 | |
15 //(OSServices Power API disabled in OSServices.h for 64bit systems) | |
16 #ifndef __POWER__ | |
17 #include <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h> | |
18 #endif | |
15289 | 19 |
20 //MPLAYER | |
21 #include "config.h" | |
22 #include "fastmemcpy.h" | |
23 #include "video_out.h" | |
24 #include "video_out_internal.h" | |
25 #include "aspect.h" | |
26 #include "mp_msg.h" | |
27 #include "m_option.h" | |
28 | |
29 #include "input/input.h" | |
30 #include "input/mouse.h" | |
31 | |
32 #include "osdep/keycodes.h" | |
33 | |
34 //Cocoa | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
35 NSDistantObject *mplayerosxProxy; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
36 id <MPlayerOSXVOProto> mplayerosxProto; |
15611 | 37 MPlayerOpenGLView *mpGLView; |
15289 | 38 NSAutoreleasePool *autoreleasepool; |
39 OSType pixelFormat; | |
40 | |
16385 | 41 //shared memory |
42 int shm_id; | |
43 struct shmid_ds shm_desc; | |
44 BOOL shared_buffer = false; | |
45 | |
15728 | 46 //Screen |
47 int screen_id; | |
48 BOOL screen_force; | |
49 NSRect screen_frame; | |
50 NSScreen *screen_handle; | |
51 NSArray *screen_array; | |
15289 | 52 |
53 //image | |
54 unsigned char *image_data; | |
25180 | 55 // For double buffering |
56 static uint8_t image_page = 0; | |
57 static unsigned char *image_datas[2]; | |
58 | |
15289 | 59 static uint32_t image_width; |
60 static uint32_t image_height; | |
61 static uint32_t image_depth; | |
62 static uint32_t image_bytes; | |
63 static uint32_t image_format; | |
64 | |
65 //vo | |
66 static int isFullscreen; | |
15320 | 67 static int isOntop; |
15327 | 68 static int isRootwin; |
15289 | 69 extern float monitor_aspect; |
70 extern float movie_aspect; | |
71 static float old_movie_aspect; | |
25446 | 72 extern int enable_mouse_movements; |
15289 | 73 |
15731 | 74 static float winAlpha = 1; |
15289 | 75 static int int_pause = 0; |
76 | |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
77 static BOOL isLeopardOrLater; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
78 |
15289 | 79 static vo_info_t info = |
80 { | |
81 "Mac OSX Core Video", | |
82 "macosx", | |
83 "Nicolas Plourde <nicolas.plourde@gmail.com>", | |
84 "" | |
85 }; | |
86 | |
87 LIBVO_EXTERN(macosx) | |
88 | |
89 extern void mplayer_put_key(int code); | |
90 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)); | |
91 | |
92 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) | |
93 { | |
94 switch (image_format) | |
95 { | |
96 case IMGFMT_RGB32: | |
97 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width); | |
98 break; | |
99 case IMGFMT_YUY2: | |
100 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2); | |
101 break; | |
102 } | |
103 } | |
104 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
105 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
15289 | 106 { |
16385 | 107 |
15728 | 108 //init screen |
109 screen_array = [NSScreen screens]; | |
110 if(screen_id < [screen_array count]) | |
15289 | 111 { |
15728 | 112 screen_handle = [screen_array objectAtIndex:screen_id]; |
15289 | 113 } |
15728 | 114 else |
115 { | |
116 mp_msg(MSGT_VO, MSGL_FATAL, "Get device error: Device ID %d do not exist, falling back to main device.\n", screen_id); | |
117 screen_handle = [screen_array objectAtIndex:0]; | |
118 screen_id = 0; | |
119 } | |
120 screen_frame = [screen_handle frame]; | |
25414
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
121 vo_screenwidth = screen_frame.size.width; |
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
122 vo_screenheight = screen_frame.size.height; |
16385 | 123 |
15289 | 124 //misc mplayer setup |
125 image_width = width; | |
126 image_height = height; | |
127 switch (image_format) | |
128 { | |
129 case IMGFMT_BGR32: | |
130 case IMGFMT_RGB32: | |
131 image_depth = 32; | |
132 break; | |
16385 | 133 case IMGFMT_YUY2: |
15289 | 134 image_depth = 16; |
135 break; | |
136 } | |
137 image_bytes = (image_depth + 7) / 8; | |
16385 | 138 |
139 if(!shared_buffer) | |
140 { | |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
141 image_data = malloc(image_width*image_height*image_bytes); |
25180 | 142 image_datas[0] = image_data; |
143 if (vo_doublebuffering) | |
144 image_datas[1] = malloc(image_width*image_height*image_bytes); | |
145 image_page = 0; | |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
146 |
16385 | 147 monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height; |
148 | |
149 //set aspect | |
150 panscan_init(); | |
151 aspect_save_orig(width,height); | |
152 aspect_save_prescale(d_width,d_height); | |
153 aspect_save_screenres(screen_frame.size.width, screen_frame.size.height); | |
154 aspect((int *)&d_width,(int *)&d_height,A_NOZOOM); | |
155 | |
156 movie_aspect = (float)d_width/(float)d_height; | |
157 old_movie_aspect = movie_aspect; | |
15726 | 158 |
16385 | 159 vo_fs = flags & VOFLAG_FULLSCREEN; |
160 | |
161 //config OpenGL View | |
162 [mpGLView config]; | |
163 [mpGLView reshape]; | |
164 } | |
165 else | |
166 { | |
167 movie_aspect = (float)d_width/(float)d_height; | |
168 | |
169 shm_id = shmget(9849, image_width*image_height*image_bytes, IPC_CREAT | 0666); | |
170 if (shm_id == -1) | |
171 { | |
172 perror("vo_mplayer shmget: "); | |
173 return 1; | |
174 } | |
175 | |
176 image_data = shmat(shm_id, NULL, 0); | |
177 if (!image_data) | |
178 { | |
179 perror("vo_mplayer shmat: "); | |
180 return 1; | |
181 } | |
182 | |
183 //connnect to mplayerosx | |
184 mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:@"mplayerosx" host:nil]; | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
185 if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
186 [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
187 mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
188 [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:(int)(movie_aspect*100)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
189 } |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
190 else { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
191 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
192 mplayerosxProxy = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
193 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
194 } |
16385 | 195 } |
15289 | 196 return 0; |
197 } | |
198 | |
199 static void check_events(void) | |
200 { | |
15611 | 201 [mpGLView check_events]; |
15289 | 202 } |
203 | |
204 static void draw_osd(void) | |
205 { | |
206 vo_draw_text(image_width, image_height, draw_alpha); | |
207 } | |
208 | |
209 static void flip_page(void) | |
210 { | |
16385 | 211 if(shared_buffer) |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
212 [mplayerosxProto render]; |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
213 else { |
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
214 [mpGLView setCurrentTexture]; |
16385 | 215 [mpGLView render]; |
25180 | 216 if (vo_doublebuffering) { |
217 image_page = 1 - image_page; | |
218 image_data = image_datas[image_page]; | |
219 } | |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
220 } |
15289 | 221 } |
222 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
223 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) |
15289 | 224 { |
225 return 0; | |
226 } | |
227 | |
228 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
229 static int draw_frame(uint8_t *src[]) |
15289 | 230 { |
231 switch (image_format) | |
232 { | |
233 case IMGFMT_BGR32: | |
234 case IMGFMT_RGB32: | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
23381
diff
changeset
|
235 fast_memcpy(image_data, src[0], image_width*image_height*image_bytes); |
15289 | 236 break; |
237 | |
238 case IMGFMT_YUY2: | |
239 memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2); | |
240 break; | |
241 } | |
16385 | 242 |
15289 | 243 return 0; |
244 } | |
245 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
246 static int query_format(uint32_t format) |
15289 | 247 { |
248 image_format = format; | |
249 | |
250 switch(format) | |
251 { | |
252 case IMGFMT_YUY2: | |
253 pixelFormat = kYUVSPixelFormat; | |
254 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
255 | |
256 case IMGFMT_RGB32: | |
257 case IMGFMT_BGR32: | |
258 pixelFormat = k32ARGBPixelFormat; | |
259 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
260 } | |
261 return 0; | |
262 } | |
263 | |
264 static void uninit(void) | |
265 { | |
16385 | 266 if(shared_buffer) |
267 { | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
268 [mplayerosxProto stop]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
269 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
270 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
271 mplayerosxProxy = nil; |
16385 | 272 |
273 if (shmdt(image_data) == -1) | |
274 mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmdt failed\n"); | |
275 | |
276 if (shmctl(shm_id, IPC_RMID, &shm_desc) == -1) | |
277 mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmctl failed\n"); | |
278 } | |
279 | |
21551 | 280 SetSystemUIMode( kUIModeNormal, 0); |
281 CGDisplayShowCursor(kCGDirectMainDisplay); | |
282 | |
283 if(mpGLView) | |
284 { | |
25136 | 285 NSAutoreleasePool *finalPool; |
24742
0bef706332b5
Fix deallocate bug which sometimes causes a crash when reinitializing.
nplourde
parents:
24698
diff
changeset
|
286 mpGLView = nil; |
21551 | 287 [autoreleasepool release]; |
25136 | 288 finalPool = [[NSAutoreleasePool alloc] init]; |
25078
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
289 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; |
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
290 [finalPool release]; |
21551 | 291 } |
25121 | 292 if (!shared_buffer) |
293 { | |
25180 | 294 free(image_datas[0]); |
295 if (vo_doublebuffering) | |
296 free(image_datas[1]); | |
297 image_datas[0] = NULL; | |
298 image_datas[1] = NULL; | |
25121 | 299 image_data = NULL; |
300 } | |
15289 | 301 } |
302 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
303 static int preinit(const char *arg) |
15289 | 304 { |
305 int parse_err = 0; | |
306 | |
15728 | 307 if(arg) |
308 { | |
309 char *parse_pos = (char *)&arg[0]; | |
310 while (parse_pos[0] && !parse_err) | |
311 { | |
312 if (strncmp (parse_pos, "device_id=", 10) == 0) | |
313 { | |
314 parse_pos = &parse_pos[10]; | |
315 screen_id = strtol(parse_pos, &parse_pos, 0); | |
316 screen_force = YES; | |
317 } | |
16385 | 318 if (strncmp (parse_pos, "shared_buffer", 13) == 0) |
319 { | |
320 parse_pos = &parse_pos[13]; | |
321 shared_buffer = YES; | |
322 } | |
15728 | 323 if (parse_pos[0] == ':') parse_pos = &parse_pos[1]; |
324 else if (parse_pos[0]) parse_err = 1; | |
325 } | |
326 } | |
327 | |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
328 NSApplicationLoad(); |
15289 | 329 autoreleasepool = [[NSAutoreleasePool alloc] init]; |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
330 NSApp = [NSApplication sharedApplication]; |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
331 isLeopardOrLater = floor(NSAppKitVersionNumber) > 824; |
15726 | 332 |
16385 | 333 if(!shared_buffer) |
16144 | 334 { |
27397
d47744b95b78
Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents:
27394
diff
changeset
|
335 #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL) |
17358
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
336 //this chunk of code is heavily based off SDL_macosx.m from SDL |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
337 ProcessSerialNumber myProc, frProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
338 Boolean sameProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
339 |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
340 if (GetFrontProcess(&frProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
341 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
342 if (GetCurrentProcess(&myProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
343 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
344 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
345 { |
27988 | 346 TransformProcessType(&myProc, kProcessTransformToForegroundApplication); |
17358
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
347 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
348 SetFrontProcess(&myProc); |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
349 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
350 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
351 #endif |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
352 |
16385 | 353 if(!mpGLView) |
354 { | |
355 mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]]; | |
356 [mpGLView autorelease]; | |
357 } | |
358 | |
359 [mpGLView display]; | |
360 [mpGLView preinit]; | |
16144 | 361 } |
362 | |
15289 | 363 return 0; |
364 } | |
365 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
366 static int control(uint32_t request, void *data, ...) |
15289 | 367 { |
368 switch (request) | |
369 { | |
26755
46f0b4d34fa1
cosmetics: Remove useless parentheses from from return statements.
diego
parents:
25468
diff
changeset
|
370 case VOCTRL_PAUSE: return int_pause = 1; |
46f0b4d34fa1
cosmetics: Remove useless parentheses from from return statements.
diego
parents:
25468
diff
changeset
|
371 case VOCTRL_RESUME: return int_pause = 0; |
15289 | 372 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
373 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE; |
15611 | 374 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
375 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE; |
15289 | 376 case VOCTRL_GET_PANSCAN: return VO_TRUE; |
15611 | 377 case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE; |
15289 | 378 } |
379 return VO_NOTIMPL; | |
380 } | |
381 | |
382 ////////////////////////////////////////////////////////////////////////// | |
383 // NSOpenGLView Subclass | |
384 ////////////////////////////////////////////////////////////////////////// | |
15611 | 385 @implementation MPlayerOpenGLView |
24076 | 386 - (void) preinit |
15289 | 387 { |
15726 | 388 //init menu |
389 [self initMenu]; | |
390 | |
391 //create window | |
15747
fbf14e1ab725
osx 10.3 dont like to have a window init with no size
nplourde
parents:
15737
diff
changeset
|
392 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) |
15726 | 393 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask |
394 backing:NSBackingStoreBuffered defer:NO]; | |
395 | |
16144 | 396 [window autorelease]; |
15726 | 397 [window setDelegate:mpGLView]; |
398 [window setContentView:mpGLView]; | |
399 [window setInitialFirstResponder:mpGLView]; | |
400 [window setAcceptsMouseMovedEvents:YES]; | |
401 [window setTitle:@"MPlayer - The Movie Player"]; | |
402 | |
403 isFullscreen = 0; | |
15855 | 404 winSizeMult = 1; |
15726 | 405 } |
406 | |
24076 | 407 - (void) config |
15726 | 408 { |
409 uint32_t d_width; | |
410 uint32_t d_height; | |
411 | |
25137 | 412 GLint swapInterval = 1; |
15726 | 413 |
414 NSRect frame; | |
15289 | 415 CVReturn error = kCVReturnSuccess; |
416 | |
15728 | 417 //config window |
15726 | 418 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); |
419 frame = NSMakeRect(0, 0, d_width, d_height); | |
420 [window setContentSize: frame.size]; | |
15570 | 421 |
15289 | 422 //create OpenGL Context |
423 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil]; | |
15647 | 424 |
15289 | 425 [self setOpenGLContext:glContext]; |
15647 | 426 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; |
15289 | 427 [glContext setView:self]; |
428 [glContext makeCurrentContext]; | |
429 | |
25180 | 430 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]); |
15289 | 431 if(error != kCVReturnSuccess) |
432 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error); | |
25180 | 433 if (vo_doublebuffering) { |
434 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]); | |
435 if(error != kCVReturnSuccess) | |
436 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Double Buffer(%d)\n", error); | |
437 } | |
15289 | 438 |
439 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); | |
440 if(error != kCVReturnSuccess) | |
441 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error); | |
442 | |
25180 | 443 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 444 if(error != kCVReturnSuccess) |
445 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
446 | |
15728 | 447 //show window |
448 [window center]; | |
449 [window makeKeyAndOrderFront:mpGLView]; | |
450 | |
15726 | 451 if(vo_rootwin) |
452 [mpGLView rootwin]; | |
453 | |
454 if(vo_fs) | |
455 [mpGLView fullscreen: NO]; | |
456 | |
457 if(vo_ontop) | |
458 [mpGLView ontop]; | |
15289 | 459 } |
460 | |
461 /* | |
15570 | 462 Init Menu |
463 */ | |
464 - (void)initMenu | |
465 { | |
21395 | 466 NSMenu *menu, *aspectMenu; |
15570 | 467 NSMenuItem *menuItem; |
468 | |
469 [NSApp setMainMenu:[[NSMenu alloc] init]]; | |
470 | |
471 //Create Movie Menu | |
472 menu = [[NSMenu alloc] initWithTitle:@"Movie"]; | |
473 menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem]; | |
474 kHalfScreenCmd = menuItem; | |
475 menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem]; | |
476 kNormalScreenCmd = menuItem; | |
477 menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem]; | |
478 kDoubleScreenCmd = menuItem; | |
479 menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem]; | |
480 kFullScreenCmd = menuItem; | |
15909 | 481 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem]; |
15570 | 482 |
483 aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"]; | |
484 menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
485 if(vo_keepaspect) [menuItem setState:NSOnState]; | |
486 kKeepAspectCmd = menuItem; | |
487 menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
488 if(vo_panscan) [menuItem setState:NSOnState]; | |
489 kPanScanCmd = menuItem; | |
15909 | 490 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [aspectMenu addItem:menuItem]; |
15570 | 491 menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; |
492 kAspectOrgCmd = menuItem; | |
493 menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
494 kAspectFullCmd = menuItem; | |
495 menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
496 kAspectWideCmd = menuItem; | |
497 menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""]; | |
498 [menuItem setSubmenu:aspectMenu]; | |
499 [menu addItem:menuItem]; | |
500 [aspectMenu release]; | |
501 | |
502 //Add to menubar | |
503 menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""]; | |
504 [menuItem setSubmenu:menu]; | |
505 [[NSApp mainMenu] addItem:menuItem]; | |
506 | |
507 //Create Window Menu | |
508 menu = [[NSMenu alloc] initWithTitle:@"Window"]; | |
509 | |
510 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem]; | |
511 menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem]; | |
512 | |
513 //Add to menubar | |
514 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; | |
515 [menuItem setSubmenu:menu]; | |
516 [[NSApp mainMenu] addItem:menuItem]; | |
517 [NSApp setWindowsMenu:menu]; | |
518 | |
519 [menu release]; | |
520 [menuItem release]; | |
521 } | |
522 | |
523 /* | |
524 Menu Action | |
525 */ | |
526 - (void)menuAction:(id)sender | |
527 { | |
528 uint32_t d_width; | |
529 uint32_t d_height; | |
530 NSRect frame; | |
531 | |
532 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); | |
15731 | 533 |
534 if(sender == kQuitCmd) | |
535 { | |
536 mplayer_put_key(KEY_ESC); | |
537 } | |
15570 | 538 |
539 if(sender == kHalfScreenCmd) | |
540 { | |
541 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
542 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 543 } |
544 | |
15855 | 545 winSizeMult = 0.5; |
546 frame.size.width = (d_width*winSizeMult); | |
547 frame.size.height = ((d_width/movie_aspect)*winSizeMult); | |
15570 | 548 [window setContentSize: frame.size]; |
549 [self reshape]; | |
550 } | |
551 if(sender == kNormalScreenCmd) | |
552 { | |
553 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
554 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 555 } |
556 | |
15855 | 557 winSizeMult = 1; |
15570 | 558 frame.size.width = d_width; |
559 frame.size.height = d_width/movie_aspect; | |
560 [window setContentSize: frame.size]; | |
561 [self reshape]; | |
562 } | |
563 if(sender == kDoubleScreenCmd) | |
564 { | |
565 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
566 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 567 } |
568 | |
15855 | 569 winSizeMult = 2; |
570 frame.size.width = d_width*winSizeMult; | |
571 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
15570 | 572 [window setContentSize: frame.size]; |
573 [self reshape]; | |
574 } | |
575 if(sender == kFullScreenCmd) | |
576 { | |
577 vo_fs = (!(vo_fs)); | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
578 [self fullscreen:NO]; |
15570 | 579 } |
580 | |
581 if(sender == kKeepAspectCmd) | |
582 { | |
583 vo_keepaspect = (!(vo_keepaspect)); | |
584 if(vo_keepaspect) | |
585 [kKeepAspectCmd setState:NSOnState]; | |
586 else | |
587 [kKeepAspectCmd setState:NSOffState]; | |
15909 | 588 |
589 [self reshape]; | |
15570 | 590 } |
591 | |
592 if(sender == kPanScanCmd) | |
593 { | |
594 vo_panscan = (!(vo_panscan)); | |
595 if(vo_panscan) | |
596 [kPanScanCmd setState:NSOnState]; | |
597 else | |
598 [kPanScanCmd setState:NSOffState]; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
599 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
600 [self panscan]; |
15570 | 601 } |
602 | |
603 if(sender == kAspectOrgCmd) | |
604 { | |
605 movie_aspect = old_movie_aspect; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
606 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
607 if(isFullscreen) |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
608 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
609 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
610 } |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
611 else |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
612 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
613 frame.size.width = d_width*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
614 frame.size.height = (d_width/movie_aspect)*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
615 [window setContentSize: frame.size]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
616 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
617 } |
15570 | 618 } |
619 | |
620 if(sender == kAspectFullCmd) | |
621 { | |
622 movie_aspect = 4.0f/3.0f; | |
15882 | 623 |
624 if(isFullscreen) | |
625 { | |
626 [self reshape]; | |
627 } | |
628 else | |
629 { | |
630 frame.size.width = d_width*winSizeMult; | |
631 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
632 [window setContentSize: frame.size]; | |
633 [self reshape]; | |
634 } | |
15570 | 635 } |
636 | |
637 if(sender == kAspectWideCmd) | |
638 { | |
639 movie_aspect = 16.0f/9.0f; | |
15882 | 640 |
641 if(isFullscreen) | |
642 { | |
643 [self reshape]; | |
644 } | |
645 else | |
646 { | |
647 frame.size.width = d_width*winSizeMult; | |
648 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
649 [window setContentSize: frame.size]; | |
650 [self reshape]; | |
651 } | |
15570 | 652 } |
653 } | |
654 | |
655 /* | |
15289 | 656 Setup OpenGL |
657 */ | |
658 - (void)prepareOpenGL | |
659 { | |
15339 | 660 glEnable(GL_BLEND); |
15289 | 661 glDisable(GL_DEPTH_TEST); |
662 glDepthMask(GL_FALSE); | |
663 glDisable(GL_CULL_FACE); | |
664 [self reshape]; | |
665 } | |
666 | |
667 /* | |
668 reshape OpenGL viewport | |
669 */ | |
670 - (void)reshape | |
671 { | |
672 uint32_t d_width; | |
673 uint32_t d_height; | |
674 float aspectX; | |
675 float aspectY; | |
676 int padding = 0; | |
677 | |
678 NSRect frame = [self frame]; | |
679 | |
680 glViewport(0, 0, frame.size.width, frame.size.height); | |
681 glMatrixMode(GL_PROJECTION); | |
682 glLoadIdentity(); | |
683 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | |
684 glMatrixMode(GL_MODELVIEW); | |
685 glLoadIdentity(); | |
686 | |
15729 | 687 //set texture frame |
15289 | 688 if(vo_keepaspect) |
689 { | |
15571 | 690 aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM); |
15289 | 691 d_height = ((float)d_width/movie_aspect); |
692 | |
693 aspectX = (float)((float)frame.size.width/(float)d_width); | |
694 aspectY = (float)((float)(frame.size.height)/(float)d_height); | |
695 | |
696 if((d_height*aspectX)>(frame.size.height)) | |
697 { | |
698 padding = (frame.size.width - d_width*aspectY)/2; | |
25424 | 699 textureFrame = NSMakeRect(padding, 0, d_width*aspectY, d_height*aspectY); |
15289 | 700 } |
701 else | |
702 { | |
703 padding = ((frame.size.height) - d_height*aspectX)/2; | |
25424 | 704 textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX); |
15289 | 705 } |
706 } | |
707 else | |
708 { | |
15729 | 709 textureFrame = frame; |
15289 | 710 } |
25446 | 711 vo_dwidth = textureFrame.size.width; |
712 vo_dheight = textureFrame.size.height; | |
15289 | 713 } |
714 | |
715 /* | |
716 Render frame | |
717 */ | |
718 - (void) render | |
719 { | |
21395 | 720 int curTime; |
24953
aca7d0259d90
Fix the prevent system idle code. Original code also works, but not as expected.
ulion
parents:
24742
diff
changeset
|
721 static int lastTime = 0; |
21395 | 722 |
15289 | 723 glClear(GL_COLOR_BUFFER_BIT); |
724 | |
725 glEnable(CVOpenGLTextureGetTarget(texture)); | |
726 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
727 | |
728 glColor3f(1,1,1); | |
729 glBegin(GL_QUADS); | |
15729 | 730 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
25424 | 731 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i(textureFrame.origin.x-(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); |
732 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); | |
733 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 734 glEnd(); |
15339 | 735 glDisable(CVOpenGLTextureGetTarget(texture)); |
736 | |
737 //render resize box | |
738 if(!isFullscreen) | |
739 { | |
740 NSRect frame = [self frame]; | |
741 | |
742 glBegin(GL_LINES); | |
743 glColor4f(0.2, 0.2, 0.2, 0.5); | |
744 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
745 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
746 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
747 | |
748 glColor4f(0.4, 0.4, 0.4, 0.5); | |
749 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
750 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
751 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1); | |
752 | |
753 glColor4f(0.6, 0.6, 0.6, 0.5); | |
754 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
755 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
756 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
757 glEnd(); | |
758 } | |
15289 | 759 |
760 glFlush(); | |
761 | |
28001 | 762 //auto hide mouse cursor (and future on-screen control?) |
15327 | 763 if(isFullscreen && !mouseHide && !isRootwin) |
15289 | 764 { |
18057 | 765 int curTime = TickCount()/60; |
766 static int lastTime = 0; | |
15289 | 767 |
768 if( ((curTime - lastTime) >= 5) || (lastTime == 0) ) | |
769 { | |
18057 | 770 CGDisplayHideCursor(kCGDirectMainDisplay); |
15289 | 771 mouseHide = YES; |
772 lastTime = curTime; | |
773 } | |
774 } | |
17546 | 775 |
17725 | 776 //update activity every 30 seconds to prevent |
17546 | 777 //screensaver from starting up. |
21395 | 778 curTime = TickCount()/60; |
18057 | 779 |
780 if( ((curTime - lastTime) >= 30) || (lastTime == 0) ) | |
17546 | 781 { |
782 UpdateSystemActivity(UsrActivity); | |
783 lastTime = curTime; | |
784 } | |
15289 | 785 } |
786 | |
787 /* | |
788 Create OpenGL texture from current frame & set texco | |
789 */ | |
790 - (void) setCurrentTexture | |
791 { | |
792 CVReturn error = kCVReturnSuccess; | |
793 | |
25180 | 794 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 795 if(error != kCVReturnSuccess) |
796 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
797 | |
798 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
799 } | |
800 | |
801 /* | |
802 redraw win rect | |
803 */ | |
804 - (void) drawRect: (NSRect *) bounds | |
805 { | |
806 [self render]; | |
807 } | |
808 | |
809 /* | |
810 Toggle Fullscreen | |
811 */ | |
812 - (void) fullscreen: (BOOL) animate | |
813 { | |
814 static NSRect old_frame; | |
815 static NSRect old_view_frame; | |
15728 | 816 |
15573 | 817 panscan_calc(); |
818 | |
15289 | 819 //go fullscreen |
820 if(vo_fs) | |
821 { | |
15327 | 822 if(!isRootwin) |
823 { | |
15882 | 824 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
18057 | 825 CGDisplayHideCursor(kCGDirectMainDisplay); |
15327 | 826 mouseHide = YES; |
827 } | |
15289 | 828 |
829 old_frame = [window frame]; //save main window size & position | |
25413 | 830 if(screen_force) |
831 screen_frame = [screen_handle frame]; | |
25414
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
832 else { |
25413 | 833 screen_frame = [[window screen] frame]; |
25414
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
834 vo_screenwidth = screen_frame.size.width; |
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
835 vo_screenheight = screen_frame.size.height; |
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
836 } |
25413 | 837 |
15728 | 838 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
15289 | 839 old_view_frame = [self bounds]; |
840 | |
841 //fix origin for multi screen setup | |
15728 | 842 screen_frame.origin.x = 0; |
843 screen_frame.origin.y = 0; | |
844 [self setFrame:screen_frame]; | |
15289 | 845 [self setNeedsDisplay:YES]; |
846 [window setHasShadow:NO]; | |
847 isFullscreen = 1; | |
848 } | |
849 else | |
15882 | 850 { |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
851 SetSystemUIMode( kUIModeNormal, 0); |
15882 | 852 |
15289 | 853 isFullscreen = 0; |
18057 | 854 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 855 mouseHide = NO; |
856 | |
857 //revert window to previous setting | |
858 [self setFrame:old_view_frame]; | |
859 [self setNeedsDisplay:YES]; | |
16081
72c352edce8f
restore window shadow when quitting fullscreen mode
nplourde
parents:
15909
diff
changeset
|
860 [window setHasShadow:YES]; |
15289 | 861 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx |
862 } | |
863 } | |
864 | |
865 /* | |
866 Toggle ontop | |
867 */ | |
868 - (void) ontop | |
869 { | |
15320 | 870 if(vo_ontop) |
871 { | |
872 [window setLevel:NSScreenSaverWindowLevel]; | |
873 isOntop = YES; | |
874 } | |
875 else | |
876 { | |
877 [window setLevel:NSNormalWindowLevel]; | |
878 isOntop = NO; | |
879 } | |
15289 | 880 } |
881 | |
882 /* | |
883 Toggle panscan | |
884 */ | |
885 - (void) panscan | |
886 { | |
15331 | 887 panscan_calc(); |
15289 | 888 } |
889 | |
890 /* | |
15327 | 891 Toggle rootwin |
892 */ | |
893 - (void) rootwin | |
894 { | |
895 if(vo_rootwin) | |
896 { | |
897 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; | |
898 [window orderBack:self]; | |
899 isRootwin = YES; | |
900 } | |
901 else | |
902 { | |
903 [window setLevel:NSNormalWindowLevel]; | |
904 isRootwin = NO; | |
905 } | |
906 } | |
907 | |
908 /* | |
15289 | 909 Check event for new event |
910 */ | |
911 - (void) check_events | |
912 { | |
913 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
25178 | 914 if (event == nil) |
915 return; | |
15289 | 916 [NSApp sendEvent:event]; |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
917 // Without SDL's bootstrap code (include SDL.h in mplayer.c), |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
918 // on Leopard, we got trouble to get the play window auto focused |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
919 // when app is actived. Following code fix this problem. |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
26755
diff
changeset
|
920 #ifndef CONFIG_SDL |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
921 if (isLeopardOrLater && [event type] == NSAppKitDefined |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
922 && [event subtype] == NSApplicationActivatedEventType) { |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
923 [window makeMainWindow]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
924 [window makeKeyAndOrderFront:mpGLView]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
925 } |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
926 #endif |
15289 | 927 } |
928 | |
929 /* | |
15731 | 930 From NSView, respond to key equivalents. |
931 */ | |
932 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent | |
933 { | |
934 switch([theEvent keyCode]) | |
935 { | |
936 case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES; | |
937 case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES; | |
938 } | |
939 return NO; | |
940 } | |
941 | |
942 /* | |
15289 | 943 Process key event |
944 */ | |
945 - (void) keyDown: (NSEvent *) theEvent | |
946 { | |
947 unsigned int key; | |
948 | |
949 switch([theEvent keyCode]) | |
950 { | |
951 case 0x34: | |
952 case 0x24: key = KEY_ENTER; break; | |
953 case 0x35: key = KEY_ESC; break; | |
954 case 0x33: key = KEY_BACKSPACE; break; | |
955 case 0x3A: key = KEY_BACKSPACE; break; | |
956 case 0x3B: key = KEY_BACKSPACE; break; | |
957 case 0x38: key = KEY_BACKSPACE; break; | |
958 case 0x7A: key = KEY_F+1; break; | |
959 case 0x78: key = KEY_F+2; break; | |
960 case 0x63: key = KEY_F+3; break; | |
961 case 0x76: key = KEY_F+4; break; | |
962 case 0x60: key = KEY_F+5; break; | |
963 case 0x61: key = KEY_F+6; break; | |
964 case 0x62: key = KEY_F+7; break; | |
965 case 0x64: key = KEY_F+8; break; | |
966 case 0x65: key = KEY_F+9; break; | |
967 case 0x6D: key = KEY_F+10; break; | |
968 case 0x67: key = KEY_F+11; break; | |
969 case 0x6F: key = KEY_F+12; break; | |
970 case 0x72: key = KEY_INSERT; break; | |
971 case 0x75: key = KEY_DELETE; break; | |
972 case 0x73: key = KEY_HOME; break; | |
973 case 0x77: key = KEY_END; break; | |
974 case 0x45: key = '+'; break; | |
975 case 0x4E: key = '-'; break; | |
976 case 0x30: key = KEY_TAB; break; | |
977 case 0x74: key = KEY_PAGE_UP; break; | |
978 case 0x79: key = KEY_PAGE_DOWN; break; | |
979 case 0x7B: key = KEY_LEFT; break; | |
980 case 0x7C: key = KEY_RIGHT; break; | |
981 case 0x7D: key = KEY_DOWN; break; | |
982 case 0x7E: key = KEY_UP; break; | |
983 case 0x43: key = '*'; break; | |
984 case 0x4B: key = '/'; break; | |
24107 | 985 case 0x4C: key = KEY_KPENTER; break; |
15289 | 986 case 0x41: key = KEY_KPDEC; break; |
987 case 0x52: key = KEY_KP0; break; | |
988 case 0x53: key = KEY_KP1; break; | |
989 case 0x54: key = KEY_KP2; break; | |
990 case 0x55: key = KEY_KP3; break; | |
991 case 0x56: key = KEY_KP4; break; | |
992 case 0x57: key = KEY_KP5; break; | |
993 case 0x58: key = KEY_KP6; break; | |
994 case 0x59: key = KEY_KP7; break; | |
995 case 0x5B: key = KEY_KP8; break; | |
996 case 0x5C: key = KEY_KP9; break; | |
997 default: key = *[[theEvent characters] UTF8String]; break; | |
998 } | |
999 mplayer_put_key(key); | |
1000 } | |
1001 | |
1002 /* | |
1003 Process mouse button event | |
1004 */ | |
1005 - (void) mouseMoved: (NSEvent *) theEvent | |
1006 { | |
15327 | 1007 if(isFullscreen && !isRootwin) |
15289 | 1008 { |
18057 | 1009 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 1010 mouseHide = NO; |
1011 } | |
25468
a77c438fedf7
Do not send mouse movements events in root win mode.
ulion
parents:
25446
diff
changeset
|
1012 if (enable_mouse_movements && !isRootwin) { |
25446 | 1013 NSPoint p =[self convertPoint:[theEvent locationInWindow] fromView:nil]; |
1014 if ([self mouse:p inRect:textureFrame]) { | |
1015 char cmdstr[40]; | |
1016 snprintf(cmdstr, sizeof(cmdstr), "set_mouse_pos %i %i", | |
1017 (int)(vo_fs ? p.x : (p.x - textureFrame.origin.x)), | |
1018 (int)(vo_fs ? [self frame].size.height - p.y: (NSMaxY(textureFrame) - p.y))); | |
1019 mp_input_queue_cmd(mp_input_parse_cmd(cmdstr)); | |
1020 } | |
1021 } | |
15289 | 1022 } |
1023 | |
1024 - (void) mouseDown: (NSEvent *) theEvent | |
1025 { | |
1026 [self mouseEvent: theEvent]; | |
1027 } | |
1028 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1029 - (void) mouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1030 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1031 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1032 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1033 |
15289 | 1034 - (void) rightMouseDown: (NSEvent *) theEvent |
1035 { | |
1036 [self mouseEvent: theEvent]; | |
1037 } | |
1038 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1039 - (void) rightMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1040 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1041 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1042 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1043 |
15289 | 1044 - (void) otherMouseDown: (NSEvent *) theEvent |
1045 { | |
1046 [self mouseEvent: theEvent]; | |
1047 } | |
1048 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1049 - (void) otherMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1050 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1051 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1052 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1053 |
15289 | 1054 - (void) scrollWheel: (NSEvent *) theEvent |
1055 { | |
1056 if([theEvent deltaY] > 0) | |
1057 mplayer_put_key(MOUSE_BTN3); | |
1058 else | |
1059 mplayer_put_key(MOUSE_BTN4); | |
1060 } | |
1061 | |
1062 - (void) mouseEvent: (NSEvent *) theEvent | |
1063 { | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1064 if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 ) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1065 { |
25422 | 1066 int buttonNumber = [theEvent buttonNumber]; |
1067 // Fix to mplayer defined button order: left, middle, right | |
1068 if (buttonNumber == 1) | |
1069 buttonNumber = 2; | |
25423 | 1070 else if (buttonNumber == 2) |
1071 buttonNumber = 1; | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1072 switch([theEvent type]) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1073 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1074 case NSLeftMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1075 case NSRightMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1076 case NSOtherMouseDown: |
25422 | 1077 mplayer_put_key((MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN); |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1078 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1079 case NSLeftMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1080 case NSRightMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1081 case NSOtherMouseUp: |
25422 | 1082 mplayer_put_key(MOUSE_BTN0 + buttonNumber); |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1083 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1084 } |
15289 | 1085 } |
1086 } | |
1087 | |
1088 /* | |
1089 NSResponder | |
1090 */ | |
1091 - (BOOL) acceptsFirstResponder | |
1092 { | |
1093 return YES; | |
1094 } | |
1095 | |
1096 - (BOOL) becomeFirstResponder | |
1097 { | |
1098 return YES; | |
1099 } | |
1100 | |
1101 - (BOOL) resignFirstResponder | |
1102 { | |
1103 return YES; | |
1104 } | |
15325 | 1105 |
1106 - (void)windowWillClose:(NSNotification *)aNotification | |
1107 { | |
21551 | 1108 mpGLView = NULL; |
15325 | 1109 mplayer_put_key(KEY_ESC); |
1110 } | |
1111 @end |