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") { ...@@ -862,7 +862,10 @@ config("angle_frame_capture_enabled") {
angle_source_set("libANGLE") { angle_source_set("libANGLE") {
public_deps = [ ":libANGLE_base" ] public_deps = [ ":libANGLE_base" ]
public_configs = [ ":angle_frame_capture_disabled" ] 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 # gl_enum_utils defaults included in with_capture build
deps = [] deps = []
...@@ -921,32 +924,35 @@ group("angle_compression") { ...@@ -921,32 +924,35 @@ group("angle_compression") {
[ "$angle_zlib_compression_utils_dir:compression_utils_portable" ] [ "$angle_zlib_compression_utils_dir:compression_utils_portable" ]
} }
angle_source_set("libjson_serializer") { if (angle_has_build) {
sources = [ "src/libANGLE/serializer/JsonSerializer.h" ] config("angle_rapidjson_config") {
defines = [ "ANGLE_HAS_RAPIDJSON" ]
if (angle_has_build) { }
defines = [ "ANGLE_HAVE_RAPIDJSON" ] angle_source_set("angle_json_serializer") {
sources += [ "src/libANGLE/serializer/JsonSerializer.cpp" ] 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") { angle_source_set("libANGLE_with_capture") {
if (angle_has_build) { public_deps = [ ":libANGLE_base" ]
defines = [ "ANGLE_HAVE_RAPIDJSON" ]
}
public_deps = [
":libANGLE_base",
":libjson_serializer",
]
deps = [ ":angle_compression" ] deps = [ ":angle_compression" ]
public_configs = [ ":angle_frame_capture_enabled" ] public_configs = [ ":angle_frame_capture_enabled" ]
sources = libangle_capture_sources 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") { config("shared_library_public_config") {
......
...@@ -39,13 +39,12 @@ ...@@ -39,13 +39,12 @@
#include "libANGLE/capture/gl_enum_utils.h" #include "libANGLE/capture/gl_enum_utils.h"
#include "libANGLE/queryconversions.h" #include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h" #include "libANGLE/queryutils.h"
#include "libANGLE/serializer/JsonSerializer.h"
#define USE_SYSTEM_ZLIB #define USE_SYSTEM_ZLIB
#include "compression_utils_portable.h" #include "compression_utils_portable.h"
#if !ANGLE_CAPTURE_ENABLED #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 #endif // !ANGLE_CAPTURE_ENABLED
namespace angle namespace angle
...@@ -1076,14 +1075,14 @@ void WriteCppReplay(bool compression, ...@@ -1076,14 +1075,14 @@ void WriteCppReplay(bool compression,
if (serializeStateEnabled) if (serializeStateEnabled)
{ {
angle::JsonSerializer serializedContextData; std::string serializedContextString;
if (SerializeContext(&serializedContextData, const_cast<gl::Context *>(context)) == if (SerializeContextToString(const_cast<gl::Context *>(context),
Result::Continue) &serializedContextString) == Result::Continue)
{ {
out << "const char *" << FmtGetSerializedContextStateFunction(context->id(), frameIndex) out << "const char *" << FmtGetSerializedContextStateFunction(context->id(), frameIndex)
<< "\n"; << "\n";
out << "{\n"; out << "{\n";
out << " return R\"(" << serializedContextData.data() << ")\";\n"; out << " return R\"(" << serializedContextString << ")\";\n";
out << "}\n"; out << "}\n";
out << "\n"; out << "\n";
} }
......
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
#include "libANGLE/renderer/RenderbufferImpl.h" #include "libANGLE/renderer/RenderbufferImpl.h"
#include "libANGLE/serializer/JsonSerializer.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 // 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 // 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. // 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) ...@@ -588,7 +592,7 @@ void SerializeImageUnit(JsonSerializer *json, const gl::ImageUnit &imageUnit)
json->addScalar("Texid", imageUnit.texture.id().value); 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"); GroupScope group(json, "ContextStates");
json->addScalar("ClientType", state.getClientType()); json->addScalar("ClientType", state.getClientType());
...@@ -1250,37 +1254,38 @@ void SerializeVertexArray(JsonSerializer *json, gl::VertexArray *vertexArray) ...@@ -1250,37 +1254,38 @@ void SerializeVertexArray(JsonSerializer *json, gl::VertexArray *vertexArray)
} // namespace } // 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); ScratchBuffer scratchBuffer(1);
const gl::FramebufferManager &framebufferManager = const gl::FramebufferManager &framebufferManager =
context->getState().getFramebufferManagerForCapture(); context->getState().getFramebufferManagerForCapture();
for (const auto &framebuffer : framebufferManager) for (const auto &framebuffer : framebufferManager)
{ {
gl::Framebuffer *framebufferPtr = framebuffer.second; 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(); const gl::BufferManager &bufferManager = context->getState().getBufferManagerForCapture();
for (const auto &buffer : bufferManager) for (const auto &buffer : bufferManager)
{ {
gl::Buffer *bufferPtr = buffer.second; 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(); const gl::SamplerManager &samplerManager = context->getState().getSamplerManagerForCapture();
for (const auto &sampler : samplerManager) for (const auto &sampler : samplerManager)
{ {
gl::Sampler *samplerPtr = sampler.second; gl::Sampler *samplerPtr = sampler.second;
SerializeSampler(json, samplerPtr); SerializeSampler(&json, samplerPtr);
} }
const gl::RenderbufferManager &renderbufferManager = const gl::RenderbufferManager &renderbufferManager =
context->getState().getRenderbufferManagerForCapture(); context->getState().getRenderbufferManagerForCapture();
for (const auto &renderbuffer : renderbufferManager) for (const auto &renderbuffer : renderbufferManager)
{ {
gl::Renderbuffer *renderbufferPtr = renderbuffer.second; gl::Renderbuffer *renderbufferPtr = renderbuffer.second;
ANGLE_TRY(SerializeRenderbuffer(context, json, &scratchBuffer, renderbufferPtr)); ANGLE_TRY(SerializeRenderbuffer(context, &json, &scratchBuffer, renderbufferPtr));
} }
const gl::ShaderProgramManager &shaderProgramManager = const gl::ShaderProgramManager &shaderProgramManager =
context->getState().getShaderProgramManagerForCapture(); context->getState().getShaderProgramManagerForCapture();
...@@ -1289,28 +1294,30 @@ Result SerializeContext(JsonSerializer *json, const gl::Context *context) ...@@ -1289,28 +1294,30 @@ Result SerializeContext(JsonSerializer *json, const gl::Context *context)
for (const auto &shader : shaderManager) for (const auto &shader : shaderManager)
{ {
gl::Shader *shaderPtr = shader.second; gl::Shader *shaderPtr = shader.second;
SerializeShader(json, shaderPtr); SerializeShader(&json, shaderPtr);
} }
const gl::ResourceMap<gl::Program, gl::ShaderProgramID> &programManager = const gl::ResourceMap<gl::Program, gl::ShaderProgramID> &programManager =
shaderProgramManager.getProgramsForCaptureAndPerf(); shaderProgramManager.getProgramsForCaptureAndPerf();
for (const auto &program : programManager) for (const auto &program : programManager)
{ {
gl::Program *programPtr = program.second; gl::Program *programPtr = program.second;
SerializeProgram(json, programPtr); SerializeProgram(&json, programPtr);
} }
const gl::TextureManager &textureManager = context->getState().getTextureManagerForCapture(); const gl::TextureManager &textureManager = context->getState().getTextureManagerForCapture();
for (const auto &texture : textureManager) for (const auto &texture : textureManager)
{ {
gl::Texture *texturePtr = texture.second; 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(); const gl::VertexArrayMap &vertexArrayMap = context->getVertexArraysForCapture();
for (auto &vertexArray : vertexArrayMap) for (auto &vertexArray : vertexArrayMap)
{ {
gl::VertexArray *vertexArrayPtr = vertexArray.second; gl::VertexArray *vertexArrayPtr = vertexArray.second;
SerializeVertexArray(json, vertexArrayPtr); SerializeVertexArray(&json, vertexArrayPtr);
} }
json->endDocument(); json.endDocument();
*stringOut = json.data();
scratchBuffer.clear(); scratchBuffer.clear();
return Result::Continue; return Result::Continue;
......
...@@ -11,11 +11,6 @@ ...@@ -11,11 +11,6 @@
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
namespace angle
{
class JsonSerializer;
} // namespace angle
namespace gl namespace gl
{ {
class Context; class Context;
...@@ -23,6 +18,6 @@ class Context; ...@@ -23,6 +18,6 @@ class Context;
namespace angle namespace angle
{ {
Result SerializeContext(JsonSerializer *bos, const gl::Context *context); Result SerializeContextToString(const gl::Context *context, std::string *stringOut);
} // namespace angle } // namespace angle
#endif // FRAME_CAPTURE_UTILS_H_ #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 @@ ...@@ -11,13 +11,16 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#if defined(ANGLE_HAVE_RAPIDJSON) #if !defined(ANGLE_HAS_RAPIDJSON)
# include <rapidjson/document.h> # error RapidJSON must be available to build this file.
#endif // !defined(ANGLE_HAVE_RAPIDJSON)
# include <memory> #include <rapidjson/document.h>
# include <sstream>
# include <stack> #include <memory>
# include <type_traits> #include <sstream>
#include <stack>
#include <type_traits>
namespace angle namespace angle
{ {
...@@ -99,46 +102,5 @@ class JsonSerializer : public angle::NonCopyable ...@@ -99,46 +102,5 @@ class JsonSerializer : public angle::NonCopyable
}; };
} // namespace angle } // 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 #endif // JSONSERIALIZER_H
...@@ -440,6 +440,7 @@ libangle_sources += [ ...@@ -440,6 +440,7 @@ libangle_sources += [
"src/libANGLE/capture/capture_gles_3_1_autogen.h", "src/libANGLE/capture/capture_gles_3_1_autogen.h",
"src/libANGLE/capture/capture_gles_3_2_autogen.h", "src/libANGLE/capture/capture_gles_3_2_autogen.h",
"src/libANGLE/capture/capture_gles_ext_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/frame_capture_utils_autogen.h",
"src/libANGLE/capture/gl_enum_utils.h", "src/libANGLE/capture/gl_enum_utils.h",
"src/libANGLE/capture/gl_enum_utils_autogen.h", "src/libANGLE/capture/gl_enum_utils_autogen.h",
...@@ -460,8 +461,6 @@ libangle_capture_sources = [ ...@@ -460,8 +461,6 @@ libangle_capture_sources = [
"src/libANGLE/capture/capture_gles_ext_autogen.cpp", "src/libANGLE/capture/capture_gles_ext_autogen.cpp",
"src/libANGLE/capture/capture_gles_ext_params.cpp", "src/libANGLE/capture/capture_gles_ext_params.cpp",
"src/libANGLE/capture/frame_capture_replay_autogen.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/frame_capture_utils_autogen.cpp",
"src/libANGLE/capture/gl_enum_utils.cpp", "src/libANGLE/capture/gl_enum_utils.cpp",
"src/libANGLE/capture/gl_enum_utils_autogen.cpp", "src/libANGLE/capture/gl_enum_utils_autogen.cpp",
......
...@@ -142,17 +142,13 @@ angle_test("angle_unittests") { ...@@ -142,17 +142,13 @@ angle_test("angle_unittests") {
defines += [ "ANGLE_ENABLE_HLSL" ] defines += [ "ANGLE_ENABLE_HLSL" ]
} }
if (angle_has_build) {
defines += [ "ANGLE_HAS_RAPIDJSON" ]
}
deps = [ deps = [
":angle_test_expectations", ":angle_test_expectations",
"$angle_root:angle_json_serializer",
"$angle_root:libANGLE", "$angle_root:libANGLE",
"$angle_root:libEGL_static", "$angle_root:libEGL_static",
"$angle_root:libGLESv2_static", "$angle_root:libGLESv2_static",
"$angle_root:libfeature_support", "$angle_root:libfeature_support",
"$angle_root:libjson_serializer",
"$angle_root:preprocessor", "$angle_root:preprocessor",
"$angle_root:translator", "$angle_root:translator",
"$angle_root/util:angle_util_static", "$angle_root/util:angle_util_static",
......
...@@ -33,7 +33,6 @@ if (angle_build_capture_replay_tests) { ...@@ -33,7 +33,6 @@ if (angle_build_capture_replay_tests) {
"$angle_root:angle_common", "$angle_root:angle_common",
"$angle_root:angle_compression", "$angle_root:angle_compression",
"$angle_root:libEGL_with_capture_static", "$angle_root:libEGL_with_capture_static",
"$angle_root:libjson_serializer",
"$angle_root/util:angle_util_static", "$angle_root/util:angle_util_static",
] ]
configs += [ configs += [
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "common/system_utils.h" #include "common/system_utils.h"
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
#include "libANGLE/capture/frame_capture_utils.h" #include "libANGLE/capture/frame_capture_utils.h"
#include "libANGLE/serializer/JsonSerializer.h"
#include "util/EGLPlatformParameters.h" #include "util/EGLPlatformParameters.h"
#include "util/EGLWindow.h" #include "util/EGLWindow.h"
#include "util/OSWindow.h" #include "util/OSWindow.h"
...@@ -131,13 +130,15 @@ class CaptureReplayTests ...@@ -131,13 +130,15 @@ class CaptureReplayTests
{ {
ReplayContextFrame(testIndex, frame); ReplayContextFrame(testIndex, frame);
gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext()); gl::Context *context = static_cast<gl::Context *>(mEGLWindow->getContext());
angle::JsonSerializer json; std::string serializedContextString;
if (angle::SerializeContext(&json, context) != angle::Result::Continue) if (angle::SerializeContextToString(context, &serializedContextString) !=
angle::Result::Continue)
{ {
cleanupTest(); cleanupTest();
return -1; 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 always to allow RenderDoc/other tools to capture frames.
swap(); swap();
if (!isEqual) 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