Bug 1349799 - Part 2: Adding high power context creation flag; r?jgilbert draft
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 10 Jan 2018 17:39:03 +0800
changeset 721378 d853caf518cde9287ee81a4a8f7b0bf46f6c9bdf
parent 721365 af5430fd30dd0ee385489a99ec8ec6a268649d4b
child 721379 6a0d86e2fafa77b021a289b1715eceaf8d53a2cc
push id95832
push userbmo:dmu@mozilla.com
push dateWed, 17 Jan 2018 08:34:22 +0000
reviewersjgilbert
bugs1349799
milestone59.0a1
Bug 1349799 - Part 2: Adding high power context creation flag; r?jgilbert Using the high power context flag by default, unless giving a low_power powerPreference attritube when asking for creating WebGL context. MozReview-Commit-ID: EZZysuu4yet
dom/canvas/WebGLContext.cpp
gfx/gl/GLContextTypes.h
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -497,16 +497,23 @@ BaseCaps(const WebGLContextOptions& opti
                                    " to blacklisting.");
             baseCaps.antialias = false;
         }
     }
 
     return baseCaps;
 }
 
+static gl::CreateContextFlags
+ContextFlagWithPowerPreference(gl::CreateContextFlags aFlag,
+                               dom::WebGLPowerPreference aPower) {
+    return (aPower == dom::WebGLPowerPreference::Low_power)
+            ? aFlag : (aFlag | gl::CreateContextFlags::HIGH_POWER);
+}
+
 ////////////////////////////////////////
 
 static already_AddRefed<gl::GLContext>
 CreateGLWithEGL(const gl::SurfaceCaps& caps, gl::CreateContextFlags flags,
                 WebGLContext* webgl,
                 std::vector<WebGLContext::FailureReason>* const out_failReasons)
 {
     const gfx::IntSize dummySize(16, 16);
@@ -586,17 +593,19 @@ WebGLContext::CreateAndInitGLWith(FnCrea
 {
     std::queue<gl::SurfaceCaps> fallbackCaps;
     PopulateCapFallbackQueue(baseCaps, &fallbackCaps);
 
     MOZ_RELEASE_ASSERT(!gl, "GFX: Already have a context.");
     RefPtr<gl::GLContext> potentialGL;
     while (!fallbackCaps.empty()) {
         const gl::SurfaceCaps& caps = fallbackCaps.front();
-        potentialGL = fnCreateGL(caps, flags, this, out_failReasons);
+        potentialGL = fnCreateGL(caps,
+                                 ContextFlagWithPowerPreference(flags, mOptions.powerPreference),
+                                 this, out_failReasons);
         if (potentialGL)
             break;
 
         fallbackCaps.pop();
     }
     if (!potentialGL) {
         out_failReasons->push_back(FailureReason("FEATURE_FAILURE_WEBGL_EXHAUSTED_CAPS",
                                                  "Exhausted GL driver caps."));
--- a/gfx/gl/GLContextTypes.h
+++ b/gfx/gl/GLContextTypes.h
@@ -52,15 +52,17 @@ enum class CreateContextFlags : int8_t {
     FORCE_ENABLE_HARDWARE = 1 << 1,
     /* Don't force discrete GPU to be used (if applicable) */
     ALLOW_OFFLINE_RENDERER =  1 << 2,
     // Ask for ES3 if possible
     PREFER_ES3 = 1 << 3,
 
     NO_VALIDATION = 1 << 4,
     PREFER_ROBUSTNESS = 1 << 5,
+
+    HIGH_POWER = 1 << 6,
 };
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CreateContextFlags)
 
 } /* namespace gl */
 } /* namespace mozilla */
 
 #endif /* GLCONTEXT_TYPES_H_ */