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