1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: VideoOutput.cpp,v 1.5 2002/10/30 00:59:22 titer Exp $
7 * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Tony Castley <tcastley@mail.powerup.com.au>
10 * Richard Shepherd <richard@rshepherd.demon.co.uk>
11 * Stephan Aßmus <stippi@yellowbites.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
34 #include <string.h> /* strerror() */
36 #include <Application.h>
37 #include <BitmapStream.h>
39 #include <DirectWindow.h>
41 #include <InterfaceKit.h>
44 #include <TranslatorRoster.h>
51 #include "VideoWindow.h"
52 #include "DrawingTidbits.h"
55 /*****************************************************************************
56 * vout_sys_t: BeOS video output method descriptor
57 *****************************************************************************
58 * This structure is part of the video output thread descriptor.
59 * It describes the BeOS specific properties of an output thread.
60 *****************************************************************************/
63 VideoWindow * p_window;
74 #define MOUSE_IDLE_TIMEOUT 2000000 // two seconds
75 #define MIN_AUTO_VSYNC_REFRESH 61 // Hz
76 #define DEFAULT_SCREEN_SHOT_FORMAT 'PNG '
77 #define DEFAULT_SCREEN_SHOT_PATH "/boot/home/vlc screenshot"
79 /*****************************************************************************
80 * beos_GetAppWindow : retrieve a BWindow pointer from the window name
81 *****************************************************************************/
83 beos_GetAppWindow(char *name)
88 for (index = 0 ; ; index++)
90 window = be_app->WindowAt(index);
93 if (window->LockWithTimeout(20000) == B_OK)
95 if (strcmp(window->Name(), name) == 0)
106 /*****************************************************************************
107 * get_interface_window
108 *****************************************************************************/
110 get_interface_window()
112 return beos_GetAppWindow(VOUT_TITLE);
115 class BackgroundView : public BView
118 BackgroundView(BRect frame, VLCView* view)
119 : BView(frame, "background",
120 B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE),
123 SetViewColor(kBlack);
125 virtual ~BackgroundView() {}
127 virtual void MouseDown(BPoint where)
129 // convert coordinates
130 where = fVideoView->ConvertFromParent(where);
132 fVideoView->MouseDown(where);
134 virtual void MouseMoved(BPoint where, uint32 transit,
135 const BMessage* dragMessage)
137 // convert coordinates
138 where = fVideoView->ConvertFromParent(where);
140 fVideoView->MouseMoved(where, transit, dragMessage);
141 // notice: It might look like transit should be
142 // B_OUTSIDE_VIEW regardless, but leave it like this,
143 // otherwise, unwanted things will happen!
150 /*****************************************************************************
151 * VideoWindow constructor and destructor
152 *****************************************************************************/
153 VideoWindow::VideoWindow(int v_width, int v_height, BRect frame,
154 vout_thread_t *p_videoout)
155 : BWindow(frame, NULL, B_TITLED_WINDOW, B_NOT_CLOSABLE | B_NOT_MINIMIZABLE),
156 i_width(frame.IntegerWidth()),
157 i_height(frame.IntegerHeight()),
161 teardownwindow(false),
163 fTrueHeight(v_height),
164 fCorrectAspect(true),
165 fCachedFeel(B_NORMAL_WINDOW_FEEL),
166 fInterfaceShowing(false),
171 // create the view to do the display
172 view = new VLCView( Bounds() );
174 // create background view
175 BView *mainView = new BackgroundView( Bounds(), view );
177 mainView->AddChild(view);
179 // figure out if we should use vertical sync by default
180 BScreen screen(this);
181 if (screen.IsValid())
184 screen.GetMode(&mode);
185 float refresh = (mode.timing.pixel_clock * 1000)
186 / ((mode.timing.h_total)* (mode.timing.v_total));
187 vsync = (refresh < MIN_AUTO_VSYNC_REFRESH);
190 // allocate bitmap buffers
191 for (int32 i = 0; i < 3; i++)
193 fInitStatus = _AllocateBuffers(v_width, v_height, &mode);
195 // make sure we layout the view correctly
196 FrameResized(i_width, i_height);
198 if (fInitStatus >= B_OK && mode == OVERLAY)
200 overlay_restrictions r;
202 bitmap[1]->GetOverlayRestrictions(&r);
203 SetSizeLimits((i_width * r.min_width_scale), i_width * r.max_width_scale,
204 (i_height * r.min_height_scale), i_height * r.max_height_scale);
208 VideoWindow::~VideoWindow()
212 teardownwindow = true;
213 wait_for_thread(fDrawThreadID, &result);
217 /*****************************************************************************
218 * VideoWindow::MessageReceived
219 *****************************************************************************/
221 VideoWindow::MessageReceived( BMessage *p_message )
223 switch( p_message->what )
225 case TOGGLE_FULL_SCREEN:
233 _SetVideoSize(p_message->what);
241 if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
244 fCachedFeel = winFeel;
249 SetCorrectAspectRatio(!fCorrectAspect);
252 // save a screen shot
253 if ( BBitmap* current = bitmap[i_buffer] )
255 // the following line might be tempting, but does not work for some overlay bitmaps!!!
256 // BBitmap* temp = new BBitmap( current );
257 // so we clone the bitmap ourselves
258 // however, we need to take care of potentially different padding!
259 // memcpy() is slow when reading from grafix memory, but what the heck...
260 BBitmap* temp = new BBitmap( current->Bounds(), current->ColorSpace() );
261 if ( temp && temp->IsValid() )
263 int32 height = (int32)current->Bounds().Height();
264 uint8* dst = (uint8*)temp->Bits();
265 uint8* src = (uint8*)current->Bits();
266 int32 dstBpr = temp->BytesPerRow();
267 int32 srcBpr = current->BytesPerRow();
268 int32 validBytes = dstBpr > srcBpr ? srcBpr : dstBpr;
269 for ( int32 y = 0; y < height; y++ )
271 memcpy( dst, src, validBytes );
275 _SaveScreenShot( temp,
276 strdup( DEFAULT_SCREEN_SHOT_PATH ),
277 DEFAULT_SCREEN_SHOT_FORMAT );
282 fprintf( stderr, "error copying bitmaps\n" );
287 BWindow::MessageReceived( p_message );
292 /*****************************************************************************
294 *****************************************************************************/
296 VideoWindow::Zoom(BPoint origin, float width, float height )
300 MoveTo(winSize.left, winSize.top);
301 ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
302 be_app->ShowCursor();
303 fInterfaceShowing = true;
307 BScreen screen(this);
308 BRect rect = screen.Frame();
311 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
312 be_app->ObscureCursor();
313 fInterfaceShowing = false;
315 is_zoomed = !is_zoomed;
318 /*****************************************************************************
319 * VideoWindow::FrameMoved
320 *****************************************************************************/
322 VideoWindow::FrameMoved(BPoint origin)
324 if (is_zoomed) return ;
328 /*****************************************************************************
329 * VideoWindow::FrameResized
330 *****************************************************************************/
332 VideoWindow::FrameResized( float width, float height )
334 int32 useWidth = fCorrectAspect ? i_width : fTrueWidth;
335 int32 useHeight = fCorrectAspect ? i_height : fTrueHeight;
336 float out_width, out_height;
337 float out_left, out_top;
338 float width_scale = width / useWidth;
339 float height_scale = height / useHeight;
341 if (width_scale <= height_scale)
343 out_width = (useWidth * width_scale);
344 out_height = (useHeight * width_scale);
346 out_top = (height - out_height) / 2;
348 else /* if the height is proportionally smaller */
350 out_width = (useWidth * height_scale);
351 out_height = (useHeight * height_scale);
353 out_left = (width - out_width) / 2;
355 view->MoveTo(out_left,out_top);
356 view->ResizeTo(out_width, out_height);
362 /*****************************************************************************
363 * VideoWindow::ScreenChanged
364 *****************************************************************************/
366 VideoWindow::ScreenChanged(BRect frame, color_space format)
368 BScreen screen(this);
370 screen.GetMode(&mode);
371 float refresh = (mode.timing.pixel_clock * 1000)
372 / ((mode.timing.h_total) * (mode.timing.v_total));
373 if (refresh < MIN_AUTO_VSYNC_REFRESH)
377 /*****************************************************************************
378 * VideoWindow::Activate
379 *****************************************************************************/
381 VideoWindow::WindowActivated(bool active)
385 /*****************************************************************************
386 * VideoWindow::drawBuffer
387 *****************************************************************************/
389 VideoWindow::drawBuffer(int bufferIndex)
391 i_buffer = bufferIndex;
393 // sync to the screen if required
396 BScreen screen(this);
397 screen.WaitForRetrace(22000);
399 if (fInitStatus >= B_OK && LockLooper())
401 // switch the overlay bitmap
405 view->SetViewOverlay(bitmap[i_buffer],
406 bitmap[i_buffer]->Bounds() ,
409 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
410 B_OVERLAY_TRANSFER_CHANNEL);
411 view->SetViewColor(key);
416 view->DrawBitmap(bitmap[i_buffer], view->Bounds() );
422 /*****************************************************************************
423 * VideoWindow::SetInterfaceShowing
424 *****************************************************************************/
426 VideoWindow::ToggleInterfaceShowing()
428 SetInterfaceShowing(!fInterfaceShowing);
431 /*****************************************************************************
432 * VideoWindow::SetInterfaceShowing
433 *****************************************************************************/
435 VideoWindow::SetInterfaceShowing(bool showIt)
437 BWindow* window = get_interface_window();
442 if (fCachedFeel != B_NORMAL_WINDOW_FEEL)
443 SetFeel(B_NORMAL_WINDOW_FEEL);
444 window->Activate(true);
449 SetFeel(fCachedFeel);
451 window->SendBehind(this);
453 fInterfaceShowing = showIt;
457 /*****************************************************************************
458 * VideoWindow::SetCorrectAspectRatio
459 *****************************************************************************/
461 VideoWindow::SetCorrectAspectRatio(bool doIt)
463 if (fCorrectAspect != doIt)
465 fCorrectAspect = doIt;
466 FrameResized(Bounds().Width(), Bounds().Height());
470 /*****************************************************************************
471 * VideoWindow::_AllocateBuffers
472 *****************************************************************************/
474 VideoWindow::_AllocateBuffers(int width, int height, int* mode)
476 // clear any old buffers
481 BRect bitmapFrame( 0, 0, width, height );
482 // read from config, if we are supposed to use overlay at all
483 int noOverlay = !config_GetInt( p_vout, "overlay" );
484 // test for overlay capability
485 for (int i = 0; i < COLOR_COUNT; i++)
487 if (noOverlay) break;
488 bitmap[0] = new BBitmap ( bitmapFrame,
489 B_BITMAP_WILL_OVERLAY |
490 B_BITMAP_RESERVE_OVERLAY_CHANNEL,
491 colspace[i].colspace);
493 if(bitmap[0] && bitmap[0]->InitCheck() == B_OK)
497 bitmap[1] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
498 colspace[colspace_index].colspace);
499 bitmap[2] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
500 colspace[colspace_index].colspace);
501 if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
505 view->SetViewOverlay(bitmap[0],
506 bitmap[0]->Bounds() ,
509 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
510 view->SetViewColor(key);
511 SetTitle(VOUT_TITLE " (Overlay)");
517 *mode = BITMAP; // might want to try again with normal bitmaps
527 colspace_index = DEFAULT_COL; // B_RGB16
528 // FIXME: an error in the YUV->RGB32 module prevents this from being used!
529 /* BScreen screen( B_MAIN_SCREEN_ID );
530 if ( screen.ColorSpace() == B_RGB32 )
531 colspace_index = 3; // B_RGB32 (faster on 32 bit screen)*/
532 SetTitle( VOUT_TITLE " (Bitmap)" );
533 bitmap[0] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
534 bitmap[1] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
535 bitmap[2] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
537 // see if everything went well
538 status_t status = B_ERROR;
539 for (int32 i = 0; i < 3; i++)
542 status = bitmap[i]->InitCheck();
548 // clear bitmaps to black
549 for (int32 i = 0; i < 3; i++)
550 _BlankBitmap(bitmap[i]);
555 /*****************************************************************************
556 * VideoWindow::_FreeBuffers
557 *****************************************************************************/
559 VideoWindow::_FreeBuffers()
567 fInitStatus = B_ERROR;
570 /*****************************************************************************
571 * VideoWindow::_BlankBitmap
572 *****************************************************************************/
574 VideoWindow::_BlankBitmap(BBitmap* bitmap) const
576 // no error checking (we do that earlier on and since it's a private function...
579 // Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
582 // Extrema points are Y 0 - 207 (absolute) U -91 - 91 (offset 128) V -127 - 127 (offset 128)
584 // we only handle weird colorspaces with special care
585 switch (bitmap->ColorSpace()) {
587 // Y0[7:0] Cb0[7:0] Y1[7:0] Cr0[7:0] Y2[7:0] Cb2[7:0] Y3[7:0] Cr2[7:0]
588 int32 height = bitmap->Bounds().IntegerHeight() + 1;
589 uint8* bits = (uint8*)bitmap->Bits();
590 int32 bpr = bitmap->BytesPerRow();
591 for (int32 y = 0; y < height; y++) {
592 // handle 2 bytes at a time
593 for (int32 i = 0; i < bpr; i += 2) {
605 // Non-interlaced only, Cb0 Y0 Y1 Cb2 Y2 Y3 on even scan lines ...
606 // Cr0 Y0 Y1 Cr2 Y2 Y3 on odd scan lines
607 int32 height = bitmap->Bounds().IntegerHeight() + 1;
608 uint8* bits = (uint8*)bitmap->Bits();
609 int32 bpr = bitmap->BytesPerRow();
610 for (int32 y = 0; y < height; y += 1) {
611 // handle 3 bytes at a time
612 for (int32 i = 0; i < bpr; i += 3) {
625 // U0[7:0] Y0[7:0] V0[7:0] Y1[7:0] U2[7:0] Y2[7:0] V2[7:0] Y3[7:0]
626 int32 height = bitmap->Bounds().IntegerHeight() + 1;
627 uint8* bits = (uint8*)bitmap->Bits();
628 int32 bpr = bitmap->BytesPerRow();
629 for (int32 y = 0; y < height; y += 1) {
630 // handle 2 bytes at a time
631 for (int32 i = 0; i < bpr; i += 2) {
642 memset(bitmap->Bits(), 0, bitmap->BitsLength());
647 /*****************************************************************************
648 * VideoWindow::_SetVideoSize
649 *****************************************************************************/
651 VideoWindow::_SetVideoSize(uint32 mode)
653 // let size depend on aspect correction
654 int32 width = fCorrectAspect ? i_width : fTrueWidth;
655 int32 height = fCorrectAspect ? i_height : fTrueHeight;
670 ResizeTo(width, height);
674 /*****************************************************************************
675 * VideoWindow::_SaveScreenShot
676 *****************************************************************************/
678 VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
679 uint32 translatorID ) const
681 // make the info object from the parameters
682 screen_shot_info* info = new screen_shot_info;
683 info->bitmap = bitmap;
685 info->translatorID = translatorID;
686 info->width = fCorrectAspect ? i_width : fTrueWidth;
687 info->height = fCorrectAspect ? i_height : fTrueHeight;
688 // spawn a new thread to take care of the actual saving to disk
689 thread_id thread = spawn_thread( _save_screen_shot,
691 B_LOW_PRIORITY, (void*)info );
692 // start thread or do the job ourself if something went wrong
693 if ( thread < B_OK || resume_thread( thread ) < B_OK )
694 _save_screen_shot( (void*)info );
697 /*****************************************************************************
698 * VideoWindow::_save_screen_shot
699 *****************************************************************************/
701 VideoWindow::_save_screen_shot( void* cookie )
703 screen_shot_info* info = (screen_shot_info*)cookie;
704 if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
706 // try to be as quick as possible creating the file (the user might have
707 // taken the next screen shot already!)
708 // make sure we have a unique name for the screen shot
709 BString path( info->path );
710 BEntry entry( path.String() );
711 int32 appendedNumber = 0;
712 if ( entry.Exists() && !entry.IsSymLink() )
714 // we would clobber an existing entry
715 bool foundUniqueName = false;
717 while ( !foundUniqueName ) {
718 BString newName( info->path );
719 newName << " " << appendedNumber;
720 BEntry possiblyClobberedEntry( newName.String() );
721 if ( possiblyClobberedEntry.Exists()
722 && !possiblyClobberedEntry.IsSymLink() )
725 foundUniqueName = true;
728 if ( appendedNumber > 0 )
729 path << " " << appendedNumber;
730 // there is still a slight chance to clobber an existing
731 // file (if it was created in the "meantime"), but we take it...
732 BFile outFile( path.String(),
733 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
735 // make colorspace converted copy of bitmap
736 BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
738 // if ( converted->IsValid() )
739 // memset( converted->Bits(), 0, converted->BitsLength() );
740 status_t status = convert_bitmap( info->bitmap, converted );
741 if ( status == B_OK )
743 BTranslatorRoster* roster = BTranslatorRoster::Default();
744 uint32 imageFormat = 0;
745 translator_id translator = 0;
748 // find suitable translator
749 translator_id* ids = NULL;
752 status = roster->GetAllTranslators( &ids, &count );
753 if ( status >= B_OK )
755 for ( int tix = 0; tix < count; tix++ )
757 const translation_format *formats = NULL;
758 int32 num_formats = 0;
760 status = roster->GetInputFormats( ids[tix],
761 &formats, &num_formats );
764 for ( int iix = 0; iix < num_formats; iix++ )
766 if ( formats[iix].type == B_TRANSLATOR_BITMAP )
775 status = roster->GetOutputFormats( ids[tix],
776 &formats, &num_formats);
777 if ( status >= B_OK )
779 for ( int32 oix = 0; oix < num_formats; oix++ )
781 if ( formats[oix].type != B_TRANSLATOR_BITMAP )
783 if ( formats[oix].type == info->translatorID )
786 imageFormat = formats[oix].type;
787 translator = ids[tix];
798 // make bitmap stream
799 BBitmapStream outStream( converted );
801 status = outFile.InitCheck();
802 if (status == B_OK) {
803 status = roster->Translate( &outStream, NULL, NULL,
804 &outFile, imageFormat );
805 if ( status == B_OK )
807 BNodeInfo nodeInfo( &outFile );
808 if ( nodeInfo.InitCheck() == B_OK )
810 translation_format* formats;
812 status = roster->GetOutputFormats( translator,
813 (const translation_format **) &formats,
815 if ( status >= B_OK )
817 const char * mime = NULL;
818 for ( int ix = 0; ix < count; ix++ ) {
819 if ( formats[ix].type == imageFormat ) {
820 mime = formats[ix].MIME;
825 nodeInfo.SetType( mime );
829 fprintf( stderr, " failed to write bitmap: %s\n",
830 strerror( status ) );
833 fprintf( stderr, " failed to create output file: %s\n",
834 strerror( status ) );
836 outStream.DetachBitmap( &converted );
840 fprintf( stderr, " failed to find translator\n");
843 fprintf( stderr, " failed to convert colorspace: %s\n",
844 strerror( status ) );
857 /*****************************************************************************
859 *****************************************************************************/
860 VLCView::VLCView(BRect bounds)
861 : BView(bounds, "video view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
862 fLastMouseMovedTime(system_time()),
863 fCursorHidden(false),
864 fCursorInside(false),
865 fIgnoreDoubleClick(false)
867 SetViewColor(B_TRANSPARENT_32_BIT);
870 /*****************************************************************************
872 *****************************************************************************/
877 /*****************************************************************************
878 * VLCVIew::AttachedToWindow
879 *****************************************************************************/
881 VLCView::AttachedToWindow()
883 // in order to get keyboard events
885 // periodically check if we want to hide the pointer
886 Window()->SetPulseRate(1000000);
889 /*****************************************************************************
891 *****************************************************************************/
893 VLCView::MouseDown(BPoint where)
895 VideoWindow* videoWindow = dynamic_cast<VideoWindow*>(Window());
896 BMessage* msg = Window()->CurrentMessage();
899 msg->FindInt32("clicks", &clicks);
900 msg->FindInt32("buttons", (int32*)&buttons);
904 if (buttons & B_PRIMARY_MOUSE_BUTTON)
906 if (clicks == 2 && !fIgnoreDoubleClick)
909 videoWindow->ToggleInterfaceShowing();
910 fIgnoreDoubleClick = false;
914 if (buttons & B_SECONDARY_MOUSE_BUTTON)
916 // clicks will be 2 next time (if interval short enough)
917 // even if the first click and the second
918 // have not been made with the same mouse button
919 fIgnoreDoubleClick = true;
921 BPopUpMenu *menu = new BPopUpMenu("context menu");
922 menu->SetRadioMode(false);
924 BMenuItem *halfItem = new BMenuItem("50%", new BMessage(RESIZE_50));
925 menu->AddItem(halfItem);
927 BMenuItem *origItem = new BMenuItem("100%", new BMessage(RESIZE_100));
928 menu->AddItem(origItem);
930 BMenuItem *doubleItem = new BMenuItem("200%", new BMessage(RESIZE_200));
931 menu->AddItem(doubleItem);
933 BMenuItem *zoomItem = new BMenuItem("Fullscreen", new BMessage(TOGGLE_FULL_SCREEN));
934 zoomItem->SetMarked(videoWindow->is_zoomed);
935 menu->AddItem(zoomItem);
937 menu->AddSeparatorItem();
940 BMenuItem *vsyncItem = new BMenuItem("Vertical Sync", new BMessage(VERT_SYNC));
941 vsyncItem->SetMarked(videoWindow->vsync);
942 menu->AddItem(vsyncItem);
943 // Correct Aspect Ratio
944 BMenuItem *aspectItem = new BMenuItem("Correct Aspect Ratio", new BMessage(ASPECT_CORRECT));
945 aspectItem->SetMarked(videoWindow->CorrectAspectRatio());
946 menu->AddItem(aspectItem);
948 menu->AddSeparatorItem();
951 /* BMessage *winNormFeel = new BMessage(WINDOW_FEEL);
952 winNormFeel->AddInt32("WinFeel", (int32)B_NORMAL_WINDOW_FEEL);
953 BMenuItem *normWindItem = new BMenuItem("Normal Window", winNormFeel);
954 normWindItem->SetMarked(videoWindow->Feel() == B_NORMAL_WINDOW_FEEL);
955 menu->AddItem(normWindItem);
957 BMessage *winFloatFeel = new BMessage(WINDOW_FEEL);
958 winFloatFeel->AddInt32("WinFeel", (int32)B_FLOATING_APP_WINDOW_FEEL);
959 BMenuItem *onTopWindItem = new BMenuItem("App Top", winFloatFeel);
960 onTopWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_APP_WINDOW_FEEL);
961 menu->AddItem(onTopWindItem);
963 BMessage *winAllFeel = new BMessage(WINDOW_FEEL);
964 winAllFeel->AddInt32("WinFeel", (int32)B_FLOATING_ALL_WINDOW_FEEL);
965 BMenuItem *allSpacesWindItem = new BMenuItem("On Top All Workspaces", winAllFeel);
966 allSpacesWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL);
967 menu->AddItem(allSpacesWindItem);*/
969 BMessage *windowFeelMsg = new BMessage( WINDOW_FEEL );
970 bool onTop = videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
971 window_feel feel = onTop ? B_NORMAL_WINDOW_FEEL : B_FLOATING_ALL_WINDOW_FEEL;
972 windowFeelMsg->AddInt32( "WinFeel", (int32)feel );
973 BMenuItem *windowFeelItem = new BMenuItem( "Stay On Top", windowFeelMsg );
974 windowFeelItem->SetMarked( onTop );
975 menu->AddItem( windowFeelItem );
977 menu->AddSeparatorItem();
979 BMenuItem* screenShotItem = new BMenuItem( "Take Screen Shot",
980 new BMessage( SCREEN_SHOT ) );
981 menu->AddItem( screenShotItem );
983 menu->SetTargetForItems( this );
984 ConvertToScreen( &where );
985 menu->Go( where, true, false, true );
989 fLastMouseMovedTime = system_time();
990 fCursorHidden = false;
993 /*****************************************************************************
994 * VLCVIew::MouseMoved
995 *****************************************************************************/
997 VLCView::MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage)
999 fLastMouseMovedTime = system_time();
1000 fCursorHidden = false;
1001 fCursorInside = (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW);
1004 /*****************************************************************************
1006 *****************************************************************************/
1010 // We are getting the pulse messages no matter if the mouse is over
1011 // this view. If we are in full screen mode, we want to hide the cursor
1012 // even if it is not.
1016 && system_time() - fLastMouseMovedTime > MOUSE_IDLE_TIMEOUT)
1018 be_app->ObscureCursor();
1019 fCursorHidden = true;
1020 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1021 // hide the interface window as well if full screen
1022 if (videoWindow && videoWindow->is_zoomed)
1023 videoWindow->SetInterfaceShowing(false);
1028 /*****************************************************************************
1030 *****************************************************************************/
1032 VLCView::KeyDown(const char *bytes, int32 numBytes)
1034 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1035 BWindow* interfaceWindow = get_interface_window();
1036 if (videoWindow && numBytes > 0) {
1037 uint32 mods = modifiers();
1040 // toggle window and full screen mode
1041 // not passing on the tab key to the default KeyDown()
1042 // implementation also avoids loosing the keyboard focus
1043 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1046 // go back to window mode
1047 if (videoWindow->is_zoomed)
1048 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1052 if (interfaceWindow)
1053 interfaceWindow->PostMessage(PAUSE_PLAYBACK);
1056 if (interfaceWindow)
1058 if (mods & B_SHIFT_KEY)
1060 interfaceWindow->PostMessage(NEXT_TITLE);
1063 interfaceWindow->PostMessage(NEXT_CHAPTER);
1067 if (interfaceWindow)
1069 if (mods & B_SHIFT_KEY)
1071 interfaceWindow->PostMessage(PREV_TITLE);
1074 interfaceWindow->PostMessage(PREV_CHAPTER);
1078 // previous file in playlist
1079 interfaceWindow->PostMessage(PREV_FILE);
1082 // next file in playlist
1083 interfaceWindow->PostMessage(NEXT_FILE);
1088 videoWindow->PostMessage( SCREEN_SHOT );
1091 BView::KeyDown(bytes, numBytes);
1097 /*****************************************************************************
1099 *****************************************************************************/
1101 VLCView::Draw(BRect updateRect)
1103 VideoWindow* window = dynamic_cast<VideoWindow*>( Window() );
1104 if ( window && window->mode == BITMAP )
1105 FillRect( updateRect );
1108 /*****************************************************************************
1110 *****************************************************************************/
1111 static int Init ( vout_thread_t * );
1112 static void End ( vout_thread_t * );
1113 // static int Manage ( vout_thread_t * );
1114 static void Display ( vout_thread_t *, picture_t * );
1116 static int BeosOpenDisplay ( vout_thread_t *p_vout );
1117 static void BeosCloseDisplay( vout_thread_t *p_vout );
1119 /*****************************************************************************
1120 * OpenVideo: allocates BeOS video thread output method
1121 *****************************************************************************
1122 * This function allocates and initializes a BeOS vout method.
1123 *****************************************************************************/
1124 int E_(OpenVideo) ( vlc_object_t *p_this )
1126 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1128 /* Allocate structure */
1129 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
1130 if( p_vout->p_sys == NULL )
1132 msg_Err( p_vout, "out of memory" );
1135 p_vout->p_sys->i_width = p_vout->render.i_width;
1136 p_vout->p_sys->i_height = p_vout->render.i_height;
1137 p_vout->p_sys->source_chroma = p_vout->render.i_chroma;
1139 p_vout->pf_init = Init;
1140 p_vout->pf_end = End;
1141 p_vout->pf_manage = NULL;
1142 p_vout->pf_render = NULL;
1143 p_vout->pf_display = Display;
1148 /*****************************************************************************
1149 * Init: initialize BeOS video thread output method
1150 *****************************************************************************/
1151 int Init( vout_thread_t *p_vout )
1156 I_OUTPUTPICTURES = 0;
1158 /* Open and initialize device */
1159 if( BeosOpenDisplay( p_vout ) )
1161 msg_Err(p_vout, "vout error: can't open display");
1164 p_vout->output.i_width = p_vout->render.i_width;
1165 p_vout->output.i_height = p_vout->render.i_height;
1167 /* Assume we have square pixels */
1168 p_vout->output.i_aspect = p_vout->p_sys->i_width
1169 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
1170 p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
1171 p_vout->p_sys->i_index = 0;
1173 p_vout->b_direct = 1;
1175 p_vout->output.i_rmask = 0x00ff0000;
1176 p_vout->output.i_gmask = 0x0000ff00;
1177 p_vout->output.i_bmask = 0x000000ff;
1179 for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
1182 /* Find an empty picture slot */
1183 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
1186 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
1188 p_pic = p_vout->p_picture + i_index;
1197 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[buffer_index]->Bits();
1198 p_pic->p->i_lines = p_vout->p_sys->i_height;
1200 p_pic->p->i_pixel_pitch = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
1201 p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
1202 p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[buffer_index]->BytesPerRow();
1203 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch * ( p_vout->p_sys->p_window->bitmap[buffer_index]->Bounds().IntegerWidth() + 1 );
1205 p_pic->i_status = DESTROYED_PICTURE;
1206 p_pic->i_type = DIRECT_PICTURE;
1208 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
1216 /*****************************************************************************
1217 * End: terminate BeOS video thread output method
1218 *****************************************************************************/
1219 void End( vout_thread_t *p_vout )
1221 BeosCloseDisplay( p_vout );
1224 /*****************************************************************************
1225 * CloseVideo: destroy BeOS video thread output method
1226 *****************************************************************************
1227 * Terminate an output method created by DummyCreateOutputMethod
1228 *****************************************************************************/
1229 void E_(CloseVideo) ( vlc_object_t *p_this )
1231 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1233 free( p_vout->p_sys );
1236 /*****************************************************************************
1237 * Display: displays previously rendered output
1238 *****************************************************************************
1239 * This function send the currently rendered image to BeOS image, waits until
1240 * it is displayed and switch the two rendering buffers, preparing next frame.
1241 *****************************************************************************/
1242 void Display( vout_thread_t *p_vout, picture_t *p_pic )
1244 VideoWindow * p_win = p_vout->p_sys->p_window;
1246 /* draw buffer if required */
1247 if (!p_win->teardownwindow)
1249 p_win->drawBuffer(p_vout->p_sys->i_index);
1252 p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
1253 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[p_vout->p_sys->i_index]->Bits();
1256 /* following functions are local */
1258 /*****************************************************************************
1259 * BeosOpenDisplay: open and initialize BeOS device
1260 *****************************************************************************/
1261 static int BeosOpenDisplay( vout_thread_t *p_vout )
1264 p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
1265 p_vout->p_sys->i_height - 1,
1267 20 + p_vout->i_window_width - 1,
1268 50 + p_vout->i_window_height - 1 ),
1270 if( p_vout->p_sys->p_window == NULL )
1272 msg_Err( p_vout, "cannot allocate VideoWindow" );
1277 p_vout->p_sys->p_window->Show();
1283 /*****************************************************************************
1284 * BeosDisplay: close and reset BeOS device
1285 *****************************************************************************
1286 * Returns all resources allocated by BeosOpenDisplay and restore the original
1287 * state of the device.
1288 *****************************************************************************/
1289 static void BeosCloseDisplay( vout_thread_t *p_vout )
1291 VideoWindow * p_win = p_vout->p_sys->p_window;
1292 /* Destroy the video window */
1293 if( p_win != NULL && !p_win->teardownwindow)
1296 p_win->teardownwindow = true;