diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2011-10-08 21:50:22 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2011-10-08 21:50:22 +0000 |
commit | 748b294646092e461053ade09a52a29586cbf4f7 (patch) | |
tree | 570e8acffa139580b5b742f651ecc1d4d38a7862 | |
parent | 70605d6fea205dc6b6d2c30c95cfb449c170108a (diff) | |
download | 2011-ddhardrescue-748b294646092e461053ade09a52a29586cbf4f7.tar.gz 2011-ddhardrescue-748b294646092e461053ade09a52a29586cbf4f7.tar.bz2 2011-ddhardrescue-748b294646092e461053ade09a52a29586cbf4f7.zip |
Essai d'optimisation de l'affichage : ne pas rafraichir tout le dessin à chaque fois. Au finak c'est compliqué car on ne peut pas réutiliser le code de slicesDump car on ne peut pas relire les caractères envoyés sur la WINDOW ncurse...
git-svn-id: file:///var/svn/2011-ddhardrescue/trunk@27 d3078510-dda0-49f1-841c-895ef4b7ec81
-rw-r--r-- | src/cursesview.c | 7 | ||||
-rw-r--r-- | src/slices.c | 89 |
2 files changed, 49 insertions, 47 deletions
diff --git a/src/cursesview.c b/src/cursesview.c index 0b346fb..83b133f 100644 --- a/src/cursesview.c +++ b/src/cursesview.c @@ -137,7 +137,7 @@ void cursesMainLoop(slices_evt_t *slicesEvt) { // TODO : faire une structure avec tous les éléments graphiques utiles au listener et tout passer par référence de la mainloop à ce listener #define DEFAULT_ZOOM_FACTOR 2.f -int winUpdateSliceDumpMouseEventListener(MEVENT mevent, WINDOW *winDebug) { +int winSlicesMouseEventListener(MEVENT mevent, WINDOW *winDebug) { bool resb; int pX, pY, maxX, maxY; address_t delta; @@ -202,7 +202,7 @@ int cursesInit(WINDOW *wins[], PANEL *panels[], int count) { set_panel_userptr(panels[2], panels[0]); */ - set_panel_userptr(panels[1], winUpdateSliceDumpMouseEventListener); + set_panel_userptr(panels[1], winSlicesMouseEventListener); #ifdef NCURSES_MOUSE_VERSION sprintf(buf, "Debug infos : mmask=%lx", mmask); @@ -233,8 +233,11 @@ void cursesUpdateSliceDump(slices_evt_t *slicesEvt, slice_t *modifiedSlice) { unsigned int charCount=(getmaxx(winUpdateSliceDump)-getbegx(winUpdateSliceDump))*(getmaxy(winUpdateSliceDump)-getbegy(winUpdateSliceDump)+2); //TODO : refesh only right parts of the representation + // This need a representation that not depends on what is already drawn because of consistency and because it not possible to re-read printed ASCII representation in curse windows + pthread_mutex_lock(&ncursesWriteMutex); + toPrint=slicesDump(slicesEvt->data, &blockSize, charCount, sliceDumpBegin, sliceDumpEnd); if (toPrint != NULL) { attron(COLOR_PAIR(4)); diff --git a/src/slices.c b/src/slices.c index fae363a..e8f1d49 100644 --- a/src/slices.c +++ b/src/slices.c @@ -92,6 +92,48 @@ int sliceSplit(slices_t *slices, slice_t *initialSlice, address_t splitAt, slice return 1 + (splitBeforeSingularity?1:0) + (splitAfterSingularity?1:0); } +void sliceDumpUpdate(char *dump, slice_t *s, address_t blockSize, unsigned int charCount, address_t begin, address_t end) { + address_t sb,se,i; + char ci; + + // If "s" slice is (partially) contained/visible in the [begin,end] display interval + if ( !(s->end < begin) && !(s->begin > end) ) { + // Draw the slice on the right number of characters + // Mathematically correct, but crashes because address_t is UNSIGNED + // sb=MAX(0, (s->begin - begin) / *blockSize); + sb=(s->begin < begin)?0:(s->begin - begin) / blockSize; + se=MIN((s->end - begin) / blockSize, charCount-1); + + /* Debug "assertion" + if (sb >= charCount || se >= charCount) { + printf("BUG : sb==%lli, se=%lli, charCount==%i\n", sb, se, charCount); + printf("BUG : MAX(0, (%lli - %lli) / %lli)", s->begin, begin, blockSize); + exit(42); + }*/ + + // Choose from the sent slice status the right char to draw + switch (s->status) { + case S_UNKNOWN: ci='_'; break; + case S_UNREADABLE: ci='!'; break; + case S_RECOVERED: ci='.'; break; + default: ci='~'; break; + } + + // Draw on the right number of characters, paying attention with information collision + for (i=sb;i<=se;i++) { + if (dump[i] == ' ' ) { + // This is a new information + dump[i]=ci; + } else if ( dump[i] == ci || dump[i] == '!' ) { + // Already the right information or error, don't modify + } else { + // Multiple information on the same character + dump[i]='#'; + } + } + } +} + slices_t *slicesNewEmpty() { int res; slices_t *ss = malloc(1*sizeof(slices_t)); @@ -203,54 +245,11 @@ slice_t *slicesFindLargestFast(slices_t *slices, address_t *foundMax, sliceStatu return sMax; } -void _sliceDump(char *dump, slice_t *curr, address_t blockSize, unsigned int charCount, address_t begin, address_t end) { - address_t sb,se,i; - char ci; - - // If "curr" slice is (partially) contained/visible in the [begin,end] display interval - if ( !(curr->end < begin) && !(curr->begin > end) ) { - // Draw the slice on the right number of characters - // Mathematically correct, but crashes because address_t is UNSIGNED - // sb=MAX(0, (curr->begin - begin) / *blockSize); - sb=(curr->begin < begin)?0:(curr->begin - begin) / blockSize; - se=MIN((curr->end - begin) / blockSize, charCount-1); - - /* Debug "assertion" - if (sb >= charCount || se >= charCount) { - printf("BUG : sb==%lli, se=%lli, charCount==%i\n", sb, se, charCount); - printf("BUG : MAX(0, (%lli - %lli) / %lli)", curr->begin, begin, blockSize); - pthread_mutex_unlock(&(slices->writeOrConsistentReadMutex)); - exit(42); - }*/ - - // Choose from the current slice status the right char to draw - switch (curr->status) { - case S_UNKNOWN: ci='_'; break; - case S_UNREADABLE: ci='!'; break; - case S_RECOVERED: ci='.'; break; - default: ci='~'; break; - } - - // Draw on the right number of characters, paying attention with information collision - for (i=sb;i<=se;i++) { - if (dump[i] == ' ' ) { - // This is a new information - dump[i]=ci; - } else if ( dump[i] == ci || dump[i] == '!' ) { - // Already the right information or error, don't modify - } else { - // Multiple information on the same character - dump[i]='#'; - } - } - } -} - char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount, address_t begin, address_t end) { int res; slice_t *curr; char *dump; - + res=pthread_mutex_lock(&(slices->writeOrConsistentReadMutex)); if (res!=0) { //FIXME Trashy code @@ -273,7 +272,7 @@ char *slicesDump(slices_t *slices, address_t *blockSize, unsigned int charCount, //For each slice write in dump ASCII representation curr = slices->first; while (curr != NULL) { - _sliceDump(dump, curr, *blockSize, charCount, begin, end); + sliceDumpUpdate(dump, curr, *blockSize, charCount, begin, end); curr=curr->next; } |