Merge changes from topic '15921'
authorJan-Simon Moeller <jsmoeller@linuxfoundation.org>
Thu, 2 Aug 2018 16:14:39 +0000 (16:14 +0000)
committerGerrit Code Review <gerrit@automotivelinux.org>
Thu, 2 Aug 2018 16:14:39 +0000 (16:14 +0000)
* changes:
  Fix WM attach layers to different screen.
  Fix source rectangle changes every state change

1  2 
src/wayland_ivi_wm.cpp
src/wayland_ivi_wm.hpp
src/window_manager.cpp

diff --combined src/wayland_ivi_wm.cpp
@@@ -435,6 -435,11 +435,6 @@@ void layer::set_visibility(uint32_t vis
      ivi_wm_set_layer_visibility(this->parent->proxy.get(), this->id, visibility);
  }
  
 -void layer::set_source_rectangle(int32_t x, int32_t y, int32_t width, int32_t height)
 -{
 -    ivi_wm_set_layer_source_rectangle(this->parent->proxy.get(), this->id, x, y, width, height);
 -}
 -
  void layer::set_destination_rectangle(int32_t x, int32_t y,
                                        int32_t width, int32_t height)
  {
@@@ -531,6 -536,11 +531,11 @@@ void controller::create_screen(struct w
      this->screen = std::make_unique<struct screen>(0, this, output);
  }
  
+ void controller::get_surface_properties(uint32_t surface_id, int param)
+ {
+     ivi_wm_surface_get(this->proxy.get(), surface_id, param);
+ }
  void controller::layer_created(uint32_t id)
  {
      HMI_DEBUG("wm", "compositor::controller @ %p layer %u (%x)", this->proxy.get(), id, id);
@@@ -591,6 -601,7 +596,7 @@@ void controller::surface_size_changed(u
      HMI_DEBUG("wm", "compositor::surface %s @ %d w %i h %i", __func__, id,
                width, height);
      this->sprops[id].size = size{uint32_t(width), uint32_t(height)};
+     this->surfaces[id]->set_source_rectangle(0, 0, width, height);
  }
  
  void controller::surface_added_to_layer(uint32_t layer_id, uint32_t surface_id)
diff --combined src/wayland_ivi_wm.hpp
@@@ -197,6 -197,7 +197,6 @@@ struct layer : public controller_chil
  
      // Requests
      void set_visibility(uint32_t visibility);
 -    void set_source_rectangle(int32_t x, int32_t y, int32_t width, int32_t height);
      void set_destination_rectangle(int32_t x, int32_t y,
                                     int32_t width, int32_t height);
      void add_surface(uint32_t surface_id);
@@@ -256,9 -257,6 +256,9 @@@ struct controller : public wayland_prox
      size output_size;   // Display size[pixel]
      size physical_size; // Display size[mm]
  
 +    // Scale for conversion CSS PX -> DP(Device Pixel)
 +    double scale;
 +
      wm::controller_hooks *chooks;
  
      struct wl::display *display;
      void layer_create(uint32_t id, int32_t w, int32_t h);
      void surface_create(uint32_t id);
      void create_screen(struct wl_output *output);
+     void get_surface_properties(uint32_t surface_id, int param = 0);
  
      // Events
      void surface_visibility_changed(uint32_t id, int32_t visibility);
diff --combined src/window_manager.cpp
@@@ -19,6 -19,7 +19,6 @@@
  
  #include "window_manager.hpp"
  #include "json_helper.hpp"
 -#include "wm_config.hpp"
  #include "applist.hpp"
  
  extern "C"
@@@ -50,7 -51,6 +50,7 @@@ const char kKeyWidthPixel[]  = "width_p
  const char kKeyHeightPixel[] = "height_pixel";
  const char kKeyWidthMm[]     = "width_mm";
  const char kKeyHeightMm[]    = "height_mm";
 +const char kKeyScale[]       = "scale";
  const char kKeyIds[]         = "ids";
  
  static sd_event_source *g_timer_ev_src = nullptr;
@@@ -147,6 -147,7 +147,6 @@@ WindowManager::WindowManager(wl::displa
  
  int WindowManager::init()
  {
 -    int ret;
      if (!this->display->ok())
      {
          return -1;
  
              // This protocol needs the output, so lets just add our mapping here...
              this->controller->add_proxy_to_id_mapping(
-                 this->outputs.back()->proxy.get(),
+                 this->outputs.front()->proxy.get(),
                  wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
-                     this->outputs.back()->proxy.get())));
+                     this->outputs.front()->proxy.get())));
  
              // Create screen
-             this->controller->create_screen(this->outputs.back()->proxy.get());
+             this->controller->create_screen(this->outputs.front()->proxy.get());
  
              // Set display to controller
              this->controller->display = this->display;
      // Third level objects
      this->display->roundtrip();
  
 -    ret = init_layers();
 -    return ret;
 +    return init_layers();
  }
  
  int WindowManager::dispatch_pending_events()
