aboutsummaryrefslogtreecommitdiffstats
path: root/common
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 /common
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.
Diffstat (limited to 'common')
-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
16 files changed, 38 insertions, 25 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;