HWInterface::Cursor() and therefor Desktop::Cursor() accessed the
current cursor without locking, and did not add a reference while using the cursor. I have tried to solve both problems by introducing a simple ServerCursorReference class, which makes sure that the reference count is properly maintained. There are only two places where this code was even used, from within ServerApp and when taking screenshots. Axel, you mentioned in #837 that the code is unsafe, is this what you meant? This hopefully fixes #837, but it is very hard to reproduce in the first place, I will close the ticket, but it should just be reopened if ever encountered again. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24741 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
42cf275606
commit
ace2d5ee37
@ -714,15 +714,15 @@ Desktop::SetCursor(ServerCursor* newCursor)
|
|||||||
if (newCursor == NULL)
|
if (newCursor == NULL)
|
||||||
newCursor = fCursorManager.GetCursor(B_CURSOR_DEFAULT);
|
newCursor = fCursorManager.GetCursor(B_CURSOR_DEFAULT);
|
||||||
|
|
||||||
ServerCursor* oldCursor = Cursor();
|
ServerCursorReference oldCursor = Cursor();
|
||||||
if (newCursor == oldCursor)
|
if (newCursor == oldCursor.Cursor())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
HWInterface()->SetCursor(newCursor);
|
HWInterface()->SetCursor(newCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ServerCursor*
|
ServerCursorReference
|
||||||
Desktop::Cursor() const
|
Desktop::Cursor() const
|
||||||
{
|
{
|
||||||
return HWInterface()->Cursor();
|
return HWInterface()->Cursor();
|
||||||
|
@ -12,12 +12,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "CursorManager.h"
|
#include "CursorManager.h"
|
||||||
|
#include "DesktopSettings.h"
|
||||||
#include "EventDispatcher.h"
|
#include "EventDispatcher.h"
|
||||||
|
#include "MessageLooper.h"
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
#include "ScreenManager.h"
|
#include "ScreenManager.h"
|
||||||
|
#include "ServerCursor.h"
|
||||||
#include "VirtualScreen.h"
|
#include "VirtualScreen.h"
|
||||||
#include "DesktopSettings.h"
|
|
||||||
#include "MessageLooper.h"
|
|
||||||
#include "WindowList.h"
|
#include "WindowList.h"
|
||||||
#include "Workspace.h"
|
#include "Workspace.h"
|
||||||
#include "WorkspacePrivate.h"
|
#include "WorkspacePrivate.h"
|
||||||
@ -78,7 +79,7 @@ class Desktop : public MessageLooper, public ScreenOwner {
|
|||||||
CursorManager& GetCursorManager() { return fCursorManager; }
|
CursorManager& GetCursorManager() { return fCursorManager; }
|
||||||
|
|
||||||
void SetCursor(ServerCursor* cursor);
|
void SetCursor(ServerCursor* cursor);
|
||||||
ServerCursor* Cursor() const;
|
ServerCursorReference Cursor() const;
|
||||||
void SetLastMouseState(const BPoint& position,
|
void SetLastMouseState(const BPoint& position,
|
||||||
int32 buttons);
|
int32 buttons);
|
||||||
// for use by the mouse filter only
|
// for use by the mouse filter only
|
||||||
|
@ -291,8 +291,6 @@ ServerApp::Activate(bool value)
|
|||||||
if (fIsActive == value)
|
if (fIsActive == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: send some message to the client?!?
|
|
||||||
|
|
||||||
fIsActive = value;
|
fIsActive = value;
|
||||||
|
|
||||||
if (fIsActive) {
|
if (fIsActive) {
|
||||||
|
@ -70,4 +70,54 @@ class ServerCursor : public ServerBitmap {
|
|||||||
vint32 fPendingViewCursor;
|
vint32 fPendingViewCursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ServerCursorReference {
|
||||||
|
public:
|
||||||
|
ServerCursorReference()
|
||||||
|
: fCursor(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
ServerCursorReference(ServerCursor* cursor)
|
||||||
|
: fCursor(cursor)
|
||||||
|
{
|
||||||
|
if (fCursor)
|
||||||
|
fCursor->Acquire();
|
||||||
|
}
|
||||||
|
ServerCursorReference(const ServerCursorReference& other)
|
||||||
|
: fCursor(other.fCursor)
|
||||||
|
{
|
||||||
|
if (fCursor)
|
||||||
|
fCursor->Acquire();
|
||||||
|
}
|
||||||
|
virtual ~ServerCursorReference()
|
||||||
|
{
|
||||||
|
if (fCursor)
|
||||||
|
fCursor->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerCursorReference& operator=(const ServerCursorReference& other)
|
||||||
|
{
|
||||||
|
SetCursor(other.fCursor);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCursor(ServerCursor* cursor)
|
||||||
|
{
|
||||||
|
if (fCursor == cursor)
|
||||||
|
return;
|
||||||
|
if (fCursor)
|
||||||
|
fCursor->Release();
|
||||||
|
fCursor = cursor;
|
||||||
|
if (fCursor)
|
||||||
|
fCursor->Acquire();
|
||||||
|
}
|
||||||
|
ServerCursor* Cursor() const
|
||||||
|
{
|
||||||
|
return fCursor;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
ServerCursor* fCursor;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SERVER_CURSOR_H
|
#endif // SERVER_CURSOR_H
|
||||||
|
@ -1155,7 +1155,10 @@ DrawingEngine::ReadBitmap(ServerBitmap *bitmap, bool drawCursor, BRect bounds)
|
|||||||
bounds.IntegerWidth() + 1, bounds.IntegerHeight() + 1);
|
bounds.IntegerWidth() + 1, bounds.IntegerHeight() + 1);
|
||||||
|
|
||||||
if (drawCursor) {
|
if (drawCursor) {
|
||||||
ServerCursor *cursor = fGraphicsCard->Cursor();
|
ServerCursorReference cursorRef = fGraphicsCard->Cursor();
|
||||||
|
ServerCursor* cursor = cursorRef.Cursor();
|
||||||
|
if (!cursor)
|
||||||
|
return result;
|
||||||
int32 cursorWidth = cursor->Width();
|
int32 cursorWidth = cursor->Width();
|
||||||
int32 cursorHeight = cursor->Height();
|
int32 cursorHeight = cursor->Height();
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include "drawing_support.h"
|
#include "drawing_support.h"
|
||||||
|
|
||||||
#include "RenderingBuffer.h"
|
#include "RenderingBuffer.h"
|
||||||
#include "ServerCursor.h"
|
|
||||||
#include "SystemPalette.h"
|
#include "SystemPalette.h"
|
||||||
#include "UpdateQueue.h"
|
#include "UpdateQueue.h"
|
||||||
|
|
||||||
@ -148,6 +147,17 @@ HWInterface::SetCursor(ServerCursor* cursor)
|
|||||||
fFloatingOverlaysLock.Unlock();
|
fFloatingOverlaysLock.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cursor
|
||||||
|
ServerCursorReference
|
||||||
|
HWInterface::Cursor() const
|
||||||
|
{
|
||||||
|
if (!fFloatingOverlaysLock.Lock())
|
||||||
|
return ServerCursorReference(NULL);
|
||||||
|
ServerCursorReference reference(fCursor);
|
||||||
|
fFloatingOverlaysLock.Unlock();
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
// SetCursorVisible
|
// SetCursorVisible
|
||||||
void
|
void
|
||||||
HWInterface::SetCursorVisible(bool visible)
|
HWInterface::SetCursorVisible(bool visible)
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
#define HW_INTERFACE_H
|
#define HW_INTERFACE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "IntRect.h"
|
||||||
#include "MultiLocker.h"
|
#include "MultiLocker.h"
|
||||||
|
#include "ServerCursor.h"
|
||||||
|
|
||||||
#include <video_overlay.h>
|
#include <video_overlay.h>
|
||||||
|
|
||||||
@ -20,13 +22,10 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
|
|
||||||
#include "IntRect.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Overlay;
|
class Overlay;
|
||||||
class RenderingBuffer;
|
class RenderingBuffer;
|
||||||
class ServerBitmap;
|
class ServerBitmap;
|
||||||
class ServerCursor;
|
|
||||||
class UpdateQueue;
|
class UpdateQueue;
|
||||||
class BString;
|
class BString;
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ class HWInterface : protected MultiLocker {
|
|||||||
virtual void Sync() {}
|
virtual void Sync() {}
|
||||||
|
|
||||||
// cursor handling (these do their own Read/Write locking)
|
// cursor handling (these do their own Read/Write locking)
|
||||||
ServerCursor* Cursor() const { return fCursor; }
|
ServerCursorReference Cursor() const;
|
||||||
virtual void SetCursor(ServerCursor* cursor);
|
virtual void SetCursor(ServerCursor* cursor);
|
||||||
virtual void SetCursorVisible(bool visible);
|
virtual void SetCursorVisible(bool visible);
|
||||||
bool IsCursorVisible();
|
bool IsCursorVisible();
|
||||||
|
Loading…
Reference in New Issue
Block a user