2014-09-09 23:51:04 +00:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <android/log.h>
|
|
|
|
#include <android/native_activity.h>
|
2014-09-11 23:39:16 +00:00
|
|
|
#include <android/input.h>
|
2014-09-09 23:51:04 +00:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <GLES/gl.h>
|
|
|
|
|
|
|
|
// TODO(crawshaw): Test configuration on more devices.
|
|
|
|
const EGLint RGB_888[] = {
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_DEPTH_SIZE, 16,
|
|
|
|
EGL_CONFIG_CAVEAT, EGL_NONE,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
EGLint windowWidth;
|
|
|
|
EGLint windowHeight;
|
|
|
|
EGLDisplay display;
|
|
|
|
EGLSurface surface;
|
|
|
|
|
|
|
|
#define LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, "Go", __VA_ARGS__)
|
|
|
|
|
2015-04-09 19:00:55 +00:00
|
|
|
void querySurfaceWidthAndHeight() {
|
|
|
|
eglQuerySurface(display, surface, EGL_WIDTH, &windowWidth);
|
|
|
|
eglQuerySurface(display, surface, EGL_HEIGHT, &windowHeight);
|
|
|
|
}
|
|
|
|
|
2014-09-09 23:51:04 +00:00
|
|
|
void createEGLWindow(ANativeWindow* window) {
|
|
|
|
EGLint numConfigs, format;
|
|
|
|
EGLConfig config;
|
|
|
|
EGLContext context;
|
|
|
|
|
|
|
|
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
|
|
if (!eglInitialize(display, 0, 0)) {
|
|
|
|
LOG_ERROR("EGL initialize failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglChooseConfig(display, RGB_888, &config, 1, &numConfigs)) {
|
|
|
|
LOG_ERROR("EGL choose RGB_888 config failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (numConfigs <= 0) {
|
|
|
|
LOG_ERROR("EGL no config found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
|
|
|
|
if (ANativeWindow_setBuffersGeometry(window, 0, 0, format) != 0) {
|
|
|
|
LOG_ERROR("EGL set buffers geometry failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface = eglCreateWindowSurface(display, config, window, NULL);
|
|
|
|
if (surface == EGL_NO_SURFACE) {
|
|
|
|
LOG_ERROR("EGL create surface failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
|
|
|
context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
|
|
|
|
|
|
|
|
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
|
|
|
|
LOG_ERROR("eglMakeCurrent failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-09 19:00:55 +00:00
|
|
|
querySurfaceWidthAndHeight();
|
2014-09-09 23:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef LOG_ERROR
|
|
|
|
*/
|
|
|
|
import "C"
|
2014-09-11 23:39:16 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2014-11-09 21:55:57 +00:00
|
|
|
"golang.org/x/mobile/event"
|
|
|
|
"golang.org/x/mobile/geom"
|
|
|
|
"golang.org/x/mobile/gl"
|
2014-09-11 23:39:16 +00:00
|
|
|
)
|
|
|
|
|
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-23 06:41:48 +00:00
|
|
|
var firstWindowDraw = true
|
2014-09-09 23:51:04 +00:00
|
|
|
|
2015-06-27 22:32:29 +00:00
|
|
|
func windowDraw(w *C.ANativeWindow, queue *C.AInputQueue, donec chan struct{}) (done bool) {
|
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-23 06:41:48 +00:00
|
|
|
C.createEGLWindow(w)
|
2014-09-11 23:39:16 +00:00
|
|
|
|
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-23 06:41:48 +00:00
|
|
|
// TODO: is this needed if we also have the "case <-windowRedrawNeeded:" below??
|
|
|
|
sendLifecycle(event.LifecycleStageFocused)
|
|
|
|
eventsIn <- event.Config{
|
|
|
|
Width: geom.Pt(float32(C.windowWidth) / pixelsPerPt),
|
|
|
|
Height: geom.Pt(float32(C.windowHeight) / pixelsPerPt),
|
|
|
|
PixelsPerPt: pixelsPerPt,
|
|
|
|
}
|
|
|
|
if firstWindowDraw {
|
|
|
|
firstWindowDraw = false
|
|
|
|
// TODO: be more principled about when to send a draw event.
|
|
|
|
eventsIn <- event.Draw{}
|
|
|
|
}
|
2015-02-22 20:27:20 +00:00
|
|
|
|
2014-09-09 23:51:04 +00:00
|
|
|
for {
|
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-23 06:41:48 +00:00
|
|
|
processEvents(queue)
|
2014-09-09 23:51:04 +00:00
|
|
|
select {
|
2015-06-27 22:32:29 +00:00
|
|
|
case <-donec:
|
|
|
|
return true
|
2015-04-09 19:00:55 +00:00
|
|
|
case <-windowRedrawNeeded:
|
|
|
|
// Re-query the width and height.
|
|
|
|
C.querySurfaceWidthAndHeight()
|
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-23 06:41:48 +00:00
|
|
|
sendLifecycle(event.LifecycleStageFocused)
|
|
|
|
eventsIn <- event.Config{
|
|
|
|
Width: geom.Pt(float32(C.windowWidth) / pixelsPerPt),
|
|
|
|
Height: geom.Pt(float32(C.windowHeight) / pixelsPerPt),
|
|
|
|
PixelsPerPt: pixelsPerPt,
|
|
|
|
}
|
|
|
|
case <-windowDestroyed:
|
|
|
|
sendLifecycle(event.LifecycleStageAlive)
|
2015-06-27 22:32:29 +00:00
|
|
|
return false
|
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-23 06:41:48 +00:00
|
|
|
case <-gl.WorkAvailable:
|
|
|
|
gl.DoWork()
|
|
|
|
case <-endDraw:
|
|
|
|
// eglSwapBuffers blocks until vsync.
|
|
|
|
C.eglSwapBuffers(C.display, C.surface)
|
|
|
|
eventsIn <- event.Draw{}
|
2014-09-09 23:51:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-11 23:39:16 +00:00
|
|
|
|
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-23 06:41:48 +00:00
|
|
|
func processEvents(queue *C.AInputQueue) {
|
2014-09-11 23:39:16 +00:00
|
|
|
var event *C.AInputEvent
|
|
|
|
for C.AInputQueue_getEvent(queue, &event) >= 0 {
|
|
|
|
if C.AInputQueue_preDispatchEvent(queue, event) != 0 {
|
|
|
|
continue
|
|
|
|
}
|
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-23 06:41:48 +00:00
|
|
|
processEvent(event)
|
2014-09-11 23:39:16 +00:00
|
|
|
C.AInputQueue_finishEvent(queue, event, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-23 06:41:48 +00:00
|
|
|
func processEvent(e *C.AInputEvent) {
|
2014-09-11 23:39:16 +00:00
|
|
|
switch C.AInputEvent_getType(e) {
|
|
|
|
case C.AINPUT_EVENT_TYPE_KEY:
|
|
|
|
log.Printf("TODO input event: key")
|
|
|
|
case C.AINPUT_EVENT_TYPE_MOTION:
|
2015-06-30 23:57:23 +00:00
|
|
|
// At most one of the events in this batch is an up or down event; get its index and change.
|
2014-12-20 15:44:54 +00:00
|
|
|
upDownIndex := C.size_t(C.AMotionEvent_getAction(e)&C.AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> C.AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT
|
2015-06-30 23:57:23 +00:00
|
|
|
upDownChange := event.ChangeNone
|
2014-12-20 15:44:54 +00:00
|
|
|
switch C.AMotionEvent_getAction(e) & C.AMOTION_EVENT_ACTION_MASK {
|
|
|
|
case C.AMOTION_EVENT_ACTION_DOWN, C.AMOTION_EVENT_ACTION_POINTER_DOWN:
|
2015-06-30 23:57:23 +00:00
|
|
|
upDownChange = event.ChangeOn
|
2014-12-20 15:44:54 +00:00
|
|
|
case C.AMOTION_EVENT_ACTION_UP, C.AMOTION_EVENT_ACTION_POINTER_UP:
|
2015-06-30 23:57:23 +00:00
|
|
|
upDownChange = event.ChangeOff
|
2014-12-20 15:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, n := C.size_t(0), C.AMotionEvent_getPointerCount(e); i < n; i++ {
|
2015-06-30 23:57:23 +00:00
|
|
|
change := event.ChangeNone
|
2014-12-20 15:44:54 +00:00
|
|
|
if i == upDownIndex {
|
2015-06-30 23:57:23 +00:00
|
|
|
change = upDownChange
|
2014-12-20 15:44:54 +00:00
|
|
|
}
|
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-23 06:41:48 +00:00
|
|
|
eventsIn <- event.Touch{
|
2015-06-30 23:57:23 +00:00
|
|
|
ID: event.TouchSequenceID(C.AMotionEvent_getPointerId(e, i)),
|
|
|
|
Change: change,
|
2014-12-20 15:44:54 +00:00
|
|
|
Loc: geom.Point{
|
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-23 06:41:48 +00:00
|
|
|
X: geom.Pt(float32(C.AMotionEvent_getX(e, i)) / pixelsPerPt),
|
|
|
|
Y: geom.Pt(float32(C.AMotionEvent_getY(e, i)) / pixelsPerPt),
|
2014-12-20 15:44:54 +00:00
|
|
|
},
|
2015-05-05 13:52:19 +00:00
|
|
|
}
|
2014-09-11 23:39:16 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Printf("unknown input event, type=%d", C.AInputEvent_getType(e))
|
|
|
|
}
|
|
|
|
}
|