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. Feel free to use FabGL in free software and hardware:
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 
139  static bool VSync() { return s_VSync; }
140 
141 private:
142 
143  void init();
144 
145  void onSetupDMABuffer(lldesc_t volatile * buffer, bool isStartOfVertFrontPorch, int scan, bool isVisible, int visibleRow);
146  void allocateViewPort();
147  void freeViewPort();
148 
149 
150  // abstract method of BitmappedDisplayController
151  void setPixelAt(PixelDesc const & pixelDesc, Rect & updateRect);
152 
153  // abstract method of BitmappedDisplayController
154  void drawEllipse(Size const & size, Rect & updateRect);
155 
156  // abstract method of BitmappedDisplayController
157  void clear(Rect & updateRect);
158 
159  // abstract method of BitmappedDisplayController
160  void VScroll(int scroll, Rect & updateRect);
161 
162  // abstract method of BitmappedDisplayController
163  void HScroll(int scroll, Rect & updateRect);
164 
165  // abstract method of BitmappedDisplayController
166  void drawGlyph(Glyph const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect);
167 
168  // abstract method of BitmappedDisplayController
169  void invertRect(Rect const & rect, Rect & updateRect);
170 
171  // abstract method of BitmappedDisplayController
172  void copyRect(Rect const & source, Rect & updateRect);
173 
174  // abstract method of BitmappedDisplayController
175  void swapFGBG(Rect const & rect, Rect & updateRect);
176 
177  // abstract method of BitmappedDisplayController
178  void rawDrawBitmap_Native(int destX, int destY, Bitmap const * bitmap, int X1, int Y1, int XCount, int YCount);
179 
180  // abstract method of BitmappedDisplayController
181  void rawDrawBitmap_Mask(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
182 
183  // abstract method of BitmappedDisplayController
184  void rawDrawBitmap_RGBA2222(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
185 
186  // abstract method of BitmappedDisplayController
187  void rawDrawBitmap_RGBA8888(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
188 
189  // abstract method of BitmappedDisplayController
190  void rawFillRow(int y, int x1, int x2, RGB888 color);
191 
192  void rawFillRow(int y, int x1, int x2, uint8_t colorIndex);
193 
194  void rawInvertRow(int y, int x1, int x2);
195 
196  void rawCopyRow(int x1, int x2, int srcY, int dstY);
197 
198  void swapRows(int yA, int yB, int x1, int x2);
199 
200  // abstract method of BitmappedDisplayController
201  void absDrawLine(int X1, int Y1, int X2, int Y2, RGB888 color);
202 
203  // abstract method of BitmappedDisplayController
204  int getBitmapSavePixelSize() { return 1; }
205 
206  static void ISRHandler(void * arg);
207 
208 
209  static VGADirectController * s_instance;
210  static volatile int s_scanLine;
211  static lldesc_t volatile * s_frameResetDesc;
212  static bool s_VSync;
213 
214  int32_t m_linesCount;
215  uint8_t * * m_lines;
216 
217  // here we use callbacks in place of virtual methods because vtables are stored in Flash and
218  // so it would not have been possible to put ISR into IRAM.
219  DrawScanlineCallback m_drawScanlineCallback;
220  void * m_drawScanlineArg;
221 
222  bool m_autoRun;
223 
224 };
225 
226 
227 
228 } // end of namespace
229 
230 
231 
232 
233 
234 
235 
236 
int16_t X2
Definition: fabutils.h:179
Represents a 24 bit RGB color.
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:180
This file contains fabgl::VGABaseController definition.
int16_t Y1
Definition: fabutils.h:178
This file contains fabgl::GPIOStream definition.
This file contains fabgl::BitmappedDisplayController definition.
Represents an base abstract class for direct draw VGA controller.
int16_t X1
Definition: fabutils.h:177
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:225
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:208
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.