'Gtk screen syncronization

I am using Gtk to control the image display on my screen. I need the monitor to be syncronized with the software in all frames. For this, I am using defining on the gtk_widget_add_tick_callback() the change in the image (PixBuf) that is displayed in my screen.

I am point a photodiode to my screen while changing the color from black to white every frame at 60 Hz. The intensity measured on my photodiode is:

enter image description here

where in the y axis is the photodiode voltage and in the x-axis the bin (proportional to time). As expected, I have this very well defined changes in the intensity when the screen changes from white to black. I.e. each change in the signal from 0 to 0.2 is due to the screen color changing from black to white.

However, randomly, if I run the same code, sometimes the screen seems to skip some frames as you can see in this example:

enter image description here

I am not sure why this happens. To debug, I looked at the displayed time of each frame using gdk_frame_clock_get_frame_time() which shows that each frames was only displayed for 16 ms (due to the 60 Hz monitor refresh frame rate). The displayed time of each frame is plotted here: [! enter image description here

where in the y axis is the time and the x-axis the frame bin (which is the same as in the other graphs).

Does anyone have any idea why this is happening? From the Gtk timings, it seems that Gtk is working as it should, but the output is not what it should be. Also, does anyone has any idea on how I could fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source