2
0
mirror of synced 2025-02-22 06:28:04 +00:00

47 Commits

Author SHA1 Message Date
David Crawshaw
59ab51f73f gl: move to context methods
All OpenGL functions are now methods on a Context interface. The
gl.Context matches the one loaded into thread-local storage in C.

For mobile apps, the context is owned by an app.App. For now, it is
provided through the events channel on a lifecycle event. Long-term,
it should probably be available by a method on app.App, but this is
inherently racey with our current use of a channel to deliver events.

Shiny-based programs will have a gl.Context associated with a each
shiny.Window. The expectation is each Window will have different
contexts, allowing them to draw separately.

Change-Id: Ie09986fb74e493129f2ea542a151c95c6fa29812
Reviewed-on: https://go-review.googlesource.com/13431
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-23 23:46:16 +00:00
David Crawshaw
0064789433 exp/gl/glutil: remove global texture cache
It is now the user's job to track the lifetime of a glutil.Image
relative to a (currently implicit, soon to be explicit) GL context.

This is an attempt to move glutil.Image closer to the model for
buffers and textures in shiny. Long-term, I would like to adopt that
model, and this is a step in that direction. It also makes the
introduction of *gl.Context possible, so this is a pre-req for
cl/13431.

Change-Id: I8e6855211b3e67c97d5831c5c4e443e857c83d50
Reviewed-on: https://go-review.googlesource.com/14795
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-23 04:24:22 +00:00
David Crawshaw
eadadb8667 internal/mobileinit: standardize JNIEnv* access
Replace the direct access to JavaVM* and the global android Context
instance with a function responsible for running attached correctly
to the JVM. This saves having to replicate the logic for attaching an
OS thread to the JVM. While here, check for any unhandled Java
exceptions.

This supersedes cl/11812.

Change-Id: Ic9291fe64083d2bd983c4f8e309941b9c47d60c2
Reviewed-on: https://go-review.googlesource.com/14162
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-14 17:30:52 +00:00
Burcu Dogan
c76d5c8830 exp/sensor: remove the manager type
The manager type is not required, because the APIs don't allow
more than one event sources as they used to. In this CL, I am
flattening out the underlying implementations by removing the
manager type.

Change-Id: I3b606ac160b9cecd85cb657e3df1d7d789604764
Reviewed-on: https://go-review.googlesource.com/14293
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 16:23:41 +00:00
Burcu Dogan
043428404d exp/sensor: enable magnetometer on darwin{arm,arm64}
Change-Id: Ib188121501ac96cb8743e57f907b23d0fdfc37a0
Reviewed-on: https://go-review.googlesource.com/14292
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 04:58:24 +00:00
Burcu Dogan
d4f6353bc3 exp/sensor: support gyro events on darwin{arm,arm64}
Change-Id: I47aa12cc942261b8035312d0eeba0caf52b562ac
Reviewed-on: https://go-review.googlesource.com/14257
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 03:40:30 +00:00
Burcu Dogan
931e394f4f exp/sensor: don't allow delays smaller than 10ms on ios
"You can set the reporting interval to be as small as 10 milliseconds
(ms), which corresponds to a 100 Hz update rate, but most app operate
sufficiently with a larger interval."

from https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html

Larger delay values makes the library poll more frequently than needed.

Change-Id: Ie3057813209746bff00b8ef534c9ae239396366e
Reviewed-on: https://go-review.googlesource.com/14252
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-03 16:03:29 +00:00
Burcu Dogan
7e79d05d9e exp/sensor: set sensor interval on ios
Change-Id: I5559f721b2e2c7506db89f804569c0b0f78abea8
Reviewed-on: https://go-review.googlesource.com/14251
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 06:02:53 +00:00
Burcu Dogan
679c68b58d exp/sensor: block forever until new events occur on android
The former Reader inspired APIs were designed to timeout if no events
occur after an excessive amount of time. As we switch to the app
event based model, timing out is not required. We can block on
pollAll forever until new events arrive.

Change-Id: I086fc908ebfe6ae9bd96ce9199636ad0242bbec5
Reviewed-on: https://go-review.googlesource.com/14223
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 02:54:22 +00:00
Burcu Dogan
5651add1eb exp/sensor: initiate the darwin/{arm,arm64} backend
The CL provides accelerometer events only, upcoming CLs will add
support for gyroscope and magnetometer.

Change-Id: Ib5629ca7c49c9dfc8ca533fe7acde371efc102b2
Reviewed-on: https://go-review.googlesource.com/14036
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 02:10:28 +00:00
Burcu Dogan
9ddeada810 exp/sensor: provide sensor events from the app event channel
We are also limiting the number of sensor managers to one.
The application provide sensor events to third-party packages
by consuming them in the main.

An application will be able to consume the sensor events similar
to the other events.

package main

func main() {
  app.Main(func(a app.App) {
    // enables the accelerometer
    sensor.Enable(a, sensor.Accelerometer, 100*time.Millisecond)

    var sz size.Event
    for e := range a.Events() {
      switch e := app.Filter(e).(type) {
      case sensor.Event:
        log.Println(e)
      }
    }
  })
}

