FabGL
ESP32 Display Controller and Graphics Library
vgacontroller.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 namespace fabgl {
57 
58 
59 
60 
89 class VGAController : public VGABaseController {
90 
91 public:
92 
93  VGAController();
94 
95  // unwanted methods
96  VGAController(VGAController const&) = delete;
97  void operator=(VGAController const&) = delete;
98 
99 
105  static VGAController * instance() { return s_instance; }
106 
107  // abstract method of BitmappedDisplayController
109 
110  // abstract method of BitmappedDisplayController
112 
113  // abstract method of BitmappedDisplayController
115 
116  // import "modeline" version of setResolution
117  using VGABaseController::setResolution;
118 
119  void setResolution(VGATimings const& timings, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
120 
147  void readScreen(Rect const & rect, RGB222 * destBuf);
148 
149  void readScreen(Rect const & rect, RGB888 * destBuf);
150 
177  void writeScreen(Rect const & rect, RGB222 * srcBuf);
178 
193  void setRawPixel(int x, int y, uint8_t rgb) { VGA_PIXEL(x, y) = rgb; }
194 
195 
196 private:
197 
198  void init();
199 
200  void allocateViewPort();
201  void onSetupDMABuffer(lldesc_t volatile * buffer, bool isStartOfVertFrontPorch, int scan, bool isVisible, int visibleRow);
202 
203  // abstract method of BitmappedDisplayController
204  void setPixelAt(PixelDesc const & pixelDesc, Rect & updateRect);
205 
206  // abstract method of BitmappedDisplayController
207  void drawEllipse(Size const & size, Rect & updateRect);
208 
209  // abstract method of BitmappedDisplayController
210  void clear(Rect & updateRect);
211 
212  // abstract method of BitmappedDisplayController
213  void VScroll(int scroll, Rect & updateRect);
214 
215  // abstract method of BitmappedDisplayController
216  void HScroll(int scroll, Rect & updateRect);
217 
218  // abstract method of BitmappedDisplayController
219  void drawGlyph(Glyph const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect);
220 
221  // abstract method of BitmappedDisplayController
222  void invertRect(Rect const & rect, Rect & updateRect);
223 
224  // abstract method of BitmappedDisplayController
225  void copyRect(Rect const & source, Rect & updateRect);
226 
227  // abstract method of BitmappedDisplayController
228  void swapFGBG(Rect const & rect, Rect & updateRect);
229 
230  // abstract method of BitmappedDisplayController
231  void rawDrawBitmap_Native(int destX, int destY, Bitmap const * bitmap, int X1, int Y1, int XCount, int YCount);
232 
233  // abstract method of BitmappedDisplayController
234  void rawDrawBitmap_Mask(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
235 
236  // abstract method of BitmappedDisplayController
237  void rawDrawBitmap_RGBA2222(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
238 
239  // abstract method of BitmappedDisplayController
240  void rawDrawBitmap_RGBA8888(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
241 
242  // abstract method of BitmappedDisplayController
243  void rawFillRow(int y, int x1, int x2, RGB888 color);
244 
245  void rawFillRow(int y, int x1, int x2, uint8_t pattern);
246 
247  void rawInvertRow(int y, int x1, int x2);
248 
249  void swapRows(int yA, int yB, int x1, int x2);
250 
251  // abstract method of BitmappedDisplayController
252  void absDrawLine(int X1, int Y1, int X2, int Y2, RGB888 color);
253 
254  // abstract method of BitmappedDisplayController
255  int getBitmapSavePixelSize() { return 1; }
256 
257  static void VSyncInterrupt(void * arg);
258 
259 
260 
261  static VGAController * s_instance;
262 
263  volatile int16_t m_maxVSyncISRTime; // Maximum us VSync interrupt routine can run
264 
265 };
266 
267 
268 
269 } // end of namespace
270 
271 
272 
273 
274 
275 
276 
int16_t X2
Definition: fabutils.h:180
Represents a 24 bit RGB color.
int16_t Y2
Definition: fabutils.h:181
This file contains fabgl::VGABaseController definition.
NativePixelFormat nativePixelFormat()
Represents the native pixel format used by this display.
int16_t Y1
Definition: fabutils.h:179
This file contains fabgl::GPIOStream definition.
This file contains fabgl::BitmappedDisplayController definition.
int16_t X1
Definition: fabutils.h:178
void setRawPixel(int x, int y, uint8_t rgb)
Sets a raw pixel prepared using VGAController.createRawPixel.
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
void suspendBackgroundPrimitiveExecution()
Suspends drawings.
NativePixelFormat
This enum defines the display controller native pixel format.
Specifies various glyph painting options.
Represents a rectangle.
Definition: fabutils.h:226
void resumeBackgroundPrimitiveExecution()
Resumes drawings after suspendBackgroundPrimitiveExecution().
Represents the VGA bitmapped controller.
Definition: vgacontroller.h:89
This file contains FabGL library configuration settings, like number of supported colors...
static VGAController * instance()
Returns the singleton instance of VGAController class.
Represents a bidimensional size.
Definition: fabutils.h:209
void readScreen(Rect const &rect, RGB222 *destBuf)
Reads pixels inside the specified rectangle.
void writeScreen(Rect const &rect, RGB222 *srcBuf)
Writes pixels inside the specified rectangle.
Represents a 6 bit RGB color.