hwc: refectoring hwc_apply_policy for supporting video 48/204548/3
authorChangyeon Lee <cyeon.lee@samsung.com>
Fri, 19 Apr 2019 08:42:41 +0000 (17:42 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Wed, 24 Apr 2019 09:53:20 +0000 (18:53 +0900)
1. support hw cursor and only use ZPOS3 layer for cursor
2. if video client is shown, ui_lzpos_bottom move to ZPOS_1

Change-Id: I6ac89c88e9f425ec7892f1402abbc314e661439c

src/tdm_vc4_hwc.c

index ea3d924..fb23094 100644 (file)
@@ -15,7 +15,7 @@
 #define ZPOS_2       2
 #define ZPOS_1       1
 #define ZPOS_0       0
-#define ZPOS_VIDEO1  -1 //TODO:
+#define ZPOS_VIDEO1  0
 #define ZPOS_NONE    -999
 
 tbm_format hwc_window_video_formats[] = {
@@ -324,10 +324,10 @@ _vc4_hwc_apply_policy(tdm_vc4_hwc_data *hwc_data , tdm_hwc_window **composited_w
        int device_count = 0;
        int video_count = 0;
        int cursor_count = 0;
-       int next_idx = 0;
        int ui_lzpos_top = ZPOS_2;
        int ui_lzpos_bottom = ZPOS_0;
        int num_ui_layers = NUM_LAYERS;
+       int set_clients_below = 0;
        int i = 0;
 
        composited_list = (tdm_vc4_hwc_window_data **)composited_wnds;
@@ -344,87 +344,82 @@ _vc4_hwc_apply_policy(tdm_vc4_hwc_data *hwc_data , tdm_hwc_window **composited_w
        /* use the target_window to commit when there is no window. */
        if (num_wnds == 0) {
                hwc_data->need_target_window = 1;
+               hwc_data->target_hwc_window->lzpos = ui_lzpos_bottom;
                return;
        }
 
-       /* count the composited(visible) windows */
+       /* 1. first check validate_type without target_window */
        for (i = 0; i < num_wnds; i++) {
-               if (composited_list[i]->client_type == TDM_HWC_WIN_COMPOSITION_CURSOR)
-                       cursor_count++;
-               if (composited_list[i]->client_type == TDM_HWC_WIN_COMPOSITION_CLIENT)
-                       client_count++;
-               if (client_count == 0 && composited_list[i]->client_type == TDM_HWC_WIN_COMPOSITION_DEVICE)
-                       device_count++;
-               if (composited_list[i]->client_type == TDM_HWC_WIN_COMPOSITION_VIDEO)
-                       video_count++;
+               switch (composited_list[i]->client_type) {
+                       case TDM_HWC_WIN_COMPOSITION_VIDEO:
+                               composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_VIDEO;
+                               video_count++;
+                               continue;
+                       case TDM_HWC_WIN_COMPOSITION_CURSOR:
+                               if (set_clients_below) break;
+                               if (cursor_count > 0) break;
+
+                               composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_CURSOR;
+                               cursor_count++;
+                               continue;
+                       case TDM_HWC_WIN_COMPOSITION_DEVICE:
+                               if (set_clients_below) break;
+                               if (num_ui_layers <= 0) break;
+                               if (!_vc4_hwc_window_can_set_on_hw_layer(composited_list[i])) break;
+
+                               composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_DEVICE;
+                               device_count++;
+                               num_ui_layers--;
+                               continue;
+                       default:
+                               break;
+               }
+
+               composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_CLIENT;
+               client_count++;
+               set_clients_below = 1;
        }
 
-       /* apply the cursor layers */
-       if (cursor_count > 1)
-               goto set_clients_below;
+       /* 2. check need target window and set ui_lzpos top and bottom */
+       num_ui_layers = NUM_LAYERS;
 
-       if (cursor_count == 1) {
-               /* set cursor composition and layer zpos */
-               composited_list[next_idx]->validated_type = TDM_HWC_WIN_COMPOSITION_CURSOR;
-               composited_list[next_idx]->lzpos = ZPOS_CURSOR;
-               next_idx++;
+       if (video_count > 0) {
+               ui_lzpos_bottom++;
+               num_ui_layers--;
        }
 
-       /* reset the lzpos_bottom when it needs target_window */
-       if ((client_count > 0) || (client_count + device_count > 2)) {
-               hwc_data->need_target_window = 1;
-               ui_lzpos_bottom = ZPOS_1;
+       if (client_count > 0) {
+               ui_lzpos_bottom++;
                num_ui_layers--;
+               hwc_data->need_target_window = 1;
+               hwc_data->target_hwc_window->lzpos = ui_lzpos_bottom - 1;
        }
 
-       /* apply the device layers from the top to the bottom */
-       if ((num_ui_layers - device_count) > 0)
+       if (num_ui_layers > device_count)
                ui_lzpos_top = ui_lzpos_bottom + device_count - 1;
 
-       while (device_count > 0) {
-               /* apply the video layer */
-               if (composited_list[next_idx]->client_type == TDM_HWC_WIN_COMPOSITION_VIDEO) {
-                       composited_list[next_idx]->validated_type = TDM_HWC_WIN_COMPOSITION_VIDEO;
-                       composited_list[next_idx]->lzpos = ZPOS_VIDEO1;
-                       next_idx++;
-                       continue;
-               }
-
-               /* set clients below when vc4 can not set the window to the hw layer */
-               if (!_vc4_hwc_window_can_set_on_hw_layer(composited_list[next_idx]))
-                       break;
-
-               /* set device comopsition and layer zpos */
-               composited_list[next_idx]->validated_type = TDM_HWC_WIN_COMPOSITION_DEVICE;
-               composited_list[next_idx]->lzpos = ui_lzpos_top;
-               ui_lzpos_top--;
-               next_idx++;
-
-               if (ui_lzpos_top < ui_lzpos_bottom)
-                       break;
-
-               device_count--;
-       }
-
-set_clients_below:
-       /* apply the client layers */
-       while (next_idx < num_wnds) {
-               hwc_data->need_target_window = 1;
-               if (composited_list[next_idx]->client_type == TDM_HWC_WIN_COMPOSITION_VIDEO) {
-                       composited_list[next_idx]->validated_type = TDM_HWC_WIN_COMPOSITION_VIDEO;
-                       composited_list[next_idx]->lzpos = ZPOS_VIDEO1;
-                       next_idx++;
-                       continue;
+       /* 3. set lzpos and modify validate_type with target_window */
+       for (i = 0; i < num_wnds; i++) {
+               switch (composited_list[i]->validated_type) {
+                       case TDM_HWC_WIN_COMPOSITION_VIDEO:
+                               composited_list[i]->lzpos = ZPOS_VIDEO1;
+                               continue;
+                       case TDM_HWC_WIN_COMPOSITION_CURSOR:
+                               composited_list[i]->lzpos = ZPOS_CURSOR;
+                               continue;
+                       case TDM_HWC_WIN_COMPOSITION_DEVICE:
+                               if (num_ui_layers <= 0) break;
+                               composited_list[i]->lzpos = ui_lzpos_top;
+                               ui_lzpos_top--;
+                               num_ui_layers--;
+                               continue;
+                       default:
+                               break;
                }
 
-               /* set client composition */
-               composited_list[next_idx]->validated_type = TDM_HWC_WIN_COMPOSITION_CLIENT;
-               composited_list[next_idx]->lzpos = ZPOS_NONE;
-               next_idx++;
+               composited_list[i]->validated_type = TDM_HWC_WIN_COMPOSITION_CLIENT;
+               composited_list[i]->lzpos = ZPOS_NONE;
        }
-
-       if (hwc_data->need_target_window)
-               hwc_data->target_hwc_window->lzpos = ZPOS_0;
 }
 
 static int