Reworked the handling of periodically updated poses (currently only ones with a volume space bar):
* Addad global list where poses that need periodic updates can be registered with a callback * Use this mechanism for poses with a volume space bar * Create only one BVolume when the BPose is created for a volume, instead of every time the free space is calculated * On Pulse() the global list is used to update all of the registered periodic update poses * As the poses know their volume, it is no longer necessary to use a BVolumeRoster to loop through each volume on each Pulse() * Removed the now superfluous SendNotices() mechanism * Removed corresponding watching / handling of these notices in BPoseView The BPoseView did a linear search for each volume pose on each Pulse() before. What's more it did this once for each mounted volume as it did get one individual notice for each of them. To get these volumes a BVolumeRoster was used to loop through the volumes, but then the BPose did still create a new BVolume to actually calculate the free space! I'm surprised that it did not suck away more performance with this method... Anyway, this should bring down BVolume construction and update overhead down to a minimum and hopefully fix ticket #1247. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21462 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -35,6 +35,7 @@ All rights reserved.
|
||||
#include "Attributes.h"
|
||||
#include "MimeTypes.h"
|
||||
#include "Model.h"
|
||||
#include "PoseView.h"
|
||||
#include "Utilities.h"
|
||||
#include "ContainerWindow.h"
|
||||
|
||||
@@ -158,7 +159,81 @@ DisallowMetaKeys(BTextView *textView)
|
||||
textView->DisallowChar(B_PAGE_DOWN);
|
||||
textView->DisallowChar(B_FUNCTION_KEY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PeriodicUpdatePoses::PeriodicUpdatePoses()
|
||||
: fPoseList(20, true)
|
||||
{
|
||||
fLock = new Benaphore("PeriodicUpdatePoses");
|
||||
}
|
||||
|
||||
|
||||
PeriodicUpdatePoses::~PeriodicUpdatePoses()
|
||||
{
|
||||
fLock->Lock();
|
||||
fPoseList.MakeEmpty();
|
||||
delete fLock;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PeriodicUpdatePoses::AddPose(BPose *pose, BPoseView *poseView,
|
||||
PeriodicUpdateCallback callback, void *cookie)
|
||||
{
|
||||
periodic_pose *periodic = new periodic_pose;
|
||||
periodic->pose = pose;
|
||||
periodic->pose_view = poseView;
|
||||
periodic->callback = callback;
|
||||
periodic->cookie = cookie;
|
||||
fPoseList.AddItem(periodic);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PeriodicUpdatePoses::RemovePose(BPose *pose, void **cookie)
|
||||
{
|
||||
int32 count = fPoseList.CountItems();
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
if (fPoseList.ItemAt(index)->pose == pose) {
|
||||
if (!fLock->Lock())
|
||||
return false;
|
||||
|
||||
periodic_pose *periodic = fPoseList.RemoveItemAt(index);
|
||||
if (cookie)
|
||||
*cookie = periodic->cookie;
|
||||
delete periodic;
|
||||
fLock->Unlock();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PeriodicUpdatePoses::DoPeriodicUpdate(bool forceRedraw)
|
||||
{
|
||||
if (!fLock->Lock())
|
||||
return;
|
||||
|
||||
int32 count = fPoseList.CountItems();
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
periodic_pose *periodic = fPoseList.ItemAt(index);
|
||||
if (periodic->callback(periodic->pose, periodic->cookie)
|
||||
|| forceRedraw) {
|
||||
periodic->pose_view->LockLooper();
|
||||
periodic->pose_view->UpdateIcon(periodic->pose);
|
||||
periodic->pose_view->UnlockLooper();
|
||||
}
|
||||
}
|
||||
|
||||
fLock->Unlock();
|
||||
}
|
||||
|
||||
|
||||
static PeriodicUpdatePoses gPeriodicUpdatePoses;
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user