1 /*****************************************************************************
2 * vout_beos.cpp: beos video output display method
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: VideoOutput.cpp,v 1.6 2002/11/22 19:37:25 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);
207 if( config_GetInt( p_vout, "fullscreen" ) )
213 VideoWindow::~VideoWindow()
217 teardownwindow = true;
218 wait_for_thread(fDrawThreadID, &result);
222 /*****************************************************************************
223 * VideoWindow::MessageReceived
224 *****************************************************************************/
226 VideoWindow::MessageReceived( BMessage *p_message )
228 switch( p_message->what )
230 case TOGGLE_FULL_SCREEN:
238 _SetVideoSize(p_message->what);
246 if (p_message->FindInt32("WinFeel", (int32*)&winFeel) == B_OK)
249 fCachedFeel = winFeel;
254 SetCorrectAspectRatio(!fCorrectAspect);
257 // save a screen shot
258 if ( BBitmap* current = bitmap[i_buffer] )
260 // the following line might be tempting, but does not work for some overlay bitmaps!!!
261 // BBitmap* temp = new BBitmap( current );
262 // so we clone the bitmap ourselves
263 // however, we need to take care of potentially different padding!
264 // memcpy() is slow when reading from grafix memory, but what the heck...
265 BBitmap* temp = new BBitmap( current->Bounds(), current->ColorSpace() );
266 if ( temp && temp->IsValid() )
268 int32 height = (int32)current->Bounds().Height();
269 uint8* dst = (uint8*)temp->Bits();
270 uint8* src = (uint8*)current->Bits();
271 int32 dstBpr = temp->BytesPerRow();
272 int32 srcBpr = current->BytesPerRow();
273 int32 validBytes = dstBpr > srcBpr ? srcBpr : dstBpr;
274 for ( int32 y = 0; y < height; y++ )
276 memcpy( dst, src, validBytes );
280 _SaveScreenShot( temp,
281 strdup( DEFAULT_SCREEN_SHOT_PATH ),
282 DEFAULT_SCREEN_SHOT_FORMAT );
287 fprintf( stderr, "error copying bitmaps\n" );
292 BWindow::MessageReceived( p_message );
297 /*****************************************************************************
299 *****************************************************************************/
301 VideoWindow::Zoom(BPoint origin, float width, float height )
305 MoveTo(winSize.left, winSize.top);
306 ResizeTo(winSize.IntegerWidth(), winSize.IntegerHeight());
307 be_app->ShowCursor();
308 fInterfaceShowing = true;
312 BScreen screen(this);
313 BRect rect = screen.Frame();
316 ResizeTo(rect.IntegerWidth(), rect.IntegerHeight());
317 be_app->ObscureCursor();
318 fInterfaceShowing = false;
320 is_zoomed = !is_zoomed;
323 /*****************************************************************************
324 * VideoWindow::FrameMoved
325 *****************************************************************************/
327 VideoWindow::FrameMoved(BPoint origin)
329 if (is_zoomed) return ;
333 /*****************************************************************************
334 * VideoWindow::FrameResized
335 *****************************************************************************/
337 VideoWindow::FrameResized( float width, float height )
339 int32 useWidth = fCorrectAspect ? i_width : fTrueWidth;
340 int32 useHeight = fCorrectAspect ? i_height : fTrueHeight;
341 float out_width, out_height;
342 float out_left, out_top;
343 float width_scale = width / useWidth;
344 float height_scale = height / useHeight;
346 if (width_scale <= height_scale)
348 out_width = (useWidth * width_scale);
349 out_height = (useHeight * width_scale);
351 out_top = (height - out_height) / 2;
353 else /* if the height is proportionally smaller */
355 out_width = (useWidth * height_scale);
356 out_height = (useHeight * height_scale);
358 out_left = (width - out_width) / 2;
360 view->MoveTo(out_left,out_top);
361 view->ResizeTo(out_width, out_height);
367 /*****************************************************************************
368 * VideoWindow::ScreenChanged
369 *****************************************************************************/
371 VideoWindow::ScreenChanged(BRect frame, color_space format)
373 BScreen screen(this);
375 screen.GetMode(&mode);
376 float refresh = (mode.timing.pixel_clock * 1000)
377 / ((mode.timing.h_total) * (mode.timing.v_total));
378 if (refresh < MIN_AUTO_VSYNC_REFRESH)
382 /*****************************************************************************
383 * VideoWindow::Activate
384 *****************************************************************************/
386 VideoWindow::WindowActivated(bool active)
390 /*****************************************************************************
391 * VideoWindow::drawBuffer
392 *****************************************************************************/
394 VideoWindow::drawBuffer(int bufferIndex)
396 i_buffer = bufferIndex;
398 // sync to the screen if required
401 BScreen screen(this);
402 screen.WaitForRetrace(22000);
404 if (fInitStatus >= B_OK && LockLooper())
406 // switch the overlay bitmap
410 view->SetViewOverlay(bitmap[i_buffer],
411 bitmap[i_buffer]->Bounds() ,
414 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL|
415 B_OVERLAY_TRANSFER_CHANNEL);
416 view->SetViewColor(key);
421 view->DrawBitmap(bitmap[i_buffer], view->Bounds() );
427 /*****************************************************************************
428 * VideoWindow::SetInterfaceShowing
429 *****************************************************************************/
431 VideoWindow::ToggleInterfaceShowing()
433 SetInterfaceShowing(!fInterfaceShowing);
436 /*****************************************************************************
437 * VideoWindow::SetInterfaceShowing
438 *****************************************************************************/
440 VideoWindow::SetInterfaceShowing(bool showIt)
442 BWindow* window = get_interface_window();
447 if (fCachedFeel != B_NORMAL_WINDOW_FEEL)
448 SetFeel(B_NORMAL_WINDOW_FEEL);
449 window->Activate(true);
454 SetFeel(fCachedFeel);
456 window->SendBehind(this);
458 fInterfaceShowing = showIt;
462 /*****************************************************************************
463 * VideoWindow::SetCorrectAspectRatio
464 *****************************************************************************/
466 VideoWindow::SetCorrectAspectRatio(bool doIt)
468 if (fCorrectAspect != doIt)
470 fCorrectAspect = doIt;
471 FrameResized(Bounds().Width(), Bounds().Height());
475 /*****************************************************************************
476 * VideoWindow::_AllocateBuffers
477 *****************************************************************************/
479 VideoWindow::_AllocateBuffers(int width, int height, int* mode)
481 // clear any old buffers
486 BRect bitmapFrame( 0, 0, width, height );
487 // read from config, if we are supposed to use overlay at all
488 int noOverlay = !config_GetInt( p_vout, "overlay" );
489 // test for overlay capability
490 for (int i = 0; i < COLOR_COUNT; i++)
492 if (noOverlay) break;
493 bitmap[0] = new BBitmap ( bitmapFrame,
494 B_BITMAP_WILL_OVERLAY |
495 B_BITMAP_RESERVE_OVERLAY_CHANNEL,
496 colspace[i].colspace);
498 if(bitmap[0] && bitmap[0]->InitCheck() == B_OK)
502 bitmap[1] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
503 colspace[colspace_index].colspace);
504 bitmap[2] = new BBitmap( bitmapFrame, B_BITMAP_WILL_OVERLAY,
505 colspace[colspace_index].colspace);
506 if ( (bitmap[2] && bitmap[2]->InitCheck() == B_OK) )
510 view->SetViewOverlay(bitmap[0],
511 bitmap[0]->Bounds() ,
514 B_OVERLAY_FILTER_HORIZONTAL|B_OVERLAY_FILTER_VERTICAL);
515 view->SetViewColor(key);
516 SetTitle(VOUT_TITLE " (Overlay)");
522 *mode = BITMAP; // might want to try again with normal bitmaps
532 colspace_index = DEFAULT_COL; // B_RGB16
533 // FIXME: an error in the YUV->RGB32 module prevents this from being used!
534 /* BScreen screen( B_MAIN_SCREEN_ID );
535 if ( screen.ColorSpace() == B_RGB32 )
536 colspace_index = 3; // B_RGB32 (faster on 32 bit screen)*/
537 SetTitle( VOUT_TITLE " (Bitmap)" );
538 bitmap[0] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
539 bitmap[1] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
540 bitmap[2] = new BBitmap( bitmapFrame, colspace[colspace_index].colspace );
542 // see if everything went well
543 status_t status = B_ERROR;
544 for (int32 i = 0; i < 3; i++)
547 status = bitmap[i]->InitCheck();
553 // clear bitmaps to black
554 for (int32 i = 0; i < 3; i++)
555 _BlankBitmap(bitmap[i]);
560 /*****************************************************************************
561 * VideoWindow::_FreeBuffers
562 *****************************************************************************/
564 VideoWindow::_FreeBuffers()
572 fInitStatus = B_ERROR;
575 /*****************************************************************************
576 * VideoWindow::_BlankBitmap
577 *****************************************************************************/
579 VideoWindow::_BlankBitmap(BBitmap* bitmap) const
581 // no error checking (we do that earlier on and since it's a private function...
584 // Loss/Saturation points are Y 16-235 (absoulte); Cb/Cr 16-240 (center 128)
587 // Extrema points are Y 0 - 207 (absolute) U -91 - 91 (offset 128) V -127 - 127 (offset 128)
589 // we only handle weird colorspaces with special care
590 switch (bitmap->ColorSpace()) {
592 // Y0[7:0] Cb0[7:0] Y1[7:0] Cr0[7:0] Y2[7:0] Cb2[7:0] Y3[7:0] Cr2[7:0]
593 int32 height = bitmap->Bounds().IntegerHeight() + 1;
594 uint8* bits = (uint8*)bitmap->Bits();
595 int32 bpr = bitmap->BytesPerRow();
596 for (int32 y = 0; y < height; y++) {
597 // handle 2 bytes at a time
598 for (int32 i = 0; i < bpr; i += 2) {
610 // Non-interlaced only, Cb0 Y0 Y1 Cb2 Y2 Y3 on even scan lines ...
611 // Cr0 Y0 Y1 Cr2 Y2 Y3 on odd scan lines
612 int32 height = bitmap->Bounds().IntegerHeight() + 1;
613 uint8* bits = (uint8*)bitmap->Bits();
614 int32 bpr = bitmap->BytesPerRow();
615 for (int32 y = 0; y < height; y += 1) {
616 // handle 3 bytes at a time
617 for (int32 i = 0; i < bpr; i += 3) {
630 // U0[7:0] Y0[7:0] V0[7:0] Y1[7:0] U2[7:0] Y2[7:0] V2[7:0] Y3[7:0]
631 int32 height = bitmap->Bounds().IntegerHeight() + 1;
632 uint8* bits = (uint8*)bitmap->Bits();
633 int32 bpr = bitmap->BytesPerRow();
634 for (int32 y = 0; y < height; y += 1) {
635 // handle 2 bytes at a time
636 for (int32 i = 0; i < bpr; i += 2) {
647 memset(bitmap->Bits(), 0, bitmap->BitsLength());
652 /*****************************************************************************
653 * VideoWindow::_SetVideoSize
654 *****************************************************************************/
656 VideoWindow::_SetVideoSize(uint32 mode)
658 // let size depend on aspect correction
659 int32 width = fCorrectAspect ? i_width : fTrueWidth;
660 int32 height = fCorrectAspect ? i_height : fTrueHeight;
675 ResizeTo(width, height);
679 /*****************************************************************************
680 * VideoWindow::_SaveScreenShot
681 *****************************************************************************/
683 VideoWindow::_SaveScreenShot( BBitmap* bitmap, char* path,
684 uint32 translatorID ) const
686 // make the info object from the parameters
687 screen_shot_info* info = new screen_shot_info;
688 info->bitmap = bitmap;
690 info->translatorID = translatorID;
691 info->width = fCorrectAspect ? i_width : fTrueWidth;
692 info->height = fCorrectAspect ? i_height : fTrueHeight;
693 // spawn a new thread to take care of the actual saving to disk
694 thread_id thread = spawn_thread( _save_screen_shot,
696 B_LOW_PRIORITY, (void*)info );
697 // start thread or do the job ourself if something went wrong
698 if ( thread < B_OK || resume_thread( thread ) < B_OK )
699 _save_screen_shot( (void*)info );
702 /*****************************************************************************
703 * VideoWindow::_save_screen_shot
704 *****************************************************************************/
706 VideoWindow::_save_screen_shot( void* cookie )
708 screen_shot_info* info = (screen_shot_info*)cookie;
709 if ( info && info->bitmap && info->bitmap->IsValid() && info->path )
711 // try to be as quick as possible creating the file (the user might have
712 // taken the next screen shot already!)
713 // make sure we have a unique name for the screen shot
714 BString path( info->path );
715 BEntry entry( path.String() );
716 int32 appendedNumber = 0;
717 if ( entry.Exists() && !entry.IsSymLink() )
719 // we would clobber an existing entry
720 bool foundUniqueName = false;
722 while ( !foundUniqueName ) {
723 BString newName( info->path );
724 newName << " " << appendedNumber;
725 BEntry possiblyClobberedEntry( newName.String() );
726 if ( possiblyClobberedEntry.Exists()
727 && !possiblyClobberedEntry.IsSymLink() )
730 foundUniqueName = true;
733 if ( appendedNumber > 0 )
734 path << " " << appendedNumber;
735 // there is still a slight chance to clobber an existing
736 // file (if it was created in the "meantime"), but we take it...
737 BFile outFile( path.String(),
738 B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE );
740 // make colorspace converted copy of bitmap
741 BBitmap* converted = new BBitmap( BRect( 0.0, 0.0, info->width, info->height ),
743 // if ( converted->IsValid() )
744 // memset( converted->Bits(), 0, converted->BitsLength() );
745 status_t status = convert_bitmap( info->bitmap, converted );
746 if ( status == B_OK )
748 BTranslatorRoster* roster = BTranslatorRoster::Default();
749 uint32 imageFormat = 0;
750 translator_id translator = 0;
753 // find suitable translator
754 translator_id* ids = NULL;
757 status = roster->GetAllTranslators( &ids, &count );
758 if ( status >= B_OK )
760 for ( int tix = 0; tix < count; tix++ )
762 const translation_format *formats = NULL;
763 int32 num_formats = 0;
765 status = roster->GetInputFormats( ids[tix],
766 &formats, &num_formats );
769 for ( int iix = 0; iix < num_formats; iix++ )
771 if ( formats[iix].type == B_TRANSLATOR_BITMAP )
780 status = roster->GetOutputFormats( ids[tix],
781 &formats, &num_formats);
782 if ( status >= B_OK )
784 for ( int32 oix = 0; oix < num_formats; oix++ )
786 if ( formats[oix].type != B_TRANSLATOR_BITMAP )
788 if ( formats[oix].type == info->translatorID )
791 imageFormat = formats[oix].type;
792 translator = ids[tix];
803 // make bitmap stream
804 BBitmapStream outStream( converted );
806 status = outFile.InitCheck();
807 if (status == B_OK) {
808 status = roster->Translate( &outStream, NULL, NULL,
809 &outFile, imageFormat );
810 if ( status == B_OK )
812 BNodeInfo nodeInfo( &outFile );
813 if ( nodeInfo.InitCheck() == B_OK )
815 translation_format* formats;
817 status = roster->GetOutputFormats( translator,
818 (const translation_format **) &formats,
820 if ( status >= B_OK )
822 const char * mime = NULL;
823 for ( int ix = 0; ix < count; ix++ ) {
824 if ( formats[ix].type == imageFormat ) {
825 mime = formats[ix].MIME;
830 nodeInfo.SetType( mime );
834 fprintf( stderr, " failed to write bitmap: %s\n",
835 strerror( status ) );
838 fprintf( stderr, " failed to create output file: %s\n",
839 strerror( status ) );
841 outStream.DetachBitmap( &converted );
845 fprintf( stderr, " failed to find translator\n");
848 fprintf( stderr, " failed to convert colorspace: %s\n",
849 strerror( status ) );
862 /*****************************************************************************
864 *****************************************************************************/
865 VLCView::VLCView(BRect bounds)
866 : BView(bounds, "video view", B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED),
867 fLastMouseMovedTime(system_time()),
868 fCursorHidden(false),
869 fCursorInside(false),
870 fIgnoreDoubleClick(false)
872 SetViewColor(B_TRANSPARENT_32_BIT);
875 /*****************************************************************************
877 *****************************************************************************/
882 /*****************************************************************************
883 * VLCVIew::AttachedToWindow
884 *****************************************************************************/
886 VLCView::AttachedToWindow()
888 // in order to get keyboard events
890 // periodically check if we want to hide the pointer
891 Window()->SetPulseRate(1000000);
894 /*****************************************************************************
896 *****************************************************************************/
898 VLCView::MouseDown(BPoint where)
900 VideoWindow* videoWindow = dynamic_cast<VideoWindow*>(Window());
901 BMessage* msg = Window()->CurrentMessage();
904 msg->FindInt32("clicks", &clicks);
905 msg->FindInt32("buttons", (int32*)&buttons);
909 if (buttons & B_PRIMARY_MOUSE_BUTTON)
911 if (clicks == 2 && !fIgnoreDoubleClick)
914 videoWindow->ToggleInterfaceShowing();
915 fIgnoreDoubleClick = false;
919 if (buttons & B_SECONDARY_MOUSE_BUTTON)
921 // clicks will be 2 next time (if interval short enough)
922 // even if the first click and the second
923 // have not been made with the same mouse button
924 fIgnoreDoubleClick = true;
926 BPopUpMenu *menu = new BPopUpMenu("context menu");
927 menu->SetRadioMode(false);
929 BMenuItem *halfItem = new BMenuItem("50%", new BMessage(RESIZE_50));
930 menu->AddItem(halfItem);
932 BMenuItem *origItem = new BMenuItem("100%", new BMessage(RESIZE_100));
933 menu->AddItem(origItem);
935 BMenuItem *doubleItem = new BMenuItem("200%", new BMessage(RESIZE_200));
936 menu->AddItem(doubleItem);
938 BMenuItem *zoomItem = new BMenuItem("Fullscreen", new BMessage(TOGGLE_FULL_SCREEN));
939 zoomItem->SetMarked(videoWindow->is_zoomed);
940 menu->AddItem(zoomItem);
942 menu->AddSeparatorItem();
945 BMenuItem *vsyncItem = new BMenuItem("Vertical Sync", new BMessage(VERT_SYNC));
946 vsyncItem->SetMarked(videoWindow->vsync);
947 menu->AddItem(vsyncItem);
948 // Correct Aspect Ratio
949 BMenuItem *aspectItem = new BMenuItem("Correct Aspect Ratio", new BMessage(ASPECT_CORRECT));
950 aspectItem->SetMarked(videoWindow->CorrectAspectRatio());
951 menu->AddItem(aspectItem);
953 menu->AddSeparatorItem();
956 /* BMessage *winNormFeel = new BMessage(WINDOW_FEEL);
957 winNormFeel->AddInt32("WinFeel", (int32)B_NORMAL_WINDOW_FEEL);
958 BMenuItem *normWindItem = new BMenuItem("Normal Window", winNormFeel);
959 normWindItem->SetMarked(videoWindow->Feel() == B_NORMAL_WINDOW_FEEL);
960 menu->AddItem(normWindItem);
962 BMessage *winFloatFeel = new BMessage(WINDOW_FEEL);
963 winFloatFeel->AddInt32("WinFeel", (int32)B_FLOATING_APP_WINDOW_FEEL);
964 BMenuItem *onTopWindItem = new BMenuItem("App Top", winFloatFeel);
965 onTopWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_APP_WINDOW_FEEL);
966 menu->AddItem(onTopWindItem);
968 BMessage *winAllFeel = new BMessage(WINDOW_FEEL);
969 winAllFeel->AddInt32("WinFeel", (int32)B_FLOATING_ALL_WINDOW_FEEL);
970 BMenuItem *allSpacesWindItem = new BMenuItem("On Top All Workspaces", winAllFeel);
971 allSpacesWindItem->SetMarked(videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL);
972 menu->AddItem(allSpacesWindItem);*/
974 BMessage *windowFeelMsg = new BMessage( WINDOW_FEEL );
975 bool onTop = videoWindow->Feel() == B_FLOATING_ALL_WINDOW_FEEL;
976 window_feel feel = onTop ? B_NORMAL_WINDOW_FEEL : B_FLOATING_ALL_WINDOW_FEEL;
977 windowFeelMsg->AddInt32( "WinFeel", (int32)feel );
978 BMenuItem *windowFeelItem = new BMenuItem( "Stay On Top", windowFeelMsg );
979 windowFeelItem->SetMarked( onTop );
980 menu->AddItem( windowFeelItem );
982 menu->AddSeparatorItem();
984 BMenuItem* screenShotItem = new BMenuItem( "Take Screen Shot",
985 new BMessage( SCREEN_SHOT ) );
986 menu->AddItem( screenShotItem );
988 menu->SetTargetForItems( this );
989 ConvertToScreen( &where );
990 menu->Go( where, true, false, true );
994 fLastMouseMovedTime = system_time();
995 fCursorHidden = false;
998 /*****************************************************************************
999 * VLCVIew::MouseMoved
1000 *****************************************************************************/
1002 VLCView::MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage)
1004 fLastMouseMovedTime = system_time();
1005 fCursorHidden = false;
1006 fCursorInside = (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW);
1009 /*****************************************************************************
1011 *****************************************************************************/
1015 // We are getting the pulse messages no matter if the mouse is over
1016 // this view. If we are in full screen mode, we want to hide the cursor
1017 // even if it is not.
1021 && system_time() - fLastMouseMovedTime > MOUSE_IDLE_TIMEOUT)
1023 be_app->ObscureCursor();
1024 fCursorHidden = true;
1025 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1026 // hide the interface window as well if full screen
1027 if (videoWindow && videoWindow->is_zoomed)
1028 videoWindow->SetInterfaceShowing(false);
1033 /*****************************************************************************
1035 *****************************************************************************/
1037 VLCView::KeyDown(const char *bytes, int32 numBytes)
1039 VideoWindow *videoWindow = dynamic_cast<VideoWindow*>(Window());
1040 BWindow* interfaceWindow = get_interface_window();
1041 if (videoWindow && numBytes > 0) {
1042 uint32 mods = modifiers();
1045 // toggle window and full screen mode
1046 // not passing on the tab key to the default KeyDown()
1047 // implementation also avoids loosing the keyboard focus
1048 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1051 // go back to window mode
1052 if (videoWindow->is_zoomed)
1053 videoWindow->PostMessage(TOGGLE_FULL_SCREEN);
1057 if (interfaceWindow)
1058 interfaceWindow->PostMessage(PAUSE_PLAYBACK);
1061 if (interfaceWindow)
1063 if (mods & B_SHIFT_KEY)
1065 interfaceWindow->PostMessage(NEXT_TITLE);
1068 interfaceWindow->PostMessage(NEXT_CHAPTER);
1072 if (interfaceWindow)
1074 if (mods & B_SHIFT_KEY)
1076 interfaceWindow->PostMessage(PREV_TITLE);
1079 interfaceWindow->PostMessage(PREV_CHAPTER);
1083 // previous file in playlist
1084 interfaceWindow->PostMessage(PREV_FILE);
1087 // next file in playlist
1088 interfaceWindow->PostMessage(NEXT_FILE);
1093 videoWindow->PostMessage( SCREEN_SHOT );
1096 BView::KeyDown(bytes, numBytes);
1102 /*****************************************************************************
1104 *****************************************************************************/
1106 VLCView::Draw(BRect updateRect)
1108 VideoWindow* window = dynamic_cast<VideoWindow*>( Window() );
1109 if ( window && window->mode == BITMAP )
1110 FillRect( updateRect );
1113 /*****************************************************************************
1115 *****************************************************************************/
1116 static int Init ( vout_thread_t * );
1117 static void End ( vout_thread_t * );
1118 // static int Manage ( vout_thread_t * );
1119 static void Display ( vout_thread_t *, picture_t * );
1121 static int BeosOpenDisplay ( vout_thread_t *p_vout );
1122 static void BeosCloseDisplay( vout_thread_t *p_vout );
1124 /*****************************************************************************
1125 * OpenVideo: allocates BeOS video thread output method
1126 *****************************************************************************
1127 * This function allocates and initializes a BeOS vout method.
1128 *****************************************************************************/
1129 int E_(OpenVideo) ( vlc_object_t *p_this )
1131 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1133 /* Allocate structure */
1134 p_vout->p_sys = (vout_sys_t*) malloc( sizeof( vout_sys_t ) );
1135 if( p_vout->p_sys == NULL )
1137 msg_Err( p_vout, "out of memory" );
1140 p_vout->p_sys->i_width = p_vout->render.i_width;
1141 p_vout->p_sys->i_height = p_vout->render.i_height;
1142 p_vout->p_sys->source_chroma = p_vout->render.i_chroma;
1144 p_vout->pf_init = Init;
1145 p_vout->pf_end = End;
1146 p_vout->pf_manage = NULL;
1147 p_vout->pf_render = NULL;
1148 p_vout->pf_display = Display;
1153 /*****************************************************************************
1154 * Init: initialize BeOS video thread output method
1155 *****************************************************************************/
1156 int Init( vout_thread_t *p_vout )
1161 I_OUTPUTPICTURES = 0;
1163 /* Open and initialize device */
1164 if( BeosOpenDisplay( p_vout ) )
1166 msg_Err(p_vout, "vout error: can't open display");
1169 p_vout->output.i_width = p_vout->render.i_width;
1170 p_vout->output.i_height = p_vout->render.i_height;
1172 /* Assume we have square pixels */
1173 p_vout->output.i_aspect = p_vout->p_sys->i_width
1174 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
1175 p_vout->output.i_chroma = colspace[p_vout->p_sys->p_window->colspace_index].chroma;
1176 p_vout->p_sys->i_index = 0;
1178 p_vout->b_direct = 1;
1180 p_vout->output.i_rmask = 0x00ff0000;
1181 p_vout->output.i_gmask = 0x0000ff00;
1182 p_vout->output.i_bmask = 0x000000ff;
1184 for (int buffer_index = 0 ; buffer_index < 3; buffer_index++)
1187 /* Find an empty picture slot */
1188 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
1191 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
1193 p_pic = p_vout->p_picture + i_index;
1202 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[buffer_index]->Bits();
1203 p_pic->p->i_lines = p_vout->p_sys->i_height;
1205 p_pic->p->i_pixel_pitch = colspace[p_vout->p_sys->p_window->colspace_index].pixel_bytes;
1206 p_pic->i_planes = colspace[p_vout->p_sys->p_window->colspace_index].planes;
1207 p_pic->p->i_pitch = p_vout->p_sys->p_window->bitmap[buffer_index]->BytesPerRow();
1208 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch * ( p_vout->p_sys->p_window->bitmap[buffer_index]->Bounds().IntegerWidth() + 1 );
1210 p_pic->i_status = DESTROYED_PICTURE;
1211 p_pic->i_type = DIRECT_PICTURE;
1213 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
1221 /*****************************************************************************
1222 * End: terminate BeOS video thread output method
1223 *****************************************************************************/
1224 void End( vout_thread_t *p_vout )
1226 BeosCloseDisplay( p_vout );
1229 /*****************************************************************************
1230 * CloseVideo: destroy BeOS video thread output method
1231 *****************************************************************************
1232 * Terminate an output method created by DummyCreateOutputMethod
1233 *****************************************************************************/
1234 void E_(CloseVideo) ( vlc_object_t *p_this )
1236 vout_thread_t * p_vout = (vout_thread_t *)p_this;
1238 free( p_vout->p_sys );
1241 /*****************************************************************************
1242 * Display: displays previously rendered output
1243 *****************************************************************************
1244 * This function send the currently rendered image to BeOS image, waits until
1245 * it is displayed and switch the two rendering buffers, preparing next frame.
1246 *****************************************************************************/
1247 void Display( vout_thread_t *p_vout, picture_t *p_pic )
1249 VideoWindow * p_win = p_vout->p_sys->p_window;
1251 /* draw buffer if required */
1252 if (!p_win->teardownwindow)
1254 p_win->drawBuffer(p_vout->p_sys->i_index);
1257 p_vout->p_sys->i_index = ++p_vout->p_sys->i_index % 3;
1258 p_pic->p->p_pixels = (u8*)p_vout->p_sys->p_window->bitmap[p_vout->p_sys->i_index]->Bits();
1261 /* following functions are local */
1263 /*****************************************************************************
1264 * BeosOpenDisplay: open and initialize BeOS device
1265 *****************************************************************************/
1266 static int BeosOpenDisplay( vout_thread_t *p_vout )
1269 p_vout->p_sys->p_window = new VideoWindow( p_vout->p_sys->i_width - 1,
1270 p_vout->p_sys->i_height - 1,
1272 20 + p_vout->i_window_width - 1,
1273 50 + p_vout->i_window_height - 1 ),
1275 if( p_vout->p_sys->p_window == NULL )
1277 msg_Err( p_vout, "cannot allocate VideoWindow" );
1282 p_vout->p_sys->p_window->Show();
1288 /*****************************************************************************
1289 * BeosDisplay: close and reset BeOS device
1290 *****************************************************************************
1291 * Returns all resources allocated by BeosOpenDisplay and restore the original
1292 * state of the device.
1293 *****************************************************************************/
1294 static void BeosCloseDisplay( vout_thread_t *p_vout )
1296 VideoWindow * p_win = p_vout->p_sys->p_window;
1297 /* Destroy the video window */
1298 if( p_win != NULL && !p_win->teardownwindow)
1301 p_win->teardownwindow = true;