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
20#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
22#endif
23
24#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
25#include <ft2build.h>
26#include FT_FREETYPE_H
27#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
28#if !__has_include(<fontconfig/fontconfig.h>)
29#undef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
30#else
31#include <fontconfig/fontconfig.h>
32#endif
33#endif
34#endif
35
36#include "GPUDisplay.h"
37#include "GPULogging.h"
38#include <string>
39
40using namespace o2::gpu;
41
44
46{
47#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
48 if (strcmp(type, "vulkan") == 0 || strcmp(type, "auto") == 0) {
49 return new GPUDisplayBackendVulkan;
50 } else
51#endif
52 if (strcmp(type, "opengl") == 0 || strcmp(type, "auto") == 0) {
53 return new GPUDisplayBackendOpenGL;
54 } else if (strcmp(type, "none") == 0) {
55 return new GPUDisplayBackendNone;
56 } else {
57 GPUError("Requested renderer not available");
58 }
59 return nullptr;
60}
61
63{
64 int32_t retVal = InitBackendA();
65 if (retVal) {
66 return retVal;
67 }
68 if (mDisplay->cfg().noFreetype) {
69 return retVal;
70 }
71 std::string fontName = mDisplay->cfg().font;
72#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
73 FcInit();
74 FcConfig* config = FcInitLoadConfigAndFonts();
75 FcPattern* pat = FcNameParse((const FcChar8*)fontName.c_str());
76 FcConfigSubstitute(config, pat, FcMatchPattern);
77 FcDefaultSubstitute(pat);
78 FcResult result;
79 FcPattern* font = FcFontMatch(config, pat, &result);
80 if (font && result == 0) {
81 FcChar8* file = nullptr;
82 if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
83 fontName = (char*)file;
84 }
85 } else {
86 GPUError("Coult not find font for pattern %s", fontName.c_str());
87 }
88 FcPatternDestroy(font);
89 FcPatternDestroy(pat);
90 FcConfigDestroy(config);
91 FcFini();
92#endif // GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
93
94#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
95 FT_Library ft;
96 FT_Face face;
97 if (FT_Init_FreeType(&ft)) {
98 GPUError("Error initializing freetype");
99 return 0;
100 }
101 if (FT_New_Face(ft, fontName.c_str(), 0, &face)) {
102 GPUError("Error loading freetypoe font");
103 return 0;
104 }
105
106 int32_t fontSize = mDisplay->cfg().fontSize;
108 if (smoothFont()) {
109 fontSize *= 4; // Font size scaled by 4, can be downsampled
110 }
111 FT_Set_Pixel_Sizes(face, 0, fontSize);
112
113 for (uint32_t i = 0; i < 128; i++) {
114 if (FT_Load_Char(face, i, FT_LOAD_RENDER)) {
115 GPUError("Error loading freetype symbol");
116 return 0;
117 }
118 const auto& glyph = face->glyph;
119 addFontSymbol(i, glyph->bitmap.width, glyph->bitmap.rows, glyph->bitmap_left, glyph->bitmap_top, glyph->advance.x, glyph->bitmap.buffer);
120 }
122 FT_Done_Face(face);
123 FT_Done_FreeType(ft);
125#endif // GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
126 return retVal;
127}
128
133
135{
136 auto retVal = std::move(mScreenshotPixels);
137 mScreenshotPixels = std::vector<char>();
138 return retVal;
139}
140
142{
143 mCmdBuffer.clear();
145 // TODO: Check if this can be parallelized
146 for (int32_t iSector = 0; iSector < GPUCA_NSECTORS; iSector++) {
147 mIndirectSectorOffset[iSector] = mCmdBuffer.size();
148 for (uint32_t k = 0; k < mDisplay->vertexBufferStart()[iSector].size(); k++) {
149 mCmdBuffer.emplace_back(mDisplay->vertexBufferCount()[iSector][k], 1, mDisplay->vertexBufferStart()[iSector][k], 0);
150 }
151 }
152}
153
155{
156 float factor = 1.0f;
157 int32_t fsaa = mDisplay->cfgR().drawQualityDownsampleFSAA;
158 int32_t screenshotScale = mDisplay->cfgR().screenshotScaleFactor;
159 if (fsaa) {
160 factor *= fsaa;
161 }
162 if (screenshotScale && screenshot) {
163 factor *= screenshotScale;
164 }
165 return factor;
166}
167
169{
170 return mDisplay->cfg().smoothFont < 0 ? (mDisplay->cfg().fontSize > 12) : mDisplay->cfg().smoothFont;
171}
int32_t i
int32_t retVal
#define GPUCA_NSECTORS
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()
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)
const GPUSettingsDisplayRenderer & cfgR() const
Definition GPUDisplay.h:62
int32_t & drawTextFontSize()
Definition GPUDisplay.h:81
const vecpod< uint32_t > * vertexBufferCount() const
Definition GPUDisplay.h:71
const GPUSettingsDisplay & cfg() const
Definition GPUDisplay.h:65
vecpod< int32_t > * vertexBufferStart()
Definition GPUDisplay.h:70
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