diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-10-12 12:37:18 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-10-12 12:37:18 +0000 |
| commit | 9248a27415b51ae5674dd79d1738cf8f0549806f (patch) | |
| tree | 7ee74806627058a1cc5c871805ccbb9779990e98 /src | |
| parent | Fix rendering issue on panning with text tool (diff) | |
| download | inkscape-9248a27415b51ae5674dd79d1738cf8f0549806f.tar.gz inkscape-9248a27415b51ae5674dd79d1738cf8f0549806f.zip | |
Move from deprecated GTimeVal to g_get_monotonic_time()
Diffstat (limited to 'src')
| -rw-r--r-- | src/debug/timestamp.cpp | 5 | ||||
| -rw-r--r-- | src/display/drawing-shape.cpp | 9 | ||||
| -rw-r--r-- | src/display/sp-canvas.cpp | 68 | ||||
| -rw-r--r-- | src/display/sp-canvas.h | 2 | ||||
| -rwxr-xr-x | src/selection-chemistry.cpp | 5 | ||||
| -rw-r--r-- | src/splivarot.cpp | 12 | ||||
| -rw-r--r-- | src/ui/dialog/icon-preview.cpp | 9 |
7 files changed, 34 insertions, 76 deletions
diff --git a/src/debug/timestamp.cpp b/src/debug/timestamp.cpp index 14d211ef3..dab4e733a 100644 --- a/src/debug/timestamp.cpp +++ b/src/debug/timestamp.cpp @@ -23,9 +23,8 @@ namespace Inkscape { namespace Debug { std::shared_ptr<std::string> timestamp() { - GTimeVal timestamp; - g_get_current_time(×tamp); - gchar *value = g_strdup_printf( "%d.%06d", static_cast<gint>(timestamp.tv_sec), static_cast<gint>(timestamp.tv_usec) ); + gint64 micr = g_get_monotonic_time(); + gchar *value = g_strdup_printf("%.6f", (gdouble)micr / 1000000.0); std::shared_ptr<std::string> result = std::make_shared<std::string>(value); g_free(value); return result; diff --git a/src/display/drawing-shape.cpp b/src/display/drawing-shape.cpp index 20544e1be..70995073b 100644 --- a/src/display/drawing-shape.cpp +++ b/src/display/drawing-shape.cpp @@ -345,8 +345,8 @@ DrawingShape::_pickItem(Geom::Point const &p, double delta, unsigned flags) // fully transparent, no pick unless outline mode return nullptr; - GTimeVal tstart, tfinish; - g_get_current_time (&tstart); + + gint64 tstart = g_get_monotonic_time(); double width; if (pick_as_clip) { @@ -379,10 +379,9 @@ DrawingShape::_pickItem(Geom::Point const &p, double delta, unsigned flags) pathv_matrix_point_bbox_wind_distance(_curve->get_pathvector(), _ctm, p, nullptr, needfill? &wind : nullptr, &dist, 0.5, nullptr); } - g_get_current_time (&tfinish); - glong this_pick = (tfinish.tv_sec - tstart.tv_sec) * 1000000 + (tfinish.tv_usec - tstart.tv_usec); + gint64 tfinish = g_get_monotonic_time(); + gint64 this_pick = tfinish - tstart; //g_print ("pick time %lu\n", this_pick); - if (this_pick > 10000) { // slow picking, remember to skip several new picks _repick_after = this_pick / 5000; } diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 932e8755c..b33dd20b6 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -1022,10 +1022,7 @@ static void sp_canvas_init(SPCanvas *canvas) canvas->_delayrendering = 0; canvas->_totalelapsed = 0; canvas->_scrooling = false; - GTimeZone *tz = g_time_zone_new(nullptr); - canvas->_idle_time = g_date_time_new_now(tz); - g_time_zone_unref(tz); - + canvas->_idle_time = g_get_monotonic_time(); bool _is_dragging; #if defined(HAVE_LIBLCMS2) @@ -1058,9 +1055,6 @@ void SPCanvas::dispose(GObject *object) cairo_surface_destroy(canvas->_backing_store); canvas->_backing_store = nullptr; } - if (canvas->_idle_time) { - g_date_time_unref(canvas->_idle_time); - } #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 12, 0) if (canvas->_surface_for_similar) { cairo_surface_destroy(canvas->_surface_for_similar); @@ -2071,18 +2065,15 @@ void SPCanvas::paintSpliter() struct PaintRectSetup { Geom::IntRect canvas_rect; - GDateTime *start_time; + gint64 start_time; int max_pixels; Geom::Point mouse_loc; }; int SPCanvas::paintRectInternal(PaintRectSetup const *setup, Geom::IntRect const &this_rect) { - GTimeZone *tz = g_time_zone_new(nullptr); - GDateTime *now = g_date_time_new_now(tz); - g_time_zone_unref(tz); - gint64 elapsed = (gint64)g_date_time_difference(now, setup->start_time); - g_date_time_unref(now); + gint64 now = g_get_monotonic_time(); + gint64 elapsed = now - setup->start_time; // if we do canvas resize or panning we want the canvas not redraw in enought times // to make a smooth response. @@ -2244,13 +2235,9 @@ bool SPCanvas::paintRect(int xx0, int yy0, int xx1, int yy1) } // Start the clock - GTimeZone *tz = g_time_zone_new(nullptr); - setup.start_time = g_date_time_new_now(tz); - g_time_zone_unref(tz); + setup.start_time = g_get_monotonic_time(); // Go - bool ret = paintRectInternal(&setup, paint_rect); - g_date_time_unref(setup.start_time); - return ret; + return paintRectInternal(&setup, paint_rect); } void SPCanvas::forceFullRedrawAfterInterruptions(unsigned int count) @@ -2557,15 +2544,11 @@ gint SPCanvas::idle_handler(gpointer data) SPCanvas *canvas = SP_CANVAS (data); #ifdef DEBUG_PERFORMANCE static int totaloops = 1; - GTimeZone *tz = nullptr; - GDateTime *now = nullptr; + gint64 now = 0; gint64 elapsed = 0; if (!canvas->_delayrendering) { - tz = g_time_zone_new(nullptr); - now = g_date_time_new_now(tz); - g_time_zone_unref(tz); - elapsed = (gint64)g_date_time_difference(now, canvas->_idle_time); - g_date_time_unref(now); + now = g_get_monotonic_time(); + elapsed = now - canvas->_idle_time; g_message("[%i] start loop %i in split %i at %f", canvas->_idle_id, totaloops, canvas->_splits, canvas->_totalelapsed / (double)1000000 + elapsed / (double)1000000); } @@ -2578,11 +2561,8 @@ gint SPCanvas::idle_handler(gpointer data) #ifdef DEBUG_PERFORMANCE if (ret == 0 && !canvas->_delayrendering) { - tz = g_time_zone_new(nullptr); - now = g_date_time_new_now(tz); - g_time_zone_unref(tz); - elapsed = (gint64)g_date_time_difference(now, canvas->_idle_time); - g_date_time_unref(now); + now = g_get_monotonic_time(); + elapsed = now - canvas->_idle_time; g_message("[%i] loop ended unclean at %f", canvas->_idle_id, canvas->_totalelapsed / (double)1000000 + elapsed / (double)1000000); } @@ -2594,11 +2574,8 @@ gint SPCanvas::idle_handler(gpointer data) canvas->_scrooling = false; canvas->_forcefull = false; canvas->_delayrendering = 0; - tz = g_time_zone_new(nullptr); - now = g_date_time_new_now(tz); - g_time_zone_unref(tz); - elapsed = (gint64)g_date_time_difference(now, canvas->_idle_time); - g_date_time_unref(now); + now = g_get_monotonic_time(); + elapsed = now - canvas->_idle_time; canvas->_totalelapsed += elapsed; SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (desktop) { @@ -2635,10 +2612,7 @@ void SPCanvas::addIdle() { if (_idle_id == 0) { #ifdef DEBUG_PERFORMANCE - g_date_time_unref(_idle_time); - GTimeZone *tz = g_time_zone_new(nullptr); - _idle_time = g_date_time_new_now(tz); - g_time_zone_unref(tz); + _idle_time = g_get_monotonic_time(); #endif _idle_id = gdk_threads_add_idle_full(UPDATE_PRIORITY, idle_handler, this, nullptr); #ifdef DEBUG_PERFORMANCE @@ -2779,21 +2753,15 @@ void SPCanvas::updateNow() { if (_need_update) { #ifdef DEBUG_PERFORMANCE - GTimeZone *tz = g_time_zone_new(nullptr); - GDateTime *now = g_date_time_new_now(tz); - g_time_zone_unref(tz); - gint64 elapsed = (gint64)g_date_time_difference(now, _idle_time); - g_date_time_unref(now); + guint64 now = g_get_monotonic_time(); + gint64 elapsed = now - _idle_time; g_message("[%i] start updateNow(): %f at %f", _idle_id, elapsed / (double)1000000, _totalelapsed / (double)1000000 + elapsed / (double)1000000); #endif doUpdate(); #ifdef DEBUG_PERFORMANCE - tz = g_time_zone_new(nullptr); - now = g_date_time_new_now(tz); - g_time_zone_unref(tz); - elapsed = (gint64)g_date_time_difference(now, _idle_time); - g_date_time_unref(now); + now = g_get_monotonic_time(); + elapsed = now - _idle_time; g_message("[%i] end updateNow(): %f at %f", _idle_id, elapsed / (double)1000000, _totalelapsed / (double)1000000 + elapsed / (double)1000000); #endif diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index 3e7424363..48a404b43 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -210,7 +210,7 @@ public: bool _scrooling; int _delayrendering; int _device_scale; ///< Scale for high DPI montiors - GDateTime *_idle_time; + gint64 _idle_time; int _splits; gint64 _totalelapsed; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 242319809..332192048 100755 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3626,10 +3626,7 @@ void ObjectSet::createBitmapCopy() // Generate a random value from the current time (you may create bitmap from the same object(s) // multiple times, and this is done so that they don't clash) - GTimeVal cu; - g_get_current_time(&cu); - guint current = (int) (cu.tv_sec * 1000000 + cu.tv_usec) % 1024; - + guint current = guint(g_get_monotonic_time() % 1024); // Create the filename. gchar *const basename = g_strdup_printf("%s-%s-%u.png", doc->getDocumentName(), diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 71920559b..1a61b4e3d 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -2261,7 +2261,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju // globals for keeping track of accelerated simplify -static double previousTime = 0.0; +static gint64 previous_time = 0; static gdouble simplifyMultiply = 1.0; void @@ -2273,13 +2273,9 @@ sp_selected_path_simplify(SPDesktop *desktop) bool simplifyJustCoalesce = prefs->getBool("/options/simplifyjustcoalesce/value", false); //Get the current time - GTimeVal currentTimeVal; - g_get_current_time(¤tTimeVal); - double currentTime = currentTimeVal.tv_sec * 1000000 + - currentTimeVal.tv_usec; - + gint64 current_time = g_get_monotonic_time(); //Was the previous call to this function recent? (<0.5 sec) - if (previousTime > 0.0 && currentTime - previousTime < 500000.0) { + if (previous_time > 0 && current_time - previous_time < 500000) { // add to the threshold 1/2 of its original value simplifyMultiply += 0.5; @@ -2291,7 +2287,7 @@ sp_selected_path_simplify(SPDesktop *desktop) } //remember time for next call - previousTime = currentTime; + previous_time = current_time; //g_print("%g\n", simplify_threshold); diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 98160bd8f..735364a98 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -281,11 +281,10 @@ IconPreviewPanel::~IconPreviewPanel() static Glib::ustring getTimestr() { Glib::ustring str; - GTimeVal now = {0, 0}; - g_get_current_time(&now); - glong secs = now.tv_sec % 60; - glong mins = (now.tv_sec / 60) % 60; - gchar *ptr = g_strdup_printf(":%02ld:%02ld.%06ld", mins, secs, now.tv_usec); + gint64 micr = g_get_monotonic_time(); + gint64 mins = ((int)round(micr / 60000000)) % 60; + gdouble dsecs = micr / 1000000; + gchar *ptr = g_strdup_printf(":%02u:%f", mins, dsecs); str = ptr; g_free(ptr); ptr = 0; |
