Hash :
2f3e4db8
Author :
Date :
2021-09-02T10:31:13
Capture/Replay: Serialize trace metadata to a JSON file. This will allow us to remove more code auto-generation for the trace tests. The trace info now can be loaded directly from JSON instead of from the autogenerated information. Bug: angleproject:5133 Change-Id: I04e22b9279b19282df274bc8defcd363d0449111 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3140218 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// frame_capture_test_utils:
// Helper functions for capture and replay of traces.
//
#include "frame_capture_test_utils.h"
#include "common/string_utils.h"
#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
#include <fstream>
namespace angle
{
namespace
{
bool LoadJSONFromFile(const std::string &fileName, rapidjson::Document *doc)
{
std::ifstream ifs(fileName);
if (!ifs.is_open())
{
return false;
}
rapidjson::IStreamWrapper inWrapper(ifs);
doc->ParseStream(inWrapper);
return !doc->HasParseError();
}
} // namespace
bool LoadTraceNamesFromJSON(const std::string jsonFilePath, std::vector<std::string> *namesOut)
{
rapidjson::Document doc;
if (!LoadJSONFromFile(jsonFilePath, &doc))
{
return false;
}
if (!doc.IsObject() || !doc.HasMember("traces") || !doc["traces"].IsArray())
{
return false;
}
// Read trace json into a list of trace names.
std::vector<std::string> traces;
rapidjson::Document::Array traceArray = doc["traces"].GetArray();
for (rapidjson::SizeType arrayIndex = 0; arrayIndex < traceArray.Size(); ++arrayIndex)
{
const rapidjson::Document::ValueType &arrayElement = traceArray[arrayIndex];
if (!arrayElement.IsString())
{
return false;
}
std::vector<std::string> traceAndVersion;
angle::SplitStringAlongWhitespace(arrayElement.GetString(), &traceAndVersion);
traces.push_back(traceAndVersion[0]);
}
*namesOut = std::move(traces);
return true;
}
bool LoadTraceInfoFromJSON(const std::string &traceName,
const std::string &traceJsonPath,
TraceInfo *traceInfoOut)
{
rapidjson::Document doc;
if (!LoadJSONFromFile(traceJsonPath, &doc))
{
return false;
}
if (!doc.IsObject() || !doc.HasMember("TraceMetadata"))
{
return false;
}
const rapidjson::Document::Object &meta = doc["TraceMetadata"].GetObject();
strncpy(traceInfoOut->name, traceName.c_str(), kTraceInfoMaxNameLen);
traceInfoOut->contextClientMajorVersion = meta["ContextClientMajorVersion"].GetInt();
traceInfoOut->contextClientMinorVersion = meta["ContextClientMinorVersion"].GetInt();
traceInfoOut->frameEnd = meta["FrameEnd"].GetInt();
traceInfoOut->frameStart = meta["FrameStart"].GetInt();
traceInfoOut->drawSurfaceHeight = meta["DrawSurfaceHeight"].GetInt();
traceInfoOut->drawSurfaceWidth = meta["DrawSurfaceWidth"].GetInt();
traceInfoOut->drawSurfaceColorSpace = meta["DrawSurfaceColorSpace"].GetInt();
traceInfoOut->displayPlatformType = meta["DisplayPlatformType"].GetInt();
traceInfoOut->displayDeviceType = meta["DisplayDeviceType"].GetInt();
traceInfoOut->configRedBits = meta["ConfigRedBits"].GetInt();
traceInfoOut->configGreenBits = meta["ConfigGreenBits"].GetInt();
traceInfoOut->configBlueBits = meta["ConfigBlueBits"].GetInt();
traceInfoOut->configAlphaBits = meta["ConfigAlphaBits"].GetInt();
traceInfoOut->configDepthBits = meta["ConfigDepthBits"].GetInt();
traceInfoOut->configStencilBits = meta["ConfigStencilBits"].GetInt();
traceInfoOut->isBinaryDataCompressed = meta["IsBinaryDataCompressed"].GetBool();
traceInfoOut->areClientArraysEnabled = meta["AreClientArraysEnabled"].GetBool();
traceInfoOut->isBindGeneratesResourcesEnabled =
meta["IsBindGeneratesResourcesEnabled"].GetBool();
traceInfoOut->isWebGLCompatibilityEnabled = meta["IsWebGLCompatibilityEnabled"].GetBool();
traceInfoOut->isRobustResourceInitEnabled = meta["IsRobustResourceInitEnabled"].GetBool();
return true;
}
} // namespace angle