Class FrameClock
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
FrameClock.FrameClock$Impl
This may be synced to the vertical refresh rate of the monitor, for example. Even when the frame clock uses a simple timer rather than a hardware-based vertical sync, the frame clock helps because it ensures everything paints at the same time (reducing the total number of frames).
The frame clock can also automatically stop painting when it knows the frames will not be visible, or scale back animation framerates.
GdkFrameClock is designed to be compatible with an OpenGL-based implementation
or with mozRequestAnimationFrame in Firefox, for example.
A frame clock is idle until someone requests a frame with
requestPhase(java.util.Set<org.gnome.gdk.FrameClockPhase>). At some later point that makes sense
for the synchronization being implemented, the clock will process a frame and
emit signals for each phase that has been requested. (See the signals of the
GdkFrameClock class for documentation of the phases.
FrameClockPhase.UPDATE and the Gdk.FrameClock::update signal
are most interesting for application writers, and are used to update the
animations, using the frame time given by getFrameTime().
The frame time is reported in microseconds and generally in the same
timescale as g_get_monotonic_time(), however, it is not the same
as g_get_monotonic_time(). The frame time does not advance during
the time a frame is being painted, and outside of a frame, an attempt
is made so that all calls to getFrameTime() that
are called at a “similar” time get the same value. This means that
if different animations are timed by looking at the difference in
time between an initial value from getFrameTime()
and the value inside the Gdk.FrameClock::update signal of the clock,
they will stay exactly synchronized.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theAfterPaintCallbackcallback.static interfaceFunctional interface declaration of theBeforePaintCallbackcallback.static classFrameClock.Builder<B extends FrameClock.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theFlushEventsCallbackcallback.static classThe FrameClock$Impl type represents a native instance of the abstract FrameClock class.static classstatic interfaceFunctional interface declaration of theLayoutCallbackcallback.static interfaceFunctional interface declaration of thePaintCallbackcallback.static interfaceFunctional interface declaration of theResumeEventsCallbackcallback.static interfaceFunctional interface declaration of theUpdateCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new FrameClock.FrameClock(MemorySegment address) Create a FrameClock proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected FrameClockasParent()Returns this instance as if it were its parent type.voidStarts updates for an animation.voidEmits the "after-paint" signal.voidEmits the "before-paint" signal.voidEmits the "flush-events" signal.voidEmits the "layout" signal.voidEmits the "paint" signal.voidEmits the "resume-events" signal.voidEmits the "update" signal.voidStops updates for an animation.@Nullable FrameTimingsGets the frame timings for the current frame.doublegetFps()Calculates the current frames-per-second, based on the frame timings offrameClock.longGdkFrameClockmaintains a 64-bit counter that increments for each frame drawn.longGets the time that should currently be used for animations.longReturns the frame counter for the oldest frame available in history.voidgetRefreshInfo(long baseTime, @Nullable Out<Long> refreshIntervalReturn, Out<Long> presentationTimeReturn) Predicts a presentation time, based on history.@Nullable FrameTimingsgetTimings(long frameCounter) Retrieves aGdkFrameTimingsobject holding timing information for the current frame or a recent frame.static @Nullable TypegetType()Get the GType of the FrameClock classThis signal ends processing of the frame.Begins processing of the frame.Used to flush pending motion events that are being batched up and compressed together.onLayout(FrameClock.LayoutCallback handler) Emitted as the second step of toolkit and application processing of the frame.onPaint(FrameClock.PaintCallback handler) Emitted as the third step of toolkit and application processing of the frame.Emitted after processing of the frame is finished.onUpdate(FrameClock.UpdateCallback handler) Emitted as the first step of toolkit and application processing of the frame.voidrequestPhase(Set<FrameClockPhase> phase) Asks the frame clock to run a particular phase.voidrequestPhase(FrameClockPhase... phase) Asks the frame clock to run a particular phase.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, builder, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
FrameClock
Create a FrameClock proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
FrameClock
public FrameClock()Creates a new FrameClock.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
beginUpdating
public void beginUpdating()Starts updates for an animation.Until a matching call to
endUpdating()is made, the frame clock will continually request a new frame with theFrameClockPhase.UPDATEphase. This function may be called multiple times and frames will be requested until gdk_frame_clock_end_updating() is called the same number of times. -
endUpdating
public void endUpdating()Stops updates for an animation.See the documentation for
beginUpdating(). -
getCurrentTimings
Gets the frame timings for the current frame.- Returns:
- the
GdkFrameTimingsfor the frame currently being processed, or even no frame is being processed, for the previous frame. Before any frames have been processed, returnsnull.
-
getFps
public double getFps()Calculates the current frames-per-second, based on the frame timings offrameClock.- Returns:
- the current fps, as a
double
-
getFrameCounter
public long getFrameCounter()GdkFrameClockmaintains a 64-bit counter that increments for each frame drawn.- Returns:
- inside frame processing, the value of the frame counter for the current frame. Outside of frame processing, the frame counter for the last frame.
-
getFrameTime
public long getFrameTime()Gets the time that should currently be used for animations.Inside the processing of a frame, it’s the time used to compute the animation position of everything in a frame. Outside of a frame, it's the time of the conceptual “previous frame,” which may be either the actual previous frame time, or if that’s too old, an updated time.
- Returns:
- a timestamp in microseconds, in the timescale of of g_get_monotonic_time().
-
getHistoryStart
public long getHistoryStart()Returns the frame counter for the oldest frame available in history.GdkFrameClockinternally keeps a history ofGdkFrameTimingsobjects for recent frames that can be retrieved withgetTimings(long). The set of stored frames is the set from the counter values given bygetHistoryStart()andgetFrameCounter(), inclusive.- Returns:
- the frame counter value for the oldest frame
that is available in the internal frame history of the
GdkFrameClock
-
getRefreshInfo
public void getRefreshInfo(long baseTime, @Nullable Out<Long> refreshIntervalReturn, Out<Long> presentationTimeReturn) Predicts a presentation time, based on history.Using the frame history stored in the frame clock, finds the last known presentation time and refresh interval, and assuming that presentation times are separated by the refresh interval, predicts a presentation time that is a multiple of the refresh interval after the last presentation time, and later than
baseTime.- Parameters:
baseTime- base time for determining a presentaton timerefreshIntervalReturn- a location to store the determined refresh interval, ornull. A default refresh interval of 1/60th of a second will be stored if no history is present.presentationTimeReturn- a location to store the next candidate presentation time after the given base time. 0 will be will be stored if no history is present.
-
getTimings
Retrieves aGdkFrameTimingsobject holding timing information for the current frame or a recent frame.The
GdkFrameTimingsobject may not yet be complete: seeFrameTimings.getComplete()andgetHistoryStart().- Parameters:
frameCounter- the frame counter value identifying the frame to be received- Returns:
- the
GdkFrameTimingsobject for the specified frame, ornullif it is not available
-
requestPhase
Asks the frame clock to run a particular phase.The signal corresponding the requested phase will be emitted the next time the frame clock processes. Multiple calls to gdk_frame_clock_request_phase() will be combined together and only one frame processed. If you are displaying animated content and want to continually request the
FrameClockPhase.UPDATEphase for a period of time, you should usebeginUpdating()instead, since this allows GTK to adjust system parameters to get maximally smooth animations.- Parameters:
phase- the phase that is requested
-
requestPhase
Asks the frame clock to run a particular phase.The signal corresponding the requested phase will be emitted the next time the frame clock processes. Multiple calls to gdk_frame_clock_request_phase() will be combined together and only one frame processed. If you are displaying animated content and want to continually request the
FrameClockPhase.UPDATEphase for a period of time, you should usebeginUpdating()instead, since this allows GTK to adjust system parameters to get maximally smooth animations.- Parameters:
phase- the phase that is requested
-
onAfterPaint
public SignalConnection<FrameClock.AfterPaintCallback> onAfterPaint(FrameClock.AfterPaintCallback handler) This signal ends processing of the frame.Applications should generally not handle this signal.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitAfterPaint
public void emitAfterPaint()Emits the "after-paint" signal. SeeonAfterPaint(org.gnome.gdk.FrameClock.AfterPaintCallback). -
onBeforePaint
public SignalConnection<FrameClock.BeforePaintCallback> onBeforePaint(FrameClock.BeforePaintCallback handler) Begins processing of the frame.Applications should generally not handle this signal.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitBeforePaint
public void emitBeforePaint()Emits the "before-paint" signal. SeeonBeforePaint(org.gnome.gdk.FrameClock.BeforePaintCallback). -
onFlushEvents
public SignalConnection<FrameClock.FlushEventsCallback> onFlushEvents(FrameClock.FlushEventsCallback handler) Used to flush pending motion events that are being batched up and compressed together.Applications should not handle this signal.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitFlushEvents
public void emitFlushEvents()Emits the "flush-events" signal. SeeonFlushEvents(org.gnome.gdk.FrameClock.FlushEventsCallback). -
onLayout
Emitted as the second step of toolkit and application processing of the frame.Any work to update sizes and positions of application elements should be performed. GTK normally handles this internally.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitLayout
public void emitLayout()Emits the "layout" signal. SeeonLayout(org.gnome.gdk.FrameClock.LayoutCallback). -
onPaint
Emitted as the third step of toolkit and application processing of the frame.The frame is repainted. GDK normally handles this internally and emits
Gdk.Surface::rendersignals which are turned into GtkWidget::snapshot signals by GTK.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPaint
public void emitPaint()Emits the "paint" signal. SeeonPaint(org.gnome.gdk.FrameClock.PaintCallback). -
onResumeEvents
public SignalConnection<FrameClock.ResumeEventsCallback> onResumeEvents(FrameClock.ResumeEventsCallback handler) Emitted after processing of the frame is finished.This signal is handled internally by GTK to resume normal event processing. Applications should not handle this signal.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitResumeEvents
public void emitResumeEvents()Emits the "resume-events" signal. SeeonResumeEvents(org.gnome.gdk.FrameClock.ResumeEventsCallback). -
onUpdate
Emitted as the first step of toolkit and application processing of the frame.Animations should be updated using
getFrameTime(). Applications can connect directly to this signal, or use gtk_widget_add_tick_callback() as a more convenient interface.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitUpdate
public void emitUpdate()Emits the "update" signal. SeeonUpdate(org.gnome.gdk.FrameClock.UpdateCallback).
-