Skip to content

Commit

Permalink
Bug 1771374 - Use {bool, T} instead of Maybe<T> for now. r=gfx-review…
Browse files Browse the repository at this point in the history
…ers,lsalzman

`Maybe` isn't is_trivially_copyable, and std::optional isn't either on
the old libstdc++ we use from gcc7 still.

I'm working on more robust approach to serialization but that's beyond
the scope of this bug.

Differential Revision: https://phabricator.services.mozilla.com/D151421
  • Loading branch information
kdashg committed Jul 12, 2022
1 parent 6676711 commit 6f56767
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
5 changes: 3 additions & 2 deletions dom/canvas/ClientWebGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,10 @@ ClientWebGLContext::SetContextOptions(JSContext* cx,
if (attributes.mAntialias.WasPassed()) {
newOpts.antialias = attributes.mAntialias.Value();
}

newOpts.ignoreColorSpace = true;
if (attributes.mColorSpace.WasPassed()) {
newOpts.colorSpace = Some(attributes.mColorSpace.Value());
newOpts.ignoreColorSpace = false;
newOpts.colorSpace = attributes.mColorSpace.Value();
}

// Don't do antialiasing if we've disabled MSAA.
Expand Down
19 changes: 2 additions & 17 deletions dom/canvas/WebGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,6 @@ WebGLContextOptions::WebGLContextOptions() {
antialias = StaticPrefs::webgl_default_antialias();
}

bool WebGLContextOptions::operator==(const WebGLContextOptions& r) const {
bool eq = true;
eq &= (alpha == r.alpha);
eq &= (depth == r.depth);
eq &= (stencil == r.stencil);
eq &= (premultipliedAlpha == r.premultipliedAlpha);
eq &= (antialias == r.antialias);
eq &= (preserveDrawingBuffer == r.preserveDrawingBuffer);
eq &= (failIfMajorPerformanceCaveat == r.failIfMajorPerformanceCaveat);
eq &= (xrCompatible == r.xrCompatible);
eq &= (powerPreference == r.powerPreference);
eq &= (colorSpace == r.colorSpace);
return eq;
}

StaticMutex WebGLContext::sLruMutex;
std::list<WebGLContext*> WebGLContext::sLru;

Expand Down Expand Up @@ -913,8 +898,8 @@ inline gfx::ColorSpace2 ToColorSpace2(const WebGLContextOptions& options) {
if (StaticPrefs::gfx_color_management_native_srgb()) {
ret = gfx::ColorSpace2::SRGB;
}
if (options.colorSpace) {
ret = gfx::ToColorSpace2(*options.colorSpace);
if (!options.ignoreColorSpace) {
ret = gfx::ToColorSpace2(options.colorSpace);
}
return ret;
}
Expand Down
4 changes: 1 addition & 3 deletions dom/canvas/WebGLIpdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ struct ParamTraits<mozilla::WebGLContextOptions> final
static bool Validate(const T& val) {
bool ok = true;
ok &= ValidateParam(val.powerPreference);
if (val.colorSpace) {
ok &= ValidateParam(*val.colorSpace);
}
ok &= ValidateParam(val.colorSpace);
return ok;
}
};
Expand Down
40 changes: 35 additions & 5 deletions dom/canvas/WebGLTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <limits>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -348,28 +349,57 @@ struct FloatOrInt final // For TexParameter[fi] and friends.
explicit FloatOrInt(GLfloat x) : isFloat(true), f(x), i(roundf(x)) {}
};

struct WebGLContextOptions {
struct WebGLContextOptions final {
bool alpha = true;
bool depth = true;
bool stencil = false;
bool premultipliedAlpha = true;

bool antialias = true;
bool preserveDrawingBuffer = false;
bool failIfMajorPerformanceCaveat = false;
bool xrCompatible = false;

dom::WebGLPowerPreference powerPreference =
dom::WebGLPowerPreference::Default;
Maybe<dom::PredefinedColorSpace> colorSpace;
bool ignoreColorSpace = true;
dom::PredefinedColorSpace colorSpace = dom::PredefinedColorSpace::Srgb;
bool shouldResistFingerprinting = true;

bool enableDebugRendererInfo = false;

// -

WebGLContextOptions();
WebGLContextOptions(const WebGLContextOptions&) = default;

bool operator==(const WebGLContextOptions&) const;
bool operator!=(const WebGLContextOptions& rhs) const {
return !(*this == rhs);
auto Fields() const {
// clang-format off
return std::tie(
alpha,
depth,
stencil,
premultipliedAlpha,

antialias,
preserveDrawingBuffer,
failIfMajorPerformanceCaveat,
xrCompatible,

powerPreference,
ignoreColorSpace,
colorSpace,
shouldResistFingerprinting,

enableDebugRendererInfo);
// clang-format on
}

using Self = WebGLContextOptions;
friend bool operator==(const Self& a, const Self& b) {
return a.Fields() == b.Fields();
}
friend bool operator!=(const Self& a, const Self& b) { return !(a == b); }
};

namespace gfx {
Expand Down

0 comments on commit 6f56767

Please sign in to comment.