acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
VNC_GFX.h (3729B)
1 #ifndef _VNC_GFX_H_ 2 #define _VNC_GFX_H_ 3 4 #include "Arduino_GFX_Library.h" 5 #include "VNC.h" 6 #include "VNC_config.h" 7 8 #ifdef ESP32 9 // #define SEPARATE_DRAW_TASK 10 #endif 11 12 #ifdef SEPARATE_DRAW_TASK 13 14 #define NUMBER_OF_DRAW_BUFFER 64 15 16 typedef struct 17 { 18 xQueueHandle xqh; 19 Arduino_GFX *gfx; 20 } ParamDrawTask; 21 22 typedef struct 23 { 24 int16_t x; 25 int16_t y; 26 int16_t w; 27 int16_t h; 28 bool isBitmap; 29 uint16_t *buf; 30 } DrawData; 31 32 static xQueueHandle _xqh; 33 static ParamDrawTask _pDrawTask; 34 static TaskHandle_t _draw_task_handle; 35 36 static DrawData drawDatas[NUMBER_OF_DRAW_BUFFER]; 37 static int draw_queue_cnt = 0; 38 39 static void queueDrawTask(uint32_t x, uint32_t y, uint32_t w, uint32_t h, bool isBitmap, uint16_t *d) 40 { 41 log_i("queueDrawTask start."); 42 DrawData *dd = &drawDatas[draw_queue_cnt % NUMBER_OF_DRAW_BUFFER]; 43 dd->x = x; 44 dd->y = y; 45 dd->w = w; 46 dd->h = h; 47 dd->isBitmap = isBitmap; 48 log_i("copy data start."); 49 uint16_t *p = &dd->buf[0]; 50 if (isBitmap) 51 { 52 log_i("copy bitmap."); 53 int i = w * h; 54 while (i--) 55 { 56 *p++ = *d++; 57 } 58 } 59 else 60 { 61 *p = *d; 62 } 63 log_i("copy data end."); 64 65 ++draw_queue_cnt; 66 67 log_i("xQueueSend start."); 68 xQueueSend(_xqh, &dd, portMAX_DELAY); 69 log_i("xQueueSend end."); 70 71 log_i("queueDrawTask end."); 72 } 73 74 static void draw_task(void *arg) 75 { 76 DrawData *dd; 77 log_i("draw_task start."); 78 while (xQueueReceive(_xqh, &dd, portMAX_DELAY)) 79 { 80 log_i("draw_task work start: x: %d, y: %d, w: %d, h: %d.", dd->x, dd->y, dd->w, dd->h); 81 if (dd->isBitmap) 82 { 83 gfx->draw16bitBeRGBBitmap(dd->x, dd->y, &dd->buf[0], dd->w, dd->h); 84 } 85 else 86 { 87 gfx->fillRect(dd->x, dd->y, dd->w, dd->h, dd->buf[0]); 88 } 89 log_i("draw_task work end."); 90 } 91 vQueueDelete(_xqh); 92 log_i("draw_task end."); 93 vTaskDelete(NULL); 94 } 95 96 void draw_task_setup() 97 { 98 _xqh = xQueueCreate(NUMBER_OF_DRAW_BUFFER, sizeof(DrawData)); 99 _pDrawTask.xqh = _xqh; 100 _pDrawTask.gfx = gfx; 101 102 log_i("xTaskCreatePinnedToCore start"); 103 xTaskCreatePinnedToCore( 104 (TaskFunction_t)draw_task, 105 (const char *const)"Draw Task", 106 (const uint32_t)1600, 107 (void *const)&_pDrawTask, 108 (UBaseType_t)configMAX_PRIORITIES - 1, 109 (TaskHandle_t *const)&_draw_task_handle, 110 (const BaseType_t)0); 111 log_i("xTaskCreatePinnedToCore end"); 112 113 for (int i = 0; i < NUMBER_OF_DRAW_BUFFER; i++) 114 { 115 if (!drawDatas[i].buf) 116 { 117 drawDatas[i].buf = (uint16_t *)malloc(FB_SIZE * 2); 118 } 119 if (drawDatas[i].buf) 120 { 121 log_i("#%d draw buffer allocated.", i); 122 } 123 else 124 { 125 log_e("#%d draw buffer allocat failed.", i); 126 } 127 } 128 } 129 130 #endif 131 132 class VNC_GFX : public VNCdisplay 133 { 134 public: 135 VNC_GFX(Arduino_GFX *gfx) 136 { 137 _gfx = gfx; 138 } 139 140 bool hasCopyRect(void) 141 { 142 return false; 143 } 144 145 uint32_t getHeight(void) 146 { 147 return _gfx->height(); 148 } 149 uint32_t getWidth(void) 150 { 151 return _gfx->width(); 152 } 153 154 void draw_area(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t *data) 155 { 156 // DEBUG_VNC("draw_area(%d, %d, %d, %d, data)\n", x, y, w, h); 157 #ifdef SEPARATE_DRAW_TASK 158 queueDrawTask(x, y, w, h, true, (uint16_t *)data); 159 #else 160 // _gfx->draw16bitBeRGBBitmap(x, y, (uint16_t *)data, w, h); 161 _gfx->draw16bitRGBBitmap(x, y, (uint16_t *)data, w, h); 162 #endif 163 } 164 165 void draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t color) 166 { 167 // DEBUG_VNC("draw_rect(%d, %d, %d, %d, color)\n", x, y, w, h); 168 // MSB_16_SET(color, color); 169 #ifdef SEPARATE_DRAW_TASK 170 queueDrawTask(x, y, w, h, false, &color); 171 #else 172 _gfx->fillRect(x, y, w, h, color); 173 #endif 174 } 175 176 void vnc_options_override(dfb_vnc_options *opt) 177 { 178 // opt->client.bigendian = 1; 179 } 180 181 private: 182 Arduino_GFX *_gfx; 183 }; 184 185 #endif /* _VNC_GFX_H_ */