Project
Loading...
Searching...
No Matches
GPUDisplayHelpers.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 "GPUDisplay.h"
16#include "GPUChainTracking.h"
17#include "GPULogging.h"
18#include "GPUParam.h"
19
20#ifndef _WIN32
21#include "bitmapfile.h"
22#endif
23
24#include "oneapi/tbb.h"
25
26using namespace o2::gpu;
27
28int32_t GPUDisplay::getNumThreads()
29{
30 if (mChain) {
31 return mChain->GetProcessingSettings().nHostThreads;
32 } else {
33 return tbb::info::default_concurrency();
34 }
35}
36
37void GPUDisplay::updateOptions()
38{
39 if (mCfgH.splitCETracks == -1 && mParam) {
40 mCfgH.splitCETracks = mParam->continuousMaxTimeBin != 0;
41 }
42}
43
44void GPUDisplay::disableUnsupportedOptions()
45{
46 if (!mIOPtrs->mergedTrackHitAttachment) {
47 mCfgH.markAdjacentClusters = 0;
48 }
49 if (!mQA) {
50 mCfgH.markFakeClusters = 0;
51 }
52 if (!mChain) {
53 mCfgL.excludeClusters = mCfgL.drawInitLinks = mCfgL.drawLinks = mCfgL.drawSeeds = mCfgL.drawTracklets = mCfgL.drawTracks = mCfgL.drawExtrapolatedTracks = 0;
54 }
55 if (mConfig.showTPCTracksFromO2Format && mParam->par.earlyTpcTransform) {
56 throw std::runtime_error("Cannot run GPU display with early Transform when input is O2 tracks");
57 }
58}
59
60void GPUDisplay::DoScreenshot(const char* filename, std::vector<char>& pixels, float animateTime)
61{
62 size_t screenshot_x = mBackend->mScreenWidth * mCfgR.screenshotScaleFactor;
63 size_t screenshot_y = mBackend->mScreenHeight * mCfgR.screenshotScaleFactor;
64 size_t size = 4 * screenshot_x * screenshot_y;
65 if (size != pixels.size()) {
66 GPUError("Pixel array of incorrect size obtained");
67 filename = nullptr;
68 }
69
70 if (filename) {
71 FILE* fp = fopen(filename, "w+b");
72 if (fp == nullptr) {
73 GPUError("Error opening screenshot file %s", filename);
74 return;
75 }
76
77 BITMAPFILEHEADER bmpFH;
78 BITMAPINFOHEADER bmpIH;
79 memset(&bmpFH, 0, sizeof(bmpFH));
80 memset(&bmpIH, 0, sizeof(bmpIH));
81
82 bmpFH.bfType = 19778; //"BM"
83 bmpFH.bfSize = sizeof(bmpFH) + sizeof(bmpIH) + size;
84 bmpFH.bfOffBits = sizeof(bmpFH) + sizeof(bmpIH);
85
86 bmpIH.biSize = sizeof(bmpIH);
87 bmpIH.biWidth = screenshot_x;
88 bmpIH.biHeight = screenshot_y;
89 bmpIH.biPlanes = 1;
90 bmpIH.biBitCount = 32;
91 bmpIH.biCompression = BI_RGB;
92 bmpIH.biSizeImage = size;
93 bmpIH.biXPelsPerMeter = 5670;
94 bmpIH.biYPelsPerMeter = 5670;
95
96 fwrite(&bmpFH, 1, sizeof(bmpFH), fp);
97 fwrite(&bmpIH, 1, sizeof(bmpIH), fp);
98 fwrite(pixels.data(), 1, size, fp);
99 fclose(fp);
100 }
101}
102
103void GPUDisplay::showInfo(const char* info)
104{
105 mBackend->prepareText();
106 float colorValue = mCfgL.invertColors ? 0.f : 1.f;
107 OpenGLPrint(info, 40.f, 20.f + std::max(20, mDrawTextFontSize + 4), colorValue, colorValue, colorValue, 1);
108 if (mInfoText2Timer.IsRunning()) {
109 if (mInfoText2Timer.GetCurrentElapsedTime() >= 6) {
110 mInfoText2Timer.Reset();
111 } else {
112 OpenGLPrint(mInfoText2, 40.f, 20.f, colorValue, colorValue, colorValue, 6 - mInfoText2Timer.GetCurrentElapsedTime());
113 }
114 }
115 if (mInfoHelpTimer.IsRunning() || mPrintInfoTextAlways) {
116 if (mInfoHelpTimer.GetCurrentElapsedTime() >= 6) {
117 mInfoHelpTimer.Reset();
118 } else {
119 PrintGLHelpText(colorValue);
120 }
121 }
122 mBackend->finishText();
123}
124
125void GPUDisplay::OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton)
126{
127 if (mBackend->mFreetypeInitialized) {
128 if (!fromBotton) {
129 y = mBackend->mScreenHeight - y;
130 }
131 float color[4] = {r, g, b, a};
132 mBackend->OpenGLPrint(s, x, y, color, 1.0f);
133 } else if (mFrontend->mCanDrawText) {
134 mFrontend->OpenGLPrint(s, x, y, r, g, b, a, fromBotton);
135 }
136}
@ BI_RGB
Definition bitmapfile.h:36
void Reset()
Definition timer.cxx:101
double GetCurrentElapsedTime(bool reset=false)
Definition timer.cxx:110
int32_t IsRunning()
Definition timer.h:33
const GPUSettingsProcessing & GetProcessingSettings() const
Definition GPUChain.h:75
virtual void OpenGLPrint(const char *s, float x, float y, float r, float g, float b, float a, bool fromBotton=true)=0
GLint GLenum GLint x
Definition glcorearb.h:403
GLsizeiptr size
Definition glcorearb.h:659
GLuint color
Definition glcorearb.h:1272
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLboolean GLboolean g
Definition glcorearb.h:1233
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition glcorearb.h:275
GLboolean r
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
std::string filename()
uint32_t bfSize
Definition bitmapfile.h:17
uint32_t bfOffBits
Definition bitmapfile.h:19
uint16_t bfType
Definition bitmapfile.h:16
uint32_t biWidth
Definition bitmapfile.h:24
uint32_t biSize
Definition bitmapfile.h:23
uint32_t biSizeImage
Definition bitmapfile.h:29
uint32_t biCompression
Definition bitmapfile.h:28
uint16_t biBitCount
Definition bitmapfile.h:27
uint16_t biPlanes
Definition bitmapfile.h:26
uint32_t biHeight
Definition bitmapfile.h:25
uint32_t biXPelsPerMeter
Definition bitmapfile.h:30
uint32_t biYPelsPerMeter
Definition bitmapfile.h:31
const uint32_t * mergedTrackHitAttachment