This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit dc2069a702aa821dac24e8e0df4ddfeeaa304dc8
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:44:06 2026 -0600

    elementary: position_manager_list: rebuild only when the average changes
    
    Nothing in the tree said that the size it gave was an estimate, so a
    list over an Average_Model only had its first and last item checked for
    a change of what the average did to the other rows. The view now gives
    the rows nobody measured of an Average_Model the average, says that they
    are an estimate, and gives a version of it that is another when the
    average is (the Average_Model keeps that, and says the total changed
    when the average does, as it learns it after the fact). The list manager
    keeps the version it built the cache with, and asks again after a
    change, once for the changes that came together: the cache is built
    again only if the version is another, where it was for any change
    before.
    
    The counting position manager classes of the tests were kept from one
    init of the library to the next, so that the tests that are not forked
    made no manager and counted nothing: they are made for each test now.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_average_model.c          |  46 ++++
 src/lib/elementary/efl_ui_collection_view.c        |  50 ++++-
 .../elementary/efl_ui_position_manager_common.h    |   2 +-
 .../efl_ui_position_manager_data_access_v1.eo      |   7 +-
 src/lib/elementary/efl_ui_position_manager_list.c  |  74 +++++--
 src/lib/elementary/elm_priv.h                      |   4 +
 src/tests/elementary/efl_ui_test_collection_view.c | 244 +++++++++++++++++++--
 7 files changed, 382 insertions(+), 45 deletions(-)

diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index 8a188980b5..b2dbbff928 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -16,6 +16,7 @@ typedef struct _Efl_Ui_Average_Model_Data Efl_Ui_Average_Model_Data;
 struct _Efl_Ui_Average_Model_Data
 {
    Efl_Ui_Average_Model_Data *parent;
+   Eo *self;
 
    struct {
       unsigned long long width;
@@ -27,6 +28,11 @@ struct _Efl_Ui_Average_Model_Data
    // The times the Exact_Model gave up its sizes that this has seen
    unsigned int forgotten;
 
+   // The average of the heights the last time it was asked for or changed, and
+   // the number of times it changed (what a view that estimates with it keeps)
+   unsigned long long average;
+   unsigned int revision;
+
    // What a row was told that has not been added to the totals yet (it is
    // added when the loop gets to it), for the row that leaves before that.
    Eina_List *pending;
@@ -45,6 +51,19 @@ struct _Efl_Ui_Average_Model_Update
    Eina_Bool dropped : 1;
 };
 
+// What an item is estimated to be, from what was told: not a number of its own,
+// a change of it is what makes the estimates of the others change.
+static Eina_Bool
+_efl_ui_average_model_revise(Efl_Ui_Average_Model_Data *root)
+{
+   unsigned long long average = root->total.hseen ? root->total.height / root->total.hseen : 0;
+
+   if (average == root->average) return EINA_FALSE;
+   root->average = average;
+   root->revision++;
+   return EINA_TRUE;
+}
+
 // Totals of what the Exact_Model says is not kept any more are of no use
 static void
 _efl_ui_average_model_forgotten_check(const Eo *obj, Efl_Ui_Average_Model_Data *root)
@@ -60,6 +79,7 @@ _efl_ui_average_model_forgotten_check(const Eo *obj, Efl_Ui_Average_Model_Data *
         update->dropped = EINA_TRUE;
      }
    memset(&root->total, 0, sizeof (root->total));
+   _efl_ui_average_model_revise(root);
 }
 
 static Eina_Value
@@ -75,6 +95,9 @@ _efl_ui_average_model_update(Eo *obj EINA_UNUSED, void *data, const Eina_Value v
    // (a row that shrinks takes from the total: the difference is signed)
    *(request->total) += (long long) now - (long long) request->previous;
    if (request->seen) *(request->seen) += 1;
+   // What is estimated for the rows nobody measured is another one: nothing else says it
+   if (_efl_ui_average_model_revise(request->root))
+     efl_model_properties_changed(request->root->self, _efl_model_property_totalh);
 
    return v;
 }
@@ -196,10 +219,12 @@ _efl_ui_average_model_child_removed(void *data, const Efl_Event *event)
         ERR("The average of the heights does not hold the row that was removed: "
             "starting it again.");
         memset(&pd->total, 0, sizeof (pd->total));
+        _efl_ui_average_model_revise(pd);
         return;
      }
    pd->total.height -= height;
    if (seen) pd->total.hseen--;
+   _efl_ui_average_model_revise(pd);
 }
 
 static Eina_Future *
