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

Move canvas and offscreenCanvas size recorders to their destructors

This prevents us from recording canvas size multiple times for the same
canvas. Also confirmed that we are recording the correct numbers and
move `isOffscreen` to an enum.

Bug: 902000
Change-Id: Ic6e66ec960ae0166699280303a61b574c9320294
Reviewed-on: https://chromium-review.googlesource.com/c/1319180
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606062}
parent 14754da5
...@@ -20,13 +20,15 @@ CanvasRenderingContextHost::CanvasRenderingContextHost() = default; ...@@ -20,13 +20,15 @@ CanvasRenderingContextHost::CanvasRenderingContextHost() = default;
void CanvasRenderingContextHost::RecordCanvasSizeToUMA(unsigned width, void CanvasRenderingContextHost::RecordCanvasSizeToUMA(unsigned width,
unsigned height, unsigned height,
bool isOffscreen) { HostType hostType) {
if (isOffscreen) { if (hostType == kCanvasHost) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.Canvas.SqrtNumberOfPixels",
std::sqrt(width * height), 1, 5000, 100);
} else if (hostType == kOffscreenCanvasHost) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.OffscreenCanvas.SqrtNumberOfPixels", UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.OffscreenCanvas.SqrtNumberOfPixels",
std::sqrt(width * height), 1, 5000, 100); std::sqrt(width * height), 1, 5000, 100);
} else { } else {
UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.Canvas.SqrtNumberOfPixels", NOTREACHED();
std::sqrt(width * height), 1, 5000, 100);
} }
} }
......
...@@ -34,9 +34,12 @@ class CORE_EXPORT CanvasRenderingContextHost : public CanvasResourceHost, ...@@ -34,9 +34,12 @@ class CORE_EXPORT CanvasRenderingContextHost : public CanvasResourceHost,
public: public:
CanvasRenderingContextHost(); CanvasRenderingContextHost();
void static RecordCanvasSizeToUMA(unsigned width, enum HostType {
unsigned height, kCanvasHost,
bool isOffscreen); kOffscreenCanvasHost,
};
void static RecordCanvasSizeToUMA(unsigned width, unsigned height, HostType);
virtual void DetachContext() = 0; virtual void DetachContext() = 0;
virtual void DidDraw(const FloatRect& rect) = 0; virtual void DidDraw(const FloatRect& rect) = 0;
......
...@@ -134,8 +134,6 @@ inline HTMLCanvasElement::HTMLCanvasElement(Document& document) ...@@ -134,8 +134,6 @@ inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
externally_allocated_memory_(0), externally_allocated_memory_(0),
gpu_readback_invoked_in_current_frame_(false), gpu_readback_invoked_in_current_frame_(false),
gpu_readback_successive_frames_(0) { gpu_readback_successive_frames_(0) {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
size_.Width(), size_.Height(), false /* Canvas */);
UseCounter::Count(document, WebFeature::kHTMLCanvasElement); UseCounter::Count(document, WebFeature::kHTMLCanvasElement);
GetDocument().IncrementNumberOfCanvases(); GetDocument().IncrementNumberOfCanvases();
...@@ -147,6 +145,9 @@ intptr_t HTMLCanvasElement::global_gpu_memory_usage_ = 0; ...@@ -147,6 +145,9 @@ intptr_t HTMLCanvasElement::global_gpu_memory_usage_ = 0;
unsigned HTMLCanvasElement::global_accelerated_context_count_ = 0; unsigned HTMLCanvasElement::global_accelerated_context_count_ = 0;
HTMLCanvasElement::~HTMLCanvasElement() { HTMLCanvasElement::~HTMLCanvasElement() {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
size_.Width(), size_.Height(),
CanvasRenderingContextHost::HostType::kCanvasHost);
if (surface_layer_bridge_ && surface_layer_bridge_->GetCcLayer()) if (surface_layer_bridge_ && surface_layer_bridge_->GetCcLayer())
GraphicsLayer::UnregisterContentsLayer(surface_layer_bridge_->GetCcLayer()); GraphicsLayer::UnregisterContentsLayer(surface_layer_bridge_->GetCcLayer());
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
...@@ -571,9 +572,6 @@ void HTMLCanvasElement::Reset() { ...@@ -571,9 +572,6 @@ void HTMLCanvasElement::Reset() {
IntSize old_size = Size(); IntSize old_size = Size();
IntSize new_size(w, h); IntSize new_size(w, h);
if (old_size != new_size)
CanvasRenderingContextHost::RecordCanvasSizeToUMA(w, h, false /* Canvas */);
// If the size of an existing buffer matches, we can just clear it instead of // If the size of an existing buffer matches, we can just clear it instead of
// reallocating. This optimization is only done for 2D canvases for now. // reallocating. This optimization is only done for 2D canvases for now.
if (had_resource_provider && old_size == new_size && Is2d()) { if (had_resource_provider && old_size == new_size && Is2d()) {
......
...@@ -46,6 +46,9 @@ OffscreenCanvas* OffscreenCanvas::Create(unsigned width, unsigned height) { ...@@ -46,6 +46,9 @@ OffscreenCanvas* OffscreenCanvas::Create(unsigned width, unsigned height) {
} }
OffscreenCanvas::~OffscreenCanvas() { OffscreenCanvas::~OffscreenCanvas() {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
Size().Width(), Size().Height(),
CanvasRenderingContextHost::HostType::kOffscreenCanvasHost);
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
-memory_usage_); -memory_usage_);
} }
...@@ -423,9 +426,6 @@ FontSelector* OffscreenCanvas::GetFontSelector() { ...@@ -423,9 +426,6 @@ FontSelector* OffscreenCanvas::GetFontSelector() {
} }
void OffscreenCanvas::UpdateMemoryUsage() { void OffscreenCanvas::UpdateMemoryUsage() {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
Size().Width(), Size().Height(), true /* OffscreenCanvas */);
int bytes_per_pixel = ColorParams().BytesPerPixel(); int bytes_per_pixel = ColorParams().BytesPerPixel();
base::CheckedNumeric<int32_t> memory_usage_checked = bytes_per_pixel; base::CheckedNumeric<int32_t> memory_usage_checked = bytes_per_pixel;
......
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