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);
30 if (!this->display->ok()) {
34 this->display->add_global_handler(
35 "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
36 this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
39 this->display->add_global_handler(
40 "ivi_controller", [this](wl_registry *r, uint32_t name, uint32_t v) {
41 this->controller = std::make_unique<genivi::controller>(r, name, v);
43 // XXX: This protocol needs the output, so lets just add our mapping
45 this->controller->add_proxy_to_id_mapping(
46 this->outputs.back()->proxy.get(),
47 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
48 this->outputs.back()->proxy.get())));
51 // First level objects
52 this->display->roundtrip();
53 // Second level objects
54 this->display->roundtrip();
55 // Third level objects
56 this->display->roundtrip();
61 int App::dispatch_events() {
62 int ret = this->display->dispatch();
64 logerror("wl_display_dipatch() returned error %d",
65 this->display->get_error());
68 this->display->flush();
70 // execute pending tasks, that is layout changes etc.
71 this->controller->execute_pending();
72 this->display->roundtrip();
78 // (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \
79 // | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | |
80 // | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | |
81 // |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | |
82 // |_____| |___/ \_\/_/
83 int App::init_layout() {
84 if (!this->controller) {
85 logerror("ivi_controller global not available");
89 if (this->outputs.empty()) {
90 logerror("no output was set up!");
94 auto &c = this->controller;
96 auto &o = this->outputs.front();
97 auto &s = c->screens.begin()->second;
98 auto &layers = c->layers;
100 // XXX: Write output dimensions to ivi controller...
101 c->output_size = genivi::size{uint32_t(o->width), uint32_t(o->height)};
109 // Setup our dummy scene...
110 c->layer_create(100, 0, 0); // bottom layer, anything else
111 c->layer_create(1000, 0, 0); // top layer, mandelbrot
113 auto &l100 = c->layers[100];
114 auto &l1k = c->layers[1000];
116 // Set layers fullscreen
117 l100->set_destination_rectangle(0, 0, o->width, o->height);
118 l1k->set_destination_rectangle(0, 0, o->width, o->height);
119 l100->set_visibility(1);
120 l1k->set_visibility(1);
122 // Add layers to screen
123 s->set_render_order({100, 1000});
127 this->display->flush();
132 binding_api::result_type binding_api::register_surface(uint32_t appid,
134 logdebug("%s appid %u surfid %u", __func__, appid, surfid);
136 return Err<json_object *>("invalid appid");
139 if (surfid > 0xffff) {
140 return Err<json_object *>("invalid surfaceid");
143 return Ok(json_object_new_int((appid << 16) + surfid));
146 binding_api::result_type binding_api::debug_layers() {
147 logdebug("%s", __func__);
148 return Ok(to_json(this->app->controller->lprops));
151 binding_api::result_type binding_api::debug_surfaces() {
152 logdebug("%s", __func__);
153 return Ok(to_json(this->app->controller->sprops));
156 binding_api::result_type binding_api::debug_status() {
157 logdebug("%s", __func__);
158 json_object *jr = json_object_new_object();
159 json_object_object_add(jr, "surfaces",
160 to_json(this->app->controller->sprops));
161 json_object_object_add(jr, "layers", to_json(this->app->controller->lprops));