@@ -278,6 +303,7 @@ _efl_ui_average_model_efl_object_constructor(Eo *obj, Efl_Ui_Average_Model_Data
 {
    Eo *parent = efl_parent_get(obj);
 
+   pd->self = obj;
    if (parent && efl_isa(parent, EFL_UI_AVERAGE_MODEL_CLASS))
      pd->parent = efl_data_scope_get(efl_parent_get(obj), EFL_UI_AVERAGE_MODEL_CLASS);
 
@@ -291,4 +317,24 @@ _efl_ui_average_model_efl_object_constructor(Eo *obj, Efl_Ui_Average_Model_Data
    return obj;
 }
 
+/* What a view that estimates the rows nobody measured of an Average_Model gives
+   them: true if it is one (the rows nobody measured are then an estimate), with
+   the height of the average of those that were if any was (known), and a number
+   that is another every time that height changes. */
+Eina_Bool
+_efl_ui_average_model_estimate_get(const Efl_Model *exact, unsigned int *height,
+                                   Eina_Bool *known, unsigned int *revision)
+{
+   Efl_Ui_Average_Model_Data *pd;
+
+   if (!efl_isa(exact, EFL_UI_AVERAGE_MODEL_CLASS)) return EINA_FALSE;
+   pd = efl_data_scope_get(exact, EFL_UI_AVERAGE_MODEL_CLASS);
+   if (!pd || pd->parent) return EINA_FALSE;
+   _efl_ui_average_model_forgotten_check(exact, pd);
+   *revision = pd->revision;
+   *known = !!pd->total.hseen;
+   *height = pd->average;
+   return EINA_TRUE;
+}
+
 #include "efl_ui_average_model.eo.c"
diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index 50d8621f1f..27b2a017c1 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -888,7 +888,7 @@ _cache_size_fetch(Eina_List *requests, Efl_Ui_Collection_Request **request,
                   Efl_Ui_Collection_View_Data *pd, Efl_Model *exact,
                   unsigned int search_index,
                   Efl_Ui_Position_Manager_Size_Batch_Entity *target,
-                  Eina_Size2D item_base)
+                  Eina_Size2D item_base, Eina_Bool *based)
 {
    Efl_Ui_Collection_Item_Lookup *lookup;
    Efl_Model *model = NULL;
@@ -925,6 +925,8 @@ _cache_size_fetch(Eina_List *requests, Efl_Ui_Collection_Request **request,
    // If we do not know the size
    if (!ITEM_SIZE_FROM_MODEL(model, item_size))
      {
+        // (the row has the size that stands in for the ones nobody knows)
+        *based = EINA_TRUE;
         if (lookup->item.entity)
           {
              ERR("Got a model '%s' and an item '%s', but no size. Recalculating.",
@@ -951,6 +953,7 @@ _cache_size_fetch(Eina_List *requests, Efl_Ui_Collection_Request **request,
    return requests;
 
  not_found:
+   *based = EINA_TRUE;
    requests = _request_add(requests, request, search_index, EINA_FALSE);
 
    target->size = item_size;
@@ -1182,6 +1185,8 @@ _batch_size_cb(void *data, Efl_Ui_Position_Manager_Size_Call_Config conf, Eina_R
    Eina_Size2D item_base = {0};
    unsigned int limit;
    unsigned int idx = 0;
+   unsigned int average = 0, revision = 0;
+   Eina_Bool based = EINA_FALSE, averaged = EINA_FALSE, known = EINA_FALSE;
 
    // get the approximate value from the tree node
    parent = pd->model;
@@ -1227,6 +1232,17 @@ _batch_size_cb(void *data, Efl_Ui_Position_Manager_Size_Call_Config conf, Eina_R
         item_base = pd->size_stand_in;
      }
 
+   /* The rows nobody measured of an Average_Model are as high as the average of
+      the ones that were. That changes with what is measured, which is said
+      to the position manager: what it has of the other rows is then not what
+      they are now. */
+   if (exact && _efl_ui_average_model_estimate_get(exact, &average, &known, &revision))
+     {
+        // (a row nobody measured has the size of the view until there is an average)
+        if (known) item_base.h = average;
+        averaged = EINA_TRUE;
+     }
+
    // Look in the temporary cache now for the beginning of the buffer
 #ifdef VIEWPORT_ENABLE
    if (pd->viewport[0] && ((unsigned int)(conf.range.start_id + idx) < pd->viewport[0]->offset))
@@ -1235,7 +1251,7 @@ _batch_size_cb(void *data, Efl_Ui_Position_Manager_Size_Call_Config conf, Eina_R
           {
              unsigned int search_index = conf.range.start_id + idx;
              requests = _cache_size_fetch(requests, &request, pd, exact,
-                                          search_index, &sizes[idx], item_base);
+                                          search_index, &sizes[idx], item_base, &based);
              idx++;
           }
      }
@@ -1307,7 +1323,7 @@ _batch_size_cb(void *data, Efl_Ui_Position_Manager_Size_Call_Config conf, Eina_R
      {
         unsigned int search_index = conf.range.start_id + idx;
         requests = _cache_size_fetch(requests, &request, pd, exact,
-                                     search_index, &sizes[idx], item_base);
+                                     search_index, &sizes[idx], item_base, &based);
         idx++;
      }
 #endif
@@ -1348,7 +1364,7 @@ _batch_size_cb(void *data, Efl_Ui_Position_Manager_Size_Call_Config conf, Eina_R
           {
              unsigned int search_index = conf.range.start_id + idx;
              requests = _cache_size_fetch(requests, &request, pd, exact,
-                                          search_index, &sizes[idx], item_base);
+                                          search_index, &sizes[idx], item_base, &based);
              idx++;
           }
 
@@ -1361,6 +1377,8 @@ _batch_size_cb(void *data, Efl_Ui_Position_Manager_Size_Call_Config conf, Eina_R
 
    // Get the amount of filled item
    result.filled_items = limit;
+   result.estimated = averaged && based;
+   result.estimate_version = revision;
 
    return result;
 }
@@ -2150,11 +2168,33 @@ _efl_model_count_changed(void *data, const Efl_Event *event EINA_UNUSED)
 }
 
 static void
-_efl_model_properties_changed(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
+_efl_model_properties_changed(void *data, const Efl_Event *event)
 {
+   Efl_Model_Property_Event *ev = event->info;
+   Efl_Model *exact;
+   Eina_Array_Iterator it;
+   const char *property;
+   unsigned int i;
+   MY_DATA_GET(data, pd);
+
    // We could here watch if the global base size item change and notify of a global change
    // But I can not find a proper way to do it for the object that are not visible, which
    // is kind of the point...
+
+   /* What is estimated for the rows nobody measured is what the Average_Model
+      says its total is made of, and it said that it changed: the position manager is
+      told that some size may have, to ask if what it keeps of the other rows is
+      still what they are. */
+   if (!pd->manager || !ev || !ev->changed_properties) return;
+   exact = _efl_ui_exact_model_find(pd->model);
+   if (!exact || !efl_isa(exact, EFL_UI_AVERAGE_MODEL_CLASS)) return;
+   EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, property, it)
+     {
+        if (!eina_streq(property, _efl_model_property_totalh)) continue;
+        if (efl_model_children_count_get(pd->model))
+          efl_ui_position_manager_entity_item_size_changed(pd->manager, 0, 0);
+        return;
+     }
 }
 
 static void
diff --git a/src/lib/elementary/efl_ui_position_manager_common.h b/src/lib/elementary/efl_ui_position_manager_common.h
index 6481d62ff6..fa84c53517 100644
--- a/src/lib/elementary/efl_ui_position_manager_common.h
+++ b/src/lib/elementary/efl_ui_position_manager_common.h
@@ -51,7 +51,7 @@ _batch_request_size(Api_Callbacks cb , int start_id, int end_id, int len, Eina_B
 
 // What is already known of the sizes only: nothing is fetched to answer, and an
 // item that is not known is 0x0
-static Efl_Ui_Position_Manager_Size_Batch_Result
+static EINA_UNUSED Efl_Ui_Position_Manager_Size_Batch_Result
 _batch_request_size_known(Api_Callbacks cb , int start_id, int end_id, int len, void *data)
 {
    return _batch_request_size_config(cb, start_id, end_id, len, EINA_TRUE, EINA_TRUE, data);
diff --git a/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo b/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo
index 4e2b216c67..8a1dd4b7dc 100644
--- a/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo
+++ b/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo
@@ -38,7 +38,12 @@ struct @beta Efl.Ui.Position_Manager.Size_Batch_Result {
 
                        A position manager that was given such a size cannot know of
                        the items it was not told about when it is told that some
-                       others changed, and asks for all of them again.]]
+                       others changed, unless the estimate is still the same one: it
+                       asks for all of them again if @.estimate_version is not.]]
+   estimate_version : uint; [[A number that is another one every time the estimates the provider gives
+                              change (that of the average of the measured items, say, and not for
+                                      each item that is measured). Only the sameness of two of them is
+                              of use. It is 0 for a provider that never estimates.]]
 }
 
 struct @beta Efl.Ui.Position_Manager.Size_Call_Config {
diff --git a/src/lib/elementary/efl_ui_position_manager_list.c b/src/lib/elementary/efl_ui_position_manager_list.c
index 2023b4d79a..4685681f17 100644
--- a/src/lib/elementary/efl_ui_position_manager_list.c
+++ b/src/lib/elementary/efl_ui_position_manager_list.c
@@ -38,10 +38,14 @@ typedef struct {
    unsigned int dirty_hi;
    int average_item_size;
    int maximum_min_size;
+   // The version of what the provider estimated when the cache was built
+   unsigned int estimate_version;
    Eina_Bool dirty : 1;
    // Some of what the cache holds is an estimate of the provider: no change is
    // known to leave the rest of it as it is
    Eina_Bool estimated : 1;
+   // A change was told since, and it is not known yet if what is estimated is the same
+   Eina_Bool estimate_check : 1;
 } Efl_Ui_Position_Manager_List_Data;
 
 /*
@@ -61,6 +65,7 @@ cache_invalidate(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
    pd->cache_size = 0;
    pd->dirty = EINA_FALSE;
    pd->estimated = EINA_FALSE;
+   pd->estimate_check = EINA_FALSE;
 }
 
 static void _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd);
@@ -77,7 +82,7 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
    if (pd->size_cache)
      {
         // What changed since is asked for now, all at once
-        if ((pd->dirty) || (pd->size != pd->cache_size))
+        if ((pd->dirty) || (pd->size != pd->cache_size) || (pd->estimate_check))
           {
              _cache_changes_apply(obj, pd);
           }
@@ -96,6 +101,7 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
    pd->size_cache[0] = 0;
    pd->maximum_min_size = 0;
    pd->estimated = EINA_FALSE;
+   pd->estimate_check = EINA_FALSE;
 
    for (i = 0; i < pd->size; ++i)
      {
@@ -111,6 +117,7 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
              filled = MIN(size_result.filled_items, len);
              batch_start = i;
              if (size_result.estimated) pd->estimated = EINA_TRUE;
+             pd->estimate_version = size_result.estimate_version;
              if (!filled)
                {
                   // Not a cache of what is not known
@@ -157,8 +164,11 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
  * What is not known about the other items is whether they are the same, if
  * the answer of the provider is something that changes under them. A provider
  * that gives an estimate (the average of what was measured, say) says so with
- * the result of the size callback, and nothing is then assumed of the items
- * that were not told of: any change drops the cache for a full build.
+ * the result of the size callback, and gives a version of it that is another
+ * when the estimate is. What the cache has of the items that were not told of
+ * is then as good as the version is the same, which is asked again after any
+ * change (once, for all that came together), and the cache is built again when
+ * it is not.
  *
  * For one that does not say so but whose answer changes still (the size of the
  * view before anything was measured, which a shared size replaces when the
@@ -174,7 +184,7 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
  */
 static Eina_Bool
 _cache_range_ask(Efl_Ui_Position_Manager_List_Data *pd, unsigned int start, unsigned int end,
-                 int *steps, int *max_min, Eina_Bool *estimated)
+                 int *steps, int *max_min, Eina_Bool *estimated, unsigned int *version)
 {
    Efl_Ui_Position_Manager_Size_Batch_Entity size_buffer[100];
    Efl_Ui_Position_Manager_Size_Batch_Result size_result;
@@ -193,6 +203,7 @@ _cache_range_ask(Efl_Ui_Position_Manager_List_Data *pd, unsigned int start, unsi
              filled = MIN(size_result.filled_items, 100);
              batch_start = i;
              if (size_result.estimated) *estimated = EINA_TRUE;
+             *version = size_result.estimate_version;
              if (filled == 0) return EINA_FALSE;
           }
         size = size_buffer[i - batch_start].size;
@@ -217,10 +228,16 @@ static Eina_Bool
 _cache_probe(Efl_Ui_Position_Manager_List_Data *pd, unsigned int item)
 {
    int step = 0, max_min = 0;
+   unsigned int version = 0;
    Eina_Bool estimated = EINA_FALSE;
 
    if (item >= pd->cache_size) return EINA_TRUE;
-   if (!_cache_range_ask(pd, item, item + 1, &step, &max_min, &estimated)) return EINA_FALSE;
+   if (!_cache_range_ask(pd, item, item + 1, &step, &max_min, &estimated, &version))
+     {
+        return EINA_FALSE;
+     }
+   // (the cache is not as it was if what is estimated is not, whatever this item is)
+   if ((pd->estimated) && (version != pd->estimate_version)) return EINA_FALSE;
    return (pd->size_cache[item + 1] - pd->size_cache[item]) == step;
 }
 
@@ -277,11 +294,24 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
    int *cache, *steps;
    int max_min = pd->maximum_min_size;
    int old_end, delta;
+   unsigned int version = pd->estimate_version;
    Eina_Bool estimated = EINA_FALSE;
 
    if (pd->size < pd->cache_size) goto full;
-   // Any change may have changed what the provider estimates for the items it was not told of
-   if (pd->estimated) goto full;
+   // Any change may have changed what the provider estimates for the items it was not told of:
+   // if it did, those are asked for again, which is the cache built again
+   if (pd->estimated && pd->estimate_check)
+     {
+        int step = 0, none = 0;
+        Eina_Bool ignored = EINA_FALSE;
+
+        pd->estimate_check = EINA_FALSE;
+        if (pd->cache_size &&
+            (!_cache_range_ask(pd, 0, 1, &step, &none, &ignored, &version) ||
+             version != pd->estimate_version))
+          goto full;
+     }
+   pd->estimate_check = EINA_FALSE;
 
    if (pd->dirty)
      {
@@ -292,7 +322,7 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
           {
              steps = malloc((to - from) * sizeof (int));
              if (!steps) goto full;
-             if (!_cache_range_ask(pd, from, to, steps, &max_min, &estimated))
+             if (!_cache_range_ask(pd, from, to, steps, &max_min, &estimated, &version))
                {
                   free(steps);
                   goto full;
@@ -323,7 +353,7 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
      {
         steps = malloc((to - from) * sizeof (int));
         if (!steps) goto full;
-        if (!_cache_range_ask(pd, from, to, steps, &max_min, &estimated))
+        if (!_cache_range_ask(pd, from, to, steps, &max_min, &estimated, &version))
           {
              free(steps);
              goto full;
@@ -345,10 +375,13 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
         new_hi = to - 1;
      }
 
+   // What was asked is told with the estimate the others have, or they are not what they were
+   if ((pd->estimated) && (version != pd->estimate_version)) goto full;
    pd->maximum_min_size = max_min;
-   if (estimated)
+   if (estimated && !pd->estimated)
      {
         pd->estimated = EINA_TRUE;
+        pd->estimate_version = version;
      }
    _cache_checked(obj, pd, dirty_lo, dirty_hi, new_lo, new_hi);
    return;
@@ -365,12 +398,8 @@ _cache_item_added(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, unsigned int i
 
    // Not built: the first build will have the item
    if (!pd->size_cache) return;
-   // What is estimated for the others is not the same with one more
-   if (pd->estimated)
-     {
-        cache_invalidate(obj, pd);
-        return;
-     }
+   // What is estimated for the others may not be the same with one more
+   if (pd->estimated) pd->estimate_check = EINA_TRUE;
    // Past what the cache has: asked for with the others that came, when it is needed
    if (idx >= pd->cache_size) return;
 
@@ -411,12 +440,8 @@ _cache_item_removed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, unsigned int
    unsigned int i;
 
    if (!cache) return;
-   // What is estimated for the others is not the same with one less
-   if (pd->estimated)
-     {
-        cache_invalidate(obj, pd);
-        return;
-     }
+   // What is estimated for the others may not be the same with one less
+   if (pd->estimated) pd->estimate_check = EINA_TRUE;
    // One of those not asked for yet
    if (idx >= pd->cache_size)
      {
@@ -459,12 +484,13 @@ _cache_item_size_changed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd,
                          unsigned int start, unsigned int end)
 {
    if (!pd->size_cache) return;
-   // Whatever changed, what is estimated for the others did too
-   if (start > end || pd->estimated)
+   if (start > end)
      {
         cache_invalidate(obj, pd);
         return;
      }
+   // Whatever changed, what is estimated for the others may have too
+   if (pd->estimated) pd->estimate_check = EINA_TRUE;
    // The items not asked for yet will be, as they are then
    if (start >= pd->cache_size) return;
    _cache_dirty(pd, start, MIN(end, pd->cache_size - 1));
diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h
index 91cc874550..da3f7efaf9 100644
--- a/src/lib/elementary/elm_priv.h
+++ b/src/lib/elementary/elm_priv.h
@@ -668,6 +668,10 @@ Eina_Bool            _efl_ui_exact_model_row_size_get(Efl_Model *exact,
 Eina_Bool            _efl_ui_exact_model_removed_height_get(const Efl_Model *exact,
                                                             unsigned int *height);
 unsigned int         _efl_ui_exact_model_forgotten_get(const Efl_Model *exact);
+Eina_Bool            _efl_ui_average_model_estimate_get(const Efl_Model *exact,
+                                                        unsigned int *height,
+                                                        Eina_Bool *known,
+                                                        unsigned int *revision);
 Eina_Bool            _elm_web_init(const char *engine);
 
 Eo                   *_elm_atspi_bridge_get(void);
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index c826f87a69..33bb849fdb 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -6,6 +6,7 @@
 #include "efl_ui_suite.h"
 #include "efl_ui_homogeneous_model.eo.h"
 #include "efl_ui_exact_model.eo.h"
+#include "efl_ui_average_model.eo.h"
 
 #define NUM_ITEMS 50
 #define SINGLE_ADDS 2000
@@ -1299,6 +1300,8 @@ EFL_END_TEST
 static unsigned int _diff_measured[DIFF_MAX_ROWS]; // 0: not measured
 static unsigned int _diff_count = 0;
 static unsigned int _diff_cap = 7;
+// The rows the provider was asked for, all told
+static unsigned int _diff_asked = 0;
 // Whether the rows nobody measured get the average (and are said to be an estimate), or 40
 static Eina_Bool _diff_estimates = EINA_TRUE;
 
@@ -1329,6 +1332,9 @@ _diff_size_cb(void *data EINA_UNUSED, Efl_Ui_Position_Manager_Size_Call_Config c
         if (!measured && _diff_estimates) result.estimated = EINA_TRUE;
      }
    result.filled_items = i;
+   // (the estimate is the average: it is another when that is)
+   if (_diff_estimates) result.estimate_version = average;
+   _diff_asked += i;
    return result;
 }
 
@@ -1464,6 +1470,77 @@ EFL_START_TEST(test_efl_ui_position_manager_list_differential)
 }
 EFL_END_TEST
 
+/* An estimate that stays the same is not a reason to ask for every item again:
+   a row that comes with the average as it was costs the rows that changed, and a
+   row that is measured and changes the average makes all of them be asked
+   again, and the result is what a manager that is given the final rows has. */
+EFL_START_TEST(test_efl_ui_position_manager_list_estimate_stable)
+{
+   Efl_Ui_Win *win;
+   Efl_Ui_Position_Manager_Entity *manager;
+   const unsigned int rows = 600;
+   unsigned int i;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   _cache_dummy = efl_add(EFL_UI_BUTTON_CLASS, win);
+   _diff_estimates = EINA_TRUE;
+   _diff_cap = 100;
+   _diff_count = rows;
+   memset(_diff_measured, 0, sizeof (_diff_measured));
+   // (all as high as 20: the average is, whichever of them are measured)
+   for (i = 0; i < _diff_count; i += 5)
+     {
+        _diff_measured[i] = 20;
+     }
+   manager = _diff_manager_add(win);
+   _diff_check(win, manager, 0);
+
+   // One more row, nobody measured it: the average is what it was
+   _diff_asked = 0;
+   memmove(_diff_measured + 301, _diff_measured + 300, (_diff_count - 300) * sizeof (unsigned int));
+   _diff_measured[300] = 0;
+   _diff_count++;
+   efl_ui_position_manager_entity_item_added(manager, 300, NULL);
+   ecore_main_loop_iterate();
+   efl_ui_position_manager_entity_position_single_item(manager, 0);
+   ck_assert_uint_lt(_diff_asked, rows / 4);
+   _diff_check(win, manager, 1);
+
+   // One that was measured as the average is still the average
+   _diff_asked = 0;
+   _diff_measured[10] = 20;
+   efl_ui_position_manager_entity_item_size_changed(manager, 11, 11);
+   _diff_measured[11] = 20;
+   efl_ui_position_manager_entity_item_size_changed(manager, 11, 11);
+   ecore_main_loop_iterate();
+   efl_ui_position_manager_entity_position_single_item(manager, 0);
+   ck_assert_uint_lt(_diff_asked, rows / 4);
+   _diff_check(win, manager, 2);
+
+   // One that was measured another: the average is another, and so is every row that has it
+   _diff_asked = 0;
+   _diff_measured[5] = 500;
+   efl_ui_position_manager_entity_item_size_changed(manager, 5, 5);
+   ecore_main_loop_iterate();
+   efl_ui_position_manager_entity_position_single_item(manager, 0);
+   ck_assert_uint_ge(_diff_asked, rows);
+   _diff_check(win, manager, 3);
+
+   // And the same for a measured one that leaves
+   _diff_asked = 0;
+   memmove(_diff_measured + 5, _diff_measured + 6, (_diff_count - 6) * sizeof (unsigned int));
+   _diff_count--;
+   efl_ui_position_manager_entity_item_removed(manager, 5, NULL);
+   ecore_main_loop_iterate();
+   efl_ui_position_manager_entity_position_single_item(manager, 0);
+   ck_assert_uint_ge(_diff_asked, rows);
+   _diff_check(win, manager, 4);
+
+   efl_del(manager);
+   _diff_cap = 7;
+}
+EFL_END_TEST
+
 /* The groups of the grid position manager follow items that are added or
    removed, with the sizes that are asked for only once: a grid told of every
    change must place every item where a grid that is given the final items
@@ -1619,6 +1696,10 @@ _counting_manager_initializer(Efl_Class *klass)
    return efl_class_functions_set(klass, &ops, NULL);
 }
 
+// (made at each call, and not kept in a static: a class made with efl_class_new
+// is freed with the Eo shutdown, and the tests that are not forked init and shut
+// the library down for each test, so a pointer kept from one test would dangle in
+// the next. It is called once per test, so there is nothing to save.)
 static const Efl_Class *
 _counting_manager_class_get(Eina_Bool grid)
 {
@@ -1640,18 +1721,10 @@ _counting_manager_class_get(Eina_Bool grid)
       NULL,
       NULL
    };
-   static const Efl_Class *list_klass = NULL;
-   static const Efl_Class *grid_klass = NULL;
 
-   if (grid)
-     {
-        if (!grid_klass)
-          grid_klass = efl_class_new(&grid_desc, EFL_UI_POSITION_MANAGER_GRID_CLASS, NULL);
-        return grid_klass;
-     }
-   if (!list_klass)
-     list_klass = efl_class_new(&list_desc, EFL_UI_POSITION_MANAGER_LIST_CLASS, NULL);
-   return list_klass;
+   return efl_class_new(grid ? &grid_desc : &list_desc,
+                        grid ? EFL_UI_POSITION_MANAGER_GRID_CLASS : EFL_UI_POSITION_MANAGER_LIST_CLASS,
+                        NULL);
 }
 
 /* Rows are added one at a time to a view that is showing an Exact_Model, as a
@@ -1992,10 +2065,9 @@ _fetch_counting_class_get(const Efl_Class *parent)
       NULL,
       NULL
    };
-   static const Efl_Class *klass = NULL;
 
-   if (!klass) klass = efl_class_new(&desc, parent, NULL);
-   return klass;
+   // (not kept, see _counting_manager_class_get)
+   return efl_class_new(&desc, parent, NULL);
 }
 
 /* The biggest minimum size of a grid is asked again when an item goes, and is
@@ -2049,6 +2121,148 @@ EFL_START_TEST(test_efl_ui_collection_view_grid_remove_fetches_nothing)
 }
 EFL_END_TEST
 
+/* A list over an Average_Model: the rows nobody measured are as high as the
+   average of those that were. */
+#define AVG_ROWS 300
+
+static unsigned int _avg_row_height = 40;
+
+static void
+_row_height_avg(void *data EINA_UNUSED, const Efl_Event *ev)
+{
+   Efl_Gfx_Entity *item = ev->info;
+
+   efl_gfx_hint_size_min_set(item, EINA_SIZE2D(0, _avg_row_height));
+}
+
+static Eina_Value
+_avg_rows_then(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
+{
+   Eo **rows = data;
+   unsigned int i, len;
+   Eo *c;
+
+   EINA_VALUE_ARRAY_FOREACH(&v, len, i, c)
+     {
+        rows[i] = efl_ref(c);
+     }
+   return v;
+}
+
+/* Every item is where the heights the model has for the rows say, and the rows
+   nobody measured are the average of those that were. */
+static void
+_avg_positions_check(Efl_Ui_Position_Manager_Entity *manager, Efl_Model *sizes, unsigned int n)
+{
+   Eo *rows[AVG_ROWS + 8] = { NULL };
+   unsigned int heights[AVG_ROWS + 8];
+   unsigned int i, sum = 0, seen = 0, average, y = 0;
+   int loops;
+
+   eina_future_then(efl_model_children_slice_get(sizes, 0, n), _avg_rows_then, rows, NULL);
+   for (loops = 0; (loops < 20) && !rows[n - 1]; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_ptr_ne(rows[n - 1], NULL);
+   for (i = 0; i < n; i++)
+     {
+        Eina_Value *v = efl_model_property_get(rows[i], "self.height");
+        unsigned int h = 0;
+
+        heights[i] = 0;
+        if (eina_value_type_get(v) != EINA_VALUE_TYPE_ERROR && eina_value_uint_convert(v, &h))
+          {
+             heights[i] = h;
+             sum += h;
+             seen++;
+          }
+        eina_value_free(v);
+     }
+   average = seen ? sum / seen : 0;
+   for (i = 0; i < n; i++)
+     {
+        Eina_Rect r = efl_ui_position_manager_entity_position_single_item(manager, i);
+        unsigned int expected = heights[i] ? heights[i] : average;
+
+        ck_assert_int_eq(r.y, y);
+        ck_assert_int_eq(r.h, expected);
+        y += expected;
+        efl_unref(rows[i]);
+     }
+}
+
+EFL_START_TEST(test_efl_ui_collection_view_average_model_estimates)
+{
+   Efl_Ui_Win *win;
+   Efl_Model *model, *sizes;
+   Efl_Ui_Factory *fl;
+   Efl_Ui_List_View *lv;
+   Efl_Ui_Position_Manager_Entity *manager;
+   Efl_Model *base;
+   unsigned int count;
+   int i;
+
+   _avg_row_height = 40;
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   efl_gfx_entity_size_set(win, EINA_SIZE2D(200, 300));
+
+   model = _make_model(win);
+   for (i = NUM_ITEMS; i < AVG_ROWS - 1; i++)
+     {
+        efl_model_child_add(model);
+     }
+   base = efl_ui_view_model_get(model);
+   sizes = efl_add(EFL_UI_AVERAGE_MODEL_CLASS, win, efl_ui_view_model_set(efl_added, model));
+   manager = efl_new(_counting_manager_class_get(EINA_FALSE));
+   fl = efl_add(EFL_UI_WIDGET_FACTORY_CLASS, win,
+                efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_PLACEHOLDER_ITEM_CLASS),
+                efl_event_callback_add(efl_added, EFL_UI_FACTORY_EVENT_ITEM_BUILDING,
+                                       _row_height_avg, NULL));
+   lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+                efl_ui_collection_view_position_manager_set(efl_added, manager),
+                efl_ui_collection_view_factory_set(efl_added, fl),
+                efl_ui_view_model_set(efl_added, sizes));
+   efl_content_set(win, lv);
+   get_me_to_those_events(lv);
+   for (i = 0; i < 50; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   count = efl_model_children_count_get(sizes);
+   ck_assert_uint_eq(count, AVG_ROWS - 1);
+   _avg_positions_check(manager, sizes, count);
+
+   // A row comes at the end, and is measured the same as the others: the average is what it was
+   _counted_rows = 0;
+   efl_model_child_add(base);
+   for (i = 0; i < 20; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   count = efl_model_children_count_get(sizes);
+   ck_assert_uint_eq(count, AVG_ROWS);
+   ck_assert_uint_lt(_counted_rows, AVG_ROWS / 3);
+   _avg_positions_check(manager, sizes, count);
+
+   // The ones that come are higher: the average is another, and every row has it
+   _avg_row_height = 200;
+   _counted_rows = 0;
+   for (i = 0; i < 3; i++)
+     {
+        efl_model_child_add(base);
+     }
+   for (i = 0; i < 20; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   count = efl_model_children_count_get(sizes);
+   ck_assert_uint_eq(count, AVG_ROWS + 3);
+   ck_assert_uint_ge(_counted_rows, count);
+   _avg_positions_check(manager, sizes, count);
+}
+EFL_END_TEST
+
 void efl_ui_test_collection_view(TCase *tc)
 {
    tcase_add_test(tc, test_efl_ui_collection_view_basic);
@@ -2074,6 +2288,7 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, test_efl_ui_position_manager_list_cache_shared_size);
    tcase_add_test(tc, test_efl_ui_position_manager_list_partial_fill);
    tcase_add_test(tc, test_efl_ui_position_manager_list_differential);
+   tcase_add_test(tc, test_efl_ui_position_manager_list_estimate_stable);
    tcase_add_test(tc, test_efl_ui_position_manager_grid_groups_follow);
    tcase_add_test(tc, test_efl_ui_collection_view_many_single_adds_idle);
    tcase_add_test(tc, test_efl_ui_collection_view_many_single_adds_grid);
@@ -2081,4 +2296,5 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, test_efl_ui_position_manager_grid_min_size_goes_down);
    tcase_add_test(tc, test_efl_ui_position_manager_grid_min_size_known_only);
    tcase_add_test(tc, test_efl_ui_collection_view_grid_remove_fetches_nothing);
+   tcase_add_test(tc, test_efl_ui_collection_view_average_model_estimates);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to