vout_beos.cpp 19.8 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.48 2002/03/22 13:16:35 tcastley 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
27
28
29
30
31
32
33
 *
 * 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.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <errno.h>                                                 /* ENOMEM */
#include <stdlib.h>                                                /* free() */
#include <stdio.h>
#include <string.h>                                            /* strerror() */
34
35
#include <InterfaceKit.h>
#include <DirectWindow.h>
36
#include <Application.h>
37
#include <Bitmap.h>
38
39
40

extern "C"
{
Sam Hocevar's avatar
   
Sam Hocevar committed
41
#include <videolan/vlc.h>
42
43
44
45

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

Sam Hocevar's avatar
   
Sam Hocevar committed
46
#include "interface.h"
47
48
}

Sam Hocevar's avatar
   
Sam Hocevar committed
49
#include "VideoWindow.h"
50

Sam Hocevar's avatar
   
Sam Hocevar committed
51
52
#define BITS_PER_PLANE  16
#define BYTES_PER_PIXEL 2
53
54

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
55
 * vout_sys_t: BeOS video output method descriptor
56
57
 *****************************************************************************
 * This structure is part of the video output thread descriptor.
Sam Hocevar's avatar
   
Sam Hocevar committed
58
 * It describes the BeOS specific properties of an output thread.
59
60
61
 *****************************************************************************/
typedef struct vout_sys_s
{
Sam Hocevar's avatar
   
Sam Hocevar committed
62
    VideoWindow *  p_window;
Sam Hocevar's avatar
   
Sam Hocevar committed
63

Sam Hocevar's avatar
   
Sam Hocevar committed
64
65
    s32 i_width;
    s32 i_height;
Sam Hocevar's avatar
   
Sam Hocevar committed
66
67
68
69

    u8 *pp_buffer[2];
    int i_index;

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
} 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;
86
        if (window->LockWithTimeout(20000) == B_OK)
87
88
89
90
91
92
93
94
95
96
97
98
        {
            if (strcmp(window->Name(), name) == 0)
            {
                window->Unlock();
                break;
            }
            window->Unlock();
        }
    }
    return window; 
}

99
100
101
102
103
/**************************************************************************** 
 * DrawingThread : thread that really does the drawing 
 ****************************************************************************/ 
int32 Draw(void *data) 
{ 
104
105
    VideoWindow* p_win; 
    p_win = (VideoWindow *) data; 
106

107
    if ( p_win-> voutWindow-> LockLooper() ) 
108
    {
109
110
111
112
113
114
115
        if (p_win->vsync)
        {
            BScreen *screen;
            screen = new BScreen(p_win->voutWindow);
            screen-> WaitForRetrace(22000);
            delete screen; 
        }
116
117
        if (p_win->resized)
        {
118
119
120
121
            p_win->resized = false;
            p_win-> view-> FillRect(p_win-> voutWindow-> Bounds());
        }  
        p_win-> view-> DrawBitmap( p_win-> bitmap[p_win-> i_buffer],  
122
123
124
                                   BRect(p_win->out_left, p_win->out_top,
                                         p_win->out_left + p_win->out_width, 
                                         p_win->out_top + p_win->out_height) );  
125
        p_win-> voutWindow-> UnlockLooper(); 
126
127
    } 
    return B_OK; 
Sam Hocevar's avatar
   
Sam Hocevar committed
128
129
}

130
/*****************************************************************************
131
 * bitmapWindow : This is the bitmap window output
132
 *****************************************************************************/
133
134
bitmapWindow::bitmapWindow(BRect frame, VideoWindow *theOwner)
        : BWindow( frame, NULL, B_TITLED_WINDOW, 
135
                    B_NOT_CLOSABLE | B_NOT_MINIMIZABLE )
136
{
137
138
139
    owner = theOwner;
    SetTitle(VOUT_TITLE " (BBitmap output)");
}
140

141
142
143
bitmapWindow::~bitmapWindow()
{
}
Richard Shepherd's avatar
Richard Shepherd committed
144

145
146
147
148
149
void bitmapWindow::FrameMoved(BPoint origin) 
{
    owner->FrameMoved(origin);
}

150
151
void bitmapWindow::FrameResized( float width, float height )
{
152
    owner->FrameResized(width, height);
153
}
154

155
156
void bitmapWindow::Zoom(BPoint origin, float width, float height )
{
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    owner->Zoom( origin, width, height );
}

void bitmapWindow::ScreenChanged(BRect frame, color_space mode)
{
    owner->ScreenChanged(frame, mode);
}

void bitmapWindow::drawBuffer(int bufferIndex)
{
    status_t status;

    owner->i_buffer = bufferIndex; 
    owner->fDrawThreadID = spawn_thread(Draw, "drawing_thread",
                                        B_DISPLAY_PRIORITY, (void*) owner);
    wait_for_thread(owner->fDrawThreadID, &status);
    
174
175
}

176
177
178
179
180
/*****************************************************************************
 * directWindow : This is the bitmap window output
 *****************************************************************************/
directWindow::directWindow(BRect frame, VideoWindow *theOwner)
        : BDirectWindow( frame, NULL, B_TITLED_WINDOW, 
181
                    B_NOT_CLOSABLE | B_NOT_MINIMIZABLE )
182
{
183
184
185
    owner = theOwner;
    SetTitle(VOUT_TITLE " (DirectWindow output)");
}
Sam Hocevar's avatar
   
Sam Hocevar committed
186

187
188
189
directWindow::~directWindow()
{
}
Sam Hocevar's avatar
   
Sam Hocevar committed
190

191
192
193
void directWindow::DirectConnected(direct_buffer_info *info)
{
}
194

195
196
197
198
199
void directWindow::FrameMoved(BPoint origin) 
{
    owner->FrameMoved(origin);
}

200
void directWindow::FrameResized( float width, float height )
Sam Hocevar's avatar
   
Sam Hocevar committed
201
{
202
    owner->FrameResized(width, height);
Sam Hocevar's avatar
   
Sam Hocevar committed
203
204
}

205
void directWindow::Zoom(BPoint origin, float width, float height )
Sam Hocevar's avatar
   
Sam Hocevar committed
206
{
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    owner->Zoom( origin, width, height );
}

void directWindow::ScreenChanged(BRect frame, color_space mode)
{
    owner->ScreenChanged(frame, mode);
}

void directWindow::drawBuffer(int bufferIndex)
{
    status_t status;

    owner->i_buffer = bufferIndex; 
    owner->fDrawThreadID = spawn_thread(Draw, "drawing_thread",
                                        B_DISPLAY_PRIORITY, (void*) owner);
    wait_for_thread(owner->fDrawThreadID, &status);
Sam Hocevar's avatar
   
Sam Hocevar committed
223
224
}

225
/*****************************************************************************
226
 * VideoWindow constructor and destructor
227
 *****************************************************************************/
228
229
VideoWindow::VideoWindow( int v_width, int v_height, 
                          int w_width, int w_height )
230
{
231
    // need to centre the window on the screeen.
232
233
    if ( BDirectWindow::SupportsWindowMode() )
    { 
234
235
        voutWindow = new directWindow( BRect( 20, 50, 
                                              20 + w_width, 50 + w_height ), this );
236
        mode = DIRECT;
237
238
239
    }
    else
    {
240
241
        voutWindow = new bitmapWindow( BRect( 20, 50, 
                                              20 + w_width, 50 + w_height ), this );
242
        mode = BITMAP;
Sam Hocevar's avatar
   
Sam Hocevar committed
243
    }
244

Sam Hocevar's avatar
   
Sam Hocevar committed
245
    /* set the VideoWindow variables */
246
    teardownwindow = false;
247
248
    is_zoomed = false;
    resized = true;
249

250
251
252
253
254
    /* call ScreenChanged to set vsync correctly */
    BScreen *screen;
    screen = new BScreen(voutWindow);
    ScreenChanged(screen->Frame(), screen->ColorSpace());
    delete screen;
Sam Hocevar's avatar
   
Sam Hocevar committed
255
256
    
    /* create the view to do the display */
257
258
    view = new VLCView( voutWindow->Bounds() );
    voutWindow->AddChild(view);
259
    
Sam Hocevar's avatar
   
Sam Hocevar committed
260
261
    /* Bitmap mode overlay not available, set the system to 32bits
     * and let BeOS do all the work */
262
263
    bitmap[0] = new BBitmap( BRect( 0, 0, v_width, v_height ), B_RGB32);
    bitmap[1] = new BBitmap( BRect( 0, 0, v_width, v_height ), B_RGB32);
Sam Hocevar's avatar
   
Sam Hocevar committed
264
265
266
    memset(bitmap[0]->Bits(), 0, bitmap[0]->BitsLength());
    memset(bitmap[1]->Bits(), 0, bitmap[1]->BitsLength());

267
268
269
270
    // remember current settings
    i_width = w_width;
    i_height = w_height;
    FrameResized(w_width, w_height);
271
272
273
274
275
276
277
    voutWindow->Show();
}

