From f97b5cb5864f348b7f4160d2031e35ff21054983 Mon Sep 17 00:00:00 2001 From: Adi Oanca Date: Tue, 28 Jun 2005 15:34:54 +0000 Subject: [PATCH] Moved CopyBits from ServerWindow to Layer. Also, made CopyBits code execute in RootLayer's thread git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13321 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/Layer.cpp | 85 ++++++++++++++++++++++++++++++++ src/servers/app/Layer.h | 23 ++++++--- src/servers/app/RootLayer.cpp | 16 ++++++ src/servers/app/ServerWindow.cpp | 56 +-------------------- src/servers/app/ServerWindow.h | 8 --- 5 files changed, 118 insertions(+), 70 deletions(-) diff --git a/src/servers/app/Layer.cpp b/src/servers/app/Layer.cpp index 4b32771545..eafebdb5e3 100644 --- a/src/servers/app/Layer.cpp +++ b/src/servers/app/Layer.cpp @@ -1660,6 +1660,91 @@ Layer::SetOverlayBitmap(const ServerBitmap* bitmap) fOverlayBitmap = bitmap; } +void +Layer::CopyBits(BRect& src, BRect& dst, int32 xOffset, int32 yOffset) { + + BPrivate::PortLink msg(-1, -1); + msg.StartMessage(AS_ROOTLAYER_LAYER_COPYBITS); + msg.Attach(this); + msg.Attach(src); + msg.Attach(dst); + msg.Attach(xOffset); + msg.Attach(yOffset); + GetRootLayer()->EnqueueMessage(msg); +} + +void +Layer::do_CopyBits(BRect& src, BRect& dst, int32 xOffset, int32 yOffset) { + // NOTE: The correct behaviour is this: + // * The region that is copied is the + // src rectangle, no matter if it fits + // into the dst rectangle. It is copied + // by the offset dst.LeftTop() - src.LeftTop() + // * The dst rectangle is used for invalidation: + // Any area in the dst rectangle that could + // not be copied from src (because either the + // src rectangle was not big enough, or because there + // were parts cut off by the current layer clipping), + // are triggering BView::Draw() to be called + // and for these parts only. + +#ifndef NEW_CLIPPING + + // the region that is going to be copied + BRegion copyRegion(src); + // apply the current clipping of the layer + + copyRegion.IntersectWith(&fVisible); + + // offset the region to the destination + // and apply the current clipping there as well + copyRegion.OffsetBy(xOffset, yOffset); + copyRegion.IntersectWith(&fVisible); + + // the region at the destination that needs invalidation + GetRootLayer()->fRedrawReg.Set(dst); + // exclude the region drawn by the copy operation + GetRootLayer()->fRedrawReg.Exclude(©Region); + // apply the current clipping as well + GetRootLayer()->fRedrawReg.IntersectWith(&fVisible); + + // move the region back for the actual operation + copyRegion.OffsetBy(-xOffset, -yOffset); + + GetDisplayDriver()->CopyRegion(©Region, xOffset, yOffset); + + // trigger the redraw + GetRootLayer()->RequestDraw(GetRootLayer()->fRedrawReg, NULL); +#else + // the region that is going to be copied + BRegion copyRegion(src); + // apply the current clipping of the layer + + copyRegion.IntersectWith(&fVisible2); + + // offset the region to the destination + // and apply the current clipping there as well + copyRegion.OffsetBy(xOffset, yOffset); + copyRegion.IntersectWith(&fVisible2); + + // the region at the destination that needs invalidation + GetRootLayer()->fRedrawReg.Set(dst); + // exclude the region drawn by the copy operation + GetRootLayer()->fRedrawReg.Exclude(©Region); + // apply the current clipping as well + GetRootLayer()->fRedrawReg.IntersectWith(&fVisible2); + + // move the region back for the actual operation + copyRegion.OffsetBy(-xOffset, -yOffset); + + GetDisplayDriver()->CopyRegion(©Region, xOffset, yOffset); + + // trigger the redraw + GetRootLayer()->RequestDraw(GetRootLayer()->fRedrawReg, NULL); +#endif + +} + #ifdef NEW_CLIPPING void diff --git a/src/servers/app/Layer.h b/src/servers/app/Layer.h index 78565e5a5f..89c9563532 100644 --- a/src/servers/app/Layer.h +++ b/src/servers/app/Layer.h @@ -41,7 +41,7 @@ #include "RGBColor.h" #include "ServerWindow.h" -#define NEW_CLIPPING 1 +//#define NEW_CLIPPING 1 enum { B_LAYER_NONE = 1, @@ -208,6 +208,10 @@ class Layer { void SetOverlayBitmap(const ServerBitmap* bitmap); inline const ServerBitmap* OverlayBitmap() const { return fOverlayBitmap; } + + void CopyBits(BRect& src, BRect& dst, + int32 xOffset, int32 yOffset); + #ifdef NEW_CLIPPING inline const BRegion& VisibleRegion() const { return fVisible2; } inline const BRegion& FullVisible() const { return fFullVisible2; } @@ -247,19 +251,22 @@ class Layer { void do_Redraw( const BRegion &invalid, const Layer *startFrom = NULL); - void rebuild_visible_regions(const BRegion &invalid, + void rebuild_visible_regions(const BRegion &invalid, const BRegion &parentLocalVisible, const Layer *startFrom); - virtual bool alter_visible_for_children(BRegion ®ion); - virtual void get_user_regions(BRegion ®); + virtual bool alter_visible_for_children(BRegion ®ion); + virtual void get_user_regions(BRegion ®); - void clear_visible_regions(); - void resize_layer_frame_by(float x, float y); - void rezize_layer_redraw_more(BRegion ®, float dx, float dy); - void resize_layer_full_update_on_resize(BRegion ®, float dx, float dy); + void clear_visible_regions(); + void resize_layer_frame_by(float x, float y); + void rezize_layer_redraw_more(BRegion ®, float dx, float dy); + void resize_layer_full_update_on_resize(BRegion ®, float dx, float dy); #endif + private: + void do_CopyBits(BRect& src, BRect& dst, + int32 xOffset, int32 yOffset); protected: friend class RootLayer; diff --git a/src/servers/app/RootLayer.cpp b/src/servers/app/RootLayer.cpp index ea3ab8046c..060701e300 100644 --- a/src/servers/app/RootLayer.cpp +++ b/src/servers/app/RootLayer.cpp @@ -355,6 +355,22 @@ RootLayer::WorkingThread(void *data) #endif break; } + case AS_ROOTLAYER_LAYER_COPYBITS: + { + Layer *layer = NULL; + int32 xOffset, yOffset; + BRect src, dst; + messageQueue.Read(&layer); + messageQueue.Read(&src); + messageQueue.Read(&dst); + messageQueue.Read(&xOffset); + messageQueue.Read(&yOffset); + + layer->do_CopyBits(src, dst, xOffset, yOffset); + + break; + } + case AS_ROOTLAYER_ADD_TO_SUBSET: { WinBorder *winBorder = NULL; diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index b8d359fe32..981c4c2125 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -435,7 +435,7 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fCurrentLayer->fLayerData->OffsetOrigin(BPoint(dh, dv)); - _CopyBits(myRootLayer, fCurrentLayer, src, dst, xOffset, yOffset); + fCurrentLayer->CopyBits(src, dst, xOffset, yOffset); #else fCurrentLayer->ScrollBy(dh, dv); #endif @@ -457,7 +457,7 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) int32 xOffset = (int32)(dst.left - src.left); int32 yOffset = (int32)(dst.top - src.top); - _CopyBits(myRootLayer, fCurrentLayer, src, dst, xOffset, yOffset); + fCurrentLayer->CopyBits(src, dst, xOffset, yOffset); break; } @@ -2095,58 +2095,6 @@ ServerWindow::_MessageLooper() } } -// _CopyBits -void -ServerWindow::_CopyBits(RootLayer* rootLayer, Layer* layer, - BRect& src, BRect& dst, - int32 xOffset, int32 yOffset) const -{ - // NOTE: The correct behaviour is this: - // * The region that is copied is the - // src rectangle, no matter if it fits - // into the dst rectangle. It is copied - // by the offset dst.LeftTop() - src.LeftTop() - // * The dst rectangle is used for invalidation: - // Any area in the dst rectangle that could - // not be copied from src (because either the - // src rectangle was not big enough, or because there - // were parts cut off by the current layer clipping), - // are triggering BView::Draw() to be called - // and for these parts only. - -#ifndef NEW_CLIPPING - - // the region that is going to be copied - BRegion copyRegion(src); - // apply the current clipping of the layer - - copyRegion.IntersectWith(&layer->fVisible); - - // offset the region to the destination - // and apply the current clipping there as well - copyRegion.OffsetBy(xOffset, yOffset); - copyRegion.IntersectWith(&layer->fVisible); - - // the region at the destination that needs invalidation - BRegion invalidRegion(dst); - // exclude the region drawn by the copy operation - invalidRegion.Exclude(©Region); - // apply the current clipping as well - invalidRegion.IntersectWith(&layer->fVisible); - - // move the region back for the actual operation - copyRegion.OffsetBy(-xOffset, -yOffset); - - layer->GetDisplayDriver()->CopyRegion(©Region, xOffset, yOffset); - - // trigger the redraw -// rootLayer->GoRedraw(fWinBorder, invalidRegion); -rootLayer->RequestDraw(invalidRegion, fWinBorder); - -#endif -} - - void ServerWindow::SendMessageToClient(const BMessage* msg, int32 target, bool usePreferred) const { diff --git a/src/servers/app/ServerWindow.h b/src/servers/app/ServerWindow.h index 6a6ff850df..e1673f2c6a 100644 --- a/src/servers/app/ServerWindow.h +++ b/src/servers/app/ServerWindow.h @@ -113,14 +113,6 @@ private: static int32 _message_thread(void *_window); - // used by CopyBits and Scrolling - void _CopyBits(RootLayer* rootLayer, - Layer* layer, - BRect& copy, - BRect& dirty, - int32 xOffset, int32 yOffset) const; - - // TODO: Move me elsewhere status_t PictureToRegion(ServerPicture *picture, BRegion &,