FabGL
ESP32 Display Controller and Graphics Library
vgapalettedcontroller.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 
61 
62 
66 class VGAPalettedController : public VGABaseController {
67 
68 public:
69 
70  VGAPalettedController(int linesCount, int columnsQuantum, NativePixelFormat nativePixelFormat, int viewPortRatioDiv, int viewPortRatioMul, intr_handler_t isrHandler);
72 
73  // unwanted methods
75  void operator=(VGAPalettedController const&) = delete;
76 
77  void end();
78 
79  // abstract method of BitmappedDisplayController
81 
82  // import "modeline" version of setResolution
83  using VGABaseController::setResolution;
84 
85  void setResolution(VGATimings const& timings, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
86 
87  int getPaletteSize();
88 
89  virtual int colorsCount() { return getPaletteSize(); }
90 
102  void setProcessPrimitivesOnBlank(bool value) { m_processPrimitivesOnBlank = value; }
103 
104  // returns "static" version of m_viewPort
105  static uint8_t * sgetScanline(int y) { return (uint8_t*) s_viewPort[y]; }
106 
107  // abstract method of BitmappedDisplayController
108  NativePixelFormat nativePixelFormat() { return m_nativePixelFormat; }
109 
110 
111 protected:
112 
113  void init();
114 
115  virtual void setupDefaultPalette() = 0;
116 
117  void updateRGB2PaletteLUT();
118  void calculateAvailableCyclesForDrawings();
119  static void primitiveExecTask(void * arg);
120 
121  uint8_t RGB888toPaletteIndex(RGB888 const & rgb) {
122  return m_packedRGB222_to_PaletteIndex[RGB888toPackedRGB222(rgb)];
123  }
124 
125  uint8_t RGB2222toPaletteIndex(uint8_t value) {
126  return m_packedRGB222_to_PaletteIndex[value & 0b00111111];
127  }
128 
129  uint8_t RGB8888toPaletteIndex(RGBA8888 value) {
130  return RGB888toPaletteIndex(RGB888(value.R, value.G, value.B));
131  }
132 
133  // abstract method of BitmappedDisplayController
134  void swapBuffers();
135 
136 
137  TaskHandle_t m_primitiveExecTask;
138 
139  volatile uint8_t * * m_lines;
140 
141  // optimization: clones of m_viewPort and m_viewPortVisible
142  static volatile uint8_t * * s_viewPort;
143  static volatile uint8_t * * s_viewPortVisible;
144 
145  static lldesc_t volatile * s_frameResetDesc;
146 
147  static volatile int s_scanLine;
148 
149  RGB222 * m_palette;
150 
151 
152 private:
153 
154  void allocateViewPort();
155  void freeViewPort();
156  void checkViewPortSize();
157  void onSetupDMABuffer(lldesc_t volatile * buffer, bool isStartOfVertFrontPorch, int scan, bool isVisible, int visibleRow);
158 
159  // Maximum time (in CPU cycles) available for primitives drawing
160  volatile uint32_t m_primitiveExecTimeoutCycles;
161 
162  volatile bool m_taskProcessingPrimitives;
163 
164  // true = allowed time to process primitives is limited to the vertical blank. Slow, but avoid flickering
165  // false = allowed time is the half of an entire frame. Fast, but may flick
166  bool m_processPrimitivesOnBlank;
167 
168  uint8_t m_packedRGB222_to_PaletteIndex[64];
169 
170  // configuration
171  int m_linesCount; // viewport height must be divisible by m_linesCount
172  int m_columnsQuantum; // viewport width must be divisble by m_columnsQuantum
173  NativePixelFormat m_nativePixelFormat;
174  int m_viewPortRatioDiv;
175  int m_viewPortRatioMul;
176  intr_handler_t m_isrHandler;
177 
178 
179 };
180 
181 
182 
183 } // end of namespace
184 
185 
186 
187 
188 
189 
190 
191 
Represents a 24 bit RGB color.
NativePixelFormat nativePixelFormat()
Represents the native pixel format used by this display.
This file contains fabgl::VGABaseController definition.
This file contains fabgl::GPIOStream definition.
This file contains fabgl::BitmappedDisplayController definition.
void suspendBackgroundPrimitiveExecution()
Suspends drawings.
Specifies the VGA timings. This is a modeline decoded.
void setProcessPrimitivesOnBlank(bool value)
Determines the maximum time allowed to process primitives.
This file contains some utility classes and functions.
Definition: canvas.cpp:36
virtual int colorsCount()
Determines number of colors this display can provide.
NativePixelFormat
This enum defines the display controller native pixel format.
This file contains FabGL library configuration settings, like number of supported colors...
Represents the base class for paletted bitmapped controllers like VGA16Controller, VGA8Controller, etc..