Auto merge of #23300 - jdm:helpful-ml, r=asajeffrey

Magic Leap developer ergonomic improvements

These changes allow passing in command line arguments for Servo via a SERVO_ARGS from the mldb terminal when launching the activity, as well as passing in a launch URL as an argument. It also redirects stdout to the ML log, which allows observing the built-in profiler output.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #23041
- [x] These changes do not require tests because no magic leap testing.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23300)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-05-03 02:58:51 -04:00 committed by GitHub
commit 60c7266e18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 152 additions and 18 deletions

View file

@ -29,7 +29,7 @@ public:
/**
* Constructs the Landscape Application.
*/
Servo2D();
Servo2D(const char* uri, const char* args);
/**
* Destroys the Landscape Application.
@ -144,4 +144,6 @@ private:
glm::quat controller_orientation_; // The last recorded orientation of the controller (in world coords)
bool controller_trigger_down_ = false; // Is the controller trigger currently down?
ServoInstance* servo_ = nullptr; // the servo instance we're embedding
const char* uri_ = nullptr;
const char* args_ = nullptr;
};

View file

@ -68,7 +68,7 @@ void keyboard(Servo2D* app, bool visible) {
// The functions Servo provides for hooking up to the ML.
extern "C" ServoInstance* init_servo(EGLContext, EGLSurface, EGLDisplay,
Servo2D*, MLLogger, MLHistoryUpdate, MLURLUpdate, MLKeyboard,
const char* url, int width, int height, float hidpi);
const char* url, const char* args, int width, int height, float hidpi);
extern "C" void heartbeat_servo(ServoInstance*);
extern "C" void keyboard_servo(ServoInstance*, char32_t code, lumin::ui::KeyType keyType);
extern "C" void trigger_servo(ServoInstance*, float x, float y, bool down);
@ -78,7 +78,10 @@ extern "C" void navigate_servo(ServoInstance*, const char* text);
extern "C" void discard_servo(ServoInstance*);
// Create a Servo2D instance
Servo2D::Servo2D() {
Servo2D::Servo2D(const char* uri, const char* args)
: uri_(uri ? uri : HOME_PAGE)
, args_(args)
{
ML_LOG(Debug, "Servo2D Constructor.");
}
@ -171,7 +174,7 @@ int Servo2D::init() {
EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
// Hook into servo
servo_ = init_servo(ctx, surf, dpy, this, logger, history, url, keyboard, HOME_PAGE, VIEWPORT_W, VIEWPORT_H, HIDPI);
servo_ = init_servo(ctx, surf, dpy, this, logger, history, url, keyboard, uri_, args_, VIEWPORT_W, VIEWPORT_H, HIDPI);
if (!servo_) {
ML_LOG(Error, "Servo2D Failed to init servo instance");
abort();

View file

@ -3,11 +3,34 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#include <Servo2D.h>
#include <ml_lifecycle.h>
#include <ml_logging.h>
int main(int argc, char **argv)
{
ML_LOG(Debug, "Servo2D Starting.");
Servo2D myApp;
return myApp.run();
// Handle optional initialization string passed via 'mldb launch'
MLLifecycleInitArgList* list = NULL;
MLLifecycleGetInitArgList(&list);
const char* uri = NULL;
if (nullptr != list) {
int64_t list_length = 0;
MLLifecycleGetInitArgListLength(list, &list_length);
if (list_length > 0) {
const MLLifecycleInitArg* iarg = NULL;
MLLifecycleGetInitArgByIndex(list, 0, &iarg);
if (nullptr != iarg) {
MLLifecycleGetInitArgUri(iarg, &uri);
}
}
}
const char* args = getenv("SERVO_ARGS");
Servo2D myApp(uri, args);
int rv = myApp.run();
MLLifecycleFreeInitArgList(&list);
return rv;
}