vout_beos.cpp 19.4 KB
Newer Older
1
2
3
/*****************************************************************************
 * vout_beos.cpp: beos video output display method
 *****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
4
 * Copyright (C) 2000, 2001 VideoLAN
5
 * $Id: vout_beos.cpp,v 1.23 2001/03/25 17:09:14 richards Exp $
6
 *
Sam Hocevar's avatar
   
Sam Hocevar committed
7
8
 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
 *          Samuel Hocevar <sam@zoy.org>
Richard Shepherd's avatar
Richard Shepherd committed
9
 *          Tony Castley <tcastley@mail.powerup.com.au>
Sam Hocevar's avatar
   
Sam Hocevar committed
10
 *          Richard Shepherd <richard@rshepherd.demon.co.uk>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

Sam Hocevar's avatar
   
Sam Hocevar committed
27
28
29
#define MODULE_NAME beos
#include "modules_inner.h"

30
31
32
33
34
35
36
37
38
39
40
41
/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include "defs.h"

#include <errno.h>                                                 /* ENOMEM */
#include <stdlib.h>                                                /* free() */
#include <stdio.h>
#include <string.h>                                            /* strerror() */
#include <kernel/OS.h>
#include <View.h>
#include <Application.h>
Sam Hocevar's avatar
   
Sam Hocevar committed
42
43
44
#include <Window.h>
#include <Locker.h>
#include <Screen.h>
45
46
47
48
49
50
51
52
53
#include <malloc.h>
#include <string.h>

extern "C"
{
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
Sam Hocevar's avatar
   
Sam Hocevar committed
54
55
#include "tests.h"
#include "modules.h"
56
57
58
59

#include "video.h"
#include "video_output.h"

Sam Hocevar's avatar
   
Sam Hocevar committed
60
#include "interface.h"
Sam Hocevar's avatar
   
Sam Hocevar committed
61
#include "intf_msg.h"
62
63
64
65

#include "main.h"
}

Sam Hocevar's avatar
   
Sam Hocevar committed
66
67
#include "VideoWindow.h"
#include <Screen.h>
68
69
70
71
72
73
74

#define WIDTH 128
#define HEIGHT 64
#define BITS_PER_PLANE 16
#define BYTES_PER_PIXEL 2

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
75
 * vout_sys_t: BeOS video output method descriptor
76
77
 *****************************************************************************
 * This structure is part of the video output thread descriptor.
Sam Hocevar's avatar
   
Sam Hocevar committed
78
 * It describes the BeOS specific properties of an output thread.
79
80
81
82
83
 *****************************************************************************/
 
typedef struct vout_sys_s
{
    VideoWindow *         p_window;
Sam Hocevar's avatar
   
Sam Hocevar committed
84

Sam Hocevar's avatar
   
Sam Hocevar committed
85
    byte_t *              pp_buffer[2];
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    s32                   i_width;
    s32                   i_height;
} vout_sys_t;


/*****************************************************************************
 * beos_GetAppWindow : retrieve a BWindow pointer from the window name
 *****************************************************************************/

BWindow *beos_GetAppWindow(char *name)
{
    int32       index;
    BWindow     *window;
    
    for (index = 0 ; ; index++)
    {
        window = be_app->WindowAt(index);
        if (window == NULL)
            break;
        if (window->LockWithTimeout(200000) == B_OK)
        {
            if (strcmp(window->Name(), name) == 0)
            {
                window->Unlock();
                break;
            }
            window->Unlock();
        }
    }
    return window; 
}

Sam Hocevar's avatar
   
Sam Hocevar committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*****************************************************************************
 * DrawingThread : thread that really does the drawing
 *****************************************************************************/

