Commit Graph

113 Commits

Author SHA1 Message Date
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
Nigel Tao 4d3dd47e87 app/debug: use the *image.RGBA drawing fast path.
On my 2013 Nexus 7, a simple

start := time.Now()
draw.Draw(etc)
log.Printf("draw.Draw took %v", time.Since(start))

around the draw.Draw call dropped from 12ms to 30µs.

Change-Id: I12aea4a4ade07eedb8ee86f7c8d4a4ed49f39f36
Reviewed-on: https://go-review.googlesource.com/11299
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-23 04:51:34 +00:00
Nigel Tao 981e383923 font: move to exp/font.
Change-Id: I62d5bcd829cb35e13843586b25829938778c79f5
Reviewed-on: https://go-review.googlesource.com/11133
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-16 21:35:30 +00:00
Jihyun Yu df8025159b app: move x11 API calls to GL thread
x11/gl is not thread-safe, so all x11/gl related API should be called
from one thread. There's already a dedicated thread for GL calls, so
move all x11 API calls to GL thread using gl.Do(...)

Fixes golang/go#11066

Change-Id: If84a8d56e978ce30d7fbbc310740fcc794ce61d7
Reviewed-on: https://go-review.googlesource.com/10744
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-11 16:42:09 +00:00
Hyang-Ah (Hana) Kim 1f1d6efd3f app: use more obscure names for objective-c classes.
Change AppDelegate, AppController to GoAppAppDelegate,
GoAppAppController - which are ugly enough so gobind users
is unlikely to use in their objective-c code.

Change-Id: I69305994a83405a1d8499df661bd5f63757a7fd6
Reviewed-on: https://go-review.googlesource.com/10852
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-09 20:50:37 +00:00
Hyang-Ah (Hana) Kim b6fda3dde1 app: fix broken build for armx.
Change-Id: I8cebd1fc3bd4cbc3113ea032d6d28177a1f31362
Reviewed-on: https://go-review.googlesource.com/10804
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-08 20:57:53 +00:00
Burcu Dogan 10cf0275e0 mobile/app: remove the callbacks declaration in the darwin/arm backend
Change-Id: I3dc03f63b9bb7ed0bd6f771bad8ac75f0cddbe35
Reviewed-on: https://go-review.googlesource.com/10127
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-08 06:10:58 +00:00
David Crawshaw 1927b21e90 app: add sync import
Fixes golang/go#11054.

Change-Id: If915f67d35639fc31cbe220872186a69c34710b5
Reviewed-on: https://go-review.googlesource.com/10700
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-04 18:00:18 +00:00
Jihyun Yu 019f8eb658 app: fix bug on linux/x11
- Fix hangs on linux/x11. x11-related code remains outdated since
   068a51c19, which seperates GL calls to dedicated thread.  Update x11
   code to work with GL thread.
 - Fix bug on coordinate system. x11 has same coordinate system with
   android, (0,0) on top-left.

Change-Id: I0b3ab97fd4842b1c9f730e1c90a5840f540fcb7a
Reviewed-on: https://go-review.googlesource.com/10623
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-03 14:42:55 +00:00
David Crawshaw 068a51c195 gl: batch calls onto a dedicated context thread
All GL function calls fill out a C.struct_fnargs and drop it on the
work queue. The Start function drains the work queue and hands
over a batch of calls to C.process which runs them. This allows
multiple GL calls to be executed in a single cgo call.

A GL call is marked as blocking if it returns a value, or if it
takes a Go pointer. In this case the call will not return until
C.process sends a value on the retvalue channel.

Change-Id: I4c76b2a8ad55f57b0c98d200d0fb708d4634e042
Reviewed-on: https://go-review.googlesource.com/10452
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-01 15:35:03 +00:00