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-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 #define VGAD_LinesCount 2
53 
54 
55 
56 namespace fabgl {
57 
65 typedef void (*DrawScanlineCallback)(void * arg, uint8_t * dest, int scanLine);
66 
67 
76 class VGADirectController : public VGABaseController {
77 
78 public:
79 
81 
82  // unwanted methods
84  void operator=(VGADirectController const&) = delete;
85 
86 
92  static VGADirectController * instance() { return s_instance; }
93 
94  // abstract method of BitmappedDisplayController
96 
97  // import "modeline" v3rsion of setResolution
98  using VGABaseController::setResolution;
99 
100  void setResolution(VGATimings const& timings, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
101 
102  void readScreen(Rect const & rect, RGB888 * destBuf);
103 
110  void setDrawScanlineCallback(DrawScanlineCallback drawScanlineCallback, void * arg = nullptr) { m_drawScanlineCallback = drawScanlineCallback; m_drawScanlineArg = arg; }
111 
112 private:
113 
114  void init();
115 
116  void onSetupDMABuffer(lldesc_t volatile * buffer, bool isStartOfVertFrontPorch, int scan, bool isVisible, int visibleRow);
117  void allocateViewPort();
118  void freeViewPort();
119 
120 
121  // abstract method of BitmappedDisplayController
122  void setPixelAt(PixelDesc const & pixelDesc, Rect & updateRect);
123 
124  // abstract method of BitmappedDisplayController
125  void drawEllipse(Size const & size, Rect & updateRect);
126 
127  // abstract method of BitmappedDisplayController
128  void clear(Rect & updateRect);
129 
130  // abstract method of BitmappedDisplayController
131  void VScroll(int scroll, Rect & updateRect);
132 
133  // abstract method of BitmappedDisplayController
134  void HScroll(int scroll, Rect & updateRect);
135 
136  // abstract method of BitmappedDisplayController
137  void drawGlyph(Glyph const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect);
138 
139  // abstract method of BitmappedDisplayController
140  void invertRect(Rect const & rect, Rect & updateRect);
141 
142  // abstract method of BitmappedDisplayController
143  void copyRect(Rect const & source, Rect & updateRect);
144 
145  // abstract method of BitmappedDisplayController
146  void swapFGBG(Rect const & rect, Rect & updateRect);
147 
148  // abstract method of BitmappedDisplayController
149  void rawDrawBitmap_Native(int destX, int destY, Bitmap const * bitmap, int X1, int Y1, int XCount, int YCount);
150 
151  // abstract method of BitmappedDisplayController
152  void rawDrawBitmap_Mask(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
153 
154  // abstract method of BitmappedDisplayController
155  void rawDrawBitmap_RGBA2222(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
156 
157  // abstract method of BitmappedDisplayController
158  void rawDrawBitmap_RGBA8888(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
159 
160  // abstract method of BitmappedDisplayController
161  void rawFillRow(int y, int x1, int x2, RGB888 color);
162 
163  void rawFillRow(int y, int x1, int x2, uint8_t colorIndex);
164 
165  void rawInvertRow(int y, int x1, int x2);
166 
167  void rawCopyRow(int x1, int x2, int srcY, int dstY);
168 
169  void swapRows(int yA, int yB, int x1, int x2);
170 
171  // abstract method of BitmappedDisplayController
172  void absDrawLine(int X1, int Y1, int X2, int Y2, RGB888 color);
173 
174  // abstract method of BitmappedDisplayController
175  int getBitmapSavePixelSize() { return 1; }
176 
177  static void ISRHandler(void * arg);
178 
179 
180  static VGADirectController * s_instance;
181  static volatile int s_scanLine;
182  static lldesc_t volatile * s_frameResetDesc;
183 
184 
185  volatile uint8_t * m_lines[VGAD_LinesCount];
186 
187  // here we use callbacks in place of virtual methods because vtables are stored in Flash and
188  // so it would not have been possible to put ISR into IRAM.
189  DrawScanlineCallback m_drawScanlineCallback;
190  void * m_drawScanlineArg;
191 
192 };
193 
194 
195 
196 } // end of namespace
197 
198 
199 
200 
201 
202 
203 
204 
int16_t X2
Definition: fabutils.h:150
Represents a 24 bit RGB color.
NativePixelFormat nativePixelFormat()
Represents the native pixel format used by this display.
int16_t Y2
Definition: fabutils.h:151
This file contains fabgl::VGABaseController definition.
int16_t Y1
Definition: fabutils.h:149
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:148
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:31
NativePixelFormat
This enum defines the display controller native pixel format.
Specifies various glyph painting options.
Represents a rectangle.
Definition: fabutils.h:191
This file contains FabGL library configuration settings, like number of supported colors...
Represents a bidimensional size.
Definition: fabutils.h:176
static VGADirectController * instance()
Returns the singleton instance of VGADirectController class.