aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2023-01-06 15:31:24 +0100
committerPierre Ossman <ossman@cendio.se>2023-02-04 14:03:13 +0100
commitf55abd7b0074bc6db9774ed563e02b11e634aa7d (patch)
tree4e84caf8a93212f64e4fc875a99585d7a1fd6c87
parent9854463f16a3b98c55494e40f909d3b1f5f39192 (diff)
downloadtigervnc-f55abd7b0074bc6db9774ed563e02b11e634aa7d.tar.gz
tigervnc-f55abd7b0074bc6db9774ed563e02b11e634aa7d.zip
Use operator overloading for comparison
It is much more natural than custom methods for this very common operation.
-rw-r--r--common/rfb/CConnection.cxx2
-rw-r--r--common/rfb/ComparingUpdateTracker.cxx2
-rw-r--r--common/rfb/EncodeManager.cxx4
-rw-r--r--common/rfb/H264DecoderContext.h2
-rw-r--r--common/rfb/JpegCompressor.cxx8
-rw-r--r--common/rfb/JpegDecompressor.cxx8
-rw-r--r--common/rfb/PixelBuffer.cxx2
-rw-r--r--common/rfb/PixelFormat.cxx9
-rw-r--r--common/rfb/PixelFormat.h3
-rw-r--r--common/rfb/Rect.h6
-rw-r--r--common/rfb/Region.cxx6
-rw-r--r--common/rfb/Region.h3
-rw-r--r--common/rfb/ScreenSet.h2
-rw-r--r--common/rfb/TightDecoder.cxx2
-rw-r--r--common/rfb/VNCSConnectionST.cxx2
-rw-r--r--common/rfb/VNCServerST.cxx2
-rw-r--r--vncviewer/EmulateMB.cxx2
-rw-r--r--win/rfb_win32/SDisplay.cxx4
-rw-r--r--win/rfb_win32/SInput.cxx2
-rw-r--r--win/rfb_win32/WMCursor.h2
-rw-r--r--win/rfb_win32/WMWindowCopyRect.cxx2
21 files changed, 44 insertions, 31 deletions
diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx
index 56429c98..521649ac 100644
--- a/common/rfb/CConnection.cxx
+++ b/common/rfb/CConnection.cxx
@@ -740,7 +740,7 @@ void CConnection::setQualityLevel(int level)
void CConnection::setPF(const PixelFormat& pf)
{
- if (server.pf().equal(pf) && !formatChange)
+ if (server.pf() == pf && !formatChange)
return;
nextPF = pf;
diff --git a/common/rfb/ComparingUpdateTracker.cxx b/common/rfb/ComparingUpdateTracker.cxx
index 1bad487e..dab5e6aa 100644
--- a/common/rfb/ComparingUpdateTracker.cxx
+++ b/common/rfb/ComparingUpdateTracker.cxx
@@ -90,7 +90,7 @@ bool ComparingUpdateTracker::compare()
for (i = rects.begin(); i != rects.end(); i++)
missedPixels += i->area();
- if (changed.equals(newChanged))
+ if (changed == newChanged)
return false;
changed = newChanged;
diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx
index cade1506..bc15e74a 100644
--- a/common/rfb/EncodeManager.cxx
+++ b/common/rfb/EncodeManager.cxx
@@ -697,7 +697,7 @@ void EncodeManager::findSolidRect(const Rect& rect, Region *changed,
extendSolidAreaByBlock(sr, colourValue, pb, &erb);
// Did we end up getting the entire rectangle?
- if (erb.equals(rect))
+ if (erb == rect)
erp = erb;
else {
// Don't bother with sending tiny rectangles
@@ -1000,7 +1000,7 @@ PixelBuffer* EncodeManager::preparePixelBuffer(const Rect& rect,
int stride;
// Do wo need to convert the data?
- if (convert && !conn->client.pf().equal(pb->getPF())) {
+ if (convert && conn->client.pf() != pb->getPF()) {
convertedPixelBuffer.setPF(conn->client.pf());
convertedPixelBuffer.setSize(rect.width(), rect.height());
diff --git a/common/rfb/H264DecoderContext.h b/common/rfb/H264DecoderContext.h
index ccb0bdb3..88c2396c 100644
--- a/common/rfb/H264DecoderContext.h
+++ b/common/rfb/H264DecoderContext.h
@@ -39,7 +39,7 @@ namespace rfb {
ModifiablePixelBuffer* /*pb*/) {}
void reset();
- inline bool isEqualRect(const Rect &r) const { return r.equals(rect); }
+ inline bool isEqualRect(const Rect &r) const { return r == rect; }
bool isReady();
protected:
diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx
index 51d3c357..d5c5fd0d 100644
--- a/common/rfb/JpegCompressor.cxx
+++ b/common/rfb/JpegCompressor.cxx
@@ -182,13 +182,13 @@ void JpegCompressor::compress(const uint8_t *buf, volatile int stride,
#ifdef JCS_EXTENSIONS
// Try to have libjpeg output directly to our native format
// libjpeg can only handle some "standard" formats
- if (pfRGBX.equal(pf))
+ if (pfRGBX == pf)
cinfo->in_color_space = JCS_EXT_RGBX;
- else if (pfBGRX.equal(pf))
+ else if (pfBGRX == pf)
cinfo->in_color_space = JCS_EXT_BGRX;
- else if (pfXRGB.equal(pf))
+ else if (pfXRGB == pf)
cinfo->in_color_space = JCS_EXT_XRGB;
- else if (pfXBGR.equal(pf))
+ else if (pfXBGR == pf)
cinfo->in_color_space = JCS_EXT_XBGR;
if (cinfo->in_color_space != JCS_RGB) {
diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx
index 5520a949..44c54fb2 100644
--- a/common/rfb/JpegDecompressor.cxx
+++ b/common/rfb/JpegDecompressor.cxx
@@ -184,13 +184,13 @@ void JpegDecompressor::decompress(const uint8_t *jpegBuf,
#ifdef JCS_EXTENSIONS
// Try to have libjpeg output directly to our native format
// libjpeg can only handle some "standard" formats
- if (pfRGBX.equal(pf))
+ if (pfRGBX == pf)
dinfo->out_color_space = JCS_EXT_RGBX;
- else if (pfBGRX.equal(pf))
+ else if (pfBGRX == pf)
dinfo->out_color_space = JCS_EXT_BGRX;
- else if (pfXRGB.equal(pf))
+ else if (pfXRGB == pf)
dinfo->out_color_space = JCS_EXT_XRGB;
- else if (pfXBGR.equal(pf))
+ else if (pfXBGR == pf)
dinfo->out_color_space = JCS_EXT_XBGR;
if (dinfo->out_color_space != JCS_RGB) {
diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx
index 28eea9a7..c8b5f3d7 100644
--- a/common/rfb/PixelBuffer.cxx
+++ b/common/rfb/PixelBuffer.cxx
@@ -101,7 +101,7 @@ void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf,
const uint8_t* srcBuffer;
int srcStride;
- if (format.equal(pf)) {
+ if (format == pf) {
getImage(imageBuf, r, stride);
return;
}
diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx
index b3ea8182..b90fc206 100644
--- a/common/rfb/PixelFormat.cxx
+++ b/common/rfb/PixelFormat.cxx
@@ -99,7 +99,7 @@ PixelFormat::PixelFormat()
updateState();
}
-bool PixelFormat::equal(const PixelFormat& other) const
+bool PixelFormat::operator==(const PixelFormat& other) const
{
if (bpp != other.bpp || depth != other.depth)
return false;
@@ -148,6 +148,11 @@ bool PixelFormat::equal(const PixelFormat& other) const
return true;
}
+bool PixelFormat::operator!=(const PixelFormat& other) const
+{
+ return !(*this == other);
+}
+
void PixelFormat::read(rdr::InStream* is)
{
bpp = is->readU8();
@@ -381,7 +386,7 @@ void PixelFormat::bufferFromBuffer(uint8_t* dst, const PixelFormat &srcPF,
const uint8_t* src, int w, int h,
int dstStride, int srcStride) const
{
- if (equal(srcPF)) {
+ if (*this == srcPF) {
// Trivial case
while (h--) {
memcpy(dst, src, w * bpp/8);
diff --git a/common/rfb/PixelFormat.h b/common/rfb/PixelFormat.h
index b59a7657..ce9b3927 100644
--- a/common/rfb/PixelFormat.h
+++ b/common/rfb/PixelFormat.h
@@ -49,7 +49,8 @@ namespace rfb {
// Checks if the formats have identical buffer representation.
// They might still have different pixel representation, endianness
// or true colour state.
- bool equal(const PixelFormat& other) const;
+ bool operator==(const PixelFormat& other) const;
+ bool operator!=(const PixelFormat& other) const;
void read(rdr::InStream* is);
void write(rdr::OutStream* os) const;
diff --git a/common/rfb/Rect.h b/common/rfb/Rect.h
index bd9b160a..b82ed274 100644
--- a/common/rfb/Rect.h
+++ b/common/rfb/Rect.h
@@ -50,7 +50,8 @@ namespace rfb {
inline Point negate() const
__attribute__ ((warn_unused_result))
{return Point(-x, -y);}
- inline bool equals(const Point &p) const {return x==p.x && y==p.y;}
+ inline bool operator==(const Point &p) const {return x==p.x && y==p.y;}
+ inline bool operator!=(const Point &p) const {return x!=p.x || y!=p.y;}
inline Point translate(const Point &p) const
__attribute__ ((warn_unused_result))
{return Point(x+p.x, y+p.y);}
@@ -105,7 +106,8 @@ namespace rfb {
{
return Rect(tl.translate(p), br.translate(p));
}
- inline bool equals(const Rect &r) const {return r.tl.equals(tl) && r.br.equals(br);}
+ inline bool operator==(const Rect &r) const {return r.tl == tl && r.br == br;}
+ inline bool operator!=(const Rect &r) const {return r.tl != tl || r.br != br;}
inline bool is_empty() const {return (tl.x >= br.x) || (tl.y >= br.y);}
inline void clear() {tl = Point(); br = Point();}
inline bool enclosed_by(const Rect &r) const {
diff --git a/common/rfb/Region.cxx b/common/rfb/Region.cxx
index fecc881e..cfdf0ca2 100644
--- a/common/rfb/Region.cxx
+++ b/common/rfb/Region.cxx
@@ -101,10 +101,14 @@ rfb::Region rfb::Region::subtract(const rfb::Region& r) const {
return ret;
}
-bool rfb::Region::equals(const rfb::Region& r) const {
+bool rfb::Region::operator==(const rfb::Region& r) const {
return pixman_region_equal(rgn, r.rgn);
}
+bool rfb::Region::operator!=(const rfb::Region& r) const {
+ return !pixman_region_equal(rgn, r.rgn);
+}
+
int rfb::Region::numRects() const {
return pixman_region_n_rects(rgn);
}
diff --git a/common/rfb/Region.h b/common/rfb/Region.h
index eb16861e..38de67ce 100644
--- a/common/rfb/Region.h
+++ b/common/rfb/Region.h
@@ -60,7 +60,8 @@ namespace rfb {
Region subtract(const Region& r) const
__attribute__ ((warn_unused_result));
- bool equals(const Region& b) const;
+ bool operator==(const Region& b) const;
+ bool operator!=(const Region& b) const;
int numRects() const;
bool is_empty() const { return numRects() == 0; }
diff --git a/common/rfb/ScreenSet.h b/common/rfb/ScreenSet.h
index e43055f2..fb93e5c2 100644
--- a/common/rfb/ScreenSet.h
+++ b/common/rfb/ScreenSet.h
@@ -44,7 +44,7 @@ namespace rfb {
inline bool operator==(const Screen& r) const {
if (id != r.id)
return false;
- if (!dimensions.equals(r.dimensions))
+ if (dimensions != r.dimensions)
return false;
if (flags != r.flags)
return false;
diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx
index 09c253bd..acc9d5a5 100644
--- a/common/rfb/TightDecoder.cxx
+++ b/common/rfb/TightDecoder.cxx
@@ -400,7 +400,7 @@ void TightDecoder::decodeRect(const Rect& r, const void* buffer,
uint8_t* outbuf;
int stride;
- if (pb->getPF().equal(pf)) {
+ if (pb->getPF() == pf) {
// Decode directly into the framebuffer (fast path)
directDecode = true;
} else {
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index 0400d510..97fa69cb 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -403,7 +403,7 @@ bool VNCSConnectionST::needRenderedCursor()
if (!client.supportsLocalCursor())
return true;
- if (!server->getCursorPos().equals(pointerEventPos) &&
+ if ((server->getCursorPos() != pointerEventPos) &&
(time(0) - pointerEventTime) > 0)
return true;
diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx
index ca32282e..5f5ee34a 100644
--- a/common/rfb/VNCServerST.cxx
+++ b/common/rfb/VNCServerST.cxx
@@ -432,7 +432,7 @@ void VNCServerST::setCursor(int width, int height, const Point& newHotspot,
void VNCServerST::setCursorPos(const Point& pos, bool warped)
{
- if (!cursorPos.equals(pos)) {
+ if (cursorPos != pos) {
cursorPos = pos;
renderedCursorInvalid = true;
std::list<VNCSConnectionST*>::iterator ci;
diff --git a/vncviewer/EmulateMB.cxx b/vncviewer/EmulateMB.cxx
index 3cd3fea6..33e685c4 100644
--- a/vncviewer/EmulateMB.cxx
+++ b/vncviewer/EmulateMB.cxx
@@ -304,7 +304,7 @@ bool EmulateMB::handleTimeout(rfb::Timer *t)
// Pointer move events are not sent when waiting for the timeout.
// However, we can't let the position get out of sync so when
// the pointer has moved we have to send the latest position here.
- if (!origPos.equals(lastPos)) {
+ if (origPos != lastPos) {
buttonMask = createButtonMask(buttonMask);
sendPointerEvent(lastPos, buttonMask);
}
diff --git a/win/rfb_win32/SDisplay.cxx b/win/rfb_win32/SDisplay.cxx
index 811b1033..612f883b 100644
--- a/win/rfb_win32/SDisplay.cxx
+++ b/win/rfb_win32/SDisplay.cxx
@@ -468,8 +468,8 @@ SDisplay::recreatePixelBuffer(bool force) {
// If nothing has changed & a recreate has not been forced, delete
// the new device context and return
if (pb && !force &&
- newScreenRect.equals(screenRect) &&
- new_device->getPF().equal(pb->getPF())) {
+ newScreenRect == screenRect &&
+ new_device->getPF() == pb->getPF()) {
delete new_device;
return;
}
diff --git a/win/rfb_win32/SInput.cxx b/win/rfb_win32/SInput.cxx
index b76060a8..94df6e98 100644
--- a/win/rfb_win32/SInput.cxx
+++ b/win/rfb_win32/SInput.cxx
@@ -71,7 +71,7 @@ win32::SPointer::pointerEvent(const Point& pos, int buttonmask)
DWORD flags = MOUSEEVENTF_ABSOLUTE;
// - Has the pointer moved since the last event?
- if (!last_position.equals(pos))
+ if (last_position != pos)
flags |= MOUSEEVENTF_MOVE;
// - If the system swaps left and right mouse buttons then we must
diff --git a/win/rfb_win32/WMCursor.h b/win/rfb_win32/WMCursor.h
index 252cb056..f4366583 100644
--- a/win/rfb_win32/WMCursor.h
+++ b/win/rfb_win32/WMCursor.h
@@ -43,7 +43,7 @@ namespace rfb {
Info() : cursor(0), visible(false) {}
bool operator!=(const Info& info) {
return ((cursor != info.cursor) ||
- (!position.equals(info.position)) ||
+ (position != info.position) ||
(visible != info.visible));
}
};
diff --git a/win/rfb_win32/WMWindowCopyRect.cxx b/win/rfb_win32/WMWindowCopyRect.cxx
index 7655da84..4d69d54b 100644
--- a/win/rfb_win32/WMWindowCopyRect.cxx
+++ b/win/rfb_win32/WMWindowCopyRect.cxx
@@ -45,7 +45,7 @@ rfb::win32::WMCopyRect::processEvent() {
if (IsWindow(window) && IsWindowVisible(window) && GetWindowRect(window, &wrect)) {
Rect winrect(wrect.left, wrect.top, wrect.right, wrect.bottom);
if (fg_window == window) {
- if (!fg_window_rect.tl.equals(winrect.tl) && ut) {
+ if (fg_window_rect.tl != winrect.tl && ut) {
// Window has moved - mark both the previous and new position as changed
// (we can't use add_copied() here because we aren't that properly synced
// with the actual state of the framebuffer)