#include <notepad_pages.h>
Data Structures | |
struct | NpPage |
Public Member Functions | |
CNotepadPages () | |
~CNotepadPages () | |
void | init (CNotepadDoc *aDoc, GCtx *aCtx, int pageno, GdkVisual *visual=0) |
void | stop () |
void | insert_page (const int pageno) |
void | delete_page (const int pageno) |
void | clear_page (const int pageno) |
void | mark_dirty (const int pageno) |
void | mark_all_dirty () |
GdkImage * | get_page (const int pageno) |
bool | execRenderPage (RenderPageCtx *ctx) |
Definition at line 53 of file notepad_pages.h.
notepad::CNotepadPages::CNotepadPages | ( | ) |
Definition at line 56 of file notepad_pages.cpp.
References LOGPRINTF, and NPAGES.
00057 : doc(0) 00058 , gctx(0) 00059 , current_page(0) 00060 , drawsem(0) 00061 , pages_rw_sem(1) 00062 { 00063 LOGPRINTF("entry"); 00064 for (gint i = 0; i < NPAGES; i++) 00065 { 00066 pages[i].image = 0; 00067 pages[i].pageno = 0; 00068 pages[i].dirty = TRUE; 00069 } 00070 LOGPRINTF("exit"); 00071 }
notepad::CNotepadPages::~CNotepadPages | ( | ) |
Definition at line 73 of file notepad_pages.cpp.
References NPAGES, and stop().
00074 { 00075 stop(); 00076 for (gint i = 0; i < NPAGES; i++) 00077 { 00078 if (pages[i].image != 0) 00079 { 00080 g_object_unref(G_OBJECT(pages[i].image) ); 00081 pages[i].image = 0; 00082 } 00083 } 00084 }
void notepad::CNotepadPages::clear_page | ( | const int | pageno | ) |
Definition at line 299 of file notepad_pages.cpp.
References LOGPRINTF, and mark_dirty().
Referenced by notepad::CNotepadWindow::delete_current_page_impl().
00300 { 00301 // clear page: implemented here to mark for redraw in cache, where 00302 // the data of the page is assumed to be cleared before. 00303 LOGPRINTF("entry"); 00304 00305 g_assert(pageno > 0); 00306 00307 mark_dirty(pageno); 00308 00309 LOGPRINTF("exit"); 00310 }
void notepad::CNotepadPages::delete_page | ( | const int | pageno | ) |
Definition at line 269 of file notepad_pages.cpp.
References notepad::CmdQueue::flush(), LOGPRINTF, NOTFOUND, notepad::CSemaphore::p(), and notepad::CSemaphore::v().
Referenced by notepad::CNotepadWindow::delete_current_page_impl().
00270 { 00271 // remove page with same position, and decrease all next pages 00272 LOGPRINTF("entry"); 00273 00274 g_assert(pageno > 0); 00275 00276 // flush running queue 00277 cmd_queue.flush(); 00278 00279 pages_rw_sem.p(); // guarded write 00280 00281 gint i = find_page(pageno); 00282 if (i != NOTFOUND) 00283 { 00284 for (gint j = 0; j < NPAGES; j++) 00285 { 00286 if (pages[j].pageno > pageno) 00287 { 00288 // page positions are also decreased inside scribble library; 00289 pages[j].pageno--; 00290 } 00291 } 00292 remove_from_cache(i); 00293 } 00294 pages_rw_sem.v(); 00295 00296 LOGPRINTF("exit"); 00297 }
bool notepad::CNotepadPages::execRenderPage | ( | RenderPageCtx * | ctx | ) |
Definition at line 407 of file notepad_pages.cpp.
References notepad::CNotepadDoc::draw_scribble_page(), notepad::RenderPageCtx::isCurrent, LOGPRINTF, NOTFOUND, notepad::CSemaphore::p(), notepad::RenderPageCtx::pageno, and notepad::CSemaphore::v().
Referenced by notepad::renderCommand::execute().
00408 { 00409 // Called in render queue workerthread 00410 g_assert(params != 0); 00411 00412 bool redraw = false; 00413 00414 pages_rw_sem.p(); // guarded write 00415 00416 // find out if page has to be redrawn 00417 int i = find_page(params->pageno); 00418 if (i == NOTFOUND) 00419 { 00420 i = make_room(params->pageno); 00421 LOGPRINTF("added page %d in %d", params->pageno, i); 00422 redraw = true; 00423 } 00424 else 00425 { 00426 redraw = pages[i].dirty; 00427 } 00428 00429 if (redraw) 00430 { 00431 LOGPRINTF("redraw page %d : %d c %d i %d", params->pageno, redraw, params->isCurrent, i); 00432 00433 // Create new image, page may be dirty because of rotation, deletion etc. 00434 i = replace_page_at_index(i, params->pageno); 00435 00436 // render page. Offline drawing on gdk_image 00437 g_assert(i >= 0 && i < NPAGES); 00438 g_assert(pages[i].image != 0); 00439 doc->draw_scribble_page(params->pageno, *gctx, pages[i].image); 00440 pages[i].dirty = FALSE; 00441 } 00442 00443 pages_rw_sem.v(); 00444 00445 if (params->isCurrent) 00446 { 00447 LOGPRINTF("ready rendering current page"); 00448 drawsem.v(); // unlock display of current page 00449 } 00450 00451 LOGPRINTF("exit"); 00452 return true; 00453 }
GdkImage * notepad::CNotepadPages::get_page | ( | const int | pageno | ) |
Definition at line 344 of file notepad_pages.cpp.
References notepad::CmdQueue::add(), notepad::CmdQueue::flush(), notepad::ipc_sys_busy(), notepad::RenderPageCtx::isCurrent, LOGPRINTF, NOTFOUND, notepad::CSemaphore::p(), and notepad::RenderPageCtx::pageno.
Referenced by notepad::CNotepadWindow::update().
00345 { 00346 // returns image of current page, a commandqueue may be used to fetch the page 00347 LOGPRINTF("entry %d", pageno); 00348 00349 g_assert(pageno > 0); 00350 00351 int i = find_page(pageno); 00352 00353 // queue render taks if page not in cache, pageflip or page marked dirty 00354 if ((i == NOTFOUND) || (pageno != current_page) || pages[i].dirty) 00355 { 00356 // flush running queue 00357 cmd_queue.flush(); 00358 00359 // Define smart order of caching 00360 const int order[NPAGES] = {0, +1, +2, -1, +3, -2, +4, -3, +5, -4, -5}; 00361 // queue render task for current and adjacent pages. 00362 for (gint j = 0; j < NPAGES; j++) 00363 { 00364 int relpage = pageno + order[j]; 00365 if ( (relpage > 0) && (relpage <= doc->get_num_pages()) ) 00366 { 00367 i = find_page(relpage); 00368 if ((i == NOTFOUND) || (pages[i].dirty)) // rerender page 00369 { 00370 LOGPRINTF("add to queue [%d] page %d", j, relpage); 00371 RenderPageCtx* params = new RenderPageCtx; // deleted by execute rendercommand 00372 memset(params, 0, sizeof params); 00373 params->pageno = relpage; 00374 params->isCurrent = (j == 0); // if waiting for current page ready must be signalled. 00375 renderCommand* rc = new renderCommand(this, params); 00376 cmd_queue.add(rc); 00377 00378 if (j == 0) // current page 00379 { 00380 LOGPRINTF("waiting for semaphore"); 00381 ipc_sys_busy(true); // begin busy 00382 drawsem.p(); // wait for render result of current window 00383 LOGPRINTF("ready waiting for semaphore"); 00384 } 00385 } 00386 } 00387 } 00388 } 00389 00390 i = find_page(pageno); 00391 g_assert(i >= 0 && i < NPAGES); // return valid page 00392 00393 // remember current page 00394 current_page = pageno; 00395 00396 ipc_sys_busy(false); // end busy 00397 00398 // return current image for use in scribbling 00399 LOGPRINTF("exit"); 00400 return pages[i].image; 00401 }
void notepad::CNotepadPages::init | ( | CNotepadDoc * | aDoc, | |
GCtx * | aCtx, | |||
int | pageno, | |||
GdkVisual * | visual = 0 | |||
) |
Definition at line 86 of file notepad_pages.cpp.
References notepad::CmdQueue::start().
Referenced by notepad::CNotepadWindow::init().
00087 { 00088 g_assert(aDoc != 0); 00089 g_assert(aCtx != 0); 00090 g_assert(aPage > 0); 00091 g_assert(aVisual!= 0); 00092 00093 visual = aVisual; 00094 doc = aDoc; 00095 gctx = aCtx; 00096 current_page = aPage; 00097 00098 // Start the thread before executing the first task. 00099 // The thread will only be started once! 00100 cmd_queue.start(); 00101 }
void notepad::CNotepadPages::insert_page | ( | const int | pageno | ) |
Definition at line 239 of file notepad_pages.cpp.
References notepad::CmdQueue::flush(), LOGPRINTF, notepad::CSemaphore::p(), and notepad::CSemaphore::v().
Referenced by notepad::CNotepadWindow::insert_page(), and notepad::CNotepadWindow::pageflip_or_create().
00240 { 00241 // insert page at position, and increase all next pages 00242 LOGPRINTF("entry"); 00243 00244 g_assert(pageno > 0); 00245 00246 // flush running queue 00247 cmd_queue.flush(); 00248 00249 pages_rw_sem.p(); // guarded write 00250 00251 gint ifree = make_room(pageno); 00252 g_assert(ifree >= 0 && ifree < NPAGES); 00253 00254 for (gint i = 0; i < NPAGES; i++) 00255 { 00256 if (pages[i].pageno >= pageno) 00257 { 00258 // page positions are also increased inside scribble library; 00259 pages[i].pageno++; 00260 } 00261 } 00262 00263 replace_page_at_index(ifree, pageno); 00264 pages_rw_sem.v(); 00265 00266 LOGPRINTF("exit"); 00267 }
void notepad::CNotepadPages::mark_all_dirty | ( | ) |
Definition at line 328 of file notepad_pages.cpp.
References LOGPRINTF.
Referenced by notepad::CNotepadWindow::set_rotation().
00329 { 00330 // mark whole cache for redraw at update. 00331 LOGPRINTF("entry"); 00332 00333 for (gint i = 0; i < NPAGES; i++) 00334 { 00335 pages[i].dirty = TRUE; // mark for redraw at update. 00336 } 00337 00338 LOGPRINTF("exit"); 00339 }
void notepad::CNotepadPages::mark_dirty | ( | const int | pageno | ) |
Definition at line 312 of file notepad_pages.cpp.
References LOGPRINTF, and NOTFOUND.
Referenced by clear_page(), and notepad::CNotepadWindow::erase().
00313 { 00314 // mark for redraw at update. 00315 LOGPRINTF("entry"); 00316 00317 g_assert(pageno > 0); 00318 00319 gint i = find_page(pageno); 00320 if (i != NOTFOUND) 00321 { 00322 pages[i].dirty = TRUE; // mark for redraw at update. 00323 } 00324 00325 LOGPRINTF("exit"); 00326 }
void notepad::CNotepadPages::stop | ( | void | ) |
Definition at line 103 of file notepad_pages.cpp.
References notepad::CmdQueue::stop().
Referenced by notepad::CNotepadWindow::quit(), ~CNotepadPages(), and notepad::CNotepadWindow::~CNotepadWindow().