int32 DrawingThread(void *data)
{
    VideoWindow *w;
    w = (VideoWindow*) data;
    
    while(!w->teardownwindow)
    {
    w->Lock();
       if( w->fDirty )
            {
Richard Shepherd's avatar
Richard Shepherd committed
132
133
           	w->view->DrawBitmap(w->bitmap[w->i_buffer_index], w->bitmap[w->i_buffer_index]->Bounds(), w->Bounds());
            w->fDirty = false;
Sam Hocevar's avatar
   
Sam Hocevar committed
134
135
136
137
138
139
140
            }
    w->Unlock();
   	snooze(20000);
    }
    return B_OK;
}

141
142
143
144
145
/*****************************************************************************
 * VideoWindow constructor and destructor
 *****************************************************************************/

VideoWindow::VideoWindow(BRect frame, const char *name, vout_thread_t *p_video_output )
146
        : BWindow(frame, name, B_TITLED_WINDOW, NULL)
147
{
Sam Hocevar's avatar
   
Sam Hocevar committed
148
	float minWidth, minHeight, maxWidth, maxHeight; 
149

Sam Hocevar's avatar
   
Sam Hocevar committed
150
151
152
    teardownwindow = false;
    is_zoomed = false;
    p_vout = p_video_output;
Richard Shepherd's avatar
Richard Shepherd committed
153
	fDrawThreadID = NULL;
154
155
	bitmap[0] = NULL;
	bitmap[1] = NULL;
Richard Shepherd's avatar
Richard Shepherd committed
156
	
Sam Hocevar's avatar
   
Sam Hocevar committed
157
158
159
160
161
    rect = Frame();
    view = new VLCView(Bounds());
    AddChild(view);
	bitmap[0] = new BBitmap(Bounds(), B_BITMAP_WILL_OVERLAY|B_BITMAP_RESERVE_OVERLAY_CHANNEL, B_YCbCr422);
	fUsingOverlay = true;
162
	i_screen_depth = 16;
Sam Hocevar's avatar
   
Sam Hocevar committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
	p_vout->b_YCbr = true;
	
	if (bitmap[0]->InitCheck() != B_OK)
	{
		delete bitmap[0];
		p_vout->b_YCbr = false;
		fUsingOverlay = false;
		BScreen *screen;
		screen = new BScreen();
		color_space space = screen->ColorSpace();
		delete screen;

		if(space == B_RGB15)
			{
			bitmap[0] = new BBitmap(Bounds(), B_RGB15);
			bitmap[1] = new BBitmap(Bounds(), B_RGB15);
	    	i_screen_depth = 15;
		    }
		    else if(space == B_RGB16)
		 	{
			bitmap[0] = new BBitmap(Bounds(), B_RGB16);
			bitmap[1] = new BBitmap(Bounds(), B_RGB16);
	   		i_screen_depth = 16;
			}
			else //default to 32bpp
			{
			bitmap[0] = new BBitmap(Bounds(), B_RGB32);
			bitmap[1] = new BBitmap(Bounds(), B_RGB32);
	   		i_screen_depth = 32;
			}
		memset(bitmap[0]->Bits(), 0, bitmap[0]->BitsLength());
	 	memset(bitmap[1]->Bits(), 0, bitmap[1]->BitsLength());
Sam Hocevar's avatar
   
Sam Hocevar committed
195
	 	SetTitle(VOUT_TITLE " (BBitmap output)");
Sam Hocevar's avatar
   
Sam Hocevar committed
196
197
198
199
200
201
202
203
	 }

	if(fUsingOverlay)
		{
		rgb_color key;
		view->SetViewOverlay(bitmap[0], bitmap[0]->Bounds(), Bounds(), &key, B_FOLLOW_ALL,
				B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
		view->SetViewColor(key);
Sam Hocevar's avatar
   
Sam Hocevar committed
204
	 	SetTitle(VOUT_TITLE " (Overlay output)");
Sam Hocevar's avatar
   
Sam Hocevar committed
205
206
		GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); 
		SetSizeLimits((float) Bounds().IntegerWidth(), maxWidth, (float) Bounds().IntegerHeight(), maxHeight);
207
		memset(bitmap[0]->Bits(), 0, bitmap[0]->BitsLength());
Sam Hocevar's avatar
   
Sam Hocevar committed
208
		}
Richard Shepherd's avatar
Richard Shepherd committed
209
	else
Richard Shepherd's avatar
Richard Shepherd committed
210
211
		{
    	fDrawThreadID = spawn_thread(DrawingThread, "drawing_thread",
Sam Hocevar's avatar
   
Sam Hocevar committed
212
                    B_DISPLAY_PRIORITY, (void*) this);
Richard Shepherd's avatar
Richard Shepherd committed
213
214
215
216
217
218
    	resume_thread(fDrawThreadID);
    	}

	i_bytes_per_pixel = bitmap[0]->BytesPerRow()/bitmap[0]->Bounds().IntegerWidth();
    fRowBytes = bitmap[0]->BytesPerRow();
    fDirty = false;
219
220
221
222
223
    Show();
}

