]> git.sesse.net Git - vlc/blobdiff - plugins/beos/vout_beos.cpp
* ALL: changed "struct foo_s" into "struct foo_t" to make greppers happy.
[vlc] / plugins / beos / vout_beos.cpp
index 468fc73f041f31dba319a85f0885ec4f36d43edf..5370320c0044fdc072e28fb7b67e3c6a992f4a30 100644 (file)
@@ -2,7 +2,7 @@
  * vout_beos.cpp: beos video output display method
  *****************************************************************************
  * Copyright (C) 2000, 2001 VideoLAN
- * $Id: vout_beos.cpp,v 1.25 2001/04/29 17:03:20 sam Exp $
+ * $Id: vout_beos.cpp,v 1.61 2002/07/20 18:01:42 sam Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#define MODULE_NAME beos
-#include "modules_inner.h"
-
 /*****************************************************************************
  * 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 <InterfaceKit.h>
+#include <DirectWindow.h>
 #include <Application.h>
-#include <Window.h>
-#include <Locker.h>
-#include <Screen.h>
-#include <malloc.h>
-#include <string.h>
-
-extern "C"
-{
-#include "config.h"
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
-#include "tests.h"
-#include "modules.h"
-
-#include "video.h"
-#include "video_output.h"
+#include <Bitmap.h>
 
-#include "interface.h"
-#include "intf_msg.h"
-
-#include "main.h"
-}
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
+#include <vlc/vout.h>
 
 #include "VideoWindow.h"
-#include <Screen.h>
-
-#define WIDTH 128
-#define HEIGHT 64
-#define BITS_PER_PLANE 16
-#define BYTES_PER_PIXEL 2
+#include "DrawingTidbits.h"
 
 /*****************************************************************************
  * vout_sys_t: BeOS video output method descriptor
@@ -77,21 +49,20 @@ extern "C"
  * This structure is part of the video output thread descriptor.
  * It describes the BeOS specific properties of an output thread.
  *****************************************************************************/
-typedef struct vout_sys_s
+struct vout_sys_t
 {
-    VideoWindow *         p_window;
+    VideoWindow *  p_window;
 
-    byte_t *              pp_buffer[2];
-    s32                   i_width;
-    s32                   i_height;
-} vout_sys_t;
+    s32 i_width;
+    s32 i_height;
 
+    u8 *pp_buffer[3];
+    int i_index;
+};
 
 /*****************************************************************************
  * beos_GetAppWindow : retrieve a BWindow pointer from the window name
  *****************************************************************************/
-
 BWindow *beos_GetAppWindow(char *name)
 {
     int32       index;
@@ -102,7 +73,7 @@ BWindow *beos_GetAppWindow(char *name)
         window = be_app->WindowAt(index);
         if (window == NULL)
             break;
-        if (window->LockWithTimeout(200000) == B_OK)
+        if (window->LockWithTimeout(20000) == B_OK)
         {
             if (strcmp(window->Name(), name) == 0)
             {
@@ -115,132 +86,89 @@ BWindow *beos_GetAppWindow(char *name)
     return window; 
 }
 
-/*****************************************************************************
+/****************************************************************************
  * DrawingThread : thread that really does the drawing
- *****************************************************************************/
-
-int32 DrawingThread(void *data)
+ ****************************************************************************/
+int32 Draw(void *data)
 {
-  VideoWindow *w;
-  w = (VideoWindow*) data;
-    
-  while(!w->teardownwindow)
-  {
-    if (w->Lock())
+    VideoWindow* p_win;
+    p_win = (VideoWindow *) data;
+
+    if ( p_win->LockWithTimeout(50000) == B_OK )
     {
-      if( w->fDirty )
-      {
-        if(w->fUsingOverlay)
+        if (p_win->vsync)
         {
-          rgb_color key;
-           w->view->SetViewOverlay( w->bitmap[w->i_buffer_index],
-                                    w->bitmap[w->i_buffer_index]->Bounds(),
-                                    w->Bounds(),
-                                    &key,
-                                    B_FOLLOW_ALL,
-                                                   B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL
-                                                   | B_OVERLAY_TRANSFER_CHANNEL );
-           w->view->SetViewColor(key);
-         }
-         else
-         {
-           w->view->DrawBitmap( w->bitmap[w->i_buffer_index],
-                                w->bitmap[w->i_buffer_index]->Bounds(),
-                                w->Bounds());
-         }
-         
-         w->fDirty = false;
-       }
-     w->Unlock();
-   }
-   else  // we couldn't lock the window, it probably closed.
-     return B_ERROR;
-     
-   snooze (20000);
- } // while
-
-  return B_OK;
+            BScreen *screen;
+            screen = new BScreen(p_win);
+            screen-> WaitForRetrace(22000);
+            delete screen;
+        }
+        if (p_win-> mode == OVERLAY)
+        {
+            rgb_color key;
+            p_win-> view->SetViewOverlay(p_win-> bitmap[p_win-> i_buffer], 
+                                         p_win-> bitmap[p_win-> i_buffer]->Bounds() ,
+                                         p_win-> view->Bounds(),
+                                         &key, B_FOLLOW_ALL,
+                                                B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
+                                                B_OVERLAY_TRANSFER_CHANNEL);
+                   p_win-> view->SetViewColor(key);
+        }
+        else
+        {
+            p_win-> view-> DrawBitmap( p_win-> bitmap[p_win-> i_buffer], 
+                                       p_win-> view->Bounds() );
+        }                                
+        p_win-> Unlock();
+    }
+    return B_OK;
 }
 
 /*****************************************************************************
  * VideoWindow constructor and destructor
  *****************************************************************************/
