Sample Android app for showcasing custom implementation of OpenGL camera preview display, written in Kotlin.
Structure inspired by
TextureFromCameraActivity in Grafika repository.
Stay as close to idiomatic Kotlin as possible.
Only place I knowingly depart from idiomatic Kotlin is the use of
lateinit. I decided to use
lateinitfor critical variables to catch bugs faster & fix them, rather then letting them pass with use of nullables &
Reduce complexity using single Executor & single Class.
I intentionally designed main class to be flat, to avoid complexity caused by
RenderThreads. A single
Executorreplaces most of their functionality.
Handle all state machines in a separate non-Activity class.
Activity lifecycle & Surface lifecycle doesn't match, so there is a need to account for both of them. I do this using Android Architecture Components
LifecycleObserver, to handle all in one single class. Grafika implementation handled all this in one Activity, which is fine for a sample app, but lacks extensibility.
Overcome possible thread problems using Annotations.
@MainThreadannotations are strategically placed to avoid GL operations on wrong threads.