VideoWindow::~VideoWindow()
{
Sam Hocevar's avatar
   
Sam Hocevar committed
224
225
226
227
228
    int32 result;

    Hide();
    Sync();
    if(!fUsingOverlay)
Richard Shepherd's avatar
Richard Shepherd committed
229
    	{
Richard Shepherd's avatar
Richard Shepherd committed
230
	    teardownwindow = true;
Richard Shepherd's avatar
Richard Shepherd committed
231
	    wait_for_thread(fDrawThreadID, &result);
Richard Shepherd's avatar
Richard Shepherd committed
232
    	delete bitmap[0];
Sam Hocevar's avatar
   
Sam Hocevar committed
233
    	delete bitmap[1];
Richard Shepherd's avatar
Richard Shepherd committed
234
    	}
Sam Hocevar's avatar
   
Sam Hocevar committed
235
236
 }

237

Sam Hocevar's avatar
   
Sam Hocevar committed
238
239
240
241
242
/*****************************************************************************
 * VideoWindow::FrameResized
 *****************************************************************************/
void VideoWindow::FrameResized( float width, float height )
{
Sam Hocevar's avatar
   
Sam Hocevar committed
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
}

/*****************************************************************************
 * VideoWindow::Zoom
 *****************************************************************************/

void VideoWindow::Zoom(BPoint origin, float width, float height )
{
if(is_zoomed)
	{
	MoveTo(rect.left, rect.top);
	ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
	be_app->ShowCursor();
	}
else
	{
	rect = Frame();
	BScreen *screen;
	screen = new BScreen(this);
	BRect rect = screen->Frame();
	delete screen;
	MoveTo(0,0);
	ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
	be_app->HideCursor();
	}
is_zoomed = !is_zoomed;
Sam Hocevar's avatar
   
Sam Hocevar committed
269
270
}

271
272
273
274
275
276
277
278
279
280
281
/*****************************************************************************
 * VideoWindow::MessageReceived
 *****************************************************************************/

void VideoWindow::MessageReceived( BMessage * p_message )
{
    BWindow * p_win;
    
    switch( p_message->what )
    {
    case B_KEY_DOWN:
Sam Hocevar's avatar
   
Sam Hocevar committed
282
    case B_SIMPLE_DATA:
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
        // post the message to the interface window which will handle it
        p_win = beos_GetAppWindow( "interface" );
        if( p_win != NULL )
        {
            p_win->PostMessage( p_message );
        }
        break;
    
    default:
        BWindow::MessageReceived( p_message );
        break;
    }
}

/*****************************************************************************
 * VideoWindow::QuitRequested
 *****************************************************************************/

bool VideoWindow::QuitRequested()
{
Sam Hocevar's avatar
   
Sam Hocevar committed
303
304
    /* FIXME: send a message ! */
    p_main->p_intf->b_die = 1;
Sam Hocevar's avatar
   
Sam Hocevar committed
305
    teardownwindow = true;
Sam Hocevar's avatar
   
Sam Hocevar committed
306
    return( false );
307
308
}

