mirror of
https://github.com/utmapp/angle.git
synced 2026-12-01 22:13:25 -10:00
We're storing some enums in the per-trace JSON as decimal.
This makes them difficult to read, i.e.:
"DisplayDeviceType": 12810,
"DisplayPlatformType": 13392,
"DrawSurfaceColorSpace": 12425,
If we instead convert them to hex, they are much easier to
read and grep the source for.
"DisplayDeviceType": "0x320A",
"DisplayPlatformType": "0x3450",
"DrawSurfaceColorSpace": "0x3089",
Since JSON doesn't actually support hexadecimal values, this CL
stores them as strings.
Ideally we could take this a step farther and store the enum
directly in JSON, but we have no facilities for converting
a string back to an enum.
Bug: angleproject:5133
Bug: angleproject:6515
Change-Id: I7b5d4dc8958d43c611da1fe98887e089f3d855b2
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3204135
Reviewed-by: Jamie Madill <[email protected]>
Reviewed-by: Tim Van Patten <[email protected]>
Commit-Queue: Cody Northrop <[email protected]>
130 lines
4.5 KiB
C++
130 lines
4.5 KiB
C++
//
|
|
// 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();
|
|
|
|
// TODO(http://anglebug.com/5133): Drop the GetInt versions after trace update
|
|
if (meta["DrawSurfaceColorSpace"].IsString())
|
|
{
|
|
angle::HexStringToUInt(meta["DrawSurfaceColorSpace"].GetString(),
|
|
&traceInfoOut->drawSurfaceColorSpace);
|
|
angle::HexStringToUInt(meta["DisplayPlatformType"].GetString(),
|
|
&traceInfoOut->displayPlatformType);
|
|
angle::HexStringToUInt(meta["DisplayDeviceType"].GetString(),
|
|
&traceInfoOut->displayDeviceType);
|
|
}
|
|
else
|
|
{
|
|
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
|