Change-Id: Iaad1c59f8d2322c7620df62ed9b9283c91746fa8
Reviewed-on: https://go-review.googlesource.com/13983
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-01 04:44:55 +00:00
Hyang-Ah (Hana) Kim
ac03bee8c3 exp/sprite/portable: fix broken build
Change-Id: I4eb6dc6a98366ad978f9fa2367b518ccfffee363
Reviewed-on: https://go-review.googlesource.com/13970
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-27 17:25:15 +00:00
Hana Kim
49a82fefe3 all: support go get golang.org/x/mobile/... on Windows
Fixes golang/go#12212
Workaround for golang/go#12261 until golang/go#9306 is fixed.

Change-Id: I51c1bcfc92c1553fe2132586a0234b1c1af6aeb1
Reviewed-on: https://go-review.googlesource.com/13745
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-24 21:09:04 +00:00
Nigel Tao
f4bcb3cc2e exp/sensor: fix nsec to usec conversion.
Also remove an unnecessary constant type conversion.

Change-Id: Iff466553fac450bd531785f4fb4e2be97a991a52
Reviewed-on: https://go-review.googlesource.com/13715
Reviewed-by: Burcu Dogan <jbd@google.com>
2015-08-21 01:49:41 +00:00
David Crawshaw
b5d916ab12 exp/gl/glutil: extra context error checking
Hoping to learn more so I can debug or replicate the darwin/amd64
builder failure, which is not creating a GL context.

Change-Id: I9f2fe54fbd9a072c65cd37c3b711554d4c71171f
Reviewed-on: https://go-review.googlesource.com/13693
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-18 19:25:21 +00:00
Burcu Dogan
25faf494e1 exp/sensor: use a better prefix in C not to pollute the namespace
Change-Id: Iac80d3ca61812ece64ae5127e4b5d1f8c54ff5b3
Reviewed-on: https://go-review.googlesource.com/13620
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-13 17:46:42 +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
Burcu Dogan
b5583e233e exp/sensor: reorg package to create space for darwin/arm,arm64 impl
Change-Id: I41e4088a92fff2f411dd82102fc3c421d2679c21
Reviewed-on: https://go-review.googlesource.com/13582
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-12 22:18:05 +00:00
Nigel Tao
723de9f813 exp/sprite/portable: update for x/image/draw API change.
The API change is http://golang.org/cl/12669

Change-Id: Ia34bb2efae808c45e9c0cfd4d3f510fdad549444
Reviewed-on: https://go-review.googlesource.com/12774
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-29 01:18:55 +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
Meir Fischer
a34303262d exp/audio: fix inability to use mono 8 format
There is no way to distinguish an unknown format from
Mono8 because Mono8 is zero. The current CL fixes this
issue by starting the format constants from iota + 1.

Change-Id: I8c709cdaff3bc46bcc15ab770cfcfd04c186034d
Reviewed-on: https://go-review.googlesource.com/12386
Reviewed-by: Burcu Dogan <jbd@google.com>
2015-07-24 05:53:18 +00:00
Nigel Tao
e5bb9c1e6f exp/gl/glutil: don't embed the *image.RGBA.
Embedding is more trouble than it's worth. For example, the image/draw
package will pick the slow code paths for an embedded *image.RGBA.

Change-Id: I64bd20a80814b838850950c05dd8257e5901aef7
Reviewed-on: https://go-review.googlesource.com/12567
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-24 05:26:20 +00:00
Nigel Tao
0d322895cb exp/sprite/portable: use golang.org/x/image/draw.
Change-Id: Ib41fd6614e3a5504d0cebe9a84b23a675d0e88fd
Reviewed-on: https://go-review.googlesource.com/12289
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-17 04:52:29 +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
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
Meir Fischer
7fb893ba43 mobile/exp/audio: use correct indefinite article prior to PCM
There is currently one usage of "an" prior to "PCM". The indefinite
article usage prior to an acronym is determined by the
pronunciation of that acronym's first letter. If the pronunciation
starts with a consonant, "a" is used. If the pronunciation starts
with a vowel, "an" is used.

Usage
https://en.wikipedia.org/wiki/Pulse-code_modulation

Note that there is currently a correct usage in the same file on a
different line: "a PCM header"

Change-Id: Id7749d20722a5cc9b96ecfe466be66fe3c76ab2b
Reviewed-on: https://go-review.googlesource.com/12083
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-13 15:00:26 +00:00
Burcu Dogan
adcf40b30c exp/audio/al: avoid creation of multiple contexts
This CL reverts the changes made in golang/go#11299.

Allowing creation of multiple contexts break the case of multiple
third party packages depending on the al bindings. These packages
need to make sure that there is a valid current context or initiate
and make a context current. Packages racing to create and make a
context current is what we would like to avoid.

Therefore, al bindings will support only a single context that is
initiated during OpenDevice.

Fixes golang/go#11385.

