diff options
Diffstat (limited to 'indra/llwindow')
31 files changed, 1909 insertions, 2172 deletions
diff --git a/indra/llwindow/lldragdropwin32.cpp b/indra/llwindow/lldragdropwin32.cpp index b164eb9579..15490ef953 100644 --- a/indra/llwindow/lldragdropwin32.cpp +++ b/indra/llwindow/lldragdropwin32.cpp @@ -124,7 +124,7 @@ class LLDragDropWin32Target: ScreenToClient( mAppWindowHandle, &pt2 ); LLCoordWindow cursor_coord_window( pt2.x, pt2.y ); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); LLWindowCallbacks::DragNDropResult result = window_imp->completeDragNDropRequest( cursor_coord_window.convert(), mask, LLWindowCallbacks::DNDA_START_TRACKING, mDropUrl ); @@ -179,7 +179,7 @@ class LLDragDropWin32Target: ScreenToClient( mAppWindowHandle, &pt2 ); LLCoordWindow cursor_coord_window( pt2.x, pt2.y ); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); LLWindowCallbacks::DragNDropResult result = window_imp->completeDragNDropRequest( cursor_coord_window.convert(), mask, LLWindowCallbacks::DNDA_TRACK, mDropUrl ); @@ -219,7 +219,7 @@ class LLDragDropWin32Target: if (NULL != window_imp) { LLCoordGL gl_coord( 0, 0 ); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); window_imp->completeDragNDropRequest( gl_coord, mask, LLWindowCallbacks::DNDA_STOP_TRACKING, mDropUrl ); }; return S_OK; @@ -249,7 +249,7 @@ class LLDragDropWin32Target: LL_INFOS() << LL_ENDL; // no keyboard modifier option yet but we could one day - MASK mask = gKeyboard->currentMask( TRUE ); + MASK mask = gKeyboard->currentMask( true ); // actually do the drop LLWindowCallbacks::DragNDropResult result = window_imp->completeDragNDropRequest( gl_coord, mask, @@ -312,7 +312,7 @@ LLDragDropWin32::~LLDragDropWin32() bool LLDragDropWin32::init( HWND hWnd ) { if ( NOERROR != OleInitialize( NULL ) ) - return FALSE; + return false; mDropTarget = new LLDragDropWin32Target( hWnd ); if ( mDropTarget ) diff --git a/indra/llwindow/lldxhardware.cpp b/indra/llwindow/lldxhardware.cpp index f972e8f628..392a67b5ce 100644 --- a/indra/llwindow/lldxhardware.cpp +++ b/indra/llwindow/lldxhardware.cpp @@ -216,7 +216,7 @@ HRESULT GetVideoMemoryViaWMI(WCHAR* strInputDeviceID, DWORD* pdwAdapterRam) } //static -S32 LLDXHardware::getMBVideoMemoryViaWMI() +U32 LLDXHardware::getMBVideoMemoryViaWMI() { DWORD vram = 0; if (SUCCEEDED(GetVideoMemoryViaWMI(NULL, &vram))) @@ -343,7 +343,7 @@ std::string LLDXHardware::getDriverVersionWMI(EGPUVendor vendor) //convert BSTR to std::string std::wstring ws(caption, SysStringLen(caption)); - std::string caption_str(ws.begin(), ws.end()); + std::string caption_str = ll_convert_wide_to_string(ws); LLStringUtil::toLower(caption_str); bool found = false; @@ -395,7 +395,7 @@ std::string LLDXHardware::getDriverVersionWMI(EGPUVendor vendor) //convert BSTR to std::string std::wstring ws(driverVersion, SysStringLen(driverVersion)); - std::string str(ws.begin(), ws.end()); + std::string str = ll_convert_wide_to_string(ws); LL_INFOS("AppInit") << " DriverVersion : " << str << LL_ENDL; if (mDriverVersion.empty()) @@ -454,10 +454,10 @@ void get_wstring(IDxDiagContainer* containerp, WCHAR* wszPropName, WCHAR* wszPro switch( var.vt ) { case VT_UI4: - swprintf( wszPropValue, L"%d", var.ulVal ); /* Flawfinder: ignore */ + swprintf( wszPropValue, outputSize, L"%d", var.ulVal ); /* Flawfinder: ignore */ break; case VT_I4: - swprintf( wszPropValue, L"%d", var.lVal ); /* Flawfinder: ignore */ + swprintf( wszPropValue, outputSize, L"%d", var.lVal ); /* Flawfinder: ignore */ break; case VT_BOOL: wcscpy( wszPropValue, (var.boolVal) ? L"true" : L"false" ); /* Flawfinder: ignore */ @@ -483,7 +483,7 @@ std::string get_string(IDxDiagContainer *containerp, WCHAR *wszPropName) LLVersion::LLVersion() { - mValid = FALSE; + mValid = false; S32 i; for (i = 0; i < 4; i++) { @@ -491,7 +491,7 @@ LLVersion::LLVersion() } } -BOOL LLVersion::set(const std::string &version_string) +bool LLVersion::set(const std::string &version_string) { S32 i; for (i = 0; i < 4; i++) @@ -518,11 +518,11 @@ BOOL LLVersion::set(const std::string &version_string) { mFields[i] = 0; } - mValid = FALSE; + mValid = false; } else { - mValid = TRUE; + mValid = true; } return mValid; } @@ -678,10 +678,10 @@ LLDXDevice *LLDXHardware::findDevice(const std::string &vendor, const std::strin } */ -BOOL LLDXHardware::getInfo(BOOL vram_only) +bool LLDXHardware::getInfo(bool vram_only) { LLTimer hw_timer; - BOOL ok = FALSE; + bool ok = false; HRESULT hr; // CLSID_DxDiagProvider does not work with Multithreaded? @@ -809,7 +809,7 @@ BOOL LLDXHardware::getInfo(BOOL vram_only) if (vram_only) { - ok = TRUE; + ok = true; goto LCleanup; } @@ -869,7 +869,7 @@ BOOL LLDXHardware::getInfo(BOOL vram_only) tokenizer::iterator iter = tokens.begin(); S32 count = 0; - BOOL valid = TRUE; + bool valid = true; for (;(iter != tokens.end()) && (count < 3);++iter) { switch (count) @@ -877,7 +877,7 @@ BOOL LLDXHardware::getInfo(BOOL vram_only) case 0: if (strcmp(iter->c_str(), "PCI")) { - valid = FALSE; + valid = false; } break; case 1: @@ -948,7 +948,7 @@ BOOL LLDXHardware::getInfo(BOOL vram_only) } // dumpDevices(); - ok = TRUE; + ok = true; LCleanup: if (!ok) diff --git a/indra/llwindow/lldxhardware.h b/indra/llwindow/lldxhardware.h index 12273e97bc..2b879e021c 100644 --- a/indra/llwindow/lldxhardware.h +++ b/indra/llwindow/lldxhardware.h @@ -37,12 +37,12 @@ class LLVersion { public: LLVersion(); - BOOL set(const std::string &version_string); + bool set(const std::string &version_string); S32 getField(const S32 field_num); protected: std::string mVersionString; S32 mFields[4]; - BOOL mValid; + bool mValid; }; class LLDXDriverFile @@ -84,9 +84,9 @@ public: void setWriteDebugFunc(void (*func)(const char*)); void cleanup(); - // Returns TRUE on success. - // vram_only TRUE does a "light" probe. - BOOL getInfo(BOOL vram_only); + // Returns true on success. + // vram_only true does a "light" probe. + bool getInfo(bool vram_only); // WMI can return multiple GPU drivers // specify which one to output @@ -104,7 +104,7 @@ public: // Will get memory of best GPU in MB, return memory on sucsess, 0 on failure // Note: WMI is not accurate in some cases - static S32 getMBVideoMemoryViaWMI(); + static U32 getMBVideoMemoryViaWMI(); // Find a particular device that matches the following specs. // Empty strings indicate that you don't care. diff --git a/indra/llwindow/llkeyboard.cpp b/indra/llwindow/llkeyboard.cpp index d4b0743f32..a16c0a318a 100644 --- a/indra/llwindow/llkeyboard.cpp +++ b/indra/llwindow/llkeyboard.cpp @@ -54,10 +54,10 @@ LLKeyboard::LLKeyboard() : mCallbacks(NULL) for (i = 0; i < KEY_COUNT; i++) { mKeyLevelFrameCount[i] = 0; - mKeyLevel[i] = FALSE; - mKeyUp[i] = FALSE; - mKeyDown[i] = FALSE; - mKeyRepeated[i] = FALSE; + mKeyLevel[i] = false; + mKeyUp[i] = false; + mKeyDown[i] = false; + mKeyRepeated[i] = false; } mInsertMode = LL_KIM_INSERT; @@ -149,14 +149,14 @@ void LLKeyboard::addKeyName(KEY key, const std::string& name) void LLKeyboard::resetKeyDownAndHandle() { - MASK mask = currentMask(FALSE); + MASK mask = currentMask(false); for (S32 i = 0; i < KEY_COUNT; i++) { if (mKeyLevel[i]) { - mKeyDown[i] = FALSE; - mKeyLevel[i] = FALSE; - mKeyUp[i] = TRUE; + mKeyDown[i] = false; + mKeyLevel[i] = false; + mKeyUp[i] = true; mCurTranslatedKey = (KEY)i; mCallbacks->handleTranslatedKeyUp(i, mask); } @@ -173,28 +173,28 @@ void LLKeyboard::resetKeys() { if( mKeyLevel[i] ) { - mKeyLevel[i] = FALSE; + mKeyLevel[i] = false; } } for (i = 0; i < KEY_COUNT; i++) { - mKeyUp[i] = FALSE; + mKeyUp[i] = false; } for (i = 0; i < KEY_COUNT; i++) { - mKeyDown[i] = FALSE; + mKeyDown[i] = false; } for (i = 0; i < KEY_COUNT; i++) { - mKeyRepeated[i] = FALSE; + mKeyRepeated[i] = false; } } -BOOL LLKeyboard::translateKey(const NATIVE_KEY_TYPE os_key, KEY *out_key) +bool LLKeyboard::translateKey(const NATIVE_KEY_TYPE os_key, KEY *out_key) { // Only translate keys in the map, ignore all other keys for now @@ -203,12 +203,12 @@ BOOL LLKeyboard::translateKey(const NATIVE_KEY_TYPE os_key, KEY *out_key) { //LL_WARNS() << "Unknown virtual key " << os_key << LL_ENDL; *out_key = 0; - return FALSE; + return false; } else { *out_key = iter->second; - return TRUE; + return true; } } @@ -226,47 +226,47 @@ LLKeyboard::NATIVE_KEY_TYPE LLKeyboard::inverseTranslateKey(const KEY translated } -BOOL LLKeyboard::handleTranslatedKeyDown(KEY translated_key, U32 translated_mask) +bool LLKeyboard::handleTranslatedKeyDown(KEY translated_key, U32 translated_mask) { - BOOL handled = FALSE; - BOOL repeated = FALSE; + bool handled = false; + bool repeated = false; // is this the first time the key went down? // if so, generate "character" message if( !mKeyLevel[translated_key] ) { - mKeyLevel[translated_key] = TRUE; + mKeyLevel[translated_key] = true; mKeyLevelTimer[translated_key].reset(); mKeyLevelFrameCount[translated_key] = 0; - mKeyRepeated[translated_key] = FALSE; + mKeyRepeated[translated_key] = false; } else { // Level is already down, assume it's repeated. - repeated = TRUE; - mKeyRepeated[translated_key] = TRUE; + repeated = true; + mKeyRepeated[translated_key] = true; } - mKeyDown[translated_key] = TRUE; + mKeyDown[translated_key] = true; mCurTranslatedKey = (KEY)translated_key; handled = mCallbacks->handleTranslatedKeyDown(translated_key, translated_mask, repeated); return handled; } -BOOL LLKeyboard::handleTranslatedKeyUp(KEY translated_key, U32 translated_mask) +bool LLKeyboard::handleTranslatedKeyUp(KEY translated_key, U32 translated_mask) { - BOOL handled = FALSE; + bool handled = false; if( mKeyLevel[translated_key] ) { - mKeyLevel[translated_key] = FALSE; + mKeyLevel[translated_key] = false; // Only generate key up events if the key is thought to // be down. This allows you to call resetKeys() in the // middle of a frame and ignore subsequent KEY_UP // messages in the same frame. This was causing the // sequence W<return> in chat to move agents forward. JC - mKeyUp[translated_key] = TRUE; + mKeyUp[translated_key] = true; handled = mCallbacks->handleTranslatedKeyUp(translated_key, translated_mask); } @@ -302,14 +302,14 @@ S32 LLKeyboard::getKeyElapsedFrameCount(KEY key) } // static -BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key) +bool LLKeyboard::keyFromString(const std::string& str, KEY *key) { std::string instring(str); size_t length = instring.size(); if (length < 1) { - return FALSE; + return false; } if (length == 1) { @@ -322,7 +322,7 @@ BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key) ('{' <= ch && ch <= '~')) // {|}~ { *key = ch; - return TRUE; + return true; } } @@ -331,10 +331,10 @@ BOOL LLKeyboard::keyFromString(const std::string& str, KEY *key) if (res != 0) { *key = res; - return TRUE; + return true; } LL_WARNS() << "keyFromString failed: " << str << LL_ENDL; - return FALSE; + return false; } @@ -355,7 +355,7 @@ std::string LLKeyboard::stringFromKey(KEY key, bool translate) LLKeyStringTranslatorFunc *trans = gKeyboard->mStringTranslator; if (trans != NULL) { - res = trans(res.c_str()); + res = trans(res); } } @@ -395,7 +395,7 @@ std::string LLKeyboard::stringFromMouse(EMouseClickType click, bool translate) LLKeyStringTranslatorFunc* trans = gKeyboard->mStringTranslator; if (trans != NULL) { - res = trans(res.c_str()); + res = trans(res); } } return res; @@ -482,52 +482,52 @@ std::string LLKeyboard::stringFromAccelerator(MASK accel_mask, EMouseClickType c } //static -BOOL LLKeyboard::maskFromString(const std::string& str, MASK *mask) +bool LLKeyboard::maskFromString(const std::string& str, MASK *mask) { std::string instring(str); if (instring == "NONE") { *mask = MASK_NONE; - return TRUE; + return true; } else if (instring == "SHIFT") { *mask = MASK_SHIFT; - return TRUE; + return true; } else if (instring == "CTL") { *mask = MASK_CONTROL; - return TRUE; + return true; } else if (instring == "ALT") { *mask = MASK_ALT; - return TRUE; + return true; } else if (instring == "CTL_SHIFT") { *mask = MASK_CONTROL | MASK_SHIFT; - return TRUE; + return true; } else if (instring == "ALT_SHIFT") { *mask = MASK_ALT | MASK_SHIFT; - return TRUE; + return true; } else if (instring == "CTL_ALT") { *mask = MASK_CONTROL | MASK_ALT; - return TRUE; + return true; } else if (instring == "CTL_ALT_SHIFT") { *mask = MASK_CONTROL | MASK_ALT | MASK_SHIFT; - return TRUE; + return true; } else { - return FALSE; + return false; } } diff --git a/indra/llwindow/llkeyboard.h b/indra/llwindow/llkeyboard.h index 11c745ae71..d3c35b1ed4 100644 --- a/indra/llwindow/llkeyboard.h +++ b/indra/llwindow/llkeyboard.h @@ -42,7 +42,7 @@ enum EKeystate }; typedef boost::function<bool(EKeystate keystate)> LLKeyFunc; -typedef std::string (LLKeyStringTranslatorFunc)(const char *label); +typedef std::string (LLKeyStringTranslatorFunc)(std::string_view); enum EKeyboardInsertMode { @@ -69,19 +69,19 @@ public: F32 getCurKeyElapsedTime() { return getKeyDown(mCurScanKey) ? getKeyElapsedTime( mCurScanKey ) : 0.f; } F32 getCurKeyElapsedFrameCount() { return getKeyDown(mCurScanKey) ? (F32)getKeyElapsedFrameCount( mCurScanKey ) : 0.f; } - BOOL getKeyDown(const KEY key) { return mKeyLevel[key]; } - BOOL getKeyRepeated(const KEY key) { return mKeyRepeated[key]; } + bool getKeyDown(const KEY key) { return mKeyLevel[key]; } + bool getKeyRepeated(const KEY key) { return mKeyRepeated[key]; } - BOOL translateKey(const NATIVE_KEY_TYPE os_key, KEY *translated_key); + bool translateKey(const NATIVE_KEY_TYPE os_key, KEY *translated_key); NATIVE_KEY_TYPE inverseTranslateKey(const KEY translated_key); - BOOL handleTranslatedKeyUp(KEY translated_key, U32 translated_mask); // Translated into "Linden" keycodes - BOOL handleTranslatedKeyDown(KEY translated_key, U32 translated_mask); // Translated into "Linden" keycodes + bool handleTranslatedKeyUp(KEY translated_key, U32 translated_mask); // Translated into "Linden" keycodes + bool handleTranslatedKeyDown(KEY translated_key, U32 translated_mask); // Translated into "Linden" keycodes - virtual BOOL handleKeyUp(const NATIVE_KEY_TYPE key, MASK mask) = 0; - virtual BOOL handleKeyDown(const NATIVE_KEY_TYPE key, MASK mask) = 0; + virtual bool handleKeyUp(const NATIVE_KEY_TYPE key, MASK mask) = 0; + virtual bool handleKeyDown(const NATIVE_KEY_TYPE key, MASK mask) = 0; #ifdef LL_DARWIN - // We only actually use this for OS X. + // We only actually use this for macOS. virtual void handleModifier(MASK mask) = 0; #endif // LL_DARWIN @@ -91,14 +91,14 @@ public: virtual void scanKeyboard() = 0; // scans keyboard, calls functions as necessary // Mac must differentiate between Command = Control for keyboard events // and Command != Control for mouse events. - virtual MASK currentMask(BOOL for_mouse_event) = 0; + virtual MASK currentMask(bool for_mouse_event) = 0; virtual KEY currentKey() { return mCurTranslatedKey; } EKeyboardInsertMode getInsertMode() { return mInsertMode; } void toggleInsertMode(); - static BOOL maskFromString(const std::string& str, MASK *mask); // False on failure - static BOOL keyFromString(const std::string& str, KEY *key); // False on failure + static bool maskFromString(const std::string& str, MASK *mask); // False on failure + static bool keyFromString(const std::string& str, KEY *key); // False on failure static std::string stringFromKey(KEY key, bool translate = true); static std::string stringFromMouse(EMouseClickType click, bool translate = true); static std::string stringFromAccelerator( MASK accel_mask ); // separated for convinience, returns with "+": "Shift+" or "Shift+Alt+"... @@ -121,10 +121,10 @@ protected: LLTimer mKeyLevelTimer[KEY_COUNT]; // Time since level was set S32 mKeyLevelFrameCount[KEY_COUNT]; // Frames since level was set - BOOL mKeyLevel[KEY_COUNT]; // Levels - BOOL mKeyRepeated[KEY_COUNT]; // Key was repeated - BOOL mKeyUp[KEY_COUNT]; // Up edge - BOOL mKeyDown[KEY_COUNT]; // Down edge + bool mKeyLevel[KEY_COUNT]; // Levels + bool mKeyRepeated[KEY_COUNT]; // Key was repeated + bool mKeyUp[KEY_COUNT]; // Up edge + bool mKeyDown[KEY_COUNT]; // Down edge KEY mCurTranslatedKey; KEY mCurScanKey; // Used during the scanKeyboard() diff --git a/indra/llwindow/llkeyboardheadless.cpp b/indra/llwindow/llkeyboardheadless.cpp index 265d7e6c76..ad8e42a412 100644 --- a/indra/llwindow/llkeyboardheadless.cpp +++ b/indra/llwindow/llkeyboardheadless.cpp @@ -34,11 +34,7 @@ LLKeyboardHeadless::LLKeyboardHeadless() void LLKeyboardHeadless::resetMaskKeys() { } - - - - -MASK LLKeyboardHeadless::currentMask(BOOL for_mouse_event) +MASK LLKeyboardHeadless::currentMask(bool for_mouse_event) { return MASK_NONE; } #ifdef LL_DARWIN @@ -65,8 +61,8 @@ void LLKeyboardHeadless::scanKeyboard() // Reset edges for next frame for (S32 key = 0; key < KEY_COUNT; key++) { - mKeyUp[key] = FALSE; - mKeyDown[key] = FALSE; + mKeyUp[key] = false; + mKeyDown[key] = false; if (mKeyLevel[key]) { mKeyLevelFrameCount[key]++; diff --git a/indra/llwindow/llkeyboardheadless.h b/indra/llwindow/llkeyboardheadless.h index 595f824872..439abaf25b 100644 --- a/indra/llwindow/llkeyboardheadless.h +++ b/indra/llwindow/llkeyboardheadless.h @@ -36,14 +36,14 @@ public: /*virtual*/ ~LLKeyboardHeadless() {}; #ifndef LL_SDL - /*virtual*/ BOOL handleKeyUp(const U16 key, MASK mask) { return FALSE; } - /*virtual*/ BOOL handleKeyDown(const U16 key, MASK mask) { return FALSE; } + /*virtual*/ bool handleKeyUp(const U16 key, MASK mask) { return false; } + /*virtual*/ bool handleKeyDown(const U16 key, MASK mask) { return false; } #else - /*virtual*/ BOOL handleKeyUp(const U32 key, MASK mask) { return FALSE; } - /*virtual*/ BOOL handleKeyDown(const U32 key, MASK mask) { return FALSE; } + /*virtual*/ bool handleKeyUp(const U32 key, MASK mask) { return false; } + /*virtual*/ bool handleKeyDown(const U32 key, MASK mask) { return false; } #endif /*virtual*/ void resetMaskKeys(); - /*virtual*/ MASK currentMask(BOOL for_mouse_event); + /*virtual*/ MASK currentMask(bool for_mouse_event); /*virtual*/ void scanKeyboard(); #ifdef LL_DARWIN /*virtual*/ void handleModifier(MASK mask); diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp index a1aeb2e5e4..89ff7c6d3f 100644 --- a/indra/llwindow/llkeyboardmacosx.cpp +++ b/indra/llwindow/llkeyboardmacosx.cpp @@ -172,22 +172,22 @@ void LLKeyboardMacOSX::resetMaskKeys() if(mask & MAC_SHIFT_KEY) { - mKeyLevel[KEY_SHIFT] = TRUE; + mKeyLevel[KEY_SHIFT] = true; } if(mask & MAC_CTRL_KEY) { - mKeyLevel[KEY_CONTROL] = TRUE; + mKeyLevel[KEY_CONTROL] = true; } if(mask & MAC_ALT_KEY) { - mKeyLevel[KEY_ALT] = TRUE; + mKeyLevel[KEY_ALT] = true; } } /* -static BOOL translateKeyMac(const U16 key, const U32 mask, KEY &outKey, U32 &outMask) +static bool translateKeyMac(const U16 key, const U32 mask, KEY &outKey, U32 &outMask) { // Translate the virtual keycode into the keycodes the keyboard system expects. U16 virtualKey = (mask >> 24) & 0x0000007F; @@ -226,11 +226,11 @@ MASK LLKeyboardMacOSX::updateModifiers(const U32 mask) return out_mask; } -BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask) +bool LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask) { KEY translated_key = 0; U32 translated_mask = 0; - BOOL handled = FALSE; + bool handled = false; translated_mask = updateModifiers(mask); @@ -243,11 +243,11 @@ BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask) } -BOOL LLKeyboardMacOSX::handleKeyUp(const U16 key, const U32 mask) +bool LLKeyboardMacOSX::handleKeyUp(const U16 key, const U32 mask) { KEY translated_key = 0; U32 translated_mask = 0; - BOOL handled = FALSE; + bool handled = false; translated_mask = updateModifiers(mask); @@ -259,7 +259,7 @@ BOOL LLKeyboardMacOSX::handleKeyUp(const U16 key, const U32 mask) return handled; } -MASK LLKeyboardMacOSX::currentMask(BOOL for_mouse_event) +MASK LLKeyboardMacOSX::currentMask(bool for_mouse_event) { MASK result = MASK_NONE; U32 mask = getModifiers(); @@ -295,8 +295,8 @@ void LLKeyboardMacOSX::scanKeyboard() // Reset edges for next frame for (key = 0; key < KEY_COUNT; key++) { - mKeyUp[key] = FALSE; - mKeyDown[key] = FALSE; + mKeyUp[key] = false; + mKeyDown[key] = false; if (mKeyLevel[key]) { mKeyLevelFrameCount[key]++; @@ -304,7 +304,7 @@ void LLKeyboardMacOSX::scanKeyboard() } } -BOOL LLKeyboardMacOSX::translateNumpadKey( const U16 os_key, KEY *translated_key ) +bool LLKeyboardMacOSX::translateNumpadKey( const U16 os_key, KEY *translated_key ) { return translateKey(os_key, translated_key); } diff --git a/indra/llwindow/llkeyboardmacosx.h b/indra/llwindow/llkeyboardmacosx.h index d6895f684d..92ab5c9a85 100644 --- a/indra/llwindow/llkeyboardmacosx.h +++ b/indra/llwindow/llkeyboardmacosx.h @@ -44,17 +44,17 @@ public: LLKeyboardMacOSX(); /*virtual*/ ~LLKeyboardMacOSX() {}; - /*virtual*/ BOOL handleKeyUp(const U16 key, MASK mask); - /*virtual*/ BOOL handleKeyDown(const U16 key, MASK mask); + /*virtual*/ bool handleKeyUp(const U16 key, MASK mask); + /*virtual*/ bool handleKeyDown(const U16 key, MASK mask); /*virtual*/ void resetMaskKeys(); - /*virtual*/ MASK currentMask(BOOL for_mouse_event); + /*virtual*/ MASK currentMask(bool for_mouse_event); /*virtual*/ void scanKeyboard(); /*virtual*/ void handleModifier(MASK mask); protected: MASK updateModifiers(const U32 mask); - void setModifierKeyLevel( KEY key, BOOL new_state ); - BOOL translateNumpadKey( const U16 os_key, KEY *translated_key ); + void setModifierKeyLevel( KEY key, bool new_state ); + bool translateNumpadKey( const U16 os_key, KEY *translated_key ); U16 inverseTranslateNumpadKey(const KEY translated_key); private: std::map<U16, KEY> mTranslateNumpadMap; // special map for translating OS keys to numpad keys diff --git a/indra/llwindow/llkeyboardsdl.cpp b/indra/llwindow/llkeyboardsdl.cpp index 0fe0b5b771..543882fc8f 100644 --- a/indra/llwindow/llkeyboardsdl.cpp +++ b/indra/llwindow/llkeyboardsdl.cpp @@ -162,17 +162,17 @@ void LLKeyboardSDL::resetMaskKeys() if(mask & KMOD_SHIFT) { - mKeyLevel[KEY_SHIFT] = TRUE; + mKeyLevel[KEY_SHIFT] = true; } if(mask & KMOD_CTRL) { - mKeyLevel[KEY_CONTROL] = TRUE; + mKeyLevel[KEY_CONTROL] = true; } if(mask & KMOD_ALT) { - mKeyLevel[KEY_ALT] = TRUE; + mKeyLevel[KEY_ALT] = true; } } @@ -226,12 +226,12 @@ static U32 adjustNativekeyFromUnhandledMask(const U32 key, const U32 mask) } -BOOL LLKeyboardSDL::handleKeyDown(const U32 key, const U32 mask) +bool LLKeyboardSDL::handleKeyDown(const U32 key, const U32 mask) { U32 adjusted_nativekey; KEY translated_key = 0; U32 translated_mask = MASK_NONE; - BOOL handled = FALSE; + bool handled = false; adjusted_nativekey = adjustNativekeyFromUnhandledMask(key, mask); @@ -246,12 +246,12 @@ BOOL LLKeyboardSDL::handleKeyDown(const U32 key, const U32 mask) } -BOOL LLKeyboardSDL::handleKeyUp(const U32 key, const U32 mask) +bool LLKeyboardSDL::handleKeyUp(const U32 key, const U32 mask) { U32 adjusted_nativekey; KEY translated_key = 0; U32 translated_mask = MASK_NONE; - BOOL handled = FALSE; + bool handled = false; adjusted_nativekey = adjustNativekeyFromUnhandledMask(key, mask); @@ -265,7 +265,7 @@ BOOL LLKeyboardSDL::handleKeyUp(const U32 key, const U32 mask) return handled; } -MASK LLKeyboardSDL::currentMask(BOOL for_mouse_event) +MASK LLKeyboardSDL::currentMask(bool for_mouse_event) { MASK result = MASK_NONE; SDL_Keymod mask = SDL_GetModState(); @@ -304,8 +304,8 @@ void LLKeyboardSDL::scanKeyboard() // Reset edges for next frame for (S32 key = 0; key < KEY_COUNT; key++) { - mKeyUp[key] = FALSE; - mKeyDown[key] = FALSE; + mKeyUp[key] = false; + mKeyDown[key] = false; if (mKeyLevel[key]) { mKeyLevelFrameCount[key]++; @@ -314,7 +314,7 @@ void LLKeyboardSDL::scanKeyboard() } -BOOL LLKeyboardSDL::translateNumpadKey( const U32 os_key, KEY *translated_key) +bool LLKeyboardSDL::translateNumpadKey( const U32 os_key, KEY *translated_key) { return translateKey(os_key, translated_key); } diff --git a/indra/llwindow/llkeyboardsdl.h b/indra/llwindow/llkeyboardsdl.h index 727bac2690..9ebff66865 100644 --- a/indra/llwindow/llkeyboardsdl.h +++ b/indra/llwindow/llkeyboardsdl.h @@ -35,16 +35,16 @@ public: LLKeyboardSDL(); /*virtual*/ ~LLKeyboardSDL() {}; - /*virtual*/ BOOL handleKeyUp(const U32 key, MASK mask); - /*virtual*/ BOOL handleKeyDown(const U32 key, MASK mask); + /*virtual*/ bool handleKeyUp(const U32 key, MASK mask); + /*virtual*/ bool handleKeyDown(const U32 key, MASK mask); /*virtual*/ void resetMaskKeys(); - /*virtual*/ MASK currentMask(BOOL for_mouse_event); + /*virtual*/ MASK currentMask(bool for_mouse_event); /*virtual*/ void scanKeyboard(); protected: MASK updateModifiers(const U32 mask); - void setModifierKeyLevel( KEY key, BOOL new_state ); - BOOL translateNumpadKey( const U32 os_key, KEY *translated_key ); + void setModifierKeyLevel( KEY key, bool new_state ); + bool translateNumpadKey( const U32 os_key, KEY *translated_key ); U16 inverseTranslateNumpadKey(const KEY translated_key); private: std::map<U32, KEY> mTranslateNumpadMap; // special map for translating OS keys to numpad keys diff --git a/indra/llwindow/llkeyboardwin32.cpp b/indra/llwindow/llkeyboardwin32.cpp index 4934e21d55..ec0055fe60 100644 --- a/indra/llwindow/llkeyboardwin32.cpp +++ b/indra/llwindow/llkeyboardwin32.cpp @@ -152,22 +152,22 @@ void LLKeyboardWin32::resetMaskKeys() // bit to indicate that the key is down. if (GetAsyncKeyState(VK_SHIFT) & 0x8000) { - mKeyLevel[KEY_SHIFT] = TRUE; + mKeyLevel[KEY_SHIFT] = true; } if (GetAsyncKeyState(VK_CONTROL) & 0x8000) { - mKeyLevel[KEY_CONTROL] = TRUE; + mKeyLevel[KEY_CONTROL] = true; } if (GetAsyncKeyState(VK_MENU) & 0x8000) { - mKeyLevel[KEY_ALT] = TRUE; + mKeyLevel[KEY_ALT] = true; } } -//void LLKeyboardWin32::setModifierKeyLevel( KEY key, BOOL new_state ) +//void LLKeyboardWin32::setModifierKeyLevel( KEY key, bool new_state ) //{ // if( mKeyLevel[key] != new_state ) // { @@ -191,17 +191,17 @@ MASK LLKeyboardWin32::updateModifiers() // (keydown encoded in high order bit of short) mKeyLevel[KEY_CAPSLOCK] = (GetKeyState(VK_CAPITAL) & 0x0001) != 0; // Low order bit carries the toggle state. // Get mask for keyboard events - MASK mask = currentMask(FALSE); + MASK mask = currentMask(false); return mask; } // mask is ignored, except for extended flag -- we poll the modifier keys for the other flags -BOOL LLKeyboardWin32::handleKeyDown(const U16 key, MASK mask) +bool LLKeyboardWin32::handleKeyDown(const U16 key, MASK mask) { KEY translated_key; U32 translated_mask; - BOOL handled = FALSE; + bool handled = false; translated_mask = updateModifiers(); @@ -214,11 +214,11 @@ BOOL LLKeyboardWin32::handleKeyDown(const U16 key, MASK mask) } // mask is ignored, except for extended flag -- we poll the modifier keys for the other flags -BOOL LLKeyboardWin32::handleKeyUp(const U16 key, MASK mask) +bool LLKeyboardWin32::handleKeyUp(const U16 key, MASK mask) { KEY translated_key; U32 translated_mask; - BOOL handled = FALSE; + bool handled = false; translated_mask = updateModifiers(); @@ -231,7 +231,7 @@ BOOL LLKeyboardWin32::handleKeyUp(const U16 key, MASK mask) } -MASK LLKeyboardWin32::currentMask(BOOL) +MASK LLKeyboardWin32::currentMask(bool) { MASK mask = MASK_NONE; @@ -263,8 +263,8 @@ void LLKeyboardWin32::scanKeyboard() // Reset edges for next frame for (key = 0; key < KEY_COUNT; key++) { - mKeyUp[key] = FALSE; - mKeyDown[key] = FALSE; + mKeyUp[key] = false; + mKeyDown[key] = false; if (mKeyLevel[key]) { mKeyLevelFrameCount[key]++; @@ -272,7 +272,7 @@ void LLKeyboardWin32::scanKeyboard() } } -BOOL LLKeyboardWin32::translateExtendedKey(const U16 os_key, const MASK mask, KEY *translated_key) +bool LLKeyboardWin32::translateExtendedKey(const U16 os_key, const MASK mask, KEY *translated_key) { return translateKey(os_key, translated_key); } diff --git a/indra/llwindow/llkeyboardwin32.h b/indra/llwindow/llkeyboardwin32.h index 838566d69c..d0dfc5cfdd 100644 --- a/indra/llwindow/llkeyboardwin32.h +++ b/indra/llwindow/llkeyboardwin32.h @@ -39,17 +39,17 @@ public: LLKeyboardWin32(); /*virtual*/ ~LLKeyboardWin32() {}; - /*virtual*/ BOOL handleKeyUp(const U16 key, MASK mask); - /*virtual*/ BOOL handleKeyDown(const U16 key, MASK mask); + /*virtual*/ bool handleKeyUp(const U16 key, MASK mask); + /*virtual*/ bool handleKeyDown(const U16 key, MASK mask); /*virtual*/ void resetMaskKeys(); - /*virtual*/ MASK currentMask(BOOL for_mouse_event); + /*virtual*/ MASK currentMask(bool for_mouse_event); /*virtual*/ void scanKeyboard(); - BOOL translateExtendedKey(const U16 os_key, const MASK mask, KEY *translated_key); + bool translateExtendedKey(const U16 os_key, const MASK mask, KEY *translated_key); U16 inverseTranslateExtendedKey(const KEY translated_key); protected: MASK updateModifiers(); - //void setModifierKeyLevel( KEY key, BOOL new_state ); + //void setModifierKeyLevel( KEY key, bool new_state ); private: std::map<U16, KEY> mTranslateNumpadMap; std::map<KEY, U16> mInvTranslateNumpadMap; diff --git a/indra/llwindow/llmousehandler.cpp b/indra/llwindow/llmousehandler.cpp index 62ad406967..eeceab502a 100644 --- a/indra/llwindow/llmousehandler.cpp +++ b/indra/llwindow/llmousehandler.cpp @@ -27,9 +27,9 @@ #include "llmousehandler.h" //virtual -BOOL LLMouseHandler::handleAnyMouseClick(S32 x, S32 y, MASK mask, EMouseClickType clicktype, BOOL down) +bool LLMouseHandler::handleAnyMouseClick(S32 x, S32 y, MASK mask, EMouseClickType clicktype, bool down) { - BOOL handled = FALSE; + bool handled = false; if (down) { switch (clicktype) diff --git a/indra/llwindow/llmousehandler.h b/indra/llwindow/llmousehandler.h index dea28a0fc3..565d7bed70 100644 --- a/indra/llwindow/llmousehandler.h +++ b/indra/llwindow/llmousehandler.h @@ -47,19 +47,19 @@ public: SHOW_ALWAYS, } EShowToolTip; - virtual BOOL handleAnyMouseClick(S32 x, S32 y, MASK mask, EMouseClickType clicktype, BOOL down); - virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleMiddleMouseUp(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleRightMouseDown(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleRightMouseUp(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleDoubleClick(S32 x, S32 y, MASK mask) = 0; + virtual bool handleAnyMouseClick(S32 x, S32 y, MASK mask, EMouseClickType clicktype, bool down); + virtual bool handleMouseDown(S32 x, S32 y, MASK mask) = 0; + virtual bool handleMouseUp(S32 x, S32 y, MASK mask) = 0; + virtual bool handleMiddleMouseDown(S32 x, S32 y, MASK mask) = 0; + virtual bool handleMiddleMouseUp(S32 x, S32 y, MASK mask) = 0; + virtual bool handleRightMouseDown(S32 x, S32 y, MASK mask) = 0; + virtual bool handleRightMouseUp(S32 x, S32 y, MASK mask) = 0; + virtual bool handleDoubleClick(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleHover(S32 x, S32 y, MASK mask) = 0; - virtual BOOL handleScrollWheel(S32 x, S32 y, S32 clicks) = 0; - virtual BOOL handleScrollHWheel(S32 x, S32 y, S32 clicks) = 0; - virtual BOOL handleToolTip(S32 x, S32 y, MASK mask) = 0; + virtual bool handleHover(S32 x, S32 y, MASK mask) = 0; + virtual bool handleScrollWheel(S32 x, S32 y, S32 clicks) = 0; + virtual bool handleScrollHWheel(S32 x, S32 y, S32 clicks) = 0; + virtual bool handleToolTip(S32 x, S32 y, MASK mask) = 0; virtual const std::string& getName() const = 0; virtual void onMouseCaptureLost() = 0; @@ -67,7 +67,7 @@ public: virtual void screenPointToLocal(S32 screen_x, S32 screen_y, S32* local_x, S32* local_y) const = 0; virtual void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x, S32* screen_y) const = 0; - virtual BOOL hasMouseCapture() = 0; + virtual bool hasMouseCapture() = 0; }; #endif diff --git a/indra/llwindow/llpreeditor.h b/indra/llwindow/llpreeditor.h index 943d70c3dd..492a3e9e88 100644 --- a/indra/llwindow/llpreeditor.h +++ b/indra/llwindow/llpreeditor.h @@ -34,7 +34,7 @@ class LLPreeditor public: typedef std::vector<S32> segment_lengths_t; - typedef std::vector<BOOL> standouts_t; + typedef std::deque<bool> standouts_t; // We don't delete against LLPreeditor, but compilers complain without this... @@ -79,7 +79,7 @@ public: // Locations are relative to the app window and measured in GL coordinate space (before scaling.) // query_position is IN argument, and other three are OUT. - virtual BOOL getPreeditLocation(S32 query_position, LLCoordGL *coord, LLRect *bounds, LLRect *control) const = 0; + virtual bool getPreeditLocation(S32 query_position, LLCoordGL *coord, LLRect *bounds, LLRect *control) const = 0; // Get the size (height) of the current font used in this preeditor. @@ -93,9 +93,9 @@ public: // Handle a UTF-32 char on this preeditor, i.e., add the character // to the contents. // This is a back door of the method of same name of LLWindowCallback. - // called_from_parent should be set to FALSE if calling through LLPreeditor. + // called_from_parent should be set to false if calling through LLPreeditor. - virtual BOOL handleUnicodeCharHere(llwchar uni_char) = 0; + virtual bool handleUnicodeCharHere(llwchar uni_char) = 0; }; #endif diff --git a/indra/llwindow/llwindow.cpp b/indra/llwindow/llwindow.cpp index 9cc11091b6..378e633cd2 100644 --- a/indra/llwindow/llwindow.cpp +++ b/indra/llwindow/llwindow.cpp @@ -46,8 +46,8 @@ // Globals // LLSplashScreen *gSplashScreenp = NULL; -BOOL gDebugClicks = FALSE; -BOOL gDebugWindowProc = FALSE; +bool gDebugClicks = false; +bool gDebugWindowProc = false; const S32 gURLProtocolWhitelistCount = 5; const std::string gURLProtocolWhitelist[] = { "secondlife:", "http:", "https:", "data:", "mailto:" }; @@ -63,16 +63,16 @@ const std::string gURLProtocolWhitelist[] = { "secondlife:", "http:", "https:", S32 OSMessageBox(const std::string& text, const std::string& caption, U32 type) { // Properly hide the splash screen when displaying the message box - BOOL was_visible = FALSE; + bool was_visible = false; if (LLSplashScreen::isVisible()) { - was_visible = TRUE; + was_visible = true; LLSplashScreen::hide(); } S32 result = 0; -#if LL_MESA_HEADLESS // !!! *FIX: (?) LL_WARNS() << "OSMessageBox: " << text << LL_ENDL; +#if LL_MESA_HEADLESS // !!! *FIX: (?) return OSBTN_OK; #elif LL_WINDOWS result = OSMessageBoxWin32(text, caption, type); @@ -97,9 +97,9 @@ S32 OSMessageBox(const std::string& text, const std::string& caption, U32 type) // LLWindow // -LLWindow::LLWindow(LLWindowCallbacks* callbacks, BOOL fullscreen, U32 flags) +LLWindow::LLWindow(LLWindowCallbacks* callbacks, bool fullscreen, U32 flags) : mCallbacks(callbacks), - mPostQuit(TRUE), + mPostQuit(true), mFullscreen(fullscreen), mFullscreenWidth(0), mFullscreenHeight(0), @@ -109,13 +109,13 @@ LLWindow::LLWindow(LLWindowCallbacks* callbacks, BOOL fullscreen, U32 flags) mNumSupportedResolutions(0), mCurrentCursor(UI_CURSOR_ARROW), mNextCursor(UI_CURSOR_ARROW), - mCursorHidden(FALSE), + mCursorHidden(false), mBusyCount(0), - mIsMouseClipping(FALSE), + mIsMouseClipping(false), mMinWindowWidth(0), mMinWindowHeight(0), mSwapMethod(SWAP_METHOD_UNDEFINED), - mHideCursorPermanent(FALSE), + mHideCursorPermanent(false), mFlags(flags), mHighSurrogate(0), mRefreshRate(0) @@ -127,15 +127,15 @@ LLWindow::~LLWindow() } //virtual -BOOL LLWindow::isValid() +bool LLWindow::isValid() { - return TRUE; + return true; } //virtual -BOOL LLWindow::canDelete() +bool LLWindow::canDelete() { - return TRUE; + return true; } //virtual @@ -178,9 +178,9 @@ ECursorType LLWindow::getCursor() const } //virtual -BOOL LLWindow::dialogColorPicker(F32 *r, F32 *g, F32 *b) +bool LLWindow::dialogColorPicker(F32 *r, F32 *g, F32 *b) { - return FALSE; + return false; } void *LLWindow::getMediaWindow() @@ -189,7 +189,7 @@ void *LLWindow::getMediaWindow() return getPlatformWindow(); } -BOOL LLWindow::setSize(LLCoordScreen size) +bool LLWindow::setSize(LLCoordScreen size) { if (!getMaximized()) { @@ -199,7 +199,7 @@ BOOL LLWindow::setSize(LLCoordScreen size) return setSizeImpl(size); } -BOOL LLWindow::setSize(LLCoordWindow size) +bool LLWindow::setSize(LLCoordWindow size) { //HACK: we are inconsistently using minimum window dimensions // in this case, we are constraining the inner "client" rect and other times @@ -241,19 +241,19 @@ void LLWindow::processMiscNativeEvents() } //virtual -BOOL LLWindow::isPrimaryTextAvailable() +bool LLWindow::isPrimaryTextAvailable() { - return FALSE; // no + return false; // no } //virtual -BOOL LLWindow::pasteTextFromPrimary(LLWString &dst) +bool LLWindow::pasteTextFromPrimary(LLWString &dst) { - return FALSE; // fail + return false; // fail } // virtual -BOOL LLWindow::copyTextToPrimary(const LLWString &src) +bool LLWindow::copyTextToPrimary(const LLWString &src) { - return FALSE; // fail + return false; // fail } // static @@ -336,7 +336,7 @@ void LLWindow::handleUnicodeUTF16(U16 utf16, MASK mask) // static bool LLSplashScreen::isVisible() { - return gSplashScreenp ? true: false; + return gSplashScreenp; } // static @@ -402,14 +402,13 @@ static std::set<LLWindow*> sWindowList; LLWindow* LLWindowManager::createWindow( LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, U32 flags, - BOOL fullscreen, - BOOL clearBg, - BOOL enable_vsync, - BOOL use_gl, - BOOL ignore_pixel_depth, + bool fullscreen, + bool clearBg, + bool enable_vsync, + bool use_gl, + bool ignore_pixel_depth, U32 fsaa_samples, U32 max_cores, - U32 max_vram, F32 max_gl_version) { LLWindow* new_window; @@ -427,7 +426,7 @@ LLWindow* LLWindowManager::createWindow( #elif LL_WINDOWS new_window = new LLWindowWin32(callbacks, title, name, x, y, width, height, flags, - fullscreen, clearBg, enable_vsync, use_gl, ignore_pixel_depth, fsaa_samples, max_cores, max_vram, max_gl_version); + fullscreen, clearBg, enable_vsync, use_gl, ignore_pixel_depth, fsaa_samples, max_cores, max_gl_version); #elif LL_DARWIN new_window = new LLWindowMacOSX(callbacks, title, name, x, y, width, height, flags, @@ -441,7 +440,7 @@ LLWindow* LLWindowManager::createWindow( fullscreen, clearBg, enable_vsync, use_gl, ignore_pixel_depth); } - if (FALSE == new_window->isValid()) + if (false == new_window->isValid()) { delete new_window; LL_WARNS() << "LLWindowManager::create() : Error creating window." << LL_ENDL; @@ -451,13 +450,13 @@ LLWindow* LLWindowManager::createWindow( return new_window; } -BOOL LLWindowManager::destroyWindow(LLWindow* window) +bool LLWindowManager::destroyWindow(LLWindow* window) { if (sWindowList.find(window) == sWindowList.end()) { LL_ERRS() << "LLWindowManager::destroyWindow() : Window pointer not valid, this window doesn't exist!" << LL_ENDL; - return FALSE; + return false; } window->close(); @@ -466,10 +465,10 @@ BOOL LLWindowManager::destroyWindow(LLWindow* window) delete window; - return TRUE; + return true; } -BOOL LLWindowManager::isWindowValid(LLWindow *window) +bool LLWindowManager::isWindowValid(LLWindow *window) { return sWindowList.find(window) != sWindowList.end(); } diff --git a/indra/llwindow/llwindow.h b/indra/llwindow/llwindow.h index aff9334cb6..5e06e665f3 100644 --- a/indra/llwindow/llwindow.h +++ b/indra/llwindow/llwindow.h @@ -63,21 +63,21 @@ public: virtual void show() = 0; virtual void hide() = 0; virtual void close() = 0; - virtual BOOL getVisible() = 0; - virtual BOOL getMinimized() = 0; - virtual BOOL getMaximized() = 0; - virtual BOOL maximize() = 0; + virtual bool getVisible() = 0; + virtual bool getMinimized() = 0; + virtual bool getMaximized() = 0; + virtual bool maximize() = 0; virtual void minimize() = 0; virtual void restore() = 0; - BOOL getFullscreen() { return mFullscreen; }; - virtual BOOL getPosition(LLCoordScreen *position) = 0; - virtual BOOL getSize(LLCoordScreen *size) = 0; - virtual BOOL getSize(LLCoordWindow *size) = 0; - virtual BOOL setPosition(LLCoordScreen position) = 0; - BOOL setSize(LLCoordScreen size); - BOOL setSize(LLCoordWindow size); + bool getFullscreen() { return mFullscreen; }; + virtual bool getPosition(LLCoordScreen *position) = 0; + virtual bool getSize(LLCoordScreen *size) = 0; + virtual bool getSize(LLCoordWindow *size) = 0; + virtual bool setPosition(LLCoordScreen position) = 0; + bool setSize(LLCoordScreen size); + bool setSize(LLCoordWindow size); virtual void setMinSize(U32 min_width, U32 min_height, bool enforce_immediately = true); - virtual BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp = NULL) = 0; + virtual bool switchContext(bool fullscreen, const LLCoordScreen &size, bool enable_vsync, const LLCoordScreen * const posp = NULL) = 0; //create a new GL context that shares a namespace with this Window's main GL context and make it current on the current thread // returns a pointer to be handed back to destroySharedConext/makeContextCurrent @@ -90,14 +90,14 @@ public: virtual void toggleVSync(bool enable_vsync) = 0; - virtual BOOL setCursorPosition(LLCoordWindow position) = 0; - virtual BOOL getCursorPosition(LLCoordWindow *position) = 0; + virtual bool setCursorPosition(LLCoordWindow position) = 0; + virtual bool getCursorPosition(LLCoordWindow *position) = 0; #if LL_WINDOWS - virtual BOOL getCursorDelta(LLCoordCommon* delta) = 0; + virtual bool getCursorDelta(LLCoordCommon* delta) = 0; #endif virtual void showCursor() = 0; virtual void hideCursor() = 0; - virtual BOOL isCursorHidden() = 0; + virtual bool isCursorHidden() = 0; virtual void showCursorFromMouseMove() = 0; virtual void hideCursorUntilMouseMove() = 0; @@ -124,22 +124,22 @@ public: virtual void captureMouse() = 0; virtual void releaseMouse() = 0; - virtual void setMouseClipping( BOOL b ) = 0; + virtual void setMouseClipping( bool b ) = 0; - virtual BOOL isClipboardTextAvailable() = 0; - virtual BOOL pasteTextFromClipboard(LLWString &dst) = 0; - virtual BOOL copyTextToClipboard(const LLWString &src) = 0; + virtual bool isClipboardTextAvailable() = 0; + virtual bool pasteTextFromClipboard(LLWString &dst) = 0; + virtual bool copyTextToClipboard(const LLWString &src) = 0; - virtual BOOL isPrimaryTextAvailable(); - virtual BOOL pasteTextFromPrimary(LLWString &dst); - virtual BOOL copyTextToPrimary(const LLWString &src); + virtual bool isPrimaryTextAvailable(); + virtual bool pasteTextFromPrimary(LLWString &dst); + virtual bool copyTextToPrimary(const LLWString &src); virtual void flashIcon(F32 seconds) = 0; virtual F32 getGamma() = 0; - virtual BOOL setGamma(const F32 gamma) = 0; // Set the gamma + virtual bool setGamma(const F32 gamma) = 0; // Set the gamma virtual void setFSAASamples(const U32 fsaa_samples) = 0; //set number of FSAA samples virtual U32 getFSAASamples() = 0; - virtual BOOL restoreGamma() = 0; // Restore original gamma table (before updating gamma) + virtual bool restoreGamma() = 0; // Restore original gamma table (before updating gamma) virtual ESwapMethod getSwapMethod() { return mSwapMethod; } virtual void processMiscNativeEvents(); virtual void gatherInput() = 0; @@ -151,12 +151,12 @@ public: // handy coordinate space conversion routines // NB: screen to window and vice verse won't work on width/height coordinate pairs, // as the conversion must take into account left AND right border widths, etc. - virtual BOOL convertCoords( LLCoordScreen from, LLCoordWindow *to) = 0; - virtual BOOL convertCoords( LLCoordWindow from, LLCoordScreen *to) = 0; - virtual BOOL convertCoords( LLCoordWindow from, LLCoordGL *to) = 0; - virtual BOOL convertCoords( LLCoordGL from, LLCoordWindow *to) = 0; - virtual BOOL convertCoords( LLCoordScreen from, LLCoordGL *to) = 0; - virtual BOOL convertCoords( LLCoordGL from, LLCoordScreen *to) = 0; + virtual bool convertCoords( LLCoordScreen from, LLCoordWindow *to) = 0; + virtual bool convertCoords( LLCoordWindow from, LLCoordScreen *to) = 0; + virtual bool convertCoords( LLCoordWindow from, LLCoordGL *to) = 0; + virtual bool convertCoords( LLCoordGL from, LLCoordWindow *to) = 0; + virtual bool convertCoords( LLCoordScreen from, LLCoordGL *to) = 0; + virtual bool convertCoords( LLCoordGL from, LLCoordScreen *to) = 0; // query supported resolutions virtual LLWindowResolution* getSupportedResolutions(S32 &num_resolutions) = 0; @@ -164,15 +164,12 @@ public: virtual F32 getPixelAspectRatio() = 0; virtual void setNativeAspectRatio(F32 aspect) = 0; - // query VRAM usage - virtual U32 getAvailableVRAMMegabytes() = 0; - virtual void beforeDialog() {}; // prepare to put up an OS dialog (if special measures are required, such as in fullscreen mode) virtual void afterDialog() {}; // undo whatever was done in beforeDialog() // opens system default color picker, modally - // Returns TRUE if valid color selected - virtual BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b); + // Returns true if valid color selected + virtual bool dialogColorPicker(F32 *r, F32 *g, F32 *b); // return a platform-specific window reference (HWND on Windows, WindowRef on the Mac, Gtk window on Linux) virtual void *getPlatformWindow() = 0; @@ -181,7 +178,7 @@ public: virtual void *getMediaWindow(); // control platform's Language Text Input mechanisms. - virtual void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) {} + virtual void allowLanguageTextInput(LLPreeditor *preeditor, bool b) {} virtual void setLanguageTextInput( const LLCoordGL & pos ) {}; virtual void updateLanguageTextInputArea() {} virtual void interruptLanguageTextInput() {} @@ -209,21 +206,21 @@ public: virtual S32 getRefreshRate() { return mRefreshRate; } protected: - LLWindow(LLWindowCallbacks* callbacks, BOOL fullscreen, U32 flags); + LLWindow(LLWindowCallbacks* callbacks, bool fullscreen, U32 flags); virtual ~LLWindow(); // Defaults to true - virtual BOOL isValid(); + virtual bool isValid(); // Defaults to true - virtual BOOL canDelete(); + virtual bool canDelete(); - virtual BOOL setSizeImpl(LLCoordScreen size) = 0; - virtual BOOL setSizeImpl(LLCoordWindow size) = 0; + virtual bool setSizeImpl(LLCoordScreen size) = 0; + virtual bool setSizeImpl(LLCoordWindow size) = 0; protected: LLWindowCallbacks* mCallbacks; - BOOL mPostQuit; // should this window post a quit message when destroyed? - BOOL mFullscreen; + bool mPostQuit; // should this window post a quit message when destroyed? + bool mFullscreen; S32 mFullscreenWidth; S32 mFullscreenHeight; S32 mFullscreenBits; @@ -232,11 +229,11 @@ protected: S32 mNumSupportedResolutions; ECursorType mCurrentCursor; ECursorType mNextCursor; - BOOL mCursorHidden; + bool mCursorHidden; S32 mBusyCount; // how deep is the "cursor busy" stack? - BOOL mIsMouseClipping; // Is this window currently clipping the mouse + bool mIsMouseClipping; // Is this window currently clipping the mouse ESwapMethod mSwapMethod; - BOOL mHideCursorPermanent; + bool mHideCursorPermanent; U32 mFlags; U16 mHighSurrogate; S32 mMinWindowWidth; @@ -281,20 +278,20 @@ protected: virtual void updateImpl(const std::string& string) = 0; virtual void hideImpl() = 0; - static BOOL sVisible; + static bool sVisible; }; // Platform-neutral for accessing the platform specific message box S32 OSMessageBox(const std::string& text, const std::string& caption, U32 type); -const U32 OSMB_OK = 0; -const U32 OSMB_OKCANCEL = 1; -const U32 OSMB_YESNO = 2; +constexpr U32 OSMB_OK = 0; +constexpr U32 OSMB_OKCANCEL = 1; +constexpr U32 OSMB_YESNO = 2; -const S32 OSBTN_YES = 0; -const S32 OSBTN_NO = 1; -const S32 OSBTN_OK = 2; -const S32 OSBTN_CANCEL = 3; +constexpr S32 OSBTN_YES = 0; +constexpr S32 OSBTN_NO = 1; +constexpr S32 OSBTN_OK = 2; +constexpr S32 OSBTN_CANCEL = 3; // // LLWindowManager @@ -307,29 +304,26 @@ public: LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, U32 flags = 0, - BOOL fullscreen = FALSE, - BOOL clearBg = FALSE, - BOOL enable_vsync = FALSE, - BOOL use_gl = TRUE, - BOOL ignore_pixel_depth = FALSE, + bool fullscreen = false, + bool clearBg = false, + bool enable_vsync = false, + bool use_gl = true, + bool ignore_pixel_depth = false, U32 fsaa_samples = 0, U32 max_cores = 0, - U32 max_vram = 0, F32 max_gl_version = 4.6f); - static BOOL destroyWindow(LLWindow* window); - static BOOL isWindowValid(LLWindow *window); + static bool destroyWindow(LLWindow* window); + static bool isWindowValid(LLWindow *window); }; // // helper funcs // -extern BOOL gDebugWindowProc; +extern bool gDebugWindowProc; // Protocols, like "http" and "https" we support in URLs extern const S32 gURLProtocolWhitelistCount; extern const std::string gURLProtocolWhitelist[]; //extern const std::string gURLProtocolWhitelistHandler[]; -void simpleEscapeString ( std::string& stringIn ); - #endif // _LL_window_h_ diff --git a/indra/llwindow/llwindowcallbacks.cpp b/indra/llwindow/llwindowcallbacks.cpp index a43d281d4c..c160382c17 100644 --- a/indra/llwindow/llwindowcallbacks.cpp +++ b/indra/llwindow/llwindowcallbacks.cpp @@ -32,35 +32,35 @@ // LLWindowCallbacks // -BOOL LLWindowCallbacks::handleTranslatedKeyDown(const KEY key, const MASK mask, BOOL repeated) +bool LLWindowCallbacks::handleTranslatedKeyDown(const KEY key, const MASK mask, bool repeated) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleTranslatedKeyUp(const KEY key, const MASK mask) +bool LLWindowCallbacks::handleTranslatedKeyUp(const KEY key, const MASK mask) { - return FALSE; + return false; } -void LLWindowCallbacks::handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level) +void LLWindowCallbacks::handleScanKey(KEY key, bool key_down, bool key_up, bool key_level) { } -BOOL LLWindowCallbacks::handleUnicodeChar(llwchar uni_char, MASK mask) +bool LLWindowCallbacks::handleUnicodeChar(llwchar uni_char, MASK mask) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask) +bool LLWindowCallbacks::handleMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask) +bool LLWindowCallbacks::handleMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask) { - return FALSE; + return false; } void LLWindowCallbacks::handleMouseLeave(LLWindow *window) @@ -68,54 +68,54 @@ void LLWindowCallbacks::handleMouseLeave(LLWindow *window) return; } -BOOL LLWindowCallbacks::handleCloseRequest(LLWindow *window) +bool LLWindowCallbacks::handleCloseRequest(LLWindow *window) { //allow the window to close - return TRUE; + return true; } void LLWindowCallbacks::handleQuit(LLWindow *window) { } -BOOL LLWindowCallbacks::handleRightMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask) +bool LLWindowCallbacks::handleRightMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleRightMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask) +bool LLWindowCallbacks::handleRightMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleMiddleMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask) +bool LLWindowCallbacks::handleMiddleMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleMiddleMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask) +bool LLWindowCallbacks::handleMiddleMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleOtherMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask, S32 button) +bool LLWindowCallbacks::handleOtherMouseDown(LLWindow *window, const LLCoordGL pos, MASK mask, S32 button) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleOtherMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask, S32 button) +bool LLWindowCallbacks::handleOtherMouseUp(LLWindow *window, const LLCoordGL pos, MASK mask, S32 button) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleActivate(LLWindow *window, BOOL activated) +bool LLWindowCallbacks::handleActivate(LLWindow *window, bool activated) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleActivateApp(LLWindow *window, BOOL activating) +bool LLWindowCallbacks::handleActivateApp(LLWindow *window, bool activating) { - return FALSE; + return false; } void LLWindowCallbacks::handleMouseMove(LLWindow *window, const LLCoordGL pos, MASK mask) @@ -151,15 +151,15 @@ void LLWindowCallbacks::handleMenuSelect(LLWindow *window, const S32 menu_item) { } -BOOL LLWindowCallbacks::handlePaint(LLWindow *window, const S32 x, const S32 y, +bool LLWindowCallbacks::handlePaint(LLWindow *window, const S32 x, const S32 y, const S32 width, const S32 height) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleDoubleClick(LLWindow *window, const LLCoordGL pos, MASK mask) +bool LLWindowCallbacks::handleDoubleClick(LLWindow *window, const LLCoordGL pos, MASK mask) { - return FALSE; + return false; } void LLWindowCallbacks::handleWindowBlock(LLWindow *window) @@ -179,24 +179,24 @@ LLWindowCallbacks::DragNDropResult LLWindowCallbacks::handleDragNDrop(LLWindow * return LLWindowCallbacks::DND_NONE; } -BOOL LLWindowCallbacks::handleTimerEvent(LLWindow *window) +bool LLWindowCallbacks::handleTimerEvent(LLWindow *window) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleDeviceChange(LLWindow *window) +bool LLWindowCallbacks::handleDeviceChange(LLWindow *window) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height) +bool LLWindowCallbacks::handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height) { - return FALSE; + return false; } -BOOL LLWindowCallbacks::handleWindowDidChangeScreen(LLWindow *window) +bool LLWindowCallbacks::handleWindowDidChangeScreen(LLWindow *window) { - return FALSE; + return false; } void LLWindowCallbacks::handlePingWatchdog(LLWindow *window, const char * msg) diff --git a/indra/llwindow/llwindowcallbacks.h b/indra/llwindow/llwindowcallbacks.h index d5681400a1..63b585231f 100644 --- a/indra/llwindow/llwindowcallbacks.h +++ b/indra/llwindow/llwindowcallbacks.h @@ -33,26 +33,26 @@ class LLWindowCallbacks { public: virtual ~LLWindowCallbacks() {} - virtual BOOL handleTranslatedKeyDown(KEY key, MASK mask, BOOL repeated); - virtual BOOL handleTranslatedKeyUp(KEY key, MASK mask); - virtual void handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level); - virtual BOOL handleUnicodeChar(llwchar uni_char, MASK mask); + virtual bool handleTranslatedKeyDown(KEY key, MASK mask, bool repeated); + virtual bool handleTranslatedKeyUp(KEY key, MASK mask); + virtual void handleScanKey(KEY key, bool key_down, bool key_up, bool key_level); + virtual bool handleUnicodeChar(llwchar uni_char, MASK mask); - virtual BOOL handleMouseDown(LLWindow *window, LLCoordGL pos, MASK mask); - virtual BOOL handleMouseUp(LLWindow *window, LLCoordGL pos, MASK mask); + virtual bool handleMouseDown(LLWindow *window, LLCoordGL pos, MASK mask); + virtual bool handleMouseUp(LLWindow *window, LLCoordGL pos, MASK mask); virtual void handleMouseLeave(LLWindow *window); - // return TRUE to allow window to close, which will then cause handleQuit to be called - virtual BOOL handleCloseRequest(LLWindow *window); + // return true to allow window to close, which will then cause handleQuit to be called + virtual bool handleCloseRequest(LLWindow *window); // window is about to be destroyed, clean up your business virtual void handleQuit(LLWindow *window); - virtual BOOL handleRightMouseDown(LLWindow *window, LLCoordGL pos, MASK mask); - virtual BOOL handleRightMouseUp(LLWindow *window, LLCoordGL pos, MASK mask); - virtual BOOL handleMiddleMouseDown(LLWindow *window, LLCoordGL pos, MASK mask); - virtual BOOL handleMiddleMouseUp(LLWindow *window, LLCoordGL pos, MASK mask); - virtual BOOL handleOtherMouseDown(LLWindow *window, LLCoordGL pos, MASK mask, S32 button); - virtual BOOL handleOtherMouseUp(LLWindow *window, LLCoordGL pos, MASK mask, S32 button); - virtual BOOL handleActivate(LLWindow *window, BOOL activated); - virtual BOOL handleActivateApp(LLWindow *window, BOOL activating); + virtual bool handleRightMouseDown(LLWindow *window, LLCoordGL pos, MASK mask); + virtual bool handleRightMouseUp(LLWindow *window, LLCoordGL pos, MASK mask); + virtual bool handleMiddleMouseDown(LLWindow *window, LLCoordGL pos, MASK mask); + virtual bool handleMiddleMouseUp(LLWindow *window, LLCoordGL pos, MASK mask); + virtual bool handleOtherMouseDown(LLWindow *window, LLCoordGL pos, MASK mask, S32 button); + virtual bool handleOtherMouseUp(LLWindow *window, LLCoordGL pos, MASK mask, S32 button); + virtual bool handleActivate(LLWindow *window, bool activated); + virtual bool handleActivateApp(LLWindow *window, bool activating); virtual void handleMouseMove(LLWindow *window, LLCoordGL pos, MASK mask); virtual void handleMouseDragged(LLWindow *window, LLCoordGL pos, MASK mask); virtual void handleScrollWheel(LLWindow *window, S32 clicks); @@ -61,15 +61,15 @@ public: virtual void handleFocus(LLWindow *window); virtual void handleFocusLost(LLWindow *window); virtual void handleMenuSelect(LLWindow *window, S32 menu_item); - virtual BOOL handlePaint(LLWindow *window, S32 x, S32 y, S32 width, S32 height); - virtual BOOL handleDoubleClick(LLWindow *window, LLCoordGL pos, MASK mask); // double-click of left mouse button + virtual bool handlePaint(LLWindow *window, S32 x, S32 y, S32 width, S32 height); + virtual bool handleDoubleClick(LLWindow *window, LLCoordGL pos, MASK mask); // double-click of left mouse button virtual void handleWindowBlock(LLWindow *window); // window is taking over CPU for a while virtual void handleWindowUnblock(LLWindow *window); // window coming back after taking over CPU for a while virtual void handleDataCopy(LLWindow *window, S32 data_type, void *data); - virtual BOOL handleTimerEvent(LLWindow *window); - virtual BOOL handleDeviceChange(LLWindow *window); - virtual BOOL handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height); - virtual BOOL handleWindowDidChangeScreen(LLWindow *window); + virtual bool handleTimerEvent(LLWindow *window); + virtual bool handleDeviceChange(LLWindow *window); + virtual bool handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height); + virtual bool handleWindowDidChangeScreen(LLWindow *window); enum DragNDropAction { DNDA_START_TRACKING = 0,// Start tracking an incoming drag diff --git a/indra/llwindow/llwindowheadless.cpp b/indra/llwindow/llwindowheadless.cpp index bbeb710445..55e5cfd51e 100644 --- a/indra/llwindow/llwindowheadless.cpp +++ b/indra/llwindow/llwindowheadless.cpp @@ -34,8 +34,8 @@ // LLWindowHeadless // LLWindowHeadless::LLWindowHeadless(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, - U32 flags, BOOL fullscreen, BOOL clear_background, - BOOL enable_vsync, BOOL use_gl, BOOL ignore_pixel_depth) + U32 flags, bool fullscreen, bool clear_background, + bool enable_vsync, bool use_gl, bool ignore_pixel_depth) : LLWindow(callbacks, fullscreen, flags) { // Initialize a headless keyboard. diff --git a/indra/llwindow/llwindowheadless.h b/indra/llwindow/llwindowheadless.h index af2cdb63fa..5696b69a59 100644 --- a/indra/llwindow/llwindowheadless.h +++ b/indra/llwindow/llwindowheadless.h @@ -35,10 +35,10 @@ public: /*virtual*/ void show() override {} /*virtual*/ void hide() override {} /*virtual*/ void close() override {} - /*virtual*/ BOOL getVisible() override {return FALSE;} - /*virtual*/ BOOL getMinimized() override {return FALSE;} - /*virtual*/ BOOL getMaximized() override {return FALSE;} - /*virtual*/ BOOL maximize() override {return FALSE;} + /*virtual*/ bool getVisible() override {return false;} + /*virtual*/ bool getMinimized() override {return false;} + /*virtual*/ bool getMaximized() override {return false;} + /*virtual*/ bool maximize() override {return false;} /*virtual*/ void minimize() override {} /*virtual*/ void restore() override {} // TODO: LLWindow::getFullscreen() is (intentionally?) NOT virtual. @@ -46,42 +46,42 @@ public: // mistake to shadow the base-class method with an LLWindowHeadless // override when called on the subclass, yet call the base-class method // when indirecting through a polymorphic pointer or reference? - BOOL getFullscreen() {return FALSE;} - /*virtual*/ BOOL getPosition(LLCoordScreen *position) override {return FALSE;} - /*virtual*/ BOOL getSize(LLCoordScreen *size) override {return FALSE;} - /*virtual*/ BOOL getSize(LLCoordWindow *size) override {return FALSE;} - /*virtual*/ BOOL setPosition(LLCoordScreen position) override {return FALSE;} - /*virtual*/ BOOL setSizeImpl(LLCoordScreen size) override {return FALSE;} - /*virtual*/ BOOL setSizeImpl(LLCoordWindow size) override {return FALSE;} - /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp = NULL) override {return FALSE;} + bool getFullscreen() {return false;} + /*virtual*/ bool getPosition(LLCoordScreen *position) override {return false;} + /*virtual*/ bool getSize(LLCoordScreen *size) override {return false;} + /*virtual*/ bool getSize(LLCoordWindow *size) override {return false;} + /*virtual*/ bool setPosition(LLCoordScreen position) override {return false;} + /*virtual*/ bool setSizeImpl(LLCoordScreen size) override {return false;} + /*virtual*/ bool setSizeImpl(LLCoordWindow size) override {return false;} + /*virtual*/ bool switchContext(bool fullscreen, const LLCoordScreen &size, bool enable_vsync, const LLCoordScreen * const posp = NULL) override {return false;} void* createSharedContext() override { return nullptr; } void makeContextCurrent(void*) override {} void destroySharedContext(void*) override {} /*virtual*/ void toggleVSync(bool enable_vsync) override { } - /*virtual*/ BOOL setCursorPosition(LLCoordWindow position) override {return FALSE;} - /*virtual*/ BOOL getCursorPosition(LLCoordWindow *position) override {return FALSE;} + /*virtual*/ bool setCursorPosition(LLCoordWindow position) override {return false;} + /*virtual*/ bool getCursorPosition(LLCoordWindow *position) override {return false;} #if LL_WINDOWS - /*virtual*/ BOOL getCursorDelta(LLCoordCommon* delta) override { return FALSE; } + /*virtual*/ bool getCursorDelta(LLCoordCommon* delta) override { return false; } #endif /*virtual*/ void showCursor() override {} /*virtual*/ void hideCursor() override {} /*virtual*/ void showCursorFromMouseMove() override {} /*virtual*/ void hideCursorUntilMouseMove() override {} - /*virtual*/ BOOL isCursorHidden() override {return FALSE;} + /*virtual*/ bool isCursorHidden() override {return false;} /*virtual*/ void updateCursor() override {} //virtual ECursorType getCursor() override { return mCurrentCursor; } /*virtual*/ void captureMouse() override {} /*virtual*/ void releaseMouse() override {} - /*virtual*/ void setMouseClipping( BOOL b ) override {} - /*virtual*/ BOOL isClipboardTextAvailable() override {return FALSE; } - /*virtual*/ BOOL pasteTextFromClipboard(LLWString &dst) override {return FALSE; } - /*virtual*/ BOOL copyTextToClipboard(const LLWString &src) override {return FALSE; } + /*virtual*/ void setMouseClipping( bool b ) override {} + /*virtual*/ bool isClipboardTextAvailable() override {return false; } + /*virtual*/ bool pasteTextFromClipboard(LLWString &dst) override {return false; } + /*virtual*/ bool copyTextToClipboard(const LLWString &src) override {return false; } /*virtual*/ void flashIcon(F32 seconds) override {} /*virtual*/ F32 getGamma() override {return 1.0f; } - /*virtual*/ BOOL setGamma(const F32 gamma) override {return FALSE; } // Set the gamma + /*virtual*/ bool setGamma(const F32 gamma) override {return false; } // Set the gamma /*virtual*/ void setFSAASamples(const U32 fsaa_samples) override { } /*virtual*/ U32 getFSAASamples() override { return 0; } - /*virtual*/ BOOL restoreGamma() override {return FALSE; } // Restore original gamma table (before updating gamma) + /*virtual*/ bool restoreGamma() override {return false; } // Restore original gamma table (before updating gamma) //virtual ESwapMethod getSwapMethod() override { return mSwapMethod; } /*virtual*/ void gatherInput() override {} /*virtual*/ void delayInputProcessing() override {} @@ -89,20 +89,18 @@ public: // handy coordinate space conversion routines - /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to) override { return FALSE; } - /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to) override { return FALSE; } - /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordGL *to) override { return FALSE; } - /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordWindow *to) override { return FALSE; } - /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordGL *to) override { return FALSE; } - /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordScreen *to) override { return FALSE; } + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordWindow *to) override { return false; } + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordScreen *to) override { return false; } + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordGL *to) override { return false; } + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordWindow *to) override { return false; } + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordGL *to) override { return false; } + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordScreen *to) override { return false; } /*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions) override { return NULL; } /*virtual*/ F32 getNativeAspectRatio() override { return 1.0f; } /*virtual*/ F32 getPixelAspectRatio() override { return 1.0f; } /*virtual*/ void setNativeAspectRatio(F32 ratio) override {} - U32 getAvailableVRAMMegabytes() override { return 4096; } - /*virtual*/ void *getPlatformWindow() override { return 0; } /*virtual*/ void bringToFront() override {} @@ -110,8 +108,8 @@ public: const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, - U32 flags, BOOL fullscreen, BOOL clear_background, - BOOL enable_vsync, BOOL use_gl, BOOL ignore_pixel_depth); + U32 flags, bool fullscreen, bool clear_background, + bool enable_vsync, bool use_gl, bool ignore_pixel_depth); virtual ~LLWindowHeadless(); private: diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index 31dc83493e..d9d8bfce1f 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -30,6 +30,7 @@ #include <map> #include <vector> +#include <deque> //fir CGSize #include <CoreGraphics/CGGeometry.h> @@ -37,7 +38,7 @@ typedef std::vector<std::pair<int, bool> > segment_t; typedef std::vector<int> segment_lengths; -typedef std::vector<int> segment_standouts; +typedef std::deque<bool> segment_standouts; struct attributedStringInfo { segment_lengths seg_lengths; diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index 453905b19b..80001b14ee 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -50,8 +50,8 @@ #include <IOKit/hid/IOHIDLib.h> #include <IOKit/usb/IOUSBLib.h> -extern BOOL gDebugWindowProc; -BOOL gHiDPISupport = TRUE; +extern bool gDebugWindowProc; +bool gHiDPISupport = true; const S32 BITS_PER_PIXEL = 32; const S32 MAX_NUM_RESOLUTIONS = 32; @@ -66,11 +66,11 @@ namespace // LLWindowMacOSX // -BOOL LLWindowMacOSX::sUseMultGL = FALSE; +bool LLWindowMacOSX::sUseMultGL = false; // Cross-platform bits: -BOOL check_for_card(const char* RENDERER, const char* bad_card) +bool check_for_card(const char* RENDERER, const char* bad_card) { if (!strnicmp(RENDERER, bad_card, strlen(bad_card))) { @@ -91,15 +91,15 @@ BOOL check_for_card(const char* RENDERER, const char* bad_card) S32 button = OSMessageBox(buffer.c_str(), "Unsupported video card", OSMB_YESNO); if (OSBTN_YES == button) { - return FALSE; + return false; } else { - return TRUE; + return true; } } - return FALSE; + return false; } // Switch to determine whether we capture all displays, or just the main one. @@ -119,9 +119,9 @@ static LLWindowMacOSX *gWindowImplementation = NULL; LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, U32 flags, - BOOL fullscreen, BOOL clearBg, - BOOL enable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, + bool fullscreen, bool clearBg, + bool enable_vsync, bool use_gl, + bool ignore_pixel_depth, U32 fsaa_samples) : LLWindow(NULL, fullscreen, flags) { @@ -143,21 +143,21 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, mContext = NULL; mPixelFormat = NULL; mDisplay = CGMainDisplayID(); - mSimulatedRightClick = FALSE; + mSimulatedRightClick = false; mLastModifiers = 0; - mHandsOffEvents = FALSE; - mCursorDecoupled = FALSE; + mHandsOffEvents = false; + mCursorDecoupled = false; mCursorLastEventDeltaX = 0; mCursorLastEventDeltaY = 0; - mCursorIgnoreNextDelta = FALSE; - mNeedsResize = FALSE; + mCursorIgnoreNextDelta = false; + mNeedsResize = false; mOverrideAspectRatio = 0.f; - mMaximized = FALSE; - mMinimized = FALSE; - mLanguageTextInputAllowed = FALSE; + mMaximized = false; + mMinimized = false; + mLanguageTextInputAllowed = false; mPreeditor = NULL; mFSAASamples = fsaa_samples; - mForceRebuild = FALSE; + mForceRebuild = false; // Get the original aspect ratio of the main device. mOriginalAspectRatio = (double)CGDisplayPixelsWide(mDisplay) / (double)CGDisplayPixelsHigh(mDisplay); @@ -197,7 +197,7 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks, initCursors(); setCursor( UI_CURSOR_ARROW ); - allowLanguageTextInput(NULL, FALSE); + allowLanguageTextInput(NULL, false); } mCallbacks = callbacks; @@ -289,7 +289,7 @@ void callRightMouseDown(float *pos, MASK mask) LLCoordGL outCoords; outCoords.mX = ll_round(pos[0]); outCoords.mY = ll_round(pos[1]); - gWindowImplementation->getCallbacks()->handleRightMouseDown(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + gWindowImplementation->getCallbacks()->handleRightMouseDown(gWindowImplementation, outCoords, gKeyboard->currentMask(true)); } void callRightMouseUp(float *pos, MASK mask) @@ -302,7 +302,7 @@ void callRightMouseUp(float *pos, MASK mask) LLCoordGL outCoords; outCoords.mX = ll_round(pos[0]); outCoords.mY = ll_round(pos[1]); - gWindowImplementation->getCallbacks()->handleRightMouseUp(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + gWindowImplementation->getCallbacks()->handleRightMouseUp(gWindowImplementation, outCoords, gKeyboard->currentMask(true)); } void callLeftMouseDown(float *pos, MASK mask) @@ -315,7 +315,7 @@ void callLeftMouseDown(float *pos, MASK mask) LLCoordGL outCoords; outCoords.mX = ll_round(pos[0]); outCoords.mY = ll_round(pos[1]); - gWindowImplementation->getCallbacks()->handleMouseDown(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + gWindowImplementation->getCallbacks()->handleMouseDown(gWindowImplementation, outCoords, gKeyboard->currentMask(true)); } void callLeftMouseUp(float *pos, MASK mask) @@ -328,7 +328,7 @@ void callLeftMouseUp(float *pos, MASK mask) LLCoordGL outCoords; outCoords.mX = ll_round(pos[0]); outCoords.mY = ll_round(pos[1]); - gWindowImplementation->getCallbacks()->handleMouseUp(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + gWindowImplementation->getCallbacks()->handleMouseUp(gWindowImplementation, outCoords, gKeyboard->currentMask(true)); } @@ -342,7 +342,7 @@ void callDoubleClick(float *pos, MASK mask) LLCoordGL outCoords; outCoords.mX = ll_round(pos[0]); outCoords.mY = ll_round(pos[1]); - gWindowImplementation->getCallbacks()->handleDoubleClick(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + gWindowImplementation->getCallbacks()->handleDoubleClick(gWindowImplementation, outCoords, gKeyboard->currentMask(true)); } void callResize(unsigned int width, unsigned int height) @@ -362,7 +362,7 @@ void callMouseMoved(float *pos, MASK mask) gWindowImplementation->getMouseDeltas(deltas); outCoords.mX += deltas[0]; outCoords.mY += deltas[1]; - gWindowImplementation->getCallbacks()->handleMouseMove(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + gWindowImplementation->getCallbacks()->handleMouseMove(gWindowImplementation, outCoords, gKeyboard->currentMask(true)); //gWindowImplementation->getCallbacks()->handleScrollWheel(gWindowImplementation, 0); } @@ -375,7 +375,7 @@ void callMouseDragged(float *pos, MASK mask) gWindowImplementation->getMouseDeltas(deltas); outCoords.mX += deltas[0]; outCoords.mY += deltas[1]; - gWindowImplementation->getCallbacks()->handleMouseDragged(gWindowImplementation, outCoords, gKeyboard->currentMask(TRUE)); + gWindowImplementation->getCallbacks()->handleMouseDragged(gWindowImplementation, outCoords, gKeyboard->currentMask(true)); } void callScrollMoved(float deltaX, float deltaY) @@ -617,7 +617,7 @@ void LLWindowMacOSX::updateMouseDeltas(float* deltas) { mCursorLastEventDeltaX = 0; mCursorLastEventDeltaY = 0; - mCursorIgnoreNextDelta = FALSE; + mCursorIgnoreNextDelta = false; } } else { mCursorLastEventDeltaX = 0; @@ -631,7 +631,7 @@ void LLWindowMacOSX::getMouseDeltas(float* delta) delta[1] = mCursorLastEventDeltaY; } -BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL enable_vsync) +bool LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits, bool fullscreen, bool enable_vsync) { mFullscreen = fullscreen; @@ -690,7 +690,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits if (err != kCGLNoError) { setupFailure("Can't activate GL rendering context", "Error", OSMB_OK); - return FALSE; + return false; } } @@ -723,15 +723,15 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits } makeFirstResponder(mWindow, mGLView); - return TRUE; + return true; } // We only support OS X 10.7's fullscreen app mode which is literally a full screen window that fills a virtual desktop. // This makes this method obsolete. -BOOL LLWindowMacOSX::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp) +bool LLWindowMacOSX::switchContext(bool fullscreen, const LLCoordScreen &size, bool enable_vsync, const LLCoordScreen * const posp) { - return FALSE; + return false; } void LLWindowMacOSX::destroyContext() @@ -801,13 +801,13 @@ void LLWindowMacOSX::show() void LLWindowMacOSX::hide() { - setMouseClipping(FALSE); + setMouseClipping(false); } //virtual void LLWindowMacOSX::minimize() { - setMouseClipping(FALSE); + setMouseClipping(false); showCursor(); } @@ -829,48 +829,48 @@ void LLWindowMacOSX::close() // } // Make sure cursor is visible and we haven't mangled the clipping state. - setMouseClipping(FALSE); + setMouseClipping(false); showCursor(); destroyContext(); } -BOOL LLWindowMacOSX::isValid() +bool LLWindowMacOSX::isValid() { if(mFullscreen) { - return(TRUE); + return(true); } return (mWindow != NULL); } -BOOL LLWindowMacOSX::getVisible() +bool LLWindowMacOSX::getVisible() { - BOOL result = FALSE; + bool result = false; if(mFullscreen) { - result = TRUE; + result = true; }if (mWindow) { - result = TRUE; + result = true; } return(result); } -BOOL LLWindowMacOSX::getMinimized() +bool LLWindowMacOSX::getMinimized() { return mMinimized; } -BOOL LLWindowMacOSX::getMaximized() +bool LLWindowMacOSX::getMaximized() { return mMaximized; } -BOOL LLWindowMacOSX::maximize() +bool LLWindowMacOSX::maximize() { if (mWindow && !mMaximized) { @@ -879,7 +879,7 @@ BOOL LLWindowMacOSX::maximize() return mMaximized; } -BOOL LLWindowMacOSX::getFullscreen() +bool LLWindowMacOSX::getFullscreen() { return mFullscreen; } @@ -889,7 +889,7 @@ void LLWindowMacOSX::gatherInput() updateCursor(); } -BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) +bool LLWindowMacOSX::getPosition(LLCoordScreen *position) { S32 err = -1; @@ -916,7 +916,7 @@ BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) return (err == noErr); } -BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) +bool LLWindowMacOSX::getSize(LLCoordScreen *size) { S32 err = -1; @@ -942,7 +942,7 @@ BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) return (err == noErr); } -BOOL LLWindowMacOSX::getSize(LLCoordWindow *size) +bool LLWindowMacOSX::getSize(LLCoordWindow *size) { S32 err = -1; @@ -970,7 +970,7 @@ BOOL LLWindowMacOSX::getSize(LLCoordWindow *size) return (err == noErr); } -BOOL LLWindowMacOSX::setPosition(const LLCoordScreen position) +bool LLWindowMacOSX::setPosition(const LLCoordScreen position) { if(mWindow) { @@ -978,32 +978,32 @@ BOOL LLWindowMacOSX::setPosition(const LLCoordScreen position) setWindowPos(mWindow, pos); } - return TRUE; + return true; } -BOOL LLWindowMacOSX::setSizeImpl(const LLCoordScreen size) +bool LLWindowMacOSX::setSizeImpl(const LLCoordScreen size) { if(mWindow) { LLCoordWindow to; convertCoords(size, &to); setWindowSize(mWindow, to.mX, to.mY); - return TRUE; + return true; } - return FALSE; + return false; } -BOOL LLWindowMacOSX::setSizeImpl(const LLCoordWindow size) +bool LLWindowMacOSX::setSizeImpl(const LLCoordWindow size) { if (mWindow) { const int titlePadding = 22; setWindowSize(mWindow, size.mX, size.mY + titlePadding); - return TRUE; + return true; } - return FALSE; + return false; } void LLWindowMacOSX::swapBuffers() @@ -1058,16 +1058,16 @@ U32 LLWindowMacOSX::getFSAASamples() void LLWindowMacOSX::setFSAASamples(const U32 samples) { mFSAASamples = samples; - mForceRebuild = TRUE; + mForceRebuild = true; } -BOOL LLWindowMacOSX::restoreGamma() +bool LLWindowMacOSX::restoreGamma() { CGDisplayRestoreColorSyncSettings(); return true; } -BOOL LLWindowMacOSX::setGamma(const F32 gamma) +bool LLWindowMacOSX::setGamma(const F32 gamma) { CGGammaValue redMin; CGGammaValue redMax; @@ -1115,7 +1115,7 @@ BOOL LLWindowMacOSX::setGamma(const F32 gamma) return true; } -BOOL LLWindowMacOSX::isCursorHidden() +bool LLWindowMacOSX::isCursorHidden() { return mCursorHidden; } @@ -1123,31 +1123,31 @@ BOOL LLWindowMacOSX::isCursorHidden() // Constrains the mouse to the window. -void LLWindowMacOSX::setMouseClipping( BOOL b ) +void LLWindowMacOSX::setMouseClipping( bool b ) { // Just stash the requested state. We'll simulate this when the cursor is hidden by decoupling. mIsMouseClipping = b; if(b) { - // LL_INFOS() << "setMouseClipping(TRUE)" << LL_ENDL; + // LL_INFOS() << "setMouseClipping(true)" << LL_ENDL; } else { - // LL_INFOS() << "setMouseClipping(FALSE)" << LL_ENDL; + // LL_INFOS() << "setMouseClipping(false)" << LL_ENDL; } adjustCursorDecouple(); } -BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position) +bool LLWindowMacOSX::setCursorPosition(const LLCoordWindow position) { - BOOL result = FALSE; + bool result = false; LLCoordScreen screen_pos; if (!convertCoords(position, &screen_pos)) { - return FALSE; + return false; } CGPoint newPosition; @@ -1160,7 +1160,7 @@ BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position) CGSetLocalEventsSuppressionInterval(0.0); if(CGWarpMouseCursorPosition(newPosition) == noErr) { - result = TRUE; + result = true; } // Under certain circumstances, this will trigger us to decouple the cursor. @@ -1177,13 +1177,13 @@ BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position) return result; } -BOOL LLWindowMacOSX::getCursorPosition(LLCoordWindow *position) +bool LLWindowMacOSX::getCursorPosition(LLCoordWindow *position) { float cursor_point[2]; LLCoordScreen screen_pos; if(mWindow == NULL) - return FALSE; + return false; getCursorPos(mWindow, cursor_point); @@ -1206,7 +1206,7 @@ BOOL LLWindowMacOSX::getCursorPosition(LLCoordWindow *position) position->mX = cursor_point[0] * scale; position->mY = cursor_point[1] * scale; - return TRUE; + return true; } void LLWindowMacOSX::adjustCursorDecouple(bool warpingMouse) @@ -1221,7 +1221,7 @@ void LLWindowMacOSX::adjustCursorDecouple(bool warpingMouse) // LL_INFOS() << "adjustCursorDecouple: decoupling cursor" << LL_ENDL; CGAssociateMouseAndMouseCursorPosition(false); mCursorDecoupled = true; - mCursorIgnoreNextDelta = TRUE; + mCursorIgnoreNextDelta = true; } } } @@ -1259,20 +1259,10 @@ F32 LLWindowMacOSX::getNativeAspectRatio() F32 LLWindowMacOSX::getPixelAspectRatio() { - //OS X always enforces a 1:1 pixel aspect ratio, regardless of video mode + //macOS always enforces a 1:1 pixel aspect ratio, regardless of video mode return 1.f; } -U32 LLWindowMacOSX::getAvailableVRAMMegabytes() { - // MTL (and MoltenVK) has some additional gpu data, such as recommendedMaxWorkingSetSize and currentAllocatedSize. - // But these are not available for OpenGL and/or our current mimimum OS version. - // So we will estimate. - static const U32 mb = 1024*1024; - // We're asked for total available gpu memory, but we only have allocation info on texture usage. So estimate by doubling that. - static const U32 total_factor = 2; // estimated total/textures - return gGLManager.mVRAM - (LLImageGL::getTextureBytesAllocated() * total_factor/mb); -} - //static SInt32 oldWindowLevel; // MBW -- XXX -- There's got to be a better way than this. Find it, please... @@ -1291,17 +1281,17 @@ void LLWindowMacOSX::afterDialog() void LLWindowMacOSX::flashIcon(F32 seconds) { - // For consistency with OS X conventions, the number of seconds given is ignored and + // For consistency with macOS conventions, the number of seconds given is ignored and // left up to the OS (which will actually bounce it for one second). requestUserAttention(); } -BOOL LLWindowMacOSX::isClipboardTextAvailable() +bool LLWindowMacOSX::isClipboardTextAvailable() { return pasteBoardAvailable(); } -BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst) +bool LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst) { unsigned short* pboard_data = copyFromPBoard(); // must free returned data llutf16string str(pboard_data); @@ -1316,9 +1306,9 @@ BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst) } } -BOOL LLWindowMacOSX::copyTextToClipboard(const LLWString &s) +bool LLWindowMacOSX::copyTextToClipboard(const LLWString &s) { - BOOL result = false; + bool result = false; llutf16string utf16str = wstring_to_utf16str(s); result = copyToPBoard(utf16str.data(), utf16str.length()); @@ -1328,7 +1318,7 @@ BOOL LLWindowMacOSX::copyTextToClipboard(const LLWString &s) // protected -BOOL LLWindowMacOSX::resetDisplayResolution() +bool LLWindowMacOSX::resetDisplayResolution() { // This is only called from elsewhere in this class, and it's not used by the Mac implementation. return true; @@ -1361,13 +1351,13 @@ LLWindow::LLWindowResolution* LLWindowMacOSX::getSupportedResolutions(S32 &num_r if(bits == BITS_PER_PIXEL && width >= 800 && height >= 600) { - BOOL resolution_exists = FALSE; + bool resolution_exists = false; for(S32 i = 0; i < mNumSupportedResolutions; i++) { if (mSupportedResolutions[i].mWidth == width && mSupportedResolutions[i].mHeight == height) { - resolution_exists = TRUE; + resolution_exists = true; } } if (!resolution_exists) @@ -1386,21 +1376,21 @@ LLWindow::LLWindowResolution* LLWindowMacOSX::getSupportedResolutions(S32 &num_r return mSupportedResolutions; } -BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordWindow *to) +bool LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordWindow *to) { to->mX = from.mX; to->mY = from.mY; - return TRUE; + return true; } -BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordGL* to) +bool LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordGL* to) { to->mX = from.mX; to->mY = from.mY; - return TRUE; + return true; } -BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordWindow* to) +bool LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordWindow* to) { if(mWindow) { @@ -1414,12 +1404,12 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordWindow* to) to->mX = mouse_point[0]; to->mY = mouse_point[1]; - return TRUE; + return true; } - return FALSE; + return false; } -BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) +bool LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) { if(mWindow) { @@ -1433,19 +1423,19 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) to->mX = mouse_point[0]; to->mY = mouse_point[1]; - return TRUE; + return true; } - return FALSE; + return false; } -BOOL LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordGL *to) +bool LLWindowMacOSX::convertCoords(LLCoordScreen from, LLCoordGL *to) { LLCoordWindow window_coord; return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); } -BOOL LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordScreen *to) +bool LLWindowMacOSX::convertCoords(LLCoordGL from, LLCoordScreen *to) { LLCoordWindow window_coord; @@ -1707,8 +1697,8 @@ void LLWindowMacOSX::hideCursor() if(!mCursorHidden) { // LL_INFOS() << "hideCursor: hiding" << LL_ENDL; - mCursorHidden = TRUE; - mHideCursorPermanent = TRUE; + mCursorHidden = true; + mHideCursorPermanent = true; hideNSCursor(); } else @@ -1724,8 +1714,8 @@ void LLWindowMacOSX::showCursor() if(mCursorHidden || !isCGCursorVisible()) { // LL_INFOS() << "showCursor: showing" << LL_ENDL; - mCursorHidden = FALSE; - mHideCursorPermanent = FALSE; + mCursorHidden = false; + mHideCursorPermanent = false; showNSCursor(); } else @@ -1749,7 +1739,7 @@ void LLWindowMacOSX::hideCursorUntilMouseMove() if (!mHideCursorPermanent) { hideCursor(); - mHideCursorPermanent = FALSE; + mHideCursorPermanent = false; } } @@ -2350,9 +2340,9 @@ LLSD LLWindowMacOSX::getNativeKeyData() return result; } -BOOL LLWindowMacOSX::dialogColorPicker( F32 *r, F32 *g, F32 *b) +bool LLWindowMacOSX::dialogColorPicker( F32 *r, F32 *g, F32 *b) { - BOOL retval = FALSE; + bool retval = false; OSErr error = noErr; NColorPickerInfo info; @@ -2409,12 +2399,12 @@ static long getDictLong (CFDictionaryRef refDict, CFStringRef key) return int_value; // otherwise return the long value } -void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) +void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, bool b) { if (preeditor != mPreeditor && !b) { // This condition may occur by a call to - // setEnabled(BOOL) against LLTextEditor or LLLineEditor + // setEnabled(bool) against LLTextEditor or LLLineEditor // when the control is not focused. // We need to silently ignore the case so that // the language input status of the focused control diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index 5e09e58a99..f5b6441746 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -47,71 +47,68 @@ public: void show() override; void hide() override; void close() override; - BOOL getVisible() override; - BOOL getMinimized() override; - BOOL getMaximized() override; - BOOL maximize() override; + bool getVisible() override; + bool getMinimized() override; + bool getMaximized() override; + bool maximize() override; void minimize() override; void restore() override; - BOOL getFullscreen(); - BOOL getPosition(LLCoordScreen *position) override; - BOOL getSize(LLCoordScreen *size) override; - BOOL getSize(LLCoordWindow *size) override; - BOOL setPosition(LLCoordScreen position) override; - BOOL setSizeImpl(LLCoordScreen size) override; - BOOL setSizeImpl(LLCoordWindow size) override; - BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp = NULL) override; - BOOL setCursorPosition(LLCoordWindow position) override; - BOOL getCursorPosition(LLCoordWindow *position) override; + bool getFullscreen(); + bool getPosition(LLCoordScreen *position) override; + bool getSize(LLCoordScreen *size) override; + bool getSize(LLCoordWindow *size) override; + bool setPosition(LLCoordScreen position) override; + bool setSizeImpl(LLCoordScreen size) override; + bool setSizeImpl(LLCoordWindow size) override; + bool switchContext(bool fullscreen, const LLCoordScreen &size, bool enable_vsync, const LLCoordScreen * const posp = NULL) override; + bool setCursorPosition(LLCoordWindow position) override; + bool getCursorPosition(LLCoordWindow *position) override; void showCursor() override; void hideCursor() override; void showCursorFromMouseMove() override; void hideCursorUntilMouseMove() override; - BOOL isCursorHidden() override; + bool isCursorHidden() override; void updateCursor() override; ECursorType getCursor() const override; void captureMouse() override; void releaseMouse() override; - void setMouseClipping( BOOL b ) override; - BOOL isClipboardTextAvailable() override; - BOOL pasteTextFromClipboard(LLWString &dst) override; - BOOL copyTextToClipboard(const LLWString & src) override; + void setMouseClipping( bool b ) override; + bool isClipboardTextAvailable() override; + bool pasteTextFromClipboard(LLWString &dst) override; + bool copyTextToClipboard(const LLWString & src) override; void flashIcon(F32 seconds) override; F32 getGamma() override; - BOOL setGamma(const F32 gamma) override; // Set the gamma + bool setGamma(const F32 gamma) override; // Set the gamma U32 getFSAASamples() override; void setFSAASamples(const U32 fsaa_samples) override; - BOOL restoreGamma() override; // Restore original gamma table (before updating gamma) + bool restoreGamma() override; // Restore original gamma table (before updating gamma) ESwapMethod getSwapMethod() override { return mSwapMethod; } void gatherInput() override; void delayInputProcessing() override {}; void swapBuffers() override; // handy coordinate space conversion routines - BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to) override; - BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to) override; - BOOL convertCoords(LLCoordWindow from, LLCoordGL *to) override; - BOOL convertCoords(LLCoordGL from, LLCoordWindow *to) override; - BOOL convertCoords(LLCoordScreen from, LLCoordGL *to) override; - BOOL convertCoords(LLCoordGL from, LLCoordScreen *to) override; + bool convertCoords(LLCoordScreen from, LLCoordWindow *to) override; + bool convertCoords(LLCoordWindow from, LLCoordScreen *to) override; + bool convertCoords(LLCoordWindow from, LLCoordGL *to) override; + bool convertCoords(LLCoordGL from, LLCoordWindow *to) override; + bool convertCoords(LLCoordScreen from, LLCoordGL *to) override; + bool convertCoords(LLCoordGL from, LLCoordScreen *to) override; LLWindowResolution* getSupportedResolutions(S32 &num_resolutions) override; F32 getNativeAspectRatio() override; F32 getPixelAspectRatio() override; void setNativeAspectRatio(F32 ratio) override { mOverrideAspectRatio = ratio; } - // query VRAM usage - /*virtual*/ U32 getAvailableVRAMMegabytes() override; - void beforeDialog() override; void afterDialog() override; - BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b) override; + bool dialogColorPicker(F32 *r, F32 *g, F32 *b) override; void *getPlatformWindow() override; void bringToFront() override {}; - void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) override; + void allowLanguageTextInput(LLPreeditor *preeditor, bool b) override; void interruptLanguageTextInput() override; void spawnWebBrowser(const std::string& escaped_url, bool async) override; F32 getSystemUISize() override; @@ -153,26 +150,26 @@ public: protected: LLWindowMacOSX(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, int x, int y, int width, int height, U32 flags, - BOOL fullscreen, BOOL clearBg, BOOL enable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, + bool fullscreen, bool clearBg, bool enable_vsync, bool use_gl, + bool ignore_pixel_depth, U32 fsaa_samples); ~LLWindowMacOSX(); void initCursors(); - BOOL isValid() override; + bool isValid() override; void moveWindow(const LLCoordScreen& position,const LLCoordScreen& size); // Changes display resolution. Returns true if successful - BOOL setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh); + bool setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh); // Go back to last fullscreen display resolution. - BOOL setFullscreenResolution(); + bool setFullscreenResolution(); // Restore the display resolution to its value before we ran the app. - BOOL resetDisplayResolution(); + bool resetDisplayResolution(); - BOOL shouldPostQuit() { return mPostQuit; } + bool shouldPostQuit() { return mPostQuit; } //Satisfy MAINT-3135 and MAINT-3288 with a flag. /*virtual */ void setOldResize(bool oldresize) override {setResizeMode(oldresize, mGLView); } @@ -186,7 +183,7 @@ protected: // // create or re-create the GL context/window. Called from the constructor and switchContext(). - BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL enable_vsync); + bool createContext(int x, int y, int width, int height, int bits, bool fullscreen, bool enable_vsync); void destroyContext(); void setupFailure(const std::string& text, const std::string& caption, U32 type); void adjustCursorDecouple(bool warpingMouse = false); @@ -214,30 +211,30 @@ protected: LLRect mOldMouseClip; // Screen rect to which the mouse cursor was globally constrained before we changed it in clipMouse() std::string mWindowTitle; double mOriginalAspectRatio; - BOOL mSimulatedRightClick; + bool mSimulatedRightClick; U32 mLastModifiers; - BOOL mHandsOffEvents; // When true, temporarially disable CarbonEvent processing. + bool mHandsOffEvents; // When true, temporarially disable CarbonEvent processing. // Used to allow event processing when putting up dialogs in fullscreen mode. - BOOL mCursorDecoupled; + bool mCursorDecoupled; S32 mCursorLastEventDeltaX; S32 mCursorLastEventDeltaY; - BOOL mCursorIgnoreNextDelta; - BOOL mNeedsResize; // Constructor figured out the window is too big, it needs a resize. + bool mCursorIgnoreNextDelta; + bool mNeedsResize; // Constructor figured out the window is too big, it needs a resize. LLCoordScreen mNeedsResizeSize; F32 mOverrideAspectRatio; - BOOL mMaximized; - BOOL mMinimized; + bool mMaximized; + bool mMinimized; U32 mFSAASamples; - BOOL mForceRebuild; + bool mForceRebuild; S32 mDragOverrideCursor; // Input method management through Text Service Manager. - BOOL mLanguageTextInputAllowed; + bool mLanguageTextInputAllowed; LLPreeditor* mPreeditor; public: - static BOOL sUseMultGL; + static bool sUseMultGL; friend class LLWindowManager; diff --git a/indra/llwindow/llwindowmesaheadless.cpp b/indra/llwindow/llwindowmesaheadless.cpp index 58f8f80d2d..6cbd737ed2 100644 --- a/indra/llwindow/llwindowmesaheadless.cpp +++ b/indra/llwindow/llwindowmesaheadless.cpp @@ -40,8 +40,8 @@ U16 *gMesaBuffer = NULL; // LLWindowMesaHeadless::LLWindowMesaHeadless(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, - U32 flags, BOOL fullscreen, BOOL clearBg, - BOOL disable_vsync, BOOL use_gl, BOOL ignore_pixel_depth) + U32 flags, bool fullscreen, bool clearBg, + bool disable_vsync, bool use_gl, bool ignore_pixel_depth) : LLWindow(callbacks, fullscreen, flags) { if (use_gl) diff --git a/indra/llwindow/llwindowmesaheadless.h b/indra/llwindow/llwindowmesaheadless.h index 9aa376a6db..0bf8c46a30 100644 --- a/indra/llwindow/llwindowmesaheadless.h +++ b/indra/llwindow/llwindowmesaheadless.h @@ -39,38 +39,38 @@ public: /*virtual*/ void show() {}; /*virtual*/ void hide() {}; /*virtual*/ void close() {}; - /*virtual*/ BOOL getVisible() {return FALSE;}; - /*virtual*/ BOOL getMinimized() {return FALSE;}; - /*virtual*/ BOOL getMaximized() {return FALSE;}; - /*virtual*/ BOOL maximize() {return FALSE;}; + /*virtual*/ bool getVisible() {return false;}; + /*virtual*/ bool getMinimized() {return false;}; + /*virtual*/ bool getMaximized() {return false;}; + /*virtual*/ bool maximize() {return false;}; /*virtual*/ void minimize() {}; /*virtual*/ void restore() {}; - /*virtual*/ BOOL getFullscreen() {return FALSE;}; - /*virtual*/ BOOL getPosition(LLCoordScreen *position) {return FALSE;}; - /*virtual*/ BOOL getSize(LLCoordScreen *size) {return FALSE;}; - /*virtual*/ BOOL getSize(LLCoordWindow *size) {return FALSE;}; - /*virtual*/ BOOL setPosition(LLCoordScreen position) {return FALSE;}; - /*virtual*/ BOOL setSizeImpl(LLCoordScreen size) {return FALSE;}; - /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp = NULL) {return FALSE;}; - /*virtual*/ BOOL setCursorPosition(LLCoordWindow position) {return FALSE;}; - /*virtual*/ BOOL getCursorPosition(LLCoordWindow *position) {return FALSE;}; + /*virtual*/ bool getFullscreen() {return false;}; + /*virtual*/ bool getPosition(LLCoordScreen *position) {return false;}; + /*virtual*/ bool getSize(LLCoordScreen *size) {return false;}; + /*virtual*/ bool getSize(LLCoordWindow *size) {return false;}; + /*virtual*/ bool setPosition(LLCoordScreen position) {return false;}; + /*virtual*/ bool setSizeImpl(LLCoordScreen size) {return false;}; + /*virtual*/ bool switchContext(bool fullscreen, const LLCoordScreen &size, bool disable_vsync, const LLCoordScreen * const posp = NULL) {return false;}; + /*virtual*/ bool setCursorPosition(LLCoordWindow position) {return false;}; + /*virtual*/ bool getCursorPosition(LLCoordWindow *position) {return false;}; /*virtual*/ void showCursor() {}; /*virtual*/ void hideCursor() {}; /*virtual*/ void showCursorFromMouseMove() {}; /*virtual*/ void hideCursorUntilMouseMove() {}; - /*virtual*/ BOOL isCursorHidden() {return FALSE;}; + /*virtual*/ bool isCursorHidden() {return false;}; /*virtual*/ void updateCursor() {}; //virtual ECursorType getCursor() { return mCurrentCursor; }; /*virtual*/ void captureMouse() {}; /*virtual*/ void releaseMouse() {}; - /*virtual*/ void setMouseClipping( BOOL b ) {}; - /*virtual*/ BOOL isClipboardTextAvailable() {return FALSE; }; - /*virtual*/ BOOL pasteTextFromClipboard(LLWString &dst) {return FALSE; }; - /*virtual*/ BOOL copyTextToClipboard(const LLWString &src) {return FALSE; }; + /*virtual*/ void setMouseClipping( bool b ) {}; + /*virtual*/ bool isClipboardTextAvailable() {return false; }; + /*virtual*/ bool pasteTextFromClipboard(LLWString &dst) {return false; }; + /*virtual*/ bool copyTextToClipboard(const LLWString &src) {return false; }; /*virtual*/ void flashIcon(F32 seconds) {}; /*virtual*/ F32 getGamma() {return 1.0f; }; - /*virtual*/ BOOL setGamma(const F32 gamma) {return FALSE; }; // Set the gamma - /*virtual*/ BOOL restoreGamma() {return FALSE; }; // Restore original gamma table (before updating gamma) + /*virtual*/ bool setGamma(const F32 gamma) {return false; }; // Set the gamma + /*virtual*/ bool restoreGamma() {return false; }; // Restore original gamma table (before updating gamma) /*virtual*/ void setFSAASamples(const U32 fsaa_samples) { /* FSAA not supported yet on Mesa headless.*/ } /*virtual*/ U32 getFSAASamples() { return 0; } //virtual ESwapMethod getSwapMethod() { return mSwapMethod; } @@ -80,12 +80,12 @@ public: /*virtual*/ void restoreGLContext() {}; // handy coordinate space conversion routines - /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to) { return FALSE; }; - /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to) { return FALSE; }; - /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordGL *to) { return FALSE; }; - /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordWindow *to) { return FALSE; }; - /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordGL *to) { return FALSE; }; - /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordScreen *to) { return FALSE; }; + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordWindow *to) { return false; }; + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordScreen *to) { return false; }; + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordGL *to) { return false; }; + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordWindow *to) { return false; }; + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordGL *to) { return false; }; + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordScreen *to) { return false; }; /*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions) { return NULL; }; /*virtual*/ F32 getNativeAspectRatio() { return 1.0f; }; @@ -97,8 +97,8 @@ public: LLWindowMesaHeadless(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, - U32 flags, BOOL fullscreen, BOOL clearBg, - BOOL disable_vsync, BOOL use_gl, BOOL ignore_pixel_depth); + U32 flags, bool fullscreen, bool clearBg, + bool disable_vsync, bool use_gl, bool ignore_pixel_depth); ~LLWindowMesaHeadless(); private: diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp index 218f953c7f..7433ad6bd2 100644 --- a/indra/llwindow/llwindowsdl.cpp +++ b/indra/llwindow/llwindowsdl.cpp @@ -25,6 +25,8 @@ * $/LicenseInfo$ */ +#if LL_SDL + #include "linden_common.h" #include "llwindowsdl.h" @@ -38,9 +40,12 @@ #include "lldir.h" #include "llfindlocale.h" -#ifdef LL_GLIB -#include <glib.h> -#endif +#if LL_GTK +extern "C" { +# include "gtk/gtk.h" +} +#include <locale.h> +#endif // LL_GTK extern "C" { # include "fontconfig/fontconfig.h" @@ -52,10 +57,9 @@ extern "C" { # include <unistd.h> # include <sys/types.h> # include <sys/wait.h> -# include <stdio.h> #endif // LL_LINUX -extern BOOL gDebugWindowProc; +extern bool gDebugWindowProc; const S32 MAX_NUM_RESOLUTIONS = 200; @@ -93,278 +97,100 @@ void maybe_unlock_display(void) } -#if LL_X11 +#if LL_GTK +// Lazily initialize and check the runtime GTK version for goodness. // static -Window LLWindowSDL::get_SDL_XWindowID(void) +bool LLWindowSDL::ll_try_gtk_init(void) { - if (gWindowImplementation) { - return gWindowImplementation->mSDL_XWindowID; - } - return None; -} + static bool done_gtk_diag = false; + static bool gtk_is_good = false; + static bool done_setlocale = false; + static bool tried_gtk_init = false; -//static -Display* LLWindowSDL::get_SDL_Display(void) -{ - if (gWindowImplementation) { - return gWindowImplementation->mSDL_Display; - } - return NULL; -} -#endif // LL_X11 - -#if LL_X11 - -// Clipboard handing via native X11, base on the implementation in Cool VL by Henri Beauchamp - -namespace -{ - std::array<Atom, 3> gSupportedAtoms; - - Atom XA_CLIPBOARD; - Atom XA_TARGETS; - Atom PVT_PASTE_BUFFER; - long const MAX_PASTE_BUFFER_SIZE = 16383; - - void filterSelectionRequest( XEvent aEvent ) + if (!done_setlocale) { - auto *display = LLWindowSDL::getSDLDisplay(); - auto &request = aEvent.xselectionrequest; - - XSelectionEvent reply { SelectionNotify, aEvent.xany.serial, aEvent.xany.send_event, display, - request.requestor, request.selection, request.target, - request.property,request.time }; - - if (request.target == XA_TARGETS) - { - XChangeProperty(display, request.requestor, request.property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *) &gSupportedAtoms.front(), gSupportedAtoms.size()); - } - else if (std::find(gSupportedAtoms.begin(), gSupportedAtoms.end(), request.target) != - gSupportedAtoms.end()) - { - std::string utf8; - if (request.selection == XA_PRIMARY) - utf8 = wstring_to_utf8str(gWindowImplementation->getPrimaryText()); - else - utf8 = wstring_to_utf8str(gWindowImplementation->getSecondaryText()); - - XChangeProperty(display, request.requestor, request.property, - request.target, 8, PropModeReplace, - (unsigned char *) utf8.c_str(), utf8.length()); - } - else if (request.selection == XA_CLIPBOARD) - { - // Did not have what they wanted, so no property set - reply.property = None; - } - else - return; - - XSendEvent(request.display, request.requestor, False, NoEventMask, (XEvent *) &reply); - XSync(display, False); - } - - void filterSelectionClearRequest( XEvent aEvent ) - { - auto &request = aEvent.xselectionrequest; - if (request.selection == XA_PRIMARY) - gWindowImplementation->clearPrimaryText(); - else if (request.selection == XA_CLIPBOARD) - gWindowImplementation->clearSecondaryText(); - } - - int x11_clipboard_filter(void*, SDL_Event *evt) - { - Display *display = LLWindowSDL::getSDLDisplay(); - if (!display) - return 1; - - if (evt->type != SDL_SYSWMEVENT) - return 1; - - auto xevent = evt->syswm.msg->msg.x11.event; - - if (xevent.type == SelectionRequest) - filterSelectionRequest( xevent ); - else if (xevent.type == SelectionClear) - filterSelectionClearRequest( xevent ); - return 1; - } - - bool grab_property(Display* display, Window window, Atom selection, Atom target) - { - if( !display ) - return false; - + LL_INFOS() << "Starting GTK Initialization." << LL_ENDL; maybe_lock_display(); - - XDeleteProperty(display, window, PVT_PASTE_BUFFER); - XFlush(display); - - XConvertSelection(display, selection, target, PVT_PASTE_BUFFER, window, CurrentTime); - - // Unlock the connection so that the SDL event loop may function + gtk_disable_setlocale(); maybe_unlock_display(); - - const auto start{ SDL_GetTicks() }; - const auto end{ start + 1000 }; - - XEvent xevent {}; - bool response = false; - - do - { - SDL_Event event {}; - - // Wait for an event - SDL_WaitEvent(&event); - - // If the event is a window manager event - if (event.type == SDL_SYSWMEVENT) - { - xevent = event.syswm.msg->msg.x11.event; - - if (xevent.type == SelectionNotify && xevent.xselection.requestor == window) - response = true; - } - } while (!response && SDL_GetTicks() < end ); - - return response && xevent.xselection.property != None; + done_setlocale = true; } -} - -void LLWindowSDL::initialiseX11Clipboard() -{ - if (!mSDL_Display) - return; - - SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); - SDL_SetEventFilter(x11_clipboard_filter, nullptr); - - maybe_lock_display(); - - XA_CLIPBOARD = XInternAtom(mSDL_Display, "CLIPBOARD", False); - - gSupportedAtoms[0] = XInternAtom(mSDL_Display, "UTF8_STRING", False); - gSupportedAtoms[1] = XInternAtom(mSDL_Display, "COMPOUND_TEXT", False); - gSupportedAtoms[2] = XA_STRING; - - // TARGETS atom - XA_TARGETS = XInternAtom(mSDL_Display, "TARGETS", False); - // SL_PASTE_BUFFER atom - PVT_PASTE_BUFFER = XInternAtom(mSDL_Display, "FS_PASTE_BUFFER", False); - - maybe_unlock_display(); -} - -bool LLWindowSDL::getSelectionText( Atom aSelection, Atom aType, LLWString &text ) -{ - if( !mSDL_Display ) - return false; - - if( !grab_property(mSDL_Display, mSDL_XWindowID, aSelection,aType ) ) - return false; - - maybe_lock_display(); - - Atom type; - int format{}; - unsigned long len{},remaining {}; - unsigned char* data = nullptr; - int res = XGetWindowProperty(mSDL_Display, mSDL_XWindowID, - PVT_PASTE_BUFFER, 0, MAX_PASTE_BUFFER_SIZE, False, - AnyPropertyType, &type, &format, &len, - &remaining, &data); - if (data && len) + if (!tried_gtk_init) { - text = LLWString( - utf8str_to_wstring(reinterpret_cast< char const *>( data ) ) - ); - XFree(data); + tried_gtk_init = true; + if (!g_thread_supported ()) g_thread_init (NULL); + maybe_lock_display(); + gtk_is_good = gtk_init_check(NULL, NULL); + maybe_unlock_display(); + if (!gtk_is_good) + LL_WARNS() << "GTK Initialization failed." << LL_ENDL; } - maybe_unlock_display(); - return res == Success; -} - -bool LLWindowSDL::getSelectionText(Atom selection, LLWString& text) -{ - if (!mSDL_Display) - return false; - - maybe_lock_display(); - - Window owner = XGetSelectionOwner(mSDL_Display, selection); - if (owner == None) + if (gtk_is_good && !done_gtk_diag) { - if (selection == XA_PRIMARY) - { - owner = DefaultRootWindow(mSDL_Display); - selection = XA_CUT_BUFFER0; - } - else + LL_INFOS() << "GTK Initialized." << LL_ENDL; + LL_INFOS() << "- Compiled against GTK version " + << GTK_MAJOR_VERSION << "." + << GTK_MINOR_VERSION << "." + << GTK_MICRO_VERSION << LL_ENDL; + LL_INFOS() << "- Running against GTK version " + << gtk_major_version << "." + << gtk_minor_version << "." + << gtk_micro_version << LL_ENDL; + maybe_lock_display(); + const gchar* gtk_warning = gtk_check_version( + GTK_MAJOR_VERSION, + GTK_MINOR_VERSION, + GTK_MICRO_VERSION); + maybe_unlock_display(); + if (gtk_warning) { - maybe_unlock_display(); - return false; + LL_WARNS() << "- GTK COMPATIBILITY WARNING: " << + gtk_warning << LL_ENDL; + gtk_is_good = false; + } else { + LL_INFOS() << "- GTK version is good." << LL_ENDL; } - } - - maybe_unlock_display(); - for( Atom atom : gSupportedAtoms ) - { - if(getSelectionText(selection, atom, text ) ) - return true; + done_gtk_diag = true; } - return false; + return gtk_is_good; } +#endif // LL_GTK -bool LLWindowSDL::setSelectionText(Atom selection, const LLWString& text) -{ - maybe_lock_display(); - if (selection == XA_PRIMARY) - { - std::string utf8 = wstring_to_utf8str(text); - XStoreBytes(mSDL_Display, utf8.c_str(), utf8.length() + 1); - mPrimaryClipboard = text; +#if LL_X11 +// static +Window LLWindowSDL::get_SDL_XWindowID(void) +{ + if (gWindowImplementation) { + return gWindowImplementation->mSDL_XWindowID; } - else - mSecondaryClipboard = text; - - XSetSelectionOwner(mSDL_Display, selection, mSDL_XWindowID, CurrentTime); - - auto owner = XGetSelectionOwner(mSDL_Display, selection); - - maybe_unlock_display(); - - return owner == mSDL_XWindowID; + return None; } -Display* LLWindowSDL::getSDLDisplay() +//static +Display* LLWindowSDL::get_SDL_Display(void) { - if (gWindowImplementation) + if (gWindowImplementation) { return gWindowImplementation->mSDL_Display; - return nullptr; + } + return NULL; } - -#endif +#endif // LL_X11 LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, - const std::string& title, S32 x, S32 y, S32 width, - S32 height, U32 flags, - BOOL fullscreen, BOOL clearBg, - BOOL disable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, U32 fsaa_samples) - : LLWindow(callbacks, fullscreen, flags), - Lock_Display(NULL), - //Unlock_Display(NULL), mGamma(1.0f) - Unlock_Display(NULL), mGamma(1.0f) + const std::string& title, S32 x, S32 y, S32 width, + S32 height, U32 flags, + bool fullscreen, bool clearBg, + bool disable_vsync, bool use_gl, + bool ignore_pixel_depth, U32 fsaa_samples) + : LLWindow(callbacks, fullscreen, flags), + Lock_Display(NULL), + Unlock_Display(NULL), mGamma(1.0f) { // Initialize the keyboard gKeyboard = new LLKeyboardSDL(); @@ -373,8 +199,7 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, // Ignore use_gl for now, only used for drones on PC mWindow = NULL; - mContext = {}; - mNeedsResize = FALSE; + mNeedsResize = false; mOverrideAspectRatio = 0.f; mGrabbyKeyFlags = 0; mReallyCapturedCount = 0; @@ -387,6 +212,13 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, mSDL_Display = NULL; #endif // LL_X11 +#if LL_GTK + // We MUST be the first to initialize GTK so that GTK doesn't get badly + // initialized with a non-C locale and cause lots of serious random + // weirdness. + ll_try_gtk_init(); +#endif // LL_GTK + // Assume 4:3 aspect ratio until we know better mOriginalAspectRatio = 1024.0 / 768.0; @@ -411,10 +243,10 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks, gWindowImplementation = this; #if LL_X11 - mFlashing = FALSE; - initialiseX11Clipboard(); + mFlashing = false; #endif // LL_X11 + mKeyScanCode = 0; mKeyVirtualKey = 0; mKeyModifiers = KMOD_NONE; } @@ -426,10 +258,10 @@ static SDL_Surface *Load_BMP_Resource(const char *basename) // Figure out where our BMP is living on the disk snprintf(path_buffer, PATH_BUFFER_SIZE-1, "%s%sres-sdl%s%s", - gDirUtilp->getAppRODataDir().c_str(), - gDirUtilp->getDirDelimiter().c_str(), - gDirUtilp->getDirDelimiter().c_str(), - basename); + gDirUtilp->getAppRODataDir().c_str(), + gDirUtilp->getDirDelimiter().c_str(), + gDirUtilp->getDirDelimiter().c_str(), + basename); path_buffer[PATH_BUFFER_SIZE-1] = '\0'; return SDL_LoadBMP(path_buffer); @@ -516,7 +348,7 @@ static int x11_detect_VRAM_kb() if (fp) { LL_INFOS() << "Looking in " << fname - << " for VRAM info..." << LL_ENDL; + << " for VRAM info..." << LL_ENDL; rtn = x11_detect_VRAM_kb_fp(fp, ": VideoRAM: "); fclose(fp); if (0 == rtn) @@ -541,7 +373,7 @@ static int x11_detect_VRAM_kb() else { LL_INFOS() << "Could not open " << fname - << " - skipped." << LL_ENDL; + << " - skipped." << LL_ENDL; // Try old XFree86 log otherwise fname = x_log_location; fname += "XFree86."; @@ -551,7 +383,7 @@ static int x11_detect_VRAM_kb() if (fp) { LL_INFOS() << "Looking in " << fname - << " for VRAM info..." << LL_ENDL; + << " for VRAM info..." << LL_ENDL; rtn = x11_detect_VRAM_kb_fp(fp, ": VideoRAM: "); fclose(fp); if (0 == rtn) @@ -567,160 +399,95 @@ static int x11_detect_VRAM_kb() else { LL_INFOS() << "Could not open " << fname - << " - skipped." << LL_ENDL; + << " - skipped." << LL_ENDL; } } return rtn; } #endif // LL_X11 -void LLWindowSDL::setTitle(const std::string title) -{ - SDL_SetWindowTitle( mWindow, title.c_str() ); -} - -void LLWindowSDL::tryFindFullscreenSize( int &width, int &height ) -{ - LL_INFOS() << "createContext: setting up fullscreen " << width << "x" << height << LL_ENDL; - - // If the requested width or height is 0, find the best default for the monitor. - if((width == 0) || (height == 0)) - { - // Scan through the list of modes, looking for one which has: - // height between 700 and 800 - // aspect ratio closest to the user's original mode - S32 resolutionCount = 0; - LLWindowResolution *resolutionList = getSupportedResolutions(resolutionCount); - - if(resolutionList != NULL) - { - F32 closestAspect = 0; - U32 closestHeight = 0; - U32 closestWidth = 0; - int i; - - LL_INFOS() << "createContext: searching for a display mode, original aspect is " << mOriginalAspectRatio << LL_ENDL; - - for(i=0; i < resolutionCount; i++) - { - F32 aspect = (F32)resolutionList[i].mWidth / (F32)resolutionList[i].mHeight; - - LL_INFOS() << "createContext: width " << resolutionList[i].mWidth << " height " << resolutionList[i].mHeight << " aspect " << aspect << LL_ENDL; - - if( (resolutionList[i].mHeight >= 700) && (resolutionList[i].mHeight <= 800) && - (fabs(aspect - mOriginalAspectRatio) < fabs(closestAspect - mOriginalAspectRatio))) - { - LL_INFOS() << " (new closest mode) " << LL_ENDL; - - // This is the closest mode we've seen yet. - closestWidth = resolutionList[i].mWidth; - closestHeight = resolutionList[i].mHeight; - closestAspect = aspect; - } - } - - width = closestWidth; - height = closestHeight; - } - } - - if((width == 0) || (height == 0)) - { - // Mode search failed for some reason. Use the old-school default. - width = 1024; - height = 768; - } -} - -BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync) +bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, bool fullscreen, bool disable_vsync) { //bool glneedsinit = false; LL_INFOS() << "createContext, fullscreen=" << fullscreen << - " size=" << width << "x" << height << LL_ENDL; + " size=" << width << "x" << height << LL_ENDL; // captures don't survive contexts mGrabbyKeyFlags = 0; mReallyCapturedCount = 0; - std::initializer_list<std::tuple< char const*, char const * > > hintList = - { - {SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR,"0"}, - {SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH,"1"}, - {SDL_HINT_IME_INTERNAL_EDITING,"1"} - }; - - for( auto hint: hintList ) + if (SDL_Init(SDL_INIT_VIDEO) < 0) { - SDL_SetHint( std::get<0>(hint), std::get<1>(hint)); - } - - std::initializer_list<std::tuple<uint32_t, char const*, bool>> initList= - { {SDL_INIT_VIDEO,"SDL_INIT_VIDEO", true}, - {SDL_INIT_AUDIO,"SDL_INIT_AUDIO", false}, - {SDL_INIT_GAMECONTROLLER,"SDL_INIT_GAMECONTROLLER", false}, - {SDL_INIT_SENSOR,"SDL_INIT_SENSOR", false} - }; - - for( auto subSystem : initList) - { - if( SDL_InitSubSystem( std::get<0>(subSystem) ) < 0 ) - { - LL_WARNS() << "SDL_InitSubSystem for " << std::get<1>(subSystem) << " failed " << SDL_GetError() << LL_ENDL; - - if( std::get<2>(subSystem)) - setupFailure("SDL_Init() failure", "error", OSMB_OK); - - } + LL_INFOS() << "sdl_init() failed! " << SDL_GetError() << LL_ENDL; + setupFailure("sdl_init() failure, window creation error", "error", OSMB_OK); + return false; } SDL_version c_sdl_version; SDL_VERSION(&c_sdl_version); LL_INFOS() << "Compiled against SDL " - << int(c_sdl_version.major) << "." - << int(c_sdl_version.minor) << "." - << int(c_sdl_version.patch) << LL_ENDL; - SDL_version r_sdl_version; - SDL_GetVersion(&r_sdl_version); + << int(c_sdl_version.major) << "." + << int(c_sdl_version.minor) << "." + << int(c_sdl_version.patch) << LL_ENDL; + const SDL_version *r_sdl_version; + r_sdl_version = SDL_Linked_Version(); LL_INFOS() << " Running against SDL " - << int(r_sdl_version.major) << "." - << int(r_sdl_version.minor) << "." - << int(r_sdl_version.patch) << LL_ENDL; + << int(r_sdl_version->major) << "." + << int(r_sdl_version->minor) << "." + << int(r_sdl_version->patch) << LL_ENDL; - if (width == 0) - width = 1024; - if (height == 0) - width = 768; - - mFullscreen = fullscreen; - - int sdlflags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; + const SDL_VideoInfo *video_info = SDL_GetVideoInfo( ); + if (!video_info) + { + LL_INFOS() << "SDL_GetVideoInfo() failed! " << SDL_GetError() << LL_ENDL; + setupFailure("SDL_GetVideoInfo() failed, Window creation error", "Error", OSMB_OK); + return false; + } - if( mFullscreen ) + if (video_info->current_h > 0) { - sdlflags |= SDL_WINDOW_FULLSCREEN; - tryFindFullscreenSize( width, height ); + mOriginalAspectRatio = (float)video_info->current_w / (float)video_info->current_h; + LL_INFOS() << "Original aspect ratio was " << video_info->current_w << ":" << video_info->current_h << "=" << mOriginalAspectRatio << LL_ENDL; } - mSDLFlags = sdlflags; + SDL_EnableUNICODE(1); + SDL_WM_SetCaption(mWindowTitle.c_str(), mWindowTitle.c_str()); - GLint redBits{8}, greenBits{8}, blueBits{8}, alphaBits{8}; + // Set the application icon. + SDL_Surface *bmpsurface; + bmpsurface = Load_BMP_Resource("ll_icon.BMP"); + if (bmpsurface) + { + // This attempts to give a black-keyed mask to the icon. + SDL_SetColorKey(bmpsurface, + SDL_SRCCOLORKEY, + SDL_MapRGB(bmpsurface->format, 0,0,0) ); + SDL_WM_SetIcon(bmpsurface, NULL); + // The SDL examples cheerfully avoid freeing the icon + // surface, but I'm betting that's leaky. + SDL_FreeSurface(bmpsurface); + bmpsurface = NULL; + } - GLint depthBits{(bits <= 16) ? 16 : 24}, stencilBits{8}; + // note: these SetAttributes make Tom's 9600-on-AMD64 fail to + // get a visual, but it's broken anyway when it does, and without + // these SetAttributes we might easily get an avoidable substandard + // visual to work with on most other machines. + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, (bits <= 16) ? 16 : 24); + // We need stencil support for a few (minor) things. + if (!getenv("LL_GL_NO_STENCIL")) + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, (bits <= 16) ? 1 : 8); - if (getenv("LL_GL_NO_STENCIL")) - stencilBits = 0; + // *FIX: try to toggle vsync here? - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, alphaBits); - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, redBits); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, greenBits); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, blueBits); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depthBits ); + mFullscreen = fullscreen; - // We need stencil support for a few (minor) things. - if (stencilBits) - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilBits); - // *FIX: try to toggle vsync here? + int sdlflags = SDL_OPENGL | SDL_RESIZABLE | SDL_ANYFORMAT; SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); @@ -730,45 +497,86 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, mFSAASamples); } - SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); - mWindow = SDL_CreateWindow( mWindowTitle.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, mSDLFlags ); + mSDLFlags = sdlflags; - if( mWindow ) + if (mFullscreen) { - mContext = SDL_GL_CreateContext( mWindow ); + LL_INFOS() << "createContext: setting up fullscreen " << width << "x" << height << LL_ENDL; + + // If the requested width or height is 0, find the best default for the monitor. + if((width == 0) || (height == 0)) + { + // Scan through the list of modes, looking for one which has: + // height between 700 and 800 + // aspect ratio closest to the user's original mode + S32 resolutionCount = 0; + LLWindowResolution *resolutionList = getSupportedResolutions(resolutionCount); + + if(resolutionList != NULL) + { + F32 closestAspect = 0; + U32 closestHeight = 0; + U32 closestWidth = 0; + int i; + + LL_INFOS() << "createContext: searching for a display mode, original aspect is " << mOriginalAspectRatio << LL_ENDL; + + for(i=0; i < resolutionCount; i++) + { + F32 aspect = (F32)resolutionList[i].mWidth / (F32)resolutionList[i].mHeight; + + LL_INFOS() << "createContext: width " << resolutionList[i].mWidth << " height " << resolutionList[i].mHeight << " aspect " << aspect << LL_ENDL; - if( mContext == 0 ) + if( (resolutionList[i].mHeight >= 700) && (resolutionList[i].mHeight <= 800) && + (fabs(aspect - mOriginalAspectRatio) < fabs(closestAspect - mOriginalAspectRatio))) + { + LL_INFOS() << " (new closest mode) " << LL_ENDL; + + // This is the closest mode we've seen yet. + closestWidth = resolutionList[i].mWidth; + closestHeight = resolutionList[i].mHeight; + closestAspect = aspect; + } + } + + width = closestWidth; + height = closestHeight; + } + } + + if((width == 0) || (height == 0)) { - LL_WARNS() << "Cannot create GL context " << SDL_GetError() << LL_ENDL; - setupFailure("GL Context creation error creation error", "Error", OSMB_OK); - return FALSE; + // Mode search failed for some reason. Use the old-school default. + width = 1024; + height = 768; } - // SDL_GL_SetSwapInterval(1); - mSurface = SDL_GetWindowSurface( mWindow ); - } + mWindow = SDL_SetVideoMode(width, height, bits, sdlflags | SDL_FULLSCREEN); + if (!mWindow && bits > 16) + { + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + mWindow = SDL_SetVideoMode(width, height, bits, sdlflags | SDL_FULLSCREEN); + } - if( mFullscreen ) - { - if (mSurface) + if (mWindow) { - mFullscreen = TRUE; - mFullscreenWidth = mSurface->w; - mFullscreenHeight = mSurface->h; - mFullscreenBits = mSurface->format->BitsPerPixel; + mFullscreen = true; + mFullscreenWidth = mWindow->w; + mFullscreenHeight = mWindow->h; + mFullscreenBits = mWindow->format->BitsPerPixel; mFullscreenRefresh = -1; LL_INFOS() << "Running at " << mFullscreenWidth - << "x" << mFullscreenHeight - << "x" << mFullscreenBits - << " @ " << mFullscreenRefresh - << LL_ENDL; + << "x" << mFullscreenHeight + << "x" << mFullscreenBits + << " @ " << mFullscreenRefresh + << LL_ENDL; } else { LL_WARNS() << "createContext: fullscreen creation failure. SDL: " << SDL_GetError() << LL_ENDL; // No fullscreen support - mFullscreen = FALSE; + mFullscreen = false; mFullscreenWidth = -1; mFullscreenHeight = -1; mFullscreenBits = -1; @@ -776,27 +584,33 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B std::string error = llformat("Unable to run fullscreen at %d x %d.\nRunning in window.", width, height); OSMessageBox(error, "Error", OSMB_OK); - return FALSE; } } - else + + if(!mFullscreen && (mWindow == NULL)) { + if (width == 0) + width = 1024; + if (height == 0) + width = 768; + + LL_INFOS() << "createContext: creating window " << width << "x" << height << "x" << bits << LL_ENDL; + mWindow = SDL_SetVideoMode(width, height, bits, sdlflags); + if (!mWindow && bits > 16) + { + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + mWindow = SDL_SetVideoMode(width, height, bits, sdlflags); + } + if (!mWindow) { LL_WARNS() << "createContext: window creation failure. SDL: " << SDL_GetError() << LL_ENDL; setupFailure("Window creation error", "Error", OSMB_OK); - return FALSE; + return false; } - } - - // Set the application icon. - SDL_Surface *bmpsurface; - bmpsurface = Load_BMP_Resource("ll_icon.BMP"); - if (bmpsurface) + } else if (!mFullscreen && (mWindow != NULL)) { - SDL_SetWindowIcon(mWindow, bmpsurface); - SDL_FreeSurface(bmpsurface); - bmpsurface = NULL; + LL_INFOS() << "createContext: SKIPPING - !fullscreen, but +mWindow " << width << "x" << height << "x" << bits << LL_ENDL; } // Detect video memory size. @@ -811,7 +625,7 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B // fallback to letting SDL detect VRAM. // note: I've not seen SDL's detection ever actually find // VRAM != 0, but if SDL *does* detect it then that's a bonus. - gGLManager.mVRAM = 0; + gGLManager.mVRAM = video_info->video_mem / 1024; if (gGLManager.mVRAM != 0) { LL_INFOS() << "SDL detected " << gGLManager.mVRAM << "MB VRAM." << LL_ENDL; @@ -823,20 +637,22 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B // explicitly unsupported cards. //const char* RENDERER = (const char*) glGetString(GL_RENDERER); - SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &redBits); - SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &greenBits); - SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blueBits); - SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &alphaBits); - SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depthBits); - SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencilBits); + GLint depthBits, stencilBits, redBits, greenBits, blueBits, alphaBits; + + glGetIntegerv(GL_RED_BITS, &redBits); + glGetIntegerv(GL_GREEN_BITS, &greenBits); + glGetIntegerv(GL_BLUE_BITS, &blueBits); + glGetIntegerv(GL_ALPHA_BITS, &alphaBits); + glGetIntegerv(GL_DEPTH_BITS, &depthBits); + glGetIntegerv(GL_STENCIL_BITS, &stencilBits); LL_INFOS() << "GL buffer:" << LL_ENDL; - LL_INFOS() << " Red Bits " << S32(redBits) << LL_ENDL; - LL_INFOS() << " Green Bits " << S32(greenBits) << LL_ENDL; - LL_INFOS() << " Blue Bits " << S32(blueBits) << LL_ENDL; - LL_INFOS() << " Alpha Bits " << S32(alphaBits) << LL_ENDL; - LL_INFOS() << " Depth Bits " << S32(depthBits) << LL_ENDL; - LL_INFOS() << " Stencil Bits " << S32(stencilBits) << LL_ENDL; + LL_INFOS() << " Red Bits " << S32(redBits) << LL_ENDL; + LL_INFOS() << " Green Bits " << S32(greenBits) << LL_ENDL; + LL_INFOS() << " Blue Bits " << S32(blueBits) << LL_ENDL; + LL_INFOS() << " Alpha Bits " << S32(alphaBits) << LL_ENDL; + LL_INFOS() << " Depth Bits " << S32(depthBits) << LL_ENDL; + LL_INFOS() << " Stencil Bits " << S32(stencilBits) << LL_ENDL; GLint colorBits = redBits + greenBits + blueBits + alphaBits; // fixme: actually, it's REALLY important for picking that we get at @@ -846,56 +662,79 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B { close(); setupFailure( - "Second Life requires True Color (32-bit) to run in a window.\n" - "Please go to Control Panels -> Display -> Settings and\n" - "set the screen to 32-bit color.\n" - "Alternately, if you choose to run fullscreen, Second Life\n" - "will automatically adjust the screen each time it runs.", - "Error", - OSMB_OK); - return FALSE; + "Second Life requires True Color (32-bit) to run in a window.\n" + "Please go to Control Panels -> Display -> Settings and\n" + "set the screen to 32-bit color.\n" + "Alternately, if you choose to run fullscreen, Second Life\n" + "will automatically adjust the screen each time it runs.", + "Error", + OSMB_OK); + return false; + } + +#if 0 // *FIX: we're going to brave it for now... + if (alphaBits < 8) + { + close(); + setupFailure( + "Second Life is unable to run because it can't get an 8 bit alpha\n" + "channel. Usually this is due to video card driver issues.\n" + "Please make sure you have the latest video card drivers installed.\n" + "Also be sure your monitor is set to True Color (32-bit) in\n" + "Control Panels -> Display -> Settings.\n" + "If you continue to receive this message, contact customer service.", + "Error", + OSMB_OK); + return false; } +#endif #if LL_X11 /* Grab the window manager specific information */ SDL_SysWMinfo info; SDL_VERSION(&info.version); - if ( SDL_GetWindowWMInfo(mWindow, &info) ) + if ( SDL_GetWMInfo(&info) ) { /* Save the information for later use */ if ( info.subsystem == SDL_SYSWM_X11 ) { mSDL_Display = info.info.x11.display; - mSDL_XWindowID = info.info.x11.window; + mSDL_XWindowID = info.info.x11.wmwindow; + Lock_Display = info.info.x11.lock_func; + Unlock_Display = info.info.x11.unlock_func; } else { LL_WARNS() << "We're not running under X11? Wild." - << LL_ENDL; + << LL_ENDL; } } else { LL_WARNS() << "We're not running under any known WM. Wild." - << LL_ENDL; + << LL_ENDL; } #endif // LL_X11 - SDL_StartTextInput(); //make sure multisampling is disabled by default glDisable(GL_MULTISAMPLE_ARB); + // We need to do this here, once video is init'd + if (-1 == SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, + SDL_DEFAULT_REPEAT_INTERVAL)) + LL_WARNS() << "Couldn't enable key-repeat: " << SDL_GetError() <<LL_ENDL; + // Don't need to get the current gamma, since there's a call that restores it to the system defaults. - return TRUE; + return true; } // changing fullscreen resolution, or switching between windowed and fullscreen mode. -BOOL LLWindowSDL::switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, const LLCoordScreen * const posp) +bool LLWindowSDL::switchContext(bool fullscreen, const LLCoordScreen &size, bool disable_vsync, const LLCoordScreen * const posp) { - const BOOL needsRebuild = TRUE; // Just nuke the context and start over. - BOOL result = true; + const bool needsRebuild = true; // Just nuke the context and start over. + bool result = true; LL_INFOS() << "switchContext, fullscreen=" << fullscreen << LL_ENDL; stop_glerror(); @@ -922,7 +761,6 @@ void LLWindowSDL::destroyContext() { LL_INFOS() << "destroyContext begins" << LL_ENDL; - SDL_StopTextInput(); #if LL_X11 mSDL_Display = NULL; mSDL_XWindowID = None; @@ -987,45 +825,45 @@ void LLWindowSDL::close() // } // Make sure cursor is visible and we haven't mangled the clipping state. - setMouseClipping(FALSE); + setMouseClipping(false); showCursor(); destroyContext(); } -BOOL LLWindowSDL::isValid() +bool LLWindowSDL::isValid() { return (mWindow != NULL); } -BOOL LLWindowSDL::getVisible() +bool LLWindowSDL::getVisible() { - BOOL result = FALSE; + bool result = false; // *FIX: This isn't really right... // Then what is? if (mWindow) { - result = TRUE; + result = true; } return(result); } -BOOL LLWindowSDL::getMinimized() +bool LLWindowSDL::getMinimized() { - BOOL result = FALSE; + bool result = false; if (mWindow && (1 == mIsMinimized)) { - result = TRUE; + result = true; } return(result); } -BOOL LLWindowSDL::getMaximized() +bool LLWindowSDL::getMaximized() { - BOOL result = FALSE; + bool result = false; if (mWindow) { @@ -1035,50 +873,50 @@ BOOL LLWindowSDL::getMaximized() return(result); } -BOOL LLWindowSDL::maximize() +bool LLWindowSDL::maximize() { // TODO - return FALSE; + return false; } -BOOL LLWindowSDL::getFullscreen() +bool LLWindowSDL::getFullscreen() { return mFullscreen; } -BOOL LLWindowSDL::getPosition(LLCoordScreen *position) +bool LLWindowSDL::getPosition(LLCoordScreen *position) { // *FIX: can anything be done with this? position->mX = 0; position->mY = 0; - return TRUE; + return true; } -BOOL LLWindowSDL::getSize(LLCoordScreen *size) +bool LLWindowSDL::getSize(LLCoordScreen *size) { - if (mSurface) + if (mWindow) { - size->mX = mSurface->w; - size->mY = mSurface->h; - return (TRUE); + size->mX = mWindow->w; + size->mY = mWindow->h; + return (true); } - return (FALSE); + return (false); } -BOOL LLWindowSDL::getSize(LLCoordWindow *size) +bool LLWindowSDL::getSize(LLCoordWindow *size) { - if (mSurface) + if (mWindow) { - size->mX = mSurface->w; - size->mY = mSurface->h; - return (TRUE); + size->mX = mWindow->w; + size->mY = mWindow->h; + return (true); } - return (FALSE); + return (false); } -BOOL LLWindowSDL::setPosition(const LLCoordScreen position) +bool LLWindowSDL::setPosition(const LLCoordScreen position) { if(mWindow) { @@ -1086,40 +924,43 @@ BOOL LLWindowSDL::setPosition(const LLCoordScreen position) //MacMoveWindow(mWindow, position.mX, position.mY, false); } - return TRUE; + return true; } -template< typename T > bool setSizeImpl( const T& newSize, SDL_Window *pWin ) +bool LLWindowSDL::setSizeImpl(const LLCoordScreen size) { - if( !pWin ) - return false; - - auto nFlags = SDL_GetWindowFlags( pWin ); - - if( nFlags & SDL_WINDOW_MAXIMIZED ) - SDL_RestoreWindow( pWin ); - + if(mWindow) + { + // Push a resize event onto SDL's queue - we'll handle it + // when it comes out again. + SDL_Event event; + event.type = SDL_VIDEORESIZE; + event.resize.w = size.mX; + event.resize.h = size.mY; + SDL_PushEvent(&event); // copied into queue - SDL_SetWindowSize( pWin, newSize.mX, newSize.mY ); - SDL_Event event; - event.type = SDL_WINDOWEVENT; - event.window.event = SDL_WINDOWEVENT_RESIZED; - event.window.windowID = SDL_GetWindowID( pWin ); - event.window.data1 = newSize.mX; - event.window.data2 = newSize.mY; - SDL_PushEvent( &event ); + return true; + } - return true; + return false; } -BOOL LLWindowSDL::setSizeImpl(const LLCoordScreen size) +bool LLWindowSDL::setSizeImpl(const LLCoordWindow size) { - return ::setSizeImpl( size, mWindow ); -} + if(mWindow) + { + // Push a resize event onto SDL's queue - we'll handle it + // when it comes out again. + SDL_Event event; + event.type = SDL_VIDEORESIZE; + event.resize.w = size.mX; + event.resize.h = size.mY; + SDL_PushEvent(&event); // copied into queue -BOOL LLWindowSDL::setSizeImpl(const LLCoordWindow size) -{ - return ::setSizeImpl( size, mWindow ); + return true; + } + + return false; } @@ -1127,7 +968,7 @@ void LLWindowSDL::swapBuffers() { if (mWindow) { - SDL_GL_SwapWindow( mWindow ); + SDL_GL_SwapBuffers(); } } @@ -1146,23 +987,23 @@ F32 LLWindowSDL::getGamma() return 1/mGamma; } -BOOL LLWindowSDL::restoreGamma() +bool LLWindowSDL::restoreGamma() { //CGDisplayRestoreColorSyncSettings(); - // SDL_SetGamma(1.0f, 1.0f, 1.0f); + SDL_SetGamma(1.0f, 1.0f, 1.0f); return true; } -BOOL LLWindowSDL::setGamma(const F32 gamma) +bool LLWindowSDL::setGamma(const F32 gamma) { mGamma = gamma; if (mGamma == 0) mGamma = 0.1f; mGamma = 1/mGamma; - // SDL_SetGamma(mGamma, mGamma, mGamma); + SDL_SetGamma(mGamma, mGamma, mGamma); return true; } -BOOL LLWindowSDL::isCursorHidden() +bool LLWindowSDL::isCursorHidden() { return mCursorHidden; } @@ -1170,7 +1011,7 @@ BOOL LLWindowSDL::isCursorHidden() // Constrains the mouse to the window. -void LLWindowSDL::setMouseClipping( BOOL b ) +void LLWindowSDL::setMouseClipping( bool b ) { //SDL_WM_GrabInput(b ? SDL_GRAB_ON : SDL_GRAB_OFF); } @@ -1194,27 +1035,27 @@ void LLWindowSDL::setMinSize(U32 min_width, U32 min_height, bool enforce_immedia #endif } -BOOL LLWindowSDL::setCursorPosition(const LLCoordWindow position) +bool LLWindowSDL::setCursorPosition(const LLCoordWindow position) { - BOOL result = TRUE; + bool result = true; LLCoordScreen screen_pos; if (!convertCoords(position, &screen_pos)) { - return FALSE; + return false; } //LL_INFOS() << "setCursorPosition(" << screen_pos.mX << ", " << screen_pos.mY << ")" << LL_ENDL; // do the actual forced cursor move. - SDL_WarpMouseInWindow(mWindow, screen_pos.mX, screen_pos.mY); + SDL_WarpMouse(screen_pos.mX, screen_pos.mY); //LL_INFOS() << llformat("llcw %d,%d -> scr %d,%d", position.mX, position.mY, screen_pos.mX, screen_pos.mY) << LL_ENDL; return result; } -BOOL LLWindowSDL::getCursorPosition(LLCoordWindow *position) +bool LLWindowSDL::getCursorPosition(LLCoordWindow *position) { //Point cursor_point; LLCoordScreen screen_pos; @@ -1232,6 +1073,18 @@ BOOL LLWindowSDL::getCursorPosition(LLCoordWindow *position) F32 LLWindowSDL::getNativeAspectRatio() { +#if 0 + // RN: this hack presumes that the largest supported resolution is monitor-limited + // and that pixels in that mode are square, therefore defining the native aspect ratio + // of the monitor...this seems to work to a close approximation for most CRTs/LCDs + S32 num_resolutions; + LLWindowResolution* resolutions = getSupportedResolutions(num_resolutions); + + + return ((F32)resolutions[num_resolutions - 1].mWidth / (F32)resolutions[num_resolutions - 1].mHeight); + //rn: AC +#endif + // MBW -- there are a couple of bad assumptions here. One is that the display list won't include // ridiculous resolutions nobody would ever use. The other is that the list is in order. @@ -1284,7 +1137,7 @@ void LLWindowSDL::beforeDialog() LL_INFOS() << "LLWindowSDL::beforeDialog()" << LL_ENDL; - if (SDLReallyCaptureInput(FALSE)) // must ungrab input so popup works! + if (SDLReallyCaptureInput(false)) // must ungrab input so popup works! { if (mFullscreen) { @@ -1293,7 +1146,7 @@ void LLWindowSDL::beforeDialog() // it only works in X11 if (running_x11 && mWindow) { - SDL_SetWindowFullscreen( mWindow, 0 ); + SDL_WM_ToggleFullScreen(mWindow); } } } @@ -1309,6 +1162,12 @@ void LLWindowSDL::beforeDialog() } #endif // LL_X11 +#if LL_GTK + // this is a good time to grab some GTK version information for + // diagnostics, if not already done. + ll_try_gtk_init(); +#endif // LL_GTK + maybe_lock_display(); } @@ -1329,7 +1188,7 @@ void LLWindowSDL::afterDialog() // in X11 if (running_x11 && mWindow) { - SDL_SetWindowFullscreen( mWindow, 0 ); + SDL_WM_ToggleFullScreen(mWindow); } } } @@ -1337,7 +1196,7 @@ void LLWindowSDL::afterDialog() #if LL_X11 // set/reset the XWMHints flag for 'urgency' that usually makes the icon flash -void LLWindowSDL::x11_set_urgent(BOOL urgent) +void LLWindowSDL::x11_set_urgent(bool urgent) { if (mSDL_Display && !mFullscreen) { @@ -1365,56 +1224,143 @@ void LLWindowSDL::x11_set_urgent(BOOL urgent) void LLWindowSDL::flashIcon(F32 seconds) { - if (getMinimized()) - { #if !LL_X11 - LL_INFOS() << "Stub LLWindowSDL::flashIcon(" << seconds << ")" << LL_ENDL; + LL_INFOS() << "Stub LLWindowSDL::flashIcon(" << seconds << ")" << LL_ENDL; #else - LL_INFOS() << "X11 LLWindowSDL::flashIcon(" << seconds << ")" << LL_ENDL; + LL_INFOS() << "X11 LLWindowSDL::flashIcon(" << seconds << ")" << LL_ENDL; - F32 remaining_time = mFlashTimer.getRemainingTimeF32(); - if (remaining_time < seconds) - remaining_time = seconds; - mFlashTimer.reset(); - mFlashTimer.setTimerExpirySec(remaining_time); + F32 remaining_time = mFlashTimer.getRemainingTimeF32(); + if (remaining_time < seconds) + remaining_time = seconds; + mFlashTimer.reset(); + mFlashTimer.setTimerExpirySec(remaining_time); - x11_set_urgent(TRUE); - mFlashing = TRUE; + x11_set_urgent(true); + mFlashing = true; #endif // LL_X11 +} + + +#if LL_GTK +bool LLWindowSDL::isClipboardTextAvailable() +{ + if (ll_try_gtk_init()) + { + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_NONE); + return gtk_clipboard_wait_is_text_available(clipboard) ? + true : false; } + return false; // failure } -BOOL LLWindowSDL::isClipboardTextAvailable() +bool LLWindowSDL::pasteTextFromClipboard(LLWString &text) +{ + if (ll_try_gtk_init()) + { + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_NONE); + gchar * const data = gtk_clipboard_wait_for_text(clipboard); + if (data) + { + text = LLWString(utf8str_to_wstring(data)); + g_free(data); + return true; + } + } + return false; // failure +} + +bool LLWindowSDL::copyTextToClipboard(const LLWString &text) +{ + if (ll_try_gtk_init()) + { + const std::string utf8 = wstring_to_utf8str(text); + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_NONE); + gtk_clipboard_set_text(clipboard, utf8.c_str(), utf8.length()); + return true; + } + return false; // failure +} + + +bool LLWindowSDL::isPrimaryTextAvailable() +{ + if (ll_try_gtk_init()) + { + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_SELECTION_PRIMARY); + return gtk_clipboard_wait_is_text_available(clipboard) ? + true : false; + } + return false; // failure +} + +bool LLWindowSDL::pasteTextFromPrimary(LLWString &text) +{ + if (ll_try_gtk_init()) + { + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gchar * const data = gtk_clipboard_wait_for_text(clipboard); + if (data) + { + text = LLWString(utf8str_to_wstring(data)); + g_free(data); + return true; + } + } + return false; // failure +} + +bool LLWindowSDL::copyTextToPrimary(const LLWString &text) +{ + if (ll_try_gtk_init()) + { + const std::string utf8 = wstring_to_utf8str(text); + GtkClipboard * const clipboard = + gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text(clipboard, utf8.c_str(), utf8.length()); + return true; + } + return false; // failure +} + +#else + +bool LLWindowSDL::isClipboardTextAvailable() { - return mSDL_Display && XGetSelectionOwner(mSDL_Display, XA_CLIPBOARD) != None; + return false; // unsupported } -BOOL LLWindowSDL::pasteTextFromClipboard(LLWString &dst) +bool LLWindowSDL::pasteTextFromClipboard(LLWString &dst) { - return getSelectionText(XA_CLIPBOARD, dst); + return false; // unsupported } -BOOL LLWindowSDL::copyTextToClipboard(const LLWString &s) +bool LLWindowSDL::copyTextToClipboard(const LLWString &s) { - return setSelectionText(XA_CLIPBOARD, s); + return false; // unsupported } -BOOL LLWindowSDL::isPrimaryTextAvailable() +bool LLWindowSDL::isPrimaryTextAvailable() { - LLWString text; - return getSelectionText(XA_PRIMARY, text) && !text.empty(); + return false; // unsupported } -BOOL LLWindowSDL::pasteTextFromPrimary(LLWString &dst) +bool LLWindowSDL::pasteTextFromPrimary(LLWString &dst) { - return getSelectionText(XA_PRIMARY, dst); + return false; // unsupported } -BOOL LLWindowSDL::copyTextToPrimary(const LLWString &s) +bool LLWindowSDL::copyTextToPrimary(const LLWString &s) { - return setSelectionText(XA_PRIMARY, s); + return false; // unsupported } +#endif // LL_GTK + LLWindow::LLWindowResolution* LLWindowSDL::getSupportedResolutions(S32 &num_resolutions) { if (!mSupportedResolutions) @@ -1422,30 +1368,33 @@ LLWindow::LLWindowResolution* LLWindowSDL::getSupportedResolutions(S32 &num_reso mSupportedResolutions = new LLWindowResolution[MAX_NUM_RESOLUTIONS]; mNumSupportedResolutions = 0; - // <FS:ND> Use display no from mWindow/mSurface here? - int max = SDL_GetNumDisplayModes(0); - max = llclamp( max, 0, MAX_NUM_RESOLUTIONS ); - - for( int i =0; i < max; ++i ) + SDL_Rect **modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN); + if ( (modes != NULL) && (modes != ((SDL_Rect **) -1)) ) { - SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; - if (SDL_GetDisplayMode( 0 , i, &mode) != 0) + int count = 0; + while (*modes && count<MAX_NUM_RESOLUTIONS) // they're sorted biggest to smallest, so find end... { - continue; + modes++; + count++; } - int w = mode.w; - int h = mode.h; - if ((w >= 800) && (h >= 600)) + while (count--) { - // make sure we don't add the same resolution multiple times! - if ( (mNumSupportedResolutions == 0) || - ((mSupportedResolutions[mNumSupportedResolutions-1].mWidth != w) && - (mSupportedResolutions[mNumSupportedResolutions-1].mHeight != h)) ) + modes--; + SDL_Rect *r = *modes; + int w = r->w; + int h = r->h; + if ((w >= 800) && (h >= 600)) { - mSupportedResolutions[mNumSupportedResolutions].mWidth = w; - mSupportedResolutions[mNumSupportedResolutions].mHeight = h; - mNumSupportedResolutions++; + // make sure we don't add the same resolution multiple times! + if ( (mNumSupportedResolutions == 0) || + ((mSupportedResolutions[mNumSupportedResolutions-1].mWidth != w) && + (mSupportedResolutions[mNumSupportedResolutions-1].mHeight != h)) ) + { + mSupportedResolutions[mNumSupportedResolutions].mWidth = w; + mSupportedResolutions[mNumSupportedResolutions].mHeight = h; + mNumSupportedResolutions++; + } } } } @@ -1455,58 +1404,58 @@ LLWindow::LLWindowResolution* LLWindowSDL::getSupportedResolutions(S32 &num_reso return mSupportedResolutions; } -BOOL LLWindowSDL::convertCoords(LLCoordGL from, LLCoordWindow *to) +bool LLWindowSDL::convertCoords(LLCoordGL from, LLCoordWindow *to) { if (!to) - return FALSE; + return false; to->mX = from.mX; - to->mY = mSurface->h - from.mY - 1; + to->mY = mWindow->h - from.mY - 1; - return TRUE; + return true; } -BOOL LLWindowSDL::convertCoords(LLCoordWindow from, LLCoordGL* to) +bool LLWindowSDL::convertCoords(LLCoordWindow from, LLCoordGL* to) { if (!to) - return FALSE; + return false; to->mX = from.mX; - to->mY = mSurface->h - from.mY - 1; + to->mY = mWindow->h - from.mY - 1; - return TRUE; + return true; } -BOOL LLWindowSDL::convertCoords(LLCoordScreen from, LLCoordWindow* to) +bool LLWindowSDL::convertCoords(LLCoordScreen from, LLCoordWindow* to) { if (!to) - return FALSE; + return false; // In the fullscreen case, window and screen coordinates are the same. to->mX = from.mX; to->mY = from.mY; - return (TRUE); + return (true); } -BOOL LLWindowSDL::convertCoords(LLCoordWindow from, LLCoordScreen *to) +bool LLWindowSDL::convertCoords(LLCoordWindow from, LLCoordScreen *to) { if (!to) - return FALSE; + return false; // In the fullscreen case, window and screen coordinates are the same. to->mX = from.mX; to->mY = from.mY; - return (TRUE); + return (true); } -BOOL LLWindowSDL::convertCoords(LLCoordScreen from, LLCoordGL *to) +bool LLWindowSDL::convertCoords(LLCoordScreen from, LLCoordGL *to) { LLCoordWindow window_coord; return(convertCoords(from, &window_coord) && convertCoords(window_coord, to)); } -BOOL LLWindowSDL::convertCoords(LLCoordGL from, LLCoordScreen *to) +bool LLWindowSDL::convertCoords(LLCoordGL from, LLCoordScreen *to) { LLCoordWindow window_coord; @@ -1523,7 +1472,7 @@ void LLWindowSDL::setupFailure(const std::string& text, const std::string& capti OSMessageBox(text, caption, type); } -BOOL LLWindowSDL::SDLReallyCaptureInput(BOOL capture) +bool LLWindowSDL::SDLReallyCaptureInput(bool capture) { // note: this used to be safe to call nestedly, but in the // end that's not really a wise usage pattern, so don't. @@ -1533,13 +1482,13 @@ BOOL LLWindowSDL::SDLReallyCaptureInput(BOOL capture) else mReallyCapturedCount = 0; - bool wantGrab; + SDL_GrabMode wantmode, newmode; if (mReallyCapturedCount <= 0) // uncapture { - wantGrab = false; + wantmode = SDL_GRAB_OFF; } else // capture { - wantGrab = true; + wantmode = SDL_GRAB_ON; } if (mReallyCapturedCount < 0) // yuck, imbalance. @@ -1548,11 +1497,9 @@ BOOL LLWindowSDL::SDLReallyCaptureInput(BOOL capture) LL_WARNS() << "ReallyCapture count was < 0" << LL_ENDL; } - bool newGrab = wantGrab; - -#if LL_X11 if (!mFullscreen) /* only bother if we're windowed anyway */ { +#if LL_X11 if (mSDL_Display) { /* we dirtily mix raw X11 with SDL so that our pointer @@ -1565,37 +1512,49 @@ BOOL LLWindowSDL::SDLReallyCaptureInput(BOOL capture) *keyboard* input from the window manager, which was frustrating users. */ int result; - if (wantGrab == true) + if (wantmode == SDL_GRAB_ON) { + //LL_INFOS() << "X11 POINTER GRABBY" << LL_ENDL; + //newmode = SDL_WM_GrabInput(wantmode); maybe_lock_display(); result = XGrabPointer(mSDL_Display, mSDL_XWindowID, - True, 0, GrabModeAsync, - GrabModeAsync, - None, None, CurrentTime); + True, 0, GrabModeAsync, + GrabModeAsync, + None, None, CurrentTime); maybe_unlock_display(); if (GrabSuccess == result) - newGrab = true; + newmode = SDL_GRAB_ON; else - newGrab = false; - } - else + newmode = SDL_GRAB_OFF; + } else if (wantmode == SDL_GRAB_OFF) { - newGrab = false; + //LL_INFOS() << "X11 POINTER UNGRABBY" << LL_ENDL; + newmode = SDL_GRAB_OFF; + //newmode = SDL_WM_GrabInput(SDL_GRAB_OFF); maybe_lock_display(); XUngrabPointer(mSDL_Display, CurrentTime); // Make sure the ungrab happens RIGHT NOW. XSync(mSDL_Display, False); maybe_unlock_display(); + } else + { + newmode = SDL_GRAB_QUERY; // neutral } - } - } + } else // not actually running on X11, for some reason + newmode = wantmode; #endif // LL_X11 + } else { + // pretend we got what we wanted, when really we don't care. + newmode = wantmode; + } + // return boolean success for whether we ended up in the desired state - return capture == newGrab; + return (capture && SDL_GRAB_ON==newmode) || + (!capture && SDL_GRAB_OFF==newmode); } -U32 LLWindowSDL::SDLCheckGrabbyKeys(U32 keysym, BOOL gain) +U32 LLWindowSDL::SDLCheckGrabbyKeys(SDLKey keysym, bool gain) { /* part of the fix for SL-13243: Some popular window managers like to totally eat alt-drag for the purposes of moving windows. We @@ -1613,16 +1572,16 @@ U32 LLWindowSDL::SDLCheckGrabbyKeys(U32 keysym, BOOL gain) U32 mask = 0; switch (keysym) { - case SDLK_LALT: - mask = 1U << 0; break; - case SDLK_RALT: - mask = 1U << 1; break; - case SDLK_LCTRL: - mask = 1U << 2; break; - case SDLK_RCTRL: - mask = 1U << 3; break; - default: - break; + case SDLK_LALT: + mask = 1U << 0; break; + case SDLK_RALT: + mask = 1U << 1; break; + case SDLK_LCTRL: + mask = 1U << 2; break; + case SDLK_RCTRL: + mask = 1U << 3; break; + default: + break; } if (gain) @@ -1720,7 +1679,7 @@ void check_vm_bloat() last_rss_size = this_rss_size; last_vm_size = this_vm_size; - finally: +finally: if (NULL != ptr) { free(ptr); @@ -1735,17 +1694,33 @@ void check_vm_bloat() // virtual void LLWindowSDL::processMiscNativeEvents() { -#if LL_GLIB - // Pump until we've nothing left to do or passed 1/15th of a - // second pumping for this frame. - static LLTimer pump_timer; - pump_timer.reset(); - pump_timer.setTimerExpirySec(1.0f / 15.0f); - do - { - g_main_context_iteration(g_main_context_default(), FALSE); - } while( g_main_context_pending(g_main_context_default()) && !pump_timer.hasExpired()); -#endif +#if LL_GTK + // Pump GTK events to avoid starvation for: + // * DBUS servicing + // * Anything else which quietly hooks into the default glib/GTK loop + if (ll_try_gtk_init()) + { + // Yuck, Mozilla's GTK callbacks play with the locale - push/pop + // the locale to protect it, as exotic/non-C locales + // causes our code lots of general critical weirdness + // and crashness. (SL-35450) + static std::string saved_locale; + saved_locale = ll_safe_string(setlocale(LC_ALL, NULL)); + + // Pump until we've nothing left to do or passed 1/15th of a + // second pumping for this frame. + static LLTimer pump_timer; + pump_timer.reset(); + pump_timer.setTimerExpirySec(1.0f / 15.0f); + do { + // Always do at least one non-blocking pump + gtk_main_iteration_do(false); + } while (gtk_events_pending() && + !pump_timer.hasExpired()); + + setlocale(LC_ALL, saved_locale.c_str() ); + } +#endif // LL_GTK // hack - doesn't belong here - but this is just for debugging if (getenv("LL_DEBUG_BLOAT")) @@ -1768,83 +1743,43 @@ void LLWindowSDL::gatherInput() { switch (event.type) { - case SDL_MOUSEWHEEL: - if( event.wheel.y != 0 ) - mCallbacks->handleScrollWheel(this, -event.wheel.y); - break; - case SDL_MOUSEMOTION: { LLCoordWindow winCoord(event.button.x, event.button.y); LLCoordGL openGlCoord; convertCoords(winCoord, &openGlCoord); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); mCallbacks->handleMouseMove(this, openGlCoord, mask); break; } - case SDL_TEXTINPUT: - { - auto string = utf8str_to_utf16str( event.text.text ); - mKeyModifiers = gKeyboard->currentMask( FALSE ); - mInputType = "textinput"; - for( auto key: string ) - { - mKeyVirtualKey = key; - - if( (MASK_CONTROL|MASK_ALT)&mKeyModifiers ) - gKeyboard->handleKeyDown(mKeyVirtualKey, mKeyModifiers ); - else - handleUnicodeUTF16( key, mKeyModifiers ); - } - break; - } - case SDL_KEYDOWN: - mKeyVirtualKey = event.key.keysym.sym; - mKeyModifiers = event.key.keysym.mod; - mInputType = "keydown"; - - // treat all possible Enter/Return keys the same - if (mKeyVirtualKey == SDLK_RETURN2 || mKeyVirtualKey == SDLK_KP_ENTER) - { - mKeyVirtualKey = SDLK_RETURN; - } + mKeyScanCode = event.key.keysym.scancode; + mKeyVirtualKey = event.key.keysym.unicode; + mKeyModifiers = event.key.keysym.mod; - gKeyboard->handleKeyDown(mKeyVirtualKey, mKeyModifiers ); - - // <FS:ND> Slightly hacky :| To make the viewer honor enter (eg to accept form input) we've to not only send handleKeyDown but also send a - // invoke handleUnicodeUTF16 in case the user hits return. - // Note that we cannot blindly use handleUnicodeUTF16 for each SDL_KEYDOWN. Doing so will create bogus keyboard input (like % for cursor left). - if( mKeyVirtualKey == SDLK_RETURN ) - { - // fix return key not working when capslock, scrolllock or numlock are enabled - mKeyModifiers &= (~(KMOD_NUM | KMOD_CAPS | KMOD_MODE | KMOD_SCROLL)); - handleUnicodeUTF16( mKeyVirtualKey, mKeyModifiers ); - } - - // part of the fix for SL-13243 - if (SDLCheckGrabbyKeys(event.key.keysym.sym, TRUE) != 0) - SDLReallyCaptureInput(TRUE); + gKeyboard->handleKeyDown(event.key.keysym.sym, event.key.keysym.mod); + // part of the fix for SL-13243 + if (SDLCheckGrabbyKeys(event.key.keysym.sym, true) != 0) + SDLReallyCaptureInput(true); + if (event.key.keysym.unicode) + { + handleUnicodeUTF16(event.key.keysym.unicode, + gKeyboard->currentMask(false)); + } break; case SDL_KEYUP: - mKeyVirtualKey = event.key.keysym.sym; - mKeyModifiers = event.key.keysym.mod; - mInputType = "keyup"; - - // treat all possible Enter/Return keys the same - if (mKeyVirtualKey == SDLK_RETURN2 || mKeyVirtualKey == SDLK_KP_ENTER) - { - mKeyVirtualKey = SDLK_RETURN; - } + mKeyScanCode = event.key.keysym.scancode; + mKeyVirtualKey = event.key.keysym.unicode; + mKeyModifiers = event.key.keysym.mod; - if (SDLCheckGrabbyKeys(mKeyVirtualKey, FALSE) == 0) - SDLReallyCaptureInput(FALSE); // part of the fix for SL-13243 + if (SDLCheckGrabbyKeys(event.key.keysym.sym, false) == 0) + SDLReallyCaptureInput(false); // part of the fix for SL-13243 - gKeyboard->handleKeyUp(mKeyVirtualKey,mKeyModifiers); - break; + gKeyboard->handleKeyUp(event.key.keysym.sym, event.key.keysym.mod); + break; case SDL_MOUSEBUTTONDOWN: { @@ -1852,7 +1787,7 @@ void LLWindowSDL::gatherInput() LLCoordWindow winCoord(event.button.x, event.button.y); LLCoordGL openGlCoord; convertCoords(winCoord, &openGlCoord); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); if (event.button.button == SDL_BUTTON_LEFT) // SDL doesn't manage double clicking... { @@ -1864,7 +1799,7 @@ void LLWindowSDL::gatherInput() if (++leftClick >= 2) { leftClick = 0; - isDoubleClick = true; + isDoubleClick = true; } } lastLeftDown = now; @@ -1895,7 +1830,7 @@ void LLWindowSDL::gatherInput() else if (event.button.button == SDL_BUTTON_RIGHT) // right { - mCallbacks->handleRightMouseDown(this, openGlCoord, mask); + mCallbacks->handleRightMouseDown(this, openGlCoord, mask); } else if (event.button.button == SDL_BUTTON_MIDDLE) // middle @@ -1915,69 +1850,86 @@ void LLWindowSDL::gatherInput() LLCoordWindow winCoord(event.button.x, event.button.y); LLCoordGL openGlCoord; convertCoords(winCoord, &openGlCoord); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); if (event.button.button == SDL_BUTTON_LEFT) // left - mCallbacks->handleMouseUp(this, openGlCoord, mask); + mCallbacks->handleMouseUp(this, openGlCoord, mask); else if (event.button.button == SDL_BUTTON_RIGHT) // right - mCallbacks->handleRightMouseUp(this, openGlCoord, mask); + mCallbacks->handleRightMouseUp(this, openGlCoord, mask); else if (event.button.button == SDL_BUTTON_MIDDLE) // middle - mCallbacks->handleMiddleMouseUp(this, openGlCoord, mask); + mCallbacks->handleMiddleMouseUp(this, openGlCoord, mask); // don't handle mousewheel here... break; } - case SDL_WINDOWEVENT: // *FIX: handle this? - { - if( event.window.event == SDL_WINDOWEVENT_RESIZED - /* || event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED*/ ) // <FS:ND> SDL_WINDOWEVENT_SIZE_CHANGED is followed by SDL_WINDOWEVENT_RESIZED, so handling one shall be enough - { - LL_INFOS() << "Handling a resize event: " << event.window.data1 << "x" << event.window.data2 << LL_ENDL; + case SDL_VIDEOEXPOSE: // VIDEOEXPOSE doesn't specify the damage, but hey, it's OpenGL...repaint the whole thing! + mCallbacks->handlePaint(this, 0, 0, mWindow->w, mWindow->h); + break; - S32 width = llmax(event.window.data1, (S32)mMinWindowWidth); - S32 height = llmax(event.window.data2, (S32)mMinWindowHeight); - mSurface = SDL_GetWindowSurface( mWindow ); + case SDL_VIDEORESIZE: // *FIX: handle this? + { + LL_INFOS() << "Handling a resize event: " << event.resize.w << + "x" << event.resize.h << LL_ENDL; - // *FIX: I'm not sure this is necessary! - // <FS:ND> I think is is not - // SDL_SetWindowSize(mWindow, width, height); - // + S32 width = llmax(event.resize.w, (S32)mMinWindowWidth); + S32 height = llmax(event.resize.h, (S32)mMinWindowHeight); - mCallbacks->handleResize(this, width, height); - } - else if( event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED ) // <FS:ND> What about SDL_WINDOWEVENT_ENTER (mouse focus) + // *FIX: I'm not sure this is necessary! + mWindow = SDL_SetVideoMode(width, height, 32, mSDLFlags); + if (!mWindow) + { + // *FIX: More informative dialog? + LL_INFOS() << "Could not recreate context after resize! Quitting..." << LL_ENDL; + if(mCallbacks->handleCloseRequest(this)) { - // We have to do our own state massaging because SDL - // can send us two unfocus events in a row for example, - // which confuses the focus code [SL-24071]. - mHaveInputFocus = true; - - mCallbacks->handleFocus(this); + // Get the app to initiate cleanup. + mCallbacks->handleQuit(this); + // The app is responsible for calling destroyWindow when done with GL } - else if( event.window.event == SDL_WINDOWEVENT_FOCUS_LOST ) // <FS:ND> What about SDL_WINDOWEVENT_LEAVE (mouse focus) + break; + } + + mCallbacks->handleResize(this, width, height); + break; + } + case SDL_ACTIVEEVENT: + if (event.active.state & SDL_APPINPUTFOCUS) { - // We have to do our own state massaging because SDL - // can send us two unfocus events in a row for example, - // which confuses the focus code [SL-24071]. - mHaveInputFocus = false; + // Note that for SDL (particularly on X11), keyboard + // and mouse focus are independent things. Here we are + // tracking keyboard focus state changes. + + // We have to do our own state massaging because SDL + // can send us two unfocus events in a row for example, + // which confuses the focus code [SL-24071]. + if (event.active.gain != mHaveInputFocus) + { + mHaveInputFocus = !!event.active.gain; + if (mHaveInputFocus) + mCallbacks->handleFocus(this); + else mCallbacks->handleFocusLost(this); + } } - else if( event.window.event == SDL_WINDOWEVENT_MINIMIZED || - event.window.event == SDL_WINDOWEVENT_MAXIMIZED || - event.window.event == SDL_WINDOWEVENT_RESTORED || - event.window.event == SDL_WINDOWEVENT_EXPOSED || - event.window.event == SDL_WINDOWEVENT_SHOWN ) + if (event.active.state & SDL_APPACTIVE) { - mIsMinimized = (event.window.event == SDL_WINDOWEVENT_MINIMIZED); + // Change in iconification/minimization state. + if ((!event.active.gain) != mIsMinimized) + { + mIsMinimized = (!event.active.gain); - mCallbacks->handleActivate(this, !mIsMinimized); - LL_INFOS() << "SDL deiconification state switched to " << mIsMinimized << LL_ENDL; + mCallbacks->handleActivate(this, !mIsMinimized); + LL_INFOS() << "SDL deiconification state switched to " << bool(event.active.gain) << LL_ENDL; + } + else + { + LL_INFOS() << "Ignored bogus redundant SDL deiconification state switch to " << bool(event.active.gain) << LL_ENDL; + } } - break; - } + case SDL_QUIT: if(mCallbacks->handleCloseRequest(this)) { @@ -1986,9 +1938,9 @@ void LLWindowSDL::gatherInput() // The app is responsible for calling destroyWindow when done with GL } break; - default: - //LL_INFOS() << "Unhandled SDL event type " << event.type << LL_ENDL; - break; + default: + //LL_INFOS() << "Unhandled SDL event type " << event.type << LL_ENDL; + break; } } @@ -1999,8 +1951,8 @@ void LLWindowSDL::gatherInput() // expired. if (mFlashing && mFlashTimer.hasExpired()) { - x11_set_urgent(FALSE); - mFlashing = FALSE; + x11_set_urgent(false); + mFlashing = false; } #endif // LL_X11 } @@ -2016,21 +1968,21 @@ static SDL_Cursor *makeSDLCursorFromBMP(const char *filename, int hotx, int hoty { SDL_Surface *cursurface; LL_DEBUGS() << "Loaded cursor file " << filename << " " - << bmpsurface->w << "x" << bmpsurface->h << LL_ENDL; + << bmpsurface->w << "x" << bmpsurface->h << LL_ENDL; cursurface = SDL_CreateRGBSurface (SDL_SWSURFACE, - bmpsurface->w, - bmpsurface->h, - 32, - SDL_SwapLE32(0xFFU), - SDL_SwapLE32(0xFF00U), - SDL_SwapLE32(0xFF0000U), - SDL_SwapLE32(0xFF000000U)); + bmpsurface->w, + bmpsurface->h, + 32, + SDL_SwapLE32(0xFFU), + SDL_SwapLE32(0xFF00U), + SDL_SwapLE32(0xFF0000U), + SDL_SwapLE32(0xFF000000U)); SDL_FillRect(cursurface, NULL, SDL_SwapLE32(0x00000000U)); // Blit the cursor pixel data onto a 32-bit RGBA surface so we // only have to cope with processing one type of pixel format. if (0 == SDL_BlitSurface(bmpsurface, NULL, - cursurface, NULL)) + cursurface, NULL)) { // n.b. we already checked that width is a multiple of 8. const int bitmap_bytes = (cursurface->w * cursurface->h) / 8; @@ -2045,26 +1997,26 @@ static SDL_Cursor *makeSDLCursorFromBMP(const char *filename, int hotx, int hoty for (i=0; i<cursurface->h; ++i) { for (j=0; j<cursurface->w; ++j) { U8 *pixelp = - ((U8*)cursurface->pixels) - + cursurface->pitch * i - + j*cursurface->format->BytesPerPixel; + ((U8*)cursurface->pixels) + + cursurface->pitch * i + + j*cursurface->format->BytesPerPixel; U8 srcred = pixelp[0]; U8 srcgreen = pixelp[1]; U8 srcblue = pixelp[2]; - BOOL mask_bit = (srcred != 200) - || (srcgreen != 200) - || (srcblue != 200); - BOOL data_bit = mask_bit && (srcgreen <= 80);//not 0x80 + bool mask_bit = (srcred != 200) + || (srcgreen != 200) + || (srcblue != 200); + bool data_bit = mask_bit && (srcgreen <= 80);//not 0x80 unsigned char bit_offset = (cursurface->w/8) * i - + j/8; + + j/8; cursor_data[bit_offset] |= (data_bit) << (7 - (j&7)); cursor_mask[bit_offset] |= (mask_bit) << (7 - (j&7)); } } sdlcursor = SDL_CreateCursor((Uint8*)cursor_data, - (Uint8*)cursor_mask, - cursurface->w, cursurface->h, - hotx, hoty); + (Uint8*)cursor_mask, + cursurface->w, cursurface->h, + hotx, hoty); delete[] cursor_data; delete[] cursor_mask; } else { @@ -2213,8 +2165,8 @@ void LLWindowSDL::hideCursor() if(!mCursorHidden) { // LL_INFOS() << "hideCursor: hiding" << LL_ENDL; - mCursorHidden = TRUE; - mHideCursorPermanent = TRUE; + mCursorHidden = true; + mHideCursorPermanent = true; SDL_ShowCursor(0); } else @@ -2228,8 +2180,8 @@ void LLWindowSDL::showCursor() if(mCursorHidden) { // LL_INFOS() << "showCursor: showing" << LL_ENDL; - mCursorHidden = FALSE; - mHideCursorPermanent = FALSE; + mCursorHidden = false; + mHideCursorPermanent = false; SDL_ShowCursor(1); } else @@ -2251,10 +2203,12 @@ void LLWindowSDL::hideCursorUntilMouseMove() if (!mHideCursorPermanent) { hideCursor(); - mHideCursorPermanent = FALSE; + mHideCursorPermanent = false; } } + + // // LLSplashScreenSDL - I don't think we'll bother to implement this; it's // fairly obsolete at this point. @@ -2279,51 +2233,133 @@ void LLSplashScreenSDL::hideImpl() { } + + +#if LL_GTK +static void response_callback (GtkDialog *dialog, + gint arg1, + gpointer user_data) +{ + gint *response = (gint*)user_data; + *response = arg1; + gtk_widget_destroy(GTK_WIDGET(dialog)); + gtk_main_quit(); +} + S32 OSMessageBoxSDL(const std::string& text, const std::string& caption, U32 type) { - SDL_MessageBoxData oData = { SDL_MESSAGEBOX_INFORMATION, nullptr, caption.c_str(), text.c_str(), 0, nullptr, nullptr }; - SDL_MessageBoxButtonData btnOk[] = {{SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, OSBTN_OK, "OK" }}; - SDL_MessageBoxButtonData btnOkCancel [] = {{SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, OSBTN_OK, "OK" }, {SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, OSBTN_CANCEL, "Cancel"} }; - SDL_MessageBoxButtonData btnYesNo[] = { {SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, OSBTN_YES, "Yes" }, {SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, OSBTN_NO, "No"} }; + S32 rtn = OSBTN_CANCEL; + + if(gWindowImplementation != NULL) + gWindowImplementation->beforeDialog(); - switch (type) + if (LLWindowSDL::ll_try_gtk_init()) { + GtkWidget *win = NULL; + + LL_INFOS() << "Creating a dialog because we're in windowed mode and GTK is happy." << LL_ENDL; + + GtkDialogFlags flags = GTK_DIALOG_MODAL; + GtkMessageType messagetype; + GtkButtonsType buttons; + switch (type) + { default: case OSMB_OK: - oData.flags = SDL_MESSAGEBOX_WARNING; - oData.buttons = btnOk; - oData.numbuttons = 1; + messagetype = GTK_MESSAGE_WARNING; + buttons = GTK_BUTTONS_OK; break; case OSMB_OKCANCEL: - oData.flags = SDL_MESSAGEBOX_INFORMATION; - oData.buttons = btnOkCancel; - oData.numbuttons = 2; + messagetype = GTK_MESSAGE_QUESTION; + buttons = GTK_BUTTONS_OK_CANCEL; break; case OSMB_YESNO: - oData.flags = SDL_MESSAGEBOX_INFORMATION; - oData.buttons = btnYesNo; - oData.numbuttons = 2; + messagetype = GTK_MESSAGE_QUESTION; + buttons = GTK_BUTTONS_YES_NO; break; + } + win = gtk_message_dialog_new(NULL, flags, messagetype, buttons, "%s", + text.c_str()); + +# if LL_X11 + // Make GTK tell the window manager to associate this + // dialog with our non-GTK SDL window, which should try + // to keep it on top etc. + if (gWindowImplementation && + gWindowImplementation->mSDL_XWindowID != None) + { + gtk_widget_realize(GTK_WIDGET(win)); // so we can get its gdkwin + GdkWindow *gdkwin = gdk_window_foreign_new(gWindowImplementation->mSDL_XWindowID); + gdk_window_set_transient_for(GTK_WIDGET(win)->window, + gdkwin); + } +# endif //LL_X11 + + gtk_window_set_position(GTK_WINDOW(win), + GTK_WIN_POS_CENTER_ON_PARENT); + + gtk_window_set_type_hint(GTK_WINDOW(win), + GDK_WINDOW_TYPE_HINT_DIALOG); + + if (!caption.empty()) + gtk_window_set_title(GTK_WINDOW(win), caption.c_str()); + + gint response = GTK_RESPONSE_NONE; + g_signal_connect (win, + "response", + G_CALLBACK (response_callback), + &response); + + // we should be able to use a gtk_dialog_run(), but it's + // apparently not written to exist in a world without a higher + // gtk_main(), so we manage its signal/destruction outselves. + gtk_widget_show_all (win); + gtk_main(); + + //LL_INFOS() << "response: " << response << LL_ENDL; + switch (response) + { + case GTK_RESPONSE_OK: rtn = OSBTN_OK; break; + case GTK_RESPONSE_YES: rtn = OSBTN_YES; break; + case GTK_RESPONSE_NO: rtn = OSBTN_NO; break; + case GTK_RESPONSE_APPLY: rtn = OSBTN_OK; break; + case GTK_RESPONSE_NONE: + case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_CLOSE: + case GTK_RESPONSE_DELETE_EVENT: + default: rtn = OSBTN_CANCEL; + } + } + else + { + LL_INFOS() << "MSGBOX: " << caption << ": " << text << LL_ENDL; + LL_INFOS() << "Skipping dialog because we're in fullscreen mode or GTK is not happy." << LL_ENDL; + rtn = OSBTN_OK; } - int btn{0}; - if( 0 == SDL_ShowMessageBox( &oData, &btn ) ) - return btn; - return OSBTN_CANCEL; + if(gWindowImplementation != NULL) + gWindowImplementation->afterDialog(); + + return rtn; } -BOOL LLWindowSDL::dialogColorPicker( F32 *r, F32 *g, F32 *b) +static void color_changed_callback(GtkWidget *widget, + gpointer user_data) { - return (FALSE); + GtkColorSelection *colorsel = GTK_COLOR_SELECTION(widget); + GdkColor *colorp = (GdkColor*)user_data; + + gtk_color_selection_get_current_color(colorsel, colorp); } + /* Make the raw keyboard data available - used to poke through to LLQtWebKit so that Qt/Webkit has access to the virtual keycodes etc. that it needs */ LLSD LLWindowSDL::getNativeKeyData() { - LLSD result = LLSD::emptyMap(); + LLSD result = LLSD::emptyMap(); U32 modifiers = 0; // pretend-native modifiers... oh what a tangled web we weave! @@ -2341,14 +2377,99 @@ LLSD LLWindowSDL::getNativeKeyData() // *todo: test ALTs - I don't have a case for testing these. Do you? // *todo: NUM? - I don't care enough right now (and it's not a GDK modifier). - result["virtual_key"] = (S32)mKeyVirtualKey; - result["virtual_key_win"] = (S32)LLKeyboardSDL::mapSDL2toWin( mKeyVirtualKey ); + result["scan_code"] = (S32)mKeyScanCode; + result["virtual_key"] = (S32)mKeyVirtualKey; result["modifiers"] = (S32)modifiers; - result["input_type"] = mInputType; - return result; + + return result; } -#if LL_LINUX || LL_SOLARIS + +bool LLWindowSDL::dialogColorPicker( F32 *r, F32 *g, F32 *b) +{ + bool rtn = false; + + beforeDialog(); + + if (ll_try_gtk_init()) + { + GtkWidget *win = NULL; + + win = gtk_color_selection_dialog_new(NULL); + +# if LL_X11 + // Get GTK to tell the window manager to associate this + // dialog with our non-GTK SDL window, which should try + // to keep it on top etc. + if (mSDL_XWindowID != None) + { + gtk_widget_realize(GTK_WIDGET(win)); // so we can get its gdkwin + GdkWindow *gdkwin = gdk_window_foreign_new(mSDL_XWindowID); + gdk_window_set_transient_for(GTK_WIDGET(win)->window, + gdkwin); + } +# endif //LL_X11 + + GtkColorSelection *colorsel = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG(win)->colorsel); + + GdkColor color, orig_color; + orig_color.pixel = 0; + orig_color.red = guint16(65535 * *r); + orig_color.green= guint16(65535 * *g); + orig_color.blue = guint16(65535 * *b); + color = orig_color; + + gtk_color_selection_set_previous_color (colorsel, &color); + gtk_color_selection_set_current_color (colorsel, &color); + gtk_color_selection_set_has_palette (colorsel, true); + gtk_color_selection_set_has_opacity_control(colorsel, false); + + gint response = GTK_RESPONSE_NONE; + g_signal_connect (win, + "response", + G_CALLBACK (response_callback), + &response); + + g_signal_connect (G_OBJECT (colorsel), "color_changed", + G_CALLBACK (color_changed_callback), + &color); + + gtk_window_set_modal(GTK_WINDOW(win), true); + gtk_widget_show_all(win); + // hide the help button - we don't service it. + gtk_widget_hide(GTK_COLOR_SELECTION_DIALOG(win)->help_button); + gtk_main(); + + if (response == GTK_RESPONSE_OK && + (orig_color.red != color.red + || orig_color.green != color.green + || orig_color.blue != color.blue) ) + { + *r = color.red / 65535.0f; + *g = color.green / 65535.0f; + *b = color.blue / 65535.0f; + rtn = true; + } + } + + afterDialog(); + + return rtn; +} +#else +S32 OSMessageBoxSDL(const std::string& text, const std::string& caption, U32 type) +{ + LL_INFOS() << "MSGBOX: " << caption << ": " << text << LL_ENDL; + return 0; +} + +bool LLWindowSDL::dialogColorPicker( F32 *r, F32 *g, F32 *b) +{ + return (false); +} +#endif // LL_GTK + +#if LL_LINUX // extracted from spawnWebBrowser for clarity and to eliminate // compiler confusion regarding close(int fd) vs. LLWindow::close() void exec_cmd(const std::string& cmd, const std::string& arg) @@ -2360,32 +2481,9 @@ void exec_cmd(const std::string& cmd, const std::string& arg) { // child // disconnect from stdin/stdout/stderr, or child will // keep our output pipe undesirably alive if it outlives us. - // close(0); - // close(1); - // close(2); - // <FS:TS> Reopen stdin, stdout, and stderr to /dev/null. - // It's good practice to always have those file - // descriptors open to something, lest the exec'd - // program actually try to use them. - FILE *result; - result = freopen("/dev/null","r",stdin); - if (result == NULL) - { - LL_WARNS() << "Error reopening stdin for web browser: " - << strerror(errno) << LL_ENDL; - } - result = freopen("/dev/null","w",stdout); - if (result == NULL) - { - LL_WARNS() << "Error reopening stdout for web browser: " - << strerror(errno) << LL_ENDL; - } - result = freopen("/dev/null","w",stderr); - if (result == NULL) - { - LL_WARNS() << "Error reopening stderr for web browser: " - << strerror(errno) << LL_ENDL; - } + close(0); + close(1); + close(2); // end ourself by running the command execv(cmd.c_str(), argv); /* Flawfinder: ignore */ // if execv returns at all, there was a problem. @@ -2451,13 +2549,31 @@ void LLWindowSDL::spawnWebBrowser(const std::string& escaped_url, bool async) LL_INFOS() << "spawn_web_browser returning." << LL_ENDL; } -void LLWindowSDL::openFile(const std::string& file_name) -{ - spawnWebBrowser("file://"+file_name,TRUE); -} void *LLWindowSDL::getPlatformWindow() { +#if LL_GTK && LL_LLMOZLIB_ENABLED + if (LLWindowSDL::ll_try_gtk_init()) + { + maybe_lock_display(); + + GtkWidget *owin = gtk_window_new(GTK_WINDOW_POPUP); + // Why a layout widget? A MozContainer would be ideal, but + // it involves exposing Mozilla headers to mozlib-using apps. + // A layout widget with a GtkWindow parent has the desired + // properties of being plain GTK, having a window, and being + // derived from a GtkContainer. + GtkWidget *rtnw = gtk_layout_new(NULL, NULL); + gtk_container_add(GTK_CONTAINER(owin), rtnw); + gtk_widget_realize(rtnw); + GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(rtnw), GTK_NO_WINDOW); + + maybe_unlock_display(); + + return rtnw; + } +#endif // LL_GTK && LL_LLMOZLIB_ENABLED + // Unixoid mozilla really needs GTK. return NULL; } @@ -2518,10 +2634,10 @@ std::vector<std::string> LLWindowSDL::getDynamicFallbackFontList() LL_INFOS("AppInit") << "Variant " << locale->variant << LL_ENDL; LL_INFOS() << "Preferring fonts of language: " - << locale->lang - << LL_ENDL; + << locale->lang + << LL_ENDL; sort_order = "lang=" + std::string(locale->lang) + ":" - + sort_order; + + sort_order; } } FL_FreeLocale(&locale); @@ -2539,7 +2655,7 @@ std::vector<std::string> LLWindowSDL::getDynamicFallbackFontList() // Sort the list of system fonts from most-to-least-desirable. FcResult result; fs = FcFontSort(NULL, sortpat, elide_unicode_coverage, - NULL, &result); + NULL, &result); FcPatternDestroy(sortpat); } @@ -2553,8 +2669,8 @@ std::vector<std::string> LLWindowSDL::getDynamicFallbackFontList() { FcChar8 *filename; if (FcResultMatch == FcPatternGetString(fs->fonts[i], - FC_FILE, 0, - &filename) + FC_FILE, 0, + &filename) && filename) { rtns.push_back(std::string((const char*)filename)); @@ -2578,59 +2694,4 @@ std::vector<std::string> LLWindowSDL::getDynamicFallbackFontList() return rtns; } - -void* LLWindowSDL::createSharedContext() -{ - auto *pContext = SDL_GL_CreateContext(mWindow); - if ( pContext) - { - SDL_GL_SetSwapInterval(0); - SDL_GL_MakeCurrent(mWindow, mContext); - - LLCoordScreen size; - if (getSize(&size)) - setSize(size); - - LL_DEBUGS() << "Creating shared OpenGL context successful!" << LL_ENDL; - - return (void*)pContext; - } - - LL_WARNS() << "Creating shared OpenGL context failed!" << LL_ENDL; - - return nullptr; -} - -void LLWindowSDL::makeContextCurrent(void* contextPtr) -{ - LL_PROFILER_GPU_CONTEXT; - SDL_GL_MakeCurrent( mWindow, contextPtr ); -} - -void LLWindowSDL::destroySharedContext(void* contextPtr) -{ - SDL_GL_DeleteContext( contextPtr ); -} - -void LLWindowSDL::toggleVSync(bool enable_vsync) -{ -} - -U32 LLWindowSDL::getAvailableVRAMMegabytes() -{ - return 4096; -} - -void LLWindowSDL::setLanguageTextInput(const LLCoordGL& position) -{ - LLCoordWindow win_pos; - convertCoords( position, &win_pos ); - - SDL_Rect r; - r.x = win_pos.mX; - r.y = win_pos.mY; - r.w = 500; - r.h = 16; - - SDL_SetTextInputRect(&r); -} +#endif // LL_SDL diff --git a/indra/llwindow/llwindowsdl.h b/indra/llwindow/llwindowsdl.h index d24739cbda..196ad2986d 100644 --- a/indra/llwindow/llwindowsdl.h +++ b/indra/llwindow/llwindowsdl.h @@ -24,20 +24,20 @@ * $/LicenseInfo$ */ -#ifndef LL_LLWINDOWSDL2_H -#define LL_LLWINDOWSDL2_H +#ifndef LL_LLWINDOWSDL_H +#define LL_LLWINDOWSDL_H // Simple Directmedia Layer (http://libsdl.org/) implementation of LLWindow class #include "llwindow.h" #include "lltimer.h" -#include "SDL2/SDL.h" -#include "SDL2/SDL_endian.h" +#include "SDL/SDL.h" +#include "SDL/SDL_endian.h" #if LL_X11 // get X11-specific headers for use in low-level stuff like copy-and-paste support -#include "SDL2/SDL_syswm.h" +#include "SDL/SDL_syswm.h" #endif // AssertMacros.h does bad things. @@ -46,139 +46,83 @@ #undef require -class LLWindowSDL : public LLWindow { +class LLWindowSDL : public LLWindow +{ public: - void show() override; - - void hide() override; - - void close() override; - - BOOL getVisible() override; - - BOOL getMinimized() override; - - BOOL getMaximized() override; - - BOOL maximize() override; - - void minimize() override; - - void restore() override; - - BOOL getFullscreen(); - - BOOL getPosition(LLCoordScreen *position) override; - - BOOL getSize(LLCoordScreen *size) override; - - BOOL getSize(LLCoordWindow *size) override; - - BOOL setPosition(LLCoordScreen position) override; - - BOOL setSizeImpl(LLCoordScreen size) override; - - BOOL setSizeImpl(LLCoordWindow size) override; - - BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL disable_vsync, - const LLCoordScreen *const posp = NULL) override; - - BOOL setCursorPosition(LLCoordWindow position) override; - - BOOL getCursorPosition(LLCoordWindow *position) override; - - void showCursor() override; - - void hideCursor() override; - - void showCursorFromMouseMove() override; - - void hideCursorUntilMouseMove() override; - - BOOL isCursorHidden() override; - - void updateCursor() override; - - void captureMouse() override; - - void releaseMouse() override; - - void setMouseClipping(BOOL b) override; - - void setMinSize(U32 min_width, U32 min_height, bool enforce_immediately = true) override; - - BOOL isClipboardTextAvailable() override; - - BOOL pasteTextFromClipboard(LLWString &dst) override; - - BOOL copyTextToClipboard(const LLWString &src) override; - - BOOL isPrimaryTextAvailable() override; - - BOOL pasteTextFromPrimary(LLWString &dst) override; - - BOOL copyTextToPrimary(const LLWString &src) override; - - void flashIcon(F32 seconds) override; - - F32 getGamma() override; - - BOOL setGamma(const F32 gamma) override; // Set the gamma - U32 getFSAASamples() override; - - void setFSAASamples(const U32 samples) override; - - BOOL restoreGamma() override; // Restore original gamma table (before updating gamma) - ESwapMethod getSwapMethod() override { return mSwapMethod; } - - void processMiscNativeEvents() override; - - void gatherInput() override; - - void swapBuffers() override; - - void restoreGLContext() {}; - - void delayInputProcessing() override {}; + /*virtual*/ void show(); + /*virtual*/ void hide(); + /*virtual*/ void close(); + /*virtual*/ bool getVisible(); + /*virtual*/ bool getMinimized(); + /*virtual*/ bool getMaximized(); + /*virtual*/ bool maximize(); + /*virtual*/ void minimize(); + /*virtual*/ void restore(); + /*virtual*/ bool getFullscreen(); + /*virtual*/ bool getPosition(LLCoordScreen *position); + /*virtual*/ bool getSize(LLCoordScreen *size); + /*virtual*/ bool getSize(LLCoordWindow *size); + /*virtual*/ bool setPosition(LLCoordScreen position); + /*virtual*/ bool setSizeImpl(LLCoordScreen size); + /*virtual*/ bool setSizeImpl(LLCoordWindow size); + /*virtual*/ bool switchContext(bool fullscreen, const LLCoordScreen &size, bool disable_vsync, const LLCoordScreen * const posp = NULL); + /*virtual*/ bool setCursorPosition(LLCoordWindow position); + /*virtual*/ bool getCursorPosition(LLCoordWindow *position); + /*virtual*/ void showCursor(); + /*virtual*/ void hideCursor(); + /*virtual*/ void showCursorFromMouseMove(); + /*virtual*/ void hideCursorUntilMouseMove(); + /*virtual*/ bool isCursorHidden(); + /*virtual*/ void updateCursor(); + /*virtual*/ void captureMouse(); + /*virtual*/ void releaseMouse(); + /*virtual*/ void setMouseClipping( bool b ); + /*virtual*/ void setMinSize(U32 min_width, U32 min_height, bool enforce_immediately = true); + + /*virtual*/ bool isClipboardTextAvailable(); + /*virtual*/ bool pasteTextFromClipboard(LLWString &dst); + /*virtual*/ bool copyTextToClipboard(const LLWString & src); + + /*virtual*/ bool isPrimaryTextAvailable(); + /*virtual*/ bool pasteTextFromPrimary(LLWString &dst); + /*virtual*/ bool copyTextToPrimary(const LLWString & src); + + /*virtual*/ void flashIcon(F32 seconds); + /*virtual*/ F32 getGamma(); + /*virtual*/ bool setGamma(const F32 gamma); // Set the gamma + /*virtual*/ U32 getFSAASamples(); + /*virtual*/ void setFSAASamples(const U32 samples); + /*virtual*/ bool restoreGamma(); // Restore original gamma table (before updating gamma) + /*virtual*/ ESwapMethod getSwapMethod() { return mSwapMethod; } + /*virtual*/ void processMiscNativeEvents(); + /*virtual*/ void gatherInput(); + /*virtual*/ void swapBuffers(); + /*virtual*/ void restoreGLContext() {}; + + /*virtual*/ void delayInputProcessing() { }; // handy coordinate space conversion routines - BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to) override; - - BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to) override; - - BOOL convertCoords(LLCoordWindow from, LLCoordGL *to) override; - - BOOL convertCoords(LLCoordGL from, LLCoordWindow *to) override; - - BOOL convertCoords(LLCoordScreen from, LLCoordGL *to) override; + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordWindow *to); + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordScreen *to); + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordGL *to); + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordWindow *to); + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordGL *to); + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordScreen *to); - BOOL convertCoords(LLCoordGL from, LLCoordScreen *to) override; + /*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions); + /*virtual*/ F32 getNativeAspectRatio(); + /*virtual*/ F32 getPixelAspectRatio(); + /*virtual*/ void setNativeAspectRatio(F32 ratio) { mOverrideAspectRatio = ratio; } - LLWindowResolution *getSupportedResolutions(S32 &num_resolutions) override; + /*virtual*/ void beforeDialog(); + /*virtual*/ void afterDialog(); - F32 getNativeAspectRatio() override; + /*virtual*/ bool dialogColorPicker(F32 *r, F32 *g, F32 *b); - F32 getPixelAspectRatio() override; + /*virtual*/ void *getPlatformWindow(); + /*virtual*/ void bringToFront(); - void setNativeAspectRatio(F32 ratio) override { mOverrideAspectRatio = ratio; } - - void beforeDialog() override; - - void afterDialog() override; - - BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b) override; - - void *getPlatformWindow() override; - - void bringToFront() override; - - void setLanguageTextInput(const LLCoordGL& pos) override; - - void spawnWebBrowser(const std::string &escaped_url, bool async) override; - - void openFile(const std::string &file_name); - - void setTitle(const std::string title) override; + /*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async); static std::vector<std::string> getDynamicFallbackFontList(); @@ -188,54 +132,40 @@ public: Window mSDL_XWindowID; Display *mSDL_Display; #endif - void (*Lock_Display)(void); - void (*Unlock_Display)(void); -#if LL_X11 +#if LL_GTK + // Lazily initialize and check the runtime GTK version for goodness. + static bool ll_try_gtk_init(void); +#endif // LL_GTK +#if LL_X11 static Window get_SDL_XWindowID(void); - - static Display *get_SDL_Display(void); - + static Display* get_SDL_Display(void); #endif // LL_X11 - void *createSharedContext() override; - - void makeContextCurrent(void *context) override; - - void destroySharedContext(void *context) override; - - void toggleVSync(bool enable_vsync) override; - - U32 getAvailableVRAMMegabytes() override; - protected: - LLWindowSDL(LLWindowCallbacks *callbacks, - const std::string &title, int x, int y, int width, int height, U32 flags, - BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, U32 fsaa_samples); - + LLWindowSDL(LLWindowCallbacks* callbacks, + const std::string& title, int x, int y, int width, int height, U32 flags, + bool fullscreen, bool clearBg, bool disable_vsync, bool use_gl, + bool ignore_pixel_depth, U32 fsaa_samples); ~LLWindowSDL(); - BOOL isValid() override; - - LLSD getNativeKeyData() override; - - void initCursors(); + /*virtual*/ bool isValid(); + /*virtual*/ LLSD getNativeKeyData(); - void quitCursors(); - - void moveWindow(const LLCoordScreen &position, const LLCoordScreen &size); + void initCursors(); + void quitCursors(); + void moveWindow(const LLCoordScreen& position,const LLCoordScreen& size); // Changes display resolution. Returns true if successful - BOOL setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh); + bool setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh); // Go back to last fullscreen display resolution. - BOOL setFullscreenResolution(); + bool setFullscreenResolution(); - BOOL shouldPostQuit() { return mPostQuit; } + bool shouldPostQuit() { return mPostQuit; } protected: // @@ -243,95 +173,57 @@ protected: // // create or re-create the GL context/window. Called from the constructor and switchContext(). - BOOL createContext(int x, int y, int width, int height, int bits, BOOL fullscreen, BOOL disable_vsync); - + bool createContext(int x, int y, int width, int height, int bits, bool fullscreen, bool disable_vsync); void destroyContext(); - - void setupFailure(const std::string &text, const std::string &caption, U32 type); - + void setupFailure(const std::string& text, const std::string& caption, U32 type); void fixWindowSize(void); - - U32 SDLCheckGrabbyKeys(U32 keysym, BOOL gain); - - BOOL SDLReallyCaptureInput(BOOL capture); + U32 SDLCheckGrabbyKeys(SDLKey keysym, bool gain); + bool SDLReallyCaptureInput(bool capture); // // Platform specific variables // - U32 mGrabbyKeyFlags; - int mReallyCapturedCount; - - SDL_Window *mWindow; - SDL_Surface *mSurface; - SDL_GLContext mContext; - SDL_Cursor *mSDLCursors[UI_CURSOR_COUNT]; - + U32 mGrabbyKeyFlags; + int mReallyCapturedCount; + SDL_Surface * mWindow; std::string mWindowTitle; - double mOriginalAspectRatio; - BOOL mNeedsResize; // Constructor figured out the window is too big, it needs a resize. - LLCoordScreen mNeedsResizeSize; - F32 mOverrideAspectRatio; - F32 mGamma; - U32 mFSAASamples; + double mOriginalAspectRatio; + bool mNeedsResize; // Constructor figured out the window is too big, it needs a resize. + LLCoordScreen mNeedsResizeSize; + F32 mOverrideAspectRatio; + F32 mGamma; + U32 mFSAASamples; - int mSDLFlags; + int mSDLFlags; - int mHaveInputFocus; /* 0=no, 1=yes, else unknown */ - int mIsMinimized; /* 0=no, 1=yes, else unknown */ + SDL_Cursor* mSDLCursors[UI_CURSOR_COUNT]; + int mHaveInputFocus; /* 0=no, 1=yes, else unknown */ + int mIsMinimized; /* 0=no, 1=yes, else unknown */ friend class LLWindowManager; private: #if LL_X11 - - void x11_set_urgent(BOOL urgent); - - BOOL mFlashing; + void x11_set_urgent(bool urgent); + bool mFlashing; LLTimer mFlashTimer; #endif //LL_X11 - U32 mKeyVirtualKey; - U32 mKeyModifiers; - std::string mInputType; - -public: -#if LL_X11 - - static Display *getSDLDisplay(); - - LLWString const &getPrimaryText() const { return mPrimaryClipboard; } - - LLWString const &getSecondaryText() const { return mSecondaryClipboard; } - - void clearPrimaryText() { mPrimaryClipboard.clear(); } - - void clearSecondaryText() { mSecondaryClipboard.clear(); } - -private: - void tryFindFullscreenSize(int &aWidth, int &aHeight); - - void initialiseX11Clipboard(); - - bool getSelectionText(Atom selection, LLWString &text); - - bool getSelectionText(Atom selection, Atom type, LLWString &text); - - bool setSelectionText(Atom selection, const LLWString &text); - -#endif - LLWString mPrimaryClipboard; - LLWString mSecondaryClipboard; + U32 mKeyScanCode; + U32 mKeyVirtualKey; + SDLMod mKeyModifiers; }; + class LLSplashScreenSDL : public LLSplashScreen { public: LLSplashScreenSDL(); virtual ~LLSplashScreenSDL(); - void showImpl(); - void updateImpl(const std::string& mesg); - void hideImpl(); + /*virtual*/ void showImpl(); + /*virtual*/ void updateImpl(const std::string& mesg); + /*virtual*/ void hideImpl(); }; S32 OSMessageBoxSDL(const std::string& text, const std::string& caption, U32 type); diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index 12cd5320b8..a2d812ae0d 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -92,7 +92,7 @@ const F32 ICON_FLASH_TIME = 0.5f; const UINT WM_DUMMY_(WM_USER + 0x0017); const UINT WM_POST_FUNCTION_(WM_USER + 0x0018); -extern BOOL gDebugWindowProc; +extern bool gDebugWindowProc; static std::thread::id sWindowThreadId; static std::thread::id sMainThreadId; @@ -167,10 +167,10 @@ GLuint SafeChoosePixelFormat(HDC &hdc, const PIXELFORMATDESCRIPTOR *ppfd) } //static -BOOL LLWindowWin32::sIsClassRegistered = FALSE; +bool LLWindowWin32::sIsClassRegistered = false; -BOOL LLWindowWin32::sLanguageTextInputAllowed = TRUE; -BOOL LLWindowWin32::sWinIMEOpened = FALSE; +bool LLWindowWin32::sLanguageTextInputAllowed = true; +bool LLWindowWin32::sWinIMEOpened = false; HKL LLWindowWin32::sWinInputLocale = 0; DWORD LLWindowWin32::sWinIMEConversionMode = IME_CMODE_NATIVE; DWORD LLWindowWin32::sWinIMESentenceMode = IME_SMODE_AUTOMATIC; @@ -189,24 +189,24 @@ public: public: // Wrappers for IMM API. - static BOOL isIME(HKL hkl); + static bool isIME(HKL hkl); static HIMC getContext(HWND hwnd); - static BOOL releaseContext(HWND hwnd, HIMC himc); - static BOOL getOpenStatus(HIMC himc); - static BOOL setOpenStatus(HIMC himc, BOOL status); - static BOOL getConversionStatus(HIMC himc, LPDWORD conversion, LPDWORD sentence); - static BOOL setConversionStatus(HIMC himc, DWORD conversion, DWORD sentence); - static BOOL getCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form); - static BOOL setCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form); + static bool releaseContext(HWND hwnd, HIMC himc); + static bool getOpenStatus(HIMC himc); + static bool setOpenStatus(HIMC himc, bool status); + static bool getConversionStatus(HIMC himc, LPDWORD conversion, LPDWORD sentence); + static bool setConversionStatus(HIMC himc, DWORD conversion, DWORD sentence); + static bool getCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form); + static bool setCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form); static LONG getCompositionString(HIMC himc, DWORD index, LPVOID data, DWORD length); - static BOOL setCompositionString(HIMC himc, DWORD index, LPVOID pComp, DWORD compLength, LPVOID pRead, DWORD readLength); - static BOOL setCompositionFont(HIMC himc, LPLOGFONTW logfont); - static BOOL setCandidateWindow(HIMC himc, LPCANDIDATEFORM candidate_form); - static BOOL notifyIME(HIMC himc, DWORD action, DWORD index, DWORD value); + static bool setCompositionString(HIMC himc, DWORD index, LPVOID pComp, DWORD compLength, LPVOID pRead, DWORD readLength); + static bool setCompositionFont(HIMC himc, LPLOGFONTW logfont); + static bool setCandidateWindow(HIMC himc, LPCANDIDATEFORM candidate_form); + static bool notifyIME(HIMC himc, DWORD action, DWORD index, DWORD value); }; // static -BOOL LLWinImm::isIME(HKL hkl) +bool LLWinImm::isIME(HKL hkl) { return ImmIsIME(hkl); } @@ -218,43 +218,43 @@ HIMC LLWinImm::getContext(HWND hwnd) } //static -BOOL LLWinImm::releaseContext(HWND hwnd, HIMC himc) +bool LLWinImm::releaseContext(HWND hwnd, HIMC himc) { return ImmReleaseContext(hwnd, himc); } // static -BOOL LLWinImm::getOpenStatus(HIMC himc) +bool LLWinImm::getOpenStatus(HIMC himc) { return ImmGetOpenStatus(himc); } // static -BOOL LLWinImm::setOpenStatus(HIMC himc, BOOL status) +bool LLWinImm::setOpenStatus(HIMC himc, bool status) { return ImmSetOpenStatus(himc, status); } // static -BOOL LLWinImm::getConversionStatus(HIMC himc, LPDWORD conversion, LPDWORD sentence) +bool LLWinImm::getConversionStatus(HIMC himc, LPDWORD conversion, LPDWORD sentence) { return ImmGetConversionStatus(himc, conversion, sentence); } // static -BOOL LLWinImm::setConversionStatus(HIMC himc, DWORD conversion, DWORD sentence) +bool LLWinImm::setConversionStatus(HIMC himc, DWORD conversion, DWORD sentence) { return ImmSetConversionStatus(himc, conversion, sentence); } // static -BOOL LLWinImm::getCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form) +bool LLWinImm::getCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form) { return ImmGetCompositionWindow(himc, form); } // static -BOOL LLWinImm::setCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form) +bool LLWinImm::setCompositionWindow(HIMC himc, LPCOMPOSITIONFORM form) { return ImmSetCompositionWindow(himc, form); } @@ -268,25 +268,25 @@ LONG LLWinImm::getCompositionString(HIMC himc, DWORD index, LPVOID data, // static -BOOL LLWinImm::setCompositionString(HIMC himc, DWORD index, LPVOID pComp, DWORD compLength, LPVOID pRead, DWORD readLength) +bool LLWinImm::setCompositionString(HIMC himc, DWORD index, LPVOID pComp, DWORD compLength, LPVOID pRead, DWORD readLength) { return ImmSetCompositionString(himc, index, pComp, compLength, pRead, readLength); } // static -BOOL LLWinImm::setCompositionFont(HIMC himc, LPLOGFONTW pFont) +bool LLWinImm::setCompositionFont(HIMC himc, LPLOGFONTW pFont) { return ImmSetCompositionFont(himc, pFont); } // static -BOOL LLWinImm::setCandidateWindow(HIMC himc, LPCANDIDATEFORM form) +bool LLWinImm::setCandidateWindow(HIMC himc, LPCANDIDATEFORM form) { return ImmSetCandidateWindow(himc, form); } // static -BOOL LLWinImm::notifyIME(HIMC himc, DWORD action, DWORD index, DWORD value) +bool LLWinImm::notifyIME(HIMC himc, DWORD action, DWORD index, DWORD value) { return ImmNotifyIME(himc, action, index, value); } @@ -350,22 +350,8 @@ struct LLWindowWin32::LLWindowWin32Thread : public LL::ThreadPool mGLReady = true; } - // initialzie DXGI adapter (for querying available VRAM) - void initDX(); - - // initialize D3D (if DXGI cannot be used) - void initD3D(); - - //clean up DXGI/D3D resources - void cleanupDX(); - - // call periodically to update available VRAM - void updateVRAMUsage(); - - U32 getAvailableVRAMMegabytes() - { - return mAvailableVRAM; - } + // Use DXGI to check memory (because WMI doesn't report more than 4Gb) + void checkDXMem(); /// called by main thread to post work to this window thread template <typename CALLABLE> @@ -407,33 +393,24 @@ struct LLWindowWin32::LLWindowWin32Thread : public LL::ThreadPool using FuncType = std::function<void()>; // call GetMessage() and pull enqueue messages for later processing - void gatherInput(); HWND mWindowHandleThrd = NULL; HDC mhDCThrd = 0; // *HACK: Attempt to prevent startup crashes by deferring memory accounting // until after some graphics setup. See SL-20177. -Cosmic,2023-09-18 bool mGLReady = false; - // best guess at available video memory in MB - std::atomic<U32> mAvailableVRAM; - - U32 mMaxVRAM = 0; // maximum amount of vram to allow in the "budget", or 0 for no maximum (see updateVRAMUsage) - - IDXGIAdapter3* mDXGIAdapter = nullptr; - LPDIRECT3D9 mD3D = nullptr; - LPDIRECT3DDEVICE9 mD3DDevice = nullptr; + bool mGotGLBuffer = false; }; LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, U32 flags, - BOOL fullscreen, BOOL clearBg, - BOOL enable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, + bool fullscreen, bool clearBg, + bool enable_vsync, bool use_gl, + bool ignore_pixel_depth, U32 fsaa_samples, U32 max_cores, - U32 max_vram, F32 max_gl_version) : LLWindow(callbacks, fullscreen, flags), @@ -442,7 +419,6 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, { sMainThreadId = LLThread::currentID(); mWindowThread = new LLWindowWin32Thread(); - mWindowThread->mMaxVRAM = max_vram; //MAINT-516 -- force a load of opengl32.dll just in case windows went sideways LoadLibrary(L"opengl32.dll"); @@ -454,7 +430,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, mMaxCores = llmin(mMaxCores, (U32) 64); DWORD_PTR mask = 0; - for (int i = 0; i < mMaxCores; ++i) + for (U32 i = 0; i < mMaxCores; ++i) { mask |= ((DWORD_PTR) 1) << i; } @@ -523,7 +499,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, mIconResource = gIconResource; mOverrideAspectRatio = 0.f; mNativeAspectRatio = 0.f; - mInputProcessingPaused = FALSE; + mInputProcessingPaused = false; mPreeditor = NULL; mKeyCharCode = 0; mKeyScanCode = 0; @@ -532,7 +508,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, mhRC = NULL; memset(mCurrentGammaRamp, 0, sizeof(mCurrentGammaRamp)); memset(mPrevGammaRamp, 0, sizeof(mPrevGammaRamp)); - mCustomGammaSet = FALSE; + mCustomGammaSet = false; mWindowHandle = NULL; mRect = {0, 0, 0, 0}; @@ -540,7 +516,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, if (!SystemParametersInfo(SPI_GETMOUSEVANISH, 0, &mMouseVanish, 0)) { - mMouseVanish = TRUE; + mMouseVanish = true; } // Initialize the keyboard @@ -552,7 +528,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, // Initialize (boot strap) the Language text input management, // based on the system's (user's) default settings. - allowLanguageTextInput(mPreeditor, FALSE); + allowLanguageTextInput(mPreeditor, false); WNDCLASS wc; RECT window_rect; @@ -670,7 +646,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, mCallbacks->translateString("MBError"), OSMB_OK); return; } - sIsClassRegistered = TRUE; + sIsClassRegistered = true; } //----------------------------------------------------------------------- @@ -698,7 +674,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, //----------------------------------------------------------------------- if (mFullscreen) { - BOOL success = FALSE; + bool success = false; DWORD closest_refresh = 0; for (S32 mode_num = 0;; mode_num++) @@ -712,7 +688,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, dev_mode.dmPelsHeight == height && dev_mode.dmBitsPerPel == BITS_PER_PIXEL) { - success = TRUE; + success = true; if ((dev_mode.dmDisplayFrequency - current_refresh) < (closest_refresh - current_refresh)) { @@ -724,11 +700,11 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, if (closest_refresh == 0) { LL_WARNS("Window") << "Couldn't find display mode " << width << " by " << height << " at " << BITS_PER_PIXEL << " bits per pixel" << LL_ENDL; - //success = FALSE; + //success = false; if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dev_mode)) { - success = FALSE; + success = false; } else { @@ -737,12 +713,12 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, LL_WARNS("Window") << "Current BBP is OK falling back to that" << LL_ENDL; window_rect.right=width=dev_mode.dmPelsWidth; window_rect.bottom=height=dev_mode.dmPelsHeight; - success = TRUE; + success = true; } else { LL_WARNS("Window") << "Current BBP is BAD" << LL_ENDL; - success = FALSE; + success = false; } } } @@ -760,7 +736,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, // If it failed, we don't want to run fullscreen if (success) { - mFullscreen = TRUE; + mFullscreen = true; mFullscreenWidth = dev_mode.dmPelsWidth; mFullscreenHeight = dev_mode.dmPelsHeight; mFullscreenBits = dev_mode.dmBitsPerPel; @@ -774,7 +750,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, } else { - mFullscreen = FALSE; + mFullscreen = false; mFullscreenWidth = -1; mFullscreenHeight = -1; mFullscreenBits = -1; @@ -855,7 +831,7 @@ LLWindowWin32::LLWindowWin32(LLWindowCallbacks* callbacks, // Initialize (boot strap) the Language text input management, // based on the system's (or user's) default settings. - allowLanguageTextInput(NULL, FALSE); + allowLanguageTextInput(NULL, false); } @@ -885,14 +861,14 @@ void LLWindowWin32::show() void LLWindowWin32::hide() { - setMouseClipping(FALSE); + setMouseClipping(false); ShowWindow(mWindowHandle, SW_HIDE); } //virtual void LLWindowWin32::minimize() { - setMouseClipping(FALSE); + setMouseClipping(false); showCursor(); ShowWindow(mWindowHandle, SW_MINIMIZE); } @@ -949,7 +925,7 @@ void LLWindowWin32::close() // Make sure cursor is visible and we haven't mangled the clipping state. showCursor(); - setMouseClipping(FALSE); + setMouseClipping(false); if (gKeyboard) { gKeyboard->resetKeys(); @@ -989,29 +965,29 @@ void LLWindowWin32::close() mWindowThread->wakeAndDestroy(); } -BOOL LLWindowWin32::isValid() +bool LLWindowWin32::isValid() { return (mWindowHandle != NULL); } -BOOL LLWindowWin32::getVisible() +bool LLWindowWin32::getVisible() { return (mWindowHandle && IsWindowVisible(mWindowHandle)); } -BOOL LLWindowWin32::getMinimized() +bool LLWindowWin32::getMinimized() { return (mWindowHandle && IsIconic(mWindowHandle)); } -BOOL LLWindowWin32::getMaximized() +bool LLWindowWin32::getMaximized() { return (mWindowHandle && IsZoomed(mWindowHandle)); } -BOOL LLWindowWin32::maximize() +bool LLWindowWin32::maximize() { - BOOL success = FALSE; + bool success = false; if (!mWindowHandle) return success; mWindowThread->post([=] @@ -1026,56 +1002,56 @@ BOOL LLWindowWin32::maximize() } }); - return TRUE; + return true; } -BOOL LLWindowWin32::getFullscreen() +bool LLWindowWin32::getFullscreen() { return mFullscreen; } -BOOL LLWindowWin32::getPosition(LLCoordScreen *position) +bool LLWindowWin32::getPosition(LLCoordScreen *position) { position->mX = mRect.left; position->mY = mRect.top; - return TRUE; + return true; } -BOOL LLWindowWin32::getSize(LLCoordScreen *size) +bool LLWindowWin32::getSize(LLCoordScreen *size) { size->mX = mRect.right - mRect.left; size->mY = mRect.bottom - mRect.top; - return TRUE; + return true; } -BOOL LLWindowWin32::getSize(LLCoordWindow *size) +bool LLWindowWin32::getSize(LLCoordWindow *size) { size->mX = mClientRect.right - mClientRect.left; size->mY = mClientRect.bottom - mClientRect.top; - return TRUE; + return true; } -BOOL LLWindowWin32::setPosition(const LLCoordScreen position) +bool LLWindowWin32::setPosition(const LLCoordScreen position) { LLCoordScreen size; if (!mWindowHandle) { - return FALSE; + return false; } getSize(&size); moveWindow(position, size); - return TRUE; + return true; } -BOOL LLWindowWin32::setSizeImpl(const LLCoordScreen size) +bool LLWindowWin32::setSizeImpl(const LLCoordScreen size) { LLCoordScreen position; getPosition(&position); if (!mWindowHandle) { - return FALSE; + return false; } mWindowThread->post([=]() @@ -1091,10 +1067,10 @@ BOOL LLWindowWin32::setSizeImpl(const LLCoordScreen size) }); moveWindow(position, size); - return TRUE; + return true; } -BOOL LLWindowWin32::setSizeImpl(const LLCoordWindow size) +bool LLWindowWin32::setSizeImpl(const LLCoordWindow size) { RECT window_rect = {0, 0, size.mX, size.mY }; DWORD dw_ex_style = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; @@ -1106,7 +1082,7 @@ BOOL LLWindowWin32::setSizeImpl(const LLCoordWindow size) } // changing fullscreen resolution -BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BOOL enable_vsync, const LLCoordScreen* const posp) +bool LLWindowWin32::switchContext(bool fullscreen, const LLCoordScreen& size, bool enable_vsync, const LLCoordScreen* const posp) { //called from main thread GLuint pixel_format; @@ -1119,11 +1095,11 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO RECT window_rect = { 0, 0, 0, 0 }; S32 width = size.mX; S32 height = size.mY; - BOOL auto_show = FALSE; + bool auto_show = false; if (mhRC) { - auto_show = TRUE; + auto_show = true; resetDisplayResolution(); } @@ -1156,8 +1132,8 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO if (fullscreen) { - mFullscreen = TRUE; - BOOL success = FALSE; + mFullscreen = true; + bool success = false; DWORD closest_refresh = 0; for (S32 mode_num = 0;; mode_num++) @@ -1171,7 +1147,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO dev_mode.dmPelsHeight == height && dev_mode.dmBitsPerPel == BITS_PER_PIXEL) { - success = TRUE; + success = true; if ((dev_mode.dmDisplayFrequency - current_refresh) < (closest_refresh - current_refresh)) { @@ -1183,7 +1159,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO if (closest_refresh == 0) { LL_WARNS("Window") << "Couldn't find display mode " << width << " by " << height << " at " << BITS_PER_PIXEL << " bits per pixel" << LL_ENDL; - return FALSE; + return false; } // If we found a good resolution, use it. @@ -1198,7 +1174,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO if (success) { - mFullscreen = TRUE; + mFullscreen = true; mFullscreenWidth = dev_mode.dmPelsWidth; mFullscreenHeight = dev_mode.dmPelsHeight; mFullscreenBits = dev_mode.dmBitsPerPel; @@ -1224,19 +1200,19 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO // If it failed, we don't want to run fullscreen else { - mFullscreen = FALSE; + mFullscreen = false; mFullscreenWidth = -1; mFullscreenHeight = -1; mFullscreenBits = -1; mFullscreenRefresh = -1; LL_INFOS("Window") << "Unable to run fullscreen at " << width << "x" << height << LL_ENDL; - return FALSE; + return false; } } else { - mFullscreen = FALSE; + mFullscreen = false; window_rect.left = (long)(posp ? posp->mX : 0); window_rect.right = (long)width + window_rect.left; // Windows GDI rects don't include rightmost pixel window_rect.top = (long)(posp ? posp->mY : 0); @@ -1248,7 +1224,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO // don't post quit messages when destroying old windows - mPostQuit = FALSE; + mPostQuit = false; // create window @@ -1298,7 +1274,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO close(); OSMessageBox(mCallbacks->translateString("MBDevContextErr"), mCallbacks->translateString("MBError"), OSMB_OK); - return FALSE; + return false; } LL_INFOS("Window") << "Device context retrieved." << LL_ENDL ; @@ -1312,7 +1288,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO OSMessageBox(mCallbacks->translateString("MBPixelFmtErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } } catch (...) @@ -1321,7 +1297,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO OSMessageBox(mCallbacks->translateString("MBPixelFmtErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } LL_INFOS("Window") << "Pixel format chosen." << LL_ENDL ; @@ -1333,7 +1309,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO OSMessageBox(mCallbacks->translateString("MBPixelFmtDescErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } // (EXP-1765) dump pixel data to see if there is a pattern that leads to unreproducible crash @@ -1372,7 +1348,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO OSMessageBox(mCallbacks->translateString("MBPixelFmtSetErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } @@ -1381,7 +1357,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO OSMessageBox(mCallbacks->translateString("MBGLContextErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } if (!wglMakeCurrent(mhDC, mhRC)) @@ -1389,14 +1365,14 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO OSMessageBox(mCallbacks->translateString("MBGLContextActErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } LL_INFOS("Window") << "Drawing context is created." << LL_ENDL ; gGLManager.initWGL(); - if (wglChoosePixelFormatARB) + if (wglChoosePixelFormatARB && wglGetPixelFormatAttribivARB) { // OK, at this point, use the ARB wglChoosePixelFormatsARB function to see if we // can get exactly what we want. @@ -1481,7 +1457,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO close(); show_window_creation_error("Error after wglChoosePixelFormatARB 32-bit"); - return FALSE; + return false; } if (!num_formats) @@ -1496,7 +1472,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO { close(); show_window_creation_error("Error after wglChoosePixelFormatARB 32-bit no AA"); - return FALSE; + return false; } } @@ -1510,7 +1486,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO { close(); show_window_creation_error("Error after wglChoosePixelFormatARB 24-bit"); - return FALSE; + return false; } if (!num_formats) @@ -1522,7 +1498,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen& size, BO { close(); show_window_creation_error("Error after wglChoosePixelFormatARB 16-bit"); - return FALSE; + return false; } } } @@ -1595,7 +1571,7 @@ const S32 max_format = (S32)num_formats - 1; { OSMessageBox(mCallbacks->translateString("MBDevContextErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } if (!SetPixelFormat(mhDC, pixel_format, &pfd)) @@ -1603,7 +1579,7 @@ const S32 max_format = (S32)num_formats - 1; OSMessageBox(mCallbacks->translateString("MBPixelFmtSetErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } if (wglGetPixelFormatAttribivARB(mhDC, pixel_format, 0, 1, &swap_query, &swap_method)) @@ -1642,7 +1618,7 @@ const S32 max_format = (S32)num_formats - 1; { OSMessageBox(mCallbacks->translateString("MBPixelFmtDescErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } LL_INFOS("Window") << "GL buffer: Color Bits " << S32(pfd.cColorBits) @@ -1656,7 +1632,7 @@ const S32 max_format = (S32)num_formats - 1; mhRC = (HGLRC) createSharedContext(); if (!mhRC) { - return FALSE; + return false; } } @@ -1664,14 +1640,14 @@ const S32 max_format = (S32)num_formats - 1; { OSMessageBox(mCallbacks->translateString("MBGLContextActErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } if (!gGLManager.initGL()) { OSMessageBox(mCallbacks->translateString("MBVideoDrvErr"), mCallbacks->translateString("MBError"), OSMB_OK); close(); - return FALSE; + return false; } // Disable vertical sync for swap @@ -1688,7 +1664,7 @@ const S32 max_format = (S32)num_formats - 1; SetTimer( mWindowHandle, 0, 1000 / 30, NULL ); // 30 fps timer // ok to post quit messages now - mPostQuit = TRUE; + mPostQuit = true; // *HACK: Attempt to prevent startup crashes by deferring memory accounting // until after some graphics setup. See SL-20177. -Cosmic,2023-09-18 @@ -1707,7 +1683,7 @@ const S32 max_format = (S32)num_formats - 1; LL_PROFILER_GPU_CONTEXT; - return TRUE; + return true; } void LLWindowWin32::recreateWindow(RECT window_rect, DWORD dw_ex_style, DWORD dw_style) @@ -1822,7 +1798,7 @@ void* LLWindowWin32::createSharedContext() mMaxGLVersion = llclamp(mMaxGLVersion, 3.f, 4.6f); S32 version_major = llfloor(mMaxGLVersion); - S32 version_minor = llround((mMaxGLVersion-version_major)*10); + S32 version_minor = (S32)llround((mMaxGLVersion-version_major)*10); S32 attribs[] = { @@ -1936,13 +1912,13 @@ void LLWindowWin32::setTitle(const std::string title) }); } -BOOL LLWindowWin32::setCursorPosition(const LLCoordWindow position) +bool LLWindowWin32::setCursorPosition(const LLCoordWindow position) { ASSERT_MAIN_THREAD(); if (!mWindowHandle) { - return FALSE; + return false; } LLCoordScreen screen_pos(position.convert()); @@ -1962,31 +1938,31 @@ BOOL LLWindowWin32::setCursorPosition(const LLCoordWindow position) SetCursorPos(screen_pos.mX, screen_pos.mY); }); - return TRUE; + return true; } -BOOL LLWindowWin32::getCursorPosition(LLCoordWindow *position) +bool LLWindowWin32::getCursorPosition(LLCoordWindow *position) { ASSERT_MAIN_THREAD(); if (!position) { - return FALSE; + return false; } *position = mCursorPosition; - return TRUE; + return true; } -BOOL LLWindowWin32::getCursorDelta(LLCoordCommon* delta) +bool LLWindowWin32::getCursorDelta(LLCoordCommon* delta) { if (delta == nullptr) { - return FALSE; + return false; } *delta = mMouseFrameDelta; - return TRUE; + return true; } void LLWindowWin32::hideCursor() @@ -2001,8 +1977,8 @@ void LLWindowWin32::hideCursor() } }); - mCursorHidden = TRUE; - mHideCursorPermanent = TRUE; + mCursorHidden = true; + mHideCursorPermanent = true; } void LLWindowWin32::showCursor() @@ -2020,8 +1996,8 @@ void LLWindowWin32::showCursor() } }); - mCursorHidden = FALSE; - mHideCursorPermanent = FALSE; + mCursorHidden = false; + mHideCursorPermanent = false; } void LLWindowWin32::showCursorFromMouseMove() @@ -2037,11 +2013,11 @@ void LLWindowWin32::hideCursorUntilMouseMove() if (!mHideCursorPermanent && mMouseVanish) { hideCursor(); - mHideCursorPermanent = FALSE; + mHideCursorPermanent = false; } } -BOOL LLWindowWin32::isCursorHidden() +bool LLWindowWin32::isCursorHidden() { return mCursorHidden; } @@ -2124,7 +2100,7 @@ void LLWindowWin32::initCursors() void LLWindowWin32::updateCursor() { ASSERT_MAIN_THREAD(); - LL_PROFILE_ZONE_SCOPED_CATEGORY_WIN32 + LL_PROFILE_ZONE_SCOPED_CATEGORY_WIN32; if (mNextCursor == UI_CURSOR_ARROW && mBusyCount > 0) { @@ -2161,14 +2137,14 @@ void LLWindowWin32::releaseMouse() void LLWindowWin32::delayInputProcessing() { - mInputProcessingPaused = TRUE; + mInputProcessingPaused = true; } void LLWindowWin32::gatherInput() { ASSERT_MAIN_THREAD(); - LL_PROFILE_ZONE_SCOPED_CATEGORY_WIN32 + LL_PROFILE_ZONE_SCOPED_CATEGORY_WIN32; MSG msg; { @@ -2242,7 +2218,7 @@ void LLWindowWin32::gatherInput() } } - mInputProcessingPaused = FALSE; + mInputProcessingPaused = false; updateCursor(); } @@ -2287,7 +2263,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ // pass along extended flag in mask MASK mask = (l_param >> 16 & KF_EXTENDED) ? MASK_EXTENDED : 0x0; - BOOL eat_keystroke = TRUE; + bool eat_keystroke = true; switch (u_msg) { @@ -2309,7 +2285,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ { WINDOW_IMP_POST(window_imp->mCallbacks->handleDeviceChange(window_imp)); - return TRUE; + return 1; } break; } @@ -2466,8 +2442,9 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ { LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_SYSKEYDOWN"); // allow system keys, such as ALT-F4 to be processed by Windows - eat_keystroke = FALSE; + eat_keystroke = false; // intentional fall-through here + [[fallthrough]]; } case WM_KEYDOWN: { @@ -2476,33 +2453,34 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ { window_imp->mKeyCharCode = 0; // don't know until wm_char comes in next window_imp->mKeyScanCode = (l_param >> 16) & 0xff; - window_imp->mKeyVirtualKey = w_param; + window_imp->mKeyVirtualKey = (U32)w_param; window_imp->mRawMsg = u_msg; - window_imp->mRawWParam = w_param; - window_imp->mRawLParam = l_param; + window_imp->mRawWParam = (U32)w_param; + window_imp->mRawLParam = (U32)l_param; - gKeyboard->handleKeyDown(w_param, mask); + gKeyboard->handleKeyDown((U16)w_param, mask); }); if (eat_keystroke) return 0; // skip DefWindowProc() handling if we're consuming the keypress break; } case WM_SYSKEYUP: - eat_keystroke = FALSE; + eat_keystroke = false; // intentional fall-through here + [[fallthrough]]; case WM_KEYUP: { LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_KEYUP"); window_imp->post([=]() { window_imp->mKeyScanCode = (l_param >> 16) & 0xff; - window_imp->mKeyVirtualKey = w_param; + window_imp->mKeyVirtualKey = (U32)w_param; window_imp->mRawMsg = u_msg; - window_imp->mRawWParam = w_param; - window_imp->mRawLParam = l_param; + window_imp->mRawWParam = (U32)w_param; + window_imp->mRawLParam = (U32)l_param; { LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_KEYUP"); - gKeyboard->handleKeyUp(w_param, mask); + gKeyboard->handleKeyUp((U16)w_param, mask); } }); if (eat_keystroke) return 0; // skip DefWindowProc() handling if we're consuming the keypress @@ -2542,7 +2520,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_IME_COMPOSITION"); if (LLWinImm::isAvailable() && window_imp->mPreeditor) { - WINDOW_IMP_POST(window_imp->handleCompositionMessage(l_param)); + WINDOW_IMP_POST(window_imp->handleCompositionMessage((U32)l_param)); return 0; } break; @@ -2563,10 +2541,10 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_CHAR"); window_imp->post([=]() { - window_imp->mKeyCharCode = w_param; + window_imp->mKeyCharCode = (U32)w_param; window_imp->mRawMsg = u_msg; - window_imp->mRawWParam = w_param; - window_imp->mRawLParam = l_param; + window_imp->mRawWParam = (U32)w_param; + window_imp->mRawLParam = (U32)l_param; // Should really use WM_UNICHAR eventually, but it requires a specific Windows version and I need // to figure out how that works. - Doug @@ -2579,9 +2557,9 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ // characters. We just need to take care of surrogate pairs sent as two WM_CHAR's // by ourselves. It is not that tough. -- Alissa Sabre @ SL - // Even if LLWindowCallbacks::handleUnicodeChar(llwchar, BOOL) returned FALSE, + // Even if LLWindowCallbacks::handleUnicodeChar(llwchar, bool) returned false, // we *did* processed the event, so I believe we should not pass it to DefWindowProc... - window_imp->handleUnicodeUTF16((U16)w_param, gKeyboard->currentMask(FALSE)); + window_imp->handleUnicodeUTF16((U16)w_param, gKeyboard->currentMask(false)); }); return 0; } @@ -2612,7 +2590,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ window_imp->interruptLanguageTextInput(); } - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); auto gl_coord = window_imp->mCursorPosition.convert(); window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask); window_imp->mCallbacks->handleMouseDown(window_imp, gl_coord, mask); @@ -2635,7 +2613,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ sHandleDoubleClick = true; return; } - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); // generate move event to update mouse coordinates window_imp->mCursorPosition = window_coord; @@ -2659,7 +2637,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ sHandleDoubleClick = true; - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); // generate move event to update mouse coordinates window_imp->mCursorPosition = window_coord; window_imp->mCallbacks->handleMouseUp(window_imp, window_imp->mCursorPosition.convert(), mask); @@ -2680,7 +2658,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ WINDOW_IMP_POST(window_imp->interruptLanguageTextInput()); } - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); // generate move event to update mouse coordinates auto gl_coord = window_imp->mCursorPosition.convert(); window_imp->mCallbacks->handleMouseMove(window_imp, gl_coord, mask); @@ -2698,7 +2676,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ LL_RECORD_BLOCK_TIME(FTM_MOUSEHANDLER); window_imp->postMouseButtonEvent([=]() { - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); window_imp->mCallbacks->handleRightMouseUp(window_imp, window_imp->mCursorPosition.convert(), mask); }); } @@ -2718,7 +2696,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ window_imp->interruptLanguageTextInput(); } - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); window_imp->mCallbacks->handleMiddleMouseDown(window_imp, window_imp->mCursorPosition.convert(), mask); }); } @@ -2732,7 +2710,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ LL_RECORD_BLOCK_TIME(FTM_MOUSEHANDLER); window_imp->postMouseButtonEvent([=]() { - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); window_imp->mCallbacks->handleMiddleMouseUp(window_imp, window_imp->mCursorPosition.convert(), mask); }); } @@ -2750,7 +2728,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ window_imp->interruptLanguageTextInput(); } - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); // Windows uses numbers 1 and 2 for buttons, remap to 4, 5 window_imp->mCallbacks->handleOtherMouseDown(window_imp, window_imp->mCursorPosition.convert(), mask, button + 3); }); @@ -2767,7 +2745,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ LL_RECORD_BLOCK_TIME(FTM_MOUSEHANDLER); S32 button = GET_XBUTTON_WPARAM(w_param); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); // Windows uses numbers 1 and 2 for buttons, remap to 4, 5 window_imp->mCallbacks->handleOtherMouseUp(window_imp, window_imp->mCursorPosition.convert(), mask, button + 3); }); @@ -2877,7 +2855,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ { LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("mwp - WM_MOUSEMOVE lambda"); - MASK mask = gKeyboard->currentMask(TRUE); + MASK mask = gKeyboard->currentMask(true); window_imp->mMouseMask = mask; window_imp->mCursorPosition = window_coord; }); @@ -2914,19 +2892,19 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ // means that the window was un-minimized. if (w_param == SIZE_RESTORED && window_imp->mLastSizeWParam != SIZE_RESTORED) { - WINDOW_IMP_POST(window_imp->mCallbacks->handleActivate(window_imp, TRUE)); + WINDOW_IMP_POST(window_imp->mCallbacks->handleActivate(window_imp, true)); } // handle case of window being maximized from fully minimized state if (w_param == SIZE_MAXIMIZED && window_imp->mLastSizeWParam != SIZE_MAXIMIZED) { - WINDOW_IMP_POST(window_imp->mCallbacks->handleActivate(window_imp, TRUE)); + WINDOW_IMP_POST(window_imp->mCallbacks->handleActivate(window_imp, true)); } // Also handle the minimization case if (w_param == SIZE_MINIMIZED && window_imp->mLastSizeWParam != SIZE_MINIMIZED) { - WINDOW_IMP_POST(window_imp->mCallbacks->handleActivate(window_imp, FALSE)); + WINDOW_IMP_POST(window_imp->mCallbacks->handleActivate(window_imp, false)); } // Actually resize all of our views @@ -2990,13 +2968,11 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ window_imp->post([=]() { - window_imp->mCallbacks->handleDataCopy(window_imp, myType, data); + window_imp->mCallbacks->handleDataCopy(window_imp, (S32)myType, data); delete[] data; }); }; return 0; - - break; } case WM_SETTINGCHANGE: { @@ -3005,7 +2981,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ { if (!SystemParametersInfo(SPI_GETMOUSEVANISH, 0, &window_imp->mMouseVanish, 0)) { - WINDOW_IMP_POST(window_imp->mMouseVanish = TRUE); + WINDOW_IMP_POST(window_imp->mMouseVanish = true); } } } @@ -3052,8 +3028,8 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ S32 width = GetSystemMetrics(v_desktop ? SM_CXVIRTUALSCREEN : SM_CXSCREEN); S32 height = GetSystemMetrics(v_desktop ? SM_CYVIRTUALSCREEN : SM_CYSCREEN); - absolute_x = (raw->data.mouse.lLastX / 65535.0f) * width; - absolute_y = (raw->data.mouse.lLastY / 65535.0f) * height; + absolute_x = (S32)((raw->data.mouse.lLastX / 65535.0f) * width); + absolute_y = (S32)((raw->data.mouse.lLastY / 65535.0f) * height); } window_imp->mRawMouseDelta.mX += absolute_x - prev_absolute_x; @@ -3074,13 +3050,14 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ } else { - window_imp->mRawMouseDelta.mX += round((F32)raw->data.mouse.lLastX * (F32)speed / DEFAULT_SPEED); - window_imp->mRawMouseDelta.mY -= round((F32)raw->data.mouse.lLastY * (F32)speed / DEFAULT_SPEED); + window_imp->mRawMouseDelta.mX += (S32)round((F32)raw->data.mouse.lLastX * (F32)speed / DEFAULT_SPEED); + window_imp->mRawMouseDelta.mY -= (S32)round((F32)raw->data.mouse.lLastY * (F32)speed / DEFAULT_SPEED); } } } } } + break; //list of messages we get often that we don't care to log about case WM_NCHITTEST: @@ -3114,7 +3091,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_ return ret; } -BOOL LLWindowWin32::convertCoords(LLCoordGL from, LLCoordWindow *to) +bool LLWindowWin32::convertCoords(LLCoordGL from, LLCoordWindow *to) { S32 client_height; RECT client_rect; @@ -3124,17 +3101,17 @@ BOOL LLWindowWin32::convertCoords(LLCoordGL from, LLCoordWindow *to) !GetClientRect(mWindowHandle, &client_rect) || NULL == to) { - return FALSE; + return false; } to->mX = from.mX; client_height = client_rect.bottom - client_rect.top; to->mY = client_height - from.mY - 1; - return TRUE; + return true; } -BOOL LLWindowWin32::convertCoords(LLCoordWindow from, LLCoordGL* to) +bool LLWindowWin32::convertCoords(LLCoordWindow from, LLCoordGL* to) { S32 client_height; RECT client_rect; @@ -3143,23 +3120,23 @@ BOOL LLWindowWin32::convertCoords(LLCoordWindow from, LLCoordGL* to) !GetClientRect(mWindowHandle, &client_rect) || NULL == to) { - return FALSE; + return false; } to->mX = from.mX; client_height = client_rect.bottom - client_rect.top; to->mY = client_height - from.mY - 1; - return TRUE; + return true; } -BOOL LLWindowWin32::convertCoords(LLCoordScreen from, LLCoordWindow* to) +bool LLWindowWin32::convertCoords(LLCoordScreen from, LLCoordWindow* to) { POINT mouse_point; mouse_point.x = from.mX; mouse_point.y = from.mY; - BOOL result = ScreenToClient(mWindowHandle, &mouse_point); + bool result = ScreenToClient(mWindowHandle, &mouse_point); if (result) { @@ -3170,13 +3147,13 @@ BOOL LLWindowWin32::convertCoords(LLCoordScreen from, LLCoordWindow* to) return result; } -BOOL LLWindowWin32::convertCoords(LLCoordWindow from, LLCoordScreen *to) +bool LLWindowWin32::convertCoords(LLCoordWindow from, LLCoordScreen *to) { POINT mouse_point; mouse_point.x = from.mX; mouse_point.y = from.mY; - BOOL result = ClientToScreen(mWindowHandle, &mouse_point); + bool result = ClientToScreen(mWindowHandle, &mouse_point); if (result) { @@ -3187,44 +3164,44 @@ BOOL LLWindowWin32::convertCoords(LLCoordWindow from, LLCoordScreen *to) return result; } -BOOL LLWindowWin32::convertCoords(LLCoordScreen from, LLCoordGL *to) +bool LLWindowWin32::convertCoords(LLCoordScreen from, LLCoordGL *to) { LLCoordWindow window_coord; if (!mWindowHandle || (NULL == to)) { - return FALSE; + return false; } convertCoords(from, &window_coord); convertCoords(window_coord, to); - return TRUE; + return true; } -BOOL LLWindowWin32::convertCoords(LLCoordGL from, LLCoordScreen *to) +bool LLWindowWin32::convertCoords(LLCoordGL from, LLCoordScreen *to) { LLCoordWindow window_coord; if (!mWindowHandle || (NULL == to)) { - return FALSE; + return false; } convertCoords(from, &window_coord); convertCoords(window_coord, to); - return TRUE; + return true; } -BOOL LLWindowWin32::isClipboardTextAvailable() +bool LLWindowWin32::isClipboardTextAvailable() { return IsClipboardFormatAvailable(CF_UNICODETEXT); } -BOOL LLWindowWin32::pasteTextFromClipboard(LLWString &dst) +bool LLWindowWin32::pasteTextFromClipboard(LLWString &dst) { - BOOL success = FALSE; + bool success = false; if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { @@ -3239,7 +3216,7 @@ BOOL LLWindowWin32::pasteTextFromClipboard(LLWString &dst) dst = utf16str_to_wstring(utf16str); LLWStringUtil::removeWindowsCR(dst); GlobalUnlock(h_data); - success = TRUE; + success = true; } } CloseClipboard(); @@ -3250,9 +3227,9 @@ BOOL LLWindowWin32::pasteTextFromClipboard(LLWString &dst) } -BOOL LLWindowWin32::copyTextToClipboard(const LLWString& wstr) +bool LLWindowWin32::copyTextToClipboard(const LLWString& wstr) { - BOOL success = FALSE; + bool success = false; if (OpenClipboard(mWindowHandle)) { @@ -3276,7 +3253,7 @@ BOOL LLWindowWin32::copyTextToClipboard(const LLWString& wstr) if (SetClipboardData(CF_UNICODETEXT, hglobal_copy_utf16)) { - success = TRUE; + success = true; } } } @@ -3288,13 +3265,13 @@ BOOL LLWindowWin32::copyTextToClipboard(const LLWString& wstr) } // Constrains the mouse to the window. -void LLWindowWin32::setMouseClipping( BOOL b ) +void LLWindowWin32::setMouseClipping( bool b ) { LL_PROFILE_ZONE_SCOPED_CATEGORY_WIN32; ASSERT_MAIN_THREAD(); if( b != mIsMouseClipping ) { - BOOL success = FALSE; + bool success = false; if( b ) { @@ -3320,9 +3297,9 @@ void LLWindowWin32::setMouseClipping( BOOL b ) } } -BOOL LLWindowWin32::getClientRectInScreenSpace( RECT* rectp ) +bool LLWindowWin32::getClientRectInScreenSpace( RECT* rectp ) { - BOOL success = FALSE; + bool success = false; RECT client_rect; if (mWindowHandle && GetClientRect(mWindowHandle, &client_rect)) @@ -3343,7 +3320,7 @@ BOOL LLWindowWin32::getClientRectInScreenSpace( RECT* rectp ) bottom_right.x, bottom_right.y); - success = TRUE; + success = true; } return success; @@ -3369,36 +3346,36 @@ F32 LLWindowWin32::getGamma() return mCurrentGamma; } -BOOL LLWindowWin32::restoreGamma() +bool LLWindowWin32::restoreGamma() { ASSERT_MAIN_THREAD(); - if (mCustomGammaSet != FALSE) + if (mCustomGammaSet) { LL_DEBUGS("Window") << "Restoring gamma" << LL_ENDL; - mCustomGammaSet = FALSE; + mCustomGammaSet = false; return SetDeviceGammaRamp(mhDC, mPrevGammaRamp); } - return TRUE; + return true; } -BOOL LLWindowWin32::setGamma(const F32 gamma) +bool LLWindowWin32::setGamma(const F32 gamma) { ASSERT_MAIN_THREAD(); mCurrentGamma = gamma; //Get the previous gamma ramp to restore later. - if (mCustomGammaSet == FALSE) + if (!mCustomGammaSet) { if (!gGLManager.mIsIntel) // skip for Intel GPUs (see SL-11341) { LL_DEBUGS("Window") << "Getting the previous gamma ramp to restore later" << LL_ENDL; - if(GetDeviceGammaRamp(mhDC, mPrevGammaRamp) == FALSE) + if (!GetDeviceGammaRamp(mhDC, mPrevGammaRamp)) { LL_WARNS("Window") << "Failed to get the previous gamma ramp" << LL_ENDL; - return FALSE; + return false; } } - mCustomGammaSet = TRUE; + mCustomGammaSet = true; } LL_DEBUGS("Window") << "Setting gamma to " << gamma << LL_ENDL; @@ -3453,13 +3430,13 @@ LLWindow::LLWindowResolution* LLWindowWin32::getSupportedResolutions(S32 &num_re dev_mode.dmPelsWidth >= 800 && dev_mode.dmPelsHeight >= 600) { - BOOL resolution_exists = FALSE; + bool resolution_exists = false; for(S32 i = 0; i < mNumSupportedResolutions; i++) { if (mSupportedResolutions[i].mWidth == dev_mode.dmPelsWidth && mSupportedResolutions[i].mHeight == dev_mode.dmPelsHeight) { - resolution_exists = TRUE; + resolution_exists = true; } } if (!resolution_exists) @@ -3512,12 +3489,12 @@ F32 LLWindowWin32::getPixelAspectRatio() // Change display resolution. Returns true if successful. // protected -BOOL LLWindowWin32::setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh) +bool LLWindowWin32::setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh) { DEVMODE dev_mode; ::ZeroMemory(&dev_mode, sizeof(DEVMODE)); dev_mode.dmSize = sizeof(DEVMODE); - BOOL success = FALSE; + bool success = false; // Don't change anything if we don't have to if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dev_mode)) @@ -3528,7 +3505,7 @@ BOOL LLWindowWin32::setDisplayResolution(S32 width, S32 height, S32 bits, S32 re dev_mode.dmDisplayFrequency == refresh ) { // ...display mode identical, do nothing - return TRUE; + return true; } } @@ -3555,7 +3532,7 @@ BOOL LLWindowWin32::setDisplayResolution(S32 width, S32 height, S32 bits, S32 re } // protected -BOOL LLWindowWin32::setFullscreenResolution() +bool LLWindowWin32::setFullscreenResolution() { if (mFullscreen) { @@ -3563,18 +3540,18 @@ BOOL LLWindowWin32::setFullscreenResolution() } else { - return FALSE; + return false; } } // protected -BOOL LLWindowWin32::resetDisplayResolution() +bool LLWindowWin32::resetDisplayResolution() { LL_DEBUGS("Window") << "resetDisplayResolution START" << LL_ENDL; LONG cds_result = ChangeDisplaySettings(NULL, 0); - BOOL success = (DISP_CHANGE_SUCCESSFUL == cds_result); + bool success = (DISP_CHANGE_SUCCESSFUL == cds_result); if (!success) { @@ -3632,13 +3609,13 @@ void LLSplashScreenWin32::updateImpl(const std::string& mesg) { if (!mWindow) return; - int output_str_len = MultiByteToWideChar(CP_UTF8, 0, mesg.c_str(), mesg.length(), NULL, 0); + int output_str_len = MultiByteToWideChar(CP_UTF8, 0, mesg.c_str(), static_cast<int>(mesg.length()), NULL, 0); if( output_str_len>1024 ) return; WCHAR w_mesg[1025];//big enought to keep null terminatos - MultiByteToWideChar (CP_UTF8, 0, mesg.c_str(), mesg.length(), w_mesg, output_str_len); + MultiByteToWideChar (CP_UTF8, 0, mesg.c_str(), static_cast<int>(mesg.length()), w_mesg, output_str_len); //looks like MultiByteToWideChar didn't add null terminator to converted string, see EXT-4858 w_mesg[output_str_len] = 0; @@ -3784,9 +3761,9 @@ LLSD LLWindowWin32::getNativeKeyData() return result; } -BOOL LLWindowWin32::dialogColorPicker( F32 *r, F32 *g, F32 *b ) +bool LLWindowWin32::dialogColorPicker( F32 *r, F32 *g, F32 *b ) { - BOOL retval = FALSE; + bool retval = false; static CHOOSECOLOR cc; static COLORREF crCustColors[16]; @@ -3839,7 +3816,7 @@ void LLWindowWin32::focusClient() }); } -void LLWindowWin32::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) +void LLWindowWin32::allowLanguageTextInput(LLPreeditor *preeditor, bool b) { if (b == sLanguageTextInputAllowed || !LLWinImm::isAvailable()) { @@ -3849,7 +3826,7 @@ void LLWindowWin32::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) if (preeditor != mPreeditor && !b) { // This condition may occur with a call to - // setEnabled(BOOL) from LLTextEditor or LLLineEditor + // setEnabled(bool) from LLTextEditor or LLLineEditor // when the control is not focused. // We need to silently ignore the case so that // the language input status of the focused control @@ -3879,7 +3856,7 @@ void LLWindowWin32::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) if (sWinIMEOpened && GetKeyboardLayout(0) == sWinInputLocale) { HIMC himc = LLWinImm::getContext(mWindowHandle); - LLWinImm::setOpenStatus(himc, TRUE); + LLWinImm::setOpenStatus(himc, true); LLWinImm::setConversionStatus(himc, sWinIMEConversionMode, sWinIMESentenceMode); LLWinImm::releaseContext(mWindowHandle, himc); } @@ -3905,7 +3882,7 @@ void LLWindowWin32::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b) // We need both ImmSetConversionStatus and ImmSetOpenStatus here to surely disable IME's // keyboard hooking, because Some IME reacts only on the former and some other on the latter... LLWinImm::setConversionStatus(himc, IME_CMODE_NOCONVERSION, sWinIMESentenceMode); - LLWinImm::setOpenStatus(himc, FALSE); + LLWinImm::setOpenStatus(himc, false); } LLWinImm::releaseContext(mWindowHandle, himc); } @@ -4032,14 +4009,14 @@ U32 LLWindowWin32::fillReconvertString(const LLWString &text, S32 focus, S32 focus_length, RECONVERTSTRING *reconvert_string) { const llutf16string text_utf16 = wstring_to_utf16str(text); - const DWORD required_size = sizeof(RECONVERTSTRING) + (text_utf16.length() + 1) * sizeof(WCHAR); + const DWORD required_size = sizeof(RECONVERTSTRING) + (static_cast<DWORD>(text_utf16.length()) + 1) * sizeof(WCHAR); if (reconvert_string && reconvert_string->dwSize >= required_size) { const DWORD focus_utf16_at = wstring_utf16_length(text, 0, focus); const DWORD focus_utf16_length = wstring_utf16_length(text, focus, focus_length); reconvert_string->dwVersion = 0; - reconvert_string->dwStrLen = text_utf16.length(); + reconvert_string->dwStrLen = static_cast<DWORD>(text_utf16.length()); reconvert_string->dwStrOffset = sizeof(RECONVERTSTRING); reconvert_string->dwCompStrLen = focus_utf16_length; reconvert_string->dwCompStrOffset = focus_utf16_at * sizeof(WCHAR); @@ -4111,7 +4088,7 @@ void LLWindowWin32::handleCompositionMessage(const U32 indexes) { return; } - BOOL needs_update = FALSE; + bool needs_update = false; LLWString result_string; LLWString preedit_string; S32 preedit_string_utf16_length = 0; @@ -4134,7 +4111,7 @@ void LLWindowWin32::handleCompositionMessage(const U32 indexes) result_string = utf16str_to_wstring(llutf16string(data, size / sizeof(WCHAR))); } delete[] data; - needs_update = TRUE; + needs_update = true; } } @@ -4151,7 +4128,7 @@ void LLWindowWin32::handleCompositionMessage(const U32 indexes) preedit_string = utf16str_to_wstring(llutf16string(data, size / sizeof(WCHAR))); } delete[] data; - needs_update = TRUE; + needs_update = true; } } @@ -4187,13 +4164,13 @@ void LLWindowWin32::handleCompositionMessage(const U32 indexes) size = LLWinImm::getCompositionString(himc, GCS_COMPATTR, data, size); if (size == preedit_string_utf16_length) { - preedit_standouts.assign(preedit_segment_lengths.size(), FALSE); + preedit_standouts.assign(preedit_segment_lengths.size(), false); S32 offset = 0; for (U32 i = 0; i < preedit_segment_lengths.size(); i++) { if (ATTR_TARGET_CONVERTED == data[offset] || ATTR_TARGET_NOTCONVERTED == data[offset]) { - preedit_standouts[i] = TRUE; + preedit_standouts[i] = true; } offset += wstring_utf16_length(preedit_string, offset, preedit_segment_lengths[i]); } @@ -4202,7 +4179,7 @@ void LLWindowWin32::handleCompositionMessage(const U32 indexes) } } - S32 caret_position = preedit_string.length(); + S32 caret_position = static_cast<S32>(preedit_string.length()); if (indexes & GCS_CURSORPOS) { const S32 caret_position_utf16 = LLWinImm::getCompositionString(himc, GCS_CURSORPOS, NULL, 0); @@ -4217,7 +4194,7 @@ void LLWindowWin32::handleCompositionMessage(const U32 indexes) // I'm not sure this condition really happens, but // Windows SDK document says it is an indication // of "reset everything." - needs_update = TRUE; + needs_update = true; } LLWinImm::releaseContext(mWindowHandle, himc); @@ -4248,11 +4225,11 @@ void LLWindowWin32::handleCompositionMessage(const U32 indexes) { if (preedit_segment_lengths.size() == 0) { - preedit_segment_lengths.assign(1, preedit_string.length()); + preedit_segment_lengths.assign(1, static_cast<S32>(preedit_string.length())); } if (preedit_standouts.size() == 0) { - preedit_standouts.assign(preedit_segment_lengths.size(), FALSE); + preedit_standouts.assign(preedit_segment_lengths.size(), false); } } mPreeditor->updatePreedit(preedit_string, preedit_segment_lengths, preedit_standouts, caret_position); @@ -4299,11 +4276,11 @@ LLWindowCallbacks::DragNDropResult LLWindowWin32::completeDragNDropRequest( cons } // Handle WM_IME_REQUEST message. -// If it handled the message, returns TRUE. Otherwise, FALSE. +// If it handled the message, returns true. Otherwise, false. // When it handled the message, the value to be returned from // the Window Procedure is set to *result. -BOOL LLWindowWin32::handleImeRequests(WPARAM request, LPARAM param, LRESULT *result) +bool LLWindowWin32::handleImeRequests(WPARAM request, LPARAM param, LRESULT *result) { if ( mPreeditor ) { @@ -4321,7 +4298,7 @@ BOOL LLWindowWin32::handleImeRequests(WPARAM request, LPARAM param, LRESULT *res form->dwIndex = dwIndex; *result = 1; - return TRUE; + return true; } case IMR_QUERYCHARPOSITION: { @@ -4341,20 +4318,20 @@ BOOL LLWindowWin32::handleImeRequests(WPARAM request, LPARAM param, LRESULT *res if (!mPreeditor->getPreeditLocation(position, &caret_coord, &preedit_bounds, &text_control)) { LL_WARNS("Window") << "*** IMR_QUERYCHARPOSITON called but getPreeditLocation failed." << LL_ENDL; - return FALSE; + return false; } fillCharPosition(caret_coord, preedit_bounds, text_control, char_position); *result = 1; - return TRUE; + return true; } case IMR_COMPOSITIONFONT: { fillCompositionLogfont((LOGFONT *)param); *result = 1; - return TRUE; + return true; } case IMR_RECONVERTSTRING: { @@ -4375,7 +4352,7 @@ BOOL LLWindowWin32::handleImeRequests(WPARAM request, LPARAM param, LRESULT *res // Let the IME to decide the reconversion range, and // adjust the reconvert_string structure accordingly. HIMC himc = LLWinImm::getContext(mWindowHandle); - const BOOL adjusted = LLWinImm::setCompositionString(himc, + const bool adjusted = LLWinImm::setCompositionString(himc, SCS_QUERYRECONVERTSTRING, reconvert_string, size, NULL, 0); LLWinImm::releaseContext(mWindowHandle, himc); if (adjusted) @@ -4392,12 +4369,12 @@ BOOL LLWindowWin32::handleImeRequests(WPARAM request, LPARAM param, LRESULT *res } *result = size; - return TRUE; + return true; } case IMR_CONFIRMRECONVERTSTRING: { - *result = FALSE; - return TRUE; + *result = 0; + return true; } case IMR_DOCUMENTFEED: { @@ -4419,14 +4396,14 @@ BOOL LLWindowWin32::handleImeRequests(WPARAM request, LPARAM param, LRESULT *res RECONVERTSTRING *reconvert_string = (RECONVERTSTRING *)param; *result = fillReconvertString(context, preedit, 0, reconvert_string); - return TRUE; + return true; } default: - return FALSE; + return false; } } - return FALSE; + return false; } //static @@ -4552,12 +4529,6 @@ std::vector<std::string> LLWindowWin32::getDynamicFallbackFontList() // Fonts previously in getFontListSans() have moved to fonts.xml. return std::vector<std::string>(); } - -U32 LLWindowWin32::getAvailableVRAMMegabytes() -{ - return mWindowThread ? mWindowThread->getAvailableVRAMMegabytes() : 0; -} - #endif // LL_WINDOWS inline LLWindowWin32::LLWindowWin32Thread::LLWindowWin32Thread() @@ -4626,41 +4597,57 @@ private: std::string mPrev; }; -// Print hardware debug info about available graphics adapters in ordinal order -void debugEnumerateGraphicsAdapters() +void LLWindowWin32::LLWindowWin32Thread::checkDXMem() { - LL_INFOS("Window") << "Enumerating graphics adapters..." << LL_ENDL; + if (!mGLReady || mGotGLBuffer) { return; } + + IDXGIFactory4* p_factory = nullptr; - IDXGIFactory1* factory; - HRESULT res = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory); - if (FAILED(res) || !factory) + HRESULT res = CreateDXGIFactory1(__uuidof(IDXGIFactory4), (void**)&p_factory); + + if (FAILED(res)) { LL_WARNS() << "CreateDXGIFactory1 failed: 0x" << std::hex << res << LL_ENDL; } else { + IDXGIAdapter3* p_dxgi_adapter = nullptr; UINT graphics_adapter_index = 0; - IDXGIAdapter3* dxgi_adapter; while (true) { - res = factory->EnumAdapters(graphics_adapter_index, reinterpret_cast<IDXGIAdapter**>(&dxgi_adapter)); + res = p_factory->EnumAdapters(graphics_adapter_index, reinterpret_cast<IDXGIAdapter**>(&p_dxgi_adapter)); if (FAILED(res)) { if (graphics_adapter_index == 0) { LL_WARNS() << "EnumAdapters failed: 0x" << std::hex << res << LL_ENDL; } - else - { - LL_INFOS("Window") << "Done enumerating graphics adapters" << LL_ENDL; - } } else { + if (graphics_adapter_index == 0) // Should it check largest one isntead of first? + { + DXGI_QUERY_VIDEO_MEMORY_INFO info; + p_dxgi_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info); + + // Alternatively use GetDesc from below to get adapter's memory + UINT64 budget_mb = info.Budget / (1024 * 1024); + if (gGLManager.mVRAM < (S32)budget_mb) + { + gGLManager.mVRAM = (S32)budget_mb; + LL_INFOS("RenderInit") << "New VRAM Budget (DX9): " << gGLManager.mVRAM << " MB" << LL_ENDL; + } + else + { + LL_INFOS("RenderInit") << "VRAM Budget (DX9): " << budget_mb + << " MB, current (WMI): " << gGLManager.mVRAM << " MB" << LL_ENDL; + } + } + DXGI_ADAPTER_DESC desc; - dxgi_adapter->GetDesc(&desc); + p_dxgi_adapter->GetDesc(&desc); std::wstring description_w((wchar_t*)desc.Description); - std::string description(description_w.begin(), description_w.end()); + std::string description = ll_convert_wide_to_string(description_w); LL_INFOS("Window") << "Graphics adapter index: " << graphics_adapter_index << ", " << "Description: " << description << ", " << "DeviceId: " << desc.DeviceId << ", " @@ -4671,10 +4658,10 @@ void debugEnumerateGraphicsAdapters() << "SharedSystemMemory: " << desc.SharedSystemMemory / 1024 / 1024 << LL_ENDL; } - if (dxgi_adapter) + if (p_dxgi_adapter) { - dxgi_adapter->Release(); - dxgi_adapter = NULL; + p_dxgi_adapter->Release(); + p_dxgi_adapter = NULL; } else { @@ -4685,168 +4672,12 @@ void debugEnumerateGraphicsAdapters() } } - if (factory) - { - factory->Release(); - } -} - -void LLWindowWin32::LLWindowWin32Thread::initDX() -{ - if (!mGLReady) { return; } - - if (mDXGIAdapter == NULL) - { - debugEnumerateGraphicsAdapters(); - - IDXGIFactory4* pFactory = nullptr; - - HRESULT res = CreateDXGIFactory1(__uuidof(IDXGIFactory4), (void**)&pFactory); - - if (FAILED(res)) - { - LL_WARNS() << "CreateDXGIFactory1 failed: 0x" << std::hex << res << LL_ENDL; - } - else - { - res = pFactory->EnumAdapters(0, reinterpret_cast<IDXGIAdapter**>(&mDXGIAdapter)); - if (FAILED(res)) - { - LL_WARNS() << "EnumAdapters failed: 0x" << std::hex << res << LL_ENDL; - } - else - { - LL_INFOS() << "EnumAdapters success" << LL_ENDL; - } - } - - if (pFactory) - { - pFactory->Release(); - } - } -} - -void LLWindowWin32::LLWindowWin32Thread::initD3D() -{ - if (!mGLReady) { return; } - - if (mDXGIAdapter == NULL && mD3DDevice == NULL && mWindowHandleThrd != 0) + if (p_factory) { - mD3D = Direct3DCreate9(D3D_SDK_VERSION); - - D3DPRESENT_PARAMETERS d3dpp; - - ZeroMemory(&d3dpp, sizeof(d3dpp)); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - - HRESULT res = mD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mWindowHandleThrd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &mD3DDevice); - - if (FAILED(res)) - { - LL_WARNS() << "(fallback) CreateDevice failed: 0x" << std::hex << res << LL_ENDL; - } - else - { - LL_INFOS() << "(fallback) CreateDevice success" << LL_ENDL; - } + p_factory->Release(); } -} -void LLWindowWin32::LLWindowWin32Thread::cleanupDX() -{ - //clean up DXGI/D3D resources - if (mDXGIAdapter) - { - mDXGIAdapter->Release(); - mDXGIAdapter = nullptr; - } - - if (mD3DDevice) - { - mD3DDevice->Release(); - mD3DDevice = nullptr; - } - - if (mD3D) - { - mD3D->Release(); - mD3D = nullptr; - } -} - -void LLWindowWin32::LLWindowWin32Thread::updateVRAMUsage() -{ - LL_PROFILE_ZONE_SCOPED; - if (!mGLReady) { return; } - - if (mDXGIAdapter != nullptr) - { - // NOTE: what lies below is hand wavy math based on compatibility testing and observation against a variety of hardware - // It doesn't make sense, but please don't refactor it to make sense. -- davep - - DXGI_QUERY_VIDEO_MEMORY_INFO info; - mDXGIAdapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info); -#if 0 // debug 0 budget and 0 CU - info.Budget = 0; - info.CurrentUsage = 0; -#endif - - U32 budget_mb = info.Budget / 1024 / 1024; - gGLManager.mVRAM = llmax(gGLManager.mVRAM, (S32) budget_mb); - - U32 afr_mb = info.AvailableForReservation / 1024 / 1024; - // correct for systems that misreport budget - if (budget_mb == 0) - { - // fall back to available for reservation clamped between 512MB and 2GB - budget_mb = llclamp(afr_mb, (U32) 512, (U32) 2048); - } - - if ( mMaxVRAM != 0) - { - budget_mb = llmin(budget_mb, mMaxVRAM); - } - - U32 cu_mb = info.CurrentUsage / 1024 / 1024; - - // get an estimated usage based on texture bytes allocated - U32 eu_mb = LLImageGL::getTextureBytesAllocated() * 2 / 1024 / 1024; - - if (cu_mb == 0) - { // current usage is sometimes unreliable on Intel GPUs, fall back to estimated usage - cu_mb = llmax((U32)1, eu_mb); - } - U32 target_mb = budget_mb; - - if (target_mb > 4096) // if 4GB are installed, try to leave 2GB free - { - target_mb -= 2048; - } - else // if less than 4GB are installed, try not to use more than half of it - { - target_mb /= 2; - } - - mAvailableVRAM = cu_mb < target_mb ? target_mb - cu_mb : 0; - -#if 0 - - F32 eu_error = (F32)((S32)eu_mb - (S32)cu_mb) / (F32)cu_mb; - LL_INFOS("Window") << "\nLocal\nAFR: " << info.AvailableForReservation / 1024 / 1024 - << "\nBudget: " << info.Budget / 1024 / 1024 - << "\nCR: " << info.CurrentReservation / 1024 / 1024 - << "\nCU: " << info.CurrentUsage / 1024 / 1024 - << "\nEU: " << eu_mb << llformat(" (%.2f)", eu_error) - << "\nTU: " << target_mb - << "\nAM: " << mAvailableVRAM << LL_ENDL; -#endif - } - else if (mD3DDevice != NULL) - { // fallback to D3D9 - mAvailableVRAM = mD3DDevice->GetAvailableTextureMem() / 1024 / 1024; - } + mGotGLBuffer = true; } void LLWindowWin32::LLWindowWin32Thread::run() @@ -4866,15 +4697,11 @@ void LLWindowWin32::LLWindowWin32Thread::run() { LL_PROFILE_ZONE_SCOPED_CATEGORY_WIN32; - // lazily call initD3D inside this loop to catch when mGLReady has been set to true - initDX(); + // Check memory budget using DirectX + checkDXMem(); if (mWindowHandleThrd != 0) { - // lazily call initD3D inside this loop to catch when mWindowHandle has been set, and mGLReady has been set to true - // *TODO: Shutdown if this fails when mWindowHandle exists - initD3D(); - MSG msg; BOOL status; if (mhDCThrd == 0) @@ -4907,13 +4734,6 @@ void LLWindowWin32::LLWindowWin32Thread::run() getQueue().runPending(); } - // update available vram once every 3 seconds - static LLFrameTimer vramTimer; - if (vramTimer.getElapsedTimeF32() > 3.f) - { - updateVRAMUsage(); - vramTimer.reset(); - } #if 0 { LL_PROFILE_ZONE_NAMED_CATEGORY_WIN32("w32t - Sleep"); @@ -4922,8 +4742,6 @@ void LLWindowWin32::LLWindowWin32Thread::run() } #endif } - - cleanupDX(); } void LLWindowWin32::LLWindowWin32Thread::wakeAndDestroy() @@ -5023,7 +4841,6 @@ void LLWindowWin32::LLWindowWin32Thread::wakeAndDestroy() // very unsafe TerminateThread(pair.second.native_handle(), 0); pair.second.detach(); - cleanupDX(); } } LL_DEBUGS("Window") << "thread pool shutdown complete" << LL_ENDL; diff --git a/indra/llwindow/llwindowwin32.h b/indra/llwindow/llwindowwin32.h index 33fa67ba50..287402faa0 100644 --- a/indra/llwindow/llwindowwin32.h +++ b/indra/llwindow/llwindowwin32.h @@ -48,47 +48,47 @@ public: /*virtual*/ void show(); /*virtual*/ void hide(); /*virtual*/ void close(); - /*virtual*/ BOOL getVisible(); - /*virtual*/ BOOL getMinimized(); - /*virtual*/ BOOL getMaximized(); - /*virtual*/ BOOL maximize(); + /*virtual*/ bool getVisible(); + /*virtual*/ bool getMinimized(); + /*virtual*/ bool getMaximized(); + /*virtual*/ bool maximize(); /*virtual*/ void minimize(); /*virtual*/ void restore(); - /*virtual*/ BOOL getFullscreen(); - /*virtual*/ BOOL getPosition(LLCoordScreen *position); - /*virtual*/ BOOL getSize(LLCoordScreen *size); - /*virtual*/ BOOL getSize(LLCoordWindow *size); - /*virtual*/ BOOL setPosition(LLCoordScreen position); - /*virtual*/ BOOL setSizeImpl(LLCoordScreen size); - /*virtual*/ BOOL setSizeImpl(LLCoordWindow size); - /*virtual*/ BOOL switchContext(BOOL fullscreen, const LLCoordScreen &size, BOOL enable_vsync, const LLCoordScreen * const posp = NULL); + /*virtual*/ bool getFullscreen(); + /*virtual*/ bool getPosition(LLCoordScreen *position); + /*virtual*/ bool getSize(LLCoordScreen *size); + /*virtual*/ bool getSize(LLCoordWindow *size); + /*virtual*/ bool setPosition(LLCoordScreen position); + /*virtual*/ bool setSizeImpl(LLCoordScreen size); + /*virtual*/ bool setSizeImpl(LLCoordWindow size); + /*virtual*/ bool switchContext(bool fullscreen, const LLCoordScreen &size, bool enable_vsync, const LLCoordScreen * const posp = NULL); /*virtual*/ void setTitle(const std::string title); void* createSharedContext() override; void makeContextCurrent(void* context) override; void destroySharedContext(void* context) override; /*virtual*/ void toggleVSync(bool enable_vsync); - /*virtual*/ BOOL setCursorPosition(LLCoordWindow position); - /*virtual*/ BOOL getCursorPosition(LLCoordWindow *position); - /*virtual*/ BOOL getCursorDelta(LLCoordCommon* delta); + /*virtual*/ bool setCursorPosition(LLCoordWindow position); + /*virtual*/ bool getCursorPosition(LLCoordWindow *position); + /*virtual*/ bool getCursorDelta(LLCoordCommon* delta); /*virtual*/ void showCursor(); /*virtual*/ void hideCursor(); /*virtual*/ void showCursorFromMouseMove(); /*virtual*/ void hideCursorUntilMouseMove(); - /*virtual*/ BOOL isCursorHidden(); + /*virtual*/ bool isCursorHidden(); /*virtual*/ void updateCursor(); /*virtual*/ ECursorType getCursor() const; /*virtual*/ void captureMouse(); /*virtual*/ void releaseMouse(); - /*virtual*/ void setMouseClipping( BOOL b ); - /*virtual*/ BOOL isClipboardTextAvailable(); - /*virtual*/ BOOL pasteTextFromClipboard(LLWString &dst); - /*virtual*/ BOOL copyTextToClipboard(const LLWString &src); + /*virtual*/ void setMouseClipping( bool b ); + /*virtual*/ bool isClipboardTextAvailable(); + /*virtual*/ bool pasteTextFromClipboard(LLWString &dst); + /*virtual*/ bool copyTextToClipboard(const LLWString &src); /*virtual*/ void flashIcon(F32 seconds); /*virtual*/ F32 getGamma(); - /*virtual*/ BOOL setGamma(const F32 gamma); // Set the gamma + /*virtual*/ bool setGamma(const F32 gamma); // Set the gamma /*virtual*/ void setFSAASamples(const U32 fsaa_samples); /*virtual*/ U32 getFSAASamples(); - /*virtual*/ BOOL restoreGamma(); // Restore original gamma table (before updating gamma) + /*virtual*/ bool restoreGamma(); // Restore original gamma table (before updating gamma) /*virtual*/ ESwapMethod getSwapMethod() { return mSwapMethod; } /*virtual*/ void gatherInput(); /*virtual*/ void delayInputProcessing(); @@ -96,27 +96,25 @@ public: /*virtual*/ void restoreGLContext() {}; // handy coordinate space conversion routines - /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordWindow *to); - /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordScreen *to); - /*virtual*/ BOOL convertCoords(LLCoordWindow from, LLCoordGL *to); - /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordWindow *to); - /*virtual*/ BOOL convertCoords(LLCoordScreen from, LLCoordGL *to); - /*virtual*/ BOOL convertCoords(LLCoordGL from, LLCoordScreen *to); + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordWindow *to); + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordScreen *to); + /*virtual*/ bool convertCoords(LLCoordWindow from, LLCoordGL *to); + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordWindow *to); + /*virtual*/ bool convertCoords(LLCoordScreen from, LLCoordGL *to); + /*virtual*/ bool convertCoords(LLCoordGL from, LLCoordScreen *to); /*virtual*/ LLWindowResolution* getSupportedResolutions(S32 &num_resolutions); /*virtual*/ F32 getNativeAspectRatio(); /*virtual*/ F32 getPixelAspectRatio(); /*virtual*/ void setNativeAspectRatio(F32 ratio) { mOverrideAspectRatio = ratio; } - U32 getAvailableVRAMMegabytes() override; - - /*virtual*/ BOOL dialogColorPicker(F32 *r, F32 *g, F32 *b ); + /*virtual*/ bool dialogColorPicker(F32 *r, F32 *g, F32 *b ); /*virtual*/ void *getPlatformWindow(); /*virtual*/ void bringToFront(); /*virtual*/ void focusClient(); - /*virtual*/ void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b); + /*virtual*/ void allowLanguageTextInput(LLPreeditor *preeditor, bool b); /*virtual*/ void setLanguageTextInput( const LLCoordGL & pos ); /*virtual*/ void updateLanguageTextInputArea(); /*virtual*/ void interruptLanguageTextInput(); @@ -141,47 +139,43 @@ public: protected: LLWindowWin32(LLWindowCallbacks* callbacks, const std::string& title, const std::string& name, int x, int y, int width, int height, U32 flags, - BOOL fullscreen, BOOL clearBg, BOOL enable_vsync, BOOL use_gl, - BOOL ignore_pixel_depth, U32 fsaa_samples, U32 max_cores, U32 max_vram, F32 max_gl_version); + bool fullscreen, bool clearBg, bool enable_vsync, bool use_gl, + bool ignore_pixel_depth, U32 fsaa_samples, U32 max_cores, F32 max_gl_version); ~LLWindowWin32(); void initCursors(); - void initInputDevices(); HCURSOR loadColorCursor(LPCTSTR name); - BOOL isValid(); + bool isValid(); void moveWindow(const LLCoordScreen& position,const LLCoordScreen& size); virtual LLSD getNativeKeyData(); // Changes display resolution. Returns true if successful - BOOL setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh); + bool setDisplayResolution(S32 width, S32 height, S32 bits, S32 refresh); // Go back to last fullscreen display resolution. - BOOL setFullscreenResolution(); + bool setFullscreenResolution(); // Restore the display resolution to its value before we ran the app. - BOOL resetDisplayResolution(); + bool resetDisplayResolution(); - BOOL shouldPostQuit() { return mPostQuit; } + bool shouldPostQuit() { return mPostQuit; } - void fillCompositionForm(const LLRect& bounds, COMPOSITIONFORM *form); void fillCandidateForm(const LLCoordGL& caret, const LLRect& bounds, CANDIDATEFORM *form); void fillCharPosition(const LLCoordGL& caret, const LLRect& bounds, const LLRect& control, IMECHARPOSITION *char_position); void fillCompositionLogfont(LOGFONT *logfont); U32 fillReconvertString(const LLWString &text, S32 focus, S32 focus_length, RECONVERTSTRING *reconvert_string); void handleStartCompositionMessage(); void handleCompositionMessage(U32 indexes); - BOOL handleImeRequests(WPARAM request, LPARAM param, LRESULT *result); + bool handleImeRequests(WPARAM request, LPARAM param, LRESULT *result); protected: // // Platform specific methods // - BOOL getClientRectInScreenSpace(RECT* rectp); - void updateJoystick( ); + bool getClientRectInScreenSpace(RECT* rectp); static LRESULT CALLBACK mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_param, LPARAM l_param); - static BOOL CALLBACK enumChildWindows(HWND h_wnd, LPARAM l_param); // @@ -209,7 +203,7 @@ protected: MASK mMouseMask; - static BOOL sIsClassRegistered; // has the window class been registered? + static bool sIsClassRegistered; // has the window class been registered? F32 mCurrentGamma; U32 mFSAASamples; @@ -217,16 +211,16 @@ protected: F32 mMaxGLVersion; // maximum OpenGL version to attempt to use (clamps to 3.2 - 4.6) WORD mPrevGammaRamp[3][256]; WORD mCurrentGammaRamp[3][256]; - BOOL mCustomGammaSet; + bool mCustomGammaSet; LPWSTR mIconResource; - BOOL mInputProcessingPaused; + bool mInputProcessingPaused; // The following variables are for Language Text Input control. // They are all static, since one context is shared by all LLWindowWin32 // instances. - static BOOL sLanguageTextInputAllowed; - static BOOL sWinIMEOpened; + static bool sLanguageTextInputAllowed; + static bool sWinIMEOpened; static HKL sWinInputLocale; static DWORD sWinIMEConversionMode; static DWORD sWinIMESentenceMode; @@ -245,7 +239,7 @@ protected: U32 mRawWParam; U32 mRawLParam; - BOOL mMouseVanish; + bool mMouseVanish; // Cached values of GetWindowRect and GetClientRect to be used by app thread void updateWindowRect(); @@ -288,8 +282,6 @@ private: extern LLW32MsgCallback gAsyncMsgCallback; extern LPWSTR gIconResource; -static void handleMessage( const MSG& msg ); - S32 OSMessageBoxWin32(const std::string& text, const std::string& caption, U32 type); #endif //LL_LLWINDOWWIN32_H |