Performance improvements to terminalkeyboardcons.
authorTom Sutcliffe <thomas.sutcliffe@accenture.com>
Tue, 24 Aug 2010 17:56:48 +0100
changeset 35 f8e05215af4a
parent 34 284c68d7a3ac
child 36 698ccde15713
child 38 99a5df8be2bb
Performance improvements to terminalkeyboardcons.
plugins/consoles/terminalkeyboardcons/terminalkeyboardcons.cpp
plugins/consoles/terminalkeyboardcons/terminalkeyboardcons.h
--- a/plugins/consoles/terminalkeyboardcons/terminalkeyboardcons.cpp	Tue Aug 24 11:54:30 2010 +0100
+++ b/plugins/consoles/terminalkeyboardcons/terminalkeyboardcons.cpp	Tue Aug 24 17:56:48 2010 +0100
@@ -62,6 +62,7 @@
 
 CTerminalKeyboardCons::~CTerminalKeyboardCons()
 	{
+	delete iIdleUpdateTimer;
 	CleanupUnderlyingConsole();
 	delete iWatcher;
 	iDriver.Close();
@@ -90,6 +91,8 @@
 	iMungedTextBuffer.CreateL((ScreenSize().iWidth + 2) * (ScreenSize().iHeight + 2));
 #endif
 
+	iIdleUpdateTimer = CPeriodic::NewL(CActive::EPriorityLow); // Lower priority than the message watcher
+
 	TInt err = User::LoadLogicalDevice(KTcLddDriverName);
 	if (err && err != KErrAlreadyExists)
 		{
@@ -311,6 +314,25 @@
 
 void CTerminalKeyboardCons::Update()
 	{
+	// Delay updates to the screen, to improve performance
+	static const TInt KDelay = 100000; // 0.1s
+	if (!iIdleUpdateTimer->IsActive())
+		{
+		// Don't reset timer if we're already running - otherwise constant typing will never show up until you stop pressing keys
+		iIdleUpdateTimer->Start(KDelay, KDelay, TCallBack(&UpdateCallback, this));
+		}
+	}
+
+TInt CTerminalKeyboardCons::UpdateCallback(TAny* aSelf)
+	{
+	static_cast<CTerminalKeyboardCons*>(aSelf)->DoUpdate();
+	return 0;
+	}
+
+void CTerminalKeyboardCons::DoUpdate()
+	{
+	iIdleUpdateTimer->Cancel(); // Stop any further updates
+
 #ifdef SHOW_TEXTSHELL_BORDERS
 	// Update munged buffer
 	const TInt contentWidth = ScreenSize().iWidth;
--- a/plugins/consoles/terminalkeyboardcons/terminalkeyboardcons.h	Tue Aug 24 11:54:30 2010 +0100
+++ b/plugins/consoles/terminalkeyboardcons/terminalkeyboardcons.h	Tue Aug 24 17:56:48 2010 +0100
@@ -50,8 +50,10 @@
 private:
 	virtual void ConstructL(const TDesC& aTitle, const TSize& aSize);
 	void Update();
+	void DoUpdate();
 	void MessageReceived(TInt aError);
 	void Transmit(const TDesC& aBuf, TInt aWidth, TInt aHeight);
+	static TInt UpdateCallback(TAny* aSelf);
 
 protected:
 	TRequestStatus* iClientStatus;
@@ -67,6 +69,7 @@
 	CMessageWatcher* iWatcher;
 	friend class CMessageWatcher;
 	TBool iBacktickModifierDown;
+	CPeriodic* iIdleUpdateTimer;
 	};
 
 #endif // TERMINALKEYBOARDCONS_H