VideoWindow::~VideoWindow()
{
    int32 result;

278
279
    teardownwindow = true;
    wait_for_thread(fDrawThreadID, &result);
280
281
282
283
    voutWindow->Hide();
    voutWindow->Sync();
    voutWindow->Lock();
    voutWindow->Quit();
Sam Hocevar's avatar
   
Sam Hocevar committed
284
285
    delete bitmap[0];
    delete bitmap[1];
286
287
288
}

void VideoWindow::drawBuffer(int bufferIndex)
289
{
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
    switch( mode )
    {
        case DIRECT:
        {
            directWindow *dW = (directWindow*)voutWindow;
            dW->drawBuffer(bufferIndex);
            break;
        }
        case BITMAP:
        default:
        {
            bitmapWindow *bW = (bitmapWindow*)voutWindow;
            bW->drawBuffer(bufferIndex);
            break;
        }
    }
}

void VideoWindow::Zoom(BPoint origin, float width, float height )
{
    if(is_zoomed)
    {
        is_zoomed = !is_zoomed;
        voutWindow->MoveTo(winSize.left, winSize.top);
        voutWindow->ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
        width_scale = winSize.IntegerWidth() / i_width;
        height_scale = winSize.IntegerHeight() / i_height;
        be_app->ShowCursor();
    }
    else
    {
        is_zoomed = !is_zoomed;
        BScreen *screen;
        screen = new BScreen(voutWindow);
        BRect rect = screen->Frame();
        delete screen;
        voutWindow->MoveTo(0,0);
        voutWindow->ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
        width_scale = rect.IntegerWidth() / i_width;
        height_scale = rect.IntegerHeight() / i_height;
330
        be_app->ObscureCursor();
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    }
    resized = true;
}

void VideoWindow::FrameMoved(BPoint origin) 
{
	if (is_zoomed) return ;
    winSize = voutWindow->Frame();
    resized = true;
}

void VideoWindow::FrameResized( float width, float height )
{
    width_scale = width / i_width;
    height_scale = height / i_height;
    if (width_scale <= height_scale)
    {
        out_width = i_width * width_scale;
        out_height = i_height * width_scale;
        out_left = 0; 
        out_top = (voutWindow->Frame().Height() - out_height) / 2;
    }
    else   /* if the height is proportionally smaller */
    {
        out_width = i_width * height_scale;
        out_height = i_height * height_scale;
        out_top = 0;
        out_left = (voutWindow->Frame().Width() - out_width) /2;
    }

	if (is_zoomed) return ;
    winSize = voutWindow->Frame();
    width_scale = width / i_width;
    height_scale = height / i_height;
    resized = true;
}

void VideoWindow::ScreenChanged(BRect frame, color_space mode)
{
    BScreen *screen;
    float refresh;
Sam Hocevar's avatar
   
Sam Hocevar committed
372
    
373
374
    screen = new BScreen(voutWindow);
    display_mode disp_mode; 
Sam Hocevar's avatar
   
Sam Hocevar committed
375
    
376
377
378
379
380
381
382
383
    screen-> GetMode(&disp_mode); 
    refresh = 
         (disp_mode.timing.pixel_clock * 1000)/((disp_mode.timing.h_total)* 
         (disp_mode.timing.v_total)); 
    if (refresh  < 61) 
    { 
        vsync = true; 
    } 
384
385
}

Sam Hocevar's avatar
   
Sam Hocevar committed
386
387
388
389
390
/*****************************************************************************
 * VLCView::VLCView
 *****************************************************************************/
VLCView::VLCView(BRect bounds) : BView(bounds, "", B_FOLLOW_ALL, B_WILL_DRAW)
{
Sam Hocevar's avatar
   
Sam Hocevar committed
391
    SetViewColor(B_TRANSPARENT_32_BIT);
Sam Hocevar's avatar
   
Sam Hocevar committed
392
393
394
395
396
397
398
399
400
401
}

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

