- simplified a little the update code/process.

- moved part of the update code from Layer to WinBorder. Fits better
there.
- renamed a couple members.
- some cleanup.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13273 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca 2005-06-25 13:09:19 +00:00
parent b62270533e
commit e603410b82
6 changed files with 163 additions and 166 deletions

View File

@ -1316,47 +1316,126 @@ Layer::PrintTree()
printf("\t%s\t%s\n", lay->Name(), lay->IsHidden()? "Hidden": "NOT hidden"); printf("\t%s\t%s\n", lay->Name(), lay->IsHidden()? "Hidden": "NOT hidden");
} }
// UpdateStart // RequestDraw
void void
Layer::UpdateStart() Layer::RequestDraw(const BRegion &reg, Layer *startFrom)
{ {
// During updates we only want to draw what's in the update region STRACE(("Layer(%s)::RequestDraw()\n", Name()));
if (fClassID == AS_WINBORDER_CLASS) {
// NOTE: don't worry, RooLayer is locked here.
WinBorder *wb = (WinBorder*)this;
wb->fInUpdate = true;
wb->fRequestSent = false;
wb->yUpdateReg = wb->fUpdateReg;
wb->fUpdateReg.MakeEmpty();
wb->cnt--;
if (wb->cnt != 0)
CRITICAL("Layer::UpdateStart(): wb->cnt != 0 -> Not Allowed!");
}
}
// UpdateEnd
void
Layer::UpdateEnd()
{
// The usual case. Drawing is permitted in the whole visible area.
if (fClassID == AS_WINBORDER_CLASS) {
WinBorder *wb = (WinBorder*)this;
wb->yUpdateReg.MakeEmpty();
wb->fInUpdate = false;
if (wb->zUpdateReg.CountRects() > 0) {
BRegion reg(wb->zUpdateReg);
wb->RequestDraw(reg, NULL);
}
}
}
// do not redraw any child until you must
int redraw = false;
if (!startFrom)
redraw = true;
#ifndef NEW_CLIPPING #ifndef NEW_CLIPPING
if (HasClient() && IsTopLayer()) {
// calculate the minimum region/rectangle to be updated with
// a single message to the client.
BRegion updateReg(fFullVisible);
if (fFlags & B_FULL_UPDATE_ON_RESIZE
&& fFrameAction == B_LAYER_ACTION_RESIZE)
{
// do nothing
} else {
updateReg.IntersectWith(&reg);
}
if (updateReg.CountRects() > 0) {
fOwner->fCumulativeRegion.Include(&updateReg);
if (!fOwner->InUpdate() && !fOwner->fRequestSent) {
fOwner->fInUpdateRegion = fOwner->fCumulativeRegion;
fOwner->cnt++;
if (fOwner->cnt != 1)
CRITICAL("Layer::RequestDraw(): fOwner->cnt != 1 -> Not Allowed!");
fOwner->fCumulativeRegion.MakeEmpty();
fOwner->fRequestSent = true;
SendUpdateMsg(fOwner->fInUpdateRegion);
}
}
}
if (fVisible.CountRects() > 0) {
BRegion updateReg(fVisible);
// calculate the update region
if (fFlags & B_FULL_UPDATE_ON_RESIZE && fFrameAction == B_LAYER_ACTION_RESIZE) {
// do nothing
} else {
updateReg.IntersectWith(&reg);
}
if (updateReg.CountRects() > 0) {
fDriver->ConstrainClippingRegion(&updateReg);
Draw(updateReg.Frame());
fDriver->ConstrainClippingRegion(NULL);
}
}
for (Layer *lay = BottomChild(); lay != NULL; lay = UpperSibling()) {
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->fFullVisible);
common.IntersectWith(&reg);
if (common.CountRects() > 0)
lay->RequestDraw(reg, NULL);
}
}
#else
if (HasClient() && IsTopLayer()) {
// calculate the minimum region/rectangle to be updated with
// a single message to the client.
BRegion updateReg(fFullVisible2);
updateReg.IntersectWith(&reg);
if (updateReg.CountRects() > 0) {
fOwner->fCumulativeRegion.Include(&updateReg);
if (!fOwner->InUpdate() && !fOwner->fRequestSent) {
fOwner->fInUpdateRegion = fOwner->fCumulativeRegion;
fOwner->cnt++;
if (fOwner->cnt != 1)
CRITICAL("Layer::RequestDraw(): fOwner->cnt != 1 -> Not Allowed!");
fOwner->fCumulativeRegion.MakeEmpty();
fOwner->fRequestSent = true;
printf("Send\n");
SendUpdateMsg(fOwner->fInUpdateRegion);
}
}
}
if (fVisible2.CountRects() > 0) {
BRegion updateReg(fVisible2);
updateReg.IntersectWith(&reg);
if (updateReg.CountRects() > 0) {
fDriver->ConstrainClippingRegion(&updateReg);
Draw(updateReg.Frame());
fDriver->ConstrainClippingRegion(NULL);
}
}
for (Layer *lay = BottomChild(); lay != NULL; lay = UpperSibling()) {
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(&reg);
if (common.CountRects() > 0)
lay->RequestDraw(reg, NULL);
}
}
#endif
}
#ifndef NEW_CLIPPING
// move_layer // move_layer
void void
@ -1364,9 +1443,9 @@ Layer::move_layer(float x, float y)
{ {
/* if (fClassID == AS_WINBORDER_CLASS) { /* if (fClassID == AS_WINBORDER_CLASS) {
WinBorder *wb = (WinBorder*)this; WinBorder *wb = (WinBorder*)this;
wb->zUpdateReg.OffsetBy(x, y); wb->fCumulativeRegion.OffsetBy(x, y);
wb->yUpdateReg.OffsetBy(x, y); wb->fInUpdateRegion.OffsetBy(x, y);
wb->fUpdateReg.OffsetBy(x, y); wb->fSavedForUpdateRegion.OffsetBy(x, y);
}*/ }*/
fFrameAction = B_LAYER_ACTION_MOVE; fFrameAction = B_LAYER_ACTION_MOVE;
@ -1473,119 +1552,6 @@ Layer::Invalidate(const BRegion& region)
#endif // 5 methods #endif // 5 methods
// RequestDraw
void
Layer::RequestDraw(const BRegion &reg, Layer *startFrom)
{
STRACE(("Layer(%s)::RequestDraw()\n", Name()));
//printf("Layer(%s)::RequestDraw()\n", Name());
//if (fClassID == AS_ROOTLAYER_CLASS)
// debugger("z");
// 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.
#ifndef NEW_CLIPPING
BRegion updateReg(fFullVisible);
#else
BRegion updateReg(fFullVisible2);
#endif
if (fFlags & B_FULL_UPDATE_ON_RESIZE
#ifndef NEW_CLIPPING
&& fFrameAction == B_LAYER_ACTION_RESIZE
#endif
)
{
// do nothing
} else {
updateReg.IntersectWith(&reg);
}
if (updateReg.CountRects() > 0) {
fOwner->zUpdateReg.Include(&updateReg);
if (!fOwner->fInUpdate && !fOwner->fRequestSent) {
fOwner->fUpdateReg = fOwner->zUpdateReg;
fOwner->cnt++;
if (fOwner->cnt != 1)
CRITICAL("Layer::RequestDraw(): fOwner->cnt != 1 -> Not Allowed!");
fOwner->zUpdateReg.MakeEmpty();
SendUpdateMsg(fOwner->fUpdateReg);
fOwner->fRequestSent = true;
}
}
}
#ifndef NEW_CLIPPING
if (fVisible.CountRects() > 0) {
BRegion updateReg(fVisible);
// calculate the update region
if (fFlags & B_FULL_UPDATE_ON_RESIZE && fFrameAction == B_LAYER_ACTION_RESIZE) {
// do nothing
} else {
updateReg.IntersectWith(&reg);
}
if (updateReg.CountRects() > 0) {
fDriver->ConstrainClippingRegion(&updateReg);
Draw(updateReg.Frame());
fDriver->ConstrainClippingRegion(NULL);
}
}
for (Layer *lay = BottomChild(); lay != NULL; lay = UpperSibling()) {
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->fFullVisible);
common.IntersectWith(&reg);
if (common.CountRects() > 0)
lay->RequestDraw(reg, NULL);
}
}
#else
if (fVisible2.CountRects() > 0) {
BRegion updateReg(fVisible2);
// calculate the update region
if (fFlags & B_FULL_UPDATE_ON_RESIZE
// TODO: must be replaced!
// && fFrameAction == B_LAYER_ACTION_RESIZE
) {
// do nothing
} else {
updateReg.IntersectWith(&reg);
}
if (updateReg.CountRects() > 0) {
fDriver->ConstrainClippingRegion(&updateReg);
Draw(updateReg.Frame());
fDriver->ConstrainClippingRegion(NULL);
}
}
for (Layer *lay = BottomChild(); lay != NULL; lay = UpperSibling()) {
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(&reg);
if (common.CountRects() > 0)
lay->RequestDraw(reg, NULL);
}
}
#endif
}
/*! /*!
\brief Returns the layer's ServerWindow \brief Returns the layer's ServerWindow

View File

@ -189,9 +189,6 @@ class Layer {
bool IsTopLayer() const bool IsTopLayer() const
{ return fIsTopLayer; } { return fIsTopLayer; }
void UpdateStart();
void UpdateEnd();
BRegion* ClippingRegion() const BRegion* ClippingRegion() const
{ return fClipReg; } { return fClipReg; }

View File

@ -288,6 +288,7 @@ RootLayer::WorkingThread(void *data)
} }
case AS_ROOTLAYER_DO_INVALIDATE: case AS_ROOTLAYER_DO_INVALIDATE:
{ {
//printf("Adi: new message\n");
BRegion invalidRegion; BRegion invalidRegion;
Layer *layer = NULL; Layer *layer = NULL;
messageQueue.Read<Layer*>(&layer); messageQueue.Read<Layer*>(&layer);
@ -399,7 +400,6 @@ RootLayer::GoInvalidate(const Layer *layer, const BRegion &region)
{ {
BPrivate::PortLink msg(fListenPort, -1); BPrivate::PortLink msg(fListenPort, -1);
msg.StartMessage(AS_ROOTLAYER_DO_INVALIDATE); msg.StartMessage(AS_ROOTLAYER_DO_INVALIDATE);
//debugger("y");
msg.Attach<const Layer*>(layer); msg.Attach<const Layer*>(layer);
msg.AttachRegion(region); msg.AttachRegion(region);
msg.Flush(); msg.Flush();

View File

@ -1461,8 +1461,8 @@ ServerWindow::_DispatchGraphicsMessage(int32 code, BPrivate::LinkReceiver &link)
(fCurrentLayer->fVisible) (fCurrentLayer->fVisible)
#endif #endif
; ;
if (fWinBorder->fInUpdate) if (fWinBorder->InUpdate())
rreg.IntersectWith(&fWinBorder->yUpdateReg); rreg.IntersectWith(&fWinBorder->RegionToBeUpdated());
gDesktop->GetDisplayDriver()->ConstrainClippingRegion(&rreg); gDesktop->GetDisplayDriver()->ConstrainClippingRegion(&rreg);
// rgb_color rrr = fCurrentLayer->fLayerData->viewcolor.GetColor32(); // rgb_color rrr = fCurrentLayer->fLayerData->viewcolor.GetColor32();

View File

@ -69,9 +69,8 @@ WinBorder::WinBorder(const BRect &r,
fDecorator(NULL), fDecorator(NULL),
fTopLayer(NULL), fTopLayer(NULL),
zUpdateReg(), fCumulativeRegion(),
yUpdateReg(), fInUpdateRegion(),
fUpdateReg(),
fMouseButtons(0), fMouseButtons(0),
fKeyModifiers(0), fKeyModifiers(0),
@ -182,9 +181,8 @@ y = (float)int32(y);
// NOTE: I moved this here from Layer::move_layer() // NOTE: I moved this here from Layer::move_layer()
// Should this have any bad consequences I'm not aware of? // Should this have any bad consequences I'm not aware of?
zUpdateReg.OffsetBy(x, y); fCumulativeRegion.OffsetBy(x, y);
yUpdateReg.OffsetBy(x, y); fInUpdateRegion.OffsetBy(x, y);
fUpdateReg.OffsetBy(x, y);
if (IsHidden()) { if (IsHidden()) {
// TODO: This is a work around for a design issue: // TODO: This is a work around for a design issue:
@ -280,6 +278,35 @@ y = (float)int32(y);
} }
} }
// UpdateStart
void
WinBorder::UpdateStart()
{
// During updates we only want to draw what's in the update region
fInUpdate = true;
fRequestSent = false;
cnt--;
if (cnt != 0)
CRITICAL("Layer::UpdateStart(): wb->cnt != 0 -> Not Allowed!");
}
// UpdateEnd
void
WinBorder::UpdateEnd()
{
// The usual case. Drawing is permitted in the whole visible area.
fInUpdate = false;
fInUpdateRegion.MakeEmpty();
if (fCumulativeRegion.CountRects() > 0) {
BRegion reg(fCumulativeRegion);
RequestDraw(reg, NULL);
}
}
#ifndef NEW_CLIPPING #ifndef NEW_CLIPPING
//! Rebuilds the WinBorder's "fully-visible" region based on info from the decorator //! Rebuilds the WinBorder's "fully-visible" region based on info from the decorator

View File

@ -66,6 +66,14 @@ class WinBorder : public Layer {
#ifndef NEW_CLIPPING #ifndef NEW_CLIPPING
virtual void RebuildFullRegion(); virtual void RebuildFullRegion();
#endif #endif
void UpdateStart();
void UpdateEnd();
inline bool InUpdate() const
{ return fInUpdate; }
inline const BRegion& RegionToBeUpdated() const
{ return fInUpdateRegion; }
void SetSizeLimits(float minWidth, void SetSizeLimits(float minWidth,
float maxWidth, float maxWidth,
float minHeight, float minHeight,
@ -132,9 +140,8 @@ class WinBorder : public Layer {
Decorator* fDecorator; Decorator* fDecorator;
Layer* fTopLayer; Layer* fTopLayer;
BRegion zUpdateReg; BRegion fCumulativeRegion;
BRegion yUpdateReg; BRegion fInUpdateRegion;
BRegion fUpdateReg;
int32 fMouseButtons; int32 fMouseButtons;
int32 fKeyModifiers; int32 fKeyModifiers;