added 1 changeset to branch 'refs/remotes/looncraz-github/compositing' old head: b116ed34dedcb58109c04a168b73fe29c7e5035f new head: 210b7c49ad0e1e483600b6a1298b4e4545b9deea ---------------------------------------------------------------------------- 210b7c4: BCompositeOverlay initialization app_server now handles initialization of BCompositeOverlay's server-side counter-part and the PortLink is initiated (I'm guessing properly). Still have to manage the remainder of the life cycle... PS: if you're wondering why all this work is going into a client version of CompositeOverlay, it is because I have no intentions on making even more app_server add-ons. It is my desire that a special server with frame-buffer access will be used to house user decorators, overlays, and effects. As in an app_addon_server. [ looncraz <looncraz@xxxxxxxxxxx> ] ---------------------------------------------------------------------------- Commit: 210b7c49ad0e1e483600b6a1298b4e4545b9deea Author: looncraz <looncraz@xxxxxxxxxxx> Date: Wed Apr 25 23:33:16 2012 UTC ---------------------------------------------------------------------------- 6 files changed, 192 insertions(+), 52 deletions(-) headers/os/interface/CompositeOverlay.h | 14 +- headers/private/app/ServerProtocol.h | 2 +- src/kits/interface/CompositeOverlay.cpp | 76 ++++++--- src/servers/app/ServerApp.cpp | 8 +- .../app/drawing/compositing/CompositeEngine.cpp | 139 +++++++++++++--- .../app/drawing/compositing/CompositeEngine.h | 5 +- ---------------------------------------------------------------------------- diff --git a/headers/os/interface/CompositeOverlay.h b/headers/os/interface/CompositeOverlay.h index a473438..ef3f538 100644 --- a/headers/os/interface/CompositeOverlay.h +++ b/headers/os/interface/CompositeOverlay.h @@ -3,6 +3,7 @@ #include <Bitmap.h> +#include <Locker.h> #include <String.h> #include <View.h> @@ -43,7 +44,7 @@ namespace BPrivate { Non-interactive animation over any area of the screen. CompositeEffects: CompositeEffects are performed in an overlay using the Window's - buffer contents as source data. Some CompositeEffects, however, + buffer contents as source data. Some CompositeEffects, however, may choose to use the frame buffer directly. CompositeOverlay provides a means by which to not need to handle the cleanup tasks required by that method. @@ -80,7 +81,7 @@ public: // fills bitmap, by default, to zero void Hide(); bool IsHidden() const; - void FollowMouse(int32 xOffset, int32 yOffset, + bool FollowMouse(int32 xOffset, int32 yOffset, follow_mouse_mode follow = B_FOLLOW_ALWAYS); bool IsFollowingMouse() const; void StopFollowingMouse(); @@ -97,6 +98,7 @@ public: // fills bitmap, by default, to zero void Invalidate(const BRegion* invalRegion); bool Quit(); + protected: // locked during Draw() virtual void Draw(BRect updateRect, BView* drawingView); @@ -120,14 +122,16 @@ private: static status_t _LinkThread(void*); status_t _LinkLoop(); + mutable BLocker fLock; BBitmap* fBitmap; BString fName; - BPoint fOriginalOrigin, - fLastOrigin; + mutable BRect fFrame; + BView* fView; bool fIsFollowingMouse, + fFrameDirty, fIsQuitting; follow_mouse_mode fFollowMouseMode; @@ -135,6 +139,8 @@ private: uint32 fFillPattern; BPrivate::PortLink* fLink; + uint32 fReserved[8]; + // reserved virtual void _ReservedCompositeOverlay1(); virtual void _ReservedCompositeOverlay2(); diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index 845255c..eeb7fc2 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -130,7 +130,6 @@ enum { AS_GET_EFFECT_CONFIG, AS_REQUEST_EFFECT, AS_SET_FPS_OVERLAY_ENABLED, - AS_COMPOSITE_ENGINE_LAST, // CompositeOverlay AS_COMPOSITE_OVERLAY_CREATE, @@ -143,6 +142,7 @@ enum { AS_COMPOSITE_OVERLAY_FRAME, AS_COMPOSITE_OVERLAY_EFFECTS, AS_COMPOSITE_OVERLAY_DESTROY, + AS_COMPOSITE_ENGINE_LAST, // BPicture definitions AS_CREATE_PICTURE, diff --git a/src/kits/interface/CompositeOverlay.cpp b/src/kits/interface/CompositeOverlay.cpp index 50ae691..02ddd8a 100644 --- a/src/kits/interface/CompositeOverlay.cpp +++ b/src/kits/interface/CompositeOverlay.cpp @@ -3,19 +3,20 @@ #undef private #include <stdio.h> -#include <View.h> +#include <Autolock.h> #include <CompositeOverlay.h> -#include <CompositingPrivate.h> #include <Looper.h> +#include <View.h> +// private #include <AppServerLink.h> +#include <CompositingPrivate.h> #include <ServerProtocol.h> using namespace BPrivate; - BCompositeOverlay:: BCompositeOverlay(const BString& name, BRect frame, screen_id screenID) : @@ -24,7 +25,7 @@ BCompositeOverlay(const BString& name, BRect frame, screen_id screenID) | B_BITMAP_IS_AREA, B_RGBA32, B_ANY_BYTES_PER_ROW, screenID)), fName(name), - fLastOrigin(frame.LeftTop()), + fFrame(frame), fView(new BView(fBitmap->Bounds(), "compositeDrawView", B_FOLLOW_NONE, B_WILL_DRAW)), fIsFollowingMouse(false), @@ -60,6 +61,7 @@ BCompositeOverlay::IsCompositingEnabled() const void BCompositeOverlay::SetOverlayEffectsEnabled(bool enable) { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_EFFECTS); fLink->AttachString("SetOverlayEffectsEnabled()"); fLink->Attach<bool>(enable); @@ -70,6 +72,7 @@ BCompositeOverlay::SetOverlayEffectsEnabled(bool enable) bool BCompositeOverlay::AreOverlayEffectsEnabled() const { + BAutolock _(fLock); int32 code = -1; fLink->StartMessage(AS_COMPOSITE_OVERLAY_EFFECTS); fLink->AttachString("AreOverlayEffectsEnabled()"); @@ -91,6 +94,7 @@ BCompositeOverlay::SetFillColor(rgb_color color) // requires such conversion will undoubtedly optimize for // bitmap conversion, in addition to providing the required // single-color pattern conversion uused here. + BAutolock _(fLock); SetFillPattern(getCompositePattern(color)); // TODO: change? // SetFillPattern(getBitmapPattern(color, ColorSpace()); } @@ -99,15 +103,15 @@ BCompositeOverlay::SetFillColor(rgb_color color) void BCompositeOverlay::SetFillPattern(uint32 pattern) { - fBitmap->Lock(); + BAutolock _(fLock); fFillPattern = pattern; - fBitmap->Unlock(); } uint32 BCompositeOverlay::FillPattern() const { + BAutolock _(fLock); return fFillPattern; } @@ -117,6 +121,7 @@ BCompositeOverlay::FillPattern() const void BCompositeOverlay::Show() { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_SHOW); fLink->AttachString("Show()"); fLink->Flush(); @@ -126,6 +131,7 @@ BCompositeOverlay::Show() void BCompositeOverlay::Hide() { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_SHOW); fLink->AttachString("Hide()"); fLink->Flush(); @@ -135,6 +141,7 @@ BCompositeOverlay::Hide() bool BCompositeOverlay::IsHidden() const { + BAutolock _(fLock); int32 code = -1; fLink->StartMessage(AS_COMPOSITE_OVERLAY_SHOW); fLink->AttachString("IsHidden()"); @@ -146,37 +153,43 @@ BCompositeOverlay::IsHidden() const // #pragma mark Mouse Following -void +bool BCompositeOverlay::FollowMouse(int32 xOffset, int32 yOffset, follow_mouse_mode followMode) { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_FOLLOW_MOUSE); fLink->AttachString("FollowMouse()"); fLink->Attach<int32>(xOffset); fLink->Attach<int32>(yOffset); fLink->Attach<follow_mouse_mode>(followMode); - fLink->Flush(); + + int32 code = -1; + fLink->FlushWithReply(code); + + if (code == B_OK) + fIsFollowingMouse = true; + + return fIsFollowingMouse; } bool BCompositeOverlay::IsFollowingMouse() const { - int32 code = -1; - fLink->StartMessage(AS_COMPOSITE_OVERLAY_FOLLOW_MOUSE); - fLink->AttachString("IsFollowingMouse()"); - fLink->FlushWithReply(code); - - return code > 0; + BAutolock _(fLock); + return fIsFollowingMouse; } void BCompositeOverlay::StopFollowingMouse() { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_FOLLOW_MOUSE); fLink->AttachString("StopFollowingMouse()"); fLink->Flush(); + fIsFollowingMouse = false; } @@ -186,38 +199,45 @@ BCompositeOverlay::StopFollowingMouse() BRect BCompositeOverlay::Frame() const { - BRect frame; + BAutolock _(fLock); + if (!fIsFollowingMouse && !fFrameDirty) + return fFrame; + int32 code = -1; fLink->StartMessage(AS_COMPOSITE_OVERLAY_FRAME); fLink->AttachString("Frame()"); fLink->FlushWithReply(code); if (code == B_OK) - fLink->Read<BRect>(&frame); + fLink->Read<BRect>(&fFrame); - return frame; + return fFrame; } void BCompositeOverlay::MoveTo(BPoint point) { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_MOVE); fLink->AttachString("MoveTo()"); fLink->Attach<float>(point.x); fLink->Attach<float>(point.y); fLink->Flush(); + fFrameDirty = true; } void BCompositeOverlay::MoveTo(float x, float y) { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_MOVE); fLink->AttachString("MoveTo()"); fLink->Attach<float>(x); fLink->Attach<float>(y); fLink->Flush(); + fFrameDirty = true; } @@ -225,11 +245,13 @@ BCompositeOverlay::MoveTo(float x, float y) void BCompositeOverlay::MoveBy(float dh, float dv) { + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_MOVE); fLink->AttachString("MoveBy()"); fLink->Attach<float>(dh); fLink->Attach<float>(dv); fLink->Flush(); + fFrameDirty = true; } @@ -248,6 +270,7 @@ BCompositeOverlay::Invalidate(BRect invalRect) if (invalRect.IsValid() == false) return; + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_INVALIDATE); fLink->AttachString("BRect"); fLink->Attach<BRect>(invalRect); @@ -261,6 +284,7 @@ BCompositeOverlay::Invalidate(const BRegion* invalRegion) if (invalRegion == NULL) return; + BAutolock _(fLock); fLink->StartMessage(AS_COMPOSITE_OVERLAY_INVALIDATE); fLink->AttachString("BRegion"); fLink->AttachRegion(*invalRegion); @@ -271,6 +295,7 @@ BCompositeOverlay::Invalidate(const BRegion* invalRegion) bool BCompositeOverlay::Quit() { + BAutolock _(fLock); if (!fIsQuitting && QuitRequested(false)){ fIsQuitting = true; fLink->StartMessage(AS_COMPOSITE_OVERLAY_QUIT); @@ -327,7 +352,10 @@ BCompositeOverlay::_Init() AppServerLink link; link.StartMessage(AS_COMPOSITE_OVERLAY_CREATE); + link.Attach<port_id>(link.ReceiverPort()); + link.Attach<port_id>(receivePort); link.AttachString(fName); + link.Attach<BRect>(fFrame); link.Attach<int32>(fBitmap->_ServerToken()); // bitmap's token int32 code = B_OK; @@ -382,6 +410,7 @@ BCompositeOverlay::_LinkLoop() BRect invalRect; if (fLink->Read<BRect>(&invalRect) == B_OK){ + BAutolock _(fLock); fBitmap->Lock(); _Fill(invalRect); fView->LockLooper(); @@ -408,6 +437,7 @@ BCompositeOverlay::_LinkLoop() if (forceQuit && !fIsQuitting){ int32 maxTries = 10; + BAutolock _(fLock); while (QuitRequested(true) == false && --maxTries > 0) snooze(2000); @@ -429,8 +459,10 @@ BCompositeOverlay::_LinkLoop() { BPoint pt; - if (fLink->Read<BPoint>(&pt) == B_OK) + if (fLink->Read<BPoint>(&pt) == B_OK){ + BAutolock _(fLock); StoppedFollowingMouse(pt); + } break; } @@ -438,8 +470,10 @@ BCompositeOverlay::_LinkLoop() { bool hidden = false; - if (fLink->Read<bool>(&hidden) == B_OK) + if (fLink->Read<bool>(&hidden) == B_OK){ + BAutolock _(fLock); Hidden(hidden); + } break; } @@ -448,8 +482,10 @@ BCompositeOverlay::_LinkLoop() { bool enabled = false; - if (fLink->Read<bool>(&enabled) == B_OK) + if (fLink->Read<bool>(&enabled) == B_OK){ + BAutolock _(fLock); CompositingEnabled(enabled); + } break; } diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index e1289c6..80140d9 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -511,12 +511,12 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) { // quickly determine if the composite engine handles this message: // TODO: create direct link for CompositeEngine?? - if ( code < AS_COMPOSITE_ENGINE_LAST - && code > AS_COMPOSITE_ENGINE_FIRST){ + if (code < AS_COMPOSITE_ENGINE_LAST + && code > AS_COMPOSITE_ENGINE_FIRST){ gCompositeEngine->HandleMessage(code, link); return; } - + switch (code) { case AS_REGISTER_INPUT_SERVER: { @@ -3339,7 +3339,7 @@ ServerApp::_CreateWindow(int32 code, BPrivate::LinkReceiver& link, if (status != B_OK){ _LOG("Window Init != B_OK!\n"); delete window; - + } } diff --git a/src/servers/app/drawing/compositing/CompositeEngine.cpp b/src/servers/app/drawing/compositing/CompositeEngine.cpp index 85e202a..aa0b922 100644 --- a/src/servers/app/drawing/compositing/CompositeEngine.cpp +++ b/src/servers/app/drawing/compositing/CompositeEngine.cpp @@ -15,6 +15,7 @@ #include "CompositeWindow.h" #include "CompositingPerfmon.h" #include "DrawingEngine.h" +#include "ProfileMessageSupport.h" #include "Desktop.h" @@ -299,10 +300,88 @@ CompositeEngine::HandleMessage(int32 code, LinkReceiver& link) { break; } + + case AS_COMPOSITE_OVERLAY_CREATE: + { + BString name; + int32 bitmapToken = -1; + // read: + // AppLink receive port + // Client PortLink receive port + // CompositeOverlay's name + // CompositeOverlay's frame + // Bitmap token + // send: + // B_OK / B_ERROR + // overlay receive port / nothing + + if (link.Read<port_id>(&port) != B_OK + || port < 0){ + _LOGF("%s: app port error\n", string_for_message_code(code)); + break; + } + + sender.SetPort(port); + + if (link.Read<port_id>(&port) != B_OK + || port < 0){ + _LOGF("%s: client port error\n", string_for_message_code(code)); + break; + } + + if (link.ReadString(name) != B_OK){ + _LOGF("%s: string error\n", string_for_message_code(code)); + break; + } + + BRect frame; + + if (link.Read<BRect>(&frame) != B_OK){ + _LOGF("%s: frame error", string_for_message_code(code)); + break; + } + + if (link.Read<int32>(&bitmapToken) != B_OK){ + _LOGF("%s: token error", string_for_message_code(code)); + break; + } + + CompositeOverlay* overlay = _FindCompositeOverlay(bitmapToken); + + if (overlay == NULL){ + _LOGF("%s: bad bitmap token", string_for_message_code(code)); + break; + } + + port_id overlayPort = overlay->Init(name, frame, port); + + if (overlayPort >= 0){ + sender.StartMessage(B_OK); + sender.Attach<float>(overlayPort); + sender.Flush(); + }else{ + sender.StartMessage(B_ERROR); + sender.Flush(); + } + + break; + } + case AS_COMPOSITE_OVERLAY_DESTROY: + { // TODO: will this ever be used? + break; + } + case AS_COMPOSITE_OVERLAY_INVALIDATE: + case AS_COMPOSITE_OVERLAY_MOVE: + case AS_COMPOSITE_OVERLAY_QUIT: + case AS_COMPOSITE_OVERLAY_FOLLOW_MOUSE: + case AS_COMPOSITE_OVERLAY_SHOW: + case AS_COMPOSITE_OVERLAY_COMPOSITING: + case AS_COMPOSITE_OVERLAY_FRAME: + case AS_COMPOSITE_OVERLAY_EFFECTS: case AS_COMPOSITE_ENGINE_FIRST: case AS_COMPOSITE_ENGINE_LAST: default: - break; // todo, log entry... + break; // todo: log entry... }; } @@ -698,20 +777,14 @@ CompositeEngine::Hide(CompositeOverlay* overlay) } - void CompositeEngine::CompositeOverlayBitmapDestroyed(ServerBitmap* bitmap) { BAutolock _(fOverlaysLock); - CompositeOverlay* overlay = NULL; - - for (int32 i = 0; i < fOverlays.CountItems(); ++i){ - overlay = fOverlays.ItemAt(i); + CompositeOverlay* overlay = _FindCompositeOverlay(bitmap); - if (overlay->GetBitmap() == bitmap){ - overlay->BitmapDestroyed(); - fOverlays.RemoveItem(overlay); - break; - } + if (overlay != NULL){ + overlay->BitmapDestroyed(); + fOverlays.RemoveItem(overlay); } } @@ -719,18 +792,16 @@ CompositeEngine::CompositeOverlayBitmapDestroyed(ServerBitmap* bitmap) void CompositeEngine::CreateCompositeOverlay(ServerBitmap* bitmap) { BAutolock _(fOverlaysLock); - CompositeOverlay* overlay = NULL; + CompositeOverlay* overlay = _FindCompositeOverlay(bitmap); - for (int32 i = 0; i < fOverlays.CountItems(); ++i){ - overlay = fOverlays.ItemAt(i); - - if (overlay->GetBitmap() == bitmap){ - _LOG("ServerBitmap already used for overlay\n"); - return; - } + if (overlay != NULL){ + _LOG("ServerBitmap already used for overlay\n"); + return; } + overlay = new CompositeOverlay(bitmap); + fOverlays.AddItem(overlay); } @@ -741,8 +812,6 @@ CompositeEngine::RedrawCursorOverlay(IntRect) const } - - // #pragma mark Acceleration Support uint32 @@ -828,10 +897,36 @@ CompositeEngine::_NextUpdateRect(bool& isFrontNonAlpha) void -CompositeEngine::_PushToFront() +CompositeEngine::_PushToFront(const BRect& rect) { BAutolock _(fHardwareLock); // BackToFrontLock should be held... } + + +CompositeOverlay* +CompositeEngine::_FindCompositeOverlay(ServerBitmap* bitmap) +{ + return _FindCompositeOverlay(bitmap->Token()); +} + + +CompositeOverlay* +CompositeEngine::_FindCompositeOverlay(int32 bitmapToken) +{ BAutolock _(fOverlaysLock); + CompositeOverlay* overlay = NULL; + + for (int32 i = 0; i < fOverlays.CountItems(); ++i){ + overlay = fOverlays.ItemAt(i); + + if (overlay->GetBitmap() != NULL + && overlay->GetBitmap()->Token() == bitmapToken) + return overlay; + } + + return NULL; +} + + diff --git a/src/servers/app/drawing/compositing/CompositeEngine.h b/src/servers/app/drawing/compositing/CompositeEngine.h index 3383142..70c4be9 100644 --- a/src/servers/app/drawing/compositing/CompositeEngine.h +++ b/src/servers/app/drawing/compositing/CompositeEngine.h @@ -121,7 +121,10 @@ private: void _EnforceMemoryLimit(); BRect _NextUpdateRect(bool&); - void _PushToFront(); + void _PushToFront(const BRect&); + + CompositeOverlay* _FindCompositeOverlay(ServerBitmap*); + CompositeOverlay* _FindCompositeOverlay(int32 bitmapToken); mutable BLocker fClientsLock, fModeSwitchLock,