dra7xx: weston: add patches for weston 1.11
[AGL/meta-agl.git] / meta-agl-bsp / meta-ti / recipes-arago / weston / weston / 0001-compositor-drm-support-RGB565-with-pixman-renderer.patch
1 From 91b452fa515b94928d32af6e1b1b0405469747fd Mon Sep 17 00:00:00 2001
2 From: Tomi Valkeinen <tomi.valkeinen@ti.com>
3 Date: Wed, 8 Mar 2017 13:05:38 -0500
4 Subject: [PATCH] compositor-drm: support RGB565 with pixman renderer
5
6 At the moment only XRGB8888 is supported when using pixman renderer.
7 This patch adds support also for RGB565.
8
9 Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
10 Reviewed-by: Daniel Stone <daniels@collabora.com>
11 Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
12 Signed-off-by: Daniel Stone <daniels@collabora.com>
13 ---
14  src/compositor-drm.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++------
15  1 file changed, 55 insertions(+), 7 deletions(-)
16
17 diff --git a/src/compositor-drm.c b/src/compositor-drm.c
18 index fd89627..443b69a 100644
19 --- a/src/compositor-drm.c
20 +++ b/src/compositor-drm.c
21 @@ -262,10 +262,12 @@ drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
22  }
23  
24  static struct drm_fb *
25 -drm_fb_create_dumb(struct drm_backend *b, unsigned width, unsigned height)
26 +drm_fb_create_dumb(struct drm_backend *b, unsigned width, unsigned height,
27 +                  uint32_t format)
28  {
29         struct drm_fb *fb;
30         int ret;
31 +       uint32_t bpp, depth;
32  
33         struct drm_mode_create_dumb create_arg;
34         struct drm_mode_destroy_dumb destroy_arg;
35 @@ -275,8 +277,20 @@ drm_fb_create_dumb(struct drm_backend *b, unsigned width, unsigned height)
36         if (!fb)
37                 return NULL;
38  
39 +       switch (format) {
40 +               case GBM_FORMAT_XRGB8888:
41 +                       bpp = 32;
42 +                       depth = 24;
43 +                       break;
44 +               case GBM_FORMAT_RGB565:
45 +                       bpp = depth = 16;
46 +                       break;
47 +               default:
48 +                       return NULL;
49 +       }
50 +
51         memset(&create_arg, 0, sizeof create_arg);
52 -       create_arg.bpp = 32;
53 +       create_arg.bpp = bpp;
54         create_arg.width = width;
55         create_arg.height = height;
56  
57 @@ -289,8 +303,29 @@ drm_fb_create_dumb(struct drm_backend *b, unsigned width, unsigned height)
58         fb->size = create_arg.size;
59         fb->fd = b->drm.fd;
60  
61 -       ret = drmModeAddFB(b->drm.fd, width, height, 24, 32,
62 -                          fb->stride, fb->handle, &fb->fb_id);
63 +       ret = -1;
64 +
65 +       if (!b->no_addfb2) {
66 +               uint32_t handles[4], pitches[4], offsets[4];
67 +
68 +               handles[0] = fb->handle;
69 +               pitches[0] = fb->stride;
70 +               offsets[0] = 0;
71 +
72 +               ret = drmModeAddFB2(b->drm.fd, width, height,
73 +                                   format, handles, pitches, offsets,
74 +                                   &fb->fb_id, 0);
75 +               if (ret) {
76 +                       weston_log("addfb2 failed: %m\n");
77 +                       b->no_addfb2 = 1;
78 +               }
79 +       }
80 +
81 +       if (ret) {
82 +               ret = drmModeAddFB(b->drm.fd, width, height, depth, bpp,
83 +                                  fb->stride, fb->handle, &fb->fb_id);
84 +       }
85 +
86         if (ret)
87                 goto err_bo;
88  
89 @@ -1879,17 +1914,30 @@ drm_output_init_pixman(struct drm_output *output, struct drm_backend *b)
90  {
91         int w = output->base.current_mode->width;
92         int h = output->base.current_mode->height;
93 +       uint32_t format = output->gbm_format;
94 +       uint32_t pixman_format;
95         unsigned int i;
96  
97 -       /* FIXME error checking */
98 +       switch (format) {
99 +               case GBM_FORMAT_XRGB8888:
100 +                       pixman_format = PIXMAN_x8r8g8b8;
101 +                       break;
102 +               case GBM_FORMAT_RGB565:
103 +                       pixman_format = PIXMAN_r5g6b5;
104 +                       break;
105 +               default:
106 +                       weston_log("Unsupported pixman format 0x%x\n", format);
107 +                       return -1;
108 +       }
109  
110 +       /* FIXME error checking */
111         for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
112 -               output->dumb[i] = drm_fb_create_dumb(b, w, h);
113 +               output->dumb[i] = drm_fb_create_dumb(b, w, h, format);
114                 if (!output->dumb[i])
115                         goto err;
116  
117                 output->image[i] =
118 -                       pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h,
119 +                       pixman_image_create_bits(pixman_format, w, h,
120                                                  output->dumb[i]->map,
121                                                  output->dumb[i]->stride);
122                 if (!output->image[i])
123 -- 
124 1.9.1
125