1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
6 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
7 * Samuel Hocevar <sam@zoy.org>
8 * Tony Castley <tcastley@mail.powerup.com.au>
9 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 #define MODULE_NAME beos
27 #include "modules_inner.h"
29 /*****************************************************************************
31 *****************************************************************************/
34 #include <errno.h> /* ENOMEM */
35 #include <stdlib.h> /* free() */
37 #include <string.h> /* strerror() */
38 #include <kernel/OS.h>
40 #include <Application.h>
57 #include "video_output.h"
59 #include "interface.h"
65 #include "VideoWindow.h"
70 #define BITS_PER_PLANE 16
71 #define BYTES_PER_PIXEL 2
73 /*****************************************************************************
74 * vout_sys_t: BeOS video output method descriptor
75 *****************************************************************************
76 * This structure is part of the video output thread descriptor.
77 * It describes the BeOS specific properties of an output thread.
78 *****************************************************************************/
80 typedef struct vout_sys_s
82 VideoWindow * p_window;
84 byte_t * pp_buffer[2];
90 /*****************************************************************************
91 * beos_GetAppWindow : retrieve a BWindow pointer from the window name
92 *****************************************************************************/
94 BWindow *beos_GetAppWindow(char *name)
99 for (index = 0 ; ; index++)
101 window = be_app->WindowAt(index);
104 if (window->LockWithTimeout(200000) == B_OK)
106 if (strcmp(window->Name(), name) == 0)
117 /*****************************************************************************
118 * DrawingThread : thread that really does the drawing
119 *****************************************************************************/
121 int32 DrawingThread(void *data)
124 w = (VideoWindow*) data;
126 while(!w->teardownwindow)
131 w->view->DrawBitmap(w->bitmap[w->i_buffer_index], w->bitmap[w->i_buffer_index]->Bounds(), w->Bounds());
140 /*****************************************************************************
141 * VideoWindow constructor and destructor
142 *****************************************************************************/
144 VideoWindow::VideoWindow(BRect frame, const char *name, vout_thread_t *p_video_output )
145 : BWindow(frame, name, B_TITLED_WINDOW, NULL)
147 float minWidth, minHeight, maxWidth, maxHeight;
149 teardownwindow = false;
151 p_vout = p_video_output;
152 fDrawThreadID = NULL;
155 view = new VLCView(Bounds());
157 bitmap[0] = new BBitmap(Bounds(), B_BITMAP_WILL_OVERLAY|B_BITMAP_RESERVE_OVERLAY_CHANNEL, B_YCbCr422);
158 fUsingOverlay = true;
160 p_vout->b_YCbr = true;
162 if (bitmap[0]->InitCheck() != B_OK)
165 p_vout->b_YCbr = false;
166 fUsingOverlay = false;
168 screen = new BScreen();
169 color_space space = screen->ColorSpace();
174 bitmap[0] = new BBitmap(Bounds(), B_RGB15);
175 bitmap[1] = new BBitmap(Bounds(), B_RGB15);
178 else if(space == B_RGB16)
180 bitmap[0] = new BBitmap(Bounds(), B_RGB16);
181 bitmap[1] = new BBitmap(Bounds(), B_RGB16);
184 else //default to 32bpp
186 bitmap[0] = new BBitmap(Bounds(), B_RGB32);
187 bitmap[1] = new BBitmap(Bounds(), B_RGB32);
190 memset(bitmap[0]->Bits(), 0, bitmap[0]->BitsLength());
191 memset(bitmap[1]->Bits(), 0, bitmap[1]->BitsLength());
192 SetTitle(VOUT_TITLE " (BBitmap output)");
197 memset(bitmap[0]->Bits(), 0, bitmap[0]->BitsLength());
199 view->SetViewOverlay(bitmap[0], bitmap[0]->Bounds(), Bounds(), &key, B_FOLLOW_ALL,
200 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
201 view->SetViewColor(key);
202 SetTitle(VOUT_TITLE " (Overlay output)");
203 GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
204 SetSizeLimits((float) Bounds().IntegerWidth(), maxWidth, (float) Bounds().IntegerHeight(), maxHeight);
208 fDrawThreadID = spawn_thread(DrawingThread, "drawing_thread",
209 B_DISPLAY_PRIORITY, (void*) this);
210 resume_thread(fDrawThreadID);
213 i_bytes_per_pixel = bitmap[0]->BytesPerRow()/bitmap[0]->Bounds().IntegerWidth();
214 fRowBytes = bitmap[0]->BytesPerRow();
219 VideoWindow::~VideoWindow()
227 teardownwindow = true;
228 wait_for_thread(fDrawThreadID, &result);
235 /*****************************************************************************
236 * VideoWindow::FrameResized
237 *****************************************************************************/
238 void VideoWindow::FrameResized( float width, float height )
242 /*****************************************************************************
244 *****************************************************************************/
246 void VideoWindow::Zoom(BPoint origin, float width, float height )
250 MoveTo(rect.left, rect.top);
251 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
252 be_app->ShowCursor();
258 screen = new BScreen(this);
259 BRect rect = screen->Frame();
262 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
263 be_app->HideCursor();
265 is_zoomed = !is_zoomed;
268 /*****************************************************************************
269 * VideoWindow::MessageReceived
270 *****************************************************************************/
272 void VideoWindow::MessageReceived( BMessage * p_message )
276 switch( p_message->what )
280 // post the message to the interface window which will handle it
281 p_win = beos_GetAppWindow( "interface" );
284 p_win->PostMessage( p_message );
289 BWindow::MessageReceived( p_message );
294 /*****************************************************************************
295 * VideoWindow::QuitRequested
296 *****************************************************************************/
298 bool VideoWindow::QuitRequested()
300 /* FIXME: send a message ! */
301 p_main->p_intf->b_die = 1;
302 teardownwindow = true;
306 /*****************************************************************************
308 *****************************************************************************/
309 VLCView::VLCView(BRect bounds) : BView(bounds, "", B_FOLLOW_ALL, B_WILL_DRAW)
311 SetViewColor(B_TRANSPARENT_32_BIT);
314 /*****************************************************************************
316 *****************************************************************************/
322 /*****************************************************************************
324 *****************************************************************************/
325 void VLCView::MouseDown(BPoint point)
327 VideoWindow *w = (VideoWindow *) Window();
330 BWindow *win = Window();
338 /*****************************************************************************
340 *****************************************************************************/
341 static int vout_Probe ( probedata_t *p_data );
342 static int vout_Create ( struct vout_thread_s * );
343 static int vout_Init ( struct vout_thread_s * );
344 static void vout_End ( struct vout_thread_s * );
345 static void vout_Destroy ( struct vout_thread_s * );
346 static int vout_Manage ( struct vout_thread_s * );
347 static void vout_Display ( struct vout_thread_s * );
349 static int BeosOpenDisplay ( vout_thread_t *p_vout );
350 static void BeosCloseDisplay( vout_thread_t *p_vout );
352 /*****************************************************************************
353 * Functions exported as capabilities. They are declared as static so that
354 * we don't pollute the namespace too much.
355 *****************************************************************************/
356 void _M( vout_getfunctions )( function_list_t * p_function_list )
358 p_function_list->pf_probe = vout_Probe;
359 p_function_list->functions.vout.pf_create = vout_Create;
360 p_function_list->functions.vout.pf_init = vout_Init;
361 p_function_list->functions.vout.pf_end = vout_End;
362 p_function_list->functions.vout.pf_destroy = vout_Destroy;
363 p_function_list->functions.vout.pf_manage = vout_Manage;
364 p_function_list->functions.vout.pf_display = vout_Display;
365 p_function_list->functions.vout.pf_setpalette = NULL;
368 /*****************************************************************************
369 * vout_Probe: probe the video driver and return a score
370 *****************************************************************************
371 * This function tries to initialize SDL and returns a score to the
372 * plugin manager so that it can select the best plugin.
373 *****************************************************************************/
374 static int vout_Probe( probedata_t *p_data )
376 if( TestMethod( VOUT_METHOD_VAR, "beos" ) )
384 /*****************************************************************************
385 * vout_Create: allocates BeOS video thread output method
386 *****************************************************************************
387 * This function allocates and initializes a BeOS vout method.
388 *****************************************************************************/
389 int vout_Create( vout_thread_t *p_vout )
391 /* Allocate structure */
392 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
393 if( p_vout->p_sys == NULL )
395 intf_ErrMsg( "error: %s", strerror(ENOMEM) );
399 /* Set video window's size */
400 p_vout->i_width = main_GetIntVariable( VOUT_WIDTH_VAR,
401 VOUT_WIDTH_DEFAULT );
402 p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
403 VOUT_HEIGHT_DEFAULT );
405 /* Open and initialize device */
406 if( BeosOpenDisplay( p_vout ) )
408 intf_ErrMsg("vout error: can't open display");
409 free( p_vout->p_sys );
416 /*****************************************************************************
417 * vout_Init: initialize BeOS video thread output method
418 *****************************************************************************/
419 int vout_Init( vout_thread_t *p_vout )
421 VideoWindow * p_win = p_vout->p_sys->p_window;
425 i_page_size = p_vout->i_width * p_vout->i_height * p_vout->i_bytes_per_pixel;
427 p_vout->p_sys->i_width = p_vout->i_width;
428 p_vout->p_sys->i_height = p_vout->i_height;
430 if(p_win->fUsingOverlay)
432 vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
433 (byte_t *)p_win->bitmap[0]->Bits());
434 delete p_win->bitmap[0];
438 vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
439 (byte_t *)p_win->bitmap[1]->Bits());
444 /*****************************************************************************
445 * vout_End: terminate BeOS video thread output method
446 *****************************************************************************/
447 void vout_End( vout_thread_t *p_vout )
451 /*****************************************************************************
452 * vout_Destroy: destroy BeOS video thread output method
453 *****************************************************************************
454 * Terminate an output method created by DummyCreateOutputMethod
455 *****************************************************************************/
456 void vout_Destroy( vout_thread_t *p_vout )
458 BeosCloseDisplay( p_vout );
460 free( p_vout->p_sys );
463 /*****************************************************************************
464 * vout_Manage: handle BeOS events
465 *****************************************************************************
466 * This function should be called regularly by video output thread. It manages
467 * console events. It returns a non null value on error.
468 *****************************************************************************/
469 int vout_Manage( vout_thread_t *p_vout )
474 /*****************************************************************************
475 * vout_Display: displays previously rendered output
476 *****************************************************************************
477 * This function send the currently rendered image to BeOS image, waits until
478 * it is displayed and switch the two rendering buffers, preparing next frame.
479 *****************************************************************************/
480 void vout_Display( vout_thread_t *p_vout )
482 VideoWindow * p_win = p_vout->p_sys->p_window;
484 p_win->i_buffer_index = p_vout->i_buffer_index;
485 p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
486 p_win->fDirty = true;
489 /* following functions are local */
491 /*****************************************************************************
492 * BeosOpenDisplay: open and initialize BeOS device
493 *****************************************************************************
494 * XXX?? The framebuffer mode is only provided as a fast and efficient way to
495 * display video, providing the card is configured and the mode ok. It is
496 * not portable, and is not supposed to work with many cards. Use at your
498 *****************************************************************************/
500 static int BeosOpenDisplay( vout_thread_t *p_vout )
502 p_vout->p_sys->p_window =
503 new VideoWindow( BRect( 80, 50, 80+p_vout->i_width-1, 50+p_vout->i_height-1 ), NULL, p_vout );
504 if( p_vout->p_sys->p_window == 0 )
506 free( p_vout->p_sys );
507 intf_ErrMsg( "error: cannot allocate memory for VideoWindow" );
510 VideoWindow * p_win = p_vout->p_sys->p_window;
512 p_vout->i_screen_depth = p_win->i_screen_depth;
513 p_vout->i_bytes_per_pixel = p_win->i_bytes_per_pixel;
514 p_vout->i_bytes_per_line = p_vout->i_width*p_win->i_bytes_per_pixel;
516 switch( p_vout->i_screen_depth )
519 intf_ErrMsg( "vout error: 8 bit mode not fully supported" );
522 p_vout->i_red_mask = 0x7c00;
523 p_vout->i_green_mask = 0x03e0;
524 p_vout->i_blue_mask = 0x001f;
527 p_vout->i_red_mask = 0xf800;
528 p_vout->i_green_mask = 0x07e0;
529 p_vout->i_blue_mask = 0x001f;
534 p_vout->i_red_mask = 0xff0000;
535 p_vout->i_green_mask = 0x00ff00;
536 p_vout->i_blue_mask = 0x0000ff;
542 /*****************************************************************************
543 * BeosDisplay: close and reset BeOS device
544 *****************************************************************************
545 * Returns all resources allocated by BeosOpenDisplay and restore the original
546 * state of the device.
547 *****************************************************************************/
548 static void BeosCloseDisplay( vout_thread_t *p_vout )
550 /* Destroy the video window */
551 p_vout->p_sys->p_window->Lock();
552 p_vout->p_sys->p_window->Quit();