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-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 #if FABGLIB_VGAXCONTROLLER_PERFORMANCE_CHECK
58  extern volatile uint64_t s_vgapalctrlcycles;
59 #endif
60 
61 
62 
66 class VGAPalettedController : public VGABaseController {
67 
68 public:
69 
70  VGAPalettedController(int linesCount, 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 
100  void setProcessPrimitivesOnBlank(bool value) { m_processPrimitivesOnBlank = value; }
101 
102  // returns "static" version of m_viewPort
103  static uint8_t * sgetScanline(int y) { return (uint8_t*) s_viewPort[y]; }
104 
105  // abstract method of BitmappedDisplayController
106  NativePixelFormat nativePixelFormat() { return m_nativePixelFormat; }
107 
108 
109 protected:
110 
111  void init();
112 
113  virtual void setupDefaultPalette() = 0;
114 
115  void updateRGB2PaletteLUT();
116  void calculateAvailableCyclesForDrawings();
117  static void primitiveExecTask(void * arg);
118 
119  uint8_t RGB888toPaletteIndex(RGB888 const & rgb) {
120  return m_packedRGB222_to_PaletteIndex[RGB888toPackedRGB222(rgb)];
121  }
122 
123  uint8_t RGB2222toPaletteIndex(uint8_t value) {
124  return m_packedRGB222_to_PaletteIndex[value & 0b00111111];
125  }
126 
127  uint8_t RGB8888toPaletteIndex(RGBA8888 value) {
128  return RGB888toPaletteIndex(RGB888(value.R, value.G, value.B));
129  }
130 
131  // abstract method of BitmappedDisplayController
132  void swapBuffers();
133 
134 
135  TaskHandle_t m_primitiveExecTask;
136 
137  volatile uint8_t * * m_lines;
138 
139  // optimization: clones of m_viewPort and m_viewPortVisible
140  static volatile uint8_t * * s_viewPort;
141  static volatile uint8_t * * s_viewPortVisible;
142 
143  static lldesc_t volatile * s_frameResetDesc;
144 
145  static volatile int s_scanLine;
146 
147  RGB222 * m_palette;
148 
149 
150 private:
151 
152  void allocateViewPort();
153  void freeViewPort();
154  void checkViewPortSize();
155  void onSetupDMABuffer(lldesc_t volatile * buffer, bool isStartOfVertFrontPorch, int scan, bool isVisible, int visibleRow);
156 
157  // Maximum time (in CPU cycles) available for primitives drawing
158  volatile uint32_t m_primitiveExecTimeoutCycles;
159 
160  volatile bool m_taskProcessingPrimitives;
161 
162  // true = allowed time to process primitives is limited to the vertical blank. Slow, but avoid flickering
163  // false = allowed time is the half of an entire frame. Fast, but may flick
164  bool m_processPrimitivesOnBlank;
165 
166  uint8_t m_packedRGB222_to_PaletteIndex[64];
167 
168  // configuration
169  int m_linesCount;
170  NativePixelFormat m_nativePixelFormat;
171  int m_viewPortRatioDiv;
172  int m_viewPortRatioMul;
173  intr_handler_t m_isrHandler;
174 
175 
176 };
177 
178 
179 
180 } // end of namespace
181 
182 
183 
184 
185 
186 
187 
188 
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:31
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..