Bug 1885028 - PlainOldDataSerializer use removed from dom/canvas. r=gfx-reviewers,lsalzman,ahale

Differential Revision: https://phabricator.services.mozilla.com/D204432
This commit is contained in:
unknown
2024-03-14 00:21:23 +00:00
parent aa016b38a9
commit 6b54094ea8
4 changed files with 88 additions and 80 deletions

View File

@@ -847,7 +847,12 @@ bool ClientWebGLContext::CreateHostContext(const uvec2& requestedSize) {
ShouldResistFingerprinting(RFPTarget::WebGLRenderCapability);
const auto principalKey = GetPrincipalHashValue();
const auto initDesc = webgl::InitContextDesc{
mIsWebGL2, resistFingerprinting, requestedSize, options, principalKey};
.isWebgl2 = mIsWebGL2,
.resistFingerprinting = resistFingerprinting,
.principalKey = principalKey,
.size = requestedSize,
.options = options,
};
// -

View File

@@ -465,9 +465,13 @@ bool SharedContextWebgl::Initialize() {
const bool resistFingerprinting = nsContentUtils::ShouldResistFingerprinting(
"Fallback", RFPTarget::WebGLRenderCapability);
const auto initDesc =
webgl::InitContextDesc{/*isWebgl2*/ true, resistFingerprinting,
/*size*/ {1, 1}, options, /*principalKey*/ 0};
const auto initDesc = webgl::InitContextDesc{
.isWebgl2 = true,
.resistFingerprinting = resistFingerprinting,
.principalKey = 0,
.size = {1, 1},
.options = options,
};
webgl::InitContextResult initResult;
mWebgl = WebGLContext::Create(nullptr, initDesc, &initResult);
@@ -619,7 +623,8 @@ bool SharedContextWebgl::SetNoClipMask() {
}
mWebgl->ActiveTexture(1);
mWebgl->BindTexture(LOCAL_GL_TEXTURE_2D, mNoClipMask);
static const auto solidMask = std::array<const uint8_t, 4>{0xFF, 0xFF, 0xFF, 0xFF};
static const auto solidMask =
std::array<const uint8_t, 4>{0xFF, 0xFF, 0xFF, 0xFF};
mWebgl->TexImage(0, LOCAL_GL_RGBA8, {0, 0, 0},
{LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE},
{LOCAL_GL_TEXTURE_2D,

View File

@@ -10,6 +10,7 @@
#include "ipc/EnumSerializer.h"
#include "ipc/IPCMessageUtils.h"
#include "mozilla/GfxMessageUtils.h"
#include "mozilla/dom/BindingIPCUtils.h"
#include "mozilla/ipc/IPDLParamTraits.h"
#include "mozilla/ipc/Shmem.h"
#include "mozilla/layers/LayersSurfaces.h"
@@ -233,6 +234,16 @@ struct ParamTraits<gfxAlphaType>
: public ContiguousEnumSerializerInclusive<
gfxAlphaType, gfxAlphaType::Opaque, gfxAlphaType::NonPremult> {};
template <>
struct ParamTraits<mozilla::dom::WebGLPowerPreference> final
: public mozilla::dom::WebIDLEnumSerializer<
mozilla::dom::WebGLPowerPreference> {};
template <>
struct ParamTraits<mozilla::dom::PredefinedColorSpace> final
: public mozilla::dom::WebIDLEnumSerializer<
mozilla::dom::PredefinedColorSpace> {};
// -
// ParamTraits_TiedFields
@@ -242,7 +253,7 @@ struct ParamTraits_TiedFields {
static void Write(MessageWriter* const writer, const T& in) {
const auto& fields = mozilla::TiedFields(in);
MapTuple(fields, [&](const auto& field) {
mozilla::MapTuple(fields, [&](const auto& field) {
WriteParam(writer, field);
return true; // ignored
});
@@ -251,7 +262,7 @@ struct ParamTraits_TiedFields {
static bool Read(MessageReader* const reader, T* const out) {
const auto& fields = mozilla::TiedFields(*out);
bool ok = true;
MapTuple(fields, [&](auto& field) {
mozilla::MapTuple(fields, [&](auto& field) {
if (ok) {
ok &= ReadParam(reader, &field);
}
@@ -263,74 +274,17 @@ struct ParamTraits_TiedFields {
// -
template <typename T>
bool ValidateParam(const T& val) {
return ParamTraits<T>::Validate(val);
}
template <typename T>
struct ValidatedPlainOldDataSerializer : public PlainOldDataSerializer<T> {
static void Write(MessageWriter* const writer, const T& in) {
MOZ_ASSERT(ValidateParam(in));
PlainOldDataSerializer<T>::Write(writer, in);
}
static bool Read(MessageReader* const reader, T* const out) {
if (!PlainOldDataSerializer<T>::Read(reader, out)) return false;
return ValidateParam(*out);
}
// static bool Validate(const T&) = 0;
};
// -
template <>
struct ParamTraits<mozilla::webgl::InitContextDesc> final
: public ValidatedPlainOldDataSerializer<mozilla::webgl::InitContextDesc> {
using T = mozilla::webgl::InitContextDesc;
static bool Validate(const T& val) {
return ValidateParam(val.options) && (val.size.x && val.size.y);
}
};
: public ParamTraits_TiedFields<mozilla::webgl::InitContextDesc> {};
template <>
struct ParamTraits<mozilla::WebGLContextOptions> final
: public ValidatedPlainOldDataSerializer<mozilla::WebGLContextOptions> {
using T = mozilla::WebGLContextOptions;
static bool Validate(const T& val) {
bool ok = true;
ok &= ValidateParam(val.powerPreference);
ok &= ValidateParam(val.colorSpace);
return ok;
}
};
template <>
struct ParamTraits<mozilla::dom::WebGLPowerPreference> final
: public ValidatedPlainOldDataSerializer<
mozilla::dom::WebGLPowerPreference> {
using T = mozilla::dom::WebGLPowerPreference;
static bool Validate(const T& val) { return val <= T::High_performance; }
};
template <>
struct ParamTraits<mozilla::dom::PredefinedColorSpace> final
: public ValidatedPlainOldDataSerializer<
mozilla::dom::PredefinedColorSpace> {
using T = mozilla::dom::PredefinedColorSpace;
static bool Validate(const T& val) {
return val <= mozilla::ContiguousEnumValues<T>::max;
}
};
: public ParamTraits_TiedFields<mozilla::WebGLContextOptions> {};
template <>
struct ParamTraits<mozilla::webgl::OpaqueFramebufferOptions> final
: public PlainOldDataSerializer<mozilla::webgl::OpaqueFramebufferOptions> {
: public ParamTraits_TiedFields<mozilla::webgl::OpaqueFramebufferOptions> {
};
// -
@@ -342,28 +296,24 @@ struct ParamTraits<mozilla::gl::GLVendor>
mozilla::gl::kHighestGLVendor> {
};
template <typename T>
struct ParamTraits<mozilla::webgl::EnumMask<T>> final
: public PlainOldDataSerializer<mozilla::webgl::EnumMask<T>> {};
template <typename U>
struct ParamTraits<mozilla::webgl::EnumMask<U>> final
: public ParamTraits_TiedFields<mozilla::webgl::EnumMask<U>> {};
template <>
struct ParamTraits<mozilla::webgl::InitContextResult> final
: public ParamTraits_TiedFields<mozilla::webgl::InitContextResult> {};
template <>
struct ParamTraits<mozilla::webgl::ExtensionBits> final
: public PlainOldDataSerializer<mozilla::webgl::ExtensionBits> {};
template <>
struct ParamTraits<mozilla::webgl::Limits> final
: public PlainOldDataSerializer<mozilla::webgl::Limits> {};
: public ParamTraits_TiedFields<mozilla::webgl::Limits> {};
template <>
struct ParamTraits<mozilla::webgl::PixelPackingState> final
: public PlainOldDataSerializer<mozilla::webgl::PixelPackingState> {};
: public ParamTraits_TiedFields<mozilla::webgl::PixelPackingState> {};
template <>
struct ParamTraits<mozilla::webgl::PixelUnpackStateWebgl> final
: public PlainOldDataSerializer<mozilla::webgl::PixelUnpackStateWebgl> {};
: public ParamTraits_TiedFields<mozilla::webgl::PixelUnpackStateWebgl> {};
// -
@@ -571,6 +521,24 @@ struct ParamTraits<mozilla::webgl::ShaderPrecisionFormat> final {
// -
template <typename U, size_t N>
struct ParamTraits<std::array<U, N>> final {
using T = std::array<U, N>;
static void Write(MessageWriter* const writer, const T& in) {
for (const auto& v : in) {
WriteParam(writer, v);
}
}
static bool Read(MessageReader* const reader, T* const out) {
for (auto& v : *out) {
if (!ReadParam(reader, &v)) return false;
}
return true;
}
};
template <typename U, size_t N>
struct ParamTraits<U[N]> final {
using T = U[N];

View File

@@ -599,9 +599,13 @@ class EnumMask {
public:
BitRef operator[](const E i) { return {*this, Mask(i)}; }
bool operator[](const E i) const { return mBits & Mask(i); }
// -
auto MutTiedFields() { return std::tie(mBits); }
};
class ExtensionBits : public EnumMask<WebGLExtensionID> {};
using ExtensionBits = EnumMask<WebGLExtensionID>;
// -
@@ -625,9 +629,16 @@ inline bool ReadContextLossReason(const uint8_t val,
struct InitContextDesc final {
bool isWebgl2 = false;
bool resistFingerprinting = false;
std::array<uint8_t, 2> _padding;
uint32_t principalKey = 0;
uvec2 size = {};
WebGLContextOptions options;
uint32_t principalKey = 0;
std::array<uint8_t, 3> _padding2;
auto MutTiedFields() {
return std::tie(isWebgl2, resistFingerprinting, _padding, principalKey,
size, options, _padding2);
}
};
constexpr uint32_t kMaxTransformFeedbackSeparateAttribs = 4;
@@ -652,10 +663,24 @@ struct Limits final {
// Exts
bool astcHdr = false;
std::array<uint8_t, 3> _padding;
uint32_t maxColorDrawBuffers = 1;
uint32_t maxMultiviewLayers = 0;
uint64_t queryCounterBitsTimeElapsed = 0;
uint64_t queryCounterBitsTimestamp = 0;
uint32_t maxMultiviewLayers = 0;
auto MutTiedFields() {
return std::tie(supportedExtensions,
maxTexUnits, maxTex2dSize, maxTexCubeSize, maxVertexAttribs,
maxViewportDim, pointSizeRange, lineWidthRange,
maxTexArrayLayers, maxTex3dSize, maxUniformBufferBindings,
uniformBufferOffsetAlignment,
astcHdr, _padding, maxColorDrawBuffers, maxMultiviewLayers,
queryCounterBitsTimeElapsed, queryCounterBitsTimestamp);
}
};
// -
@@ -756,8 +781,13 @@ struct CompileResult final {
struct OpaqueFramebufferOptions final {
bool depthStencil = true;
bool antialias = true;
std::array<uint8_t, 2> _padding;
uint32_t width = 0;
uint32_t height = 0;
auto MutTiedFields() {
return std::tie(depthStencil, antialias, _padding, width, height);
}
};
// -