backend-drm: Place pixel format checks for the overlay plane in its own
authorMarius Vlad <marius.vlad@collabora.com>
Sun, 13 Oct 2019 21:27:05 +0000 (00:27 +0300)
committerDaniel Stone <daniels@collabora.com>
Mon, 11 Nov 2019 16:51:48 +0000 (16:51 +0000)
function

The idea is to place pixel the format checks in a common part and until
then, to make it available as a function so we can re-use easily.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
libweston/backend-drm/state-propose.c

index 4e91e60dd74f12e6f4f41c4a95c7fe9ecf18b21c..d794f2c0f1127484d24911061ed03cafdcc8db68 100644 (file)
@@ -123,6 +123,35 @@ drm_output_check_plane_has_view_assigned(struct drm_plane *plane,
        return false;
 }
 
+static bool
+drm_output_plane_has_valid_format(struct drm_plane *plane,
+                                 struct drm_output_state *state,
+                                 struct drm_fb *fb)
+{
+       unsigned int i;
+
+       if (!fb)
+               return false;
+
+       /* Check whether the format is supported */
+       for (i = 0; i < plane->count_formats; i++) {
+               unsigned int j;
+
+               if (plane->formats[i].format != fb->format->format)
+                       continue;
+
+               if (fb->modifier == DRM_FORMAT_MOD_INVALID)
+                       return true;
+
+               for (j = 0; j < plane->formats[i].count_modifiers; j++) {
+                       if (plane->formats[i].modifiers[j] == fb->modifier)
+                               return true;
+               }
+       }
+
+       return false;
+}
+
 static struct drm_plane_state *
 drm_output_prepare_overlay_view(struct drm_output_state *output_state,
                                struct weston_view *ev,
@@ -135,7 +164,6 @@ drm_output_prepare_overlay_view(struct drm_output_state *output_state,
        struct drm_plane *p;
        struct drm_plane_state *state = NULL;
        struct drm_fb *fb;
-       unsigned int i;
        int ret;
        enum {
                NO_PLANES,
@@ -170,31 +198,8 @@ drm_output_prepare_overlay_view(struct drm_output_state *output_state,
                if (availability == NO_PLANES)
                        availability = NO_PLANES_WITH_FORMAT;
 
-               /* Check whether the format is supported */
-               for (i = 0; i < p->count_formats; i++) {
-                       unsigned int j;
-
-                       if (p->formats[i].format != fb->format->format)
-                               continue;
-
-                       if (fb->modifier == DRM_FORMAT_MOD_INVALID)
-                               break;
-
-                       for (j = 0; j < p->formats[i].count_modifiers; j++) {
-                               if (p->formats[i].modifiers[j] == fb->modifier)
-                                       break;
-                       }
-                       if (j != p->formats[i].count_modifiers)
-                               break;
-               }
-               if (i == p->count_formats) {
-                       drm_plane_state_put_back(state);
-                       state = NULL;
+               if (!drm_output_plane_has_valid_format(p, output_state, fb))
                        continue;
-               }
-
-               if (availability == NO_PLANES_WITH_FORMAT)
-                       availability = NO_PLANES_ACCEPTED;
 
                state->ev = ev;
                state->output = output;