-
-VideoWindow::VideoWindow(BRect frame, const char *name, vout_thread_t *p_video_output )
-        : BWindow(frame, name, B_TITLED_WINDOW, NULL)
+VideoWindow::VideoWindow( int v_width, int v_height, 
+                          BRect frame )
+            : BWindow( frame, NULL, B_TITLED_WINDOW, 
+                    B_NOT_CLOSABLE | B_NOT_MINIMIZABLE )
 {
-       float minWidth, minHeight, maxWidth, maxHeight; 
-
+    BView *mainView =  new BView( Bounds(), "mainView", 
+                                  B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE);
+    AddChild(mainView);
+    mainView->SetViewColor(kBlack);
+                                  
+    /* create the view to do the display */
+    view = new VLCView( Bounds() );
+    mainView->AddChild(view);
+
+    /* set the VideoWindow variables */
     teardownwindow = false;
     is_zoomed = false;
-    p_vout = p_video_output;
-       fDrawThreadID = NULL;
-       bitmap[0] = NULL;
-       bitmap[1] = NULL;
-       
-    rect = Frame();
-    view = new VLCView(Bounds());
-    AddChild(view);
-       bitmap[0] = new BBitmap(Bounds(), B_BITMAP_WILL_OVERLAY|B_BITMAP_RESERVE_OVERLAY_CHANNEL, B_YCbCr422);
-       bitmap[1] = new BBitmap(Bounds(), B_BITMAP_WILL_OVERLAY, B_YCbCr422);
-       fUsingOverlay = true;
-       i_screen_depth = 16;
-       p_vout->b_YCbr = true;
-       
-       if ((bitmap[0]->InitCheck() != B_OK) || (bitmap[1]->InitCheck() != B_OK))
-       {
-               delete bitmap[0];
-               delete bitmap[1];
-               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;
-                       }
-               SetTitle(VOUT_TITLE " (BBitmap output)");
-        }
-
-       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);
-               SetTitle(VOUT_TITLE " (Overlay output)");
-               GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); 
-               SetSizeLimits((float) Bounds().IntegerWidth(), maxWidth, (float) Bounds().IntegerHeight(), maxHeight);
-               }
-//     else
-               {
-       fDrawThreadID = spawn_thread(DrawingThread, "drawing_thread",
-                    B_DISPLAY_PRIORITY, (void*) this);
-       resume_thread(fDrawThreadID);
-       }
-
-       memset(bitmap[0]->Bits(), 0, bitmap[0]->BitsLength());
-       memset(bitmap[1]->Bits(), 0, bitmap[1]->BitsLength());
-       i_bytes_per_pixel = bitmap[0]->BytesPerRow()/bitmap[0]->Bounds().IntegerWidth();
-    fRowBytes = bitmap[0]->BytesPerRow();
-    fDirty = false;
+    i_buffer = 0;
+
+    /* call ScreenChanged to set vsync correctly */
+    BScreen *screen;
+    display_mode disp_mode; 
+    float refresh;
+
+    screen = new BScreen(this);
+    
+    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; 
+    } 
+    delete screen;
+    
+    // remember current settings
+    i_width = frame.IntegerWidth();
+    i_height = frame.IntegerHeight();
+    FrameResized(frame.IntegerWidth(), frame.IntegerHeight());
+
+    mode = SelectDrawingMode(v_width, v_height);
     Show();
 }
 
