Skip to content

Commit

Permalink
Bug 1561073 - powerPreference 'default' => 'low-power' if Canvas elem…
Browse files Browse the repository at this point in the history
…ent has no parent. r=jrmuizel

Differential Revision: https://phabricator.services.mozilla.com/D35704

--HG--
extra : moz-landing-system : lando
  • Loading branch information
kdashg committed Jun 24, 2019
1 parent dadb1f6 commit 5c6f58f
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions dom/canvas/WebGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,32 +483,46 @@ bool WebGLContext::CreateAndInitGL(
flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
}

switch (mOptions.powerPreference) {
case dom::WebGLPowerPreference::Low_power:
break;

case dom::WebGLPowerPreference::High_performance:
flags |= gl::CreateContextFlags::HIGH_POWER;
break;
{
bool highPower = false;
switch (mOptions.powerPreference) {
case dom::WebGLPowerPreference::Low_power:
highPower = false;
break;

case dom::WebGLPowerPreference::High_performance:
highPower = true;
break;

// Eventually add a heuristic, but for now default to high-performance.
// We can even make it dynamic by holding on to a
// ForceDiscreteGPUHelperCGL iff we decide it's a high-performance
// application:
// - Non-trivial canvas size
// - Many draw calls
// - Same origin with root page (try to stem bleeding from WebGL
// ads/trackers)
default:
highPower = true;
if (StaticPrefs::WebGLDefaultLowPower()) {
highPower = false;
} else if (!mCanvasElement->GetParentNode()) {
GenerateWarning(
"WebGLContextAttributes.powerPreference: 'default' when <canvas>"
" has no parent Element defaults to 'low-power'.");
highPower = false;
}
break;
}

// Eventually add a heuristic, but for now default to high-performance.
// We can even make it dynamic by holding on to a
// ForceDiscreteGPUHelperCGL iff we decide it's a high-performance
// application:
// - Non-trivial canvas size
// - Many draw calls
// - Same origin with root page (try to stem bleeding from WebGL
// ads/trackers)
default:
if (!StaticPrefs::WebGLDefaultLowPower()) {
flags |= gl::CreateContextFlags::HIGH_POWER;
}
break;
}
// If "Use hardware acceleration when available" option is disabled:
if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
highPower = false;
}

// If "Use hardware acceleration when available" option is disabled:
if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
flags &= ~gl::CreateContextFlags::HIGH_POWER;
if (highPower) {
flags |= gl::CreateContextFlags::HIGH_POWER;
}
}

#ifdef XP_MACOSX
Expand Down

0 comments on commit 5c6f58f

Please sign in to comment.