2 // Created by mfritzsc on 7/11/17.
6 #include "json_helper.hpp"
12 #include <json-c/json.h>
20 App::App(wl::display *d) : api{this}, display{d}, controller{}, outputs() {
21 assert(g_app == nullptr);
26 if (!this->display->ok()) {
30 this->display->r.add_global_handler(
31 "wl_output", [](wl_registry *r, uint32_t name, uint32_t v) {
32 g_app->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
35 this->display->r.add_global_handler(
36 "ivi_controller", [](wl_registry *r, uint32_t name, uint32_t v) {
37 g_app->controller = std::make_unique<genivi::controller>(r, name, v);
39 // XXX: This protocol needs the output, so lets just add our mapping
41 g_app->controller->add_proxy_to_id_mapping(
42 g_app->outputs.back()->proxy.get(),
43 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
44 g_app->outputs.back()->proxy.get())));
47 // First level objects
48 this->display->roundtrip();
49 // Second level objects
50 this->display->roundtrip();
51 // Third level objects
52 this->display->roundtrip();
57 int App::dispatch_events() {
58 int ret = this->display->dispatch();
60 logerror("wl_display_dipatch() returned error %d",
61 this->display->get_error());
64 this->display->flush();
66 // execute pending tasks, that is layout changes etc.
67 this->controller->execute_pending();
68 this->display->roundtrip();
74 // (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \
75 // | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | |
76 // | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | |
77 // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | |
78 // |_____| |___/ \_\/_/
79 int App::init_layout() {
80 if (!this->controller) {
81 logerror("ivi_controller global not available");
85 if (this->outputs.empty()) {
86 logerror("no output was set up!");
90 auto &c = this->controller;
92 auto &o = this->outputs.front();
93 auto &s = c->screens.begin()->second;
94 auto &layers = c->layers;
96 // XXX: Write output dimensions to ivi controller...
97 c->output_size = genivi::size{uint32_t(o->width), uint32_t(o->height)};
105 // Setup our dummy scene...
106 c->layer_create(100, 0, 0); // bottom layer, anything else
107 c->layer_create(1000, 0, 0); // top layer, mandelbrot
109 auto &l100 = c->layers[100];
110 auto &l1k = c->layers[1000];
112 // Set layers fullscreen
113 l100->set_destination_rectangle(0, 0, o->width, o->height);
114 l1k->set_destination_rectangle(0, 0, o->width, o->height);
115 l100->set_visibility(1);
116 l1k->set_visibility(1);
118 // Add layers to screen
119 s->set_render_order({100, 1000});
123 this->display->flush();
128 binding_api::result_type binding_api::register_surface(uint32_t appid,
130 logdebug("%s appid %u surfid %u", __func__, appid, surfid);
132 return Err<json_object *>("invalid appid");
135 if (surfid > 0xffff) {
136 return Err<json_object *>("invalid surfaceid");
139 return Ok(json_object_new_int((appid << 16) + surfid));
142 binding_api::result_type binding_api::debug_layers() {
143 logdebug("%s", __func__);
144 return Ok(to_json(this->app->controller->lprops));
147 binding_api::result_type binding_api::debug_surfaces() {
148 logdebug("%s", __func__);
149 return Ok(to_json(this->app->controller->sprops));
152 binding_api::result_type binding_api::debug_status() {
153 logdebug("%s", __func__);
154 json_object *jr = json_object_new_object();
155 json_object_object_add(jr, "surfaces",
156 to_json(this->app->controller->sprops));
157 json_object_object_add(jr, "layers", to_json(this->app->controller->lprops));