MCPcopy Create free account
hub / github.com/KLayout/klayout / prepare_drawing

Method prepare_drawing

src/laybasic/laybasic/layLayoutCanvas.cc:409–517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407}
408
409void
410LayoutCanvas::prepare_drawing ()
411{
412 if (m_need_redraw) {
413
414 BitmapViewObjectCanvas::set_size (m_viewport_l.width (), m_viewport_l.height (), resolution (), font_resolution ());
415
416 if (! mp_image ||
417 (unsigned int) mp_image->width () != m_viewport_l.width () ||
418 (unsigned int) mp_image->height () != m_viewport_l.height ()) {
419 if (mp_image) {
420 delete mp_image;
421 }
422 mp_image = new tl::PixelBuffer (m_viewport_l.width (), m_viewport_l.height ());
423 if (mp_image_fg) {
424 delete mp_image_fg;
425 mp_image_fg = 0;
426 }
427 }
428
429 mp_image->fill (m_background);
430
431 // Cancel any pending "finish" event so there is no race between finish and restart (important for caching)
432 m_do_end_of_drawing_dm.cancel ();
433
434 // look for a cache entry we may reuse
435 std::vector <ImageCacheEntry>::iterator c;
436 for (c = m_image_cache.begin (); c != m_image_cache.end (); ++c) {
437 if (! c->opened () && c->equals (m_viewport_l, m_layers) && can_restore_data (c->data ())) {
438 break;
439 }
440 }
441
442 if (c != m_image_cache.end ()) {
443
444 // move selected entry to end of cache for renewed life time
445 while (c + 1 != m_image_cache.end ()) {
446 c->swap (c [1]);
447 ++c;
448 }
449
450 mp_redraw_thread->commit (m_layers, m_viewport_l, resolution (), font_resolution ());
451
452 if (tl::verbosity () >= 20) {
453 tl::info << "Restored image from cache";
454 }
455 restore_data (c->data ());
456
457 } else {
458
459 bool precious = m_viewport_l.target_box ().equal (m_precious_box);
460
461 // discard all open cache entries and reset all previously precious ones
462 for (size_t i = 0; i < m_image_cache.size (); ++i) {
463 if (precious) {
464 m_image_cache [i].set_precious (false);
465 }
466 if (m_image_cache [i].opened () || m_image_cache [i].equals (m_viewport_l, m_layers)) {

Callers

nothing calls this directly

Calls 15

set_sizeFunction · 0.85
verbosityFunction · 0.85
ImageCacheEntryClass · 0.85
openedMethod · 0.80
set_preciousMethod · 0.80
preciousMethod · 0.80
is_runningMethod · 0.80
resolutionFunction · 0.70
font_resolutionFunction · 0.70
widthMethod · 0.45
heightMethod · 0.45
fillMethod · 0.45

Tested by

no test coverage detected