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