function getFPS()

in 2019/media/sphericalOnCobaltTest.js [73:94]


  function getFPS() {
    if ('h5vcc' in window && 'cVal' in window.h5vcc) {
      // Query Cobalt for the average amount of time between the start of
      // each frame.  Translate that into a framerate and then update a
      // framerate counter on the window.
      var average_frame_time_in_us = window.h5vcc.cVal.getValue(
          'Renderer.Rasterize.DurationInterval.Avg');
      if (!average_frame_time_in_us || average_frame_time_in_us <= 0) {
        // In older versions of Cobalt use a different name for the framerate
        // counter, so try falling back to that if the first fails.
        average_frame_time_in_us = window.h5vcc.cVal.getValue(
            'Renderer.Rasterize.Duration.Avg');
      }
      if (average_frame_time_in_us && average_frame_time_in_us > 0) {
        // Convert frame time into frame rate (by taking the inverse).
        // We also multiply by 1000000 to convert from microseconds to
        // seconds.
        return Math.round(1000000.0 / average_frame_time_in_us);
      }
    }
    return 0;
  }