1 /* 2 * VideoView.cpp - Media Player for the Haiku Operating System 3 * 4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * version 2 as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * 19 */ 20 #include <Message.h> 21 #include <Bitmap.h> 22 #include "VideoView.h" 23 24 #include <stdio.h> 25 #include <string.h> 26 27 VideoView::VideoView(BRect frame, const char *name, uint32 resizeMask, uint32 flags) 28 : BView(frame, name, resizeMask, flags) 29 , fController(NULL) 30 , fOverlayActive(false) 31 { 32 // SetViewColor(B_TRANSPARENT_COLOR); 33 SetViewColor(127,255,127); 34 } 35 36 37 VideoView::~VideoView() 38 { 39 } 40 41 42 void 43 VideoView::AttachedToWindow() 44 { 45 } 46 47 void 48 VideoView::OverlayLockAcquire() 49 { 50 printf("VideoView::OverlayLockAcquire\n"); 51 } 52 53 54 void 55 VideoView::OverlayLockRelease() 56 { 57 printf("VideoView::OverlayLockRelease\n"); 58 // overlaybitmap->UnlockBits 59 } 60 61 62 void 63 VideoView::OverlayScreenshotPrepare() 64 { 65 printf("OverlayScreenshotPrepare enter\n"); 66 /* 67 fController->LockBitmap(); 68 if (fOverlayActive) { 69 BBitmap *bmp = fController->Bitmap(); 70 if (bmp) { 71 // Window()->UpdateIfNeeded(); 72 // Sync(); 73 BBitmap *tmp = new BBitmap(bmp->Bounds(), 0, B_RGB32); 74 // ConvertBitmap(tmp, bmp); 75 ClearViewOverlay(); 76 DrawBitmap(tmp, Bounds()); 77 delete tmp; 78 // Sync(); 79 } 80 } 81 fController->UnlockBitmap(); 82 */ 83 printf("OverlayScreenshotPrepare leave\n"); 84 } 85 86 87 void 88 VideoView::OverlayScreenshotCleanup() 89 { 90 printf("OverlayScreenshotCleanup enter\n"); 91 /* 92 snooze(50000); // give app server some time to take the screenshot 93 fController->LockBitmap(); 94 if (fOverlayActive) { 95 BBitmap *bmp = fController->Bitmap(); 96 if (bmp) { 97 DrawBitmap(bmp, Bounds()); 98 SetViewOverlay(bmp, bmp->Bounds(), Bounds(), &fOverlayKeyColor, 99 B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL); 100 Invalidate(); 101 } 102 } 103 fController->UnlockBitmap(); 104 */ 105 printf("OverlayScreenshotCleanup leave\n"); 106 } 107 108 109 void 110 VideoView::RemoveVideoDisplay() 111 { 112 printf("VideoView::RemoveVideoDisplay\n"); 113 114 if (fOverlayActive) { 115 ClearViewOverlay(); 116 fOverlayActive = false; 117 } 118 Invalidate(); 119 } 120 121 122 void 123 VideoView::RemoveOverlay() 124 { 125 printf("VideoView::RemoveOverlay\n"); 126 if (LockLooperWithTimeout(50000) == B_OK) { 127 ClearViewOverlay(); 128 fOverlayActive = false; 129 UnlockLooper(); 130 } 131 } 132 133 134 void 135 VideoView::Draw(BRect updateRect) 136 { 137 if (fOverlayActive) { 138 SetHighColor(fOverlayKeyColor); 139 FillRect(updateRect); 140 } else { 141 fController->LockBitmap(); 142 BBitmap *bmp = fController->Bitmap(); 143 if (bmp) 144 DrawBitmap(bmp, Bounds()); 145 fController->UnlockBitmap(); 146 } 147 } 148 149 150 void 151 VideoView::DrawFrame() 152 { 153 // printf("VideoView::DrawFrame\n"); 154 155 bool want_overlay = fController->IsOverlayActive(); 156 157 if (!want_overlay && fOverlayActive) { 158 if (LockLooperWithTimeout(50000) == B_OK) { 159 ClearViewOverlay(); 160 UnlockLooper(); 161 fOverlayActive = false; 162 } else { 163 printf("can't ClearViewOverlay, as LockLooperWithTimeout failed\n"); 164 } 165 } 166 if (want_overlay && !fOverlayActive) { 167 fController->LockBitmap(); 168 BBitmap *bmp = 0; // fController->Bitmap(); 169 if (bmp && LockLooperWithTimeout(50000) == B_OK) { 170 SetViewOverlay(bmp, bmp->Bounds(), Bounds(), &fOverlayKeyColor, 171 B_FOLLOW_ALL, B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL); 172 fOverlayActive = true; 173 174 Invalidate(); 175 UnlockLooper(); 176 } 177 fController->UnlockBitmap(); 178 } 179 if (!fOverlayActive) { 180 if (LockLooperWithTimeout(50000) != B_OK) 181 return; 182 Invalidate(); 183 UnlockLooper(); 184 } 185 } 186 187 188 void 189 VideoView::MessageReceived(BMessage *msg) 190 { 191 switch (msg->what) { 192 193 default: 194 BView::MessageReceived(msg); 195 } 196 } 197 198 199 bool 200 VideoView::IsOverlaySupported() 201 { 202 struct colorcombo { 203 color_space colspace; 204 const char *name; 205 } colspace[] = { 206 { B_RGB32, "B_RGB32"}, 207 { B_RGBA32, "B_RGBA32"}, 208 { B_RGB24, "B_RGB24"}, 209 { B_RGB16, "B_RGB16"}, 210 { B_RGB15, "B_RGB15"}, 211 { B_RGBA15, "B_RGBA15"}, 212 { B_RGB32_BIG, "B_RGB32_BIG"}, 213 { B_RGBA32_BIG, "B_RGBA32_BIG "}, 214 { B_RGB24_BIG, "B_RGB24_BIG "}, 215 { B_RGB16_BIG, "B_RGB16_BIG "}, 216 { B_RGB15_BIG, "B_RGB15_BIG "}, 217 { B_RGBA15_BIG, "B_RGBA15_BIG "}, 218 { B_YCbCr422, "B_YCbCr422"}, 219 { B_YCbCr411, "B_YCbCr411"}, 220 { B_YCbCr444, "B_YCbCr444"}, 221 { B_YCbCr420, "B_YCbCr420"}, 222 { B_YUV422, "B_YUV422"}, 223 { B_YUV411, "B_YUV411"}, 224 { B_YUV444, "B_YUV444"}, 225 { B_YUV420, "B_YUV420"}, 226 { B_NO_COLOR_SPACE, NULL} 227 }; 228 229 bool supported = false; 230 for (int i = 0; colspace[i].name; i++) { 231 BBitmap *test = new BBitmap(BRect(0,0,320,240), B_BITMAP_WILL_OVERLAY | B_BITMAP_RESERVE_OVERLAY_CHANNEL, colspace[i].colspace); 232 if (test->InitCheck() == B_OK) { 233 printf("Display supports %s (0x%08x) overlay\n", colspace[i].name, colspace[i].colspace); 234 supported = true; 235 } 236 delete test; 237 // if (supported) 238 // break; 239 } 240 return supported; 241 } 242 243