Changeset 20433 in vbox for trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp
- Timestamp:
- Jun 9, 2009 12:40:36 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 48381
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp
r19844 r20433 66 66 } 67 67 #endif /* VBOX_SECURELABEL */ 68 69 static SDL_Surface *gWMIcon; /**< the application icon */ 70 static RTNATIVETHREAD gSdlNativeThread; /**< the SDL thread */ 68 71 69 72 // … … 83 86 * @param iFixedHeight fixed SDL height (-1 means not set) 84 87 */ 85 VBoxSDLFB::VBoxSDLFB(bool fFullscreen, bool fResizable, bool fShowSDLConfig, 88 VBoxSDLFB::VBoxSDLFB(uint32_t uScreenId, 89 bool fFullscreen, bool fResizable, bool fShowSDLConfig, 86 90 bool fKeepHostRes, uint32_t u32FixedWidth, 87 91 uint32_t u32FixedHeight, uint32_t u32FixedBPP) … … 94 98 #endif 95 99 100 mScreenId = uScreenId; 96 101 mScreen = NULL; 102 #ifdef VBOX_WITH_SDL13 103 mWindow = 0; 104 mTexture = 0; 105 #endif 97 106 mSurfVRAM = NULL; 98 107 mfInitialized = false; … … 105 114 mFixedSDLHeight = u32FixedHeight; 106 115 mFixedSDLBPP = u32FixedBPP; 107 mDefaultSDLBPP = 32;108 116 mCenterXOffset = 0; 109 117 mCenterYOffset = 0; … … 122 130 mLabelOffs = 0; 123 131 #endif 124 mWMIcon = NULL;125 126 /* memorize the thread that inited us, that's the SDL thread */127 mSdlNativeThread = RTThreadNativeSelf();128 132 129 133 rc = RTCritSectInit(&mUpdateLock); 130 134 AssertMsg(rc == VINF_SUCCESS, ("Error from RTCritSectInit!\n")); 135 136 resizeGuest(); 137 Assert(mScreen); 138 mfInitialized = true; 139 } 140 141 VBoxSDLFB::~VBoxSDLFB() 142 { 143 LogFlow(("VBoxSDLFB::~VBoxSDLFB\n")); 144 if (mSurfVRAM) 145 { 146 SDL_FreeSurface(mSurfVRAM); 147 mSurfVRAM = NULL; 148 } 149 mScreen = NULL; 150 151 #ifdef VBOX_SECURELABEL 152 if (mLabelFont) 153 pTTF_CloseFont(mLabelFont); 154 if (pTTF_Quit) 155 pTTF_Quit(); 156 #endif 157 158 RTCritSectDelete(&mUpdateLock); 159 } 160 161 void VBoxSDLFB::init(bool fShowSDLConfig) 162 { 163 LogFlow(("VBoxSDLFB::init\n")); 164 165 /* memorize the thread that inited us, that's the SDL thread */ 166 gSdlNativeThread = RTThreadNativeSelf(); 131 167 132 168 #ifdef RT_OS_WINDOWS … … 143 179 RTEnvSet("SDL_VIDEO_X11_DGAMOUSE", "0"); 144 180 #endif 145 rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);181 int rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); 146 182 if (rc != 0) 147 183 { … … 154 190 if (videoInfo) 155 191 { 156 switch (videoInfo->vfmt->BitsPerPixel)157 {158 case 16: mDefaultSDLBPP = 16; break;159 case 24: mDefaultSDLBPP = 24; break;160 default:161 case 32: mDefaultSDLBPP = 32; break;162 }163 164 192 /* output what SDL is capable of */ 165 if ( mfShowSDLConfig)193 if (fShowSDLConfig) 166 194 RTPrintf("SDL capabilities:\n" 167 195 " Hardware surface support: %s\n" … … 193 221 if (12320 == g_cbIco64x01) 194 222 { 195 mWMIcon = SDL_AllocSurface(SDL_SWSURFACE, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0);223 gWMIcon = SDL_AllocSurface(SDL_SWSURFACE, 64, 64, 24, 0xff, 0xff00, 0xff0000, 0); 196 224 /** @todo make it as simple as possible. No PNM interpreter here... */ 197 if ( mWMIcon)225 if (gWMIcon) 198 226 { 199 memcpy( mWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32);200 SDL_WM_SetIcon( mWMIcon, NULL);227 memcpy(gWMIcon->pixels, g_abIco64x01+32, g_cbIco64x01-32); 228 SDL_WM_SetIcon(gWMIcon, NULL); 201 229 } 202 230 } 203 204 resizeGuest(); 205 Assert(mScreen); 206 mfInitialized = true; 207 } 208 209 VBoxSDLFB::~VBoxSDLFB() 210 { 211 LogFlow(("VBoxSDLFB::~VBoxSDLFB\n")); 212 RTCritSectDelete(&mUpdateLock); 213 } 214 231 } 232 233 /** 234 * Terminate SDL 235 * 236 * @remarks must be called from the SDL thread! 237 */ 238 void VBoxSDLFB::uninit() 239 { 240 AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n")); 241 SDL_QuitSubSystem(SDL_INIT_VIDEO); 242 if (gWMIcon) 243 { 244 SDL_FreeSurface(gWMIcon); 245 gWMIcon = NULL; 246 } 247 } 215 248 216 249 /** … … 280 313 return E_INVALIDARG; 281 314 282 if (mSurfVRAM) 283 { 284 *address = (BYTE *) mSurfVRAM->pixels; 285 } 286 else 315 if (!mSurfVRAM) 287 316 { 288 317 /* That's actually rather bad. */ … … 290 319 return E_FAIL; 291 320 } 321 322 *address = (BYTE *) mSurfVRAM->pixels; 292 323 LogFlow(("VBoxSDL::GetAddress returning %p\n", *address)); 293 324 return S_OK; … … 425 456 SDL_Event event; 426 457 event.type = SDL_USEREVENT; 458 event.user.code = mScreenId; 427 459 event.user.type = SDL_USER_EVENT_UPDATERECT; 428 460 // 16 bit is enough for coordinates … … 502 534 event.type = SDL_USEREVENT; 503 535 event.user.type = SDL_USER_EVENT_RESIZE; 536 event.user.code = mScreenId; 504 537 505 538 /* Try multiple times if necessary */ … … 593 626 { 594 627 LogFlowFunc (("mGuestXRes: %d, mGuestYRes: %d\n", mGuestXRes, mGuestYRes)); 595 AssertMsg( mSdlNativeThread == RTThreadNativeSelf(),628 AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), 596 629 ("Wrong thread! SDL is not threadsafe!\n")); 597 630 … … 643 676 if (mUsesGuestVRAM) 644 677 { 645 646 678 /* Create a source surface from guest VRAM. */ 647 679 mSurfVRAM = SDL_CreateRGBSurfaceFrom(mPtrVRAM, mGuestXRes, mGuestYRes, mBitsPerPixel, 648 680 mBytesPerLine, Rmask, Gmask, Bmask, Amask); 681 LogRel(("mSurfVRAM from guest %d x %d\n", mGuestXRes, mGuestYRes)); 649 682 } 650 683 else … … 653 686 mSurfVRAM = SDL_CreateRGBSurface(SDL_SWSURFACE, mGuestXRes, mGuestYRes, mBitsPerPixel, 654 687 Rmask, Gmask, Bmask, Amask); 688 LogRel(("mSurfVRAM from SDL %d x %d\n", mGuestXRes, mGuestYRes)); 655 689 } 656 690 LogFlow(("VBoxSDL:: created VRAM surface %p\n", mSurfVRAM)); … … 751 785 mTopOffset = 0; 752 786 787 #if defined(VBOX_WITH_SDL13) 788 int sdlWindowFlags = SDL_WINDOW_SHOWN; 789 if (mfResizable) 790 sdlWindowFlags |= SDL_WINDOW_RESIZABLE; 791 if (!mWindow) 792 { 793 SDL_DisplayMode desktop_mode; 794 int x = 40 + mScreenId * 20; 795 int y = 40 + mScreenId * 15; 796 797 SDL_GetDesktopDisplayMode(&desktop_mode); 798 /* create new window */ 799 800 char szTitle[64]; 801 RTStrPrintf(szTitle, sizeof(szTitle), "SDL window %d", mScreenId); 802 mWindow = SDL_CreateWindow(szTitle, x, y, 803 newWidth, newHeight, sdlWindowFlags); 804 if (SDL_CreateRenderer(mWindow, -1, 805 SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD) < 0) 806 AssertReleaseFailed(); 807 808 SDL_GetRendererInfo(&mRenderInfo); 809 810 mTexture = SDL_CreateTexture(desktop_mode.format, 811 SDL_TEXTUREACCESS_STREAMING, newWidth, newHeight); 812 if (!mTexture) 813 AssertReleaseFailed(); 814 } 815 else 816 { 817 int w, h; 818 uint32_t format; 819 int access; 820 821 /* resize current window */ 822 SDL_GetWindowSize(mWindow, &w, &h); 823 824 if (w != (int)newWidth || h != (int)newHeight) 825 SDL_SetWindowSize(mWindow, newWidth, newHeight); 826 827 SDL_QueryTexture(mTexture, &format, &access, &w, &h); 828 SDL_SelectRenderer(mWindow); 829 SDL_DestroyTexture(mTexture); 830 mTexture = SDL_CreateTexture(format, access, newWidth, newHeight); 831 if (!mTexture) 832 AssertReleaseFailed(); 833 } 834 835 void *pixels; 836 int pitch; 837 int w, h, bpp; 838 uint32_t Rmask, Gmask, Bmask, Amask; 839 uint32_t format; 840 841 if (SDL_QueryTexture(mTexture, &format, NULL, &w, &h) < 0) 842 AssertReleaseFailed(); 843 844 if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) 845 AssertReleaseFailed(); 846 847 if (SDL_QueryTexturePixels(mTexture, &pixels, &pitch) == 0) 848 { 849 mScreen = SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, 850 Rmask, Gmask, Bmask, Amask); 851 } 852 else 853 { 854 mScreen = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask); 855 AssertReleaseFailed(); 856 } 857 858 SDL_SetClipRect(mScreen, NULL); 859 860 #else 753 861 /* 754 862 * Now set the screen resolution and get the surface pointer … … 756 864 */ 757 865 mScreen = SDL_SetVideoMode(newWidth, newHeight, 0, sdlFlags); 866 #endif 758 867 #ifdef VBOX_SECURELABEL 759 868 /* … … 816 925 { 817 926 #ifdef VBOXSDL_WITH_X11 818 AssertMsg( mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));927 AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n")); 819 928 #endif 820 929 Assert(mScreen); … … 822 931 if (!mScreen || !mSurfVRAM) 823 932 return; 824 933 825 934 /* the source and destination rectangles */ 826 935 SDL_Rect srcRect; … … 880 989 dstRect.h = RT_MAX(0, h - yCutoffGuest); 881 990 882 //RTPrintf("y = %d h = %d mapped to srcY %d srcH %d mapped to dstY = %d dstH %d (guestrel: %d, mLabelHeight: %d, mTopOffset: %d)\n",883 // y, h, srcRect.y, srcRect.h, dstRect.y, dstRect.h, fGuestRelative, mLabelHeight, mTopOffset);884 885 991 /* 886 992 * Now we just blit … … 888 994 SDL_BlitSurface(mSurfVRAM, &srcRect, mScreen, &dstRect); 889 995 /* hardware surfaces don't need update notifications */ 996 #if defined(VBOX_WITH_SDL13) 997 AssertRelease(mScreen->flags & SDL_PREALLOC); 998 SDL_SelectRenderer(mWindow); 999 SDL_DirtyTexture(mTexture, 1, &dstRect); 1000 AssertRelease(mRenderInfo.flags & SDL_RENDERER_PRESENTCOPY); 1001 SDL_RenderCopy(mTexture, &dstRect, &dstRect); 1002 SDL_RenderPresent(); 1003 #else 890 1004 if ((mScreen->flags & SDL_HWSURFACE) == 0) 891 1005 SDL_UpdateRect(mScreen, dstRect.x, dstRect.y, dstRect.w, dstRect.h); 1006 #endif 892 1007 893 1008 #ifdef VBOX_SECURELABEL … … 904 1019 void VBoxSDLFB::repaint() 905 1020 { 906 AssertMsg( mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));1021 AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n")); 907 1022 LogFlow(("VBoxSDLFB::repaint\n")); 908 1023 update(0, 0, mScreen->w, mScreen->h, false /* fGuestRelative */); 909 1024 } 910 1025 911 bool VBoxSDLFB::getFullscreen()912 {913 LogFlow(("VBoxSDLFB::getFullscreen\n"));914 return mfFullscreen;915 }916 917 1026 /** 918 1027 * Toggle fullscreen mode … … 922 1031 void VBoxSDLFB::setFullscreen(bool fFullscreen) 923 1032 { 924 AssertMsg( mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));1033 AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n")); 925 1034 LogFlow(("VBoxSDLFB::SetFullscreen: fullscreen: %d\n", fFullscreen)); 926 1035 mfFullscreen = fFullscreen; … … 965 1074 } 966 1075 967 /**968 * Returns the current x offset of the start of the guest screen969 *970 * @returns current x offset in pixels971 */972 int VBoxSDLFB::getXOffset()973 {974 /* there can only be an offset for centering */975 return mCenterXOffset;976 }977 978 /**979 * Returns the current y offset of the start of the guest screen980 *981 * @returns current y offset in pixels982 */983 int VBoxSDLFB::getYOffset()984 {985 /* we might have a top offset and a center offset */986 return mTopOffset + mCenterYOffset;987 }988 989 1076 #ifdef VBOX_SECURELABEL 990 1077 /** … … 1051 1138 { 1052 1139 #ifdef VBOXSDL_WITH_X11 1053 AssertMsg( mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));1140 AssertMsg(gSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n")); 1054 1141 #endif 1055 1142 /* only when the function is present */ … … 1086 1173 } 1087 1174 #endif /* VBOX_SECURELABEL */ 1088 1089 /**1090 * Terminate SDL1091 *1092 * @remarks must be called from the SDL thread!1093 */1094 void VBoxSDLFB::uninit()1095 {1096 AssertMsg(mSdlNativeThread == RTThreadNativeSelf(), ("Wrong thread! SDL is not threadsafe!\n"));1097 if (mSurfVRAM)1098 {1099 SDL_FreeSurface(mSurfVRAM);1100 mSurfVRAM = NULL;1101 }1102 SDL_QuitSubSystem(SDL_INIT_VIDEO);1103 #ifdef VBOX_SECURELABEL1104 if (mLabelFont)1105 pTTF_CloseFont(mLabelFont);1106 if (pTTF_Quit)1107 pTTF_Quit();1108 #endif1109 mScreen = NULL;1110 if (mWMIcon)1111 {1112 SDL_FreeSurface(mWMIcon);1113 mWMIcon = NULL;1114 }1115 }1116 1175 1117 1176 // IFramebufferOverlay
Note:
See TracChangeset
for help on using the changeset viewer.