@@ -248,131 +176,248 @@ VideoWindow::~VideoWindow()
 {
     int32 result;
 
-    Hide();
-    Sync();
-//    if(!fUsingOverlay)
-//     {
-           teardownwindow = true;
-           wait_for_thread(fDrawThreadID, &result);
-       delete bitmap[0];
-       delete bitmap[1];
-//     }
- }
-
+    teardownwindow = true;
+    wait_for_thread(fDrawThreadID, &result);
+    delete bitmap[0];
+    delete bitmap[1];
+    delete bitmap[2];
+}
 
-/*****************************************************************************
- * VideoWindow::FrameResized
- *****************************************************************************/
-void VideoWindow::FrameResized( float width, float height )
+bool VideoWindow::QuitRequested()
 {
+    return true;
 }
 
-/*****************************************************************************
- * VideoWindow::Zoom
- *****************************************************************************/
+void VideoWindow::drawBuffer(int bufferIndex)
+{
+    status_t status;
+
+    i_buffer = bufferIndex;
+    // sync to the screen if required
+    if (vsync)
+    {
+        BScreen *screen;
+        screen = new BScreen(this);
+        screen-> WaitForRetrace(22000);
+        delete screen;
+    }
+    if (LockLooper())
+    {
+       // switch the overlay bitmap
+       if (mode == OVERLAY)
+       {
+          rgb_color key;
+          view->SetViewOverlay(bitmap[i_buffer], 
+                            bitmap[i_buffer]->Bounds() ,
+                            view->Bounds(),
+                            &key, B_FOLLOW_ALL,
+                                   B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
+                                   B_OVERLAY_TRANSFER_CHANNEL);
+                  //view->SetViewColor(key);
+          }
+       else
+       {
+         // switch the bitmap
+         view-> DrawBitmap(bitmap[i_buffer], view->Bounds() );
+       }
+       UnlockLooper();
+    }
+}
 
 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;
+    if(is_zoomed)
+    {
+        is_zoomed = !is_zoomed;
+        MoveTo(winSize.left, winSize.top);
+        ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
+        be_app->ShowCursor();
+    }
+    else
+    {
+        is_zoomed = !is_zoomed;
+        BScreen *screen;
+        screen = new BScreen(this);
+        BRect rect = screen->Frame();
+        delete screen;
+        MoveTo(0,0);
+        ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
+        be_app->ObscureCursor();
+    }
 }
 
-/*****************************************************************************
- * VideoWindow::MessageReceived
- *****************************************************************************/
+void VideoWindow::FrameMoved(BPoint origin) 
+{
+       if (is_zoomed) return ;
+    winSize = Frame();
+}
 