Change-Id: I662f70e49d12833a545005cf0724cc21f67bea09
Reviewed-on: https://go-review.googlesource.com/12001
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-11 16:23:18 +00:00
Nigel Tao
8631054b13 exp/app/debug: fit the FPS counter's aspect ratio to the backing image.
Ever since we moved to a bitmap font instead of using freetype, the backing
image's dimensions are 43x9, not 50x12, and we might as well match. For
example, the output will be exactly 43x9 pixels at 72DPI, or 86x18 pixels at
144DPI, etc.

Change-Id: I99975cc780760b28b73fbf6d55befbe500f1a6e1
Reviewed-on: https://go-review.googlesource.com/11880
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-04 02:53:51 +00:00
Nigel Tao
f464c65ce4 exp/gl/glutil: fix test for the foo to exp/foo package rename.
Change-Id: I8709146467d15f59433783759a51a1d0a59cdcfc
Reviewed-on: https://go-review.googlesource.com/11857
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-03 01:37:31 +00:00
Nigel Tao
467d8559f2 f32: move to exp/f32.
In the long term, a lot of this package should be removed in favor of the
golang.org/x/image/math/f32 package. The latter is the common location for
matrix types shared across graphics libraries. For example, the
golang.org/x/image/draw package refers to golang.org/x/image/math/f64.

Change-Id: I9d7ccd3cb35912e0d9dc5bd46c919516ea840340
Reviewed-on: https://go-review.googlesource.com/11856
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-03 01:37:12 +00:00
Nigel Tao
bd8fa0d7bb gl/glutil: move to exp/gl/glutil.
Change-Id: I310c365300cb3fbf8a1abb630e26661fa7ef4844
Reviewed-on: https://go-review.googlesource.com/11824
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-01 11:41:50 +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
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
Burcu Dogan
383ad68fc0 exp/audio: APIs should not use Context pointer type
This CL is a followup of CL/11315 where it is suggested to remove
Context pointer types from the signatures.

Change-Id: Ice68bfabad0e345f7d93102257a99402be8760b5
Reviewed-on: https://go-review.googlesource.com/11560
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-30 06:09:10 +00:00
Nigel Tao
d06bbc53e4 exp/audio/al: use the standard log library, if al_init fails.
This means that there's only one adb log prefix that Go app developers
need to watch: GoLog.

Change-Id: I562566b92a7bba19f7c7a9cc71315bea02844db1
Reviewed-on: https://go-review.googlesource.com/11609
Reviewed-by: Burcu Dogan <jbd@google.com>
2015-06-30 06:08:38 +00:00
Nigel Tao
d1d3d8a5a0 exp/audio/al: delete a debugging log message.
This was accidentally introduced in
https://go-review.googlesource.com/#/c/11351/

Change-Id: Icc9bc9ccb97e48d376e0da440b72631e605a0a15
Reviewed-on: https://go-review.googlesource.com/11608
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-29 04:33:40 +00:00
Nigel Tao
b6ec031d27 exp/audio/al: call log.Fatalf for a dlsym failure.
Change-Id: I197e101f2b93c2aa9dc69cb697afa68a69142783
Reviewed-on: https://go-review.googlesource.com/11537
Reviewed-by: Burcu Dogan <jbd@google.com>
2015-06-29 01:50:48 +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
Burcu Dogan
0a8a8b8cb6 exp/audio/al,cmd/gomobile: fix the broken build
Change-Id: Ia2da7d987f253c11a62843f54051c9d18c1612b5
Reviewed-on: https://go-review.googlesource.com/11521
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-26 07:40:05 +00:00
Burcu Dogan
25dc511cde exp/audio: allow multiple instances of al.Context
Fixes golang/go#11299.

Change-Id: Ie59981a0515abcf015c7b22d05d2cdbb8be35f56
Reviewed-on: https://go-review.googlesource.com/11315
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-26 06:57:01 +00:00
Nigel Tao
229b9af752 exp/sprite/portable: unbreak test.
The test was broken with the foo -> exp/foo move.

Change-Id: Ie2bdf54f6da0365d2e0332bcacdd2b7a000c950c
Reviewed-on: https://go-review.googlesource.com/11392
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-24 23:49:55 +00:00
Burcu Dogan
1d641b5393 audio: move to exp/audio
Change-Id: I8640b1a38a292972db6dd00506e38c89470b2c15
Reviewed-on: https://go-review.googlesource.com/11311
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-21 18:18:56 +00:00
Burcu Dogan
e9faa8965b sensor: move to exp/sensor
Change-Id: I707a1555952355ccdd5e851062c4749dc94544eb
Reviewed-on: https://go-review.googlesource.com/11312
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-21 07:47:51 +00:00
Nigel Tao
c0c696a96d sprite: move to exp/sprite.
Change-Id: Idfdc0c192d7e6d50e1063b2eb582bbe05294643a
Reviewed-on: https://go-review.googlesource.com/11230
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-21 03:08:52 +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
Nigel Tao
93e2526d55 exp: add a new directory for experimental packages.
Change-Id: I80ebfa6c7e79c1985262fe1572a927ce60df6946
Reviewed-on: https://go-review.googlesource.com/11118
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-16 21:06:44 +00:00