Class FrameClock
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
FrameClock.FrameClockImpl
GdkFrameClock
tells the application when to update and repaint
a surface.
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
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theAfterPaintCallback
callback.static interface
Functional interface declaration of theBeforePaintCallback
callback.static class
FrameClock.Builder<B extends FrameClock.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theFlushEventsCallback
callback.static class
static class
The FrameClockImpl type represents a native instance of the abstract FrameClock class.static interface
Functional interface declaration of theLayoutCallback
callback.static interface
Functional interface declaration of thePaintCallback
callback.static interface
Functional interface declaration of theResumeEventsCallback
callback.static interface
Functional interface declaration of theUpdateCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionFrameClock
(MemorySegment address) Create a FrameClock proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected FrameClock
asParent()
Returns this instance as if it were its parent type.void
Starts updates for an animation.static FrameClock.Builder
<? extends FrameClock.Builder> builder()
AFrameClock.Builder
object constructs aFrameClock
with the specified properties.void
Emits the "after-paint" signal.void
Emits the "before-paint" signal.void
Emits the "flush-events" signal.void
Emits the "layout" signal.void
Emits the "paint" signal.void
Emits the "resume-events" signal.void
Emits the "update" signal.void
Stops updates for an animation.Gets the frame timings for the current frame.double
getFps()
Calculates the current frames-per-second, based on the frame timings of this FrameClock.long
GdkFrameClock
maintains a 64-bit counter that increments for each frame drawn.long
Gets the time that should currently be used for animations.long
Returns the frame counter for the oldest frame available in history.void
getRefreshInfo
(long baseTime, @Nullable Out<Long> refreshIntervalReturn, Out<Long> presentationTimeReturn) Predicts a presentation time, based on history.getTimings
(long frameCounter) Retrieves aGdkFrameTimings
object holding timing information for the current frame or a recent frame.static Type
getType()
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.void
requestPhase
(Set<FrameClockPhase> phase) Asks the frame clock to run a particular phase.void
requestPhase
(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, 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.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
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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.UPDATE
phase. 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
GdkFrameTimings
for 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 of this FrameClock.- Returns:
- the current fps, as a
double
-
getFrameCounter
public long getFrameCounter()GdkFrameClock
maintains 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.GdkFrameClock
internally keeps a history ofGdkFrameTimings
objects 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 @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 aGdkFrameTimings
object holding timing information for the current frame or a recent frame.The
GdkFrameTimings
object may not yet be complete: seeFrameTimings.getComplete()
andgetHistoryStart()
.- Parameters:
frameCounter
- the frame counter value identifying the frame to be received- Returns:
- the
GdkFrameTimings
object for the specified frame, ornull
if 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.UPDATE
phase 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.UPDATE
phase 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::render
signals 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)
. -
builder
AFrameClock.Builder
object constructs aFrameClock
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withFrameClock.Builder.build()
.
-