From d4e4f29a420718c8ec346f37c84377c5638195bb Mon Sep 17 00:00:00 2001 From: Adi Oanca Date: Mon, 7 Nov 2005 21:24:53 +0000 Subject: [PATCH] Cleanup after the old clipping code. Removed a few methods as others took their place. More cleanup to follow on tomorrow. :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14764 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/Layer.cpp | 182 ++++++++++--------------------- src/servers/app/Layer.h | 9 -- src/servers/app/RootLayer.h | 8 +- src/servers/app/ServerWindow.cpp | 6 - src/servers/app/WinBorder.cpp | 18 ++- src/servers/app/WinBorder.h | 3 +- 6 files changed, 77 insertions(+), 149 deletions(-) diff --git a/src/servers/app/Layer.cpp b/src/servers/app/Layer.cpp index d97301b605..dcab577a2a 100644 --- a/src/servers/app/Layer.cpp +++ b/src/servers/app/Layer.cpp @@ -441,23 +441,6 @@ Layer::SetFlags(uint32 flags) fDrawState->SetSubPixelPrecise(fFlags & B_SUBPIXEL_PRECISE); } -// Redraw -void -Layer::Redraw(const BRegion& reg, Layer *startFrom) -{ - STRACE(("Layer(%s)::Redraw();\n", Name())); - if (IsHidden()) - // this layer has nothing visible on screen, so bail out. - return; - - BRegion *pReg = const_cast(®); - - if (pReg->CountRects() > 0) - RequestDraw(reg, startFrom); - - STRACE(("Layer(%s)::Redraw() ENDED\n", Name())); -} - // Draw void Layer::Draw(const BRect &rect) @@ -945,70 +928,6 @@ Layer::PrintTree() printf("\t%s\t%s\n", lay->Name(), lay->IsHidden()? "Hidden": "NOT hidden"); } -// RequestDraw -void -Layer::RequestDraw(const BRegion ®, Layer *startFrom) -{ - STRACE(("Layer(%s)::RequestDraw()\n", Name())); - - // do not redraw any child until you must - int redraw = false; - if (!startFrom) - redraw = true; - - if (HasClient() && IsTopLayer()) { - // calculate the minimum region/rectangle to be updated with - // a single message to the client. - BRegion updateReg(fFullVisible2); - - updateReg.IntersectWith(®); - - if (updateReg.CountRects() > 0) { - fOwner->fCumulativeRegion.Include(&updateReg); - if (fOwner->fUpdateRequestsEnabled && !fOwner->InUpdate() && !fOwner->fRequestSent) { - fOwner->fInUpdateRegion = fOwner->fCumulativeRegion; -fOwner->cnt++; -if (fOwner->cnt != 1) - CRITICAL("Layer::RequestDraw(): fOwner->cnt != 1 -> Not Allowed!"); - fOwner->fRequestSent = true; // this is here to avoid a possible de-synchronization - if (SendUpdateMsg(fOwner->fInUpdateRegion) == B_OK) { - fOwner->fCumulativeRegion.MakeEmpty(); - } - else { - fOwner->fRequestSent = false; - fOwner->fInUpdateRegion.MakeEmpty(); - } - } - } - } - - if (fVisible2.CountRects() > 0) { - BRegion updateReg(fVisible2); - updateReg.IntersectWith(®); - - if (updateReg.CountRects() > 0) { - fDriver->ConstrainClippingRegion(&updateReg); - Draw(updateReg.Frame()); - fDriver->ConstrainClippingRegion(NULL); - } - } - - for (Layer *lay = LastChild(); lay != NULL; lay = PreviousChild()) { - if (lay == startFrom) - redraw = true; - - if (redraw && !(lay->IsHidden())) { - // no need to go deeper if not even the FullVisible region intersects - // Update one. - BRegion common(lay->fFullVisible2); - common.IntersectWith(®); - - if (common.CountRects() > 0) - lay->RequestDraw(reg, NULL); - } - } -} - /*! \brief Returns the layer's ServerWindow @@ -1034,7 +953,6 @@ Layer::SendUpdateMsg(BRegion& reg) ConvertFromScreen2(&rect); msg.AddRect("_rect", rect ); msg.AddRect("debug_rect", reg.Frame()); -// msg.AddInt32("_token",fViewToken); return Owner()->Window()->SendMessageToClient(&msg); } @@ -1127,12 +1045,12 @@ Layer::do_CopyBits(BRect& src, BRect& dst, int32 xOffset, int32 yOffset) { copyRegion.IntersectWith(&fVisible2); // the region at the destination that needs invalidation - GetRootLayer()->fRedrawReg.Set(dst); + BRegion redrawReg(dst); // exclude the region drawn by the copy operation // TODO: quick fix for our scrolling problem. FIX THIS! -// GetRootLayer()->fRedrawReg.Exclude(©Region); +// redrawReg.Exclude(©Region); // apply the current clipping as well - GetRootLayer()->fRedrawReg.IntersectWith(&fVisible2); + redrawReg.IntersectWith(&fVisible2); // move the region back for the actual operation copyRegion.OffsetBy(-xOffset, -yOffset); @@ -1140,7 +1058,8 @@ Layer::do_CopyBits(BRect& src, BRect& dst, int32 xOffset, int32 yOffset) { GetDrawingEngine()->CopyRegion(©Region, xOffset, yOffset); // trigger the redraw - GetRootLayer()->RequestDraw(GetRootLayer()->fRedrawReg, NULL); + GetRootLayer()->MarkForRedraw(redrawReg); + GetRootLayer()->TriggerRedraw(); } void @@ -1513,9 +1432,8 @@ Layer::do_ResizeBy(float dx, float dy) GetWantedRegion(invalid); invalid.Include(&fFullVisible2); - clear_visible_regions(); - - fParent->do_RebuildVisibleRegions(invalid, this); + fParent->MarkForRebuild(invalid); + fParent->TriggerRebuild(); // done rebuilding regions, now redraw regions that became visible @@ -1535,19 +1453,16 @@ Layer::do_ResizeBy(float dx, float dy) // layers that had their frame modified must be entirely redrawn. rezize_layer_redraw_more(redrawReg, dx, dy); - // add redrawReg to our RootLayer's redraw region. -// GetRootLayer()->fRedrawReg.Include(&redrawReg); - GetRootLayer()->fRedrawReg = redrawReg; // include layer's visible region in case we want a full update on resize if (fFlags & B_FULL_UPDATE_ON_RESIZE && fVisible2.Frame().IsValid()) { - resize_layer_full_update_on_resize(GetRootLayer()->fRedrawReg, dx, dy); + resize_layer_full_update_on_resize(redrawReg, dx, dy); - GetRootLayer()->fRedrawReg.Include(&fVisible2); - GetRootLayer()->fRedrawReg.Include(&oldVisible); + redrawReg.Include(&fVisible2); + redrawReg.Include(&oldVisible); } - // clear canvas and set invalid regions for affected WinBorders - GetRootLayer()->RequestDraw(GetRootLayer()->fRedrawReg, NULL); -// GetRootLayer()->RequestRedraw(); // TODO: what if we pass (fParent, startFromTHIS, &redrawReg)? + + GetRootLayer()->MarkForRedraw(redrawReg); + GetRootLayer()->TriggerRedraw(); } SendViewCoordUpdateMsg(); @@ -1572,9 +1487,8 @@ void Layer::do_MoveBy(float dx, float dy) GetWantedRegion(invalid); invalid.Include(&fFullVisible2); - clear_visible_regions(); - - fParent->do_RebuildVisibleRegions(invalid, this); + fParent->MarkForRebuild(invalid); + fParent->TriggerRebuild(); // done rebuilding regions, now copy common parts and redraw regions that became visible @@ -1596,11 +1510,8 @@ void Layer::do_MoveBy(float dx, float dy) oldFullVisible.OffsetBy(-dx, -dy); GetDrawingEngine()->CopyRegion(&oldFullVisible, dx, dy); - // add redrawReg to our RootLayer's redraw region. -// GetRootLayer()->fRedrawReg.Include(&redrawReg); - GetRootLayer()->fRedrawReg = redrawReg; - GetRootLayer()->RequestDraw(GetRootLayer()->fRedrawReg, NULL); -// GetRootLayer()->RequestRedraw(); // TODO: what if we pass (fParent, startFromTHIS, &redrawReg)? + GetRootLayer()->MarkForRedraw(redrawReg); + GetRootLayer()->TriggerRedraw(); } SendViewCoordUpdateMsg(); @@ -1610,15 +1521,14 @@ void Layer::do_ScrollBy(float dx, float dy) { fDrawState->OffsetOrigin(BPoint(dx, dy)); -// fOrigin.Set(fOrigin.x + dx, fOrigin.y + dy); if (!IsHidden() && GetRootLayer()) { // set the region to be invalidated. BRegion invalid(fFullVisible2); - clear_visible_regions(); + MarkForRebuild(invalid); - rebuild_visible_regions(invalid, invalid, LastChild()); + TriggerRebuild(); // for the moment we say that the whole surface needs to be redraw. BRegion redrawReg(fFullVisible2); @@ -1636,10 +1546,8 @@ Layer::do_ScrollBy(float dx, float dy) // TODO: a quick fix for the scrolling problem!!! FIX THIS! // redrawReg.Exclude(&invalid); -// GetRootLayer()->fRedrawReg.Include(&redrawReg); - GetRootLayer()->fRedrawReg = redrawReg; - GetRootLayer()->RequestDraw(GetRootLayer()->fRedrawReg, NULL); -// GetRootLayer()->RequestRedraw(); // TODO: what if we pass (fParent, startFromTHIS, &redrawReg)? + GetRootLayer()->MarkForRedraw(redrawReg); + GetRootLayer()->TriggerRedraw(); } if (dx != 0.0f || dy != 0.0f) @@ -1677,19 +1585,12 @@ Layer::GetWantedRegion(BRegion ®) } } -void -Layer::do_RebuildVisibleRegions(const BRegion &invalid, const Layer *startFrom) -{ - BRegion localVisible(fFullVisible2); - localVisible.IntersectWith(&invalid); - rebuild_visible_regions(invalid, localVisible, startFrom); -} - void Layer::rebuild_visible_regions(const BRegion &invalid, const BRegion &parentLocalVisible, const Layer *startFrom) { +/* // no point in continuing if this layer is hidden. if (fHidden) return; @@ -1735,6 +1636,43 @@ Layer::rebuild_visible_regions(const BRegion &invalid, common.Exclude(&lay->fFullVisible2); } + // include what's left after all children took what they could. + fVisible2.Include(&common); +*/ + +// NOTE: I modified this method for the moment because of some issues that I have +// with the new public methods that I recently introduced. +// This code works very well, the single problem that it has it's that it +// rebuilds all the visible regions of its descendants. +// TODO: only rebuild what's needed. See above code. +// NOTE2: this does not affect the redrawing code. + + // no point in continuing if this layer is hidden. + if (fHidden) + return; + + // no need to go deeper if the parent doesn't have a visible region anymore + if (!parentLocalVisible.Frame().IsValid()) + return; + + BRegion common; + GetWantedRegion(common); + + // see how much you can take + common.IntersectWith(&parentLocalVisible); + fFullVisible2 = common; + fVisible2.MakeEmpty(); + + // allow this layer to hide some parts from its children + _ReserveRegions(common); + + for (Layer *lay = LastChild(); lay; lay = PreviousChild()) { + lay->rebuild_visible_regions(invalid, common, lay->LastChild()); + + // to let children know much they can take from parent's visible region + common.Exclude(&lay->fFullVisible2); + } + // include what's left after all children took what they could. fVisible2.Include(&common); } @@ -1780,7 +1718,7 @@ Layer::TriggerRebuild() // localFullVisible.IntersectWith(&totalInvalidReg); -// clear_visible_regions(); + clear_visible_regions(); rebuild_visible_regions(totalInvalidReg, localFullVisible, LastChild()); } diff --git a/src/servers/app/Layer.h b/src/servers/app/Layer.h index 90c6ed0ec0..f4f8069930 100644 --- a/src/servers/app/Layer.h +++ b/src/servers/app/Layer.h @@ -26,8 +26,6 @@ #include "RGBColor.h" #include "ServerWindow.h" -#define NEW_CLIPPING 1 - enum { B_LAYER_NONE = 1, B_LAYER_MOVE = 2, @@ -103,9 +101,6 @@ class Layer { inline uint32 Flags() const { return fFlags; } - void Redraw(const BRegion& reg, - Layer* startFrom = NULL); - virtual void Draw(const BRect& r); void Show(bool invalidate = true); @@ -254,8 +249,6 @@ class Layer { private: void do_Hide(); void do_Show(); - void do_RebuildVisibleRegions(const BRegion &invalid, - const Layer *startFrom); void do_MoveBy(float dx, float dy); void do_ResizeBy(float dx, float dy); void do_ScrollBy(float dx, float dy); @@ -320,8 +313,6 @@ class Layer { RootLayer* fRootLayer; private: - void RequestDraw(const BRegion& reg, - Layer* startFrom); ServerWindow* SearchForServerWindow(); status_t SendUpdateMsg(BRegion& reg); diff --git a/src/servers/app/RootLayer.h b/src/servers/app/RootLayer.h index 96c8156584..1184ac80b6 100644 --- a/src/servers/app/RootLayer.h +++ b/src/servers/app/RootLayer.h @@ -126,10 +126,10 @@ public: virtual void Draw(const BRect &r); thread_id LockingThread() { return fAllRegionsLock.LockingThread(); } - - BRegion fRedrawReg; - BList fCopyRegList; - BList fCopyList; + +// BRegion fRedrawReg; +// BList fCopyRegList; +// BList fCopyList; private: friend class Desktop; diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 2fc936816b..1ddbf96874 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -1160,8 +1160,6 @@ if (myRootLayer) myRootLayer->MarkForRedraw(invalidReg); myRootLayer->TriggerRedraw(); - -// myRootLayer->GoRedraw(fCurrentLayer, invalReg); } break; @@ -1229,10 +1227,6 @@ if (myRootLayer) { STRACE(("ServerWindow %s: Message Enable_Updates unimplemented\n", Title())); fWinBorder->EnableUpdateRequests(); - if (fWinBorder->CulmulatedUpdateRegion().Frame().IsValid()) { - BRegion reg(fWinBorder->CulmulatedUpdateRegion()); - fWinBorder->RequestDraw(reg, NULL); - } break; } case AS_DISABLE_UPDATES: diff --git a/src/servers/app/WinBorder.cpp b/src/servers/app/WinBorder.cpp index 96f5dcf133..1c1724cc3b 100644 --- a/src/servers/app/WinBorder.cpp +++ b/src/servers/app/WinBorder.cpp @@ -269,8 +269,18 @@ WinBorder::UpdateEnd() fInUpdateRegion.MakeEmpty(); if (fCumulativeRegion.CountRects() > 0) { - BRegion reg(fCumulativeRegion); - RequestDraw(reg, NULL); + GetRootLayer()->MarkForRedraw(fCumulativeRegion); + GetRootLayer()->TriggerRedraw(); +// RequestDraw(reg, NULL); + } +} +void +WinBorder::EnableUpdateRequests() { + fUpdateRequestsEnabled = true; + if (fCumulativeRegion.CountRects() > 0) { + GetRootLayer()->MarkForRedraw(fCumulativeRegion); + GetRootLayer()->TriggerRedraw(); +// RequestDraw(reg, NULL); } } @@ -754,11 +764,7 @@ void WinBorder::GetWantedRegion(BRegion ®) { if (fRebuildDecRegion) - { set_decorator_region(Bounds()); - // TODO? the decorator should be in WinBorder coordinates?? It's easier not to. - //ConvertToScreen2(&fDecRegion); - } BRect screenFrame(Bounds()); ConvertToScreen2(&screenFrame); diff --git a/src/servers/app/WinBorder.h b/src/servers/app/WinBorder.h index 62c24a1123..403213186e 100644 --- a/src/servers/app/WinBorder.h +++ b/src/servers/app/WinBorder.h @@ -68,8 +68,7 @@ class WinBorder : public Layer { { return fInUpdateRegion; } inline const BRegion& CulmulatedUpdateRegion() const { return fCumulativeRegion; } - inline void EnableUpdateRequests() - { fUpdateRequestsEnabled = true; } + void EnableUpdateRequests(); inline void DisableUpdateRequests() { fUpdateRequestsEnabled = false; }