diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wm_layer.cpp | 70 | ||||
-rw-r--r-- | src/wm_layer.hpp | 15 | ||||
-rw-r--r-- | src/wm_layer_control.cpp | 223 | ||||
-rw-r--r-- | src/wm_layer_control.hpp | 28 |
4 files changed, 304 insertions, 32 deletions
diff --git a/src/wm_layer.cpp b/src/wm_layer.cpp index 6131165..773b5c2 100644 --- a/src/wm_layer.cpp +++ b/src/wm_layer.cpp @@ -16,30 +16,57 @@ #include <regex> +#include "wm_client.hpp" #include "wm_layer.hpp" #include "json_helper.hpp" #include "util.hpp" using std::string; using std::vector; +using std::unordered_map; namespace wm { LayerState::LayerState() - : _ivi_layer_id_list(), - area2ivi_layer_id() + : render_order(), + area2appid() {} + +void LayerState::attachIdToArea(const string& area, const WMClient& client) +{ + this->area2appid[area] = client.appID(); + this->render_order.push_back(client.layerID()); +} + +const unordered_map<std::string, std::string> LayerState::popCurrentState() +{ + unordered_map<string, string> tmp = this->area2appid; + this->area2appid.clear(); + this->render_order.clear(); + return tmp; +} + +const unordered_map<std::string, std::string> LayerState::getCurrentState() +{ + return this->area2appid; +} + +const vector<unsigned> LayerState::getIviIdList() +{ + return this->render_order; +} + LayerSetting::LayerSetting(const string& name, MANAGEMENT_TYPE type, unsigned begin, unsigned end) : name(name), type(type), role_list(), area_list(), id_list(), id_begin(begin), id_end(end) {} -void LayerSetting::appendRole(const string& role) +void LayerSetting::setRoleList(const string& role) { - this->role_list.push_back(role); + this->role_list = role; } void LayerSetting::appendArea(const string& area) @@ -50,20 +77,24 @@ void LayerSetting::appendArea(const string& area) unsigned LayerSetting::getNewLayerID(const string& role) { unsigned ret = 0; - auto found = std::find(role_list.cbegin(), role_list.cend(), role); - if(found == role_list.cend()) + auto re = std::regex(this->role_list); + if (std::regex_match(role, re)) + { + // generate new layer id; + ret = this->id_list.back() + 1; + HMI_DEBUG("role %s matches layer %d, new layerID %d", role.c_str(), this->name.c_str(), ret); + } + + if(ret == 0) { return ret; } - // generate new ivi layer id - ret = id_list.back() + 1; - HMI_INFO("generate ivi_layer_id : %d on the layer: %s", ret, this->name.c_str()); auto id_found = std::find(id_list.begin(), id_list.end(), ret); if( (ret > this->idEnd()) || (id_found != id_list.cend()) ) { HMI_NOTICE("id %d is not available then generate new id", ret); - ret = 0; + ret = 0; // reset for(unsigned i = this->idBegin(); i < this->idEnd(); i++) { auto ret_found = std::find(id_list.begin(), id_list.end(), i); @@ -108,13 +139,13 @@ WMLayer::WMLayer(json_object* j) : before_state(), state() { LayerSetting::MANAGEMENT_TYPE t; const char* layer_name = jh::getStringFromJson(j, "name"); - const char* role = jh::getStringFromJson(j, "role"); + const char* roles = jh::getStringFromJson(j, "role"); const char* type = jh::getStringFromJson(j, "type"); int begin = jh::getIntFromJson(j, "id_range_begin"); int end = jh::getIntFromJson(j, "id_range_end"); string name = layer_name; - if (layer_name || type || !begin < 0 || end < 0) + if (layer_name || type || begin < 0 || end < 0) { HMI_ERROR("Parse Error!!"); } @@ -123,9 +154,9 @@ WMLayer::WMLayer(json_object* j) : before_state(), state() HMI_ERROR("INVALID."); } string str_type = type; - t = (type == "tile") ? LayerSetting::TILE : LayerSetting::STACK; + t = (str_type == "tile") ? LayerSetting::TILE : LayerSetting::STACK; this->setting = std::make_unique<LayerSetting>(name, t, begin, end); - this->setting->appendRole(role); + this->setting->setRoleList(roles); } unsigned WMLayer::getNewLayerID(const std::string& role) @@ -135,6 +166,7 @@ unsigned WMLayer::getNewLayerID(const std::string& role) WMError WMLayer::setLayerState(const LayerState& l) { + this->before_state = l; return WMError::SUCCESS; } @@ -143,4 +175,14 @@ bool WMLayer::checkIDBelongTo(unsigned id) return (id > this->setting->idBegin() && id < this->setting->idEnd()); } +/* WMError WMLayer::commitChange() +{ + this->state = this->before_state; +} + +void WMLayer::undo() +{ + this->before_state = this->state; +} + */ } // namespace wm diff --git a/src/wm_layer.hpp b/src/wm_layer.hpp index 6cfd9c2..001134a 100644 --- a/src/wm_layer.hpp +++ b/src/wm_layer.hpp @@ -28,15 +28,20 @@ struct json_object; namespace wm { +class WMClient; class LayerState { public: LayerState(); ~LayerState() = default; + void attachIdToArea(const std::string& area, const WMClient&); + const std::unordered_map<std::string, std::string> popCurrentState(); + const std::unordered_map<std::string, std::string> getCurrentState(); + const std::vector<unsigned> getIviIdList(); + private: - std::vector<unsigned> _ivi_layer_id_list; - std::unordered_map<std::string, unsigned> area2ivi_layer_id; - // std::map<std::string, unsigned> _render_order; + std::vector<unsigned> render_order; + std::unordered_map<std::string, std::string> area2appid; }; class LayerSetting @@ -53,7 +58,7 @@ class LayerSetting const std::string& layerName() { return this->name; } MANAGEMENT_TYPE layerType() { return this->type; }; - void appendRole(const std::string& role); + void setRoleList(const std::string& role); void appendArea(const std::string& area); unsigned idBegin() { return this->id_begin; } unsigned idEnd() { return this->id_end; } @@ -70,7 +75,7 @@ class LayerSetting private: std::string name = ""; // Layer name MANAGEMENT_TYPE type; - std::vector<std::string> role_list; + std::string role_list; std::vector<std::string> area_list; std::vector<unsigned> id_list; unsigned id_begin; diff --git a/src/wm_layer_control.cpp b/src/wm_layer_control.cpp index b15ebbb..72a3a19 100644 --- a/src/wm_layer_control.cpp +++ b/src/wm_layer_control.cpp @@ -19,19 +19,36 @@ #include "wm_layer.hpp"
#include "json_helper.hpp"
-#define LC_AREA_PATH "/etc/area.db"
+#define LC_AREA_PATH "/etc/areas.db"
#define LC_LAYER_SETTING_PATH "/etc/layer_setting.json"
using std::string;
+using std::vector;
namespace wm {
-static void notification_static(ilmObjectType object,
+LayerControl* g_lc_ctxt;
+
+static void createCallback_static(ilmObjectType object,
t_ilm_uint id,
t_ilm_bool created,
void* data)
{
- static_cast<LayerControl*>(data)->dispatchILMEvent(object, id, created);
+ static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);
+}
+
+static void surfaceCallback_static(t_ilm_surface surface,
+ struct ilmSurfaceProperties* surface_prop,
+ t_ilm_notification_mask mask)
+{
+ g_lc_ctxt->dispatchPropertyChangeEvent(surface, surface_prop, mask);
+}
+
+static void layerCallback_static(t_ilm_layer layer,
+ struct ilmLayerProperties* layer_prop,
+ t_ilm_notification_mask mask)
+{
+ g_lc_ctxt->dispatchPropertyChangeEvent(layer, layer_prop, mask);
}
LayerControl::LayerControl(const std::string& root)
@@ -46,7 +63,7 @@ LayerControl::LayerControl(const std::string& root) assert(ret == WMError::SUCCESS);
}
-WMError LayerControl::init()
+WMError LayerControl::init(const LayerControlCallbacks& cb)
{
ilmErrorTypes rc = ilm_init();
t_ilm_uint num = 0;
@@ -67,6 +84,7 @@ WMError LayerControl::init() }
if(rc != ILM_SUCCESS) goto lc_init_error;
+ // Get current screen setting
rc = ilm_getScreenIDs(&num, &ids);
if(rc != ILM_SUCCESS) goto lc_init_error;
@@ -83,7 +101,8 @@ WMError LayerControl::init() if(rc != ILM_SUCCESS) goto lc_init_error;
// Register Callback from ILM
- ilm_registerNotification(notification_static, this);
+ this->cb = cb;
+ ilm_registerNotification(createCallback_static, this);
return WMError::SUCCESS;
@@ -107,12 +126,45 @@ unsigned LayerControl::getNewLayerID(const string& role) return ret;
}
-WMError LayerControl::updateLayer(WMLayer& wm_layer)
+WMError LayerControl::updateLayer(LayerState& layer_state)
{
return WMError::SUCCESS;
}
-void LayerControl::commitChange() {}
+WMError LayerControl::commitChange()
+{
+ WMError rc = WMError::SUCCESS;
+ vector<unsigned> ivi_l_ids;
+ for(const auto& l : this->wm_layers)
+ {
+ auto state = l->getLayerState();
+ for(const auto& id : state.getIviIdList())
+ {
+ ivi_l_ids.push_back(id);
+ }
+ }
+ t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
+ if(id_array == nullptr)
+ {
+ HMI_WARNING("short memory");
+ this->undoUpdate();
+ return WMError::FAIL;
+ }
+ int count = 0;
+ for(const auto& i : ivi_l_ids)
+ {
+ id_array[count] = i;
+ }
+
+ ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
+ if(ret != ILM_SUCCESS)
+ {
+ this->undoUpdate();
+ rc = WMError::FAIL;
+ }
+ delete id_array;
+ return rc;
+}
void LayerControl::undoUpdate() {}
@@ -217,9 +269,162 @@ WMError LayerControl::loadAreaDb(const std::string& path) return WMError::SUCCESS;
}
-void LayerControl::dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created)
+void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
+{
+ this->cb.test(id);
+ if (ILM_SURFACE == object)
+ {
+ if (created)
+ {
+ ilmSurfaceProperties sp;
+ ilmErrorTypes rc;
+ rc = ilm_getPropertiesOfSurface(id, &sp);
+ if(rc != ILM_SUCCESS)
+ return;
+ // this->cb->surfaceCreated(pid, id);
+ ilm_surfaceAddNotification(id, surfaceCallback_static);
+ ilm_surfaceSetSourceRectangle(id, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
+ }
+ else
+ {
+ // this->cb->surfaceDestroyed(id);
+ }
+ }
+ if (ILM_LAYER == object)
+ {
+ if(created)
+ {
+ ilm_layerAddNotification(id, layerCallback_static);
+ // this->cb->layerCreated(id);
+ }
+ else
+ {
+ // this->cb->layerDestroyed(id); // Means Application is dead.
+ }
+ }
+}
+
+void LayerControl::dispatchPropertyChangeEvent(unsigned id,
+ struct ilmSurfaceProperties* sprop,
+ t_ilm_notification_mask mask)
+{
+ pid_t pid = sprop->creatorPid;
+ HMI_DEBUG("pid : %d", pid);
+
+ if (ILM_NOTIFICATION_VISIBILITY & mask)
+ {
+ //this->cb->surfaceVisibilityChanged(id, sprop->visibility);
+ }
+ if (ILM_NOTIFICATION_OPACITY & mask)
+ {
+ }
+ if (ILM_NOTIFICATION_ORIENTATION & mask)
+ {
+ }
+ if (ILM_NOTIFICATION_SOURCE_RECT & mask)
+ {
+ // this->cb->surfaceSourceRectChanged(id, )
+ }
+ if (ILM_NOTIFICATION_DEST_RECT & mask)
+ {
+ // this->cb->surfaceSourceRectChanged(id, )
+ }
+ if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
+ {
+ }
+ if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
+ {
+ /* application being down */
+ // m_appLayers.remove(pid);
+ }
+ if (ILM_NOTIFICATION_CONFIGURED & mask)
+ {
+ /* qDebug("ILM_NOTIFICATION_CONFIGURED");
+ qDebug(" surfaceProperties %d", surface);
+ qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
+ qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
+
+ if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
+ addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
+ configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
+ } else {
+ ilmErrorTypes result;
+ t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
+
+ if (layer != 0) {
+ configureAppSurface(surface,
+ surfaceProperties->origSourceWidth,
+ surfaceProperties->origSourceHeight);
+
+ result = ilm_layerAddSurface(layer, surface);
+ if (result != ILM_SUCCESS) {
+ qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
+ }
+ ilm_commitChanges();
+ }
+ }
+ updateScreen(); */
+ }
+}
+
+void LayerControl::dispatchPropertyChangeEvent(unsigned id,
+ struct ilmLayerProperties* lprop,
+ t_ilm_notification_mask mask)
{
- ;
+ if (ILM_NOTIFICATION_VISIBILITY & mask)
+ {
+ //this->cb->layerVisibilityChanged(id, sprop->visibility);
+ }
+ if (ILM_NOTIFICATION_OPACITY & mask)
+ {
+ }
+ if (ILM_NOTIFICATION_ORIENTATION & mask)
+ {
+ }
+ if (ILM_NOTIFICATION_SOURCE_RECT & mask)
+ {
+ // this->cb->surfaceSourceRectChanged(id, )
+ }
+ if (ILM_NOTIFICATION_DEST_RECT & mask)
+ {
+ // this->cb->surfaceSourceRectChanged(id, )
+ }
+ if (ILM_NOTIFICATION_CONTENT_AVAILABLE & mask)
+ {
+ }
+ if (ILM_NOTIFICATION_CONTENT_REMOVED & mask)
+ {
+ /* application being down */
+ // m_appLayers.remove(pid);
+ }
+ if (ILM_NOTIFICATION_CONFIGURED & mask)
+ {
+ /* qDebug("ILM_NOTIFICATION_CONFIGURED");
+ qDebug(" surfaceProperties %d", surface);
+ qDebug(" surfaceProperties.origSourceWidth: %d", surfaceProperties->origSourceWidth);
+ qDebug(" surfaceProperties.origSourceHeight: %d", surfaceProperties->origSourceHeight);
+
+ if (surface == WINDOWMANAGER_HOMESCREEN_MAIN_SURFACE_ID) {
+ addSurfaceToLayer(surface, WINDOWMANAGER_LAYER_HOMESCREEN);
+ configureHomeScreenMainSurface(surface, surfaceProperties->origSourceWidth, surfaceProperties->origSourceHeight);
+ } else {
+ ilmErrorTypes result;
+ t_ilm_layer layer = addSurfaceToAppLayer(pid, surface);
+
+ if (layer != 0) {
+ configureAppSurface(surface,
+ surfaceProperties->origSourceWidth,
+ surfaceProperties->origSourceHeight);
+
+ result = ilm_layerAddSurface(layer, surface);
+ if (result != ILM_SUCCESS) {
+ qDebug("ilm_layerAddSurface(%d,%d) failed.", layer, surface);
+ }
+ ilm_commitChanges();
+ }
+ }
+ updateScreen(); */
+ }
}
} // namespace wm
\ No newline at end of file diff --git a/src/wm_layer_control.hpp b/src/wm_layer_control.hpp index d8d3273..ad6bf53 100644 --- a/src/wm_layer_control.hpp +++ b/src/wm_layer_control.hpp @@ -18,6 +18,7 @@ #include <memory>
#include <vector>
#include <unordered_map>
+#include <functional>
#include <ilm/ilm_control.h>
#include "wm_error.hpp"
#include "util.hpp"
@@ -28,31 +29,50 @@ class Screen : public rectangle { };
+class LayerControlCallbacks {
+ public:
+ LayerControlCallbacks() {};
+ virtual ~LayerControlCallbacks() = default;
+ LayerControlCallbacks(const LayerControlCallbacks &obj) = default;
+
+ // callback functions
+ virtual void test(unsigned i) { HMI_DEBUG("test %d", i); }
+ std::function<void(unsigned)> surfaceCreated;
+ /* std::function<void(unsigned)> surfaceDestroyed;
+ std::function<void(unsigned)> layerCreated;
+ std::function<void(unsigned)> layerDestroyed; */
+};
+
class WMLayer;
+class LayerState;
class LayerControl
{
public:
explicit LayerControl(const std::string& root);
~LayerControl() = default;
- WMError init();
+ WMError init(const LayerControlCallbacks& cb);
unsigned getNewLayerID(const std::string& role);
// void setRenderOrder(const std::vector<unsigned> layer_render_order);
// std::vector<unsigned> getAllRenderOrder();
// std::vector<std::shared_ptr<WMLayer>>& getAllLayers();
// std::vector<unsigned> getRenderOrder(const std::string& layer_name);
- WMError updateLayer(WMLayer& wm_layer);
- void commitChange();
+ WMError updateLayer(LayerState& layer_state);
+ WMError commitChange();
void undoUpdate();
// Don't use this function.
- void dispatchILMEvent(ilmObjectType object, t_ilm_uint id, t_ilm_bool created);
+ void dispatchCreateEvent(ilmObjectType object, unsigned id, bool created);
+ void dispatchPropertyChangeEvent(unsigned id, struct ilmSurfaceProperties*, t_ilm_notification_mask);
+ void dispatchPropertyChangeEvent(unsigned id, struct ilmLayerProperties*, t_ilm_notification_mask);
private:
WMError loadLayerSetting(const std::string& path);
WMError loadAreaDb(const std::string& path);
+
std::vector<std::shared_ptr<WMLayer>> wm_layers;
std::unordered_map<std::string, struct rect> area2size;
unsigned screenID;
struct ilmScreenProperties screen_prop;
+ LayerControlCallbacks cb;
};
} // namespace wm
\ No newline at end of file |