diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index b8639a7713..19de675203 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -88,19 +88,26 @@ using namespace mozilla::gl; using namespace mozilla::layers; WebGLContextOptions::WebGLContextOptions() - : alpha(true) - , depth(true) - , stencil(false) - , premultipliedAlpha(true) - , antialias(true) - , preserveDrawingBuffer(false) - , failIfMajorPerformanceCaveat(false) { // Set default alpha state based on preference. if (gfxPrefs::WebGLDefaultNoAlpha()) 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::kMinMaxDrawBuffers = 4; @@ -375,6 +382,7 @@ WebGLContext::SetContextOptions(JSContext* cx, JS::Handle options, newOpts.antialias = attributes.mAntialias; newOpts.preserveDrawingBuffer = attributes.mPreserveDrawingBuffer; newOpts.failIfMajorPerformanceCaveat = attributes.mFailIfMajorPerformanceCaveat; + newOpts.powerPreference = attributes.mPowerPreference; if (attributes.mAlpha.WasPassed()) newOpts.alpha = attributes.mAlpha.Value(); @@ -393,7 +401,7 @@ WebGLContext::SetContextOptions(JSContext* cx, JS::Handle options, newOpts.preserveDrawingBuffer ? 1 : 0); #endif - if (mOptionsFrozen && newOpts != mOptions) { + if (mOptionsFrozen && !(newOpts == mOptions)) { // Error if the options are already frozen, and the ones that were asked for // aren't the same as what they were originally. return NS_ERROR_FAILURE; @@ -692,6 +700,16 @@ WebGLContext::CreateAndInitGL(bool forceEnabled, 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"); @@ -1377,6 +1395,7 @@ WebGLContext::GetContextAttributes(dom::Nullable& r result.mPremultipliedAlpha = mOptions.premultipliedAlpha; result.mPreserveDrawingBuffer = mOptions.preserveDrawingBuffer; result.mFailIfMajorPerformanceCaveat = mOptions.failIfMajorPerformanceCaveat; + result.mPowerPreference = mOptions.powerPreference; } NS_IMETHODIMP diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 8984b71366..6073da1754 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -137,30 +137,17 @@ void AssertUintParamCorrect(gl::GLContext* gl, GLenum pname, GLuint shadow); 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(); - - 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; + bool operator==(const WebGLContextOptions&) const; }; // From WebGLContextUtils diff --git a/dom/webidl/WebGLRenderingContext.webidl b/dom/webidl/WebGLRenderingContext.webidl index 323d234219..8cff320b3f 100644 --- a/dom/webidl/WebGLRenderingContext.webidl +++ b/dom/webidl/WebGLRenderingContext.webidl @@ -32,6 +32,10 @@ typedef unrestricted float GLfloat; typedef unrestricted float GLclampf; 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 { // boolean alpha = true; // We deviate from the spec here. @@ -43,6 +47,7 @@ dictionary WebGLContextAttributes { GLboolean premultipliedAlpha = true; GLboolean preserveDrawingBuffer = false; GLboolean failIfMajorPerformanceCaveat = false; + WebGLPowerPreference powerPreference = "default"; }; [Exposed=(Window,Worker), diff --git a/gfx/gl/GLContextTypes.h b/gfx/gl/GLContextTypes.h index de59acf491..b8ece51e88 100644 --- a/gfx/gl/GLContextTypes.h +++ b/gfx/gl/GLContextTypes.h @@ -45,7 +45,7 @@ struct GLFormats GLsizei samples; }; -enum class CreateContextFlags : int8_t { +enum class CreateContextFlags : uint8_t { NONE = 0, REQUIRE_COMPAT_PROFILE = 1 << 0, // 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, NO_VALIDATION = 1 << 4, + //PREFER_ROBUSTNESS = 1 << 5, /* reserved for now */ + + HIGH_POWER = 1 << 6, }; MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CreateContextFlags)