While I'm here, make pixelsPerPt local on android and darwin/amd64.
The one place where it's global is darwin/arm, which has another
similar global (screenScale).
Change-Id: I5897e7e5341afca1976fdf0215fb4f6fe2f411be
Reviewed-on: https://go-review.googlesource.com/13446
Reviewed-by: Nigel Tao <nigeltao@golang.org>
When the generation number is bumped, the <-endPaint case will drop
any old paints. So if a new paint isn't sent to replace it, the app
locks up.
This is a bug that looks like it crept into cl/12533 just before it
was submitted. (Sorry.) I'm working on tests as part of adding
android orientation support.
Change-Id: I6b62bdc6774e090b67a5577c3eae7355e3937894
Reviewed-on: https://go-review.googlesource.com/13445
Reviewed-by: Nigel Tao <nigeltao@golang.org>
There's no need for more than one Android .go file.
Change-Id: I75f5ced5680088b0ddbe5c700981b9a595d9e321
Reviewed-on: https://go-review.googlesource.com/13343
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This CL fixes two bugs in the existing app implementation on android.
The first, is it assumed a single NativeActivity instance is created
per process. This is not true. If you open an app, hit the back
button, then open it again, the original activity is destroyed and a
new one is created. So only call main.main in the first onCreate.
The second bug has to do with window lifetimes. Previously we only
processed GL work while the window existed, as part of a paint cycle.
This missed GL events called as part of a lifecycle downgrade when
the window was destroyed. (I.e. the contents of onStop.) This CL
fixes this by making the main android event processing loop last for
the life of the process, not the window.
Fixesgolang/go#11804.
Change-Id: Ia03e464aab5bc10ba75564b7ca11054515cda011
Reviewed-on: https://go-review.googlesource.com/12533
Reviewed-by: Nigel Tao <nigeltao@golang.org>
EGL is a poor source of window dimensions. On some fraction of
rotations, it reported the old dimensions. Switch to extracting the
data from ANativeWindow, which appears to be more reliable.
While here, plumb through orientation, and follow the recommendation
in the Android platform docs to block onNativeWindowRedrawNeeded
until the draw is complete.
Fixesgolang/go#11741.
Change-Id: I6b29b6a1e5743c612c9af2a8cce4260c5d7e9ca6
Reviewed-on: https://go-review.googlesource.com/12381
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This is done by moving app.Context to internal/mobileinit,
introducing mobileinit.SetCurrentContext and,
making bind/java depend on it.
TODO: check gomobile bind's proguard rule - context lookup
was implemented through reflection on android.app.AppGlobals class.
Change-Id: Ieb6ad503eeef8c2c1c5836a21c667938c5a701a2
Reviewed-on: https://go-review.googlesource.com/12279
Reviewed-by: David Crawshaw <crawshaw@golang.org>
The gl package is not safe for concurrent use.
Change-Id: Ib0e7908746ea3a6520b2ce2f5d8aa7233ab2642c
Reviewed-on: https://go-review.googlesource.com/12165
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Subclassing NativeActivity makes two things possible. Firstly, we can
implement an InputConnection to offer good support for IMEs,
necessary for good keyboard support. Secondly, we can use it to
overlay WebViews onto the NativeActivity.
But to sublcass NativeActivity, we need to compile Java. To keep the
toolchain go gettable, this is done with go generate.
While here, check the exception after FindClass. Apparently it can
throw an exception.
Updates golang/go#9361.
Updates golang/go#10247.
Change-Id: I672545997f0c9a7580f06988a273c03404772247
Reviewed-on: https://go-review.googlesource.com/11980
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This does not break the dependency on the app package's AndroidContext
for loading assets on android. A potential answer for gobind-based
apps: add a SetAndroidContext method to app.Context. But I'll explore
that separately after the long weekend.
Change-Id: I812f899740e288c379eee7900f42d9d53926d4ce
Reviewed-on: https://go-review.googlesource.com/11675
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Historically, the app package implemented Go runtime initialization.
This was convoluted, so the package was used both by all-Go apps
(currently based on Android's NativeActivity) and bind-based apps.
With Go 1.5 we have -buildmode=c-shared, which does a lot of the work
of the old app package. That code was removed a while back, but both
all-Go and gobind-based apps still used package app. The intermingled
initialization processes led to some strange states.
This CL separates gobind-based apps completely from the app package.
As part of that users are now expected to use System.loadLibrary
themselves. (A future CL may want to make the loadLibrary call part
of the .aar generated by gomobile bind.)
Delete the libhello example, which has been replaced by gomobile bind,
which could do with its own example at some point. Also delete the
libhellojni example, which now has nothing to do with the x/mobile
repository.
Change-Id: I444397f246dbafe81e5c53532eb482c197d26f70
Reviewed-on: https://go-review.googlesource.com/11654
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Move runtime.LockOSThread from the portable Main to the
platform-specific android main. For darwin, calling LockOSThread in
Main is too late, there has been enough time for the goroutine
calling it to jump off the initial OS thread. For darwin we call
LockOSThread from an init function, which the runtime keeps on the
first thread. For Android we call LockOSThread only to maintain the
thread-local storage for the GL context that is created later, so
it is safe to call it from func main.
Also remove TODOs about starting a gobind app on Android, which
will be simplified in a followup CL.
Tested on darwin/amd64 and android. Not tested on X11.
Change-Id: I34c56abf8b1292959d4d508bfade287d196c0380
Reviewed-on: https://go-review.googlesource.com/11653
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This change will break Darwin. I have only built and tested this on
desktop linux and Android linux. A follow-up CL will fix Darwin.
Currently, OpenGL gets its own thread, and UI C code (e.g. the Android
event loop, or the X11 event loop) gets its own thread. This relies on
multiple system-provided UI-related C libraries working nicely together,
even when running on different threads. Keeping all the C code on the
one thread seems more sound.
As side-effects:
- In package app/debug, DrawFPS now takes an explicit Config.
- In package app, some callbacks now take an explicit Config.
- In package exp/sprite, Render now takes an explicit Config.
- In package event, there are new events (Config, Draw, Lifecycle),
and an event filter mechanism to replace multiple app Callbacks.
- In package geom, the deprecated Width, Height and PixelsPerPt global
variables were removed in favor of an event.Config that is
explicitly passed around (and does not require mutex-locking).
Converting a geom.Pt to pixels now requires passing a pixelsPerPt.
- In package gl, the Do, Start and Stop functions are removed, as well
as the need to call Start in its own goroutine. There is no longer a
separate GL thread. Instead, package app explicitly performs any GL
work (gl.DoWork) when some is available (gl.WorkAvailable).
- In package gl/glutil, Image.Draw now takes an explicit Config.
Callbacks are no longer executed on 'the UI thread'.
Changing the app programming model from callbacks to events (since a
channel of events works with select) will be a follow-up change.
Change-Id: Id9865cd9ee1c45a98c613e9021a63c17226a64b1
Reviewed-on: https://go-review.googlesource.com/11351
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This trusts bionic's reading of the system clock.
Future work should address the fact we cannot read the Android
zoneinfo file.
Fixesgolang/go#10857.
Change-Id: I5a684fecc920dce5ab8f624658e91d9e2d71738d
Reviewed-on: https://go-review.googlesource.com/10299
Reviewed-by: Elias Naur <elias.naur@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Config provides a way to concurrently access Width and Height.
Register provides a way for packages to run code on app state change
without plumbing changes all the way to the process main function.
This is motivated by gl/glutil.Image which needs to rebuild its
textures on start/stop and can be deeply nested.
(See golang.org/cl/9707 for the followup.)
Tested manually on android and darwin/amd64. Doing this kind makes it
clear any CL modifying this code needs a lot of manual testing right
now, so some kind of trybot support is something I'm going to
prioritise.
Fixesgolang/go#10686Fixesgolang/go#10461Fixesgolang/go#10442Fixesgolang/go#10226
Updates golang/go#10327
Change-Id: I2882ebf3995b6ed857cda823e94fbb17c54b43a8
Reviewed-on: https://go-review.googlesource.com/9708
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
The global constructor added for -buildmode=c-shared takes care
of a lot of the messier steps that were being done here.
Change-Id: I00525765855b2ad0fcecb0639d6a7ee3feea9ed9
Reviewed-on: https://go-review.googlesource.com/9648
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
There is some cleanup to be done in this package now, but I'm
deferring it until later in the cycle.
We should probably also change the semantics slightly: main should
be called for all-Go apps (that is, apps that use NativeActivity),
but it would be more consistent with buildmode=c-shared and c-archive
if we did not call main for Go shared libraries being included in
Java android apps.
Change-Id: I13ca797a478edb22b0c602c1ee6e616fe4fea1e6
Reviewed-on: https://go-review.googlesource.com/9016
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Orientation invokes onNativeWindowRedrawNeeded.
Requery the window width and height when redraw needed.
Change-Id: I45816f13b42db38e71d28cb05bf7cfffda75882c
Reviewed-on: https://go-review.googlesource.com/8700
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Tested manually by modifying example/libhello to read an asset file,
and checking crawshaw's balloon app continues to work.
Fixesgolang/go#9422.
Change-Id: I17b25d9456a4023c68be1de82ee071ea01299e68
Reviewed-on: https://go-review.googlesource.com/5680
Reviewed-by: David Crawshaw <crawshaw@golang.org>
The State can be used in the Start callback (and lazily-initialized
packages) instead of JavaInit. This stores a reference to the
android.context.Context for the (future) keyboard package and for
setting TMPDIR.
Second attempt at https://golang.org/cl/4400.
Change-Id: I673997b26ab25ce5140cb31950593d8c6dbd9c51
Reviewed-on: https://go-review.googlesource.com/5555
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Not thought through. For gobind-based apps, JNI_OnLoad is called and there is never any NativeActivity.
This reverts commit b781b80ee8.
Change-Id: Ib076f30d144cbacb7926d54981ac86bbb8a5a4ff
Reviewed-on: https://go-review.googlesource.com/4440
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
I am working on a virtual keyboard package that needs access to the
*ANativeActivity. As the *ANativeActivity contains *JavaVM, this CL
deprecates JavaInit. I'll remove it in a subsequent CL that updates
gobind to use RegisterAndroidInit.
Change-Id: Ib1d60bbaac5de4583b368c93ab90b764c6081291
Reviewed-on: https://go-review.googlesource.com/4400
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Some Android systems cannot read from /proc/self/auxv. Work around
this by creating a minimal fake auxv for the Go runtime.
Fixes#9229
Change-Id: Id2d743f43d91be23006aac708a5b5b5cd60a6dca
Reviewed-on: https://go-review.googlesource.com/1284
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Missing many features (like event processing). This is
just enough to get example/basic working.
LGTM=nigeltao
R=golang-codereviews, capnm9, bryanturley, nigeltao, crawshaw
CC=golang-codereviews
https://golang.org/cl/131030043
This is the minimum amount of machinery necessary to get
libgojni.so loading and callable from an Android App.
To keep impact on the Go runtime small, we construct an
auxv array here from /proc/self/auxv.
LGTM=minux, adonovan
R=adonovan, golang-codereviews, minux, bradfitz
CC=golang-codereviews
https://golang.org/cl/107500043