2 // Created by mfritzsc on 7/11/17.
7 #include "json_helper.hpp"
12 #include <json-c/json.h>
20 App::App(wl::display *d)
21 : api{this}, display{d}, controller{}, outputs() {
22 assert(g_app == nullptr);
27 if (!this->display->ok()) {
31 this->display->r.add_global_handler("wl_output", [](wl_registry *r,
34 g_app->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
37 this->display->r.add_global_handler(
38 "ivi_controller", [](wl_registry *r, uint32_t name, uint32_t v) {
40 std::make_unique<genivi::controller>(r, name, v);
42 // XXX: This protocol needs the output, so lets just add our mapping
44 g_app->controller->add_proxy_to_id_mapping(
45 g_app->outputs.back()->proxy.get(),
46 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
47 g_app->outputs.back()->proxy.get())));
50 // First level objects
51 this->display->roundtrip();
52 // Second level objects
53 this->display->roundtrip();
54 // Third level objects
55 this->display->roundtrip();
60 int App::dispatch_events() {
61 int ret = this->display->dispatch();
63 logerror("wl_display_dipatch() returned error %d",
64 this->display->get_error());
67 this->display->flush();
69 // execute pending tasks, that is layout changes etc.
70 this->controller->execute_pending();
71 this->display->roundtrip();
77 // (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \
78 // | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | |
79 // | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | |
80 // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | |
81 // |_____| |___/ \_\/_/
82 int App::init_layout() {
83 if (!this->controller) {
84 logerror("ivi_controller global not available");
88 if (this->outputs.empty()) {
89 logerror("no output was set up!");
93 auto &c = this->controller;
95 auto &o = this->outputs.front();
96 auto &s = c->screens.begin()->second;
97 auto &layers = c->layers;
99 // XXX: Write output dimensions to ivi controller...
100 c->output_size = genivi::size{uint32_t(o->width), uint32_t(o->height)};
108 // Setup our dummy scene...
109 c->layer_create(100, 0, 0); // bottom layer, anything else
110 c->layer_create(1000, 0, 0); // top layer, mandelbrot
112 auto &l100 = c->layers[100];
113 auto &l1k = c->layers[1000];
115 // Set layers fullscreen
116 l100->set_destination_rectangle(0, 0, o->width, o->height);
117 l1k->set_destination_rectangle(0, 0, o->width, o->height);
118 l100->set_visibility(1);
119 l1k->set_visibility(1);
121 // Add layers to screen
122 s->set_render_order({100, 1000});
126 this->display->flush();
131 binding_api::result_type binding_api::register_surface(uint32_t appid,
133 logdebug("%s appid %u surfid %u", __func__, appid, surfid);
135 return Err<json_object *>("invalid appid");
138 if (surfid > 0xffff) {
139 return Err<json_object *>("invalid surfaceid");
142 return Ok(json_object_new_int((appid << 16) + surfid));
145 binding_api::result_type binding_api::debug_layers() {
146 logdebug("%s", __func__);
147 return Ok(to_json(this->app->controller->lprops));
150 binding_api::result_type binding_api::debug_surfaces() {
151 logdebug("%s", __func__);
152 return Ok(to_json(this->app->controller->sprops));
155 binding_api::result_type binding_api::debug_status() {
156 logdebug("%s", __func__);
157 json_object *jr = json_object_new_object();
158 json_object_object_add(jr, "surfaces", to_json(this->app->controller->sprops));
159 json_object_object_add(jr, "layers", to_json(this->app->controller->lprops));