Commit 67e4aff5 by Jamie Madill Committed by Commit Bot

Fix rapidjson build error in Skia.

Instead of using defines in the header, use the same approach as we do with frame capture by defining a stub "mock" cpp file. Bug: angleproject:5805 Change-Id: Ief1cb6497ddafc9656bb0e7d6a921eff3610a7fb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2801695Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 88b91df1
......@@ -862,7 +862,10 @@ config("angle_frame_capture_enabled") {
angle_source_set("libANGLE") {
public_deps = [ ":libANGLE_base" ]
public_configs = [ ":angle_frame_capture_disabled" ]
sources = [ "src/libANGLE/capture/FrameCapture_mock.cpp" ]
sources = [
"src/libANGLE/capture/FrameCapture_mock.cpp",
"src/libANGLE/capture/frame_capture_utils_mock.cpp",
]
# gl_enum_utils defaults included in with_capture build
deps = []
......@@ -921,32 +924,35 @@ group("angle_compression") {
[ "$angle_zlib_compression_utils_dir:compression_utils_portable" ]
}
angle_source_set("libjson_serializer") {
sources = [ "src/libANGLE/serializer/JsonSerializer.h" ]
if (angle_has_build) {
defines = [ "ANGLE_HAVE_RAPIDJSON" ]
sources += [ "src/libANGLE/serializer/JsonSerializer.cpp" ]
if (angle_has_build) {
config("angle_rapidjson_config") {
defines = [ "ANGLE_HAS_RAPIDJSON" ]
}
angle_source_set("angle_json_serializer") {
public_deps = [
":libANGLE_base",
"$angle_root/third_party/rapidjson",
]
sources = [
"src/libANGLE/serializer/JsonSerializer.cpp",
"src/libANGLE/serializer/JsonSerializer.h",
]
public_configs = [ ":angle_rapidjson_config" ]
}
public_deps = [
":libANGLE_base",
"$angle_root/third_party/rapidjson",
]
}
angle_source_set("libANGLE_with_capture") {
if (angle_has_build) {
defines = [ "ANGLE_HAVE_RAPIDJSON" ]
}
public_deps = [
":libANGLE_base",
":libjson_serializer",
]
public_deps = [ ":libANGLE_base" ]
deps = [ ":angle_compression" ]
public_configs = [ ":angle_frame_capture_enabled" ]
sources = libangle_capture_sources
if (angle_has_build) {
public_deps += [ ":angle_json_serializer" ]
sources += [ "src/libANGLE/capture/frame_capture_utils.cpp" ]
} else {
sources += [ "src/libANGLE/capture/frame_capture_utils_mock.cpp" ]
}
}
config("shared_library_public_config") {
......
......@@ -39,13 +39,12 @@
#include "libANGLE/capture/gl_enum_utils.h"
#include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h"
#include "libANGLE/serializer/JsonSerializer.h"
#define USE_SYSTEM_ZLIB
#include "compression_utils_portable.h"
#if !ANGLE_CAPTURE_ENABLED
# error Frame capture must be enbled to include this file.
# error Frame capture must be enabled to include this file.
#endif // !ANGLE_CAPTURE_ENABLED
namespace angle
......@@ -1076,14 +1075,14 @@ void WriteCppReplay(bool compression,
if (serializeStateEnabled)
{
angle::JsonSerializer serializedContextData;
if (SerializeContext(&serializedContextData, const_cast<gl::Context *>(context)) ==
Result::Continue)
std::string serializedContextString;
if (SerializeContextToString(const_cast<gl::Context *>(context),
&serializedContextString) == Result::Continue)
{
out << "const char *" << FmtGetSerializedContextStateFunction(context->id(), frameIndex)
<< "\n";
out << "{\n";
out << " return R\"(" << serializedContextData.data() << ")\";\n";
out << " return R\"(" << serializedContextString << ")\";\n";
out << "}\n";
out << "\n";
}
......
......@@ -31,6 +31,10 @@
#include "libANGLE/renderer/RenderbufferImpl.h"
#include "libANGLE/serializer/JsonSerializer.h"
#if !ANGLE_CAPTURE_ENABLED
# error Frame capture must be enabled to build this file.
#endif // !ANGLE_CAPTURE_ENABLED
// Note: when diagnosing serialization comparison failures, you can disable the unused function
// compiler warning to allow bisecting the comparison function. One first check is to disable
// Framebuffer Attachment pixel comparison which includes the pixel contents of the default FBO.
......@@ -588,7 +592,7 @@ void SerializeImageUnit(JsonSerializer *json, const gl::ImageUnit &imageUnit)
json->addScalar("Texid", imageUnit.texture.id().value);
}
void SerializeGLContextStates(JsonSerializer *json, const gl::State &state)
void SerializeContextState(JsonSerializer *json, const gl::State &state)
{
GroupScope group(json, "ContextStates");
json->addScalar("ClientType", state.getClientType());
......@@ -1250,37 +1254,38 @@ void SerializeVertexArray(JsonSerializer *json, gl::VertexArray *vertexArray)
} // namespace
Result SerializeContext(JsonSerializer *json, const gl::Context *context)
Result SerializeContextToString(const gl::Context *context, std::string *stringOut)
{
json->startDocument("Context");
JsonSerializer json;
json.startDocument("Context");
SerializeGLContextStates(json, context->getState());
SerializeContextState(&json, context->getState());
ScratchBuffer scratchBuffer(1);
const gl::FramebufferManager &framebufferManager =
context->getState().getFramebufferManagerForCapture();
for (const auto &framebuffer : framebufferManager)
{
gl::Framebuffer *framebufferPtr = framebuffer.second;
ANGLE_TRY(SerializeFramebuffer(context, json, &scratchBuffer, framebufferPtr));
ANGLE_TRY(SerializeFramebuffer(context, &json, &scratchBuffer, framebufferPtr));
}
const gl::BufferManager &bufferManager = context->getState().getBufferManagerForCapture();
for (const auto &buffer : bufferManager)
{
gl::Buffer *bufferPtr = buffer.second;
ANGLE_TRY(SerializeBuffer(context, json, &scratchBuffer, bufferPtr));
ANGLE_TRY(SerializeBuffer(context, &json, &scratchBuffer, bufferPtr));
}
const gl::SamplerManager &samplerManager = context->getState().getSamplerManagerForCapture();
for (const auto &sampler : samplerManager)
{
gl::Sampler *samplerPtr = sampler.second;
SerializeSampler(json, samplerPtr);
SerializeSampler(&json, samplerPtr);
}
const gl::RenderbufferManager &renderbufferManager =
context->getState().getRenderbufferManagerForCapture();
for (const auto &renderbuffer : renderbufferManager)
{
gl::Renderbuffer *renderbufferPtr = renderbuffer.second;
ANGLE_TRY(SerializeRenderbuffer(context, json, &scratchBuffer, renderbufferPtr));
ANGLE_TRY(SerializeRenderbuffer(context, &json, &scratchBuffer, renderbufferPtr));
}
const gl::ShaderProgramManager &shaderProgramManager =
context->getState().getShaderProgramManagerForCapture();
......@@ -1289,28 +1294,30 @@ Result SerializeContext(JsonSerializer *json, const gl::Context *context)
for (const auto &shader : shaderManager)
{
gl::Shader *shaderPtr = shader.second;
SerializeShader(json, shaderPtr);
SerializeShader(&json, shaderPtr);
}
const gl::ResourceMap<gl::Program, gl::ShaderProgramID> &programManager =
shaderProgramManager.getProgramsForCaptureAndPerf();
for (const auto &program : programManager)
{
gl::Program *programPtr = program.second;
SerializeProgram(json, programPtr);
SerializeProgram(&json, programPtr);
}
const gl::TextureManager &textureManager = context->getState().getTextureManagerForCapture();
for (const auto &texture : textureManager)
{
gl::Texture *texturePtr = texture.second;
ANGLE_TRY(SerializeTexture(context, json, &scratchBuffer, texturePtr));
ANGLE_TRY(SerializeTexture(context, &json, &scratchBuffer, texturePtr));
}
const gl::VertexArrayMap &vertexArrayMap = context->getVertexArraysForCapture();
for (auto &vertexArray : vertexArrayMap)
{
gl::VertexArray *vertexArrayPtr = vertexArray.second;
SerializeVertexArray(json, vertexArrayPtr);
SerializeVertexArray(&json, vertexArrayPtr);
}
json->endDocument();
json.endDocument();
*stringOut = json.data();
scratchBuffer.clear();
return Result::Continue;
......
......@@ -11,11 +11,6 @@
#include "libANGLE/Error.h"
namespace angle
{
class JsonSerializer;
} // namespace angle
namespace gl
{
class Context;
......@@ -23,6 +18,6 @@ class Context;
namespace angle
{
Result SerializeContext(JsonSerializer *bos, const gl::Context *context);
Result SerializeContextToString(const gl::Context *context, std::string *stringOut);
} // namespace angle
#endif // FRAME_CAPTURE_UTILS_H_
//
// 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_utils_mock.cpp:
// ANGLE frame capture util stub implementation.
//
#include "libANGLE/capture/frame_capture_utils.h"
namespace angle
{
Result SerializeContextToString(const gl::Context *context, std::string *stringOut)
{
*stringOut = "SerializationNotAvailable";
return angle::Result::Continue;
}
} // namespace angle
......@@ -11,13 +11,16 @@
#include "common/angleutils.h"
#if defined(ANGLE_HAVE_RAPIDJSON)
# include <rapidjson/document.h>
#if !defined(ANGLE_HAS_RAPIDJSON)
# error RapidJSON must be available to build this file.
#endif // !defined(ANGLE_HAVE_RAPIDJSON)
# include <memory>
# include <sstream>
# include <stack>
# include <type_traits>
#include <rapidjson/document.h>
#include <memory>
#include <sstream>
#include <stack>
#include <type_traits>
namespace angle
{
......@@ -99,46 +102,5 @@ class JsonSerializer : public angle::NonCopyable
};
} // namespace angle
#else
namespace angle
{
class JsonSerializer : public angle::NonCopyable
{
JsonSerializer() {}
~JsonSerializer() {}
void startDocument(const std::string &name) { (void)name; }
void endDocument() {}
void addCString(const std::string &name, const char *value) {}
void addString(const std::string &name, const std::string &value) {}
void addBlob(const std::string &name, const uint8_t *value, size_t length) {}
void startGroup(const std::string &name) { (void)name; }
void endGroup() {}
const char *data() const { return ""; }
std::vector<uint8_t> getData() const { return std::vector<uint8_t>(); }
size_t length() const { return 0; }
template <typename T>
void addScalar(const std::string &name, T value)
{}
template <typename T>
void addVector(const std::string &name, const std::vector<T> &value)
{}
};
} // namespace angle
#endif
#endif // JSONSERIALIZER_H
......@@ -440,6 +440,7 @@ libangle_sources += [
"src/libANGLE/capture/capture_gles_3_1_autogen.h",
"src/libANGLE/capture/capture_gles_3_2_autogen.h",
"src/libANGLE/capture/capture_gles_ext_autogen.h",
"src/libANGLE/capture/frame_capture_utils.h",
"src/libANGLE/capture/frame_capture_utils_autogen.h",
"src/libANGLE/capture/gl_enum_utils.h",
"src/libANGLE/capture/gl_enum_utils_autogen.h",
......@@ -460,8 +461,6 @@ libangle_capture_sources = [
"src/libANGLE/capture/capture_gles_ext_autogen.cpp",
"src/libANGLE/capture/capture_gles_ext_params.cpp",
"src/libANGLE/capture/frame_capture_replay_autogen.cpp",
"src/libANGLE/capture/frame_capture_utils.cpp",
"src/libANGLE/capture/frame_capture_utils.h",
"src/libANGLE/capture/frame_capture_utils_autogen.cpp",
"src/libANGLE/capture/gl_enum_utils.cpp",
"src/libANGLE/capture/gl_enum_utils_autogen.cpp",
......
......@@ -142,17 +142,13 @@ angle_test("angle_unittests") {
defines += [ "ANGLE_ENABLE_HLSL" ]
}
if (angle_has_build) {
defines += [ "ANGLE_HAS_RAPIDJSON" ]
}
deps = [
":angle_test_expectations",
"$angle_root:angle_json_serializer",
"$angle_root:libANGLE",
"$angle_root:libEGL_static",
"$angle_root:libGLESv2_static",
"$angle_root:libfeature_support",
"$angle_root:libjson_serializer",
"$angle_root:preprocessor",
"$angle_root:translator",
"$angle_root/util:angle_util_static",
......
......@@ -33,7 +33,6 @@ if (angle_build_capture_replay_tests) {
"$angle_root:angle_common",
"$angle_root:angle_compression",
"$angle_root:libEGL_with_capture_static",
"$angle_root:libjson_serializer",
"$angle_root/util:angle_util_static",
]
configs += [
......
......@@ -10,7 +10,6 @@
#include "common/system_utils.h"
#include "libANGLE/Context.h"
#include "libANGLE/capture/frame_capture_utils.h"
#include "libANGLE/serializer/JsonSerializer.h"
#include "util/EGLPlatformParameters.h"
#include "util/EGLWindow.h"
#include "util/OSWindow.h"
......@@ -131,13 +130,15 @@ class CaptureReplayTests
{
ReplayContextFrame(testIndex, frame);
gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext());
angle::JsonSerializer json;
if (angle::SerializeContext(&json, context) != angle::Result::Continue)
std::string serializedContextString;
if (angle::SerializeContextToString(context, &serializedContextString) !=
angle::Result::Continue)
{
cleanupTest();
return -1;
}
bool isEqual = compareSerializedContexts(testIndex, frame, json.data());
bool isEqual =
compareSerializedContexts(testIndex, frame, serializedContextString.c_str());
// Swap always to allow RenderDoc/other tools to capture frames.
swap();
if (!isEqual)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment