diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-03 10:28:39 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2025-02-25 17:18:35 +0100 |
commit | e0e4f4ca67dbb2db2cf547431fc1c60192aad21a (patch) | |
tree | 4d35b90f0800744dc62de028f6cd45a5564448f4 | |
parent | fc215c8c1dc5c8d70e476e6cc0a574b8e2edf842 (diff) | |
download | tigervnc-e0e4f4ca67dbb2db2cf547431fc1c60192aad21a.tar.gz tigervnc-e0e4f4ca67dbb2db2cf547431fc1c60192aad21a.zip |
Get rid of __rfbmax()/__rfbmin()
They weren't that well used, and were mostly just confusing special
functions anyway.
Allows us to move away from generic and ambigious headers such as
"util".
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | common/core/Rect.h | 28 | ||||
-rw-r--r-- | common/core/util.h | 12 | ||||
-rw-r--r-- | common/rdr/CMakeLists.txt | 5 | ||||
-rw-r--r-- | common/rfb/CConnection.cxx | 5 | ||||
-rw-r--r-- | common/rfb/ComparingUpdateTracker.cxx | 9 | ||||
-rw-r--r-- | common/rfb/Congestion.cxx | 13 | ||||
-rw-r--r-- | common/rfb/EncodeManager.cxx | 15 | ||||
-rw-r--r-- | common/rfb/HextileDecoder.cxx | 10 | ||||
-rw-r--r-- | common/rfb/HextileEncoder.cxx | 10 | ||||
-rw-r--r-- | common/rfb/ZRLEDecoder.cxx | 6 | ||||
-rw-r--r-- | unix/tx/TXButton.h | 7 | ||||
-rw-r--r-- | unix/tx/TXCheckbox.h | 7 | ||||
-rw-r--r-- | unix/tx/TXLabel.h | 7 | ||||
-rw-r--r-- | unix/vncconfig/QueryConnectDialog.cxx | 10 | ||||
-rw-r--r-- | win/rfb_win32/SDisplayCorePolling.cxx | 7 |
16 files changed, 78 insertions, 78 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e6b84601..77990d04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,11 @@ if(ENABLE_TSAN AND NOT WIN32 AND NOT APPLE AND CMAKE_SIZEOF_VOID_P MATCHES 8) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") endif() +if(MSVC) + # undef min and max macro + target_compile_definitions(rfb PRIVATE NOMINMAX) +endif() + if(NOT DEFINED BUILD_WINVNC) set(BUILD_WINVNC 1) endif() diff --git a/common/core/Rect.h b/common/core/Rect.h index 1f035c70..e4cb1634 100644 --- a/common/core/Rect.h +++ b/common/core/Rect.h @@ -21,17 +21,7 @@ #ifndef __CORE_RECT_INCLUDED__ #define __CORE_RECT_INCLUDED__ -// Some platforms (e.g. Windows) include max() and min() macros in their -// standard headers, but they are also standard C++ template functions, so some -// C++ headers will undefine them. So we steer clear of the names min and max -// and define __rfbmin and __rfbmax instead. - -#ifndef __rfbmax -#define __rfbmax(a,b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef __rfbmin -#define __rfbmin(a,b) (((a) < (b)) ? (a) : (b)) -#endif +#include <algorithm> namespace core { @@ -83,10 +73,10 @@ namespace core { __attribute__ ((warn_unused_result)) { Rect result; - result.tl.x = __rfbmax(tl.x, r.tl.x); - result.tl.y = __rfbmax(tl.y, r.tl.y); - result.br.x = __rfbmax(__rfbmin(br.x, r.br.x), result.tl.x); - result.br.y = __rfbmax(__rfbmin(br.y, r.br.y), result.tl.y); + result.tl.x = std::max(tl.x, r.tl.x); + result.tl.y = std::max(tl.y, r.tl.y); + result.br.x = std::max(std::min(br.x, r.br.x), result.tl.x); + result.br.y = std::max(std::min(br.y, r.br.y), result.tl.y); return result; } inline Rect union_boundary(const Rect &r) const @@ -95,10 +85,10 @@ namespace core { if (r.is_empty()) return *this; if (is_empty()) return r; Rect result; - result.tl.x = __rfbmin(tl.x, r.tl.x); - result.tl.y = __rfbmin(tl.y, r.tl.y); - result.br.x = __rfbmax(br.x, r.br.x); - result.br.y = __rfbmax(br.y, r.br.y); + result.tl.x = std::min(tl.x, r.tl.x); + result.tl.y = std::min(tl.y, r.tl.y); + result.br.x = std::max(br.x, r.br.x); + result.br.y = std::max(br.y, r.br.y); return result; } inline Rect translate(const Point &p) const diff --git a/common/core/util.h b/common/core/util.h index 9666a93a..698d291e 100644 --- a/common/core/util.h +++ b/common/core/util.h @@ -77,16 +77,4 @@ namespace core { int precision=6); } -// Some platforms (e.g. Windows) include max() and min() macros in their -// standard headers, but they are also standard C++ template functions, so some -// C++ headers will undefine them. So we steer clear of the names min and max -// and define __rfbmin and __rfbmax instead. - -#ifndef __rfbmax -#define __rfbmax(a,b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef __rfbmin -#define __rfbmin(a,b) (((a) < (b)) ? (a) : (b)) -#endif - #endif diff --git a/common/rdr/CMakeLists.txt b/common/rdr/CMakeLists.txt index 29e968db..520ac664 100644 --- a/common/rdr/CMakeLists.txt +++ b/common/rdr/CMakeLists.txt @@ -20,11 +20,6 @@ target_include_directories(rdr SYSTEM PUBLIC ${ZLIB_INCLUDE_DIRS}) target_link_libraries(rdr core os) target_link_libraries(rdr ${ZLIB_LIBRARIES}) -if(MSVC) - # undef min and max macro - target_compile_definitions(rfb PRIVATE NOMINMAX) -endif() - if(GNUTLS_FOUND) target_include_directories(rdr SYSTEM PUBLIC ${GNUTLS_INCLUDE_DIR}) target_link_libraries(rdr ${GNUTLS_LIBRARIES}) diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 725ba5cd..2857d91f 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -109,9 +109,8 @@ void CConnection::setFramebuffer(ModifiablePixelBuffer* fb) // Copy still valid area - rect.setXYWH(0, 0, - __rfbmin(fb->width(), framebuffer->width()), - __rfbmin(fb->height(), framebuffer->height())); + rect = fb->getRect(); + rect = rect.intersect(framebuffer->getRect()); data = framebuffer->getBuffer(framebuffer->getRect(), &stride); fb->imageRect(rect, data, stride); diff --git a/common/rfb/ComparingUpdateTracker.cxx b/common/rfb/ComparingUpdateTracker.cxx index 6e4d1d9d..c436b3ff 100644 --- a/common/rfb/ComparingUpdateTracker.cxx +++ b/common/rfb/ComparingUpdateTracker.cxx @@ -23,6 +23,7 @@ #include <stdio.h> #include <string.h> +#include <algorithm> #include <vector> #include <core/LogWriter.h> @@ -62,7 +63,7 @@ bool ComparingUpdateTracker::compare() oldFb.setSize(fb->width(), fb->height()); for (int y=0; y<fb->height(); y+=BLOCK_SIZE) { - core::Rect pos(0, y, fb->width(), __rfbmin(fb->height(), y+BLOCK_SIZE)); + core::Rect pos(0, y, fb->width(), std::min(fb->height(), y+BLOCK_SIZE)); int srcStride; const uint8_t* srcData = fb->getBuffer(pos, &srcStride); oldFb.imageRect(pos, srcData, srcStride); @@ -135,20 +136,20 @@ void ComparingUpdateTracker::compareRect(const core::Rect& r, for (int blockTop = r.tl.y; blockTop < r.br.y; blockTop += BLOCK_SIZE) { // Get a strip of the source buffer - core::Rect pos(r.tl.x, blockTop, r.br.x, __rfbmin(r.br.y, blockTop+BLOCK_SIZE)); + core::Rect pos(r.tl.x, blockTop, r.br.x, std::min(r.br.y, blockTop+BLOCK_SIZE)); int fbStride; const uint8_t* newBlockPtr = fb->getBuffer(pos, &fbStride); int newStrideBytes = fbStride * bytesPerPixel; uint8_t* oldBlockPtr = oldData; - int blockBottom = __rfbmin(blockTop+BLOCK_SIZE, r.br.y); + int blockBottom = std::min(blockTop+BLOCK_SIZE, r.br.y); for (int blockLeft = r.tl.x; blockLeft < r.br.x; blockLeft += BLOCK_SIZE) { const uint8_t* newPtr = newBlockPtr; uint8_t* oldPtr = oldBlockPtr; - int blockRight = __rfbmin(blockLeft+BLOCK_SIZE, r.br.x); + int blockRight = std::min(blockLeft+BLOCK_SIZE, r.br.x); int blockWidthInBytes = (blockRight-blockLeft) * bytesPerPixel; // Scan the block top to bottom, to identify the first row of change diff --git a/common/rfb/Congestion.cxx b/common/rfb/Congestion.cxx index 7008bc33..46bae00d 100644 --- a/common/rfb/Congestion.cxx +++ b/common/rfb/Congestion.cxx @@ -50,7 +50,6 @@ #endif #include <core/LogWriter.h> -#include <core/util.h> #include <core/time.h> #include <rfb/Congestion.h> @@ -101,7 +100,7 @@ Congestion::~Congestion() void Congestion::updatePosition(unsigned pos) { struct timeval now; - unsigned delta, consumed; + unsigned idle, delta, consumed; gettimeofday(&now, nullptr); @@ -112,15 +111,17 @@ void Congestion::updatePosition(unsigned pos) // Idle for too long? // We use a very crude RTO calculation in order to keep things simple // FIXME: should implement RFC 2861 - if (core::msBetween(&lastSent, &now) > __rfbmax(baseRTT*2, 100)) { + idle = core::msBetween(&lastSent, &now); + if (idle > 100 && idle > baseRTT*2) { #ifdef CONGESTION_DEBUG vlog.debug("Connection idle for %d ms, resetting congestion control", - core::msBetween(&lastSent, &now)); + idle); #endif // Close congestion window and redo wire latency measurement - congWindow = __rfbmin(INITIAL_WINDOW, congWindow); + if (congWindow > INITIAL_WINDOW) + congWindow = INITIAL_WINDOW; baseRTT = -1; measurements = 0; gettimeofday(&lastAdjustment, nullptr); @@ -432,7 +433,7 @@ void Congestion::updateCongestion() diff = minRTT - baseRTT; - if (diff > __rfbmax(100, baseRTT/2)) { + if (diff > 100 && diff > baseRTT/2) { // We have no way of detecting loss, so assume massive latency // spike means packet loss. Adjust the window and go directly // to congestion avoidance. diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index a482991e..0655f404 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -481,9 +481,10 @@ void EncodeManager::prepareEncoders(bool allowLossy) encoder->setFineQualityLevel(conn->client.fineQualityLevel, conn->client.subsampling); } else { - int level = __rfbmax(conn->client.qualityLevel, - encoder->losslessQuality); - encoder->setQualityLevel(level); + if (conn->client.qualityLevel < encoder->losslessQuality) + encoder->setQualityLevel(encoder->losslessQuality); + else + encoder->setQualityLevel(conn->client.qualityLevel); encoder->setFineQualityLevel(-1, subsampleUndefined); } } @@ -520,10 +521,14 @@ core::Region EncodeManager::getLosslessRefresh(const core::Region& req, // Use the narrowest axis to avoid getting to thin rects if (rect.width() > rect.height()) { int width = (maxUpdateSize - area) / rect.height(); - rect.br.x = rect.tl.x + __rfbmax(1, width); + if (width < 1) + width = 1; + rect.br.x = rect.tl.x + width; } else { int height = (maxUpdateSize - area) / rect.width(); - rect.br.y = rect.tl.y + __rfbmax(1, height); + if (height < 1) + height = 1; + rect.br.y = rect.tl.y + height; } refresh.assign_union(rect); break; diff --git a/common/rfb/HextileDecoder.cxx b/common/rfb/HextileDecoder.cxx index 0adffd54..c6eb428b 100644 --- a/common/rfb/HextileDecoder.cxx +++ b/common/rfb/HextileDecoder.cxx @@ -21,6 +21,8 @@ #include <config.h> #endif +#include <algorithm> + #include <rdr/InStream.h> #include <rdr/MemInStream.h> #include <rdr/OutStream.h> @@ -53,12 +55,12 @@ bool HextileDecoder::readRect(const core::Rect& r, rdr::InStream* is, for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) { - t.br.y = __rfbmin(r.br.y, t.tl.y + 16); + t.br.y = std::min(r.br.y, t.tl.y + 16); for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) { uint8_t tileType; - t.br.x = __rfbmin(r.br.x, t.tl.x + 16); + t.br.x = std::min(r.br.x, t.tl.x + 16); if (!is->hasDataOrRestore(1)) return false; @@ -149,11 +151,11 @@ void HextileDecoder::hextileDecode(const core::Rect& r, rdr::InStream* is, for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 16) { - t.br.y = __rfbmin(r.br.y, t.tl.y + 16); + t.br.y = std::min(r.br.y, t.tl.y + 16); for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 16) { - t.br.x = __rfbmin(r.br.x, t.tl.x + 16); + t.br.x = std::min(r.br.x, t.tl.x + 16); int tileType = is->readU8(); diff --git a/common/rfb/HextileEncoder.cxx b/common/rfb/HextileEncoder.cxx index 3a9982fb..5ee07a2d 100644 --- a/common/rfb/HextileEncoder.cxx +++ b/common/rfb/HextileEncoder.cxx @@ -22,6 +22,8 @@ #include <config.h> #endif +#include <algorithm> + #include <core/Configuration.h> #include <rdr/OutStream.h> @@ -129,11 +131,11 @@ void HextileEncoder::hextileEncode(rdr::OutStream* os, for (t.tl.y = 0; t.tl.y < pb->height(); t.tl.y += 16) { - t.br.y = __rfbmin(pb->height(), t.tl.y + 16); + t.br.y = std::min(pb->height(), t.tl.y + 16); for (t.tl.x = 0; t.tl.x < pb->width(); t.tl.x += 16) { - t.br.x = __rfbmin(pb->width(), t.tl.x + 16); + t.br.x = std::min(pb->width(), t.tl.x + 16); pb->getImage(buf, t); @@ -548,11 +550,11 @@ void HextileEncoder::hextileEncodeBetter(rdr::OutStream* os, for (t.tl.y = 0; t.tl.y < pb->height(); t.tl.y += 16) { - t.br.y = __rfbmin(pb->height(), t.tl.y + 16); + t.br.y = std::min(pb->height(), t.tl.y + 16); for (t.tl.x = 0; t.tl.x < pb->width(); t.tl.x += 16) { - t.br.x = __rfbmin(pb->width(), t.tl.x + 16); + t.br.x = std::min(pb->width(), t.tl.x + 16); pb->getImage(buf, t); diff --git a/common/rfb/ZRLEDecoder.cxx b/common/rfb/ZRLEDecoder.cxx index f149eca6..845bf4dc 100644 --- a/common/rfb/ZRLEDecoder.cxx +++ b/common/rfb/ZRLEDecoder.cxx @@ -21,6 +21,8 @@ #include <config.h> #endif +#include <algorithm> + #include <rdr/InStream.h> #include <rdr/MemInStream.h> #include <rdr/OutStream.h> @@ -134,11 +136,11 @@ void ZRLEDecoder::zrleDecode(const core::Rect& r, rdr::InStream* is, for (t.tl.y = r.tl.y; t.tl.y < r.br.y; t.tl.y += 64) { - t.br.y = __rfbmin(r.br.y, t.tl.y + 64); + t.br.y = std::min(r.br.y, t.tl.y + 64); for (t.tl.x = r.tl.x; t.tl.x < r.br.x; t.tl.x += 64) { - t.br.x = __rfbmin(r.br.x, t.tl.x + 64); + t.br.x = std::min(r.br.x, t.tl.x + 64); zlibHasData(&zis, 1); int mode = zis.readU8(); diff --git a/unix/tx/TXButton.h b/unix/tx/TXButton.h index 579d011f..f94561e3 100644 --- a/unix/tx/TXButton.h +++ b/unix/tx/TXButton.h @@ -26,8 +26,9 @@ #ifndef __TXBUTTON_H__ #define __TXBUTTON_H__ +#include <algorithm> + #include "TXWindow.h" -#include <core/util.h> // TXButtonCallback's buttonActivate() method is called when a button is // activated. @@ -63,8 +64,8 @@ public: text = text_; int textWidth = XTextWidth(defaultFS, text.data(), text.size()); int textHeight = (defaultFS->ascent + defaultFS->descent); - int newWidth = __rfbmax(width(), textWidth + xPad*2 + bevel*2); - int newHeight = __rfbmax(height(), textHeight + yPad*2 + bevel*2); + int newWidth = std::max(width(), textWidth + xPad*2 + bevel*2); + int newHeight = std::max(height(), textHeight + yPad*2 + bevel*2); if (width() < newWidth || height() < newHeight) { resize(newWidth, newHeight); } diff --git a/unix/tx/TXCheckbox.h b/unix/tx/TXCheckbox.h index e9debce4..64d56074 100644 --- a/unix/tx/TXCheckbox.h +++ b/unix/tx/TXCheckbox.h @@ -33,8 +33,9 @@ #ifndef __TXCHECKBOX_H__ #define __TXCHECKBOX_H__ +#include <algorithm> + #include "TXWindow.h" -#include <core/util.h> // TXCheckboxCallback's checkboxSelect() method is called when the state of a // checkbox changes. @@ -72,8 +73,8 @@ public: text = strdup((char*)text_); int textWidth = XTextWidth(defaultFS, text, strlen(text)); int textHeight = (defaultFS->ascent + defaultFS->descent); - int newWidth = __rfbmax(width(), textWidth + xPad*2 + boxPad*2 + boxSize); - int newHeight = __rfbmax(height(), textHeight + yPad*2); + int newWidth = std::max(width(), textWidth + xPad*2 + boxPad*2 + boxSize); + int newHeight = std::max(height(), textHeight + yPad*2); if (width() < newWidth || height() < newHeight) { resize(newWidth, newHeight); } diff --git a/unix/tx/TXLabel.h b/unix/tx/TXLabel.h index 85bce5bf..053433c8 100644 --- a/unix/tx/TXLabel.h +++ b/unix/tx/TXLabel.h @@ -27,6 +27,9 @@ #define __TXLABEL_H__ #include <stdlib.h> + +#include <algorithm> + #include "TXWindow.h" #include <core/util.h> @@ -63,8 +66,8 @@ public: } while (i < text.size()); int textHeight = ((defaultFS->ascent + defaultFS->descent + lineSpacing) * lines); - int newWidth = __rfbmax(width(), textWidth + xPad*2); - int newHeight = __rfbmax(height(), textHeight + yPad*2); + int newWidth = std::max(width(), textWidth + xPad*2); + int newHeight = std::max(height(), textHeight + yPad*2); if (width() < newWidth || height() < newHeight) { resize(newWidth, newHeight); } diff --git a/unix/vncconfig/QueryConnectDialog.cxx b/unix/vncconfig/QueryConnectDialog.cxx index 7beee5f4..1d495ea5 100644 --- a/unix/vncconfig/QueryConnectDialog.cxx +++ b/unix/vncconfig/QueryConnectDialog.cxx @@ -22,6 +22,8 @@ #include <stdio.h> +#include <algorithm> + #include "QueryConnectDialog.h" #include "vncExt.h" @@ -43,7 +45,7 @@ QueryConnectDialog::QueryConnectDialog(Display* dpy_, { const int pad = 4; int y=pad; - int lblWidth = __rfbmax(addressLbl.width(), userLbl.width()); + int lblWidth = std::max(addressLbl.width(), userLbl.width()); userLbl.move(pad+lblWidth-userLbl.width(), y); user.move(pad+lblWidth, y); addressLbl.move(pad+lblWidth-addressLbl.width(), y+=userLbl.height()); @@ -51,9 +53,9 @@ QueryConnectDialog::QueryConnectDialog(Display* dpy_, timeoutLbl.move(pad, y+=addressLbl.height()); timeout.move(pad+timeoutLbl.width(), y); accept.move(pad, y+=addressLbl.height()); - int maxWidth = __rfbmax(user.width(), address.width()+pad+lblWidth); - maxWidth = __rfbmax(maxWidth, accept.width()*3); - maxWidth = __rfbmax(maxWidth, timeoutLbl.width()+timeout.width()+pad); + int maxWidth = std::max(user.width(), address.width()+pad+lblWidth); + maxWidth = std::max(maxWidth, accept.width()*3); + maxWidth = std::max(maxWidth, timeoutLbl.width()+timeout.width()+pad); reject.move(maxWidth-reject.width(), y); resize(maxWidth + pad, y+reject.height()+pad); setBorderWidth(1); diff --git a/win/rfb_win32/SDisplayCorePolling.cxx b/win/rfb_win32/SDisplayCorePolling.cxx index ba30704c..0a600c97 100644 --- a/win/rfb_win32/SDisplayCorePolling.cxx +++ b/win/rfb_win32/SDisplayCorePolling.cxx @@ -39,7 +39,9 @@ const unsigned int SDisplayCorePolling::pollTimerId = 1; SDisplayCorePolling::SDisplayCorePolling(SDisplay* d, UpdateTracker* ut, int pollInterval_) : MsgWindow("rfb::win32::SDisplayCorePolling"), pollTimer(getHandle(), pollTimerId), pollNextStrip(false), display(d), updateTracker(ut) { - pollInterval = __rfbmax(10, (pollInterval_ / POLLING_SEGMENTS)); + pollInterval = pollInterval_ / POLLING_SEGMENTS; + if (pollInterval < 10) + pollInterval = 10; copyrect.setUpdateTracker(ut); } @@ -80,7 +82,8 @@ void SDisplayCorePolling::flushUpdates() { // No. Poll the next section pollrect.tl.y = pollNextY; pollNextY += pollIncrementY; - pollrect.br.y = __rfbmin(pollNextY, pollrect.br.y); + if (pollrect.br.y > pollNextY) + pollrect.br.y = pollNextY; updateTracker->add_changed(pollrect); } } |