annotate libvo/vo_macosx.m @ 15289:e985d786c5f1

macosx core video module
author nplourde
date Fri, 29 Apr 2005 11:05:16 +0000
parents
children f743828642fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15289
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
1 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
2 vo_macosx.m
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
3 by Nicolas Plourde <nicolasplourde@gmail.com>
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
4
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
5 MPlayer Mac OSX video out module.
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
6 Copyright (c) Nicolas Plourde - 2005
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
7 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
8
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
9 #import "vo_macosx.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
10
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
11 //MPLAYER
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
12 #include "config.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
13 #include "fastmemcpy.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
14 #include "video_out.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
15 #include "video_out_internal.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
16 #include "aspect.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
17 #include "mp_msg.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
18 #include "m_option.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
19
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
20 #include "input/input.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
21 #include "input/mouse.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
22
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
23 #include "osdep/keycodes.h"
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
24
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
25 extern void mplayer_put_key(int code);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
26
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
27 //Cocoa
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
28 CustomOpenGLView *glView;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
29 NSAutoreleasePool *autoreleasepool;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
30 OSType pixelFormat;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
31
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
32 //Device
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
33 static int device_width;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
34 static int device_height;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
35 static int device_id;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
36 static GDHandle device_handle;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
37
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
38 //image
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
39 unsigned char *image_data;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
40 static uint32_t image_width;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
41 static uint32_t image_height;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
42 static uint32_t image_depth;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
43 static uint32_t image_bytes;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
44 static uint32_t image_format;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
45 static NSRect image_rec;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
46
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
47 //vo
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
48 extern int vo_rootwin;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
49 extern int vo_ontop;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
50 extern int vo_fs;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
51 static int isFullscreen;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
52 extern float monitor_aspect;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
53 extern int vo_keepaspect;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
54 extern float movie_aspect;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
55 static float old_movie_aspect;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
56 extern float vo_panscan;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
57
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
58 static int int_pause = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
59
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
60 static vo_info_t info =
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
61 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
62 "Mac OSX Core Video",
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
63 "macosx",
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
64 "Nicolas Plourde <nicolas.plourde@gmail.com>",
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
65 ""
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
66 };
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
67
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
68 LIBVO_EXTERN(macosx)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
69
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
70 extern void mplayer_put_key(int code);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
71 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));
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
72
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
73 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
74 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
75 switch (image_format)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
76 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
77 case IMGFMT_RGB32:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
78 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
79 break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
80 case IMGFMT_YUY2:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
81 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
82 break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
83 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
84 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
85
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
86 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
87 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
88 int i;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
89
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
90 //Get Main device info///////////////////////////////////////////////////
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
91 device_handle = GetMainDevice();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
92
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
93 for(i=0; i<device_id; i++)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
94 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
95 device_handle = GetNextDevice(device_handle);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
96
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
97 if(device_handle == NULL)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
98 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
99 mp_msg(MSGT_VO, MSGL_FATAL, "Get device error: Device ID %d do not exist, falling back to main device.\n", device_id);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
100 device_handle = GetMainDevice();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
101 device_id = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
102 break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
103 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
104 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
105
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
106 NSRect device_rect = [[NSScreen mainScreen] frame];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
107 device_width = device_rect.size.width;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
108 device_height = device_rect.size.height;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
109 monitor_aspect = (float)device_width/(float)device_height;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
110
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
111 //misc mplayer setup
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
112 image_width = width;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
113 image_height = height;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
114 switch (image_format)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
115 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
116 case IMGFMT_BGR32:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
117 case IMGFMT_RGB32:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
118 image_depth = 32;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
119 break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
120 case IMGFMT_YUY2:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
121 image_depth = 16;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
122 break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
123 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
124 image_bytes = (image_depth + 7) / 8;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
125 image_data = (unsigned char*)malloc(image_width*image_height*image_bytes);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
126
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
127 //set aspect
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
128 panscan_init();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
129 aspect_save_orig(width,height);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
130 aspect_save_prescale(d_width,d_height);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
131 aspect_save_screenres(device_width,device_height);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
132 aspect(&d_width,&d_height,A_NOZOOM);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
133
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
134 movie_aspect = (float)d_width/(float)d_height;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
135 old_movie_aspect = movie_aspect;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
136
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
137 //init OpenGL View
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
138 glView = [[CustomOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, d_width, d_height) pixelFormat:[CustomOpenGLView defaultPixelFormat]];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
139 [glView initOpenGLView];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
140
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
141 vo_fs = flags & VOFLAG_FULLSCREEN;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
142
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
143 if(vo_fs)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
144 [glView fullscreen: NO];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
145
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
146 if(vo_ontop)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
147 [glView ontop];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
148
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
149 return 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
150 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
151
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
152 static void check_events(void)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
153 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
154 [glView check_events];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
155
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
156 //update activity every 60 seconds to prevent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
157 //screensaver from starting up.
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
158 DateTimeRec d;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
159 unsigned long curTime;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
160 static unsigned long lastTime = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
161
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
162 GetTime(&d);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
163 DateToSeconds( &d, &curTime);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
164
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
165 if( ( (curTime - lastTime) >= 60) || (lastTime == 0))
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
166 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
167 UpdateSystemActivity(UsrActivity);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
168 lastTime = curTime;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
169 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
170 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
171
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
172 static void draw_osd(void)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
173 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
174 vo_draw_text(image_width, image_height, draw_alpha);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
175 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
176
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
177 static void flip_page(void)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
178 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
179 [glView render];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
180 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
181
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
182 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
183 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
184 [glView setCurrentTexture];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
185 return 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
186 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
187
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
188
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
189 static uint32_t draw_frame(uint8_t *src[])
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
190 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
191 switch (image_format)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
192 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
193 case IMGFMT_BGR32:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
194 case IMGFMT_RGB32:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
195 memcpy(image_data, src[0], image_width*image_height*image_bytes);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
196 break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
197
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
198 case IMGFMT_YUY2:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
199 memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
200 break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
201 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
202 [glView setCurrentTexture];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
203 return 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
204 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
205
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
206 static uint32_t query_format(uint32_t format)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
207 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
208 image_format = format;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
209
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
210 switch(format)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
211 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
212 case IMGFMT_YUY2:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
213 pixelFormat = kYUVSPixelFormat;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
214 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
215
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
216 case IMGFMT_RGB32:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
217 case IMGFMT_BGR32:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
218 pixelFormat = k32ARGBPixelFormat;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
219 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
220 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
221 return 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
222 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
223
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
224 static void uninit(void)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
225 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
226 [autoreleasepool release];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
227 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
228
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
229 static uint32_t preinit(const char *arg)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
230 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
231 int parse_err = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
232
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
233 if(arg)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
234 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
235 char *parse_pos = (char *)&arg[0];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
236 while (parse_pos[0] && !parse_err)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
237 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
238 if (strncmp (parse_pos, "device_id=", 10) == 0)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
239 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
240 parse_pos = &parse_pos[10];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
241 device_id = strtol(parse_pos, &parse_pos, 0);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
242 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
243 if (parse_pos[0] == ':') parse_pos = &parse_pos[1];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
244 else if (parse_pos[0]) parse_err = 1;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
245 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
246 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
247
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
248 #if !defined (MACOSX_FINDER_SUPPORT) || !defined (HAVE_SDL)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
249 //this chunk of code is heavily based off SDL_macosx.m from SDL
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
250 //it uses an Apple private function to request foreground operation
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
251 void CPSEnableForegroundOperation(ProcessSerialNumber* psn);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
252 ProcessSerialNumber myProc, frProc;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
253 Boolean sameProc;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
254
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
255 if (GetFrontProcess(&frProc) == noErr)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
256 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
257 if (GetCurrentProcess(&myProc) == noErr)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
258 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
259 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
260 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
261 CPSEnableForegroundOperation(&myProc);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
262 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
263 SetFrontProcess(&myProc);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
264 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
265 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
266 #endif
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
267
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
268 NSApplicationLoad();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
269 autoreleasepool = [[NSAutoreleasePool alloc] init];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
270
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
271 return 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
272 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
273
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
274 static uint32_t control(uint32_t request, void *data, ...)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
275 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
276 switch (request)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
277 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
278 case VOCTRL_PAUSE: return (int_pause=1);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
279 case VOCTRL_RESUME: return (int_pause=0);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
280 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data));
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
281 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); [glView ontop]; return VO_TRUE;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
282 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); [glView fullscreen: YES]; return VO_TRUE;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
283 case VOCTRL_GET_PANSCAN: return VO_TRUE;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
284 case VOCTRL_SET_PANSCAN: [glView panscan]; return VO_TRUE;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
285 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
286 return VO_NOTIMPL;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
287 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
288
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
289 //////////////////////////////////////////////////////////////////////////
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
290 // NSOpenGLView Subclass
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
291 //////////////////////////////////////////////////////////////////////////
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
292 @implementation CustomOpenGLView
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
293 - (void) initOpenGLView
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
294 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
295 NSRect frame = [self frame];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
296 CVReturn error = kCVReturnSuccess;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
297
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
298 //create OpenGL Context
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
299 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
300
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
301
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
302 //create window
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
303 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, frame.size.width, frame.size.height)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
304 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
305 backing:NSBackingStoreBuffered
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
306 defer:NO];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
307
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
308 [window setContentView:self];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
309 [window setInitialFirstResponder:self];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
310 [window setAcceptsMouseMovedEvents:YES];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
311 [window setTitle:@"MPlayer - The Movie Player"];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
312 [window center];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
313 [window makeKeyAndOrderFront:nil];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
314
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
315 [self setOpenGLContext:glContext];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
316 [glContext setView:self];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
317 [glContext makeCurrentContext];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
318
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
319 error = CVPixelBufferCreateWithBytes( NULL,
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
320 image_width, image_height,
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
321 pixelFormat,
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
322 image_data,
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
323 image_width*image_bytes,
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
324 NULL, NULL, NULL,
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
325 &currentFrameBuffer);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
326 if(error != kCVReturnSuccess)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
327 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
328
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
329 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
330 if(error != kCVReturnSuccess)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
331 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
332
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
333 error = CVOpenGLTextureCacheCreateTextureFromImage( NULL, textureCache, currentFrameBuffer, 0, &texture);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
334 if(error != kCVReturnSuccess)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
335 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
336
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
337 isFullscreen = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
338 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
339
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
340 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
341 Setup OpenGL
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
342 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
343 - (void)prepareOpenGL
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
344 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
345 glDisable(GL_BLEND);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
346 glDisable(GL_DEPTH_TEST);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
347 glDepthMask(GL_FALSE);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
348 glDisable(GL_CULL_FACE);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
349 [self reshape];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
350 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
351
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
352 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
353 reshape OpenGL viewport
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
354 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
355 - (void)reshape
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
356 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
357 uint32_t d_width;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
358 uint32_t d_height;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
359 float aspectX;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
360 float aspectY;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
361 int padding = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
362
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
363 NSRect frame = [self frame];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
364
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
365 glViewport(0, 0, frame.size.width, frame.size.height);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
366 glMatrixMode(GL_PROJECTION);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
367 glLoadIdentity();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
368 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
369 glMatrixMode(GL_MODELVIEW);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
370 glLoadIdentity();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
371
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
372 //set image_rec
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
373 if(vo_keepaspect)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
374 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
375 aspect( &d_width, &d_height, A_NOZOOM);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
376 d_height = ((float)d_width/movie_aspect);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
377
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
378 aspectX = (float)((float)frame.size.width/(float)d_width);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
379 aspectY = (float)((float)(frame.size.height)/(float)d_height);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
380
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
381 if((d_height*aspectX)>(frame.size.height))
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
382 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
383 padding = (frame.size.width - d_width*aspectY)/2;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
384 image_rec.origin.x = padding;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
385 image_rec.origin.y = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
386 image_rec.size.width = d_width*aspectY+padding;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
387 image_rec.size.height = d_height*aspectY;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
388 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
389 else
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
390 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
391 padding = ((frame.size.height) - d_height*aspectX)/2;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
392 image_rec.origin.x = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
393 image_rec.origin.y = padding;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
394 image_rec.size.width = d_width*aspectX;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
395 image_rec.size.height = d_height*aspectX+padding;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
396 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
397 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
398 else
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
399 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
400 image_rec = frame;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
401 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
402 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
403
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
404 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
405 Render frame
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
406 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
407 - (void) render
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
408 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
409 glClear(GL_COLOR_BUFFER_BIT);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
410
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
411 glEnable(CVOpenGLTextureGetTarget(texture));
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
412 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture));
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
413
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
414 glColor3f(1,1,1);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
415 glBegin(GL_QUADS);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
416 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i(image_rec.origin.x, image_rec.origin.y);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
417 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i(image_rec.origin.x, image_rec.size.height);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
418 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i(image_rec.size.width, image_rec.size.height);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
419 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i(image_rec.size.width, image_rec.origin.y);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
420 glEnd();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
421
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
422 glFlush();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
423
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
424 //auto hide mouse cursor and futur on-screen control?
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
425 if(isFullscreen && !mouseHide)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
426 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
427 DateTimeRec d;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
428 unsigned long curTime;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
429 static unsigned long lastTime = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
430
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
431 GetTime(&d);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
432 DateToSeconds( &d, &curTime);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
433
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
434 if( ((curTime - lastTime) >= 5) || (lastTime == 0) )
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
435 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
436 HideMenuBar();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
437 HideCursor();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
438 mouseHide = YES;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
439 lastTime = curTime;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
440 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
441 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
442 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
443
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
444 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
445 Create OpenGL texture from current frame & set texco
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
446 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
447 - (void) setCurrentTexture
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
448 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
449 CVReturn error = kCVReturnSuccess;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
450
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
451 error = CVOpenGLTextureCacheCreateTextureFromImage (NULL, textureCache, currentFrameBuffer, 0, &texture);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
452 if(error != kCVReturnSuccess)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
453 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
454
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
455 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
456 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
457
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
458 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
459 redraw win rect
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
460 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
461 - (void) drawRect: (NSRect *) bounds
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
462 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
463 [self render];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
464 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
465
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
466 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
467 Toggle Fullscreen
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
468 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
469 - (void) fullscreen: (BOOL) animate
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
470 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
471 static NSRect old_frame;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
472 static NSRect old_view_frame;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
473 NSRect device_rect = [[window screen] frame];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
474
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
475 //go fullscreen
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
476 if(vo_fs)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
477 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
478 //hide menubar and mouse if fullscreen on main display
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
479 HideMenuBar();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
480 HideCursor();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
481 mouseHide = YES;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
482
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
483 panscan_calc();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
484 old_frame = [window frame]; //save main window size & position
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
485 [window setFrame:device_rect display:YES animate:animate]; //zoom-in window with nice useless sfx
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
486 old_view_frame = [self bounds];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
487
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
488 //fix origin for multi screen setup
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
489 device_rect.origin.x = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
490 device_rect.origin.y = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
491 [self setFrame:device_rect];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
492 [self setNeedsDisplay:YES];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
493 [window setHasShadow:NO];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
494 isFullscreen = 1;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
495 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
496 else
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
497 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
498 isFullscreen = 0;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
499 ShowMenuBar();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
500 ShowCursor();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
501 mouseHide = NO;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
502
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
503 //revert window to previous setting
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
504 [self setFrame:old_view_frame];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
505 [self setNeedsDisplay:YES];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
506 [window setHasShadow:NO];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
507 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
508 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
509 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
510
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
511 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
512 Toggle ontop
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
513 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
514 - (void) ontop
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
515 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
516 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
517
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
518 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
519 Toggle panscan
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
520 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
521 - (void) panscan
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
522 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
523 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
524
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
525 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
526 Check event for new event
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
527 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
528 - (void) check_events
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
529 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
530 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
531 [NSApp sendEvent:event];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
532 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
533
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
534 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
535 Process key event
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
536 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
537 - (void) keyDown: (NSEvent *) theEvent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
538 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
539 unsigned int key;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
540
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
541 switch([theEvent keyCode])
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
542 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
543 case 0x34:
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
544 case 0x24: key = KEY_ENTER; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
545 case 0x35: key = KEY_ESC; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
546 case 0x33: key = KEY_BACKSPACE; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
547 case 0x3A: key = KEY_BACKSPACE; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
548 case 0x3B: key = KEY_BACKSPACE; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
549 case 0x38: key = KEY_BACKSPACE; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
550 case 0x7A: key = KEY_F+1; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
551 case 0x78: key = KEY_F+2; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
552 case 0x63: key = KEY_F+3; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
553 case 0x76: key = KEY_F+4; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
554 case 0x60: key = KEY_F+5; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
555 case 0x61: key = KEY_F+6; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
556 case 0x62: key = KEY_F+7; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
557 case 0x64: key = KEY_F+8; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
558 case 0x65: key = KEY_F+9; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
559 case 0x6D: key = KEY_F+10; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
560 case 0x67: key = KEY_F+11; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
561 case 0x6F: key = KEY_F+12; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
562 case 0x72: key = KEY_INSERT; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
563 case 0x75: key = KEY_DELETE; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
564 case 0x73: key = KEY_HOME; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
565 case 0x77: key = KEY_END; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
566 case 0x45: key = '+'; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
567 case 0x4E: key = '-'; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
568 case 0x30: key = KEY_TAB; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
569 case 0x74: key = KEY_PAGE_UP; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
570 case 0x79: key = KEY_PAGE_DOWN; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
571 case 0x7B: key = KEY_LEFT; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
572 case 0x7C: key = KEY_RIGHT; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
573 case 0x7D: key = KEY_DOWN; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
574 case 0x7E: key = KEY_UP; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
575 case 0x43: key = '*'; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
576 case 0x4B: key = '/'; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
577 case 0x4C: key = KEY_BACKSPACE; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
578 case 0x41: key = KEY_KPDEC; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
579 case 0x52: key = KEY_KP0; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
580 case 0x53: key = KEY_KP1; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
581 case 0x54: key = KEY_KP2; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
582 case 0x55: key = KEY_KP3; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
583 case 0x56: key = KEY_KP4; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
584 case 0x57: key = KEY_KP5; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
585 case 0x58: key = KEY_KP6; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
586 case 0x59: key = KEY_KP7; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
587 case 0x5B: key = KEY_KP8; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
588 case 0x5C: key = KEY_KP9; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
589 default: key = *[[theEvent characters] UTF8String]; break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
590 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
591 mplayer_put_key(key);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
592 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
593
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
594 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
595 Process mouse button event
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
596 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
597 - (void) mouseMoved: (NSEvent *) theEvent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
598 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
599 if(isFullscreen)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
600 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
601 ShowMenuBar();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
602 ShowCursor();
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
603 mouseHide = NO;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
604 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
605 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
606
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
607 - (void) mouseDown: (NSEvent *) theEvent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
608 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
609 [self mouseEvent: theEvent];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
610 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
611
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
612 - (void) rightMouseDown: (NSEvent *) theEvent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
613 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
614 [self mouseEvent: theEvent];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
615 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
616
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
617 - (void) otherMouseDown: (NSEvent *) theEvent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
618 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
619 [self mouseEvent: theEvent];
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
620 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
621
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
622 - (void) scrollWheel: (NSEvent *) theEvent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
623 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
624 if([theEvent deltaY] > 0)
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
625 mplayer_put_key(MOUSE_BTN3);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
626 else
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
627 mplayer_put_key(MOUSE_BTN4);
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
628 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
629
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
630 - (void) mouseEvent: (NSEvent *) theEvent
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
631 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
632 switch( [theEvent buttonNumber] )
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
633 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
634 case 0: mplayer_put_key(MOUSE_BTN0);break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
635 case 1: mplayer_put_key(MOUSE_BTN1);break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
636 case 2: mplayer_put_key(MOUSE_BTN2);break;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
637 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
638 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
639
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
640 /*
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
641 NSResponder
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
642 */
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
643 - (BOOL) acceptsFirstResponder
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
644 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
645 return YES;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
646 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
647
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
648 - (BOOL) becomeFirstResponder
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
649 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
650 return YES;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
651 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
652
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
653 - (BOOL) resignFirstResponder
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
654 {
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
655 return YES;
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
656 }
e985d786c5f1 macosx core video module
nplourde
parents:
diff changeset
657 @end