Commit a59e347c authored by Aaron Krajeski's avatar Aaron Krajeski Committed by Commit Bot

Fix the logic for always accelerating canvases

Because HTMLCanvasElement::ShouldAccelerate always returned true if the
AlwaysAccelerate finch trial was running, it would never hit the path
where it creates a ContextProviderWrapper and checks that it is even
POSSIBLE to create an accelerated canvas.

This CL changes the logic of that function so that
features::kAlwaysAccelerateCanvas simply bypasses all of the other
heuristics, but still performs the check on the context provider.

Bug: 930559
Change-Id: If4d52b6696424488c468fcaa779793dbec9e689b
Reviewed-on: https://chromium-review.googlesource.com/c/1478484Reviewed-by: default avatarenne <enne@chromium.org>
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633835}
parent f35abe10
......@@ -994,44 +994,47 @@ void HTMLCanvasElement::PushFrame(scoped_refptr<CanvasResource> image,
}
bool HTMLCanvasElement::ShouldAccelerate(AccelerationCriteria criteria) const {
if (base::FeatureList::IsEnabled(features::kAlwaysAccelerateCanvas))
return true;
if (context_ && !Is2d())
return false;
// The following is necessary for handling the special case of canvases in the
// dev tools overlay, which run in a process that supports accelerated 2d
// canvas but in a special compositing context that does not.
if (GetLayoutBox() && !GetLayoutBox()->HasAcceleratedCompositing())
return false;
base::CheckedNumeric<int> checked_canvas_pixel_count = Size().Width();
checked_canvas_pixel_count *= Size().Height();
if (!checked_canvas_pixel_count.IsValid())
return false;
int canvas_pixel_count = checked_canvas_pixel_count.ValueOrDie();
// Do not use acceleration for small canvas.
if (criteria != kIgnoreResourceLimitCriteria) {
Settings* settings = GetDocument().GetSettings();
if (!settings ||
canvas_pixel_count < settings->GetMinimumAccelerated2dCanvasSize()) {
// With this feature enabled we want to accelerate canvases whenever we can.
// This does not include when the context_provider CANNOT accelerated
// canvases.
if (!base::FeatureList::IsEnabled(features::kAlwaysAccelerateCanvas)) {
if (context_ && !Is2d())
return false;
}
// When GPU allocated memory runs low (due to having created too many
// accelerated canvases), the compositor starves and browser becomes laggy.
// Thus, we should stop allocating more GPU memory to new canvases created
// when the current memory usage exceeds the threshold.
if (global_gpu_memory_usage_ >= kMaxGlobalGPUMemoryUsage)
// The following is necessary for handling the special case of canvases in
// the dev tools overlay, which run in a process that supports accelerated
// 2d canvas but in a special compositing context that does not.
if (GetLayoutBox() && !GetLayoutBox()->HasAcceleratedCompositing())
return false;
// Allocating too many GPU resources can makes us run into the driver's
// resource limits. So we need to keep the number of texture resources
// under tight control
if (global_accelerated_context_count_ >= kMaxGlobalAcceleratedResourceCount)
base::CheckedNumeric<int> checked_canvas_pixel_count = Size().Width();
checked_canvas_pixel_count *= Size().Height();
if (!checked_canvas_pixel_count.IsValid())
return false;
int canvas_pixel_count = checked_canvas_pixel_count.ValueOrDie();
// Do not use acceleration for small canvas.
if (criteria != kIgnoreResourceLimitCriteria) {
Settings* settings = GetDocument().GetSettings();
if (!settings ||
canvas_pixel_count < settings->GetMinimumAccelerated2dCanvasSize()) {
return false;
}
// When GPU allocated memory runs low (due to having created too many
// accelerated canvases), the compositor starves and browser becomes
// laggy. Thus, we should stop allocating more GPU memory to new canvases
// created when the current memory usage exceeds the threshold.
if (global_gpu_memory_usage_ >= kMaxGlobalGPUMemoryUsage)
return false;
// Allocating too many GPU resources can makes us run into the driver's
// resource limits. So we need to keep the number of texture resources
// under tight control
if (global_accelerated_context_count_ >=
kMaxGlobalAcceleratedResourceCount)
return false;
}
}
// Avoid creating |contextProvider| until we're sure we want to try use it,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment