summaryrefslogtreecommitdiffstats
path: root/meta-agl-drm-lease/recipes-core/psplash/files/0008-Extract-draw-font-from-psplash-fb.patch
blob: a62e939ce80ec67f10a867aef838f74acf2d8f51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
From 532e889486ed4c6b254893e89c63cc4395cc83da Mon Sep 17 00:00:00 2001
From: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
Date: Mon, 25 Apr 2022 10:59:47 +0300
Subject: [PATCH 08/17] Extract draw font from psplash-fb

drm-backend backport from:
https://patchwork.yoctoproject.org/project/yocto/cover/20220425075954.10427-1-vasyl.vavrychuk@opensynergy.com/

Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
---
 psplash-draw.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++-
 psplash-draw.h |  25 ++++++++----
 psplash-fb.c   | 108 ------------------------------------------------
 psplash-fb.h   |  16 --------
 psplash.c      |   4 +-
 5 files changed, 125 insertions(+), 137 deletions(-)

diff --git a/psplash-draw.c b/psplash-draw.c
index 6887e22..aa9887a 100644
--- a/psplash-draw.c
+++ b/psplash-draw.c
@@ -11,8 +11,7 @@
 
 #define OFFSET(canvas, x, y) (((y) * (canvas)->stride) + ((x) * ((canvas)->bpp >> 3)))
 
-/* TODO: change to 'static inline' as psplash_fb_plot_pixel was before */
-void
+static inline void
 psplash_plot_pixel(PSplashCanvas *canvas,
 		   int            x,
 		   int            y,
@@ -188,3 +187,109 @@ psplash_draw_image(PSplashCanvas *canvas,
 	}
     }
 }
+
+/* Font rendering code based on BOGL by Ben Pfaff */
+
+static int
+psplash_font_glyph (const PSplashFont *font, wchar_t wc, u_int32_t **bitmap)
+{
+  int mask = font->index_mask;
+  int i;
+
+  for (;;)
+    {
+      for (i = font->offset[wc & mask]; font->index[i]; i += 2)
+	{
+	  if ((wchar_t)(font->index[i] & ~mask) == (wc & ~mask))
+	    {
+	      if (bitmap != NULL)
+		*bitmap = &font->content[font->index[i+1]];
+	      return font->index[i] & mask;
+	    }
+	}
+    }
+  return 0;
+}
+
+void
+psplash_text_size(int                *width,
+		  int                *height,
+		  const PSplashFont  *font,
+		  const char         *text)
+{
+  char   *c = (char*)text;
+  wchar_t wc;
+  int     k, n, w, h, mw;
+
+  n = strlen (text);
+  mw = h = w = 0;
+
+  mbtowc (0, 0, 0);
+  for (; (k = mbtowc (&wc, c, n)) > 0; c += k, n -= k)
+    {
+      if (*c == '\n')
+	{
+	  if (w > mw)
+	    mw = w;
+	  w = 0;
+	  h += font->height;
+	  continue;
+	}
+
+      w += psplash_font_glyph (font, wc, NULL);
+    }
+
+  *width  = (w > mw) ? w : mw;
+  *height = (h == 0) ? font->height : h;
+}
+
+void
+psplash_draw_text(PSplashCanvas     *canvas,
+		  int                x,
+		  int                y,
+		  uint8              red,
+		  uint8              green,
+		  uint8              blue,
+		  const PSplashFont *font,
+		  const char        *text)
+{
+  int     h, w, k, n, cx, cy, dx, dy;
+  char   *c = (char*)text;
+  wchar_t wc;
+
+  n = strlen (text);
+  h = font->height;
+  dx = dy = 0;
+
+  mbtowc (0, 0, 0);
+  for (; (k = mbtowc (&wc, c, n)) > 0; c += k, n -= k)
+    {
+      u_int32_t *glyph = NULL;
+
+      if (*c == '\n')
+	{
+	  dy += h;
+	  dx  = 0;
+	  continue;
+	}
+
+      w = psplash_font_glyph (font, wc, &glyph);
+
+      if (glyph == NULL)
+	continue;
+
+      for (cy = 0; cy < h; cy++)
+	{
+	  u_int32_t g = *glyph++;
+
+	  for (cx = 0; cx < w; cx++)
+	    {
+	      if (g & 0x80000000)
+		psplash_plot_pixel(canvas, x+dx+cx, y+dy+cy, red, green, blue);
+	      g <<= 1;
+	    }
+	}
+
+      dx += w;
+    }
+}
diff --git a/psplash-draw.h b/psplash-draw.h
index f8361da..44546b0 100644
--- a/psplash-draw.h
+++ b/psplash-draw.h
@@ -39,15 +39,6 @@ typedef struct PSplashCanvas
 }
 PSplashCanvas;
 
-/* TODO: Remove after rest of drawing functions migrated to psplash-draw.c */
-void
-psplash_plot_pixel(PSplashCanvas *canvas,
-		   int            x,
-		   int            y,
-		   uint8          red,
-		   uint8          green,
-		   uint8          blue);
-
 void
 psplash_draw_rect(PSplashCanvas *canvas,
 		  int            x,
@@ -68,4 +59,20 @@ psplash_draw_image(PSplashCanvas *canvas,
 		   int            img_rowstride,
 		   uint8         *rle_data);
 
+void
+psplash_text_size(int                *width,
+		  int                *height,
+		  const PSplashFont  *font,
+		  const char         *text);
+
+void
+psplash_draw_text(PSplashCanvas     *canvas,
+		  int                x,
+		  int                y,
+		  uint8              red,
+		  uint8              green,
+		  uint8              blue,
+		  const PSplashFont *font,
+		  const char        *text);
+
 #endif
diff --git a/psplash-fb.c b/psplash-fb.c
index 07839d5..dd50a5a 100644
--- a/psplash-fb.c
+++ b/psplash-fb.c
@@ -338,111 +338,3 @@ psplash_fb_new (int angle, int fbdev_id)
 
   return NULL;
 }
-
-/* Font rendering code based on BOGL by Ben Pfaff */
-
-static int
-psplash_font_glyph (const PSplashFont *font, wchar_t wc, u_int32_t **bitmap)
-{
-  int mask = font->index_mask;
-  int i;
-
-  for (;;)
-    {
-      for (i = font->offset[wc & mask]; font->index[i]; i += 2)
-	{
-	  if ((wchar_t)(font->index[i] & ~mask) == (wc & ~mask))
-	    {
-	      if (bitmap != NULL)
-		*bitmap = &font->content[font->index[i+1]];
-	      return font->index[i] & mask;
-	    }
-	}
-    }
-  return 0;
-}
-
-void
-psplash_fb_text_size (int                *width,
-		      int                *height,
-		      const PSplashFont  *font,
-		      const char         *text)
-{
-  char   *c = (char*)text;
-  wchar_t wc;
-  int     k, n, w, h, mw;
-
-  n = strlen (text);
-  mw = h = w = 0;
-
-  mbtowc (0, 0, 0);
-  for (; (k = mbtowc (&wc, c, n)) > 0; c += k, n -= k)
-    {
-      if (*c == '\n')
-	{
-	  if (w > mw)
-	    mw = w;
-	  w = 0;
-	  h += font->height;
-	  continue;
-	}
-
-      w += psplash_font_glyph (font, wc, NULL);
-    }
-
-  *width  = (w > mw) ? w : mw;
-  *height = (h == 0) ? font->height : h;
-}
-
-void
-psplash_fb_draw_text (PSplashFB         *fb,
-		      int                x,
-		      int                y,
-		      uint8              red,
-		      uint8              green,
-		      uint8              blue,
-		      const PSplashFont *font,
-		      const char        *text)
-{
-  int     h, w, k, n, cx, cy, dx, dy;
-  char   *c = (char*)text;
-  wchar_t wc;
-
-  n = strlen (text);
-  h = font->height;
-  dx = dy = 0;
-
-  mbtowc (0, 0, 0);
-  for (; (k = mbtowc (&wc, c, n)) > 0; c += k, n -= k)
-    {
-      u_int32_t *glyph = NULL;
-
-      if (*c == '\n')
-	{
-	  dy += h;
-	  dx  = 0;
-	  continue;
-	}
-
-      w = psplash_font_glyph (font, wc, &glyph);
-
-      if (glyph == NULL)
-	continue;
-
-      for (cy = 0; cy < h; cy++)
-	{
-	  u_int32_t g = *glyph++;
-
-	  for (cx = 0; cx < w; cx++)
-	    {
-	      if (g & 0x80000000)
-		psplash_plot_pixel(&fb->canvas, x+dx+cx, y+dy+cy,
-				       red, green, blue);
-	      g <<= 1;
-	    }
-	}
-
-      dx += w;
-    }
-}
-
diff --git a/psplash-fb.h b/psplash-fb.h
index 1eecb47..1b16bd5 100644
--- a/psplash-fb.h
+++ b/psplash-fb.h
@@ -40,22 +40,6 @@ psplash_fb_destroy (PSplashFB *fb);
 PSplashFB*
 psplash_fb_new (int angle, int fbdev_id);
 
-void
-psplash_fb_text_size (int                *width,
-		      int                *height,
-		      const PSplashFont  *font,
-		      const char         *text);
-
-void
-psplash_fb_draw_text (PSplashFB         *fb,
-		      int                x,
-		      int                y,
-		      uint8              red,
-		      uint8              green,
-		      uint8              blue,
-		      const PSplashFont *font,
-		      const char        *text);
-
 void
 psplash_fb_flip(PSplashFB *fb, int sync);
 
diff --git a/psplash.c b/psplash.c
index 2aeb583..1a5e543 100644
--- a/psplash.c
+++ b/psplash.c
@@ -41,7 +41,7 @@ psplash_draw_msg (PSplashFB *fb, const char *msg)
 {
   int w, h;
 
-  psplash_fb_text_size (&w, &h, &FONT_DEF, msg);
+  psplash_text_size(&w, &h, &FONT_DEF, msg);
 
   DBG("displaying '%s' %ix%i\n", msg, w, h);
 
@@ -54,7 +54,7 @@ psplash_draw_msg (PSplashFB *fb, const char *msg)
 			h,
 			PSPLASH_BACKGROUND_COLOR);
 
-  psplash_fb_draw_text (fb,
+  psplash_draw_text(&fb->canvas,
 			(fb->canvas.width-w)/2,
 			SPLIT_LINE_POS(fb) - h,
 			PSPLASH_TEXT_COLOR,
-- 
2.25.1