-void VideoWindow::MessageReceived( BMessage * p_message )
+void VideoWindow::FrameResized( float width, float height )
 {
-    BWindow * p_win;
+    float out_width, out_height;
+    float out_left, out_top;
+    float width_scale = width / i_width;
+    float 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 = (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 = (width - out_width) /2;
+    }
+    view->MoveTo(out_left,out_top);
+    view->ResizeTo(out_width, out_height);
+       if (!is_zoomed)
+       {
+        winSize = Frame();
+    }
+}
+
+void VideoWindow::ScreenChanged(BRect frame, color_space mode)
+{
+    BScreen *screen;
+    float refresh;
     
-    switch( p_message->what )
+    screen = new BScreen(this);
+    display_mode disp_mode; 
+    
+    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; 
+    } 
+    rgb_color key;
+    view->SetViewOverlay(bitmap[i_buffer], 
+                         bitmap[i_buffer]->Bounds() ,
+                         view->Bounds(),
+                         &key, B_FOLLOW_ALL,
+                         B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
+    view->SetViewColor(key);
+}
+
+void VideoWindow::WindowActivated(bool active)
+{
+}
+
+int VideoWindow::SelectDrawingMode(int width, int height)
+{
+    int drawingMode = BITMAP;
+
+    int noOverlay = !config_GetInt( p_vout, "overlay" );
+    for (int i = 0; i < COLOR_COUNT; i++)
     {
-    case B_KEY_DOWN:
-    case B_SIMPLE_DATA:
-        // post the message to the interface window which will handle it
-        p_win = beos_GetAppWindow( "interface" );
-        if( p_win != NULL )
+        if (noOverlay) break;
+        bitmap[0] = new BBitmap ( BRect( 0, 0, width, height ), 
+                                  B_BITMAP_WILL_OVERLAY,
+                                  colspace[i].colspace);
+
+        if(bitmap[0] && bitmap[0]->InitCheck() == B_OK) 
         {
-            p_win->PostMessage( p_message );
+            colspace_index = i;
+
+            bitmap[1] = new BBitmap( BRect( 0, 0, width, height ), B_BITMAP_WILL_OVERLAY,
+                                     colspace[colspace_index].colspace);
+            bitmap[2] = new BBitmap( BRect( 0, 0, width, height ), B_BITMAP_WILL_OVERLAY,
+                                     colspace[colspace_index].colspace);
+            if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
+            {
+               drawingMode = OVERLAY;
+               rgb_color key;
+               view->SetViewOverlay(bitmap[0], 
+                                    bitmap[0]->Bounds() ,
+                                    view->Bounds(),
+                                    &key, B_FOLLOW_ALL,
+                                           B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
+                      view->SetViewColor(key);
+               SetTitle(VOUT_TITLE " (Overlay)");
+               break;
+            }
+            else
+            {
+               delete bitmap[0];
+               delete bitmap[1];
+               delete bitmap[2];
+            }
         }
-        break;
-    
-    default:
-        BWindow::MessageReceived( p_message );
-        break;
+        else
+        {
+            delete bitmap[0];
+        }        
+       }
+
+    if (drawingMode == BITMAP)
+       {
+        // fallback to RGB32
+        colspace_index = DEFAULT_COL;
+        SetTitle(VOUT_TITLE " (Bitmap)");
+        bitmap[0] = new BBitmap( BRect( 0, 0, width, height ), colspace[colspace_index].colspace);
+        bitmap[1] = new BBitmap( BRect( 0, 0, width, height ), colspace[colspace_index].colspace);
+        bitmap[2] = new BBitmap( BRect( 0, 0, width, height ), colspace[colspace_index].colspace);
     }
+    return drawingMode;
 }
 
 /*****************************************************************************
- * VideoWindow::QuitRequested
+ * VLCView::VLCView
  *****************************************************************************/
+VLCView::VLCView(BRect bounds) : BView(bounds, "", B_FOLLOW_NONE,
+                                       B_WILL_DRAW)
 
-bool VideoWindow::QuitRequested()
 {
-    /* FIXME: send a message ! */
-    p_main->p_intf->b_die = 1;
-    teardownwindow = true;
-    return( false );
+    SetViewColor(B_TRANSPARENT_32_BIT);
 }
 
 /*****************************************************************************
- * VLCView::VLCView
+ * VLCView::~VLCView
  *****************************************************************************/
-VLCView::VLCView(BRect bounds) : BView(bounds, "", B_FOLLOW_ALL, B_WILL_DRAW)
+VLCView::~VLCView()
 {
-SetViewColor(B_TRANSPARENT_32_BIT);
 }
 
 /*****************************************************************************
- * VLCView::~VLCView
+ * VLCVIew::MouseDown
  *****************************************************************************/
-VLCView::~VLCView()
+void VLCView::MouseDown(BPoint point)
 {
-
+    BWindow *win = Window();
+    win->Zoom();
 }
 
 /*****************************************************************************
- * VLCVIew::~VLCView
+ * VLCVIew::Draw
  *****************************************************************************/
-void VLCView::MouseDown(BPoint point)
+void VLCView::Draw(BRect updateRect) 
 {
-VideoWindow *w = (VideoWindow *) Window();
-if(w->is_zoomed)
-       {
-       BWindow *win = Window();
-       win->Zoom();
-       }
+    VideoWindow *win = (VideoWindow *) Window();
+    if (win->mode == BITMAP)
+      FillRect(updateRect);
 }
 
+
 extern "C"
 {
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-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  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 * );
 
 static int  BeosOpenDisplay ( vout_thread_t *p_vout );
 static void BeosCloseDisplay( vout_thread_t *p_vout );
@@ -383,30 +428,13 @@ static void BeosCloseDisplay( vout_thread_t *p_vout );
  *****************************************************************************/
 void _M( vout_getfunctions )( function_list_t * p_function_list )
 {
-    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 );
+    p_function_list->functions.vout.pf_render     = vout_Render;
 }
 
 /*****************************************************************************
@@ -420,23 +448,11 @@ int vout_Create( vout_thread_t *p_vout )
     p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
     {
-        intf_ErrMsg( "error: %s", strerror(ENOMEM) );
-        return( 1 );
-    }
-    
-    /* Set video window's size */
-    p_vout->i_width =  main_GetIntVariable( VOUT_WIDTH_VAR,
-                                            VOUT_WIDTH_DEFAULT );
-    p_vout->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
-                                            VOUT_HEIGHT_DEFAULT );
-
-    /* Open and initialize device */
-    if( BeosOpenDisplay( p_vout ) )
-    {
-        intf_ErrMsg("vout error: can't open display");
-        free( p_vout->p_sys );
+        msg_Err( p_vout, "out of memory" );
         return( 1 );
     }
