Changeset 81537 in vbox for trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp
- Timestamp:
- Oct 25, 2019 11:46:30 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp
r77370 r81537 113 113 bool fUpdateImage) 114 114 { 115 int rc;116 115 LogFlow(("VBoxSDLFB::VBoxSDLFB\n")); 117 116 … … 119 118 mfUpdateImage = fUpdateImage; 120 119 mScreen = NULL; 121 #ifdef VBOX_WITH_SDL13 122 mWindow = 0; 123 mTexture = 0; 120 #ifdef VBOX_WITH_SDL2 121 mpWindow = NULL; 122 mpTexture = NULL; 123 mpRenderer = NULL; 124 124 #endif 125 125 mSurfVRAM = NULL; … … 150 150 mfUpdates = false; 151 151 152 rc = RTCritSectInit(&mUpdateLock);152 int rc = RTCritSectInit(&mUpdateLock); 153 153 AssertMsg(rc == VINF_SUCCESS, ("Error from RTCritSectInit!\n")); 154 154 … … 161 161 #endif 162 162 163 return 0; 163 #ifdef VBOX_WITH_SDL2 164 rc = SDL_GetRendererInfo(mpRenderer, &mRenderInfo); 165 if (RT_SUCCESS(rc)) 166 { 167 if (fShowSDLConfig) 168 RTPrintf("Render info:\n" 169 " Name: %s\n" 170 " Render flags: 0x%x\n" 171 " SDL video driver: %s\n", 172 mRenderInfo.name, 173 mRenderInfo.flags, 174 RTEnvGet("SDL_VIDEODRIVER")); 175 } 176 #endif 177 178 return rc; 164 179 } 165 180 … … 184 199 } 185 200 201 /* static */ 186 202 bool VBoxSDLFB::init(bool fShowSDLConfig) 187 203 { … … 195 211 if (!RTEnvExist("SDL_VIDEODRIVER")) 196 212 { 197 _putenv("SDL_VIDEODRIVER=directx"); 198 // _putenv("SDL_VIDEODRIVER=windib"); 213 # ifndef VBOX_WITH_SDL2 214 /* Always select the windib driver by default, as the directx one is known to be broken on newer Windows OSes. */ 215 RTEnvSet("SDL_VIDEODRIVER", "windib"); 216 # else 217 RTEnvSet("SDL_VIDEODRIVER", "directx"); 218 # endif 199 219 } 200 220 #endif … … 204 224 RTEnvSet("SDL_VIDEO_X11_DGAMOUSE", "0"); 205 225 #endif 226 206 227 int rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); 207 228 if (rc != 0) … … 212 233 gfSdlInitialized = true; 213 234 235 #ifdef VBOX_WITH_SDL2 236 RT_NOREF(fShowSDLConfig); 237 #else 214 238 const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); 215 Assert (videoInfo);239 AssertPtr(videoInfo); 216 240 if (videoInfo) 217 241 { … … 244 268 RTEnvGet("SDL_VIDEODRIVER")); 245 269 } 246 247 if (12320 == g_cbIco64x01) 248 { 249 250 251 252 253 254 255 256 } 270 #endif /* !VBOX_WITH_SDL2 */ 271 272 #ifndef VBOX_WITH_SDL2 273 gWMIcon = SDL_AllocSurface(SDL_SWSURFACE, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0); 274 /** @todo make it as simple as possible. No PNM interpreter here... */ 275 if (gWMIcon) 276 { 277 memcpy(gWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32); 278 SDL_WM_SetIcon(gWMIcon, NULL); 279 } 280 #endif 257 281 258 282 return true; … … 270 294 AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n")); 271 295 SDL_QuitSubSystem(SDL_INIT_VIDEO); 296 297 #ifndef VBOX_WITH_SDL2 272 298 if (gWMIcon) 273 299 { … … 275 301 gWMIcon = NULL; 276 302 } 303 #endif 277 304 } 278 305 } … … 581 608 /* nope, we don't want that (but still don't freak out if it is set) */ 582 609 #ifdef DEBUG 583 printf("VBoxSDL::VideoModeSupported: we refused mode %dx%dx%d\n", width, height, bpp);610 RTPrintf("VBoxSDL::VideoModeSupported: we refused mode %dx%dx%d\n", width, height, bpp); 584 611 #endif 585 612 *supported = false; … … 770 797 { 771 798 LogFlow(("VBoxSDL:resizeSDL\n")); 799 800 #ifdef VBOX_WITH_SDL2 801 const int cDisplays = SDL_GetNumVideoDisplays(); 802 if (cDisplays > 0) 803 { 804 for (int d = 0; d < cDisplays; d++) 805 { 806 const int cDisplayModes = SDL_GetNumDisplayModes(d); 807 for (int m = 0; m < cDisplayModes; m++) 808 { 809 SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; 810 if (SDL_GetDisplayMode(d, m, &mode) != 0) 811 { 812 RTPrintf("Display #%d, mode %d:\t\t%i bpp\t%i x %i", 813 SDL_BITSPERPIXEL(mode.format), mode.w, mode.h); 814 } 815 816 if (m == 0) 817 { 818 /* 819 * according to the SDL documentation, the API guarantees that 820 * the modes are sorted from larger to smaller, so we just 821 * take the first entry as the maximum. 822 */ 823 mMaxScreenWidth = mode.w; 824 mMaxScreenHeight = mode.h; 825 } 826 827 /* Keep going. */ 828 } 829 } 830 } 831 else 832 AssertFailed(); /** @todo */ 833 #else 772 834 773 835 /* … … 814 876 mMaxScreenHeight = ~(uint32_t)0; 815 877 } 878 #endif /* VBOX_WITH_SDL2 */ 816 879 817 880 uint32_t newWidth; … … 841 904 mTopOffset = 0; 842 905 843 #if defined(VBOX_WITH_SDL13)906 #ifdef VBOX_WITH_SDL2 844 907 int sdlWindowFlags = SDL_WINDOW_SHOWN; 845 908 if (mfResizable) 846 909 sdlWindowFlags |= SDL_WINDOW_RESIZABLE; 847 if (!m Window)910 if (!mpWindow) 848 911 { 849 912 SDL_DisplayMode desktop_mode; … … 851 914 int y = 40 + mScreenId * 15; 852 915 853 SDL_GetDesktopDisplayMode( &desktop_mode);916 SDL_GetDesktopDisplayMode(mScreenId, &desktop_mode); 854 917 /* create new window */ 855 918 856 919 char szTitle[64]; 857 920 RTStrPrintf(szTitle, sizeof(szTitle), "SDL window %d", mScreenId); 858 m Window = SDL_CreateWindow(szTitle, x, y,921 mpWindow = SDL_CreateWindow(szTitle, x, y, 859 922 newWidth, newHeight, sdlWindowFlags); 860 if (SDL_CreateRenderer(mWindow, -1, 861 SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD) < 0) 923 mpRenderer = SDL_CreateRenderer(mpWindow, -1, 0 /* SDL_RendererFlags */); 924 if (mpRenderer) 925 { 926 SDL_GetRendererInfo(mpRenderer, &mRenderInfo); 927 928 mpTexture = SDL_CreateTexture(mpRenderer, desktop_mode.format, 929 SDL_TEXTUREACCESS_STREAMING, newWidth, newHeight); 930 if (!mpTexture) 931 AssertReleaseFailed(); 932 } 933 else 862 934 AssertReleaseFailed(); 863 935 864 SDL_GetRendererInfo(&mRenderInfo); 865 866 mTexture = SDL_CreateTexture(desktop_mode.format, 867 SDL_TEXTUREACCESS_STREAMING, newWidth, newHeight); 868 if (!mTexture) 869 AssertReleaseFailed(); 936 if (12320 == g_cbIco64x01) 937 { 938 gWMIcon = SDL_CreateRGBSurface(0 /* Flags, must be 0 */, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0); 939 /** @todo make it as simple as possible. No PNM interpreter here... */ 940 if (gWMIcon) 941 { 942 memcpy(gWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32); 943 SDL_SetWindowIcon(mpWindow, gWMIcon); 944 } 945 } 870 946 } 871 947 else … … 876 952 877 953 /* resize current window */ 878 SDL_GetWindowSize(m Window, &w, &h);954 SDL_GetWindowSize(mpWindow, &w, &h); 879 955 880 956 if (w != (int)newWidth || h != (int)newHeight) 881 SDL_SetWindowSize(mWindow, newWidth, newHeight); 882 883 SDL_QueryTexture(mTexture, &format, &access, &w, &h); 884 SDL_SelectRenderer(mWindow); 885 SDL_DestroyTexture(mTexture); 886 mTexture = SDL_CreateTexture(format, access, newWidth, newHeight); 887 if (!mTexture) 957 SDL_SetWindowSize(mpWindow, newWidth, newHeight); 958 959 SDL_QueryTexture(mpTexture, &format, &access, &w, &h); 960 SDL_DestroyTexture(mpTexture); 961 mpTexture = SDL_CreateTexture(mpRenderer, format, access, newWidth, newHeight); 962 if (!mpTexture) 888 963 AssertReleaseFailed(); 889 964 } … … 895 970 uint32_t format; 896 971 897 if (SDL_QueryTexture(m Texture, &format, NULL, &w, &h) < 0)972 if (SDL_QueryTexture(mpTexture, &format, NULL, &w, &h) < 0) 898 973 AssertReleaseFailed(); 899 974 … … 901 976 AssertReleaseFailed(); 902 977 903 if (SDL_ QueryTexturePixels(mTexture, &pixels, &pitch) == 0)978 if (SDL_LockTexture(mpTexture, NULL /* SDL_Rect */, &pixels, &pitch) == 0) 904 979 { 905 980 mScreen = SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, 906 981 Rmask, Gmask, Bmask, Amask); 982 SDL_UnlockTexture(mpTexture); /** @BUGBUG See: https://bugzilla.libsdl.org/show_bug.cgi?id=1586 */ 907 983 } 908 984 else … … 933 1009 SDL_VERSION(&info.version); 934 1010 if (SDL_GetWMInfo(&info)) 935 mWinId = (LONG64) info.info.x11.wm window;1011 mWinId = (LONG64) info.info.x11.wmpWindow; 936 1012 # elif defined(RT_OS_DARWIN) 937 1013 mWinId = (intptr_t)VBoxSDLGetDarwinWindowId(); … … 939 1015 /* XXX ignore this for other architectures */ 940 1016 # endif 941 #endif 1017 #endif /* VBOX_WITH_SDL2 */ 942 1018 #ifdef VBOX_SECURELABEL 943 1019 /* … … 971 1047 mCenterYOffset = (mFixedSDLHeight - (mGuestYRes + mLabelHeight)) / 2; 972 1048 } 973 #endif 1049 #endif /* VBOX_SECURELABEL */ 1050 974 1051 AssertMsg(mScreen, ("Error: SDL_SetVideoMode failed!\n")); 975 1052 if (mScreen) … … 980 1057 #endif 981 1058 if (mfShowSDLConfig) 982 RTPrintf("Resized to %dx%d, screen surface type: %s\n", mScreen->w, mScreen->h, 983 ((mScreen->flags & SDL_HWSURFACE) == 0) ? "software" : "hardware"); 1059 RTPrintf("Resized to %dx%d\n", mScreen->w, mScreen->h); 984 1060 } 985 1061 } … … 1079 1155 SDL_BlitSurface(mSurfVRAM, &srcRect, mScreen, &dstRect); 1080 1156 /* hardware surfaces don't need update notifications */ 1081 #if defined(VBOX_WITH_SDL 13)1157 #if defined(VBOX_WITH_SDL2) 1082 1158 AssertRelease(mScreen->flags & SDL_PREALLOC); 1083 SDL_SelectRenderer(mWindow); 1084 SDL_DirtyTexture(mTexture, 1, &dstRect); 1085 AssertRelease(mRenderInfo.flags & SDL_RENDERER_PRESENTCOPY); 1086 SDL_RenderCopy(mTexture, &dstRect, &dstRect); 1087 SDL_RenderPresent(); 1159 /** @todo Do we need to update the dirty rect for the texture for SDL2 here as well? */ 1160 SDL_RenderClear(mpRenderer); 1161 SDL_RenderCopy(mpRenderer, mpTexture, &dstRect, &dstRect); 1162 SDL_RenderPresent(mpRenderer); 1088 1163 #else 1089 1164 if ((mScreen->flags & SDL_HWSURFACE) == 0) … … 1131 1206 void VBoxSDLFB::getFullscreenGeometry(uint32_t *width, uint32_t *height) 1132 1207 { 1208 #ifndef VBOX_WITH_SDL2 1133 1209 SDL_Rect **modes; 1134 1210 … … 1159 1235 } 1160 1236 } 1161 } 1237 #else 1238 SDL_DisplayMode dm; 1239 int rc = SDL_GetDesktopDisplayMode(0, &dm); /** @BUGBUG Handle multi monitor setups! */ 1240 if (rc == 0) 1241 { 1242 *width = dm.w; 1243 *height = dm.w; 1244 } 1245 #endif 1246 } 1247 1248 #ifdef VBOX_WITH_SDL2 1249 int VBoxSDLFB::setWindowTitle(const char *pcszTitle) 1250 { 1251 SDL_SetWindowTitle(mpWindow, pcszTitle); 1252 1253 return VINF_SUCCESS; 1254 } 1255 #endif 1162 1256 1163 1257 #ifdef VBOX_SECURELABEL … … 1302 1396 HRESULT VBoxSDLFBOverlay::init() 1303 1397 { 1304 mBlendedBits = SDL_CreateRGBSurface(SDL_ANYFORMAT, mOverlayWidth, mOverlayHeight, 32, 1398 #ifndef VBOX_WITH_SDL2 1399 Uint32 fFlags = SDL_ANYFORMAT; 1400 #else 1401 Uint32 fFlags = 0; 1402 #endif 1403 1404 mBlendedBits = SDL_CreateRGBSurface(fFlags, mOverlayWidth, mOverlayHeight, 32, 1305 1405 0x00ff0000, 0x0000ff00, 0x000000ff, 0); 1306 1406 AssertMsgReturn(mBlendedBits != NULL, ("Failed to create an SDL surface\n"), 1307 1407 E_OUTOFMEMORY); 1308 mOverlayBits = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, mOverlayWidth, 1408 1409 #ifndef VBOX_WITH_SDL2 1410 fFlags = SDL_SWSURFACE | SDL_SRCALPHA, mOverlayWidth; 1411 #else 1412 fFlags = 0; 1413 #endif 1414 1415 mOverlayBits = SDL_CreateRGBSurface(fFlags, 1309 1416 mOverlayHeight, 32, 0x00ff0000, 0x0000ff00, 1310 0x000000ff, 0xff000000 );1417 0x000000ff, 0xff000000, 0); 1311 1418 AssertMsgReturn(mOverlayBits != NULL, ("Failed to create an SDL surface\n"), 1312 1419 E_OUTOFMEMORY); … … 1617 1724 mOverlayHeight = h; 1618 1725 SDL_FreeSurface(mOverlayBits); 1619 mBlendedBits = SDL_CreateRGBSurface(SDL_ANYFORMAT, mOverlayWidth, mOverlayHeight, 32, 1726 1727 #ifndef VBOX_WITH_SDL2 1728 Uint32 fFlags = SDL_ANYFORMAT; 1729 #else 1730 Uint32 fFlags = 0; 1731 #endif 1732 1733 mBlendedBits = SDL_CreateRGBSurface(fFlags, mOverlayWidth, mOverlayHeight, 32, 1620 1734 0x00ff0000, 0x0000ff00, 0x000000ff, 0); 1621 1735 AssertMsgReturn(mBlendedBits != NULL, ("Failed to create an SDL surface\n"), 1622 1736 E_OUTOFMEMORY); 1623 mOverlayBits = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, mOverlayWidth, 1737 1738 #ifndef VBOX_WITH_SDL2 1739 fFlags = SDL_SWSURFACE | SDL_SRCALPHA; 1740 #else 1741 fFlags = 0; 1742 #endif 1743 1744 mOverlayBits = SDL_CreateRGBSurface(fFlags, mOverlayWidth, 1624 1745 mOverlayHeight, 32, 0x00ff0000, 0x0000ff00, 1625 1746 0x000000ff, 0xff000000);
Note:
See TracChangeset
for help on using the changeset viewer.