1 | /*
|
---|
2 | * Copyright (c) 2020 Jiri Svoboda
|
---|
3 | * Copyright (c) 2013 Jan Vesely
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup amdm37x_dispc
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /**
|
---|
34 | * @file
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <align.h>
|
---|
38 | #include <as.h>
|
---|
39 | #include <assert.h>
|
---|
40 | #include <errno.h>
|
---|
41 | #include <ddev_srv.h>
|
---|
42 | #include <ddev/info.h>
|
---|
43 | #include <ddf/driver.h>
|
---|
44 | #include <ddf/log.h>
|
---|
45 | #include <ddi.h>
|
---|
46 | #include <gfx/color.h>
|
---|
47 | #include <io/pixelmap.h>
|
---|
48 |
|
---|
49 | #include "amdm37x_dispc.h"
|
---|
50 |
|
---|
51 | #ifndef CONFIG_BFB_BPP
|
---|
52 | #define CONFIG_BFB_BPP 24
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | #ifndef CONFIG_BFB_WIDTH
|
---|
56 | #define CONFIG_BFB_WIDTH 1024
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | #ifndef CONFIG_BFB_HEIGHT
|
---|
60 | #define CONFIG_BFB_HEIGHT 768
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | static errno_t amdm37x_change_mode(amdm37x_dispc_t *, unsigned, unsigned,
|
---|
64 | visual_t);
|
---|
65 |
|
---|
66 | static errno_t amdm37x_ddev_get_gc(void *, sysarg_t *, sysarg_t *);
|
---|
67 | static errno_t amdm37x_ddev_get_info(void *, ddev_info_t *);
|
---|
68 |
|
---|
69 | static errno_t amdm37x_gc_set_color(void *, gfx_color_t *);
|
---|
70 | static errno_t amdm37x_gc_fill_rect(void *, gfx_rect_t *);
|
---|
71 | static errno_t amdm37x_gc_bitmap_create(void *, gfx_bitmap_params_t *,
|
---|
72 | gfx_bitmap_alloc_t *, void **);
|
---|
73 | static errno_t amdm37x_gc_bitmap_destroy(void *);
|
---|
74 | static errno_t amdm37x_gc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
|
---|
75 | static errno_t amdm37x_gc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
|
---|
76 |
|
---|
77 | ddev_ops_t amdm37x_ddev_ops = {
|
---|
78 | .get_gc = amdm37x_ddev_get_gc,
|
---|
79 | .get_info = amdm37x_ddev_get_info
|
---|
80 | };
|
---|
81 |
|
---|
82 | gfx_context_ops_t amdm37x_gc_ops = {
|
---|
83 | .set_color = amdm37x_gc_set_color,
|
---|
84 | .fill_rect = amdm37x_gc_fill_rect,
|
---|
85 | .bitmap_create = amdm37x_gc_bitmap_create,
|
---|
86 | .bitmap_destroy = amdm37x_gc_bitmap_destroy,
|
---|
87 | .bitmap_render = amdm37x_gc_bitmap_render,
|
---|
88 | .bitmap_get_alloc = amdm37x_gc_bitmap_get_alloc
|
---|
89 | };
|
---|
90 |
|
---|
91 | static const struct {
|
---|
92 | unsigned bpp;
|
---|
93 | pixel2visual_t func;
|
---|
94 | } pixel2visual_table[] = {
|
---|
95 | [VISUAL_INDIRECT_8] = { .bpp = 1, .func = pixel2bgr_323 },
|
---|
96 | [VISUAL_RGB_5_5_5_LE] = { .bpp = 2, .func = pixel2rgb_555_le },
|
---|
97 | [VISUAL_RGB_5_5_5_BE] = { .bpp = 2, .func = pixel2rgb_555_be },
|
---|
98 | [VISUAL_RGB_5_6_5_LE] = { .bpp = 2, .func = pixel2rgb_565_le },
|
---|
99 | [VISUAL_RGB_5_6_5_BE] = { .bpp = 2, .func = pixel2rgb_565_be },
|
---|
100 | [VISUAL_BGR_8_8_8] = { .bpp = 3, .func = pixel2bgr_888 },
|
---|
101 | [VISUAL_RGB_8_8_8] = { .bpp = 3, .func = pixel2rgb_888 },
|
---|
102 | [VISUAL_BGR_0_8_8_8] = { .bpp = 4, .func = pixel2rgb_0888 },
|
---|
103 | [VISUAL_BGR_8_8_8_0] = { .bpp = 4, .func = pixel2bgr_8880 },
|
---|
104 | [VISUAL_ABGR_8_8_8_8] = { .bpp = 4, .func = pixel2abgr_8888 },
|
---|
105 | [VISUAL_BGRA_8_8_8_8] = { .bpp = 4, .func = pixel2bgra_8888 },
|
---|
106 | [VISUAL_RGB_0_8_8_8] = { .bpp = 4, .func = pixel2rgb_0888 },
|
---|
107 | [VISUAL_RGB_8_8_8_0] = { .bpp = 4, .func = pixel2rgb_8880 },
|
---|
108 | [VISUAL_ARGB_8_8_8_8] = { .bpp = 4, .func = pixel2argb_8888 },
|
---|
109 | [VISUAL_RGBA_8_8_8_8] = { .bpp = 4, .func = pixel2rgba_8888 },
|
---|
110 | };
|
---|
111 |
|
---|
112 | errno_t amdm37x_dispc_init(amdm37x_dispc_t *instance, ddf_fun_t *fun)
|
---|
113 | {
|
---|
114 | instance->fun = fun;
|
---|
115 | instance->fb_data = NULL;
|
---|
116 | instance->size = 0;
|
---|
117 |
|
---|
118 | /* Default is 24bpp, use config option if available */
|
---|
119 | visual_t visual = VISUAL_BGR_8_8_8;
|
---|
120 | switch (CONFIG_BFB_BPP) {
|
---|
121 | case 8:
|
---|
122 | visual = VISUAL_INDIRECT_8;
|
---|
123 | break;
|
---|
124 | case 16:
|
---|
125 | visual = VISUAL_RGB_5_6_5_LE;
|
---|
126 | break;
|
---|
127 | case 24:
|
---|
128 | visual = VISUAL_BGR_8_8_8;
|
---|
129 | break;
|
---|
130 | case 32:
|
---|
131 | visual = VISUAL_RGB_8_8_8_0;
|
---|
132 | break;
|
---|
133 | default:
|
---|
134 | return EINVAL;
|
---|
135 | }
|
---|
136 |
|
---|
137 | errno_t ret = pio_enable((void *)AMDM37x_DISPC_BASE_ADDRESS,
|
---|
138 | AMDM37x_DISPC_SIZE, (void **)&instance->regs);
|
---|
139 | if (ret != EOK) {
|
---|
140 | return EIO;
|
---|
141 | }
|
---|
142 |
|
---|
143 | ret = amdm37x_change_mode(instance, CONFIG_BFB_WIDTH,
|
---|
144 | CONFIG_BFB_HEIGHT, visual);
|
---|
145 | if (ret != EOK)
|
---|
146 | return EIO;
|
---|
147 |
|
---|
148 | return EOK;
|
---|
149 | }
|
---|
150 |
|
---|
151 | errno_t amdm37x_dispc_fini(amdm37x_dispc_t *instance)
|
---|
152 | {
|
---|
153 | return EOK;
|
---|
154 | }
|
---|
155 |
|
---|
156 | static errno_t amdm37x_dispc_setup_fb(amdm37x_dispc_regs_t *regs,
|
---|
157 | unsigned x, unsigned y, unsigned bpp, uint32_t pa)
|
---|
158 | {
|
---|
159 | assert(regs);
|
---|
160 | /*
|
---|
161 | * Init sequence for dispc is in chapter 7.6.5.1.4 p. 1810,
|
---|
162 | * no idea what parts of that work.
|
---|
163 | */
|
---|
164 |
|
---|
165 | /* Disable all interrupts */
|
---|
166 | regs->irqenable = 0;
|
---|
167 |
|
---|
168 | /* Pixel format specifics */
|
---|
169 | uint32_t attrib_pixel_format = 0;
|
---|
170 | uint32_t control_data_lanes = 0;
|
---|
171 | switch (bpp) {
|
---|
172 | case 32:
|
---|
173 | attrib_pixel_format = AMDM37X_DISPC_GFX_ATTRIBUTES_FORMAT_RGBX;
|
---|
174 | control_data_lanes = AMDM37X_DISPC_CONTROL_TFTDATALINES_24B;
|
---|
175 | break;
|
---|
176 | case 24:
|
---|
177 | attrib_pixel_format = AMDM37X_DISPC_GFX_ATTRIBUTES_FORMAT_RGB24;
|
---|
178 | control_data_lanes = AMDM37X_DISPC_CONTROL_TFTDATALINES_24B;
|
---|
179 | break;
|
---|
180 | case 16:
|
---|
181 | attrib_pixel_format = AMDM37X_DISPC_GFX_ATTRIBUTES_FORMAT_RGB16;
|
---|
182 | control_data_lanes = AMDM37X_DISPC_CONTROL_TFTDATALINES_16B;
|
---|
183 | break;
|
---|
184 | default:
|
---|
185 | return EINVAL;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* Prepare sizes */
|
---|
189 | const uint32_t size_reg =
|
---|
190 | (((x - 1) & AMDM37X_DISPC_SIZE_WIDTH_MASK) <<
|
---|
191 | AMDM37X_DISPC_SIZE_WIDTH_SHIFT) |
|
---|
192 | (((y - 1) & AMDM37X_DISPC_SIZE_HEIGHT_MASK) <<
|
---|
193 | AMDM37X_DISPC_SIZE_HEIGHT_SHIFT);
|
---|
194 |
|
---|
195 | /* modes taken from u-boot, for 1024x768 */
|
---|
196 | // TODO replace magic values with actual correct values
|
---|
197 | #if 0
|
---|
198 | regs->timing_h = 0x1a4024c9;
|
---|
199 | regs->timing_v = 0x02c00509;
|
---|
200 | regs->pol_freq = 0x00007028;
|
---|
201 | regs->divisor = 0x00010001;
|
---|
202 | #endif
|
---|
203 |
|
---|
204 | /* setup output */
|
---|
205 | regs->size_lcd = size_reg;
|
---|
206 | regs->size_dig = size_reg;
|
---|
207 |
|
---|
208 | /* Nice blue default color */
|
---|
209 | regs->default_color[0] = 0x0000ff;
|
---|
210 | regs->default_color[1] = 0x0000ff;
|
---|
211 |
|
---|
212 | /* Setup control register */
|
---|
213 | uint32_t control = 0 |
|
---|
214 | AMDM37X_DISPC_CONTROL_PCKFREEENABLE_FLAG |
|
---|
215 | (control_data_lanes << AMDM37X_DISPC_CONTROL_TFTDATALINES_SHIFT) |
|
---|
216 | AMDM37X_DISPC_CONTROL_GPOUT0_FLAG |
|
---|
217 | AMDM37X_DISPC_CONTROL_GPOUT1_FLAG;
|
---|
218 | regs->control = control;
|
---|
219 |
|
---|
220 | /* No gamma stuff only data */
|
---|
221 | uint32_t config = (AMDM37X_DISPC_CONFIG_LOADMODE_DATAEVERYFRAME <<
|
---|
222 | AMDM37X_DISPC_CONFIG_LOADMODE_SHIFT);
|
---|
223 | regs->config = config;
|
---|
224 |
|
---|
225 | /* Set framebuffer base address */
|
---|
226 | regs->gfx.ba[0] = pa;
|
---|
227 | regs->gfx.ba[1] = pa;
|
---|
228 | regs->gfx.position = 0;
|
---|
229 |
|
---|
230 | /* Setup fb size */
|
---|
231 | regs->gfx.size = size_reg;
|
---|
232 |
|
---|
233 | /* Set pixel format */
|
---|
234 | uint32_t attribs = 0 |
|
---|
235 | (attrib_pixel_format << AMDM37X_DISPC_GFX_ATTRIBUTES_FORMAT_SHIFT);
|
---|
236 | regs->gfx.attributes = attribs;
|
---|
237 |
|
---|
238 | /* 0x03ff03c0 is the default */
|
---|
239 | regs->gfx.fifo_threshold = 0x03ff03c0;
|
---|
240 | /*
|
---|
241 | * This value should be stride - width, 1 means next pixel i.e.
|
---|
242 | * stride == width
|
---|
243 | */
|
---|
244 | regs->gfx.row_inc = 1;
|
---|
245 | /* number of bytes to next pixel in BPP multiples */
|
---|
246 | regs->gfx.pixel_inc = 1;
|
---|
247 | /* only used if video is played over fb */
|
---|
248 | regs->gfx.window_skip = 0;
|
---|
249 | /* Gamma and palette table */
|
---|
250 | regs->gfx.table_ba = 0;
|
---|
251 |
|
---|
252 | /* enable frame buffer graphics */
|
---|
253 | regs->gfx.attributes |= AMDM37X_DISPC_GFX_ATTRIBUTES_ENABLE_FLAG;
|
---|
254 | /* Update register values */
|
---|
255 | regs->control |= AMDM37X_DISPC_CONTROL_GOLCD_FLAG;
|
---|
256 | regs->control |= AMDM37X_DISPC_CONTROL_GODIGITAL_FLAG;
|
---|
257 | /* Enable output */
|
---|
258 | regs->control |= AMDM37X_DISPC_CONTROL_LCD_ENABLE_FLAG;
|
---|
259 | regs->control |= AMDM37X_DISPC_CONTROL_DIGITAL_ENABLE_FLAG;
|
---|
260 | return EOK;
|
---|
261 | }
|
---|
262 |
|
---|
263 | static errno_t amdm37x_change_mode(amdm37x_dispc_t *dispc, unsigned x,
|
---|
264 | unsigned y, visual_t visual)
|
---|
265 | {
|
---|
266 | assert((size_t)visual < sizeof(pixel2visual_table) / sizeof(pixel2visual_table[0]));
|
---|
267 | const unsigned bpp = pixel2visual_table[visual].bpp;
|
---|
268 | pixel2visual_t p2v = pixel2visual_table[visual].func;
|
---|
269 | ddf_log_note("Setting mode: %ux%ux%u\n", x, y, bpp * 8);
|
---|
270 | const size_t size = ALIGN_UP(x * y * bpp, PAGE_SIZE);
|
---|
271 | uintptr_t pa;
|
---|
272 | void *buffer = AS_AREA_ANY;
|
---|
273 | errno_t ret = dmamem_map_anonymous(size, DMAMEM_4GiB,
|
---|
274 | AS_AREA_READ | AS_AREA_WRITE, 0, &pa, &buffer);
|
---|
275 | if (ret != EOK) {
|
---|
276 | ddf_log_error("Failed to get new FB\n");
|
---|
277 | return ret;
|
---|
278 | }
|
---|
279 | if (dispc->fb_data)
|
---|
280 | dmamem_unmap_anonymous(dispc->fb_data);
|
---|
281 |
|
---|
282 | dispc->fb_data = buffer;
|
---|
283 | amdm37x_dispc_setup_fb(dispc->regs, x, y, bpp * 8, (uint32_t)pa);
|
---|
284 | dispc->active_fb.width = x;
|
---|
285 | dispc->active_fb.height = y;
|
---|
286 | dispc->active_fb.pitch = 0;
|
---|
287 | dispc->active_fb.bpp = bpp;
|
---|
288 | dispc->active_fb.pixel2visual = p2v;
|
---|
289 | dispc->rect.p0.x = 0;
|
---|
290 | dispc->rect.p0.y = 0;
|
---|
291 | dispc->rect.p1.x = x;
|
---|
292 | dispc->rect.p1.y = y;
|
---|
293 | dispc->size = size;
|
---|
294 |
|
---|
295 | return EOK;
|
---|
296 | }
|
---|
297 |
|
---|
298 | #define FB_POS(d, x, y) \
|
---|
299 | (((y) * ((d)->active_fb.width + (d)->active_fb.pitch) + (x)) \
|
---|
300 | * (d)->active_fb.bpp)
|
---|
301 |
|
---|
302 | static errno_t amdm37x_ddev_get_gc(void *arg, sysarg_t *arg2, sysarg_t *arg3)
|
---|
303 | {
|
---|
304 | amdm37x_dispc_t *dispc = (amdm37x_dispc_t *) arg;
|
---|
305 |
|
---|
306 | *arg2 = ddf_fun_get_handle(dispc->fun);
|
---|
307 | *arg3 = 42;
|
---|
308 | return EOK;
|
---|
309 | }
|
---|
310 |
|
---|
311 | static errno_t amdm37x_ddev_get_info(void *arg, ddev_info_t *info)
|
---|
312 | {
|
---|
313 | amdm37x_dispc_t *dispc = (amdm37x_dispc_t *) arg;
|
---|
314 |
|
---|
315 | ddev_info_init(info);
|
---|
316 | info->rect.p0.x = 0;
|
---|
317 | info->rect.p0.y = 0;
|
---|
318 | info->rect.p1.x = dispc->active_fb.width;
|
---|
319 | info->rect.p1.y = dispc->active_fb.height;
|
---|
320 | return EOK;
|
---|
321 | }
|
---|
322 |
|
---|
323 | /** Set color on AMDM37x display controller.
|
---|
324 | *
|
---|
325 | * Set drawing color on AMDM37x GC.
|
---|
326 | *
|
---|
327 | * @param arg AMDM37x display controller
|
---|
328 | * @param color Color
|
---|
329 | *
|
---|
330 | * @return EOK on success or an error code
|
---|
331 | */
|
---|
332 | static errno_t amdm37x_gc_set_color(void *arg, gfx_color_t *color)
|
---|
333 | {
|
---|
334 | amdm37x_dispc_t *dispc = (amdm37x_dispc_t *) arg;
|
---|
335 | uint16_t r, g, b;
|
---|
336 |
|
---|
337 | gfx_color_get_rgb_i16(color, &r, &g, &b);
|
---|
338 | dispc->color = PIXEL(0, r >> 8, g >> 8, b >> 8);
|
---|
339 | return EOK;
|
---|
340 | }
|
---|
341 |
|
---|
342 | /** Fill rectangle on AMDM37x display controller.
|
---|
343 | *
|
---|
344 | * @param arg AMDM37x display controller
|
---|
345 | * @param rect Rectangle
|
---|
346 | *
|
---|
347 | * @return EOK on success or an error code
|
---|
348 | */
|
---|
349 | static errno_t amdm37x_gc_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
350 | {
|
---|
351 | amdm37x_dispc_t *dispc = (amdm37x_dispc_t *) arg;
|
---|
352 | gfx_rect_t crect;
|
---|
353 | gfx_coord_t x, y;
|
---|
354 |
|
---|
355 | /* Make sure we have a sorted, clipped rectangle */
|
---|
356 | gfx_rect_clip(rect, &dispc->rect, &crect);
|
---|
357 |
|
---|
358 | for (y = crect.p0.y; y < crect.p1.y; y++) {
|
---|
359 | for (x = crect.p0.x; x < crect.p1.x; x++) {
|
---|
360 | dispc->active_fb.pixel2visual(dispc->fb_data +
|
---|
361 | FB_POS(dispc, x, y), dispc->color);
|
---|
362 | }
|
---|
363 | }
|
---|
364 |
|
---|
365 | return EOK;
|
---|
366 | }
|
---|
367 |
|
---|
368 | /** Create bitmap in AMDM37x GC.
|
---|
369 | *
|
---|
370 | * @param arg AMDM37x display controller
|
---|
371 | * @param params Bitmap params
|
---|
372 | * @param alloc Bitmap allocation info or @c NULL
|
---|
373 | * @param rbm Place to store pointer to new bitmap
|
---|
374 | * @return EOK on success or an error code
|
---|
375 | */
|
---|
376 | errno_t amdm37x_gc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
|
---|
377 | gfx_bitmap_alloc_t *alloc, void **rbm)
|
---|
378 | {
|
---|
379 | amdm37x_dispc_t *dispc = (amdm37x_dispc_t *) arg;
|
---|
380 | amdm37x_bitmap_t *dcbm = NULL;
|
---|
381 | gfx_coord2_t dim;
|
---|
382 | errno_t rc;
|
---|
383 |
|
---|
384 | /* Check that we support all required flags */
|
---|
385 | if ((params->flags & ~(bmpf_color_key | bmpf_colorize)) != 0)
|
---|
386 | return ENOTSUP;
|
---|
387 |
|
---|
388 | dcbm = calloc(1, sizeof(amdm37x_bitmap_t));
|
---|
389 | if (dcbm == NULL)
|
---|
390 | return ENOMEM;
|
---|
391 |
|
---|
392 | gfx_coord2_subtract(¶ms->rect.p1, ¶ms->rect.p0, &dim);
|
---|
393 | dcbm->rect = params->rect;
|
---|
394 | dcbm->flags = params->flags;
|
---|
395 |
|
---|
396 | if (alloc == NULL) {
|
---|
397 | dcbm->alloc.pitch = dim.x * sizeof(uint32_t);
|
---|
398 | dcbm->alloc.off0 = 0;
|
---|
399 | dcbm->alloc.pixels = malloc(dcbm->alloc.pitch * dim.y);
|
---|
400 | dcbm->myalloc = true;
|
---|
401 |
|
---|
402 | if (dcbm->alloc.pixels == NULL) {
|
---|
403 | rc = ENOMEM;
|
---|
404 | goto error;
|
---|
405 | }
|
---|
406 | } else {
|
---|
407 | dcbm->alloc = *alloc;
|
---|
408 | }
|
---|
409 |
|
---|
410 | dcbm->dispc = dispc;
|
---|
411 | *rbm = (void *)dcbm;
|
---|
412 | return EOK;
|
---|
413 | error:
|
---|
414 | if (rbm != NULL)
|
---|
415 | free(dcbm);
|
---|
416 | return rc;
|
---|
417 | }
|
---|
418 |
|
---|
419 | /** Destroy bitmap in AMDM37x GC.
|
---|
420 | *
|
---|
421 | * @param bm Bitmap
|
---|
422 | * @return EOK on success or an error code
|
---|
423 | */
|
---|
424 | static errno_t amdm37x_gc_bitmap_destroy(void *bm)
|
---|
425 | {
|
---|
426 | amdm37x_bitmap_t *dcbm = (amdm37x_bitmap_t *)bm;
|
---|
427 | if (dcbm->myalloc)
|
---|
428 | free(dcbm->alloc.pixels);
|
---|
429 | free(dcbm);
|
---|
430 | return EOK;
|
---|
431 | }
|
---|
432 |
|
---|
433 | /** Render bitmap in AMDM37x GC.
|
---|
434 | *
|
---|
435 | * @param bm Bitmap
|
---|
436 | * @param srect0 Source rectangle or @c NULL
|
---|
437 | * @param offs0 Offset or @c NULL
|
---|
438 | * @return EOK on success or an error code
|
---|
439 | */
|
---|
440 | static errno_t amdm37x_gc_bitmap_render(void *bm, gfx_rect_t *srect0,
|
---|
441 | gfx_coord2_t *offs0)
|
---|
442 | {
|
---|
443 | amdm37x_bitmap_t *dcbm = (amdm37x_bitmap_t *)bm;
|
---|
444 | amdm37x_dispc_t *dispc = dcbm->dispc;
|
---|
445 | gfx_rect_t srect;
|
---|
446 | gfx_rect_t drect;
|
---|
447 | gfx_rect_t skfbrect;
|
---|
448 | gfx_rect_t crect;
|
---|
449 | gfx_coord2_t offs;
|
---|
450 | gfx_coord2_t bmdim;
|
---|
451 | gfx_coord2_t dim;
|
---|
452 | gfx_coord2_t sp;
|
---|
453 | gfx_coord2_t dp;
|
---|
454 | gfx_coord2_t pos;
|
---|
455 | pixelmap_t pbm;
|
---|
456 | pixel_t color;
|
---|
457 |
|
---|
458 | /* Clip source rectangle to bitmap bounds */
|
---|
459 |
|
---|
460 | if (srect0 != NULL)
|
---|
461 | gfx_rect_clip(srect0, &dcbm->rect, &srect);
|
---|
462 | else
|
---|
463 | srect = dcbm->rect;
|
---|
464 |
|
---|
465 | if (offs0 != NULL) {
|
---|
466 | offs = *offs0;
|
---|
467 | } else {
|
---|
468 | offs.x = 0;
|
---|
469 | offs.y = 0;
|
---|
470 | }
|
---|
471 |
|
---|
472 | /* Destination rectangle */
|
---|
473 | gfx_rect_translate(&offs, &srect, &drect);
|
---|
474 | gfx_coord2_subtract(&drect.p1, &drect.p0, &dim);
|
---|
475 | gfx_coord2_subtract(&dcbm->rect.p1, &dcbm->rect.p0, &bmdim);
|
---|
476 |
|
---|
477 | pbm.width = bmdim.x;
|
---|
478 | pbm.height = bmdim.y;
|
---|
479 | pbm.data = dcbm->alloc.pixels;
|
---|
480 |
|
---|
481 | /* Transform AMDM37x bounding rectangle back to bitmap coordinate system */
|
---|
482 | gfx_rect_rtranslate(&offs, &dispc->rect, &skfbrect);
|
---|
483 |
|
---|
484 | /*
|
---|
485 | * Make sure we have a sorted source rectangle, clipped so that
|
---|
486 | * destination lies within AMDM37x bounding rectangle
|
---|
487 | */
|
---|
488 | gfx_rect_clip(&srect, &skfbrect, &crect);
|
---|
489 |
|
---|
490 | if ((dcbm->flags & bmpf_color_key) == 0) {
|
---|
491 | /* Simple copy */
|
---|
492 | for (pos.y = crect.p0.y; pos.y < crect.p1.y; pos.y++) {
|
---|
493 | for (pos.x = crect.p0.x; pos.x < crect.p1.x; pos.x++) {
|
---|
494 | gfx_coord2_subtract(&pos, &dcbm->rect.p0, &sp);
|
---|
495 | gfx_coord2_add(&pos, &offs, &dp);
|
---|
496 |
|
---|
497 | color = pixelmap_get_pixel(&pbm, sp.x, sp.y);
|
---|
498 | dispc->active_fb.pixel2visual(dispc->fb_data +
|
---|
499 | FB_POS(dispc, dp.x, dp.y), color);
|
---|
500 | }
|
---|
501 | }
|
---|
502 | } else if ((dcbm->flags & bmpf_colorize) == 0) {
|
---|
503 | /* Color key */
|
---|
504 | for (pos.y = crect.p0.y; pos.y < crect.p1.y; pos.y++) {
|
---|
505 | for (pos.x = crect.p0.x; pos.x < crect.p1.x; pos.x++) {
|
---|
506 | gfx_coord2_subtract(&pos, &dcbm->rect.p0, &sp);
|
---|
507 | gfx_coord2_add(&pos, &offs, &dp);
|
---|
508 |
|
---|
509 | color = pixelmap_get_pixel(&pbm, sp.x, sp.y);
|
---|
510 | if (color != dcbm->key_color) {
|
---|
511 | dispc->active_fb.pixel2visual(dispc->fb_data +
|
---|
512 | FB_POS(dispc, dp.x, dp.y), color);
|
---|
513 | }
|
---|
514 | }
|
---|
515 | }
|
---|
516 | } else {
|
---|
517 | /* Color key & colorize */
|
---|
518 | for (pos.y = crect.p0.y; pos.y < crect.p1.y; pos.y++) {
|
---|
519 | for (pos.x = crect.p0.x; pos.x < crect.p1.x; pos.x++) {
|
---|
520 | gfx_coord2_subtract(&pos, &dcbm->rect.p0, &sp);
|
---|
521 | gfx_coord2_add(&pos, &offs, &dp);
|
---|
522 |
|
---|
523 | color = pixelmap_get_pixel(&pbm, sp.x, sp.y);
|
---|
524 | if (color != dcbm->key_color) {
|
---|
525 | dispc->active_fb.pixel2visual(dispc->fb_data +
|
---|
526 | FB_POS(dispc, dp.x, dp.y),
|
---|
527 | dcbm->dispc->color);
|
---|
528 | }
|
---|
529 | }
|
---|
530 | }
|
---|
531 | }
|
---|
532 |
|
---|
533 | return EOK;
|
---|
534 | }
|
---|
535 |
|
---|
536 | /** Get allocation info for bitmap in AMDM37x GC.
|
---|
537 | *
|
---|
538 | * @param bm Bitmap
|
---|
539 | * @param alloc Place to store allocation info
|
---|
540 | * @return EOK on success or an error code
|
---|
541 | */
|
---|
542 | static errno_t amdm37x_gc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
|
---|
543 | {
|
---|
544 | amdm37x_bitmap_t *dcbm = (amdm37x_bitmap_t *)bm;
|
---|
545 | *alloc = dcbm->alloc;
|
---|
546 | return EOK;
|
---|
547 | }
|
---|
548 |
|
---|
549 | /**
|
---|
550 | * @}
|
---|
551 | */
|
---|