FabGL
ESP32 Display Controller and Graphics Library
vgadirectcontroller.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3  Copyright (c) 2019-2021 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6 
7 * Please contact fdivitto2013@gmail.com if you need a commercial license.
8 
9 
10 * This library and related software is available under GPL v3.
11 
12  FabGL is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  FabGL is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #pragma once
28 
29 
30 
38 #include <stdint.h>
39 #include <stddef.h>
40 #include <atomic>
41 
42 #include "driver/gpio.h"
43 
44 #include "freertos/FreeRTOS.h"
45 #include "freertos/queue.h"
46 
47 #include "fabglconf.h"
48 #include "fabutils.h"
49 #include "devdrivers/swgenerator.h"
50 #include "displaycontroller.h"
52 
53 
54 
55 
56 
57 namespace fabgl {
58 
66 typedef void (*DrawScanlineCallback)(void * arg, uint8_t * dest, int scanLine);
67 
68 
77 class VGADirectController : public VGABaseController {
78 
79 public:
80 
86  VGADirectController(bool autoRun = true);
87 
88  // unwanted methods
90  void operator=(VGADirectController const&) = delete;
91 
92 
98  static VGADirectController * instance() { return s_instance; }
99 
100  // abstract method of BitmappedDisplayController
102 
103  // import "modeline" version of setResolution
104  using VGABaseController::setResolution;
105 
106  void setResolution(VGATimings const& timings, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
107 
108  void readScreen(Rect const & rect, RGB888 * destBuf);
109 
116  void setDrawScanlineCallback(DrawScanlineCallback drawScanlineCallback, void * arg = nullptr) { m_drawScanlineCallback = drawScanlineCallback; m_drawScanlineArg = arg; }
117 
123  void run();
124 
132  void setScanlinesPerCallBack(int value) { m_linesCount = value * 2; }
133 
140  void setScanlineBuffer(int scanline, uint8_t volatile * lineBuffer);
141 
147  uint8_t volatile * getScanlineBuffer(int scanline);
148 
157  uint8_t volatile * getDefaultScanlineBuffer(int scanline);
158 
164  static bool VSync() { return s_VSync; }
165 
166 private:
167 
168  void init();
169 
170  void onSetupDMABuffer(lldesc_t volatile * buffer, bool isStartOfVertFrontPorch, int scan, bool isVisible, int visibleRow);
171  void allocateViewPort();
172  void freeViewPort();
173 
174 
175  // abstract method of BitmappedDisplayController
176  void setPixelAt(PixelDesc const & pixelDesc, Rect & updateRect);
177 
178  // abstract method of BitmappedDisplayController
179  void drawEllipse(Size const & size, Rect & updateRect);
180 
181  // abstract method of BitmappedDisplayController
182  void clear(Rect & updateRect);
183 
184  // abstract method of BitmappedDisplayController
185  void VScroll(int scroll, Rect & updateRect);
186 
187  // abstract method of BitmappedDisplayController
188  void HScroll(int scroll, Rect & updateRect);
189 
190  // abstract method of BitmappedDisplayController
191  void drawGlyph(Glyph const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect);
192 
193  // abstract method of BitmappedDisplayController
194  void invertRect(Rect const & rect, Rect & updateRect);
195 
196  // abstract method of BitmappedDisplayController
197  void copyRect(Rect const & source, Rect & updateRect);
198 
199  // abstract method of BitmappedDisplayController
200  void swapFGBG(Rect const & rect, Rect & updateRect);
201 
202  // abstract method of BitmappedDisplayController
203  void rawDrawBitmap_Native(int destX, int destY, Bitmap const * bitmap, int X1, int Y1, int XCount, int YCount);
204 
205  // abstract method of BitmappedDisplayController
206  void rawDrawBitmap_Mask(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
207 
208  // abstract method of BitmappedDisplayController
209  void rawDrawBitmap_RGBA2222(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
210 
211  // abstract method of BitmappedDisplayController
212  void rawDrawBitmap_RGBA8888(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
213 
214  // abstract method of BitmappedDisplayController
215  void rawFillRow(int y, int x1, int x2, RGB888 color);
216 
217  void rawFillRow(int y, int x1, int x2, uint8_t colorIndex);
218 
219  void rawInvertRow(int y, int x1, int x2);
220 
221  void rawCopyRow(int x1, int x2, int srcY, int dstY);
222 
223  void swapRows(int yA, int yB, int x1, int x2);
224 
225  // abstract method of BitmappedDisplayController
226  void absDrawLine(int X1, int Y1, int X2, int Y2, RGB888 color);
227 
228  // abstract method of BitmappedDisplayController
229  int getBitmapSavePixelSize() { return 1; }
230 
231  static void ISRHandler(void * arg);
232 
233 
234  static VGADirectController * s_instance;
235  static volatile int s_scanLine;
236  static lldesc_t volatile * s_frameResetDesc;
237  static bool s_VSync;
238  static lldesc_t volatile * * s_DMALines;
239 
240  int32_t m_linesCount;
241  uint8_t * * m_lines;
242 
243  // here we use callbacks in place of virtual methods because vtables are stored in Flash and
244  // so it would not have been possible to put ISR into IRAM.
245  DrawScanlineCallback m_drawScanlineCallback;
246  void * m_drawScanlineArg;
247 
248  bool m_autoRun;
249 
250 };
251 
252 
253 
254 } // end of namespace
255 
256 
257 
258 
259 
260 
261 
262 
int16_t X2
Definition: fabutils.h:180
Represents a 24 bit RGB color.
uint8_t volatile * getDefaultScanlineBuffer(int scanline)
Gets default scanline buffer.
void setScanlineBuffer(int scanline, uint8_t volatile *lineBuffer)
Sets a scanline buffer.
NativePixelFormat nativePixelFormat()
Represents the native pixel format used by this display.
void setScanlinesPerCallBack(int value)
Sets number of scanlines to draw in a single callback.
int16_t Y2
Definition: fabutils.h:181
uint8_t volatile * getScanlineBuffer(int scanline)
Gets current scanline buffer.
This file contains fabgl::VGABaseController definition.
int16_t Y1
Definition: fabutils.h:179
This file contains fabgl::GPIOStream definition.
This file contains fabgl::BitmappedDisplayController definition.
Represents a base abstract class for direct draw VGA controller.
int16_t X1
Definition: fabutils.h:178
void setDrawScanlineCallback(DrawScanlineCallback drawScanlineCallback, void *arg=nullptr)
Sets the callback used when VGADirectController needs to prepare a new scanline to be sent to the VGA...
Specifies the VGA timings. This is a modeline decoded.
Represents a glyph position, size and binary data.
Represents an image.
This file contains some utility classes and functions.
Definition: canvas.cpp:36
NativePixelFormat
This enum defines the display controller native pixel format.
Specifies various glyph painting options.
Represents a rectangle.
Definition: fabutils.h:226
static bool VSync()
Determines if retracing is in progress.
This file contains FabGL library configuration settings, like number of supported colors...
Represents a bidimensional size.
Definition: fabutils.h:209
void run()
Begins to call the callback function and to display video frames.
VGADirectController(bool autoRun=true)
Initializes a new instance of VGADirectController.
static VGADirectController * instance()
Returns the singleton instance of VGADirectController class.