mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
(backported from UXP) Issue #3042 - Add canvas WebGL context powerPreference
This commit is contained in:
parent
fbe9582c37
commit
6822713a60
4 changed files with 46 additions and 32 deletions
|
|
@ -88,19 +88,26 @@ using namespace mozilla::gl;
|
||||||
using namespace mozilla::layers;
|
using namespace mozilla::layers;
|
||||||
|
|
||||||
WebGLContextOptions::WebGLContextOptions()
|
WebGLContextOptions::WebGLContextOptions()
|
||||||
: alpha(true)
|
|
||||||
, depth(true)
|
|
||||||
, stencil(false)
|
|
||||||
, premultipliedAlpha(true)
|
|
||||||
, antialias(true)
|
|
||||||
, preserveDrawingBuffer(false)
|
|
||||||
, failIfMajorPerformanceCaveat(false)
|
|
||||||
{
|
{
|
||||||
// Set default alpha state based on preference.
|
// Set default alpha state based on preference.
|
||||||
if (gfxPrefs::WebGLDefaultNoAlpha())
|
if (gfxPrefs::WebGLDefaultNoAlpha())
|
||||||
alpha = false;
|
alpha = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 &= (powerPreference == r.powerPreference);
|
||||||
|
return eq;
|
||||||
|
}
|
||||||
|
|
||||||
/*static*/ const uint32_t WebGLContext::kMinMaxColorAttachments = 4;
|
/*static*/ const uint32_t WebGLContext::kMinMaxColorAttachments = 4;
|
||||||
/*static*/ const uint32_t WebGLContext::kMinMaxDrawBuffers = 4;
|
/*static*/ const uint32_t WebGLContext::kMinMaxDrawBuffers = 4;
|
||||||
|
|
@ -375,6 +382,7 @@ WebGLContext::SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options,
|
||||||
newOpts.antialias = attributes.mAntialias;
|
newOpts.antialias = attributes.mAntialias;
|
||||||
newOpts.preserveDrawingBuffer = attributes.mPreserveDrawingBuffer;
|
newOpts.preserveDrawingBuffer = attributes.mPreserveDrawingBuffer;
|
||||||
newOpts.failIfMajorPerformanceCaveat = attributes.mFailIfMajorPerformanceCaveat;
|
newOpts.failIfMajorPerformanceCaveat = attributes.mFailIfMajorPerformanceCaveat;
|
||||||
|
newOpts.powerPreference = attributes.mPowerPreference;
|
||||||
|
|
||||||
if (attributes.mAlpha.WasPassed())
|
if (attributes.mAlpha.WasPassed())
|
||||||
newOpts.alpha = attributes.mAlpha.Value();
|
newOpts.alpha = attributes.mAlpha.Value();
|
||||||
|
|
@ -393,7 +401,7 @@ WebGLContext::SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options,
|
||||||
newOpts.preserveDrawingBuffer ? 1 : 0);
|
newOpts.preserveDrawingBuffer ? 1 : 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mOptionsFrozen && newOpts != mOptions) {
|
if (mOptionsFrozen && !(newOpts == mOptions)) {
|
||||||
// Error if the options are already frozen, and the ones that were asked for
|
// Error if the options are already frozen, and the ones that were asked for
|
||||||
// aren't the same as what they were originally.
|
// aren't the same as what they were originally.
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
@ -692,6 +700,16 @@ WebGLContext::CreateAndInitGL(bool forceEnabled,
|
||||||
flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
|
flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (mOptions.powerPreference) {
|
||||||
|
case dom::WebGLPowerPreference::Low_power:
|
||||||
|
break;
|
||||||
|
case dom::WebGLPowerPreference::High_performance:
|
||||||
|
default:
|
||||||
|
// Default to high-performance if queried.
|
||||||
|
flags |= gl::CreateContextFlags::HIGH_POWER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
|
|
||||||
const bool useEGL = PR_GetEnv("MOZ_WEBGL_FORCE_EGL");
|
const bool useEGL = PR_GetEnv("MOZ_WEBGL_FORCE_EGL");
|
||||||
|
|
@ -1377,6 +1395,7 @@ WebGLContext::GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& r
|
||||||
result.mPremultipliedAlpha = mOptions.premultipliedAlpha;
|
result.mPremultipliedAlpha = mOptions.premultipliedAlpha;
|
||||||
result.mPreserveDrawingBuffer = mOptions.preserveDrawingBuffer;
|
result.mPreserveDrawingBuffer = mOptions.preserveDrawingBuffer;
|
||||||
result.mFailIfMajorPerformanceCaveat = mOptions.failIfMajorPerformanceCaveat;
|
result.mFailIfMajorPerformanceCaveat = mOptions.failIfMajorPerformanceCaveat;
|
||||||
|
result.mPowerPreference = mOptions.powerPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
||||||
|
|
@ -137,30 +137,17 @@ void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow);
|
||||||
|
|
||||||
struct WebGLContextOptions
|
struct WebGLContextOptions
|
||||||
{
|
{
|
||||||
// these are defaults
|
bool alpha = true;
|
||||||
|
bool depth = true;
|
||||||
|
bool stencil = false;
|
||||||
|
bool premultipliedAlpha = true;
|
||||||
|
bool antialias = true;
|
||||||
|
bool preserveDrawingBuffer = false;
|
||||||
|
bool failIfMajorPerformanceCaveat = false;
|
||||||
|
dom::WebGLPowerPreference powerPreference = dom::WebGLPowerPreference::Default;
|
||||||
|
|
||||||
WebGLContextOptions();
|
WebGLContextOptions();
|
||||||
|
bool operator==(const WebGLContextOptions&) const;
|
||||||
bool operator==(const WebGLContextOptions& other) const {
|
|
||||||
return
|
|
||||||
alpha == other.alpha &&
|
|
||||||
depth == other.depth &&
|
|
||||||
stencil == other.stencil &&
|
|
||||||
premultipliedAlpha == other.premultipliedAlpha &&
|
|
||||||
antialias == other.antialias &&
|
|
||||||
preserveDrawingBuffer == other.preserveDrawingBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const WebGLContextOptions& other) const {
|
|
||||||
return !operator==(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool alpha;
|
|
||||||
bool depth;
|
|
||||||
bool stencil;
|
|
||||||
bool premultipliedAlpha;
|
|
||||||
bool antialias;
|
|
||||||
bool preserveDrawingBuffer;
|
|
||||||
bool failIfMajorPerformanceCaveat;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// From WebGLContextUtils
|
// From WebGLContextUtils
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,10 @@ typedef unrestricted float GLfloat;
|
||||||
typedef unrestricted float GLclampf;
|
typedef unrestricted float GLclampf;
|
||||||
typedef unsigned long long GLuint64EXT;
|
typedef unsigned long long GLuint64EXT;
|
||||||
|
|
||||||
|
// The power preference settings are documented in the WebGLContextAttributes
|
||||||
|
// section of the specification.
|
||||||
|
enum WebGLPowerPreference { "default", "low-power", "high-performance" };
|
||||||
|
|
||||||
dictionary WebGLContextAttributes {
|
dictionary WebGLContextAttributes {
|
||||||
// boolean alpha = true;
|
// boolean alpha = true;
|
||||||
// We deviate from the spec here.
|
// We deviate from the spec here.
|
||||||
|
|
@ -43,6 +47,7 @@ dictionary WebGLContextAttributes {
|
||||||
GLboolean premultipliedAlpha = true;
|
GLboolean premultipliedAlpha = true;
|
||||||
GLboolean preserveDrawingBuffer = false;
|
GLboolean preserveDrawingBuffer = false;
|
||||||
GLboolean failIfMajorPerformanceCaveat = false;
|
GLboolean failIfMajorPerformanceCaveat = false;
|
||||||
|
WebGLPowerPreference powerPreference = "default";
|
||||||
};
|
};
|
||||||
|
|
||||||
[Exposed=(Window,Worker),
|
[Exposed=(Window,Worker),
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ struct GLFormats
|
||||||
GLsizei samples;
|
GLsizei samples;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class CreateContextFlags : int8_t {
|
enum class CreateContextFlags : uint8_t {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
REQUIRE_COMPAT_PROFILE = 1 << 0,
|
REQUIRE_COMPAT_PROFILE = 1 << 0,
|
||||||
// Force the use of hardware backed GL, don't allow software implementations.
|
// Force the use of hardware backed GL, don't allow software implementations.
|
||||||
|
|
@ -56,6 +56,9 @@ enum class CreateContextFlags : int8_t {
|
||||||
PREFER_ES3 = 1 << 3,
|
PREFER_ES3 = 1 << 3,
|
||||||
|
|
||||||
NO_VALIDATION = 1 << 4,
|
NO_VALIDATION = 1 << 4,
|
||||||
|
//PREFER_ROBUSTNESS = 1 << 5, /* reserved for now */
|
||||||
|
|
||||||
|
HIGH_POWER = 1 << 6,
|
||||||
};
|
};
|
||||||
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CreateContextFlags)
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CreateContextFlags)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue