microui  14.5.5
microui
ui_display_brs.c
1 /*
2  * Copyright 2023-2026 MicroEJ Corp. All rights reserved.
3  * MicroEJ Corp. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  *
5  * Build: 7E4D1F7C
6  */
7 
8 /*
9  * @file
10  * @brief This file implements is the common part of all display buffer strategies (BRS).
11  * @author MicroEJ Developer Team
12  * @version 14.5.5
13  */
14 
15 // --------------------------------------------------------------------------------
16 // Includes
17 // --------------------------------------------------------------------------------
18 
19 #include <string.h>
20 
21 #include "ui_display_brs.h"
22 #include "bsp_util.h"
23 #include "ui_drawing.h"
24 
25 // --------------------------------------------------------------------------------
26 // ui_display_brs.h API
27 // --------------------------------------------------------------------------------
28 
29 /*
30  * @brief Provides a simple implementation of the restore: use memcpy().
31  * See the header file for the function documentation
32  */
33 BSP_DECLARE_WEAK_FCNT DRAWING_Status UI_DISPLAY_BRS_restore(MICROUI_GraphicsContext *gc, MICROUI_Image *old_back_buffer,
34  ui_rect_t *rect) {
35  DRAWING_Status ret;
36  uint32_t bpp = LLUI_DISPLAY_getImageBPP(old_back_buffer);
37  uint32_t width = UI_RECT_get_width(rect);
38  uint32_t height = UI_RECT_get_height(rect);
39 
40  if (8u > bpp) {
41  // this weak function is not designed to target this kind of buffer
42  // -> let the standard function copyImage() performing the job
43  ret = UI_DRAWING_copyImage(gc, old_back_buffer, rect->x1, rect->y1, width, height, rect->x1, rect->y1);
44  } else {
45  uint8_t *dst = LLUI_DISPLAY_getBufferAddress(&gc->image);
46  uint8_t *src = LLUI_DISPLAY_getBufferAddress(old_back_buffer);
47  uint32_t stride = LLUI_DISPLAY_getStrideInBytes(&gc->image);
48 
49  dst += rect->y1 * stride;
50  src += rect->y1 * stride;
51 
52  if ((0 == rect->x1) && (old_back_buffer->width == width)) {
53  // a simple memcpy is required!
54  (void)memcpy(dst, src, stride * height);
55  } else {
56  // have to perform one memcpy per line
57  dst += rect->x1 * bpp / 8u;
58  src += rect->x1 * bpp / 8u;
59  uint32_t size = width * bpp / 8u;
60 
61  for (uint32_t y = 0; y < height; y++) {
62  (void)memcpy(dst, src, size);
63  dst += stride;
64  src += stride;
65  }
66  }
67 
68  // the memcpy() above draws in the back buffer with the CPU, so it is notified like any other
69  // software drawing: on a VEE port whose buffers sit in a cached memory, the next drawing may be a
70  // GPU one and it has to flush the cache first. The bpp < 8 branch above needs no notification:
71  // UI_DRAWING_copyImage() notifies by itself when it falls back to software.
72  LLUI_DISPLAY_IMPL_notifyDrawingSoft(gc);
73 
74  ret = DRAWING_DONE;
75  }
76  return ret;
77 }
78 
79 // --------------------------------------------------------------------------------
80 // EOF
81 // --------------------------------------------------------------------------------
Provides some implementations of the LLUI_DISPLAY_impl.h functions relating to the display buffer str...
DRAWING_Status UI_DISPLAY_BRS_restore(MICROUI_GraphicsContext *gc, MICROUI_Image *old_back_buffer, ui_rect_t *rect)
Restores (copies) the given rectangular region from old back buffer to the graphics context's current...