2 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>. All rights reserved.
4 * Distributed under the terms of the MIT License.
12 #include <MediaRoster.h>
21 VideoView::VideoView(BRect frame
, const char *name
, uint32 resizeMask
, uint32 flags
, VideoNode
*node
)
22 : BView(frame
, name
, resizeMask
, flags
)
24 , fOverlayActive(false)
26 SetViewColor(B_TRANSPARENT_COLOR
);
30 VideoView::~VideoView()
36 VideoView::AttachedToWindow()
49 VideoView::OverlayLockAcquire()
56 VideoView::OverlayLockRelease()
59 // overlaybitmap->UnlockBits
64 VideoView::OverlayScreenshotPrepare()
68 fVideoNode->LockBitmap();
70 BBitmap *bmp = fVideoNode->Bitmap();
72 // Window()->UpdateIfNeeded();
74 BBitmap *tmp = new BBitmap(bmp->Bounds(), 0, B_RGB32);
75 // ConvertBitmap(tmp, bmp);
77 DrawBitmap(tmp, Bounds());
82 fVideoNode->UnlockBitmap();
88 VideoView::OverlayScreenshotCleanup()
92 snooze(50000); // give app server some time to take the screenshot
93 fVideoNode->LockBitmap();
95 BBitmap *bmp = fVideoNode->Bitmap();
97 DrawBitmap(bmp, Bounds());
98 SetViewOverlay(bmp, bmp->Bounds(), Bounds(), &fOverlayKeyColor,
99 B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL);
103 fVideoNode->UnlockBitmap();
109 VideoView::RemoveVideoDisplay()
113 if (fOverlayActive
) {
115 fOverlayActive
= false;
122 VideoView::RemoveOverlay()
125 if (LockLooperWithTimeout(50000) == B_OK
) {
127 fOverlayActive
= false;
134 VideoView::Draw(BRect updateRect
)
136 if (fOverlayActive
) {
137 SetHighColor(fOverlayKeyColor
);
138 FillRect(updateRect
);
140 fVideoNode
->LockBitmap();
141 BBitmap
*bmp
= fVideoNode
->Bitmap();
143 SetHighColor(0, 0, 0, 0);
144 FillRect(updateRect
);
146 DrawBitmap(bmp
, Bounds());
147 fVideoNode
->UnlockBitmap();
153 VideoView::DrawFrame()
157 bool want_overlay
= fVideoNode
->IsOverlayActive();
159 if (!want_overlay
&& fOverlayActive
) {
160 if (LockLooperWithTimeout(50000) == B_OK
) {
163 fOverlayActive
= false;
165 fprintf(stderr
, "VideoView::DrawFrame: cannot ClearViewOverlay, as LockLooperWithTimeout failed\n");
169 if (want_overlay
&& !fOverlayActive
) {
170 fVideoNode
->LockBitmap();
171 BBitmap
*bmp
= fVideoNode
->Bitmap();
172 if (bmp
&& LockLooperWithTimeout(50000) == B_OK
) {
173 SetViewOverlay(bmp
, bmp
->Bounds(), Bounds(), &fOverlayKeyColor
,
174 B_FOLLOW_ALL
, B_OVERLAY_FILTER_HORIZONTAL
| B_OVERLAY_FILTER_VERTICAL
);
175 fOverlayActive
= true;
180 fVideoNode
->UnlockBitmap();
182 if (!fOverlayActive
) {
183 if (LockLooperWithTimeout(50000) != B_OK
)
192 VideoView::MessageReceived(BMessage
*msg
)
197 BView::MessageReceived(msg
);
203 VideoView::IsOverlaySupported()
206 color_space colspace
;
209 { B_RGB32
, "B_RGB32"},
210 { B_RGBA32
, "B_RGBA32"},
211 { B_RGB24
, "B_RGB24"},
212 { B_RGB16
, "B_RGB16"},
213 { B_RGB15
, "B_RGB15"},
214 { B_RGBA15
, "B_RGBA15"},
215 { B_RGB32_BIG
, "B_RGB32_BIG"},
216 { B_RGBA32_BIG
, "B_RGBA32_BIG "},
217 { B_RGB24_BIG
, "B_RGB24_BIG "},
218 { B_RGB16_BIG
, "B_RGB16_BIG "},
219 { B_RGB15_BIG
, "B_RGB15_BIG "},
220 { B_RGBA15_BIG
, "B_RGBA15_BIG "},
221 { B_YCbCr422
, "B_YCbCr422"},
222 { B_YCbCr411
, "B_YCbCr411"},
223 { B_YCbCr444
, "B_YCbCr444"},
224 { B_YCbCr420
, "B_YCbCr420"},
225 { B_YUV422
, "B_YUV422"},
226 { B_YUV411
, "B_YUV411"},
227 { B_YUV444
, "B_YUV444"},
228 { B_YUV420
, "B_YUV420"},
229 { B_NO_COLOR_SPACE
, NULL
}
232 bool supported
= false;
233 for (int i
= 0; colspace
[i
].name
; i
++) {
234 BBitmap
*test
= new BBitmap(BRect(0,0,320,240), B_BITMAP_WILL_OVERLAY
| B_BITMAP_RESERVE_OVERLAY_CHANNEL
, colspace
[i
].colspace
);
235 if (test
->InitCheck() == B_OK
) {
236 printf("Display supports %s (0x%08x) overlay\n", colspace
[i
].name
, colspace
[i
].colspace
);