Commit Graph

38 Commits

Author SHA1 Message Date
David Crawshaw 0f9ce16152 app: plumb through android orientation
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>
2015-08-11 15:19:09 +00:00
David Crawshaw 354679495a app: always send paint event when bumping gen
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>
2015-08-11 14:52:42 +00:00
Nigel Tao 1df827c65a app: merge android.go with loop_android.go.
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>
2015-08-07 12:48:53 +00:00
David Crawshaw 5c91e60c93 app: android activity lifecycle awareness
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.

Fixes golang/go#11804.

Change-Id: Ia03e464aab5bc10ba75564b7ca11054515cda011
Reviewed-on: https://go-review.googlesource.com/12533
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-29 14:29:11 +00:00
David Crawshaw 34f7142b5a app: be more careful about android redraw events
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.

Fixes golang/go#11741.

Change-Id: I6b29b6a1e5743c612c9af2a8cce4260c5d7e9ca6
Reviewed-on: https://go-review.googlesource.com/12381
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-22 15:25:30 +00:00
Hyang-Ah (Hana) Kim 136fa9bbbb bind/java: reenable asset access.
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>
2015-07-16 21:15:37 +00:00
Nigel Tao a2120ea61f app: make gl.Viewport calls happen on 'the event thread'.
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>
2015-07-15 01:03:17 +00:00
David Crawshaw 8f20c3e9d3 app, cmd/gomobile: subclass NativeActivity
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>
2015-07-13 19:05:26 +00:00
Nigel Tao a5abc28279 app: consolidate multiple cgo directives into one.
Change-Id: Ie65251fe24063096cd95645089a222b597f3bd8b
Reviewed-on: https://go-review.googlesource.com/11666
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-30 23:04:34 +00:00
Nigel Tao 4f45fb5d7f app: remove some unnecessary logging.
Change-Id: Idf0e03e90a9cc2a497c4ac6ebde7a842d5f0a81b
Reviewed-on: https://go-review.googlesource.com/11606
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-30 03:36:16 +00:00
David Crawshaw 8bb4ca139b asset: move app.Open to its own package
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>
2015-06-29 21:49:28 +00:00
David Crawshaw 8144405762 app, bind: separate the app package from gobind
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>
2015-06-29 11:40:40 +00:00
David Crawshaw d1958fa5cf app: remove error return from Main
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>
2015-06-28 03:06:59 +00:00
Nigel Tao 42f0d17876 app: use one thread for both GL and other UI C code.
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>
2015-06-26 07:43:17 +00:00
Nigel Tao e47fb7683e app: delete the unused Config.ClassFinder method.
Change-Id: I8eea69f3ac6406fd58a9338f3aa358fead1afc0e
Reviewed-on: https://go-review.googlesource.com/11473
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-26 01:34:58 +00:00
Nigel Tao 0d468be861 app: fix onInputQueueDestroyed shadowing bug.
Change-Id: Ia225c944e76c9ccd3f9ab16d7d13afbcbf41fd16
Reviewed-on: https://go-review.googlesource.com/10560
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-06-01 04:35:06 +00:00
David Crawshaw 730f563fbc app: set timezone on app initialization
This trusts bionic's reading of the system clock.

Future work should address the fact we cannot read the Android
zoneinfo file.

Fixes golang/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>
2015-05-28 18:11:00 +00:00
David Crawshaw 5cddc1460e app: introduce Config and start registration
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.

Fixes golang/go#10686
Fixes golang/go#10461
Fixes golang/go#10442
Fixes golang/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>
2015-05-06 17:32:53 +00:00
Hyang-Ah (Hana) Kim 601608a0e0 bind/java: use the class loader cached during JNI_OnLoad call.
This allows the application class loader to be used when
the bind/java package or other part of JNI dynamically
loads java classes from a non-Java thread.

http://developer.android.com/training/articles/perf-jni.html#faq_FindClass

Fixes golang/go#10668.

Change-Id: I44df3a9362617fa6dd26ddf88247e4fdaee7c7e8
Reviewed-on: https://go-review.googlesource.com/9732
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-06 03:41:18 +00:00
David Crawshaw 66ea9e5b49 app: simplify and document init sequence
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>
2015-05-04 12:09:13 +00:00
David Crawshaw d77bba0a9f app: call main.main on app startup
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>
2015-04-17 16:08:58 +00:00
Burcu Dogan 2952048198 mobile/app: update the window width and height after rotation
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>
2015-04-11 11:51:47 +00:00
Hyang-Ah Hana Kim 595ca5ba2c app: initialize asset manager for gobind android app.
Tested manually by modifying example/libhello to read an asset file,
and checking crawshaw's balloon app continues to work.

Fixes golang/go#9422.

Change-Id: I17b25d9456a4023c68be1de82ee071ea01299e68
Reviewed-on: https://go-review.googlesource.com/5680
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-02-24 16:06:04 +00:00
David Crawshaw b2dee7a880 app, cmd/gomobile: expose an app.State variable
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>
2015-02-23 17:54:17 +00:00
David Crawshaw 8602f76ecd Revert "app: repalce JavaInit with RegisterAndroidInit"
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>
2015-02-10 19:28:17 +00:00
David Crawshaw b781b80ee8 app: repalce JavaInit with RegisterAndroidInit
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>
2015-02-10 18:52:00 +00:00
David Crawshaw 96c0ef1480 all: update docs to remove code.google.com
Fixes golang/go#9259.

Change-Id: I4768ce0a2abc56100e6616bacdf6aad196639b10
Reviewed-on: https://go-review.googlesource.com/1370
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2014-12-11 14:15:30 +00:00
David Crawshaw 32030f7750 app: build fake auxv
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>
2014-12-10 17:26:16 +00:00
David Crawshaw 2d6073265a x/mobile/app: Open function for basic asset management
LGTM=hyangah
R=hyangah
CC=golang-codereviews
https://golang.org/cl/187740044
2014-12-05 13:52:06 -05:00
Andrew Gerrand 9470e0ba58 go.mobile: use golang.org/x/... import paths
LGTM=bradfitz, rsc
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/162710043
2014-11-10 08:55:57 +11:00
Nigel Tao fab1e51609 go.mobile/geom: rename Scale to PixelsPerPt.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/160160043
2014-10-22 13:50:04 +11:00
David Crawshaw 7f2ffa1c58 go.mobile/app: remove enum not defined in earlier android platforms
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/143680044
2014-09-28 08:22:16 +10:00
David Crawshaw 56cb2dac4e go.mobile/app: Touch callback
LGTM=adg, nigeltao
R=nigeltao, adg, bryanturley
CC=davidday, golang-codereviews
https://golang.org/cl/140450043
2014-09-11 19:39:16 -04:00
David Crawshaw e27dbf7bf9 go.mobile/app: an exceedingly simple display loop
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
2014-09-09 19:51:04 -04:00
David Crawshaw 3d312b5a2b go.mobile: break dependency on gobind
Preparation for NativeActivity-based apps.

LGTM=nigeltao
R=golang-codereviews, nigeltao
CC=golang-codereviews
https://golang.org/cl/126520043
2014-09-03 09:03:00 -04:00
David Crawshaw 1e86c633f3 go.mobile/app: initialize java language binding
LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/114300043
2014-07-31 08:27:33 -04:00
David Crawshaw 3c9259eba0 go.mobile/app: Java thread check, extra doc comment
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/109670043
2014-07-10 13:13:00 -04:00
David Crawshaw d3521b7338 go.mobile/app: entry point for android shared libraries
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
2014-07-10 07:29:36 -04:00