+    p_vout->p_sys->i_width = p_vout->render.i_width;
+    p_vout->p_sys->i_height = p_vout->render.i_height;
 
     return( 0 );
 }
@@ -446,39 +462,80 @@ int vout_Create( vout_thread_t *p_vout )
  *****************************************************************************/
 int vout_Init( vout_thread_t *p_vout )
 {
-    VideoWindow * p_win = p_vout->p_sys->p_window;
-    u32 i_page_size;
+    int i_index;
+    picture_t *p_pic;
 
+    I_OUTPUTPICTURES = 0;
+
+    /* Open and initialize device */
+    if( BeosOpenDisplay( p_vout ) )
+    {
+        msg_Err( p_vout, "cannot open display" );
+        return 0;
+    }
+    /* Set the buffers */
+    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();
+    p_vout->p_sys->pp_buffer[2] = (u8*)p_vout->p_sys->p_window->bitmap[2]->Bits();
+    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 */
+    p_vout->output.i_aspect = p_vout->p_sys->i_width
+                               * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
+    p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
+    p_vout->p_sys->i_index = 0;
+
+    p_vout->output.i_rmask  = 0x00ff0000;
+    p_vout->output.i_gmask  = 0x0000ff00;
+    p_vout->output.i_bmask  = 0x000000ff;
+
+    for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
+    {
+       p_pic = NULL;
+       /* Find an empty picture slot */
+       for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
+       {
+           p_pic = NULL;
+           if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
+           {
+               p_pic = p_vout->p_picture + i_index;
+               break;
+           }
+       }
+
+       if( p_pic == NULL )
+       {
+           return 0;
+       }
+       p_pic->p->p_pixels = p_vout->p_sys->pp_buffer[0];
+       p_pic->p->i_lines = p_vout->p_sys->i_height;
+
+       p_pic->p->i_pixel_bytes = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
+       p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
+       p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[0]->BytesPerRow(); 
+
+       if (p_vout->p_sys->p_window->mode == OVERLAY)
+       {
+          p_pic->p->i_visible_bytes = (p_vout->p_sys->p_window->bitmap[0]->Bounds().IntegerWidth()+1) 
+                                     * p_pic->p->i_pixel_bytes; 
+          p_pic->p->b_margin = 1;
+          p_pic->p->b_hidden = 0;
+       }
+       else
+       {
+          p_pic->p->b_margin = 0;
+          p_pic->p->i_visible_bytes = p_pic->p->i_pitch;
+       }
+
+       p_pic->i_status = DESTROYED_PICTURE;
+       p_pic->i_type   = DIRECT_PICTURE;
+       PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
+
+       I_OUTPUTPICTURES++;
+    }
 
-    i_page_size =   p_vout->i_width * p_vout->i_height * p_vout->i_bytes_per_pixel;
-    
-    p_vout->p_sys->i_width =         p_vout->i_width;
-    p_vout->p_sys->i_height =        p_vout->i_height;    
-
-/*    if(p_win->fUsingOverlay)
-       {
-           if(p_win->bitmap[0] != NULL)
-               {
-                   vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
-                        (byte_t *)p_win->bitmap[0]->Bits());
-               delete p_win->bitmap[0];
-               p_win->bitmap[0] = NULL;
-               }
-       }
-    else
-               {
-           if((p_win->bitmap[0] != NULL) && (p_win->bitmap[1] != NULL))
-               {
-               vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
-                        (byte_t *)p_win->bitmap[1]->Bits());
-               }
-       }*/
-           if((p_win->bitmap[0] != NULL) && (p_win->bitmap[1] != NULL))
-               {
-               vout_SetBuffers( p_vout, (byte_t *)p_win->bitmap[0]->Bits(),
-                        (byte_t *)p_win->bitmap[1]->Bits());
-               }
-    
     return( 0 );
 }
 
