1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: VideoOutput.cpp,v 1.2 2002/09/30 18:30:27 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 : BWindow(frame, NULL, B_TITLED_WINDOW, B_NOT_CLOSABLE | B_NOT_MINIMIZABLE),
155 i_width(frame.IntegerWidth()),
156 i_height(frame.IntegerHeight()),
160 teardownwindow(false),
162 fTrueHeight(v_height),
163 fCorrectAspect(true),
164 fCachedFeel(B_NORMAL_WINDOW_FEEL),
165 fInterfaceShowing(false),
168 // create the view to do the display
169 view = new VLCView( Bounds() );
171 // create background view
172 BView *mainView = new BackgroundView( Bounds(), view );
174 mainView->AddChild(view);
176 // figure out if we should use vertical sync by default
177 BScreen screen(this);
178 if (screen.IsValid())
181 screen.GetMode(&mode);
182 float refresh = (mode.timing.pixel_clock * 1000)
183 / ((mode.timing.h_total)* (mode.timing.v_total));
184 vsync = (refresh < MIN_AUTO_VSYNC_REFRESH);
187 // allocate bitmap buffers
188 for (int32 i = 0; i < 3; i++)
190 fInitStatus = _AllocateBuffers(v_width, v_height, &mode);
192 // make sure we layout the view correctly
193 FrameResized(i_width, i_height);
195 if (fInitStatus >= B_OK && mode == OVERLAY)
197 overlay_restrictions r;
199 bitmap[1]->GetOverlayRestrictions(&r);
200 SetSizeLimits((i_width * r.min_width_scale), i_width * r.max_width_scale,
201 (i_height * r.min_height_scale), i_height * r.max_height_scale);
205 VideoWindow::~VideoWindow()
209 teardownwindow = true;
210 wait_for_thread(fDrawThreadID, &result);
214 /*****************************************************************************
215 * VideoWindow::MessageReceived
216 *****************************************************************************/
218 VideoWindow::MessageReceived( BMessage *p_message )
220 switch( p_message->what )
222 case TOGGLE_FULL_SCREEN:
230 _SetVideoSize(p_message->what);
238 if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
241 fCachedFeel = winFeel;
246 SetCorrectAspectRatio(!fCorrectAspect);
249 // save a screen shot
250 if ( BBitmap* current = bitmap[i_buffer] )
252 // the following line might be tempting, but does not work for some overlay bitmaps!!!
253 // BBitmap* temp = new BBitmap( current );
254 // so we clone the bitmap ourselves
255 // however, we need to take care of potentially different padding!
256 // memcpy() is slow when reading from grafix memory, but what the heck...
257 BBitmap* temp = new BBitmap( current->Bounds(), current->ColorSpace() );
258 if ( temp && temp->IsValid() )
260 int32 height = current->Bounds().Height();
261 uint8* dst = (uint8*)temp->Bits();
262 uint8* src = (uint8*)current->Bits();
263 int32 dstBpr = temp->BytesPerRow();
264 int32 srcBpr = current->BytesPerRow();
265 int32 validBytes = dstBpr > srcBpr ? srcBpr : dstBpr;
266 for ( int32 y = 0; y < height; y++ )
268 memcpy( dst, src, validBytes );
272 _SaveScreenShot( temp,
273 strdup( DEFAULT_SCREEN_SHOT_PATH ),
274 DEFAULT_SCREEN_SHOT_FORMAT );
279 fprintf( stderr, "error copying bitmaps\n" );
284 BWindow::MessageReceived( p_message );
289 /*****************************************************************************
291 *****************************************************************************/
293 VideoWindow::Zoom(BPoint origin, float width, float height )
297 MoveTo(winSize.left, winSize.top);
298 ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
299 be_app->ShowCursor();
300 fInterfaceShowing = true;
304 BScreen screen(this);
305 BRect rect = screen.Frame();
308 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
309 be_app->ObscureCursor();
310 fInterfaceShowing = false;
312 is_zoomed = !is_zoomed;
315 /*****************************************************************************
316 * VideoWindow::FrameMoved
317 *****************************************************************************/
319 VideoWindow::FrameMoved(BPoint origin)
321 if (is_zoomed) return ;
325 /*****************************************************************************
326 * VideoWindow::FrameResized
327 *****************************************************************************/
329 VideoWindow::FrameResized( float width, float height )
331 int32 useWidth = fCorrectAspect ? i_width : fTrueWidth;
332 int32 useHeight = fCorrectAspect ? i_height : fTrueHeight;
333 float out_width, out_height;
334 float out_left, out_top;
335 float width_scale = width / useWidth;
336 float height_scale = height / useHeight;
338 if (width_scale <= height_scale)
340 out_width = (useWidth * width_scale);
341 out_height = (useHeight * width_scale);
343 out_top = (height - out_height) / 2;
345 else /* if the height is proportionally smaller */
347 out_width = (useWidth * height_scale);
348 out_height = (useHeight * height_scale);
350 out_left = (width - out_width) / 2;
352 view->MoveTo(out_left,out_top);
353 view->ResizeTo(out_width, out_height);
359 /*****************************************************************************
360 * VideoWindow::ScreenChanged
361 *****************************************************************************/
363 VideoWindow::ScreenChanged(BRect frame, color_space format)
365 BScreen screen(this);
367 screen.GetMode(&mode);
368 float refresh = (mode.timing.pixel_clock * 1000)
369 / ((mode.timing.h_total) * (mode.timing.v_total));
370 if (refresh < MIN_AUTO_VSYNC_REFRESH)
374 /*****************************************************************************
375 * VideoWindow::Activate
376 *****************************************************************************/
378 VideoWindow::WindowActivated(bool active)
382 /*****************************************************************************
383 * VideoWindow::drawBuffer
384 *****************************************************************************/
386 VideoWindow::drawBuffer(int bufferIndex)
388 i_buffer = bufferIndex;
390 // sync to the screen if required
393 BScreen screen(this);
394 screen.WaitForRetrace(22000);
396 if (fInitStatus >= B_OK && LockLooper())
398 // switch the overlay bitmap
402 view->SetViewOverlay(bitmap[i_buffer],
403 bitmap[i_buffer]->Bounds() ,
406 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
407 B_OVERLAY_TRANSFER_CHANNEL);
408 view->SetViewColor(key);
413 view->DrawBitmap(bitmap[i_buffer], view->Bounds() );
419 /*****************************************************************************
420 * VideoWindow::SetInterfaceShowing
421 *****************************************************************************/
423 VideoWindow::ToggleInterfaceShowing()
425 SetInterfaceShowing(!fInterfaceShowing);
428 /*****************************************************************************
429 * VideoWindow::SetInterfaceShowing
430 *****************************************************************************/
432 VideoWindow::SetInterfaceShowing(bool showIt)
434 BWindow* window = get_interface_window();
439 if (fCachedFeel != B_NORMAL_WINDOW_FEEL)
440 SetFeel(B_NORMAL_WINDOW_FEEL);
441 window->Activate(true);
446 SetFeel(fCachedFeel);
448 window->SendBehind(this);
450 fInterfaceShowing = showIt;
454 /*****************************************************************************
455 * VideoWindow::SetCorrectAspectRatio
456 *****************************************************************************/
458 VideoWindow::SetCorrectAspectRatio(bool doIt)
460 if (fCorrectAspect != doIt)
462 fCorrectAspect = doIt;
463 FrameResized(Bounds().Width(), Bounds().Height());
467 /*****************************************************************************
468 * VideoWindow::_AllocateBuffers
469 *****************************************************************************/
471 VideoWindow::_AllocateBuffers(int width, int height, int* mode)
473 // clear any old buffers
478 BRect bitmapFrame( 0, 0, width, height );
479 // read from config, if we are supposed to use overlay at all
481 /* noOverlay = !config_GetInt( , "overlay" ); */
482 // test for overlay capability
483 for (int i = 0; i < COLOR_COUNT; i++)
485 if (noOverlay) break;
486 bitmap[0] = new BBitmap ( bitmapFrame,
487 B_BITMAP_WILL_OVERLAY,
488 colspace[i].colspace);
490 if(bitmap[0] && bitmap[0]->InitCheck() == B_OK)
494 bitmap[1] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
495 colspace[colspace_index].colspace);
496 bitmap[2] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
497 colspace[colspace_index].colspace);
498 if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
502 view->SetViewOverlay(bitmap[0],
503 bitmap[0]->Bounds() ,
506 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
507 view->SetViewColor(key);
508 SetTitle(VOUT_TITLE " (Overlay)");
514 *mode = BITMAP; // might want to try again with normal bitmaps
524 colspace_index = DEFAULT_COL; // B_RGB16
525 // FIXME: an error in the YUV->RGB32 module prevents this from being used!
526 /* BScreen screen( B_MAIN_SCREEN_ID );
527 if ( screen.ColorSpace() == B_RGB32 )
528 colspace_index = 3; // B_RGB32 (faster on 32 bit screen)*/
529 SetTitle( VOUT_TITLE " (Bitmap)" );
530 bitmap[0] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
531 bitmap[1] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
532 bitmap[2] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
534 // see if everything went well
535 status_t status = B_ERROR;
536 for (int32 i = 0; i < 3; i++)
539 status = bitmap[i]->InitCheck();
545 // clear bitmaps to black
546 for (int32 i = 0; i < 3; i++)
547 _BlankBitmap(bitmap[i]);
552 /*****************************************************************************
553 * VideoWindow::_FreeBuffers
554 *****************************************************************************/
556 VideoWindow::_FreeBuffers()
564 fInitStatus = B_ERROR;
567 /*****************************************************************************
568 * VideoWindow::_BlankBitmap
569 *****************************************************************************/
571 VideoWindow::_BlankBitmap(BBitmap* bitmap) const
573 // no error checking (we do that earlier on and since it's a private function...
576 // Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
579 // Extrema points are Y 0 - 207 (absolute) U -91 - 91 (offset 128) V -127 - 127 (offset 128)
581 // we only handle weird colorspaces with special care
582 switch (bitmap->ColorSpace()) {
584 // Y0[7:0] Cb0[7:0] Y1[7:0] Cr0[7:0] Y2[7:0] Cb2[7:0] Y3[7:0] Cr2[7:0]
585 int32 height = bitmap->Bounds().IntegerHeight() + 1;
586 uint8* bits = (uint8*)bitmap->Bits();
587 int32 bpr = bitmap->BytesPerRow();
588 for (int32 y = 0; y < height; y++) {
589 // handle 2 bytes at a time
590 for (int32 i = 0; i < bpr; i += 2) {
602 // Non-interlaced only, Cb0 Y0 Y1 Cb2 Y2 Y3 on even scan lines ...
603 // Cr0 Y0 Y1 Cr2 Y2 Y3 on odd scan lines
604 int32 height = bitmap->Bounds().IntegerHeight() + 1;
605 uint8* bits = (uint8*)bitmap->Bits();
606 int32 bpr = bitmap->BytesPerRow();
607 for (int32 y = 0; y < height; y += 1) {
608 // handle 3 bytes at a time
609 for (int32 i = 0; i < bpr; i += 3) {
622 // U0[7:0] Y0[7:0] V0[7:0] Y1[7:0] U2[7:0] Y2[7:0] V2[7:0] Y3[7:0]
623 int32 height = bitmap->Bounds().IntegerHeight() + 1;
624 uint8* bits = (uint8*)bitmap->Bits();
625 int32 bpr = bitmap->BytesPerRow();
626 for (int32 y = 0; y < height; y += 1) {
627 // handle 2 bytes at a time
628 for (int32 i = 0; i < bpr; i += 2) {
639 memset(bitmap->Bits(), 0, bitmap->BitsLength());
644 /*****************************************************************************
645 * VideoWindow::_SetVideoSize
646 *****************************************************************************/
648 VideoWindow::_SetVideoSize(uint32 mode)
650 // let size depend on aspect correction
651 int32 width = fCorrectAspect ? i_width : fTrueWidth;
652 int32 height = fCorrectAspect ? i_height : fTrueHeight;
667 ResizeTo(width, height);
671 /*****************************************************************************
672 * VideoWindow::_SaveScreenShot
673 *****************************************************************************/
675 VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
676 uint32 translatorID ) const
678 // make the info object from the parameters
679 screen_shot_info* info = new screen_shot_info;
680 info->bitmap = bitmap;
682 info->translatorID = translatorID;
683 info->width = fCorrectAspect ? i_width : fTrueWidth;
684 info->height = fCorrectAspect ? i_height : fTrueHeight;
685 // spawn a new thread to take care of the actual saving to disk
686 thread_id thread = spawn_thread( _save_screen_shot,
688 B_LOW_PRIORITY, (void*)info );
689 // start thread or do the job ourself if something went wrong
690 if ( thread < B_OK || resume_thread( thread ) < B_OK )
691 _save_screen_shot( (void*)info );
694 /*****************************************************************************
695 * VideoWindow::_save_screen_shot
696 *****************************************************************************/
698 VideoWindow::_save_screen_shot( void* cookie )
700 screen_shot_info* info = (screen_shot_info*)cookie;
701 if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
703 // try to be as quick as possible creating the file (the user might have
704 // taken the next screen shot already!)
705 // make sure we have a unique name for the screen shot
706 BString path( info->path );
707 BEntry entry( path.String() );
708 int32 appendedNumber = 0;
709 if ( entry.Exists() && !entry.IsSymLink() )
711 // we would clobber an existing entry
712 bool foundUniqueName = false;
714 while ( !foundUniqueName ) {
715 BString newName( info->path );
716 newName << " " << appendedNumber;
717 BEntry possiblyClobberedEntry( newName.String() );
718 if ( possiblyClobberedEntry.Exists()
719 && !possiblyClobberedEntry.IsSymLink() )
722 foundUniqueName = true;
725 if ( appendedNumber > 0 )
726 path << " " << appendedNumber;
727 // there is still a slight chance to clobber an existing
728 // file (if it was created in the "meantime"), but we take it...
729 BFile outFile( path.String(),
730 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
732 // make colorspace converted copy of bitmap
733 BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
735 // if ( converted->IsValid() )
736 // memset( converted->Bits(), 0, converted->BitsLength() );
737 status_t status = convert_bitmap( info->bitmap, converted );
738 if ( status == B_OK )
740 BTranslatorRoster* roster = BTranslatorRoster::Default();
741 uint32 imageFormat = 0;
742 translator_id translator = 0;
745 // find suitable translator
746 translator_id* ids = NULL;
749 status = roster->GetAllTranslators( &ids, &count );
750 if ( status >= B_OK )
752 for ( int tix = 0; tix < count; tix++ )
754 const translation_format *formats = NULL;
755 int32 num_formats = 0;
757 status = roster->GetInputFormats( ids[tix],
758 &formats, &num_formats );
761 for ( int iix = 0; iix < num_formats; iix++ )
763 if ( formats[iix].type == B_TRANSLATOR_BITMAP )
772 status = roster->GetOutputFormats( ids[tix],
773 &formats, &num_formats);
774 if ( status >= B_OK )
776 for ( int32 oix = 0; oix < num_formats; oix++ )
778 if ( formats[oix].type != B_TRANSLATOR_BITMAP )
780 if ( formats[oix].type == info->translatorID )
783 imageFormat = formats[oix].type;
784 translator = ids[tix];
795 // make bitmap stream
796 BBitmapStream outStream( converted );
798 status = outFile.InitCheck();
799 if (status == B_OK) {
800 status = roster->Translate( &outStream, NULL, NULL,
801 &outFile, imageFormat );
802 if ( status == B_OK )
804 BNodeInfo nodeInfo( &outFile );
805 if ( nodeInfo.InitCheck() == B_OK )
807 translation_format* formats;
809 status = roster->GetOutputFormats( translator,
810 (const translation_format **) &formats,
812 if ( status >= B_OK )
814 const char * mime = NULL;
815 for ( int ix = 0; ix < count; ix++ ) {
816 if ( formats[ix].type == imageFormat ) {
817 mime = formats[ix].MIME;
822 nodeInfo.SetType( mime );
826 fprintf( stderr, " failed to write bitmap: %s\n",
827 strerror( status ) );
830 fprintf( stderr, " failed to create output file: %s\n",
831 strerror( status ) );
833 outStream.DetachBitmap( &converted );
837 fprintf( stderr, " failed to find translator\n");
840 fprintf( stderr, " failed to convert colorspace: %s\n",
841 strerror( status ) );
854 /*****************************************************************************
856 *****************************************************************************/
857 VLCView::VLCView(BRect bounds)
858 : BView(bounds, "video view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
859 fLastMouseMovedTime(system_time()),
860 fCursorHidden(false),
861 fCursorInside(false),
862 fIgnoreDoubleClick(false)
864 SetViewColor(B_TRANSPARENT_32_BIT);
867 /*****************************************************************************
869 *****************************************************************************/
874 /*****************************************************************************
875 * VLCVIew::AttachedToWindow
876 *****************************************************************************/
878 VLCView::AttachedToWindow()
880 // in order to get keyboard events
882 // periodically check if we want to hide the pointer
883 Window()->SetPulseRate(1000000);
886 /*****************************************************************************
888 *****************************************************************************/
890 VLCView::MouseDown(BPoint where)
892 VideoWindow* videoWindow = dynamic_cast<VideoWindow*>(Window());
893 BMessage* msg = Window()->CurrentMessage();
896 msg->FindInt32("clicks", &clicks);
897 msg->FindInt32("buttons", (int32*)&buttons);
901 if (buttons & B_PRIMARY_MOUSE_BUTTON)
903 if (clicks == 2 && !fIgnoreDoubleClick)
906 videoWindow->ToggleInterfaceShowing();
907 fIgnoreDoubleClick = false;
911 if (buttons & B_SECONDARY_MOUSE_BUTTON)
913 // clicks will be 2 next time (if interval short enough)
914 // even if the first click and the second
915 // have not been made with the same mouse button
916 fIgnoreDoubleClick = true;
918 BPopUpMenu *menu = new BPopUpMenu("context menu");
919 menu->SetRadioMode(false);
921 BMenuItem *halfItem = new BMenuItem("50%", new BMessage(RESIZE_50));
922 menu->AddItem(halfItem);
924 BMenuItem *origItem = new BMenuItem("100%", new BMessage(RESIZE_100));
925 menu->AddItem(origItem);
927 BMenuItem *doubleItem = new BMenuItem("200%", new BMessage(RESIZE_200));
928 menu->AddItem(doubleItem);
930 BMenuItem *zoomItem = new BMenuItem("Fullscreen", new BMessage(TOGGLE_FULL_SCREEN));
931 zoomItem->SetMarked(videoWindow->is_zoomed);
932 menu->AddItem(zoomItem);
934 menu->AddSeparatorItem();
937 BMenuItem *vsyncItem = new BMenuItem("Vertical Sync", new BMessage(VERT_SYNC));
938 vsyncItem->SetMarked(videoWindow->vsync);
939 menu->AddItem(vsyncItem);
940 // Correct Aspect Ratio
941 BMenuItem *aspectItem = new BMenuItem("Correct Aspect Ratio", new BMessage(ASPECT_CORRECT));
942 aspectItem->SetMarked(videoWindow->CorrectAspectRatio());
943 menu->AddItem(aspectItem);
945 menu->AddSeparatorItem();
948 /* BMessage *winNormFeel = new BMessage(WINDOW_FEEL);
949 winNormFeel->AddInt32("WinFeel", (int32)B_NORMAL_WINDOW_FEEL);
950 BMenuItem *normWindItem = new BMenuItem("Normal Window", winNormFeel);
951 normWindItem->SetMarked(videoWindow->Feel() == B_NORMAL_WINDOW_FEEL);
952 menu->AddItem(normWindItem);
954 BMessage *winFloatFeel = new BMessage(WINDOW_FEEL);
955 winFloatFeel->AddInt32("WinFeel", (int32)B_FLOATING_APP_WINDOW_FEEL);
956 BMenuItem *onTopWindItem = new BMenuItem("App Top", winFloatFeel);
957 onTopWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_APP_WINDOW_FEEL);
958 menu->AddItem(onTopWindItem);
960 BMessage *winAllFeel = new BMessage(WINDOW_FEEL);
961 winAllFeel->AddInt32("WinFeel", (int32)B_FLOATING_ALL_WINDOW_FEEL);
962 BMenuItem *allSpacesWindItem = new BMenuItem("On Top All Workspaces", winAllFeel);
963 allSpacesWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL);
964 menu->AddItem(allSpacesWindItem);*/
966 BMessage *windowFeelMsg = new BMessage( WINDOW_FEEL );
967 bool onTop = videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
968 window_feel feel = onTop ? B_NORMAL_WINDOW_FEEL : B_FLOATING_ALL_WINDOW_FEEL;
969 windowFeelMsg->AddInt32( "WinFeel", (int32)feel );
970 BMenuItem *windowFeelItem = new BMenuItem( "Stay On Top", windowFeelMsg );
971 windowFeelItem->SetMarked( onTop );
972 menu->AddItem( windowFeelItem );
974 menu->AddSeparatorItem();
976 BMenuItem* screenShotItem = new BMenuItem( "Take Screen Shot",
977 new BMessage( SCREEN_SHOT ) );
978 menu->AddItem( screenShotItem );
980 menu->SetTargetForItems( this );
981 ConvertToScreen( &where );
982 menu->Go( where, true, false, true );
986 fLastMouseMovedTime = system_time();
987 fCursorHidden = false;
990 /*****************************************************************************
991 * VLCVIew::MouseMoved
992 *****************************************************************************/
994 VLCView::MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage)
996 fLastMouseMovedTime = system_time();
997 fCursorHidden = false;
998 fCursorInside = (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW);
1001 /*****************************************************************************
1003 *****************************************************************************/
1007 // We are getting the pulse messages no matter if the mouse is over
1008 // this view. If we are in full screen mode, we want to hide the cursor
1009 // even if it is not.
1013 && system_time() - fLastMouseMovedTime > MOUSE_IDLE_TIMEOUT)
1015 be_app->ObscureCursor();
1016 fCursorHidden = true;
1017 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1018 // hide the interface window as well if full screen
1019 if (videoWindow && videoWindow->is_zoomed)
1020 videoWindow->SetInterfaceShowing(false);
1025 /*****************************************************************************
1027 *****************************************************************************/
1029 VLCView::KeyDown(const char *bytes, int32 numBytes)
1031 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1032 BWindow* interfaceWindow = get_interface_window();
1033 if (videoWindow && numBytes > 0) {
1034 uint32 mods = modifiers();
1037 // toggle window and full screen mode
1038 // not passing on the tab key to the default KeyDown()
1039 // implementation also avoids loosing the keyboard focus
1040 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1043 // go back to window mode
1044 if (videoWindow->is_zoomed)
1045 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1049 if (interfaceWindow)
1050 interfaceWindow->PostMessage(PAUSE_PLAYBACK);
1053 if (interfaceWindow)
1055 if (mods & B_SHIFT_KEY)
1057 interfaceWindow->PostMessage(NEXT_TITLE);
1060 interfaceWindow->PostMessage(NEXT_CHAPTER);
1064 if (interfaceWindow)
1066 if (mods & B_SHIFT_KEY)
1068 interfaceWindow->PostMessage(PREV_TITLE);
1071 interfaceWindow->PostMessage(PREV_CHAPTER);
1075 // previous file in playlist
1076 interfaceWindow->PostMessage(PREV_FILE);
1079 // next file in playlist
1080 interfaceWindow->PostMessage(NEXT_FILE);
1085 videoWindow->PostMessage( SCREEN_SHOT );
1088 BView::KeyDown(bytes, numBytes);
1094 /*****************************************************************************
1096 *****************************************************************************/
1098 VLCView::Draw(BRect updateRect)
1100 VideoWindow* window = dynamic_cast<VideoWindow*>( Window() );
1101 if ( window && window->mode == BITMAP )
1102 FillRect( updateRect );
1105 /*****************************************************************************
1107 *****************************************************************************/
1108 static int Init ( vout_thread_t * );
1109 static void End ( vout_thread_t * );
1110 static int Manage ( vout_thread_t * );
1111 static void Display ( vout_thread_t *, picture_t * );
1113 static int BeosOpenDisplay ( vout_thread_t *p_vout );
1114 static void BeosCloseDisplay( vout_thread_t *p_vout );
1116 /*****************************************************************************
1117 * OpenVideo: allocates BeOS video thread output method
1118 *****************************************************************************
1119 * This function allocates and initializes a BeOS vout method.
1120 *****************************************************************************/
1121 int E_(OpenVideo) ( vlc_object_t *p_this )
1123 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1125 /* Allocate structure */
1126 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
1127 if( p_vout->p_sys == NULL )
1129 msg_Err( p_vout, "out of memory" );
1132 p_vout->p_sys->i_width = p_vout->render.i_width;
1133 p_vout->p_sys->i_height = p_vout->render.i_height;
1134 p_vout->p_sys->source_chroma = p_vout->render.i_chroma;
1136 p_vout->pf_init = Init;
1137 p_vout->pf_end = End;
1138 p_vout->pf_manage = NULL;
1139 p_vout->pf_render = NULL;
1140 p_vout->pf_display = Display;
1145 /*****************************************************************************
1146 * Init: initialize BeOS video thread output method
1147 *****************************************************************************/
1148 int Init( vout_thread_t *p_vout )
1153 I_OUTPUTPICTURES = 0;
1155 /* Open and initialize device */
1156 if( BeosOpenDisplay( p_vout ) )
1158 msg_Err(p_vout, "vout error: can't open display");
1161 p_vout->output.i_width = p_vout->render.i_width;
1162 p_vout->output.i_height = p_vout->render.i_height;
1164 /* Assume we have square pixels */
1165 p_vout->output.i_aspect = p_vout->p_sys->i_width
1166 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
1167 p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
1168 p_vout->p_sys->i_index = 0;
1170 p_vout->b_direct = 1;
1172 p_vout->output.i_rmask = 0x00ff0000;
1173 p_vout->output.i_gmask = 0x0000ff00;
1174 p_vout->output.i_bmask = 0x000000ff;
1176 for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
1179 /* Find an empty picture slot */
1180 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
1183 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
1185 p_pic = p_vout->p_picture + i_index;
1194 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[buffer_index]->Bits();
1195 p_pic->p->i_lines = p_vout->p_sys->i_height;
1197 p_pic->p->i_pixel_pitch = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
1198 p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
1199 p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[buffer_index]->BytesPerRow();
1200 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch * ( p_vout->p_sys->p_window->bitmap[buffer_index]->Bounds().IntegerWidth() + 1 );
1202 p_pic->i_status = DESTROYED_PICTURE;
1203 p_pic->i_type = DIRECT_PICTURE;
1205 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
1213 /*****************************************************************************
1214 * End: terminate BeOS video thread output method
1215 *****************************************************************************/
1216 void End( vout_thread_t *p_vout )
1218 BeosCloseDisplay( p_vout );
1221 /*****************************************************************************
1222 * CloseVideo: destroy BeOS video thread output method
1223 *****************************************************************************
1224 * Terminate an output method created by DummyCreateOutputMethod
1225 *****************************************************************************/
1226 void E_(CloseVideo) ( vlc_object_t *p_this )
1228 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1230 free( p_vout->p_sys );
1233 /*****************************************************************************
1234 * Display: displays previously rendered output
1235 *****************************************************************************
1236 * This function send the currently rendered image to BeOS image, waits until
1237 * it is displayed and switch the two rendering buffers, preparing next frame.
1238 *****************************************************************************/
1239 void Display( vout_thread_t *p_vout, picture_t *p_pic )
1241 VideoWindow * p_win = p_vout->p_sys->p_window;
1243 /* draw buffer if required */
1244 if (!p_win->teardownwindow)
1246 p_win->drawBuffer(p_vout->p_sys->i_index);
1249 p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
1250 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[p_vout->p_sys->i_index]->Bits();
1253 /* following functions are local */
1255 /*****************************************************************************
1256 * BeosOpenDisplay: open and initialize BeOS device
1257 *****************************************************************************/
1258 static int BeosOpenDisplay( vout_thread_t *p_vout )
1261 p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
1262 p_vout->p_sys->i_height - 1,
1264 20 + p_vout->i_window_width - 1,
1265 50 + p_vout->i_window_height - 1 ));
1266 if( p_vout->p_sys->p_window == NULL )
1268 msg_Err( p_vout, "cannot allocate VideoWindow" );
1273 p_vout->p_sys->p_window->Show();
1279 /*****************************************************************************
1280 * BeosDisplay: close and reset BeOS device
1281 *****************************************************************************
1282 * Returns all resources allocated by BeosOpenDisplay and restore the original
1283 * state of the device.
1284 *****************************************************************************/
1285 static void BeosCloseDisplay( vout_thread_t *p_vout )
1287 VideoWindow * p_win = p_vout->p_sys->p_window;
1288 /* Destroy the video window */
1289 if( p_win != NULL && !p_win->teardownwindow)
1292 p_win->teardownwindow = true;