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.cpp
Views: 1401
1
// Copyright (c) 2017- 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
#include "Common/File/FileUtil.h"
19
#include "Common/Log.h"
20
#include "Common/StringUtils.h"
21
#include "Core/CoreParameter.h"
22
#include "Core/System.h"
23
#include "GPU/Common/GPUDebugInterface.h"
24
#include "headless/Compare.h"
25
#include "headless/HeadlessHost.h"
26
27
void HeadlessHost::SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h) {
28
// Only if we're actually comparing.
29
if (comparisonScreenshot_.empty()) {
30
return;
31
}
32
33
// We ignore the current framebuffer parameters and just grab the full screen.
34
const static u32 FRAME_STRIDE = 512;
35
const static u32 FRAME_WIDTH = 480;
36
const static u32 FRAME_HEIGHT = 272;
37
38
GPUDebugBuffer buffer;
39
gpuDebug->GetCurrentFramebuffer(buffer, GPU_DBG_FRAMEBUF_DISPLAY);
40
const std::vector<u32> pixels = TranslateDebugBufferToCompare(&buffer, 512, 272);
41
42
ScreenshotComparer comparer(pixels, FRAME_STRIDE, FRAME_WIDTH, FRAME_HEIGHT);
43
double errors = comparer.Compare(comparisonScreenshot_);
44
if (errors < 0)
45
SendAndCollectOutput(comparer.GetError() + "\n");
46
47
if (errors > maxScreenshotError_)
48
SendAndCollectOutput(StringFromFormat("Screenshot MSE: %f\n", errors));
49
50
if (errors > maxScreenshotError_ && writeFailureScreenshot_) {
51
if (comparer.SaveActualBitmap(Path("__testfailure.bmp")))
52
SendAndCollectOutput("Actual output written to: __testfailure.bmp\n");
53
comparer.SaveVisualComparisonPNG(Path("__testcompare.png"));
54
}
55
}
56
57
void HeadlessHost::SendAndCollectOutput(const std::string &output) {
58
SendDebugOutput(output);
59
if (PSP_CoreParameter().collectDebugOutput)
60
*PSP_CoreParameter().collectDebugOutput += output;
61
}
62
63