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-2020 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of FabGL Library.
7 
8  FabGL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  FabGL is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #pragma once
24 
25 
26 
34 #include <stdint.h>
35 #include <stddef.h>
36 #include <atomic>
37 
38 #include "rom/lldesc.h"
39 #include "driver/gpio.h"
40 
41 #include "freertos/FreeRTOS.h"
42 #include "freertos/queue.h"
43 
44 #include "fabglconf.h"
45 #include "fabutils.h"
46 #include "devdrivers/swgenerator.h"
47 #include "displaycontroller.h"
49 
50 
51 
52 
53 namespace fabgl {
54 
55 
56 
57 
86 class VGAController : public VGABaseController {
87 
88 public:
89 
90  VGAController();
91 
92  // unwanted methods
93  VGAController(VGAController const&) = delete;
94  void operator=(VGAController const&) = delete;
95 
96 
102  static VGAController * instance() { return s_instance; }
103 
104  // abstract method of BitmappedDisplayController
106 
107  // abstract method of BitmappedDisplayController
109 
110  // abstract method of BitmappedDisplayController
112 
113  // import "modeline" v3rsion of setResolution
114  using VGABaseController::setResolution;
115 
116  void setResolution(VGATimings const& timings, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
117 
144  void readScreen(Rect const & rect, RGB222 * destBuf);
145 
146  void readScreen(Rect const & rect, RGB888 * destBuf);
147 
174  void writeScreen(Rect const & rect, RGB222 * srcBuf);
175 
176 
177 private:
178 
179  void init();
180 
181  void allocateViewPort();
182  void onSetupDMABuffer(lldesc_t volatile * buffer, bool isStartOfVertFrontPorch, int scan, bool isVisible, int visibleRow);
183 
184  // abstract method of BitmappedDisplayController
185  void setPixelAt(PixelDesc const & pixelDesc, Rect & updateRect);
186 
187  // abstract method of BitmappedDisplayController
188  void drawEllipse(Size const & size, Rect & updateRect);
189 
190  // abstract method of BitmappedDisplayController
191  void clear(Rect & updateRect);
192 
193  // abstract method of BitmappedDisplayController
194  void VScroll(int scroll, Rect & updateRect);
195 
196  // abstract method of BitmappedDisplayController
197  void HScroll(int scroll, Rect & updateRect);
198 
199  // abstract method of BitmappedDisplayController
200  void drawGlyph(Glyph const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect);
201 
202  // abstract method of BitmappedDisplayController
203  void invertRect(Rect const & rect, Rect & updateRect);
204 
205  // abstract method of BitmappedDisplayController
206  void copyRect(Rect const & source, Rect & updateRect);
207 
208  // abstract method of BitmappedDisplayController
209  void swapFGBG(Rect const & rect, Rect & updateRect);
210 
211  // abstract method of BitmappedDisplayController
212  void rawDrawBitmap_Native(int destX, int destY, Bitmap const * bitmap, int X1, int Y1, int XCount, int YCount);
213 
214  // abstract method of BitmappedDisplayController
215  void rawDrawBitmap_Mask(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
216 
217  // abstract method of BitmappedDisplayController
218  void rawDrawBitmap_RGBA2222(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
219 
220  // abstract method of BitmappedDisplayController
221  void rawDrawBitmap_RGBA8888(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
222 
223  // abstract method of BitmappedDisplayController
224  void rawFillRow(int y, int x1, int x2, RGB888 color);
225 
226  void rawFillRow(int y, int x1, int x2, uint8_t pattern);
227 
228  void rawInvertRow(int y, int x1, int x2);
229 
230  void swapRows(int yA, int yB, int x1, int x2);
231 
232  // abstract method of BitmappedDisplayController
233  void absDrawLine(int X1, int Y1, int X2, int Y2, RGB888 color);
234 
235  // abstract method of BitmappedDisplayController
236  int getBitmapSavePixelSize() { return 1; }
237 
238  static void VSyncInterrupt(void * arg);
239 
240 
241 
242  static VGAController * s_instance;
243 
244  volatile int16_t m_maxVSyncISRTime; // Maximum us VSync interrupt routine can run
245 
246 };
247 
248 
249 
250 } // end of namespace
251 
252 
253 
254 
255 
256 
257 
int16_t X2
Definition: fabutils.h:150
Represents a 24 bit RGB color.
int16_t Y2
Definition: fabutils.h:151
This file contains fabgl::VGABaseController definition.
NativePixelFormat nativePixelFormat()
Represents the native pixel format used by this display.
int16_t Y1
Definition: fabutils.h:149
This file contains fabgl::GPIOStream definition.
This file contains fabgl::BitmappedDisplayController definition.
int16_t X1
Definition: fabutils.h:148
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:31
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:191
void resumeBackgroundPrimitiveExecution()
Resumes drawings after suspendBackgroundPrimitiveExecution().
Represents the VGA bitmapped controller.
Definition: vgacontroller.h:86
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:176
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.