View Single Post
Old 02-15-2010, 04:45 PM   #1
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 976
Karma: 687
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
Code to accelerate FBReader page-flip on iLiad

This my current work on preloading next-page in FBReader. The idea starts here:https://www.mobileread.com/forums/sho...&postcount=167
Thanx for Antartica's xepdmgr and OpenInkpot project's previous efforts.

Basically, it works. The page-flip is really fast. It's even more fast (slightly) than I thought. I thought this idea will improve page-flip from 5-6 secs to 3 secs, but I estimate that page-flip is completed in 2-3 secs. Still, some finetune is needed.

To make it work with xepdmgr, I have to make FBReader sleep and yield priority to xepdmgr after calling EpdRefreshAuto(). Without the sleep() function call, xepdmgr's auto-refresh ability will be disabled before it starts and finishes the desired refresh job. The result will be no screen refresh at all. It took me some time to figure out this solution.
However, using sleep function is not elegant, and sometimes unwanted result may occur. That is, due to the un-anticipatability of multi-process environment, xepdmgr may not have enough time to finish a screen refresh before its auto-refresh ability got disabled. One of the solution is to increase sleep time. I wonder if I can get some feedback about its executing status from xepdmgr. Is there a way to ensure xepdmgr's auto-refresh is disabled only after the desired screen refresh is done?

The mod is simple. It's displayed below. Any comments or suggestions are welcome.


In ScrollingAction.cpp of FBReader-0.12.2
Code:
#include "xepdmgr-1.9-iliad/xepdmgrclient.h"
extern sEpd *Epd;
bool preloaded = false;

void ScrollingAction::run() {

/*	//original code
	FBReader &fbreader = FBReader::Instance();
	shared_ptr<ZLView> view = fbreader.currentView();
	int delay = fbreader.myLastScrollingTime.millisecondsTo(ZLTime());
	if (view.isNull() ||
			(delay >= 0 && delay < scrollingDelay())) {
		return;
	}

	if (view->typeId() == ZLTextView::TYPE_ID) {
		((ZLTextView&)*view).scrollPage(myForward, myTextScrollingMode, textOptionValue());
		FBReader::Instance().refreshWindow();
	} else if (view->typeId() == ZLBlockTreeView::TYPE_ID) {
		((ZLBlockTreeView&)*view).scroll(myBlockScrollingMode, !myForward);
	}
	fbreader.myLastScrollingTime = ZLTime();*/

	//added for iLiad
	FBReader &fbreader = FBReader::Instance();
	shared_ptr<ZLView> view = fbreader.currentView();
	int delay = fbreader.myLastScrollingTime.millisecondsTo(ZLTime());
	
	if (view.isNull() ||
			(delay >= 0 && delay < scrollingDelay())) {
		return;
	}

	if (view->typeId() == ZLTextView::TYPE_ID) {


		if(preloaded){
			if(myForward){
				//use preloaded page
				
				EpdRefreshAuto(Epd,1);
				sleep(2);
			}else{
				//reverse page-scroll
				((ZLTextView&)*view).scrollPage(myForward, myTextScrollingMode, textOptionValue());				
			}
		}else{
			((ZLTextView&)*view).scrollPage(myForward, myTextScrollingMode, textOptionValue());
			FBReader::Instance().refreshWindow();
			fbreader.myLastScrollingTime = ZLTime();
			EpdRefreshAuto(Epd,1);
			sleep(2);
		}
		preloaded = false;
		
		//do the preloading job
		EpdRefreshAuto(Epd,0);
		sleep(0);
		((ZLTextView&)*view).scrollPage(true, myTextScrollingMode, textOptionValue());
		FBReader::Instance().refreshWindow();
		preloaded = true;
	} else if (view->typeId() == ZLBlockTreeView::TYPE_ID) {
		((ZLBlockTreeView&)*view).scroll(myBlockScrollingMode, !myForward);
		fbreader.myLastScrollingTime = ZLTime();
		EpdRefreshAuto(Epd,1);
		sleep(2);
	}
}


In main.cpp
Code:
#include "xepdmgr-1.9-iliad/xepdmgrclient.c"

sEpd *Epd = NULL;

int main(int argc, char **argv) {
	//added for iLiad
	if((Epd=EpdInit(NULL))==NULL)
		return(1); /*ERROR */

	if (!ZLibrary::init(argc, argv)) {
		return 1;
	}
	
	ZLibrary::run(new FBReader(argc == 1 ? std::string() : argv[1]));
	ZLibrary::shutdown();
	EpdFini(Epd);//added for iLiad
	return 0;
}

Some note:
1. FBreader is comprised by one executable (FBReader) and three libs (zltext, zlcore, zl-ui). The above mod only affect the file "FBReader", and libs will stay the same.

2. Page-flip is only accelerated for next-page. Besides, the effect of acceleration will not be noticed at the first time when next-page button is pushed. Users will notice the effect after that. It's because preloading only starts after the first page-flip event. A demonstrative video is uploaded.
Attached Files
File Type: avi DSCN2221_xvid.avi (3.78 MB, 542 views)

Last edited by ericshliao; 02-15-2010 at 07:09 PM.
ericshliao is offline   Reply With Quote