Sam Hocevar's avatar
   
Sam Hocevar committed
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*****************************************************************************
 * VLCView::VLCView
 *****************************************************************************/
VLCView::VLCView(BRect bounds) : BView(bounds, "", B_FOLLOW_ALL, B_WILL_DRAW)
{
SetViewColor(B_TRANSPARENT_32_BIT);
}

/*****************************************************************************
 * VLCView::~VLCView
 *****************************************************************************/
VLCView::~VLCView()
{

}

/*****************************************************************************
 * VLCVIew::~VLCView
 *****************************************************************************/
void VLCView::MouseDown(BPoint point)
{
VideoWindow *w = (VideoWindow *) Window();
if(w->is_zoomed)
	{
	BWindow *win = Window();
	win->Zoom();
	}
}

338
339
340
341
342
343
extern "C"
{

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
static int  vout_Probe      ( probedata_t *p_data );
static int  vout_Create     ( struct vout_thread_s * );
static int  vout_Init       ( struct vout_thread_s * );
static void vout_End        ( struct vout_thread_s * );
static void vout_Destroy    ( struct vout_thread_s * );
static int  vout_Manage     ( struct vout_thread_s * );
static void vout_Display    ( struct vout_thread_s * );

static int  BeosOpenDisplay ( vout_thread_t *p_vout );
static void BeosCloseDisplay( vout_thread_t *p_vout );

/*****************************************************************************
 * Functions exported as capabilities. They are declared as static so that
 * we don't pollute the namespace too much.
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
359
void _M( vout_getfunctions )( function_list_t * p_function_list )
Sam Hocevar's avatar
   
Sam Hocevar committed
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
{
    p_function_list->pf_probe = vout_Probe;
    p_function_list->functions.vout.pf_create     = vout_Create;
    p_function_list->functions.vout.pf_init       = vout_Init;
    p_function_list->functions.vout.pf_end        = vout_End;
    p_function_list->functions.vout.pf_destroy    = vout_Destroy;
    p_function_list->functions.vout.pf_manage     = vout_Manage;
    p_function_list->functions.vout.pf_display    = vout_Display;
    p_function_list->functions.vout.pf_setpalette = NULL;
}

/*****************************************************************************
 * vout_Probe: probe the video driver and return a score
 *****************************************************************************
 * This function tries to initialize SDL and returns a score to the
 * plugin manager so that it can select the best plugin.
 *****************************************************************************/
static int vout_Probe( probedata_t *p_data )
{
    if( TestMethod( VOUT_METHOD_VAR, "beos" ) )
    {
        return( 999 );
    }

    return( 100 );
}
386
387

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
388
 * vout_Create: allocates BeOS video thread output method
389
 *****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
390
 * This function allocates and initializes a BeOS vout method.
391
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
392
int vout_Create( vout_thread_t *p_vout )
393
394
395
396
397
{
    /* Allocate structure */
    p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
    {
Sam Hocevar's avatar
   
Sam Hocevar committed
398
        intf_ErrMsg( "error: %s", strerror(ENOMEM) );
399
400
401
402
        return( 1 );
    }
    
    /* Set video window's size */
Sam Hocevar's avatar
   
Sam Hocevar committed
403
404
405
406
    p_vout->i_width =  main_GetIntVariable( VOUT_WIDTH_VAR,
                                            VOUT_WIDTH_DEFAULT );
    p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
                                            VOUT_HEIGHT_DEFAULT );
407
408
409
410

    /* Open and initialize device */
    if( BeosOpenDisplay( p_vout ) )
    {
Sam Hocevar's avatar
   
Sam Hocevar committed
411
        intf_ErrMsg("vout error: can't open display");
412
413
414
415
416
417
418
419
        free( p_vout->p_sys );
        return( 1 );
    }

    return( 0 );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
420
 * vout_Init: initialize BeOS video thread output method
421
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
422
int vout_Init( vout_thread_t *p_vout )
423
424
{
    VideoWindow * p_win = p_vout->p_sys->p_window;
Sam Hocevar's avatar
   
Sam Hocevar committed
425
    u32 i_page_size;
426

Sam Hocevar's avatar
   
Sam Hocevar committed
427
428

    i_page_size =   p_vout->i_width * p_vout->i_height * p_vout->i_bytes_per_pixel;
429
    
Sam Hocevar's avatar
   
Sam Hocevar committed
430
431
432
433
434
    p_vout->p_sys->i_width =         p_vout->i_width;
    p_vout->p_sys->i_height =        p_vout->i_height;    

    if(p_win->fUsingOverlay)
    	{
435
436
437
	    if(p_win->bitmap[0] != NULL)
	    	{
		    vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
Sam Hocevar's avatar
   
Sam Hocevar committed
438
    	                 (byte_t *)p_win->bitmap[0]->Bits());
439
440
441
	    	delete p_win->bitmap[0];
	    	p_win->bitmap[0] = NULL;
	    	}
Sam Hocevar's avatar
   
Sam Hocevar committed
442
    	}
443
    else
Sam Hocevar's avatar
   
Sam Hocevar committed
444
   		{
445
446
447
	    if((p_win->bitmap[0] != NULL) && (p_win->bitmap[1] != NULL))
	    	{
	    	vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
Sam Hocevar's avatar
   
Sam Hocevar committed
448
   	                 (byte_t *)p_win->bitmap[1]->Bits());
449
   	        }
Sam Hocevar's avatar
   
Sam Hocevar committed
450
    	}
