microui  14.2.0
microui
ui_display_brs.c
1 /*
2  * Copyright 2023-2024 MicroEJ Corp. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be found with this software.
4  */
5 
6 /*
7  * @file
8  * @brief This file implements is the common part of all display buffer strategies (BRS).
9  * @author MicroEJ Developer Team
10  * @version 14.2.0
11  */
12 
13 // --------------------------------------------------------------------------------
14 // Includes
15 // --------------------------------------------------------------------------------
16 
17 #include <string.h>
18 
19 #include "ui_display_brs.h"
20 #include "bsp_util.h"
21 #include "ui_drawing.h"
22 
23 // --------------------------------------------------------------------------------
24 // ui_display_brs.h API
25 // --------------------------------------------------------------------------------
26 
27 /*
28  * @brief Provides a simple implementation of the restore: use memcpy().
29  * See the header file for the function documentation
30  */
31 BSP_DECLARE_WEAK_FCNT DRAWING_Status UI_DISPLAY_BRS_restore(MICROUI_GraphicsContext *gc, MICROUI_Image *old_back_buffer,
32  ui_rect_t *rect) {
33  DRAWING_Status ret;
34  uint32_t bpp = LLUI_DISPLAY_getImageBPP(old_back_buffer);
35  uint32_t width = UI_RECT_get_width(rect);
36  uint32_t height = UI_RECT_get_height(rect);
37 
38  if (8u > bpp) {
39  // this weak function is not designed to target this kind of buffer
40  // -> let the standard function copyImage() performing the job
41  ret = UI_DRAWING_copyImage(gc, old_back_buffer, rect->x1, rect->y1, width, height, rect->x1, rect->y1);
42  } else {
43  uint8_t *dst = LLUI_DISPLAY_getBufferAddress(&gc->image);
44  uint8_t *src = LLUI_DISPLAY_getBufferAddress(old_back_buffer);
45  uint32_t stride = LLUI_DISPLAY_getStrideInBytes(&gc->image);
46 
47  dst += rect->y1 * stride;
48  src += rect->y1 * stride;
49 
50  if ((0 == rect->x1) && (old_back_buffer->width == width)) {
51  // a simple memcpy is required!
52  (void)memcpy(dst, src, stride * height);
53  } else {
54  // have to perform one memcpy per line
55  dst += rect->x1 * bpp / 8u;
56  src += rect->x1 * bpp / 8u;
57  uint32_t size = width * bpp / 8u;
58 
59  for (uint32_t y = 0; y < height; y++) {
60  (void)memcpy(dst, src, size);
61  dst += stride;
62  src += stride;
63  }
64  }
65 
66  ret = DRAWING_DONE;
67  }
68  return ret;
69 }
70 
71 // --------------------------------------------------------------------------------
72 // EOF
73 // --------------------------------------------------------------------------------