/*****************************************************************************
402
 * VLCVIew::MouseDown
Sam Hocevar's avatar
   
Sam Hocevar committed
403
404
405
 *****************************************************************************/
void VLCView::MouseDown(BPoint point)
{
Sam Hocevar's avatar
   
Sam Hocevar committed
406
407
    BWindow *win = Window();
    win->Zoom();
Sam Hocevar's avatar
   
Sam Hocevar committed
408
409
}

410
411
412
413
414
415
416
417
418
/*****************************************************************************
 * VLCVIew::Draw
 *****************************************************************************/
void VLCView::Draw(BRect updateRect) 
{
    FillRect(updateRect);
}


419
420
421
422
423
424
extern "C"
{

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
425
426
427
428
429
430
431
static int  vout_Create     ( vout_thread_t * );
static int  vout_Init       ( vout_thread_t * );
static void vout_End        ( vout_thread_t * );
static void vout_Destroy    ( vout_thread_t * );
static int  vout_Manage     ( vout_thread_t * );
static void vout_Display    ( vout_thread_t *, picture_t * );
static void vout_Render     ( vout_thread_t *, picture_t * );
Sam Hocevar's avatar
   
Sam Hocevar committed
432
433
434
435
436
437
438
439

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
440
void _M( vout_getfunctions )( function_list_t * p_function_list )
Sam Hocevar's avatar
   
Sam Hocevar committed
441
442
443
444
445
446
447
{
    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;
Sam Hocevar's avatar
   
Sam Hocevar committed
448
    p_function_list->functions.vout.pf_render     = vout_Render;
Sam Hocevar's avatar
   
Sam Hocevar committed
449
450
}

451
/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
452
 * vout_Create: allocates BeOS video thread output method
453
 *****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
454
 * This function allocates and initializes a BeOS vout method.
455
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
456
int vout_Create( vout_thread_t *p_vout )
457
458
459
460
461
{
    /* 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
462
        intf_ErrMsg( "error: %s", strerror(ENOMEM) );
463
464
        return( 1 );
    }
Sam Hocevar's avatar
   
Sam Hocevar committed
465

466
467
468
    p_vout->p_sys->i_width = p_vout->render.i_width;
    p_vout->p_sys->i_height = p_vout->render.i_height;
      
469
470
471
472
    return( 0 );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
473
 * vout_Init: initialize BeOS video thread output method
474
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
475
int vout_Init( vout_thread_t *p_vout )
476
{
Sam Hocevar's avatar
   
Sam Hocevar committed
477
478
479
480
481
    int i_index;
    picture_t *p_pic;

    I_OUTPUTPICTURES = 0;

Sam Hocevar's avatar
   
Sam Hocevar committed
482
483
484
485
486
487
    /* Open and initialize device */
    if( BeosOpenDisplay( p_vout ) )
    {
        intf_ErrMsg("vout error: can't open display");
        return 0;
    }
488
    /* Set the buffers */
489
490
491
    p_vout->p_sys->pp_buffer[0] = (u8*)p_vout->p_sys->p_window->bitmap[0]->Bits();
    p_vout->p_sys->pp_buffer[1] = (u8*)p_vout->p_sys->p_window->bitmap[1]->Bits();

492
493
494
495
    p_vout->output.i_width  = p_vout->render.i_width;
    p_vout->output.i_height = p_vout->render.i_height;

    /* Assume we have square pixels */
Sam Hocevar's avatar
   
Sam Hocevar committed
496
    p_vout->output.i_aspect = p_vout->p_sys->i_width
Sam Hocevar's avatar
   
Sam Hocevar committed
497
                               * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
498

Sam Hocevar's avatar
   
Sam Hocevar committed
499
500
    p_vout->output.i_chroma = FOURCC_RV32;

Sam Hocevar's avatar
   
Sam Hocevar committed
501
502
503
504
    p_vout->output.i_rmask  = 0x00ff0000;
    p_vout->output.i_gmask  = 0x0000ff00;
    p_vout->output.i_bmask  = 0x000000ff;

Sam Hocevar's avatar
   
Sam Hocevar committed
505
506
507
508
509
510
511
512
513
514
515
    p_pic = NULL;

    /* Find an empty picture slot */
    for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
    {
        if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
        {
            p_pic = p_vout->p_picture + i_index;
            break;
        }
    }
516

Sam Hocevar's avatar
   
Sam Hocevar committed
517
    if( p_pic == NULL )
Sam Hocevar's avatar
   
Sam Hocevar committed
518
    {
Sam Hocevar's avatar
   
Sam Hocevar committed
519
        return 0;
520
    }
Sam Hocevar's avatar
   
Sam Hocevar committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537

    p_vout->p_sys->i_index = 0;
    p_pic->p->p_pixels = p_vout->p_sys->pp_buffer[0];
    p_pic->p->i_pixel_bytes = 4;
    p_pic->p->i_lines = p_vout->p_sys->i_height;
    p_pic->p->b_margin = 0;
    p_pic->p->i_pitch = 4 * p_vout->p_sys->i_width;

    p_pic->i_planes = 1;

    p_pic->i_status = DESTROYED_PICTURE;
    p_pic->i_type   = DIRECT_PICTURE;

    PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;

    I_OUTPUTPICTURES++;

538
539
540
541
    return( 0 );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
542
 * vout_End: terminate BeOS video thread output method
543
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
544
void vout_End( vout_thread_t *p_vout )
545
{
Sam Hocevar's avatar
   
Sam Hocevar committed
546
    BeosCloseDisplay( p_vout );
547
548
549
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
550
 * vout_Destroy: destroy BeOS video thread output method
551
552
553
 *****************************************************************************
 * Terminate an output method created by DummyCreateOutputMethod
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
554
void vout_Destroy( vout_thread_t *p_vout )
555
556
557
558
559
{
    free( p_vout->p_sys );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
560
 * vout_Manage: handle BeOS events
561
562
563
564
 *****************************************************************************
 * 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
565
int vout_Manage( vout_thread_t *p_vout )
566
{
567
                          
Sam Hocevar's avatar
   
Sam Hocevar committed
568
569
570
571
572
573
574
575
576
    return( 0 );
}

/*****************************************************************************
 * vout_Render: render previously calculated output
 *****************************************************************************/
void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
{
    ;
577
578
579
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
580
 * vout_Display: displays previously rendered output
581
 *****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
582
 * This function send the currently rendered image to BeOS image, waits until
583
584
 * it is displayed and switch the two rendering buffers, preparing next frame.
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
585
void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
586
587
{
    VideoWindow * p_win = p_vout->p_sys->p_window;
Sam Hocevar's avatar
   
Sam Hocevar committed
588

589
    /* draw buffer if required */    
Sam Hocevar's avatar
   
Sam Hocevar committed
590
591
    if (!p_win->teardownwindow)
    {
Sam Hocevar's avatar
   
Sam Hocevar committed
592
       p_win->drawBuffer(p_vout->p_sys->i_index);
593
    }
594
    /* change buffer */
Sam Hocevar's avatar
   
Sam Hocevar committed
595
596
    p_vout->p_sys->i_index = ++p_vout->p_sys->i_index & 1;
    p_pic->p->p_pixels = p_vout->p_sys->pp_buffer[p_vout->p_sys->i_index];
597
598
599
600
601
}

/* following functions are local */

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
602
 * BeosOpenDisplay: open and initialize BeOS device
603
604
605
 *****************************************************************************/
static int BeosOpenDisplay( vout_thread_t *p_vout )
{ 
606

Sam Hocevar's avatar
   
Sam Hocevar committed
607
608
    p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
                                               p_vout->p_sys->i_height - 1,
609
610
                                               p_vout->i_window_width,
                                               p_vout->i_window_height);
611

Sam Hocevar's avatar
   
Sam Hocevar committed
612
    if( p_vout->p_sys->p_window == NULL )
613
    {
Sam Hocevar's avatar
   
Sam Hocevar committed
614
        intf_ErrMsg( "error: cannot allocate memory for VideoWindow" );
615
616
617
618
619
620
621
        return( 1 );
    }   
    
    return( 0 );
}

/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
622
 * BeosDisplay: close and reset BeOS device
623
624
625
626
627
628
629
 *****************************************************************************
 * 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 */
630
    delete p_vout->p_sys->p_window;
631
632
633
}

} /* extern "C" */