@@@ -461,9 -463,10 +461,9 @@@ void WindowManager::api_enddraw(char co
  
  result<json_object *> WindowManager::api_get_display_info()
  {
 -    // Check controller
 -    if (!this->controller)
 +    if (!this->display->ok())
      {
 -        return Err<json_object *>("ivi_controller global not available");
 +        return Err<json_object *>("Wayland compositor is not available");
      }
  
      // Set display info
      json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h));
      json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w));
      json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h));
 +    json_object_object_add(object, kKeyScale, json_object_new_double(this->controller->scale));
  
      return Ok<json_object *>(object);
  }
@@@ -574,6 -576,8 +574,8 @@@ void WindowManager::send_event(char con
   */
  void WindowManager::surface_created(uint32_t surface_id)
  {
+     this->controller->get_surface_properties(surface_id, IVI_WM_PARAM_SIZE);
      auto layer_id = this->layers.get_layer_id(surface_id);
      if (!layer_id)
      {
@@@ -655,32 -659,27 +657,32 @@@ int WindowManager::init_layers(
          return -1;
      }
  
 -    WMConfig wm_config;
 -    wm_config.loadConfigs();
 -
      auto &c = this->controller;
  
      auto &o = this->outputs.front();
      auto &s = c->screens.begin()->second;
      auto &layers = c->layers;
  
 -    this->layers.loadAreaDb();
 -    const compositor::rect base = this->layers.getAreaSize("fullscreen");
 -
 -    const std::string aspect_setting = wm_config.getConfigAspect();
 -    const compositor::rect scale_rect =
 -        this->layers.getScaleDestRect(o->width, o->height, aspect_setting);
 -
      // Write output dimensions to ivi controller...
      c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
      c->physical_size = compositor::size{uint32_t(o->physical_width),
                                          uint32_t(o->physical_height)};
  
 +
 +    HMI_DEBUG("wm", "SCALING: screen (%dx%d), physical (%dx%d)",
 +              o->width, o->height, o->physical_width, o->physical_height);
 +
 +    this->layers.loadAreaDb();
 +
 +    const compositor::rect css_bg = this->layers.getAreaSize("fullscreen");
 +    rectangle dp_bg(o->width, o->height);
 +
 +    dp_bg.set_aspect(static_cast<double>(css_bg.w) / css_bg.h);
 +    dp_bg.fit(o->width, o->height);
 +    dp_bg.center(o->width, o->height);
 +    HMI_DEBUG("wm", "SCALING: CSS BG(%dx%d) -> DDP %dx%d,(%dx%d)",
 +              css_bg.w, css_bg.h, dp_bg.left(), dp_bg.top(), dp_bg.width(), dp_bg.height());
 +
      // Clear scene
      layers.clear();
  
      // Quick and dirty setup of layers
      for (auto const &i : this->layers.mapping)
      {
 -        c->layer_create(i.second.layer_id, scale_rect.w, scale_rect.h);
 +        c->layer_create(i.second.layer_id, dp_bg.width(), dp_bg.height());
          auto &l = layers[i.second.layer_id];
 -        l->set_source_rectangle(0, 0, base.w, base.h);
 -        l->set_destination_rectangle(
 -            scale_rect.x, scale_rect.y, scale_rect.w, scale_rect.h);
 +        l->set_destination_rectangle(dp_bg.left(), dp_bg.top(), dp_bg.width(), dp_bg.height());
          l->set_visibility(1);
          HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
                    i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
  
      this->layout_commit();
  
 +    c->scale = static_cast<double>(dp_bg.height()) / css_bg.h;
 +    this->layers.setupArea(c->scale);
 +
      return 0;
  }
  
@@@ -742,8 -740,6 +744,6 @@@ void WindowManager::surface_set_layout(
                layer_id);
  
      // set destination to the display rectangle
-     s->set_source_rectangle(0, 0, w, h);
-     this->layout_commit();
      s->set_destination_rectangle(x, y, w, h);
  
      // update area information
@@@ -1292,6 -1288,7 +1292,7 @@@ WMError WindowManager::doEndDraw(unsign
          HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str());
          //this->lm_enddraw(act.role.c_str());
      }
+     this->layout_commit();
  
      // Change current state
      this->changeCurrentState(req_num);
@@@ -1771,12 -1768,12 +1772,12 @@@ const char* WindowManager::kDefaultOldR
   */
  void controller_hooks::surface_created(uint32_t surface_id)
  {
-     this->app->surface_created(surface_id);
+     this->wmgr->surface_created(surface_id);
  }
  
  void controller_hooks::surface_removed(uint32_t surface_id)
  {
-     this->app->surface_removed(surface_id);
+     this->wmgr->surface_removed(surface_id);
  }
  
  void controller_hooks::surface_visibility(uint32_t /*surface_id*/,