From: Pierre Ossman Date: Fri, 1 May 2020 15:37:04 +0000 (+0200) Subject: Get rid of magical assignment to Region X-Git-Tag: v1.10.90~17^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6e6a221e3db5f384bcadeeef015676ef2b91d48e;p=tigervnc.git Get rid of magical assignment to Region Might as well make these explicit so the cost is apparent. --- diff --git a/common/rfb/ComparingUpdateTracker.cxx b/common/rfb/ComparingUpdateTracker.cxx index 237adc41..d5651200 100644 --- a/common/rfb/ComparingUpdateTracker.cxx +++ b/common/rfb/ComparingUpdateTracker.cxx @@ -120,8 +120,6 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged) rdr::U8* oldData = oldFb.getBufferRW(r, &oldStride); int oldStrideBytes = oldStride * bytesPerPixel; - std::vector changedBlocks; - for (int blockTop = r.tl.y; blockTop < r.br.y; blockTop += BLOCK_SIZE) { // Get a strip of the source buffer @@ -146,8 +144,8 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged) if (memcmp(oldPtr, newPtr, blockWidthInBytes) != 0) { // A block has changed - copy the remainder to the oldFb - changedBlocks.push_back(Rect(blockLeft, blockTop, - blockRight, blockBottom)); + newChanged->assign_union(Region(Rect(blockLeft, blockTop, + blockRight, blockBottom))); for (int y2 = y; y2 < blockBottom; y2++) { memcpy(oldPtr, newPtr, blockWidthInBytes); @@ -169,12 +167,6 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged) } oldFb.commitBufferRW(r); - - if (!changedBlocks.empty()) { - Region temp; - temp.setOrderedRects(changedBlocks); - newChanged->assign_union(temp); - } } void ComparingUpdateTracker::logStats() diff --git a/common/rfb/Region.cxx b/common/rfb/Region.cxx index 17170fa6..2664fb11 100644 --- a/common/rfb/Region.cxx +++ b/common/rfb/Region.cxx @@ -67,25 +67,6 @@ void rfb::Region::translate(const Point& delta) { pixman_region_translate(rgn, delta.x, delta.y); } -void rfb::Region::setOrderedRects(const std::vector& rects) { - clear(); - std::vector::const_iterator i; - for (i=rects.begin(); i != rects.end(); i++) - pixman_region_union_rect(rgn, rgn, i->tl.x, i->tl.y, i->width(), i->height()); -} - -void rfb::Region::setExtentsAndOrderedRects(const ShortRect* extents, - int nRects, const ShortRect* rects) -{ - clear(); - std::vector::const_iterator i; - for (int i = 0; i < nRects; i++) { - pixman_region_union_rect(rgn, rgn, rects[i].x1, rects[i].y1, - rects[i].x2 - rects[i].x1, - rects[i].y2 - rects[i].y1); - } -} - void rfb::Region::assign_intersect(const rfb::Region& r) { pixman_region_intersect(rgn, rgn, r.rgn); } diff --git a/common/rfb/Region.h b/common/rfb/Region.h index ef26aa7c..6ac3a75b 100644 --- a/common/rfb/Region.h +++ b/common/rfb/Region.h @@ -29,10 +29,6 @@ struct pixman_region16; namespace rfb { - struct ShortRect { - short x1, y1, x2, y2; - }; - class Region { public: // Create an empty region @@ -50,9 +46,6 @@ namespace rfb { void clear(); void reset(const Rect& r); void translate(const rfb::Point& delta); - void setOrderedRects(const std::vector& rects); - void setExtentsAndOrderedRects(const ShortRect* extents, int nRects, - const ShortRect* rects); void assign_intersect(const Region& r); void assign_union(const Region& r); diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index 6ab306b1..d05bf85b 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -150,9 +150,6 @@ void vncExtensionInit(void) if (vncGetScreenCount() > MAXSCREENS) vncFatalError("vncExtensionInit: too many screens"); - if (sizeof(ShortRect) != sizeof(struct UpdateRect)) - vncFatalError("vncExtensionInit: Incompatible ShortRect size"); - vncAddExtension(); vncSelectionInit(); @@ -372,25 +369,24 @@ void vncSetLEDState(unsigned long leds) desktop[scr]->setLEDState(state); } -void vncAddChanged(int scrIdx, const struct UpdateRect *extents, - int nRects, const struct UpdateRect *rects) +void vncAddChanged(int scrIdx, int nRects, + const struct UpdateRect *rects) { - Region reg; - - reg.setExtentsAndOrderedRects((const ShortRect*)extents, - nRects, (const ShortRect*)rects); - desktop[scrIdx]->add_changed(reg); + for (int i = 0;i < nRects;i++) { + desktop[scrIdx]->add_changed(Region(Rect(rects[i].x1, rects[i].y1, + rects[i].x2, rects[i].y2))); + } } -void vncAddCopied(int scrIdx, const struct UpdateRect *extents, - int nRects, const struct UpdateRect *rects, +void vncAddCopied(int scrIdx, int nRects, + const struct UpdateRect *rects, int dx, int dy) { - Region reg; - - reg.setExtentsAndOrderedRects((const ShortRect*)extents, - nRects, (const ShortRect*)rects); - desktop[scrIdx]->add_copied(reg, rfb::Point(dx, dy)); + for (int i = 0;i < nRects;i++) { + desktop[scrIdx]->add_copied(Region(Rect(rects[i].x1, rects[i].y1, + rects[i].x2, rects[i].y2)), + Point(dx, dy)); + } } void vncSetCursor(int width, int height, int hotX, int hotY, diff --git a/unix/xserver/hw/vnc/vncExtInit.h b/unix/xserver/hw/vnc/vncExtInit.h index 1fb87c19..23c0c669 100644 --- a/unix/xserver/hw/vnc/vncExtInit.h +++ b/unix/xserver/hw/vnc/vncExtInit.h @@ -73,10 +73,10 @@ struct UpdateRect { short x1, y1, x2, y2; }; -void vncAddChanged(int scrIdx, const struct UpdateRect *extents, - int nRects, const struct UpdateRect *rects); -void vncAddCopied(int scrIdx, const struct UpdateRect *extents, - int nRects, const struct UpdateRect *rects, +void vncAddChanged(int scrIdx, int nRects, + const struct UpdateRect *rects); +void vncAddCopied(int scrIdx, int nRects, + const struct UpdateRect *rects, int dx, int dy); void vncSetCursor(int width, int height, int hotX, int hotY, diff --git a/unix/xserver/hw/vnc/vncHooks.c b/unix/xserver/hw/vnc/vncHooks.c index f631941b..a8ab917b 100644 --- a/unix/xserver/hw/vnc/vncHooks.c +++ b/unix/xserver/hw/vnc/vncHooks.c @@ -340,7 +340,6 @@ static inline void add_changed(ScreenPtr pScreen, RegionPtr reg) if (RegionNil(reg)) return; vncAddChanged(pScreen->myNum, - (const struct UpdateRect*)RegionExtents(reg), RegionNumRects(reg), (const struct UpdateRect*)RegionRects(reg)); } @@ -354,7 +353,6 @@ static inline void add_copied(ScreenPtr pScreen, RegionPtr dst, if (RegionNil(dst)) return; vncAddCopied(pScreen->myNum, - (const struct UpdateRect*)RegionExtents(dst), RegionNumRects(dst), (const struct UpdateRect*)RegionRects(dst), dx, dy); }