CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/headless/HeadlessHost.h
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include "Common/CommonTypes.h"
21
#include "Common/File/Path.h"
22
23
#include "Core/CoreParameter.h"
24
25
class HeadlessHost {
26
public:
27
virtual ~HeadlessHost() {}
28
virtual bool InitGraphics(std::string *error_message, GraphicsContext **ctx, GPUCore core) {return false;}
29
virtual void ShutdownGraphics() {}
30
31
virtual void SendDebugOutput(const std::string &output) {
32
if (!writeDebugOutput_)
33
return;
34
if (output.find('\n') != output.npos) {
35
FlushDebugOutput();
36
fwrite(output.data(), sizeof(char), output.length(), stdout);
37
} else {
38
debugOutputBuffer_ += output;
39
}
40
}
41
void FlushDebugOutput() {
42
if (!debugOutputBuffer_.empty()) {
43
fwrite(debugOutputBuffer_.data(), sizeof(char), debugOutputBuffer_.length(), stdout);
44
debugOutputBuffer_.clear();
45
}
46
}
47
48
void SetWriteDebugOutput(bool flag) {
49
writeDebugOutput_ = flag;
50
}
51
52
void SetComparisonScreenshot(const Path &filename, double maxError) {
53
comparisonScreenshot_ = filename;
54
maxScreenshotError_ = maxError;
55
}
56
void SetWriteFailureScreenshot(bool flag) {
57
writeFailureScreenshot_ = flag;
58
}
59
60
void SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h);
61
62
virtual void SwapBuffers() {}
63
64
protected:
65
void SendAndCollectOutput(const std::string &output);
66
67
Path comparisonScreenshot_;
68
double maxScreenshotError_ = 0.0;
69
std::string debugOutputBuffer_;
70
GPUCore gpuCore_;
71
GraphicsContext *gfx_ = nullptr;
72
bool writeFailureScreenshot_ = true;
73
bool writeDebugOutput_ = true;
74
};
75
76