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