Project
Loading...
Searching...
No Matches
GPUDisplayBackend.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include "GPUDisplayBackend.h"
17
19#ifdef GPUCA_BUILD_EVENT_DISPLAY_OPENGL
21#endif
22#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
24#endif
25
26#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
27#include <ft2build.h>
28#include FT_FREETYPE_H
29#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
30#if !__has_include(<fontconfig/fontconfig.h>)
31#undef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
32#else
33#include <fontconfig/fontconfig.h>
34#endif
35#endif
36#endif
37
38#include "GPUDisplay.h"
39#include "GPULogging.h"
40#include "GPUTPCGeometry.h"
41#include <string>
42
43using namespace o2::gpu;
44
47
49{
50#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
51 if (strcmp(type, "vulkan") == 0 || strcmp(type, "auto") == 0) {
52 return new GPUDisplayBackendVulkan;
53 } else
54#endif
55#ifdef GPUCA_BUILD_EVENT_DISPLAY_OPENGL
56 if (strcmp(type, "opengl") == 0 || strcmp(type, "auto") == 0) {
57 return new GPUDisplayBackendOpenGL;
58 } else
59#endif
60 if (strcmp(type, "none") == 0) {
61 return new GPUDisplayBackendNone;
62 } else {
63 GPUError("Requested renderer not available");
64 }
65 return nullptr;
66}
67
69{
70 int32_t retVal = InitBackendA();
71 if (retVal) {
72 return retVal;
73 }
74 if (!mDisplay->cfg().noFreetype) {
75 loadFont();
76 }
77 return retVal;
78}
79
81{
82 if (mFreetypeInitialized && scale != mFontRasterScale) {
85 loadFont();
86 }
87}
88
90{
91 std::string fontName = mDisplay->cfg().font;
92#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
93 FcInit();
94 FcConfig* config = FcInitLoadConfigAndFonts();
95 FcPattern* pat = FcNameParse((const FcChar8*)fontName.c_str());
96 FcConfigSubstitute(config, pat, FcMatchPattern);
97 FcDefaultSubstitute(pat);
98 FcResult result;
99 FcPattern* font = FcFontMatch(config, pat, &result);
100 if (font && result == 0) {
101 FcChar8* file = nullptr;
102 if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
103 fontName = (char*)file;
104 }
105 } else {
106 GPUError("Coult not find font for pattern %s", fontName.c_str());
107 }
108 FcPatternDestroy(font);
109 FcPatternDestroy(pat);
110 FcConfigDestroy(config);
111 FcFini();
112#endif // GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
113
114#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
115 FT_Library ft;
116 FT_Face face;
117 if (FT_Init_FreeType(&ft)) {
118 GPUError("Error initializing freetype");
119 return;
120 }
121 if (FT_New_Face(ft, fontName.c_str(), 0, &face)) {
122 GPUError("Error loading freetype font");
123 FT_Done_FreeType(ft);
124 return;
125 }
126
127 int32_t fontSize = mDisplay->cfg().fontSize;
129 if (smoothFont()) {
130 fontSize *= 4; // Font size scaled by 4, can be downsampled
131 }
133 FT_Set_Pixel_Sizes(face, 0, (uint32_t)(fontSize * mFontRasterScale + 0.5f)); // Rasterize at physical pixel size for HiDPI
134
135 for (uint32_t i = 0; i < 128; i++) {
136 if (FT_Load_Char(face, i, FT_LOAD_RENDER)) {
137 GPUError("Error loading freetype symbol");
138 FT_Done_Face(face);
139 FT_Done_FreeType(ft);
140 return;
141 }
142 const auto& glyph = face->glyph;
143 addFontSymbol(i, glyph->bitmap.width, glyph->bitmap.rows, glyph->bitmap_left, glyph->bitmap_top, glyph->advance.x, glyph->bitmap.buffer);
144 }
146 FT_Done_Face(face);
147 FT_Done_FreeType(ft);
149#endif // GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
150}
151
156
158{
159 auto retVal = std::move(mScreenshotPixels);
160 mScreenshotPixels = std::vector<char>();
161 return retVal;
162}
163
165{
166 mCmdBuffer.clear();
167 mIndirectSectorOffset.resize(GPUTPCGeometry::NSECTORS);
168 // TODO: Check if this can be parallelized
169 for (uint32_t iSector = 0; iSector < GPUTPCGeometry::NSECTORS; iSector++) {
171 for (uint32_t k = 0; k < mDisplay->vertexBufferStart()[iSector].size(); k++) {
173 }
174 }
175}
176
178{
179 const auto& cfg = mDisplay->cfgR();
180 if (cfg.fpsLimit == FPS_LIMIT_VSYNC) {
181 return !cfg.drawQualityVSync ? FPS_LIMIT_NONE : (canLimitToVSync() ? FPS_LIMIT_VSYNC : FPS_LIMIT_RATE);
182 }
183 return cfg.fpsLimit;
184}
185
187{
188 float factor = 1.0f;
189 int32_t fsaa = mDisplay->cfgR().drawQualityDownsampleFSAA;
190 int32_t screenshotScale = mDisplay->cfgR().screenshotScaleFactor;
191 if (fsaa) {
192 factor *= fsaa;
193 }
194 if (screenshotScale && screenshot) {
195 factor *= screenshotScale;
196 }
197 return factor;
198}
199
201{
202 return mDisplay->cfg().smoothFont < 0 ? (mDisplay->cfg().fontSize > 12) : mDisplay->cfg().smoothFont;
203}
int32_t i
uint32_t iSector
int32_t retVal
virtual void addFontSymbol(int32_t symbol, int32_t sizex, int32_t sizey, int32_t offsetx, int32_t offsety, int32_t advance, void *data)=0
std::vector< char > getPixels()
virtual bool canLimitToVSync() const
vecpod< DrawArraysIndirectCommand > mCmdBuffer
std::vector< int32_t > mIndirectSectorOffset
static GPUDisplayBackend * getBackend(const char *type)
std::vector< char > mScreenshotPixels
virtual void ExitBackendA()=0
virtual void initializeTextDrawing()=0
virtual int32_t InitBackendA()=0
float getDownsampleFactor(bool screenshot=false)
virtual float getDisplayScale() const
const GPUSettingsDisplayRenderer & cfgR() const
Definition GPUDisplay.h:68
int32_t & drawTextFontSize()
Definition GPUDisplay.h:87
GPUDisplayFrontend * frontend()
Definition GPUDisplay.h:85
const vecpod< uint32_t > * vertexBufferCount() const
Definition GPUDisplay.h:77
const GPUSettingsDisplay & cfg() const
Definition GPUDisplay.h:71
vecpod< int32_t > * vertexBufferStart()
Definition GPUDisplay.h:76
GLuint64EXT * result
Definition glcorearb.h:5662
GLsizeiptr size
Definition glcorearb.h:659
GLenum GLuint GLint GLenum face
Definition glcorearb.h:3184
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLenum GLsizeiptr fontSize
Definition glcorearb.h:5519
GLenum const void * fontName
Definition glcorearb.h:5473