add redraw_fixer, separate controller tool
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 12 Sep 2017 09:29:41 +0000 (11:29 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 12 Sep 2017 09:29:41 +0000 (11:29 +0200)
* Use the existing wayland.hpp/cpp implementation
* Listen for visibility and destination_rectangle events
* Apply changing values to opacity to "fix" redraw

Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/CMakeLists.txt
src/redraw_fixer.cpp [new file with mode: 0644]

index 953b59a..f83aae2 100644 (file)
@@ -27,7 +27,22 @@ add_library(winman MODULE
    afb_binding_api.cpp
    result.hpp
    afb_binding_api.hpp
-   afb_binding_glue.inl layers.cpp layers.hpp controller_hooks.hpp config.cpp config.hpp policy.hpp)
+   afb_binding_glue.inl
+   layers.cpp
+   layers.hpp
+   controller_hooks.hpp
+   config.cpp
+   config.hpp
+   policy.hpp)
+
+add_executable(redraw_fixer
+        redraw_fixer.cpp
+        ${IVI_CON_PROTO}
+        wayland.cpp
+        wayland.hpp
+        controller_hooks.hpp
+        util.cpp
+        util.hpp)
 
 target_include_directories(winman
     PRIVATE
@@ -36,6 +51,10 @@ target_include_directories(winman
         ../include
         ../src)
 
+target_link_libraries(redraw_fixer
+        PRIVATE
+        ${WLC_LIBRARIES})
+
 target_link_libraries(winman
     PRIVATE
         ${AFB_LIBRARIES}
@@ -50,10 +69,18 @@ target_compile_definitions(winman
         WINMAN_VERSION_STRING="${PACKAGE_VERSION}"
         _GNU_SOURCE)  # XXX should I define this here?!
 
+target_compile_definitions(redraw_fixer
+        PRIVATE
+        DO_NOT_USE_AFB   # override log* AFB macros
+        _GNU_SOURCE)
+
 if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release")
    target_compile_definitions(winman
        PRIVATE
            _GLIBCXX_DEBUG)
+   target_compile_definitions(redraw_fixer
+           PRIVATE
+           _GLIBCXX_DEBUG)
 endif()
 
 target_compile_options(winman
@@ -78,6 +105,9 @@ if (LINK_LIBCXX)
    set_target_properties(winman
            PROPERTIES
            LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../export.map -lc++")
+   set_target_properties(redraw_fixer
+           PROPERTIES
+           LINK_FLAGS "-lc++")
 endif()
 
 if (NOT ${SANITIZER_MODE} STREQUAL "none" AND NOT ${SANITIZER_MODE} STREQUAL "")
diff --git a/src/redraw_fixer.cpp b/src/redraw_fixer.cpp
new file mode 100644 (file)
index 0000000..e6a84e3
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// Created by mfritzsc on 9/11/17.
+//
+
+#include "wayland.hpp"
+
+#include <algorithm>
+#include <chrono>
+#include <thread>
+
+using namespace std::chrono_literals;
+
+// pretend we are a WM ...
+namespace wm {
+
+struct App {
+   controller_hooks chooks;
+   std::unique_ptr<wl::display> display;
+   std::unique_ptr<genivi::controller> controller;
+   std::vector<std::unique_ptr<wl::output>> outputs;
+
+   App();
+   void commit();
+   void surface_created(uint32_t surface_id);
+   void surface_removed(uint32_t surface_id);
+   void surface_visibility(uint32_t surface_id, uint32_t v);
+   void surface_destination_rectangle(uint32_t surface_id, uint32_t x,
+                                      uint32_t y, uint32_t w, uint32_t h);
+   void try_fix(uint32_t surface_id);
+};
+
+void controller_hooks::surface_created(uint32_t surface_id) {
+   this->app->surface_created(surface_id);
+}
+
+void controller_hooks::surface_removed(uint32_t surface_id) {
+   this->app->surface_removed(surface_id);
+}
+
+void controller_hooks::surface_visibility(uint32_t surface_id, uint32_t v) {
+   this->app->surface_visibility(surface_id, v);
+}
+
+void controller_hooks::surface_destination_rectangle(uint32_t surface_id,
+                                                     uint32_t x, uint32_t y,
+                                                     uint32_t w, uint32_t h) {
+   this->app->surface_destination_rectangle(surface_id, x, y, w, h);
+}
+
+App::App() : chooks{this}, display{new wl::display}, controller{} {
+   // The same init, the WM does, at least we can reuse the wayland stuff
+   if (this->display->ok()) {
+      this->display->add_global_handler("wl_output", [this](wl_registry *r,
+                                                            uint32_t name,
+                                                            uint32_t v) {
+         this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
+      });
+
+      this->display->add_global_handler(
+         "ivi_controller", [this](wl_registry *r, uint32_t name, uint32_t v) {
+            this->controller =
+               std::make_unique<struct genivi::controller>(r, name, v);
+
+            // Init controller hooks
+            this->controller->chooks = &this->chooks;
+
+            // XXX: This protocol needs the output, so lets just add our
+            // mapping
+            // here...
+            this->controller->add_proxy_to_id_mapping(
+               this->outputs.back()->proxy.get(),
+               wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
+                  this->outputs.back()->proxy.get())));
+         });
+
+      for (int i : {1, 2, 3})
+         this->display->roundtrip();
+   }
+}
+
+void App::commit() {
+   this->controller->commit_changes();
+   this->display->dispatch();  // read: flush()++
+}
+
+void App::surface_created(uint32_t surface_id) { }
+
+void App::surface_removed(uint32_t surface_id) { }
+
+void App::surface_visibility(uint32_t surface_id, uint32_t v) {
+   fprintf(stderr, "surface %u visibility %u\n", surface_id, v);
+
+   if (v == 1) {
+     this->try_fix(surface_id);
+   }
+}
+
+void App::surface_destination_rectangle(uint32_t surface_id, uint32_t x,
+                                        uint32_t y, uint32_t w, uint32_t h) {
+   fprintf(stderr, "surface %u dst %u %u %u %u\n", surface_id, x, y, w, h);
+
+   if (w != 1 && h != 1) {
+      this->try_fix(surface_id);
+   }
+}
+
+void App::try_fix(uint32_t surface_id) {
+   this->controller->surfaces[surface_id]->set_opacity(255);
+   this->commit();
+   std::this_thread::sleep_for(200ms);
+   this->controller->surfaces[surface_id]->set_opacity(256);
+   this->commit();
+}
+
+}  // namespace wm
+
+int main(int argc, char **argv) {
+   wm::App app;
+   if (!app.display->ok()) {
+      fputs("Could not init wayland display\n", stderr);
+      return 1;
+   }
+   while (app.display->dispatch() != -1)
+      ;
+   return 0;
+}