451
452
453
454
    return( 0 );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
455
 * vout_End: terminate BeOS video thread output method
456
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
457
void vout_End( vout_thread_t *p_vout )
458
459
460
461
{
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
462
 * vout_Destroy: destroy BeOS video thread output method
463
464
465
 *****************************************************************************
 * Terminate an output method created by DummyCreateOutputMethod
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
466
void vout_Destroy( vout_thread_t *p_vout )
467
468
469
470
471
472
473
{
    BeosCloseDisplay( p_vout );
    
    free( p_vout->p_sys );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
474
 * vout_Manage: handle BeOS events
475
476
477
478
 *****************************************************************************
 * This function should be called regularly by video output thread. It manages
 * console events. It returns a non null value on error.
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
479
int vout_Manage( vout_thread_t *p_vout )
480
{
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
VideoWindow * p_win = p_vout->p_sys->p_window;
rgb_color key;
float minWidth, minHeight, maxWidth, maxHeight; 

if( (p_vout->i_width  != p_vout->p_sys->i_width) ||
             (p_vout->i_height != p_vout->p_sys->i_height) )
    {
        /* If video output size has changed, change interface window size */
        intf_DbgMsg( "resizing output window" );
        if(p_win->fUsingOverlay)
        	{
	        p_win->Lock();
	        p_win->view->ClearViewOverlay();
	        p_vout->p_sys->i_width =    p_vout->i_width;
	        p_vout->p_sys->i_height =   p_vout->i_height;;
			p_win->GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); 
			p_win->SetSizeLimits((float) p_vout->p_sys->i_width, maxWidth, (float) p_vout->p_sys->i_height, maxHeight);       
	        p_win->ResizeTo(p_vout->p_sys->i_width, p_vout->p_sys->i_height);
	        p_win->bitmap[0] = new BBitmap(p_win->Bounds(),
        					B_BITMAP_WILL_OVERLAY|B_BITMAP_RESERVE_OVERLAY_CHANNEL,
        					B_YCbCr422);
			memset(p_win->bitmap[0]->Bits(), 0, p_win->bitmap[0]->BitsLength());
			p_win->view->SetViewOverlay(p_win->bitmap[0], p_win->bitmap[0]->Bounds(), p_win->Bounds(), &key, B_FOLLOW_ALL,
					B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
			p_win->view->SetViewColor(key);
			p_win->Unlock();
		    vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
	   	                 (byte_t *)p_win->bitmap[0]->Bits());
	   	    delete p_win->bitmap[0];
	   	    }
	    }
return( 0 );
513
514
515
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
516
 * vout_Display: displays previously rendered output
517
 *****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
518
 * This function send the currently rendered image to BeOS image, waits until
519
520
 * it is displayed and switch the two rendering buffers, preparing next frame.
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
521
void vout_Display( vout_thread_t *p_vout )
522
523
{
    VideoWindow * p_win = p_vout->p_sys->p_window;
524
    
Sam Hocevar's avatar
   
Sam Hocevar committed
525
526
527
   	p_win->i_buffer_index = p_vout->i_buffer_index;
   	p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
    p_win->fDirty = true;
528
529
530
531
532
}

/* following functions are local */

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
533
 * BeosOpenDisplay: open and initialize BeOS device
Sam Hocevar's avatar
   
Sam Hocevar committed
534
535
536
537
538
 *****************************************************************************
 * XXX?? The framebuffer mode is only provided as a fast and efficient way to
 * display video, providing the card is configured and the mode ok. It is
 * not portable, and is not supposed to work with many cards. Use at your
 * own risk !
539
540
541
542
543
 *****************************************************************************/

static int BeosOpenDisplay( vout_thread_t *p_vout )
{ 
    p_vout->p_sys->p_window =
Richard Shepherd's avatar
Richard Shepherd committed
544
        new VideoWindow(  BRect( 80, 50, 80+p_vout->i_width-1, 50+p_vout->i_height-1 ), NULL, p_vout );
545
546
547
    if( p_vout->p_sys->p_window == 0 )
    {
        free( p_vout->p_sys );
Sam Hocevar's avatar
   
Sam Hocevar committed
548
        intf_ErrMsg( "error: cannot allocate memory for VideoWindow" );
549
550
        return( 1 );
    }   
Sam Hocevar's avatar
   
Sam Hocevar committed
551
    VideoWindow * p_win = p_vout->p_sys->p_window;
552
    
Sam Hocevar's avatar
   
Sam Hocevar committed
553
554
555
    p_vout->i_screen_depth =         p_win->i_screen_depth;
    p_vout->i_bytes_per_pixel =      p_win->i_bytes_per_pixel;
    p_vout->i_bytes_per_line =       p_vout->i_width*p_win->i_bytes_per_pixel;
556
557
558
559
    
    switch( p_vout->i_screen_depth )
    {
    case 8:
Sam Hocevar's avatar
   
Sam Hocevar committed
560
        intf_ErrMsg( "vout error: 8 bit mode not fully supported" );
Sam Hocevar's avatar
   
Sam Hocevar committed
561
        break;
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
    case 15:
        p_vout->i_red_mask =        0x7c00;
        p_vout->i_green_mask =      0x03e0;
        p_vout->i_blue_mask =       0x001f;
        break;
    case 16:
        p_vout->i_red_mask =        0xf800;
        p_vout->i_green_mask =      0x07e0;
        p_vout->i_blue_mask =       0x001f;
        break;
    case 24:
    case 32:
    default:
        p_vout->i_red_mask =        0xff0000;
        p_vout->i_green_mask =      0x00ff00;
        p_vout->i_blue_mask =       0x0000ff;
        break;
    }
    return( 0 );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
584
 * BeosDisplay: close and reset BeOS device
585
586
587
588
589
590
591
592
593
594
595
596
 *****************************************************************************
 * Returns all resources allocated by BeosOpenDisplay and restore the original
 * state of the device.
 *****************************************************************************/
static void BeosCloseDisplay( vout_thread_t *p_vout )
{    
    /* Destroy the video window */
    p_vout->p_sys->p_window->Lock();
    p_vout->p_sys->p_window->Quit();
}

} /* extern "C" */