return -1;
}
+bool App::pop_pending_events() {
+ bool x{true};
+ return this->pending_events.compare_exchange_strong(
+ x, false, std::memory_order_consume);
+}
+
+void App::set_pending_events() {
+ this->pending_events.store(true, std::memory_order_release);
+}
+
+optional<int> App::lookup_id(char const *name) {
+ return this->id_alloc.lookup(std::string(name));
+}
+optional<std::string> App::lookup_name(int id) {
+ return this->id_alloc.lookup(id);
+}
+
// _ _ _ _ _ ____
// (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \
// | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | |
state.sub = -1;
state.s = LayoutState::Single;
- //////this->emit_flushdraw(drawing_name);
- this->pending_end_draw.push_back(state.main);
+ this->enqueue_flushdraw(state.main);
} else {
bool can_split = this->can_split(state, *surface_id);
this->activate(*surface_id);
state.sub = *surface_id;
- this->pending_end_draw.push_back(state.main);
- this->pending_end_draw.push_back(state.sub);
- // Should wait for EndDraw event...
- //////this->emit_flushdraw(drawing_name);
- //////this->emit_flushdraw(main.c_str());
+ this->enqueue_flushdraw(state.main);
+ this->enqueue_flushdraw(state.sub);
}
} else {
this->emit_syncdraw(drawing_name);
state.sub = -1;
state.s = LayoutState::Single;
- //////this->emit_flushdraw(drawing_name);
- this->pending_end_draw.push_back(state.main);
+ this->enqueue_flushdraw(state.main);
}
}
}
state.sub = -1;
state.s = LayoutState::Single;
- //////this->emit_flushdraw(sub.c_str());
- this->pending_end_draw.push_back(state.sub);
+ this->enqueue_flushdraw(state.sub);
} else {
this->deactivate(*surface_id);
state.main = -1;
state.sub = -1;
state.s = LayoutState::Single;
- //////this->emit_flushdraw(main.c_str());
- this->pending_end_draw.push_back(state.main);
+ this->enqueue_flushdraw(state.main);
} else {
return "Surface is not active";
}
return nullptr;
}
+void App::enqueue_flushdraw(int surface_id) {
+ this->check_flushdraw(surface_id);
+ logdebug("Enqueuing EndDraw for surface_id %d", surface_id);
+ this->pending_end_draw.push_back(surface_id);
+}
+
+void App::check_flushdraw(int surface_id) {
+ auto i = std::find(std::begin(this->pending_end_draw),
+ std::end(this->pending_end_draw), surface_id);
+ if (i != std::end(this->pending_end_draw)) {
+ auto n = this->lookup_name(surface_id);
+ logerror("Application %s (%d) has pending EndDraw call(s)!",
+ n ? n->c_str() : "unknown-name", surface_id);
+ std::swap(this->pending_end_draw[std::distance(
+ std::begin(this->pending_end_draw), i)],
+ this->pending_end_draw.back());
+ this->pending_end_draw.resize(this->pending_end_draw.size() - 1);
+ }
+}
+
char const *App::api_enddraw(char const *drawing_name) {
for (unsigned i = 0, iend = this->pending_end_draw.size(); i < iend; i++) {
auto n = this->lookup_name(this->pending_end_draw[i]);
return "No EndDraw pending for surface";
}
+void App::api_ping() {
+ this->dispatch_pending_events();
+}
+
// _ _ _____ _
// _ __ _ __ _____ _(_) ___ __| | | ____|_ _____ _ __ | |_ ___
// | '_ \| '__/ _ \ \/ / |/ _ \/ _` | | _| \ \ / / _ \ '_ \| __/ __|