[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haiku-commits
Subject:    [haiku-commits] haiku: hrev55750 - src/apps/activitymonitor
From:       waddlesplash <waddlesplash () gmail ! com>
Date:       2021-12-29 17:26:01
Message-ID: 20211229172601.C31C346F2D () turing ! freelists ! org
[Download RAW message or body]

hrev55750 adds 1 changeset to branch 'master'
old head: 05ce14d174e9f6637b317d1805346b7d7631f525
new head: 0f2661cc0887839b11d447986125c99b2a8491f4
overview: https://git.haiku-os.org/haiku/log/?qt=range&q=0f2661cc0887+%5E05ce14d174e9

----------------------------------------------------------------------------

0f2661cc0887: Partially revert "ActivityMonitor: remove double buffering and custom background drawing"
  
  This partially reverts commit cc0226fad05a6796f50723554c10b1bbd02de7b1.
  
  This commit caused high CPU usage in app_server. The double buffering in
  ActivityMonitor is not to avoid flickering, it allows to draw just a few
  pixels of the the curves at each update, and reuse most of the bitmap
  from the previous run.
  
  Removing this means all the curves are fully redrawn at each update,
  resulting in higher CPU usage (one core at 30% on my machine with 5
  different graphs).
  
  Keep the part of the changes removing code for custom background
  drawing. B_TRANSPARENT_VIEW flag can be used instead.
  
  Change-Id: Ie3438ca634c934f3e96ce5f7ad71ce7b3a435013
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/4833
  Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
  Reviewed-by: Axel Dörfler <axeld@pinc-software.de>

                             [ Adrien Destugues <pulkomandy@pulkomandy.tk> ]

----------------------------------------------------------------------------

Revision:    hrev55750
Commit:      0f2661cc0887839b11d447986125c99b2a8491f4
URL:         https://git.haiku-os.org/haiku/commit/?id=0f2661cc0887
Author:      Adrien Destugues <pulkomandy@pulkomandy.tk>
Date:        Fri Dec 24 09:42:04 2021 UTC
Committer:   waddlesplash <waddlesplash@gmail.com>
Commit-Date: Wed Dec 29 17:25:56 2021 UTC

----------------------------------------------------------------------------

2 files changed, 63 insertions(+), 3 deletions(-)
src/apps/activitymonitor/ActivityView.cpp | 62 +++++++++++++++++++++++++--
src/apps/activitymonitor/ActivityView.h   |  4 ++

----------------------------------------------------------------------------

diff --git a/src/apps/activitymonitor/ActivityView.cpp b/src/apps/activitymonitor/ActivityView.cpp
index a4e1ee2b0e..5fea2cd6b4 100644
--- a/src/apps/activitymonitor/ActivityView.cpp
+++ b/src/apps/activitymonitor/ActivityView.cpp
@@ -553,7 +553,7 @@ const float kDraggerSize = 7;
 ActivityView::ActivityView(BRect frame, const char* name,
 		const BMessage* settings, uint32 resizingMode)
 	: BView(frame, name, resizingMode,
-		B_WILL_DRAW | B_SUBPIXEL_PRECISE | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
+		B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
 	fSourcesLock("data sources")
 {
 	_Init(settings);
@@ -598,6 +598,7 @@ ActivityView::ActivityView(BMessage* archive)
 
 ActivityView::~ActivityView()
 {
+	delete fOffscreen;
 	delete fSystemInfoHandler;
 }
 
@@ -608,6 +609,7 @@ ActivityView::_Init(const BMessage* settings)
 	fHistoryBackgroundColor = (rgb_color){255, 255, 240};
 	fLegendBackgroundColor = LowColor();
 		// the low color is restored by the BView unarchiving
+	fOffscreen = NULL;
 #ifdef __HAIKU__
 	fHistoryLayoutItem = NULL;
 	fLegendLayoutItem = NULL;
@@ -924,6 +926,51 @@ ActivityView::MinSize()
 #endif
 
 
+void
+ActivityView::FrameResized(float /*width*/, float /*height*/)
+{
+	_UpdateOffscreenBitmap();
+}
+
+
+void
+ActivityView::_UpdateOffscreenBitmap()
+{
+	BRect frame = _HistoryFrame();
+	frame.OffsetTo(B_ORIGIN);
+
+	if (fOffscreen != NULL && frame == fOffscreen->Bounds())
+		return;
+
+	delete fOffscreen;
+
+	// create offscreen bitmap
+
+	fOffscreen = new(std::nothrow) BBitmap(frame, B_BITMAP_ACCEPTS_VIEWS,
+		B_RGB32);
+	if (fOffscreen == NULL || fOffscreen->InitCheck() != B_OK) {
+		delete fOffscreen;
+		fOffscreen = NULL;
+		return;
+	}
+
+	BView* view = new BView(frame, NULL, B_FOLLOW_NONE, B_SUBPIXEL_PRECISE);
+	view->SetViewColor(fHistoryBackgroundColor);
+	view->SetLowColor(view->ViewColor());
+	fOffscreen->AddChild(view);
+}
+
+
+BView*
+ActivityView::_OffscreenView()
+{
+	if (fOffscreen == NULL)
+		return NULL;
+
+	return fOffscreen->ChildAt(0);
+}
+
+
 void
 ActivityView::MouseDown(BPoint where)
 {
@@ -1279,7 +1326,13 @@ ActivityView::_PositionForValue(DataSource* source, DataHistory* values,
 void
 ActivityView::_DrawHistory()
 {
+	_UpdateOffscreenBitmap();
+
 	BView* view = this;
+	if (fOffscreen != NULL) {
+		fOffscreen->Lock();
+		view = _OffscreenView();
+	}
 
 	BRect frame = _HistoryFrame();
 	BRect outerFrame = frame.InsetByCopy(-2, -2);
@@ -1378,9 +1431,12 @@ ActivityView::_DrawHistory()
 		view->EndLineArray();
 	}
 
-	view->SetPenSize(1);
-
 	// TODO: add marks when an app started or quit
+	view->Sync();
+	if (fOffscreen != NULL) {
+		fOffscreen->Unlock();
+		DrawBitmap(fOffscreen, outerFrame.LeftTop());
+	}
 }
 
 
diff --git a/src/apps/activitymonitor/ActivityView.h b/src/apps/activitymonitor/ActivityView.h
index 82ed245d24..9983f1f323 100644
--- a/src/apps/activitymonitor/ActivityView.h
+++ b/src/apps/activitymonitor/ActivityView.h
@@ -86,6 +86,7 @@ protected:
 	virtual	BSize		MinSize();
 #endif
 
+	virtual void		FrameResized(float width, float height);
 	virtual void		MouseDown(BPoint where);
 	virtual void		MouseUp(BPoint where);
 	virtual void		MouseMoved(BPoint where, uint32 transit,
@@ -100,6 +101,8 @@ private:
 			::Scale*	_ScaleFor(scale_type type);
 			void		_Refresh();
 	static	status_t	_RefreshThread(void* self);
+			void		_UpdateOffscreenBitmap();
+			BView*		_OffscreenView();
 			void		_UpdateFrame();
 			BRect		_HistoryFrame() const;
 			float		_LegendHeight() const;
@@ -121,6 +124,7 @@ private:
 
 	rgb_color			fHistoryBackgroundColor;
 	rgb_color			fLegendBackgroundColor;
+	BBitmap*			fOffscreen;
 #ifdef __HAIKU__
 	BLayoutItem*		fHistoryLayoutItem;
 	BLayoutItem*		fLegendLayoutItem;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic