Commit Graph

122 Commits

Author SHA1 Message Date
David Crawshaw 9308ad61ea app: android key code mapping to USB HID codes
Change-Id: I1225f51fd06a5f9a9f0fdf09096982df761b5a51
Reviewed-on: https://go-review.googlesource.com/13678
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-08-19 14:09:33 +00:00
David Crawshaw 377063dfa4 app: plumbing for physical android key events
This is only the first half of physical key event mapping. The
modifiers and hardware key codes will be in a followup CL. I'm
splitting this out because it covers two other parts of the problem:
first is maintaining a JNIEnv pointer for the main routine, the
second is access to the Android unicode key map. The NDK does not have
a method to give us the key mapping, so we get to it via
GoNativeActivity.

Tested with a USB keyboard. I'll attempt an abd-based unit test later,
but I suspect it will be difficult to set a device ID.

Change-Id: Ie93700d1f2a5d382a9b17cdd668cb4acaa6e4bcc
Reviewed-on: https://go-review.googlesource.com/13649
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-18 13:10:55 +00:00
David Crawshaw 0cfb79fc77 app: test painting using a screenshot
Also catches any bugs that cause painting to lock up after
rotation (of which there have been many).

Change-Id: I3783030efd2c342afebf2b861e9e9dc32e96f659
Reviewed-on: https://go-review.googlesource.com/13616
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-17 16:26:32 +00:00
David Crawshaw 99aacab40d app: attach main thread to the JNI
Ran into this while working on keyboard events. I'm a little surprised
this hasn't been a problem so far -- my understanding of the NDK
functions for working with a NativeActivity is that the require you
hold a valid JNI context before calling them.

Change-Id: Ifd322ef5e8406df648d1a8f667e5ce08ffef954d
Reviewed-on: https://go-review.googlesource.com/13648
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-17 14:38:43 +00:00
Nigel Tao f632204bcc event/config: rename to event/size.
Change-Id: I908b5f0818da32b2b040f430ebcc3762eb6f7570
Reviewed-on: https://go-review.googlesource.com/13601
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-13 13:31:00 +00:00
David Crawshaw ec91477003 app: mention wiki docs in app package docs
Change-Id: I5fc7fe86f47e117e2b09dd16d7a588374b32dd66
Reviewed-on: https://go-review.googlesource.com/13611
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-12 16:21:36 +00:00
Nigel Tao 4ee6e2bd6d app: fix s/spaces/tabs/.
Change-Id: I795a82a8549d250fb9ca33134248fb4ff12bd0a0
Reviewed-on: https://go-review.googlesource.com/13491
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-12 04:16:58 +00:00
David Crawshaw c2f4676407 app: fix X11 build
Change-Id: Ida7cd57eefac66bcff89720ac5c82015d1d37f00
Reviewed-on: https://go-review.googlesource.com/13540
Reviewed-by: Jeffrey Regan <jregan@google.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-11 19:16:57 +00:00
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
David Crawshaw d382b23901 app: plumb through iOS orientation
Change-Id: I9cfaf23219a8e7e15727bd7338503b9fbc4634a2
Reviewed-on: https://go-review.googlesource.com/13444
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-10 17:11:20 +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
Nigel Tao 8fffdfa9fd event/{mouse,touch}: work in float32 pixels, not geom.Pt.
Higher-level widget or animation libraries should probably work in
geom.Pt, but pixels instead of (1/72s of) inches seems a better fit for
lower-level event libraries. Needlessly converting from (float32) pixels
to (float32) points and back can be lossy and lead to off-by-one errors.

Change-Id: I68102e36f2574b07b44c6a1b7281f4f27f9174cf
Reviewed-on: https://go-review.googlesource.com/13002
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-04 07:35:09 +00:00
David Crawshaw 92213082f9 app: update EndPaint in test and documentation
Change-Id: I7c9e6edc2d50dca3c2d15426370d218d0c4dfe09
Reviewed-on: https://go-review.googlesource.com/13021
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-31 16:28:29 +00:00
David Crawshaw 0c8ff9f648 app, event/paint: plumb through paint Generation
Change-Id: I82bac0dc24943c64560a0bac4687cbbbb8b5c328
Reviewed-on: https://go-review.googlesource.com/12841
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-30 16:09:38 +00:00
Hyang-Ah (Hana) Kim 68f31e14ae mobile: limit build to linux/darwin.
Change-Id: I99f3841742e8f2ea098cfb08e8f5575c84f7cf75
Reviewed-on: https://go-review.googlesource.com/12850
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-29 20:28:35 +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 d691afa36e app: basic android app lifecycle test
Change-Id: I3db2d631e9be50b34ee9ac6df9615575cc1d6e33
Reviewed-on: https://go-review.googlesource.com/12642
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-28 15:24:53 +00:00
Nigel Tao cdc5281044 event/config: specify width and height in both pixels and points.
Change-Id: I494c17b2bad6c920ea20b22046d1d3fbc7b6b1d4
Reviewed-on: https://go-review.googlesource.com/12700
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-28 01:48:05 +00:00
Nigel Tao f2f4efe74b event/mouse: new package.
Change-Id: Idd30a70bf62971ecea8ee9db905d4a0a8baf6525
Reviewed-on: https://go-review.googlesource.com/12667
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-28 01:28:46 +00:00
David Crawshaw bd8a095b54 event/key: add Code type
Also add a few missing codes.

Change-Id: I26b6db31067c67107fe4db142ec9f48ff13cc53e
Reviewed-on: https://go-review.googlesource.com/12536
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-24 12:23:42 +00:00
David Crawshaw 2341c96d9d app: use isARepeat method instead of ARepeat prop
The property was only introduced in 10.10, and doesn't offer us
anything more than what the method gives us.

Fixes golang/go#11827.

Change-Id: I5a9f9b068b9f18acc85a68a37dae11f19df686a1
Reviewed-on: https://go-review.googlesource.com/12552
Reviewed-by: Andrey Petrov <shazow@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-23 12:08:15 +00:00
David Crawshaw de4ba64cf5 app, event/key: keyboard events
First cut of events from physical keyboards.
Simple darwin/amd64 implementation.

Change-Id: I6e9d0a253387c841864ca9845ee729ea4f7573c7
Reviewed-on: https://go-review.googlesource.com/11815
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-22 20:09:27 +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
Nigel Tao c4654583ad event/touch: rename TypeStart to TypeBegin.
Change-Id: Ie8392cd6167fca1c0a7f10192824300d7885151d
Reviewed-on: https://go-review.googlesource.com/12342
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-18 04:39:45 +00:00
David Crawshaw 9359647d9e app: remove Callbacks and Run
It has to go sometime.

Fixes golang/go#10896.

Change-Id: I2ac1437e1d5913c09060931454bf11c3f742ef87
Reviewed-on: https://go-review.googlesource.com/12337
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-17 17:58:59 +00:00
Nigel Tao 84f8e5edcc event: move event.Filter to app.Filter.
Change-Id: I11044a6e01b53e441c05fc1baec36718e783622f
Reviewed-on: https://go-review.googlesource.com/12288
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-17 01:18:36 +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
David Crawshaw d709f21793 app: fix darwin/arm build
Change-Id: I5ce658362ff24c7ed16a269eab7a5fcdcb5ad019
Reviewed-on: https://go-review.googlesource.com/12302
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-16 18:09:48 +00:00
Nigel Tao b43065626f app: rename EndDraw to EndPaint.
Change-Id: I3e38df0e21be2246dd16886fa00c9360d42db145
Reviewed-on: https://go-review.googlesource.com/12282
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 03:33:11 +00:00
Nigel Tao e4c6af17e3 event: rename event.Foo to foo.Event.
Fixes golang/go#10444

Change-Id: Ie5a8ab8a09b1b1a4f7037da7cf945d39ab6a98fc
Reviewed-on: https://go-review.googlesource.com/12225
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 01:03:51 +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 7deab368af app: ensure gl work is drained before endDraw
If a frame draw cycle does not end in a blocking GL call,
then the app package may process the <-endDraw before the
final <-gl.WorkAvailable, meaning some GL calls miss the
frame.

So we make sure the final GL call for a frame is blocking.

Fixes golang/go#11696.
Fixes golang/go#10688.

Change-Id: I39772a3308c98947b1f0838ad58d1d406a711e7f
Reviewed-on: https://go-review.googlesource.com/12123
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-14 10:21:53 +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
David Crawshaw 960fedd178 internal/mobileinit: new package for shared logic
Package app contains some logic that we want to share with
gobind-based libraries. So move it to a new internal package
that both can import.

Long term the log changes should be in the standard library,
but the Go tree is currently frozen.

Fixes golang/go#11630.

Change-Id: I9ff622fc499bf255bce18df23cb68b03f667947f
Reviewed-on: https://go-review.googlesource.com/11981
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-08 21:29:11 +00:00
David Crawshaw 28e6297551 app: update package docs for gomobile and events
Change-Id: I96e0e5fe7d5de9c04aee049b88efed4964fefc0d
Reviewed-on: https://go-review.googlesource.com/11921
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-07 11:34:25 +00:00
David Crawshaw ddd9618c5b app: darwin/amd64 rendering improvements
The full set of event.LifecycleStages are now plumbed through.

More user control over the window, in particular it:
- takes focus correctly on start
- can now be closed and minimized
- can be hidden (allowing testing of LifecycleStageAlive)

Flickering during resize has been eliminated by triggering draws from
a second thread. This encouraged the introduction of a dedicated draw
loop in Go, which makes responsibility for GL calls a little more
like android/x11.

Change-Id: I63982f20bd4859601e2a27915f60f6c8083a176f
Reviewed-on: https://go-review.googlesource.com/11733
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-06 06:21:37 +00:00
Nigel Tao 15dc27054b event: delete TouchType in favor of Change.
Change-Id: I8772c8d2690fbe6b636f1dcafe1393f6810d6716
Reviewed-on: https://go-review.googlesource.com/11822
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-03 01:56:41 +00:00
Nigel Tao c7c93d6952 app/debug: move to exp/app/debug.
Change-Id: I97f3585ff155e8c5b95c5bb32cfa793980c81a9a
Reviewed-on: https://go-review.googlesource.com/11821
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-30 23:41:11 +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 8de8fcfbf7 app/debug, exp/font: remove the freetype dependency.
Change-Id: Id71acfeb605995d8caf947d996a1375335410e08
Reviewed-on: https://go-review.googlesource.com/11668
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-30 23:03:35 +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 20f0df5da5 app: darwin/arm{,64} event model implementation
Change-Id: Ie04a58ac090d8916463586b5fadb14c5539a21dd
Reviewed-on: https://go-review.googlesource.com/11640
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-29 11:38:56 +00:00
David Crawshaw 9ed16d2774 app: leave GL buffer clearing to clients
It is already done in our examples and is missing from the linux/x11
implementation. If memory serves this is just long-standing
debugging cruft.

Change-Id: I1919a8704b11502fe8f402e3840bc5a1cd8b16e3
Reviewed-on: https://go-review.googlesource.com/11655
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-29 11:10: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
David Crawshaw 9cc656ecd6 app: darwin/amd64 event model implementation
Change-Id: I16d706131508bd27415f26c6bbb64210e0af2819
Reviewed-on: https://go-review.googlesource.com/11620
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-27 19:19:22 +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