@@ -487,6 +544,7 @@ int vout_Init( vout_thread_t *p_vout )
  *****************************************************************************/
 void vout_End( vout_thread_t *p_vout )
 {
+    BeosCloseDisplay( p_vout );
 }
 
 /*****************************************************************************
@@ -496,8 +554,6 @@ void vout_End( vout_thread_t *p_vout )
  *****************************************************************************/
 void vout_Destroy( vout_thread_t *p_vout )
 {
-    BeosCloseDisplay( p_vout );
-    
     free( p_vout->p_sys );
 }
 
@@ -509,43 +565,16 @@ void vout_Destroy( vout_thread_t *p_vout )
  *****************************************************************************/
 int vout_Manage( vout_thread_t *p_vout )
 {
-VideoWindow * p_win = p_vout->p_sys->p_window;
-rgb_color key;
-float minWidth, minHeight, maxWidth, maxHeight; 
+                          
+    return( 0 );
+}
 
-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();
-               delete p_win->bitmap[0];
-               delete p_win->bitmap[1];
-               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);
-               p_win->bitmap[0] = new BBitmap(p_win->Bounds(),
-                                               B_BITMAP_WILL_OVERLAY, B_YCbCr422);
-                       memset(p_win->bitmap[0]->Bits(), 0, p_win->bitmap[0]->BitsLength());
-                       memset(p_win->bitmap[1]->Bits(), 0, p_win->bitmap[1]->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|B_OVERLAY_TRANSFER_CHANNEL);
-                       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 );
+/*****************************************************************************
+ * vout_Render: render previously calculated output
+ *****************************************************************************/
+void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
+{
+    ;
 }
 
 /*****************************************************************************
@@ -554,68 +583,40 @@ return( 0 );
  * This function send the currently rendered image to BeOS image, waits until
  * it is displayed and switch the two rendering buffers, preparing next frame.
  *****************************************************************************/
-void vout_Display( vout_thread_t *p_vout )
+void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
 {
     VideoWindow * p_win = p_vout->p_sys->p_window;
-    
-       p_win->i_buffer_index = p_vout->i_buffer_index;
-       if(p_win->fUsingOverlay)
-               p_vout->i_buffer_index = p_vout->i_buffer_index & 1;
-       else
-               p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
-    p_win->fDirty = true;
+
+    /* draw buffer if required */    
+    if (!p_win->teardownwindow)
+    { 
+       p_win->drawBuffer(p_vout->p_sys->i_index);
+    }
+    /* change buffer */
+    p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
+    p_pic->p->p_pixels = p_vout->p_sys->pp_buffer[p_vout->p_sys->i_index];
 }
 
 /* following functions are local */
 
 /*****************************************************************************
  * BeosOpenDisplay: open and initialize BeOS device
- *****************************************************************************
- * 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 !
  *****************************************************************************/
-
 static int BeosOpenDisplay( vout_thread_t *p_vout )
 { 
-    p_vout->p_sys->p_window =
-        new VideoWindow(  BRect( 80, 50, 80+p_vout->i_width-1, 50+p_vout->i_height-1 ), NULL, p_vout );
-    if( p_vout->p_sys->p_window == 0 )
+
+    p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
+                                               p_vout->p_sys->i_height - 1,
+                                               BRect( 20, 50,
+                                                      20 + p_vout->i_window_width - 1, 
+                                                      50 + p_vout->i_window_height - 1 ));
+
+    if( p_vout->p_sys->p_window == NULL )
     {
-        free( p_vout->p_sys );
-        intf_ErrMsg( "error: cannot allocate memory for VideoWindow" );
+        msg_Err( p_vout, "cannot allocate VideoWindow" );
         return( 1 );
     }   
-    VideoWindow * p_win = p_vout->p_sys->p_window;
-    
-    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;
     
-    switch( p_vout->i_screen_depth )
-    {
-    case 8:
-        intf_ErrMsg( "vout error: 8 bit mode not fully supported" );
-        break;
-    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 );
 }
 
@@ -627,9 +628,18 @@ static int BeosOpenDisplay( vout_thread_t *p_vout )
  *****************************************************************************/
 static void BeosCloseDisplay( vout_thread_t *p_vout )
 {    
+    VideoWindow * p_win = p_vout->p_sys->p_window;
     /* Destroy the video window */
-    p_vout->p_sys->p_window->Lock();
-    p_vout->p_sys->p_window->Quit();
+    if( p_win != NULL && !p_win->teardownwindow)
+    {
+        p_win->Lock();
+        p_win->teardownwindow = true;
+        p_win->Hide();
+        p_win->Quit();
+    }
+    p_win = NULL;
 }
 
+
+
 } /* extern "C" */