-
- All Implemented Interfaces:
-
android.view.Choreographer.FrameCallback,app.rive.runtime.kotlin.core.RefCount
public abstract class Renderer extends NativeObject implements Choreographer.FrameCallback
-
-
Field Summary
Fields Modifier and Type Field Description private BooleanisPlayingprivate BooleanisAttachedprivate final ObjectframeLockprivate final Floatwidthprivate final Floatheightprivate final FloataverageFpsprivate RendererTypetypeprivate final Booleantraceprivate final BooleanhasCppObjectprivate AtomicIntegerrefsprivate LongcppPointerprivate final List<RefCount>dependenciesprivate final IntegerrefCount
-
Constructor Summary
Constructors Constructor Description Renderer(RendererType type, Boolean trace)
-
Method Summary
Modifier and Type Method Description final BooleangetIsPlaying()final UnitsetIsPlaying(Boolean isPlaying)final BooleangetIsAttached()final UnitsetIsAttached(Boolean isAttached)final ObjectgetFrameLock()A lock to synchronize access to the C++ renderer object between the UI thread (which handles lifecycle events like delete()) and the Choreographer thread (which executesdoFrame()).final FloatgetWidth()final FloatgetHeight()final FloatgetAverageFps()final RendererTypegetType()final UnitsetType(RendererType type)final BooleangetTrace()final BooleangetHasCppObject()final AtomicIntegergetRefs()final UnitsetRefs(AtomicInteger refs)final LonggetCppPointer()final UnitsetCppPointer(Long cppPointer)final List<RefCount>getDependencies()IntegergetRefCount()UnitcppDelete(Long pointer)Unitmake()abstract Unitdraw()abstract Unitadvance(Float elapsed)final Unitstart()Starts the renderer and registers for frameCallbacks. final UnitsetSurface(Surface surface)Sets the drawing surface for the renderer. final Unitstop()Calls stopThread and removes any pending FrameCallbacks from the Choreographer. UnitscheduleFrame()final Unitsave()final Unitrestore()final Unitalign(Fit fit, Alignment alignment, RectF targetBounds, RectF sourceBounds, Float scaleFactor)final Unittransform(Float x, Float sy, Float sx, Float y, Float tx, Float ty)final Unitscale(Float sx, Float sy)final Unittranslate(Float dx, Float dy)UnitdoFrame(Long frameTimeNanos)Unitdelete()Schedules the deletion of the underlying C++ object using a two-phase disposal pattern. -
-
Constructor Detail
-
Renderer
Renderer(RendererType type, Boolean trace)
-
-
Method Detail
-
getIsPlaying
final Boolean getIsPlaying()
-
setIsPlaying
final Unit setIsPlaying(Boolean isPlaying)
-
getIsAttached
final Boolean getIsAttached()
-
setIsAttached
final Unit setIsAttached(Boolean isAttached)
-
getFrameLock
final Object getFrameLock()
A lock to synchronize access to the C++ renderer object between the UI thread (which handles lifecycle events like
delete()) and the Choreographer thread (which executesdoFrame()). This prevents a race condition where the UI thread might nullify the C++ pointer while the worker thread is still using it.
-
getAverageFps
final Float getAverageFps()
-
getType
@VisibleForTesting(otherwise = 2) final RendererType getType()
-
setType
final Unit setType(RendererType type)
-
getHasCppObject
final Boolean getHasCppObject()
-
getRefs
final AtomicInteger getRefs()
-
setRefs
final Unit setRefs(AtomicInteger refs)
-
getCppPointer
final Long getCppPointer()
-
setCppPointer
final Unit setCppPointer(Long cppPointer)
-
getDependencies
final List<RefCount> getDependencies()
-
getRefCount
Integer getRefCount()
-
draw
@WorkerThread() abstract Unit draw()
-
advance
@WorkerThread() abstract Unit advance(Float elapsed)
-
start
final Unit start()
Starts the renderer and registers for frameCallbacks.
Goal: When we trigger start, doFrame gets called once per frame until we stop or the animation finishes.
Gotchas:
scheduleFrame triggers callbacks to doFrame which in turn schedules more frames
If we call scheduleFrame multiple times we enter multiple parallel animations loops
To avoid this we check isPlaying and deregister FrameCallbacks when stop is called by users
-
setSurface
@Deprecated(message = This low-level method can cause crashes and will be removed. Prefer using higher-level APIs., level = DeprecationLevel.WARNING) final Unit setSurface(Surface surface)
Sets the drawing surface for the renderer.
-
stop
@CallSuper() final Unit stop()
Calls stopThread and removes any pending FrameCallbacks from the Choreographer.
Note: this is not safe to call from the animation thread. e.g inside draw/advance callbacks.
-
scheduleFrame
Unit scheduleFrame()
-
align
final Unit align(Fit fit, Alignment alignment, RectF targetBounds, RectF sourceBounds, Float scaleFactor)
-
delete
@CallSuper() Unit delete()
Schedules the deletion of the underlying C++ object using a two-phase disposal pattern.
UI Thread: Immediately marks the Kotlin object as disposed to prevent new operations. cppDelete schedules the actual deletion on the background render thread, ensuring the C++ object is deleted only after all work for this Renderer has completed.
Background Thread: cleans up resources after all pending work completes via disposeDependencies
-
-
-
-